1055_A. Metro

Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.

In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that.

Some stations are not yet open at all and some are only partially open — for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it.

When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport.

Input

The first line contains two integers n and s (2 ≤ s ≤ n ≤ 1000) — the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1.

Next lines describe information about closed and open stations.

The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track.

The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track.

Output

Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise.

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

Examples

Input

5 3
1 1 1 1 1
1 1 1 1 1

Output

YES

Input

5 4
1 0 0 0 1
0 1 1 1 1

Output

YES

Input

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

Output

NO

Note

In the first example, all stations are opened, so Bob can simply travel to the station with number 3.

In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then.

In the third example, Bob simply can't enter the train going in the direction of Alice's home.

```python
n, s = input().split()
n = int(n)
s = int(s)
a = input().split()
b = input().split()

for j in range(n):
	a[j] = int(a[j])
	b[j] = int(b[j])

if a[0]==1:
	if a[s-1]==1:
		print("YES")

	elif b[s-1]==1:
		for i in range(s,n):
			if a[i]==1 and b[i]==1:
				print("YES")
				break
		else:
			print("NO")

	else:
		print("NO")

else:
	print("NO")

```


1077_B. Disturbed People

There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise.

Vova thinks that people in the i-th flats are disturbed and cannot sleep if and only if 1 < i < n and a_{i - 1} = a_{i + 1} = 1 and a_i = 0.

Vova is concerned by the following question: what is the minimum number k such that if people from exactly k pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number k.

Input

The first line of the input contains one integer n (3 ≤ n ≤ 100) — the number of flats in the house.

The second line of the input contains n integers a_1, a_2, ..., a_n (a_i ∈ \{0, 1\}), where a_i is the state of light in the i-th flat.

Output

Print only one integer — the minimum number k such that if people from exactly k pairwise distinct flats will turn off the light then nobody will be disturbed.

Examples

Input

10
1 1 0 1 1 0 1 0 1 0

Output

2

Input

5
1 1 0 0 0

Output

0

Input

4
1 1 1 1

Output

0

Note

In the first example people from flats 2 and 7 or 4 and 7 can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.

There are no disturbed people in second and third examples.

```python
n = int(input())
A = [int(i) for i in input().split()]
V = []
for i in range(n-2):
    if (A[i]==1 and A[i+1]==0 and A[i+2]==1):
        V.append(i+1)
V.append(1000)

k = 0
l = 0
n = len(V)
for i in range(n):
    if (V[i]-V[l] != 2):
        d = i-l
        k += (d+1)//2
        l = i
print(k)

```


1098_A. Sum in the tree

Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vertex v, which denotes the number of vertices on the path from vertex v to the root. Clearly, s_1=a_1 and h_1=1.

Then Mitya erased all numbers a_v, and by accident he also erased all values s_v for vertices with even depth (vertices with even h_v). Your task is to restore the values a_v for every vertex, or determine that Mitya made a mistake. In case there are multiple ways to restore the values, you're required to find one which minimizes the total sum of values a_v for all vertices in the tree.

Input

The first line contains one integer n — the number of vertices in the tree (2 ≤ n ≤ 10^5). The following line contains integers p_2, p_3, ... p_n, where p_i stands for the parent of vertex with index i in the tree (1 ≤ p_i < i). The last line contains integer values s_1, s_2, ..., s_n (-1 ≤ s_v ≤ 10^9), where erased values are replaced by -1.

Output

Output one integer — the minimum total sum of all values a_v in the original tree, or -1 if such tree does not exist.

Examples

Input

5
1 1 1 1
1 -1 -1 -1 -1

Output

1

Input

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

Output

2

Input

3
1 2
2 -1 1

Output

-1

```python
# alpha = "abcdefghijklmnopqrstuvwxyz"
prime = 998244353
# INF = 100000000000
# from heapq import heappush
from collections import defaultdict, deque
t = 1#int(input())
from math import sqrt
for test in range(t):
    n = int(input())
    p = [0, 0]
    p.extend(list(map(int, input().split())))
    s = [0]
    s.extend(list(map(int, input().split())))
    a = [0 for i in range(n+1)]
    a[1] = s[1]
    D = defaultdict(list)
    depth = {}
    depth[1] = 1
    # S[1] =
    for i in range(2,n+1):
        D[p[i]].append(i)
        depth[i] = depth[p[i]]+1
    q = deque([])
    q.append(1)

    found = True
    while q:
        cur = q.popleft()
        if not found:
            break
        for j in D[cur]:
            if depth[j]%2==0:
                if D[j]==[]:
                    a[j] = 0
                    s[j] = s[cur]
                else:
                    tmp = 2000000000
                    for k in D[j]:
                        tmp = min(tmp, s[k] - s[cur])
                    if tmp<0:
                        found = False
                        break
                    a[j] = tmp
                    s[j] = s[cur]+tmp
                    for k in D[j]:
                        a[k] = s[k]-tmp-s[cur]

            else:
                if a[k]<0:
                    # print(k,a[k])
                    found = False
                    break
            q.append(j)
    if found:
        print(sum(a))
    else:
        print(-1)

```


1119_B. Alyona and a Narrow Fridge

Alyona has recently bought a miniature fridge that can be represented as a matrix with h rows and 2 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but separates the inside of the fridge to the lower and upper part.

<image> An example of a fridge with h = 7 and two shelves. The shelves are shown in black. The picture corresponds to the first example.

Alyona has n bottles of milk that she wants to put in the fridge. The i-th bottle is a_i cells tall and 1 cell wide. She can put a bottle on some shelf if the corresponding space above the shelf is at least as tall as the bottle. She can not put a bottle on top of another bottle (if there is no shelf between them). Two bottles can not share a cell.

Alyona is interested in the largest integer k such that she can put bottles 1, 2, ..., k in the fridge at the same time. Find this largest k.

Input

The first line contains two integers n and h (1 ≤ n ≤ 10^3, 1 ≤ h ≤ 10^9) — the number of bottles and the height of the fridge.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ h) — the heights of the bottles.

Output

Print the single integer k — the maximum integer such that Alyona can put the bottles 1, 2, ..., k in the fridge at the same time. If Alyona can put all bottles in the fridge, print n. It is easy to see that Alyona can always put at least one bottle in the fridge.

Examples

Input

5 7
2 3 5 4 1

Output

3

Input

10 10
9 1 1 1 1 1 1 1 1 1

Output

4

Input

5 10
3 1 4 2 4

Output

5

Note

One of optimal locations in the first example is shown on the picture in the statement.

One of optimal locations in the second example is shown on the picture below.

<image>

One of optimal locations in the third example is shown on the picture below.

<image>

```python
n,h=input().split()
n=int(n)
h=int(h)
l=list(map(int,input().split()))
k=[]
r=0
for i in range(n):
    k.append(l[i])
    k.sort(reverse=True)
    ans=0
    for j in range(0,len(k),2):
        ans=ans+k[j]
    if(ans<=h):
        r=i+1
    else:
        break
print(r)
```


1145_F. Neat Words

Input

The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.

Output

Output "YES" or "NO".

Examples

Input

NEAT

Output

YES

Input

WORD

Output

NO

Input

CODER

Output

NO

Input

APRILFOOL

Output

NO

Input

AI

Output

YES

Input

JUROR

Output

YES

Input

YES

Output

NO

```python
lin = set(list('WETYIAFHKLZXVNM'))
s = input()
print('YES' if len(set(list(s)).intersection(lin)) in [len(set(list(s))), 0] else 'NO')

```


1166_E. The LCMs Must be Large

Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?

There are n stores numbered from 1 to n in Nlogonia. The i-th of these stores offers a positive integer a_i.

Each day among the last m days Dora bought a single integer from some of the stores. The same day, Swiper the fox bought a single integer from all the stores that Dora did not buy an integer from on that day.

Dora considers Swiper to be her rival, and she considers that she beat Swiper on day i if and only if the least common multiple of the numbers she bought on day i is strictly greater than the least common multiple of the numbers that Swiper bought on day i.

The least common multiple (LCM) of a collection of integers is the smallest positive integer that is divisible by all the integers in the collection.

However, Dora forgot the values of a_i. Help Dora find out if there are positive integer values of a_i such that she beat Swiper on every day. You don't need to find what are the possible values of a_i though.

Note that it is possible for some values of a_i to coincide in a solution.

Input

The first line contains integers m and n (1≤ m ≤ 50, 1≤ n ≤ 10^4) — the number of days and the number of stores.

After this m lines follow, the i-th line starts with an integer s_i (1≤ s_i ≤ n-1), the number of integers Dora bought on day i, followed by s_i distinct integers, the indices of the stores where Dora bought an integer on the i-th day. The indices are between 1 and n.

Output

Output must consist of a single line containing "possible" if there exist positive integers a_i such that for each day the least common multiple of the integers bought by Dora is strictly greater than the least common multiple of the integers bought by Swiper on that day. Otherwise, print "impossible".

Note that you don't have to restore the integers themselves.

Examples

Input

2 5
3 1 2 3
3 3 4 5

Output

possible

Input

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

Output

impossible

Note

In the first sample, a possible choice for the values of the a_i is 3, 4, 3, 5, 2. On the first day, Dora buys the integers 3, 4 and 3, whose LCM is 12, while Swiper buys integers 5 and 2, whose LCM is 10. On the second day, Dora buys 3, 5 and 2, whose LCM is 30, and Swiper buys integers 3 and 4, whose LCM is 12.

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

s = [0] * m

for w in range(m):
    for i in list(map(int, input().split()))[1:]:
        s[w] |= 1 << i

for i in s:
    for j in s:
        if not (i & j):
            print('impossible')
            exit(0)

print('possible')
```


1185_C1. Exam in BerSU (easy version)

The only difference between easy and hard versions is constraints.

A session has begun at Beland State University. Many students are taking exams.

Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:

  * The i-th student randomly chooses a ticket.
  * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
  * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.

Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

The duration of the whole exam for all students is M minutes (max t_i ≤ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.

For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.

For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.

Input

The first line of the input contains two integers n and M (1 ≤ n ≤ 100, 1 ≤ M ≤ 100) — the number of students and the total duration of the exam in minutes, respectively.

The second line of the input contains n integers t_i (1 ≤ t_i ≤ 100) — time in minutes that i-th student spends to answer to a ticket.

It's guaranteed that all values of t_i are not greater than M.

Output

Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.

Examples

Input

7 15
1 2 3 4 5 6 7

Output

0 0 0 0 0 2 3

Input

5 100
80 40 40 40 60

Output

0 1 1 2 3

Note

The explanation for the example 1.

Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.

In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).

In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).

```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * 101
curr = 0
for i in range(n):
    tm = m - a[i]
    ans = 0
    for j in range(1, 101):
        tmp = int(tm / j)
        if tmp >= cnt[j]:
            tm -= cnt[j] * j
            ans += cnt[j]
        else:
            tm -= tmp * j
            ans += tmp
    print(i - ans, end=' ')
    cnt[a[i]] += 1

```


1203_F2. Complete the Projects (hard version)

The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.

Polycarp is a very famous freelancer. His current rating is r units.

Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.

Polycarp can choose the order in which he completes projects. Furthermore, he can even skip some projects altogether.

To gain more experience (and money, of course) Polycarp wants to choose the subset of projects having maximum possible size and the order in which he will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.

Your task is to calculate the maximum possible size of such subset of projects.

Input

The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.

The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.

Output

Print one integer — the size of the maximum possible subset (possibly, empty) of projects Polycarp can choose.

Examples

Input

3 4
4 6
10 -2
8 -1

Output

3

Input

5 20
45 -6
34 -15
10 34
1 27
40 -45

Output

5

Input

3 2
300 -300
1 299
1 123

Output

3

```python
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
import math
import copy

#T = int(input())
#N = int(input())
#print(N)
N,r = [int(x) for x in stdin.readline().split()]
#arr = [int(x) for x in stdin.readline().split()]

visited = [0]*N

a = [0]*N
b = [0]*N

pos = 0

dp = {}

for i in range(N):
    arr = [int(x) for x in stdin.readline().split()]
    a[i] = arr[0]
    b[i] = arr[1]

    if b[i]>=0:
        pos += 1

valid = 0
for i in range(pos):
    idx = -1
    start = 0
    gain = -50000
    for j in range(N):
        # find available and largest gain
        # if gain tie, find largest start r
        if visited[j]==1 or b[j]<0:
            continue

        if b[j]>gain and r>=a[j]:
            gain = b[j]
            idx = j
            start = a[j]
        elif b[j]==gain and r>=a[j]:
            if a[j]>start:
                idx = j
                start = a[j]

    if idx==-1:
        break
    else:
        visited[idx] = 1
        r += b[idx]
        valid = i+1
        #print(idx,r)

dp[r] = valid
tmp = []
for i in range(N):
    if visited[i]==1 or b[i]>=0:
        continue
    tmp.append((a[i],b[i],i))

tmp.sort(key=lambda e: (e[0]+e[1],e[0]),reverse=True)

#print(dp)
for i in range(len(tmp)):
    dp_tmp = copy.deepcopy(dp)

    for threshold in dp:
        if threshold>=tmp[i][0]:
            new_r = threshold + tmp[i][1]
            if new_r in dp_tmp:
                dp_tmp[new_r] = max(dp[new_r],dp[threshold]+1)
            else:
                dp_tmp[new_r] = dp[threshold]+1

    #print(dp_tmp)
    dp = dp_tmp

res = 0
#print(dp)
for key in dp:
    if key>=0:
        res = max(res,dp[key])

print(res)

```


1220_E. Tourism

Alex decided to go on a touristic trip over the country.

For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex.

Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u.

Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.

Input

First line of input contains two integers n and m, (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ 2 ⋅ 10^5) which are numbers of cities and roads in the country.

Second line contains n integers w_1, w_2, …, w_n (0 ≤ w_i ≤ 10^9) which are scores of all cities.

The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≤ u, v ≤ n) which are cities connected by this road.

It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads.

The last line contains single integer s (1 ≤ s ≤ n), which is the number of the initial city.

Output

Output single integer which is the maximum possible sum of scores of visited cities.

Examples

Input

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

Output

27

Input

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

Output

61

```python
from collections import defaultdict

def get_neighbors(edges):
    neighbors = defaultdict(set, {})
    for v1, v2 in edges:
        neighbors[v1].add(v2)
        neighbors[v2].add(v1)

    return dict(neighbors)

def get_component(neighbors_map, root):
    if root not in neighbors_map:
        return {root}

    horizon = set(neighbors_map[root])
    component = {root}

    while horizon:
        new_node = horizon.pop()
        if new_node in component:
            continue

        component.add(new_node)
        new_neighbors = neighbors_map[new_node].difference(component)
        horizon |= new_neighbors

    return component

def fn(weights, edges, root):
    neihgbors_map = get_neighbors(edges)
    if root not in neihgbors_map:
        return weights[root]

    first_component = get_component(neihgbors_map, root)

    neihgbors_map = {k: v for k, v in neihgbors_map.items() if k in first_component}
    degrees = {}
    leaves = []
    for n, neigh in neihgbors_map.items():
        degrees[n] = len(neigh)
        if len(neigh) == 1 and n != root:
            leaves.append(n)

    extra_values = defaultdict(int, {})
    max_extra = 0
    removed_set = set()
    while leaves:
        leaf = leaves.pop()
        value = weights[leaf] + extra_values[leaf]
        parent = neihgbors_map.pop(leaf).pop()
        neihgbors_map[parent].remove(leaf)
        degrees[parent] -= 1
        if degrees[parent] == 1 and parent != root:
            leaves.append(parent)

        mm = max(extra_values[parent], value)
        extra_values[parent] = mm
        max_extra = max(mm, max_extra)
        removed_set.add(leaf)

    return sum(weights[n] for n in neihgbors_map) + max_extra

def print_answer(source):
    n, m = map(int, source().split())
    weights = list(map(int, source().split()))
    edges = [[int(k) - 1 for k in source().split()] for _ in range(m)]
    root = int(source()) - 1

    print(fn(weights, edges, root))

print_answer(input)

if False:
    from string_source import string_source

    print_answer(string_source("""3 2
1 1335 2
2 1
3 2
2"""))

    from string_source import string_source
    print_answer(string_source("""1 0
1000000000
1"""))

    print_answer(string_source("""10 12
    1 7 1 9 3 3 6 30 1 10
    1 2
    1 3
    3 5
    5 7
    2 3
    5 4
    6 9
    4 6
    3 7
    6 8
    9 4
    9 10
    6"""))

    print_answer(string_source(
            """5 7
    2 2 8 6 9
    1 2
    1 3
    2 4
    3 2
    4 5
    2 5
    1 5
    2"""))

    source = string_source("""3 2
1 1335 2
2 1
3 2
2""")
    n, m = map(int, source().split())
    weights = list(map(int, source().split()))
    edges = [[int(k) - 1 for k in source().split()] for _ in range(m)]
    root = int(source())

    fn(weights, edges, root)

    from graphviz import Graph

    dot = Graph(format="png", name="xx", filename=f"_files/temp/graph.png")

    for idx, w in enumerate(weights):
        dot.node(str(idx), label=f"{idx} - {w}")

    for s,e in edges:
        dot.edge(str(s),str(e))

    dot.view(cleanup=True)

    sum(weights)

```


1246_A. p-binary

Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binary numbers of the form 2^x + p, where x is a non-negative integer.

For example, some -9-binary ("minus nine" binary) numbers are: -8 (minus eight), 7 and 1015 (-8=2^0-9, 7=2^4-9, 1015=2^{10}-9).

The boys now use p-binary numbers to represent everything. They now face a problem: given a positive integer n, what's the smallest number of p-binary numbers (not necessarily distinct) they need to represent n as their sum? It may be possible that representation is impossible altogether. Help them solve this problem.

For example, if p=0 we can represent 7 as 2^0 + 2^1 + 2^2.

And if p=-9 we can represent 7 as one number (2^4-9).

Note that negative p-binary numbers are allowed to be in the sum (see the Notes section for an example).

Input

The only line contains two integers n and p (1 ≤ n ≤ 10^9, -1000 ≤ p ≤ 1000).

Output

If it is impossible to represent n as the sum of any number of p-binary numbers, print a single integer -1. Otherwise, print the smallest possible number of summands.

Examples

Input

24 0

Output

2

Input

24 1

Output

3

Input

24 -1

Output

4

Input

4 -7

Output

2

Input

1 1

Output

-1

Note

0-binary numbers are just regular binary powers, thus in the first sample case we can represent 24 = (2^4 + 0) + (2^3 + 0).

In the second sample case, we can represent 24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1).

In the third sample case, we can represent 24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1). Note that repeated summands are allowed.

In the fourth sample case, we can represent 4 = (2^4 - 7) + (2^1 - 7). Note that the second summand is negative, which is allowed.

In the fifth sample case, no representation is possible.

```python
n,p=map(int,input().split())
#print("{0:b}".format(n).count('1'))
t=0
while (("{0:b}".format(n).count('1'))>t or n<t) and n>=0:
    t+=1
    n-=p
if n<0:
    print(-1)
else:
    print(t)

```


1265_E. Beautiful Mirrors

Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability (p_i)/(100) for all 1 ≤ i ≤ n.

Creatnx asks the mirrors one by one, starting from the 1-st mirror. Every day, if he asks i-th mirror, there are two possibilities:

  * The i-th mirror tells Creatnx that he is beautiful. In this case, if i = n Creatnx will stop and become happy, otherwise he will continue asking the i+1-th mirror next day;
  * In the other case, Creatnx will feel upset. The next day, Creatnx will start asking from the 1-st mirror again.

You need to calculate [the expected number](https://en.wikipedia.org/wiki/Expected_value) of days until Creatnx becomes happy.

This number should be found by modulo 998244353. Formally, let M = 998244353. It can be shown that the answer can be expressed as an irreducible fraction p/q, where p and q are integers and q not ≡ 0 \pmod{M}. Output the integer equal to p ⋅ q^{-1} mod M. In other words, output such an integer x that 0 ≤ x < M and x ⋅ q ≡ p \pmod{M}.

Input

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

The second line contains n integers p_1, p_2, …, p_n (1 ≤ p_i ≤ 100).

Output

Print the answer modulo 998244353 in a single line.

Examples

Input

1
50

Output

2

Input

3
10 20 50

Output

112

Note

In the first test, there is only one mirror and it tells, that Creatnx is beautiful with probability 1/2. So, the expected number of days until Creatnx becomes happy is 2.

```python
N = int(input())
P = list(map(int, input().split()))
mod = 998244353

p = 0
q = 1
for i in range(N):
    p, q = (100 * (p+q)) % mod, (P[i] * q) % mod

print((p * pow(q, mod-2, mod))%mod)

```


1287_A. Angry Students

It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.

Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":

  * "A" corresponds to an angry student
  * "P" corresponds to a patient student

Such string describes the row from the last to the first student.

Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index i in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+1 (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.

<image>

Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.

Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.

Input

The first line contains a single integer t — the number of groups of students (1 ≤ t ≤ 100). The following 2t lines contain descriptions of groups of students.

The description of the group starts with an integer k_i (1 ≤ k_i ≤ 100) — the number of students in the group, followed by a string s_i, consisting of k_i letters "A" and "P", which describes the i-th group of students.

Output

For every group output single integer — the last moment a student becomes angry.

Examples

Input

1
4
PPAP

Output

1

Input

3
12
APPAPPPAPPPP
3
AAP
3
PPA

Output

4
1
0

Note

In the first test, after 1 minute the state of students becomes PPAA. After that, no new angry students will appear.

In the second tets, state of students in the first group is:

  * after 1 minute — AAPAAPPAAPPP
  * after 2 minutes — AAAAAAPAAAPP
  * after 3 minutes — AAAAAAAAAAAP
  * after 4 minutes all 12 students are angry

In the second group after 1 minute, all students are angry.

```python
n=int(input())
for i in range(n):
	m=int(input())
	l=list(input())
	p=[]
	c=0
	r=len(l)
	for i in range(r):
		if l[i]=="P":
			c+=1
			if i==r-1:
				p.append(c)
		if l[i]=="A":
			p.append(c)
			c=0
	if len(p)!=1:
		if p[0]==0:
			print(max(p))
		else:
			p.pop(0)
			print(max(p))
	else:
		print(0)
```


1307_A. Cow and Haybales

The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of n haybale piles on the farm. The i-th pile contains a_i haybales.

However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adjacent pile. Formally, in one day she can choose any two indices i and j (1 ≤ i, j ≤ n) such that |i-j|=1 and a_i>0 and apply a_i = a_i - 1, a_j = a_j + 1. She may also decide to not do anything on some days because she is lazy.

Bessie wants to maximize the number of haybales in pile 1 (i.e. to maximize a_1), and she only has d days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile 1 if she acts optimally!

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 100) — the number of test cases. Next 2t lines contain a description of test cases — two lines per test case.

The first line of each test case contains integers n and d (1 ≤ n,d ≤ 100) — the number of haybale piles and the number of days, respectively.

The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 100) — the number of haybales in each pile.

Output

For each test case, output one integer: the maximum number of haybales that may be in pile 1 after d days if Bessie acts optimally.

Example

Input

3
4 5
1 0 3 2
2 2
100 1
1 8
0

Output

3
101
0

Note

In the first test case of the sample, this is one possible way Bessie can end up with 3 haybales in pile 1:

  * On day one, move a haybale from pile 3 to pile 2
  * On day two, move a haybale from pile 3 to pile 2
  * On day three, move a haybale from pile 2 to pile 1
  * On day four, move a haybale from pile 2 to pile 1
  * On day five, do nothing

In the second test case of the sample, Bessie can do nothing on the first day and move a haybale from pile 2 to pile 1 on the second day.

```python
t = int (input ())
ans = []

for i in range (t):
    day = 0

    p = list (map (int, input ().split ()))
    n, d = p #

    flag = False

    num = list (map (int, input ().split ()))

    for k in range (1, n) :

        while (num[k] > 0 and day + k <= d) :
            num[0] += 1
            num[k] -= 1
            day += k
        #    print ("DEBUG : ", k, day)
            if (day + k > d) :
                flag = True
                break
        if (flag) :
            break

    ans.append (num[0])

for j in ans :
    print (j)

```


1330_A. Dreamoon and Ranking Collection

Dreamoon is a big fan of the Codeforces contests.

One day, he claimed that he will collect all the places from 1 to 54 after two more rated contests. It's amazing!

Based on this, you come up with the following problem:

There is a person who participated in n Codeforces rounds. His place in the first round is a_1, his place in the second round is a_2, ..., his place in the n-th round is a_n.

You are given a positive non-zero integer x.

Please, find the largest v such that this person can collect all the places from 1 to v after x more rated contests.

In other words, you need to find the largest v, such that it is possible, that after x more rated contests, for each 1 ≤ i ≤ v, there will exist a contest where this person took the i-th place.

For example, if n=6, x=2 and a=[3,1,1,5,7,10] then answer is v=5, because if on the next two contest he will take places 2 and 4, then he will collect all places from 1 to 5, so it is possible to get v=5.

Input

The first line contains an integer t (1 ≤ t ≤ 5) denoting the number of test cases in the input.

Each test case contains two lines. The first line contains two integers n, x (1 ≤ n, x ≤ 100). The second line contains n positive non-zero integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 100).

Output

For each test case print one line containing the largest v, such that it is possible that after x other contests, for each 1 ≤ i ≤ v, there will exist a contest where this person took the i-th place.

Example

Input

5
6 2
3 1 1 5 7 10
1 100
100
11 1
1 1 1 1 1 1 1 1 1 1 1
1 1
1
4 57
80 60 40 20

Output

5
101
2
2
60

Note

The first test case is described in the statement.

In the second test case, the person has one hundred future contests, so he can take place 1,2,…,99 and place 101 on them in some order, to collect places 1,2,…,101.

```python
cycles = int(input())

def find_v(x, places):
    places = set(places)
    v = 0
    i = 1
    while True:
        if i in places:
            v = i
        elif x > 0:
            v = i
            x -= 1
        else:
            break
        i += 1
    return v

results = []

for cycle in range(cycles):
    n, x = map(int, input().split())
    places = map(int, input().split())
    results.append(find_v(x, places))

for r in results:
    print(r)

```


1350_A. Orac and Factors

Orac is studying number theory, and he is interested in the properties of divisors.

For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that a⋅ c=b.

For n ≥ 2, we will denote as f(n) the smallest positive divisor of n, except 1.

For example, f(7)=7,f(10)=2,f(35)=5.

For the fixed integer n, Orac decided to add f(n) to n.

For example, if he had an integer n=5, the new value of n will be equal to 10. And if he had an integer n=6, n will be changed to 8.

Orac loved it so much, so he decided to repeat this operation several times.

Now, for two positive integers n and k, Orac asked you to add f(n) to n exactly k times (note that n will change after each operation, so f(n) may change too) and tell him the final value of n.

For example, if Orac gives you n=5 and k=2, at first you should add f(5)=5 to n=5, so your new value of n will be equal to n=10, after that, you should add f(10)=2 to 10, so your new (and the final!) value of n will be equal to 12.

Orac may ask you these queries many times.

Input

The first line of the input is a single integer t\ (1≤ t≤ 100): the number of times that Orac will ask you.

Each of the next t lines contains two positive integers n,k\ (2≤ n≤ 10^6, 1≤ k≤ 10^9), corresponding to a query by Orac.

It is guaranteed that the total sum of n is at most 10^6.

Output

Print t lines, the i-th of them should contain the final value of n in the i-th query by Orac.

Example

Input

3
5 1
8 2
3 4

Output

10
12
12

Note

In the first query, n=5 and k=1. The divisors of 5 are 1 and 5, the smallest one except 1 is 5. Therefore, the only operation adds f(5)=5 to 5, and the result is 10.

In the second query, n=8 and k=2. The divisors of 8 are 1,2,4,8, where the smallest one except 1 is 2, then after one operation 8 turns into 8+(f(8)=2)=10. The divisors of 10 are 1,2,5,10, where the smallest one except 1 is 2, therefore the answer is 10+(f(10)=2)=12.

In the third query, n is changed as follows: 3 → 6 → 8 → 10 → 12.

```python
t = int(input())
for _ in range(t):
  n, k = map(int, input().split())
  ans = n
  for i in range(2, n + 1):
    if n % i == 0:
      ans += i
      break
  ans += 2 * (k - 1)
  print(ans)
```


1370_D. Odd-Even Subsequence

Ashish has an array a of size n.

A subsequence of a is defined as a sequence that can be obtained from a by deleting some elements (possibly none), without changing the order of the remaining elements.

Consider a subsequence s of a. He defines the cost of s as the minimum between:

  * The maximum among all elements at odd indices of s.
  * The maximum among all elements at even indices of s.

Note that the index of an element is its index in s, rather than its index in a. The positions are numbered from 1. So, the cost of s is equal to min(max(s_1, s_3, s_5, …), max(s_2, s_4, s_6, …)).

For example, the cost of \{7, 5, 6\} is min( max(7, 6), max(5) ) = min(7, 5) = 5.

Help him find the minimum cost of a subsequence of size k.

Input

The first line contains two integers n and k (2 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the size of the array a and the size of the subsequence.

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

Output

Output a single integer — the minimum cost of a subsequence of size k.

Examples

Input

4 2
1 2 3 4

Output

1

Input

4 3
1 2 3 4

Output

2

Input

5 3
5 3 4 2 6

Output

2

Input

6 4
5 3 50 2 4 5

Output

3

Note

In the first test, consider the subsequence s = \{1, 3\}. Here the cost is equal to min(max(1), max(3)) = 1.

In the second test, consider the subsequence s = \{1, 2, 4\}. Here the cost is equal to min(max(1, 4), max(2)) = 2.

In the fourth test, consider the subsequence s = \{3, 50, 2, 4\}. Here the cost is equal to min(max(3, 2), max(50, 4)) = 3.

```python
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n,k = MI()
a = LI()
def check(mid,isEven):
	ans = 0
	for i in range(n):
		if isEven or a[i]<=mid:
			ans+=1
			isEven = 1-isEven
	return ans>=k

l = 0
r = max(a)
ans = r
while l<r:
	mid = (l+r)//2
	if check(mid,1) or check(mid,0):
		r = mid
		ans = min(ans,mid)
	else:
		l = mid+1
print(ans)

```


1417_E. XOR Inverse

You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)).

An inversion in the b array is a pair of integers i and j such that 1 ≤ i < j ≤ n and b_i > b_j.

You should choose x in such a way that the number of inversions in b is minimized. If there are several options for x — output the smallest one.

Input

First line contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of elements in a.

Second line contains n space-separated integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.

Output

Output two integers: the minimum possible number of inversions in b, and the minimum possible value of x, which achieves those number of inversions.

Examples

Input

4
0 1 3 2

Output

1 0

Input

9
10 7 9 10 7 5 5 3 5

Output

4 14

Input

3
8 10 3

Output

0 8

Note

In the first sample it is optimal to leave the array as it is by choosing x = 0.

In the second sample the selection of x = 14 results in b: [4, 9, 7, 4, 9, 11, 11, 13, 11]. It has 4 inversions:

  * i = 2, j = 3;
  * i = 2, j = 4;
  * i = 3, j = 4;
  * i = 8, j = 9.

In the third sample the selection of x = 8 results in b: [0, 2, 11]. It has no inversions.

```python
import os
from sys import stdin, stdout

class Input:
    def __init__(self):
        self.lines = stdin.readlines()
        self.idx = 0

    def line(self):
        try:
            return self.lines[self.idx].strip()
        finally:
            self.idx += 1

    def array(self, sep = ' ', cast = int):
        return list(map(cast, self.line().split(sep = sep)))

    def known_tests(self):
        num_of_cases, = self.array()

        for case in range(num_of_cases):
            yield self

    def unknown_tests(self):
        while self.idx < len(self.lines):
            yield self

def problem_solver():
    oo = float('Inf')
    mem = None

    def backtrack(a, L, R, B = 31):
        if B < 0 or L == R:
            return

        mask = 1 << B
        l = L
        r = L
        inv0 = 0
        inv1 = 0
        zero = 0
        one = 0
        la = []
        ra = []
        while l < R:
            while r < R and (a[l] & mask) == (a[r] & mask):
                if (a[r] & mask):
                    la.append(a[r])
                    one += 1
                    inv1 += zero
                else:
                    ra.append(a[r])
                    zero += 1
                    inv0 += one

                r += 1

            l = r

        backtrack(la, 0, len(la), B - 1)
        backtrack(ra, 0, len(ra), B - 1)

        mem[B][0] += inv0
        mem[B][1] += inv1

    '''

    '''
    def solver(inpt):
        nonlocal mem

        n, = inpt.array()
        a = inpt.array()

        mem = [[0, 0] for i in range(32)]

        backtrack(a, 0, n)

        inv = 0
        x = 0

        for b in range(32):
            if mem[b][0] <= mem[b][1]:
                inv += mem[b][0]
            else:
                inv += mem[b][1]
                x |= 1 << b

        print(inv, x)

    '''Returns solver'''
    return solver

try:
    solver = problem_solver()
    for tc in Input().unknown_tests():
        solver(tc)
except Exception as e:
    import traceback
    traceback.print_exc(file=stdout)
```


1434_C. Solo mid Oracle

Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of every second, for exactly c seconds, starting one second after the ability is used. That means that if the ability is used at time t, the enemy's health decreases by a at time t, and then increases by b at time points t + 1, t + 2, ..., t + c due to this ability.

The ability has a cooldown of d seconds, i. e. if Meka-Naruto uses it at time moment t, next time he can use it is the time t + d. Please note that he can only use the ability at integer points in time, so all changes to the enemy's health also occur at integer times only.

The effects from different uses of the ability may stack with each other; that is, the enemy which is currently under k spells gets k⋅ b amount of heal this time. Also, if several health changes occur at the same moment, they are all counted at once.

Now Meka-Naruto wonders if he can kill the enemy by just using the ability each time he can (that is, every d seconds). The enemy is killed if their health points become 0 or less. Assume that the enemy's health is not affected in any way other than by Meka-Naruto's character ability. What is the maximal number of health points the enemy can have so that Meka-Naruto is able to kill them?

Input

The first line contains an integer t (1≤ t≤ 10^5) standing for the number of testcases.

Each test case is described with one line containing four numbers a, b, c and d (1≤ a, b, c, d≤ 10^6) denoting the amount of instant damage, the amount of heal per second, the number of heals and the ability cooldown, respectively.

Output

For each testcase in a separate line print -1 if the skill can kill an enemy hero with an arbitrary number of health points, otherwise print the maximal number of health points of the enemy that can be killed.

Example

Input

7
1 1 1 1
2 2 2 2
1 2 3 4
4 3 2 1
228 21 11 3
239 21 11 3
1000000 1 1000000 1

Output

1
2
1
5
534
-1
500000500000

Note

In the first test case of the example each unit of damage is cancelled in a second, so Meka-Naruto cannot deal more than 1 damage.

In the fourth test case of the example the enemy gets:

  * 4 damage (1-st spell cast) at time 0;
  * 4 damage (2-nd spell cast) and 3 heal (1-st spell cast) at time 1 (the total of 5 damage to the initial health);
  * 4 damage (3-nd spell cast) and 6 heal (1-st and 2-nd spell casts) at time 2 (the total of 3 damage to the initial health);
  * and so on.

One can prove that there is no time where the enemy gets the total of 6 damage or more, so the answer is 5. Please note how the health is recalculated: for example, 8-health enemy would not die at time 1, as if we first subtracted 4 damage from his health and then considered him dead, before adding 3 heal.

In the sixth test case an arbitrarily healthy enemy can be killed in a sufficient amount of time.

In the seventh test case the answer does not fit into a 32-bit integer type.

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

def solve_case():
    a, b, c, d = [int(x) for x in input().split()]
    if a > b * c:
        print(-1)
    else:
        k = a // (b * d)
        print(a * (k + 1) - k * (k + 1) // 2 * b * d)

def main():
    for _ in range(int(input())):
        solve_case()

main()
```


145_A. Lucky Conversion

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

Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types:

  * replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);
  * swap any pair of digits in string a.

Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task.

Input

The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.

Output

Print on the single line the single number — the minimum number of operations needed to convert string a into string b.

Examples

Input

47
74

Output

1

Input

774
744

Output

1

Input

777
444

Output

3

Note

In the first sample it is enough simply to swap the first and the second digit.

In the second sample we should replace the second digit with its opposite.

In the third number we should replace all three digits with their opposites.

```python
a,b=input(),input();c,d=0,0
for i in range(len(a)):
    if a[i]!=b[i]:
        if a[i]=='4': c+=1
        else: d+=1
print(max(c,d))
```


1485_C. Floor and Mod

A pair of positive integers (a,b) is called special if ⌊ a/b ⌋ = a mod b. Here, ⌊ a/b ⌋ is the result of the integer division between a and b, while a mod b is its remainder.

You are given two integers x and y. Find the number of special pairs (a,b) such that 1≤ a ≤ x and 1 ≤ b ≤ y.

Input

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

The only line of the description of each test case contains two integers x, y (1 ≤ x,y ≤ 10^9).

Output

For each test case print the answer on a single line.

Example

Input

9
3 4
2 100
4 3
50 3
12 4
69 420
12345 6789
123456 789
12345678 9

Output

1
0
2
3
5
141
53384
160909
36

Note

In the first test case, the only special pair is (3, 2).

In the second test case, there are no special pairs.

In the third test case, there are two special pairs: (3, 2) and (4, 3).

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

t = int(input())
for f in range(t):
    x,y = map(int,input().split())
    ok = 1
    ng = y+1
    while ng-ok > 1:
        c = (ng+ok)//2
        if c*c-1 <= x:
            ok = c
        else:
            ng = c
    ans = 0
    ans += (ok*(ok-1))//2

    if ok != y:
        divisor = 1

        while x//divisor > ng:
            ans += min(x//divisor-1,y)-ng+1
            divisor += 1
    print(ans)

```


150_A. Win or Freeze

You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.

The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.

Input

The first line contains the only integer q (1 ≤ q ≤ 1013).

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

Output

In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.

Examples

Input

6

Output

2

Input

30

Output

1
6

Input

1

Output

1
0

Note

Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.

```python
n = int(input())
p = n
arr = []
while p%2==0:
    arr.append(2)
    p = p//2
x = int(p**0.5)+1
for i in range(3,x,2):
    while p%i==0:
        arr.append(i)
        p = p//i
if p>2:
    arr.append(p)
if n==1 or len(arr)==1:
    print(1)
    print(0)
elif len(arr)==2:
    print(2)
else:
    x = arr[0]*arr[1]
    print(1)
    print(x)
```


1535_E. Gold Transfer

You are given a rooted tree. Each vertex contains a_i tons of gold, which costs c_i per one ton. Initially, the tree consists only a root numbered 0 with a_0 tons of gold and price c_0 per ton.

There are q queries. Each query has one of two types:

  1. Add vertex i (where i is an index of query) as a son to some vertex p_i; vertex i will have a_i tons of gold with c_i per ton. It's guaranteed that c_i > c_{p_i}.
  2. For a given vertex v_i consider the simple path from v_i to the root. We need to purchase w_i tons of gold from vertices on this path, spending the minimum amount of money. If there isn't enough gold on the path, we buy all we can.

If we buy x tons of gold in some vertex v the remaining amount of gold in it decreases by x (of course, we can't buy more gold that vertex has at the moment). For each query of the second type, calculate the resulting amount of gold we bought and the amount of money we should spend.

Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query, so don't forget to flush output after printing answers. You can use functions like fflush(stdout) in C++ and BufferedWriter.flush in Java or similar after each writing in your program. In standard (if you don't tweak I/O), endl flushes cout in C++ and System.out.println in Java (or println in Kotlin) makes automatic flush as well.

Input

The first line contains three integers q, a_0 and c_0 (1 ≤ q ≤ 3 ⋅ 10^5; 1 ≤ a_0, c_0 < 10^6) — the number of queries, the amount of gold in the root and its price.

Next q lines contain descriptions of queries; The i-th query has one of two types:

  * "1 p_i a_i c_i" (0 ≤ p_i < i; 1 ≤ a_i, c_i < 10^6): add vertex i as a son to vertex p_i. The vertex i will have a_i tons of gold with price c_i per one ton. It's guaranteed that p_i exists and c_i > c_{p_i}.
  * "2 v_i w_i" (0 ≤ v_i < i; 1 ≤ w_i < 10^6): buy w_i tons of gold from vertices on path from v_i to 0 spending the minimum amount of money. If there isn't enough gold, we buy as much as we can. It's guaranteed that vertex v_i exist.

It's guaranteed that there is at least one query of the second type.

Output

For each query of the second type, print the resulting amount of gold we bought and the minimum amount of money we should spend.

Example

Input

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

Output

2 4
4 10
1 3

Note

Explanation of the sample:

At the first query, the tree consist of root, so we purchase 2 tons of gold and pay 2 ⋅ 2 = 4. 3 tons remain in the root.

At the second query, we add vertex 2 as a son of vertex 0. Vertex 2 now has 3 tons of gold with price 4 per one ton.

At the third query, a path from 2 to 0 consists of only vertices 0 and 2 and since c_0 < c_2 we buy 3 remaining tons of gold in vertex 0 and 1 ton in vertex 2. So we bought 3 + 1 = 4 tons and paid 3 ⋅ 2 + 1 ⋅ 4 = 10. Now, in vertex 0 no gold left and 2 tons of gold remain in vertex 2.

At the fourth query, we add vertex 4 as a son of vertex 0. Vertex 4 now has 1 ton of gold with price 3.

At the fifth query, a path from 4 to 0 consists of only vertices 0 and 4. But since no gold left in vertex 0 and only 1 ton is in vertex 4, we buy 1 ton of gold in vertex 4 and spend 1 ⋅ 3 = 3. Now, in vertex 4 no gold left.

```python
import os
import sys

input = sys.stdin.buffer.readline

def main():
    (Q, A0, C0) = [int(x) for x in input().split()]

    N = Q + 2

    A = [0] * N
    C = [0] * N
    P = [0] * N
    pref = [0] * N  # pref[u] is sum of A from root to u (inclusive, immutable)
    anc = [None for i in range(N)]  # anc[u][k] is (2**k)-th ancestor of u
    anc[-1] = [-1] * 20

    root = 0
    A[root] = A0
    C[root] = C0
    P[root] = -1
    pref[root] = A0
    anc[root] = [-1] * 20

    def buildJumps(u, parent):
        jumps = [0] * 20
        jumps[0] = parent
        for i in range(1, 20):
            jumps[i] = anc[jumps[i - 1]][i - 1]
        anc[u] = jumps

    def getAncestor(u, k):
        # Binary lifting, k-th ancestor of u
        for i in reversed(range(20)):
            if k & (1 << i):
                u = anc[u][i]
        return u

    def getLast(u, f):
        # Returns highest node on the path from u to root where f(node) is true.
        # Assumes f is monotonic and goes from true to false. If all false, returns u.
        for i in reversed(range(20)):
            if f(anc[u][i]):
                u = anc[u][i]
        return u

    for i in range(1, Q + 1):
        query = [int(x) for x in input().split()]
        if query[0] == 1:
            _, p, A[i], C[i] = query
            P[i] = p
            pref[i] = pref[p] + A[i]
            buildJumps(i, p)
        else:
            assert query[0] == 2
            _, v, want = query

            gold = 0
            spend = 0
            if False:
                if A[v] != 0:
                    hi = getLast(v, lambda node: A[node])
                    target = want + (pref[hi] - A[hi])
                    lo = getLast(v, lambda node: pref[node] >= target)

                    path = [lo]
                    while path[-1] != hi:
                        path.append(P[path[-1]])
                    for u in reversed(path):
                        take = min(want, A[u])
                        A[u] -= take
                        gold += take
                        spend += C[u] * take
                        want -= take

            else:
                while A[v] != 0 and want:
                    u = getLast(v, lambda node: A[node] != 0)
                    take = min(want, A[u])
                    A[u] -= take
                    gold += take
                    spend += C[u] * take
                    want -= take

            os.write(1, b"%d %d\n" % (gold, spend))

if __name__ == "__main__":
    main()

```


182_D. Common Divisors

Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.

String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string "abab" has two divisors — "ab" and "abab".

Now Vasya wants to write a program that calculates the number of common divisors of two strings. Please help him.

Input

The first input line contains a non-empty string s1.

The second input line contains a non-empty string s2.

Lengths of strings s1 and s2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters.

Output

Print the number of common divisors of strings s1 and s2.

Examples

Input

abcdabcd
abcdabcdabcdabcd

Output

2

Input

aaa
aa

Output

1

Note

In first sample the common divisors are strings "abcd" and "abcdabcd".

In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa".

```python
s1=input()
s2=input()
n=len(s1)
m=len(s2)
cnt=0
from math import gcd
g=gcd(n,m)
for i in range(g):
    #curr=s1[:i+1]
    if n%(i+1)==0 and m%(i+1)==0:
        if s1[:i+1]*(n//(i+1))==s1 and s1[:i+1]*(m//(i+1))==s2:
            cnt+=1
print(cnt)
```


22_E. Scheme

To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third member, and so on; i.e. a person with index i got a person with index fi, to whom he has to call, if he learns the news. With time BolgenOS community members understood that their scheme doesn't work sometimes — there were cases when some members didn't learn the news at all. Now they want to supplement the scheme: they add into the scheme some instructions of type (xi, yi), which mean that person xi has to call person yi as well. What is the minimum amount of instructions that they need to add so, that at the end everyone learns the news, no matter who is the first to learn it?

Input

The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.

Output

In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.

Examples

Input

3
3 3 2

Output

1
3 1

Input

7
2 3 1 3 4 4 1

Output

3
2 5
2 6
3 7

```python
import sys

n = int(input())
g = [int(i) - 1 for i in sys.stdin.readline().split()]

def solve(n, g):
    vertex_id = [-1]*n
    current_id = 0

    cycle_starts = []
    cycle_starts_by_vertex = [-1]*n
    cycle_vertex_sample = []
    start_on_cycle = []

    cycle_index_by_ID = []

    for v in range(n):
        if vertex_id[v] != -1: continue

        current_vertex = v
        cycle_found = False
        while vertex_id[current_vertex] == -1:
            vertex_id[current_vertex] = current_id
            current_vertex = g[current_vertex]

            if vertex_id[current_vertex] == current_id:
                cycle_found = True
                # cycle_starts.append([v])
                cycle_vertex_sample.append(current_vertex)
                start_on_cycle.append(current_vertex == v)

        if not cycle_found:
            if cycle_starts_by_vertex[current_vertex] != -1:
                cycle_starts_by_vertex[v] = cycle_starts_by_vertex[current_vertex]
                cycle_starts_by_vertex[current_vertex] = -1
            cycle_index_by_ID.append(cycle_index_by_ID[vertex_id[current_vertex]])

            cycle = cycle_index_by_ID[-1]

            if start_on_cycle[cycle]:
                cycle_starts_by_vertex[cycle_vertex_sample[cycle]] = -1
                start_on_cycle[cycle] = False
                # cycle_starts[cycle] = []

            cycle_starts_by_vertex[v] = cycle

            # starts = cycle_starts[cycle]
            # for i in range(len(starts)):
            #     if starts[i] == current_vertex:
            #         starts[i] = v
            #         break
            # else:
            #     starts.append(v)

        else:
            cycle_starts_by_vertex[v] = len(cycle_vertex_sample) - 1
            cycle_index_by_ID.append(len(cycle_vertex_sample) - 1)
        current_id += 1

    cycle_starts = [[] for _ in range(len(cycle_vertex_sample))]
    for i in range(n):
        if cycle_starts_by_vertex[i] != -1:
            cycle_starts[cycle_starts_by_vertex[i]].append(i)

    expanded = []
    for i in range(len(cycle_vertex_sample)):
        v = cycle_vertex_sample[i]
        for u in cycle_starts[i]:
            expanded.append([v, u])

    if len(expanded) == 1 and expanded[0][0] == expanded[0][1]:
        print(0)
    else:
        ans = []
        for i in range(len(expanded)-1):
            v = expanded[i][0]
            u = expanded[i+1][1]
            ans.append('{0} {1}'.format(v+1, u+1))
        ans.append('{0} {1}'.format(expanded[-1][0] + 1, expanded[0][1] + 1))

        print(len(ans))
        print('\n'.join(ans))

solve(n, g)
```


255_D. Mr. Bender and Square

Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.

We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.

For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).

In how many seconds will Mr. Bender get happy?

Input

The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 109; 1 ≤ x, y ≤ n; c ≤ n2).

Output

In a single line print a single integer — the answer to the problem.

Examples

Input

6 4 3 1

Output

0

Input

9 3 8 10

Output

2

Note

Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. <image>.

```python
import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
sdata = lambda: list(ii())

def solve():
    n, x, y, c = idata()
    r = n ** 2
    l = -1
    while l + 1 < r:
        middle = (l + r) // 2
        ans = 1 + 2 * (middle + 1) * middle
        ans -= pow(middle - n + y, 2) if middle - n + y > 0 else 0
        ans -= pow(middle + 1 - y, 2) if middle + 1 - y > 0 else 0
        ans -= pow(middle - n + x, 2) if middle - n + x > 0 else 0
        ans -= pow(middle + 1 - x, 2) if middle + 1 - x > 0 else 0
        d = 1 + n - x + y
        if middle >= d:
            ans += (middle - d + 1) * (middle - d + 2) // 2
        d = 2 + 2 * n - y - x
        if middle >= d:
            ans += (middle - d + 1) * (middle - d + 2) // 2
        d = 1 + n - y + x
        if middle >= d:
            ans += (middle - d + 1) * (middle - d + 2) // 2
        d = x + y
        if middle >= d:
            ans += (middle - d + 1) * (middle - d + 2) // 2
        if ans >= c:
            r = middle
        else:
            l = middle
    print(r)
    return

for t in range(1):
    solve()
```


279_D. The Minimum Number of Variables

You've got a positive integer sequence a1, a2, ..., an. All numbers in the sequence are distinct. Let's fix the set of variables b1, b2, ..., bm. Initially each variable bi (1 ≤ i ≤ m) contains the value of zero. Consider the following sequence, consisting of n operations.

The first operation is assigning the value of a1 to some variable bx (1 ≤ x ≤ m). Each of the following n - 1 operations is assigning to some variable by the value that is equal to the sum of values that are stored in the variables bi and bj (1 ≤ i, j, y ≤ m). At that, the value that is assigned on the t-th operation, must equal at. For each operation numbers y, i, j are chosen anew.

Your task is to find the minimum number of variables m, such that those variables can help you perform the described sequence of operations.

Input

The first line contains integer n (1 ≤ n ≤ 23). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ak ≤ 109).

It is guaranteed that all numbers in the sequence are distinct.

Output

In a single line print a single number — the minimum number of variables m, such that those variables can help you perform the described sequence of operations.

If you cannot perform the sequence of operations at any m, print -1.

Examples

Input

5
1 2 3 6 8

Output

2

Input

3
3 6 5

Output

-1

Input

6
2 4 8 6 10 18

Output

3

Note

In the first sample, you can use two variables b1 and b2 to perform the following sequence of operations.

  1. b1 := 1;
  2. b2 := b1 + b1;
  3. b1 := b1 + b2;
  4. b1 := b1 + b1;
  5. b1 := b1 + b2.

```python
def Solve(x,B):
    if((X,x,B) in Mem):
        return Mem[(X,x,B)]
    if(len(B)>X):
        return False
    if(x==len(L)):
        return True
    if(Form(L[x],B)):
        A=list(B)
        for e in range(len(B)):
            r=A[e]
            A[e]=L[x]
            if(Solve(x+1,tuple(sorted(A)))):
                Mem[(X,x,B)]=True
                return True
            A[e]=r
        A+=[L[x]]
        if(Solve(x+1,tuple(sorted(A)))):
            Mem[(X,x,B)]=True
            return True
    Mem[(X,x,B)]=False
    return False

def Form(x,B):
    for i in range(len(B)):
        for j in range(i,len(B)):
            if(B[i]+B[j]==x):
                return True
    return False

n=int(input())
L=list(map(int,input().split()))
done=False
Mem={}
for X in range(1,n+1):
    if(Solve(1,(L[0],))):
        print(X)
        done=True
        break
if(not done):
    print(-1)

```


301_C. Yaroslav and Algorithm

Yaroslav likes algorithms. We'll describe one of his favorite algorithms.

  1. The algorithm receives a string as the input. We denote this input string as a.
  2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strings of length at most 7, consisting of digits and characters "?".
  3. At each iteration, the algorithm looks for a command with the minimum index i, such that si occurs in a as a substring. If this command is not found the algorithm terminates.
  4. Let's denote the number of the found command as k. In string a the first occurrence of the string sk is replaced by string wk. If the found command at that had form sk >> wk, then the algorithm continues its execution and proceeds to the next iteration. Otherwise, the algorithm terminates.
  5. The value of string a after algorithm termination is considered to be the output of the algorithm.

Yaroslav has a set of n positive integers, he needs to come up with his favorite algorithm that will increase each of the given numbers by one. More formally, if we consider each number as a string representing the decimal representation of the number, then being run on each of these strings separately, the algorithm should receive the output string that is a recording of the corresponding number increased by one.

Help Yaroslav.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the set. The next n lines contains one positive integer each. All the given numbers are less than 1025.

Output

Print the algorithm which can individually increase each number of the set. In the i-th line print the command number i without spaces.

Your algorithm will be launched for each of these numbers. The answer will be considered correct if:

  * Each line will a correct algorithm command (see the description in the problem statement).
  * The number of commands should not exceed 50.
  * The algorithm will increase each of the given numbers by one.
  * To get a respond, the algorithm will perform no more than 200 iterations for each number.

Examples

Input

2
10
79

Output

10<>11
79<>80


328_A. IQ Test

Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.

Arithmetic progression is a sequence a1, a1 + d, a1 + 2d, ..., a1 + (n - 1)d, where a1 and d are any numbers.

Geometric progression is a sequence b1, b2 = b1q, ..., bn = bn - 1q, where b1 ≠ 0, q ≠ 0, q ≠ 1.

Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.

Input

The first line contains exactly four integer numbers between 1 and 1000, inclusively.

Output

Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element.

Print 42 if the given sequence is not an arithmetic or geometric progression.

Examples

Input

836 624 412 200

Output

-12

Input

1 334 667 1000

Output

1333

Note

This problem contains very weak pretests!

```python
import sys
fin = sys.stdin

a = list(map(int, fin.readline().split()))

d = a[1] - a[0]

if a[2] - a[1] == a[3] - a[2] == d:
    print(a[3] + d)
else:
    d = a[1] / a[0]
    if a[2] / a[1] == a[3] / a[2] == d and d * a[3] == int(d * a[3]):
        print(int(d * a[3]))
    else:
        print(42)
```


34_B. Sale

Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.

Input

The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets.

Output

Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.

Examples

Input

5 3
-6 0 35 -2 4

Output

8

Input

4 2
7 0 0 -7

Output

7

```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(len(a)):
    if a[i] < 0:
        ans += a[i]
        m -= 1
    if m == 0:
        break
print(-1 * ans)
```


373_C. Counting Kangaroos is Fun

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

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

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

Input

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

Output

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

Examples

Input

8
2
5
7
6
9
8
4
2

Output

5

Input

8
9
1
6
2
6
5
8
3

Output

5

```python
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
# vsInput()

n=Int()
a=[]
for i in range(n): a.append(Int())

a.sort(reverse=True)

b=a[n//2:]
a=a[0:n//2]

# print(a)
# print(b)
# print()

i=0
j=0
ans=n

while(i<len(a) and j<len(b)):
    key=a[i]
    while(j<len(b) and key<2*b[j]):
        j+=1
    if(j!=len(b)):
        # print(key,b[j])
        ans-=1
    j+=1
    i+=1

print(ans)

```


418_A. Football

One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.

The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.

Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Examples

Input

3 1

Output

3
1 2
2 3
3 1

```python
n,k=map(int,input().split())
a=n*(n-1)//2
if(n*k>a):
    print(-1)
else:
    print(n*k)
    for i in range(1,n+1):
        for j in range(k):
            print(i,(i+j)%n+1)
```


466_E. Information Graph

There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place:

  * either employee y became the boss of employee x (at that, employee x didn't have a boss before);
  * or employee x gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive);
  * or comes a request of type "determine whether employee x signs certain documents".

Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of employees and the number of events.

Each of the next m lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event t (1 ≤ t ≤ 3).

  * If t = 1, then next follow two integers x and y (1 ≤ x, y ≤ n) — numbers of the company employees. It is guaranteed that employee x doesn't have the boss currently.
  * If t = 2, then next follow integer x (1 ≤ x ≤ n) — the number of the employee who got a document packet.
  * If t = 3, then next follow two integers x and i (1 ≤ x ≤ n; 1 ≤ i ≤ [number of packets that have already been given]) — the employee and the number of the document packet for which you need to find out information. The document packets are numbered started from 1 in the chronological order.

It is guaranteed that the input has at least one query of the third type.

Output

For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes.

Examples

Input

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

Output

YES
NO
YES

```python
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__

n, m = map(int, input().split())
ev = [tuple(map(int, input().split())) for _ in range(m)]

g = [[] for _ in range(n + 1)]
qry = [[] for _ in range(m + 1)]
roots = set(range(1, n + 1))
qcnt = 0
for e in ev:
	if e[0] == 1:
		g[e[2]].append(e[1])
		roots.remove(e[1])
	elif e[0] == 3:
		qry[e[2]].append((qcnt, e[1]))
		qcnt += 1

tin, tout = [0] * (n + 1), [0] * (n + 1)
st = [(u, 0) for u in roots]
time = 0
while st:
	u, w = st.pop()
	if w:
		tout[u] = time
		continue
	time += 1
	tin[u] = time
	st.append((u, 1))
	for v in g[u]:
		st.append((v, 0))

p = list(range(n + 1))
def find(x):
	if x != p[x]:
		p[x] = find(p[x])
	return p[x]

pcnt = 0
ans = [None] * qcnt
for e in ev:
	if e[0] == 1:
		p[find(e[1])] = find(e[2])
	elif e[0] == 2:
		pcnt += 1
		for qid, x in qry[pcnt]:
			ans[qid] = 'YES' if find(e[1]) == find(x) and tin[x] <= tin[e[1]] <= tout[x] else 'NO'

print(*ans, sep='\n')
```


48_C. The Race

Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.

So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α liters of petrol (α ≥ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers.

Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with α liters of petrol. Otherwise, he doesn't stop at the station and drives on.

For example, if α = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on.

You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage.

One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the α number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be.

Input

The first line contains an integer n (1 ≤ n ≤ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number α ≥ 10, to which such a succession of stops corresponds.

Output

Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique".

Examples

Input

3
1 2 4

Output

unique
5

Input

2
1 2

Output

not unique

Note

In the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4.

```python
eps=10**(-9)
mn=10
mx=100000000
n=int(input())
arr=list(map(int,input().split()))
for i in range(n):
    mn = max(mn,(arr[i]*10)/(i+1))
    mx = min(mx,((arr[i]+1)*10)/(i+1))
ans1=((n+1)*mn)//10
ans2=((n+1)*(mx-eps))//10
if ans2>ans1:
    print('not unique')
else:
    print('unique')
    print(int(ans1))

```


53_A. Autocomplete

Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.

Input

The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.

Output

If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.

The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.

Examples

Input

next
2
nextpermutation
nextelement

Output

nextelement

Input

find
4
find
findfirstof
findit
fand

Output

find

Input

find
4
fondfind
fondfirstof
fondit
fand

Output

find

```python
s = input()
l = len(s)
n = int(input())
u = []

for i in range(n):
	a = input()
	#print('Taken input', a,len(a),l)
	if a[:l] == s:
		if len(u) == 0:
			u.append(a if len(a) == l else a[l:])
		elif len(a) == l:
			u = [a] + u
		else:
			j = 0
			k = 0
			while True:
				if u[k] == s:
					if k < len(u) - 1:
						k += 1
						j = 0
					else:
						u.append(a[l:])
						break
				if a[l:][j] == u[k][j]:
					if j < len(u[k]) - 1 and j < len(a[l:]) - 1 :
						j += 1
					else:
						if len(a[l:]) > len(u[k]):
							if k < len(u) - 1:
								k += 1
								j = 0
							else:
								u.append(a[l:])
								break
						else:
							u.insert(k, a[l:])
							break
				elif a[l:][j] > u[k][j]:
					if k < len(u) - 1:
						k += 1
						j = 0
					else:
						u.append(a[l:])
						break
				else:
					u.insert(k, a[l:])
					break
		#print(u)

print(s+(u[0] if u and u[0] != s else ''))

```