1467_E. Distinctive Roots in a Tree

You are given a tree with n vertices. Each vertex i has a value a_i associated with it.

Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some other node, all the values encountered are distinct. Two different paths may have values in common but a single path must have all distinct values.

Find the number of distinctive roots in the tree.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 2⋅10^5) — the number of vertices in the tree.

The next line contains n space-separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

The following n-1 lines each contain two space-separated integers u and v (1 ≤ u, v ≤ n), denoting an edge from u to v.

It is guaranteed that the edges form a tree.

Output

Print a single integer — the number of distinctive roots in the tree.

Examples

Input

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

Output

3

Input

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

Output

0

Note

In the first example, 1, 2 and 5 are distinctive roots.

```python
import io, os
from collections import Counter, defaultdict, deque

class LazySegmentTree:
    def __init__(self, data, default=0, func=max):
        _default = default
        self._func = func

        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()
        self._lazy = [0] * (2 * _size)

        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 __len__(self):
        return self._len

    def _push(self, idx):
        q, self._lazy[idx] = self._lazy[idx], 0

        self._lazy[2 * idx] += q
        self._lazy[2 * idx + 1] += q
        self.data[2 * idx] += q
        self.data[2 * idx + 1] += q

    def _update(self, idx):
        for i in reversed(range(1, idx.bit_length())):
            self._push(idx >> i)

    def _build(self, idx):
        idx >>= 1
        while idx:
            self.data[idx] = (
                self._func(self.data[2 * idx], self.data[2 * idx + 1]) + self._lazy[idx]
            )
            idx >>= 1

    def add(self, start, stop, value):
        if start == stop:
            return
        start = start_copy = start + self._size
        stop = stop_copy = stop + self._size
        while start < stop:
            if start & 1:
                self._lazy[start] += value
                self.data[start] += value
                start += 1
            if stop & 1:
                stop -= 1
                self._lazy[stop] += value
                self.data[stop] += value
            start >>= 1
            stop >>= 1
        self._build(start_copy)
        self._build(stop_copy - 1)

    def query(self, start, stop, default=0):
        start += self._size
        stop += self._size
        self._update(start)
        self._update(stop - 1)

        res = 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 "LazySegmentTree({0})".format(self.data)

def solve(N, A, edges):

    graph = [[] for i in range(N)]
    for u, indices in edges:
        graph[u].append(indices)
        graph[indices].append(u)

    # Build euler tour
    eulerTour = []
    root = 0
    stack = [root]
    seen = [False] * len(graph)
    while stack:
        node = stack.pop()
        eulerTour.append(node)
        if not seen[node]:
            seen[node] = True
            for nbr in graph[node]:
                if not seen[nbr]:
                    stack.append(node)
                    stack.append(nbr)

    assert eulerTour[0] == eulerTour[-1]
    eulerTour.pop()
    tourByValues = defaultdict(list)
    for i, x in enumerate(eulerTour):
        tourByValues[A[x]].append(i)
    segTree = LazySegmentTree([0] * len(eulerTour), 0, lambda x, y: x + y)

    for k, indices in tourByValues.items():
        nodes = set(eulerTour[i] for i in indices)
        if len(nodes) >= 2:
            for i in indices:
                segTree.add(i, i + 1, 1)
            subtour = []
            for i, j in zip(indices, indices[1:]):
                x = eulerTour[i]
                y = eulerTour[j]
                if x == y:
                    segTree.add(i, j + 1, 1)
                else:
                    subtour.append(i)
            i = indices[-1]
            j = indices[0]
            x = eulerTour[i]
            y = eulerTour[j]
            if x == y:
                segTree.add(i, len(eulerTour), 1)
                segTree.add(0, j + 1, 1)
            else:
                subtour.append(i)

            if len(nodes) != len(subtour):
                # Subtour has non leaves, impossible
                return 0
        if False:
            print("label", k, "visits", indices, "nodes", nodes)
            print(
                "\t".join(
                    str(eulerTour[i]) + ":" + str(A[eulerTour[i]])
                    for i in range(len(eulerTour))
                )
            )
            for i in range(len(eulerTour)):
                if segTree.query(i, i + 1) != 0:
                    print("x", end="\t")
                else:
                    print("o", end="\t")
            print()
            print()
    return N - len(set([eulerTour[i] for i in range(len(eulerTour)) if segTree.query(i, i + 1) != 0]))

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N = int(input());A = [int(x) for x in input().split()];e = [[int(x) - 1 for x in input().split()] for i in range(N - 1)];print(solve(N, A, e))
```


1541_E1. Converging Array (Easy Version)

This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.

There is a process that takes place on arrays a and b of length n and length n-1 respectively.

The process is an infinite sequence of operations. Each operation is as follows:

  * First, choose a random integer i (1 ≤ i ≤ n-1).
  * Then, simultaneously set a_i = min\left(a_i, \frac{a_i+a_{i+1}-b_i}{2}\right) and a_{i+1} = max\left(a_{i+1}, \frac{a_i+a_{i+1}+b_i}{2}\right) without any rounding (so values may become non-integer).

See notes for an example of an operation.

It can be proven that array a converges, i. e. for each i there exists a limit a_i converges to. Let function F(a, b) return the value a_1 converges to after a process on a and b.

You are given array b, but not array a. However, you are given a third array c. Array a is good if it contains only integers and satisfies 0 ≤ a_i ≤ c_i for 1 ≤ i ≤ n.

Your task is to count the number of good arrays a where F(a, b) ≥ x for q values of x. Since the number of arrays can be very large, print it modulo 10^9+7.

Input

The first line contains a single integer n (2 ≤ n ≤ 100).

The second line contains n integers c_1, c_2 …, c_n (0 ≤ c_i ≤ 100).

The third line contains n-1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 100).

The fourth line contains a single integer q (q=1).

The fifth line contains q space separated integers x_1, x_2, …, x_q (-10^5 ≤ x_i ≤ 10^5).

Output

Output q integers, where the i-th integer is the answer to the i-th query, i. e. the number of good arrays a where F(a, b) ≥ x_i modulo 10^9+7.

Example

Input

3
2 3 4
2 1
1
-1

Output

56

Note

The following explanation assumes b = [2, 1] and c=[2, 3, 4] (as in the sample).

Examples of arrays a that are not good:

  * a = [3, 2, 3] is not good because a_1 > c_1;
  * a = [0, -1, 3] is not good because a_2 < 0.

One possible good array a is [0, 2, 4]. We can show that no operation has any effect on this array, so F(a, b) = a_1 = 0.

Another possible good array a is [0, 1, 4]. In a single operation with i = 1, we set a_1 = min((0+1-2)/(2), 0) and a_2 = max((0+1+2)/(2), 1). So, after a single operation with i = 1, a becomes equal to [-1/2, 3/2, 4]. We can show that no operation has any effect on this array, so F(a, b) = -1/2.

```python
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
C = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
Q = int(input())
x = int(input())
P = 10 ** 9 + 7
dp = [[0] * 20100 for _ in range(N + 1)]
dp[0][0] = 1
ans = 0
s = x
t = s
for i in range(N):
    for j in range(20050, t - 1, -1):
        if j < 0: break
        dp[i+1][j] = (dp[i+1][j+1] + dp[i][max(j-C[i], 0)] - dp[i][j+1]) % P
    for j in range(min(t - 1, 20050), -1, -1):
        dp[i+1][j] = dp[i+1][j+1]

    if i < N - 1:
        s += B[i]
        t += s
print(dp[-1][0] % P)
```


18_B. Platforms

In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

Input

The first input line contains 4 integer numbers n, d, m, l (1 ≤ n, d, m, l ≤ 106, l < m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k - 1)m, (k - 1)m + l].

Output

Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.

Examples

Input

2 2 5 3

Output

4

Input

5 4 11 8

Output

20

```python
class Platforms:
    @classmethod
    def read_input(cls):
        nums = list(map(int, input('').split()))
        return nums[0], nums[1], nums[2], nums[3]

    @classmethod
    def run(cls):
        n, d, m, l = cls.read_input()
        end_plat = (n - 1) * m + l
        for cur_jump in range(d, (m + 1) * d, d):
            if (cur_jump % m) > l or cur_jump > end_plat:
                print(cur_jump)
                return
        print(end_plat - (end_plat % d) + d)

if __name__ == "__main__":
    Platforms.run()

```


213_B. Numbers

Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.

There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive integers with the following properties:

  * the number's length does not exceed n;
  * the number doesn't have leading zeroes;
  * digit i (0 ≤ i ≤ 9) occurs in the number at least a[i] times.

Input

The first line contains integer n (1 ≤ n ≤ 100). The next line contains 10 integers a[0], a[1], ..., a[9] (0 ≤ a[i] ≤ 100) — elements of array a. The numbers are separated by spaces.

Output

On a single line print the remainder of dividing the answer to the problem by 1000000007 (109 + 7).

Examples

Input

1
0 0 0 0 0 0 0 0 0 1

Output

1

Input

2
1 1 0 0 0 0 0 0 0 0

Output

1

Input

3
1 1 0 0 0 0 0 0 0 0

Output

36

Note

In the first sample number 9 meets the requirements.

In the second sample number 10 meets the requirements.

In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total.

```python
from math import factorial
dp=[[-1 for i in range (101)] for j in range(101)]
def solve(n,p,a):
    if dp[n][p] is not -1:
        return dp[n][p]
    elif p is 9:
        if n>=a[9]:
            return 1
        else:
            return 0
    elif p is 0:
        ans=0
        for i in range(a[0],n):
            z=solve(n-i,1,a)
            z*=factorial(n-1)
            z//=factorial(i)
            z//=factorial(n-1-i)
            ans+=z
        dp[n][p]=ans
        return ans
    else:
        ans=0
        for i in range(a[p],n+1):
            z=solve(n-i,p+1,a)
            z*=factorial(n)
            z//=factorial(i)
            z//=factorial(n-i)
            ans+=z
        dp[n][p]=ans
        return ans
hell=1000000007
n=int(input())
a=input().rstrip().split(' ');
for i in range(0,len(a)):
    a[i]=int(a[i])
ans=0
for i in range(1,n+1):
    ans+=solve(i,0,a)
    ans%=hell
print(ans)
```


237_B. Young Table

You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1.

Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct.

Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions:

  1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j;
  2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1.

In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap.

Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows.

Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j.

It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct.

Output

In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps.

In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed.

Examples

Input

3
3 2 1
4 3 5
6 1
2

Output

2
1 1 2 2
2 1 3 1

Input

1
4
4 3 2 1

Output

2
1 1 1 4
1 2 1 3

```python
n = int(input())
I = lambda : map(int,input().split())
li = list (I())
dd = {}
arr = [ [0 for i in range(51)] for j in range(51) ]
l2 = [ ]
c=0
for i in range (1,n+1) :
    l1 = list(I())
    l2 = l2 + l1
    c = c + len(l1)
    for j in range(li[i-1]) :
        arr[i][j+1] = l1[j]
        dd[l1[j]] = [i , j+1]
#print(dd)
#print(l2)
l3 = l2[:]
l3.sort()
#print(l3)
ans= 0
d1 = {}
for i,j in enumerate(l2) :
    d1[j]=i
#print(d1)
answer = [ ]
#print(dd)
#print(l2)
for i in range(c) :
    if l2[i]!=l3[i] :
        t1 = l2[i]
        t2 = i+1
        #print(t1,t2)
        #temp = dd[t1]
        #temp1 = dd[t2]
        answer = answer + [dd[t1] + dd[t2]]
        l2[i] = i+1
        l2[d1[t2]] = t1
        d1[t1] = d1[t2]
        d1[i+1] = i
        temp2 = dd[t1]
        dd[t1] = dd[t2]
        dd[t2] = temp2
        ans+=1
        #print(l2)
print(ans)
for i in range(ans) :
    print(*answer[i])

```


285_E. Positions in Permutations

Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.

We'll call position i (1 ≤ i ≤ n) in permutation p1, p2, ..., pn good, if |p[i] - i| = 1. Count the number of permutations of size n with exactly k good positions. Print the answer modulo 1000000007 (109 + 7).

Input

The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 0 ≤ k ≤ n).

Output

Print the number of permutations of length n with exactly k good positions modulo 1000000007 (109 + 7).

Examples

Input

1 0

Output

1

Input

2 1

Output

0

Input

3 2

Output

4

Input

4 1

Output

6

Input

7 4

Output

328

Note

The only permutation of size 1 has 0 good positions.

Permutation (1, 2) has 0 good positions, and permutation (2, 1) has 2 positions.

Permutations of size 3:

  1. (1, 2, 3) — 0 positions
  2. <image> — 2 positions
  3. <image> — 2 positions
  4. <image> — 2 positions
  5. <image> — 2 positions
  6. (3, 2, 1) — 0 positions


356_C. Compartments

A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip.

The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student.

However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number.

After all the swaps each compartment should either have no student left, or have a company of three or four students.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.

Output

If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.

Examples

Input

5
1 2 2 4 3

Output

2

Input

3
4 1 1

Output

2

Input

4
0 3 0 4

Output

0


37_B. Computer Game

Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.

While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:

1) The boss has two parameters: max — the initial amount of health and reg — regeneration rate per second.

2) Every scroll also has two parameters: powi — spell power measured in percents — the maximal amount of health counted off the initial one, which allows to use the scroll (i.e. if the boss has more than powi percent of health the scroll cannot be used); and dmgi the damage per second inflicted upon the boss if the scroll is used. As soon as a scroll is used it disappears and another spell is cast upon the boss that inflicts dmgi of damage per second upon him until the end of the game.

During the battle the actions per second are performed in the following order: first the boss gets the damage from all the spells cast upon him, then he regenerates reg of health (at the same time he can’t have more than max of health), then the player may use another scroll (no more than one per second).

The boss is considered to be defeated if at the end of a second he has nonpositive ( ≤ 0) amount of health.

Help Petya to determine whether he can win with the set of scrolls available to him and if he can, determine the minimal number of seconds he needs to do it.

Input

The first line contains three integers N, max and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 100, 1 ≤ dmgi ≤ 2000).

Output

In case Petya can’t complete this level, output in the single line NO.

Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the start of the battle to the moment the scroll was used and the number of the scroll. Scrolls are numbered starting from 1 in the input order. The first scroll is considered to be available to be used after 0 seconds.

Output scrolls in the order they were used. It is not allowed to use scrolls after the boss is defeated.

Examples

Input

2 10 3
100 3
99 1

Output

NO

Input

2 100 10
100 11
90 9

Output

YES
19 2
0 1
10 2

```python
class Scroll:
	def __init__(self, id, power, damage):
		self.id = id
		self.power = power
		self.damage = damage
		self.active = False

num_scrolls, boss_max, regenerate = map(int, input().split())
scrolls = [Scroll(i+1, *map(int, input().split())) for i in range(num_scrolls)]
scrolls.sort(key = lambda scroll: -scroll.damage)
boss_curr = boss_max
scroll_damage = 0
active_scrolls = []
tick = 0
while True:
	boss_prev = boss_curr
	boss_curr -= scroll_damage
	boss_curr = min(boss_max, boss_curr + regenerate)
	if boss_curr <= 0:
		print('YES')
		print(tick, len(active_scrolls))
		for scroll in active_scrolls:
			print(scroll.start, scroll.id)
		break
	found = False
	for scroll in scrolls:
		if not scroll.active and 100*boss_curr <= scroll.power*boss_max:
			scroll.start = tick
			scroll.active = True
			active_scrolls.append(scroll)
			scroll_damage += scroll.damage
			found = True
			break
	if not found and boss_curr >= boss_prev:
		print('NO')
		break
	tick += 1

```


400_A. Inna and Choose Options

There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:

There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers a and b (a·b = 12), after that he makes a table of size a × b from the cards he put on the table as follows: the first b cards form the first row of the table, the second b cards form the second row of the table and so on, the last b cards form the last (number a) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses.

Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers a and b to choose. Help her win the game: print to her all the possible ways of numbers a, b that she can choose and win.

Input

The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.

The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th character of the string shows the character that is written on the i-th card from the start.

Output

For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces.

Examples

Input

4
OXXXOXOOXOOX
OXOXOXOXOXOX
XXXXXXXXXXXX
OOOOOOOOOOOO

Output

3 1x12 2x6 4x3
4 1x12 2x6 3x4 6x2
6 1x12 2x6 3x4 4x3 6x2 12x1
0

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

a = [1, 2, 3, 4, 6, 12]

for i in range(0, n):
	s = str(input())
	ans = [False for x in range(0, 6)]
	nans = 0;

	for i in range (0, 6):
		for j in range (0, 12 // a[i]):
			good = True
			for k in range(0, a[i]):
				if s[k * 12 // a[i] + j] is 'O':
					good = False
					break
			if good:
				nans = nans + 1
				ans[i] = True
				break

	print(nans, end = ' ')
	for i in range (0, 6):
		if ans[i]:
			print(str(a[i]) + 'x' + str(12 // a[i]), end = ' ')
	print()

```


427_B. Prison Transfer

The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.

For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.

Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,

  * The chosen c prisoners has to form a contiguous segment of prisoners.
  * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.

Find the number of ways you can choose the c prisoners.

Input

The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.

Output

Print a single integer — the number of ways you can choose the c prisoners.

Examples

Input

4 3 3
2 3 1 1

Output

2

Input

1 1 1
2

Output

0

Input

11 4 2
2 2 0 7 3 2 2 4 9 1 4

Output

6

```python
a=list(map(int,input().split()[1:]))
b=list(map(int,input().split()))
m=0
c=0
for i in b:
    if i>a[0]:
        if not c<a[1]:
            m+=c-a[1]+1
        c=0
    else:c+=1
print(m+c-a[1]+1 if c>=a[1]else m)

```


472_A. Design Tutorial: Learn from Math

One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.

For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.

You are given an integer n no less than 12, express it as a sum of two composite numbers.

Input

The only line contains an integer n (12 ≤ n ≤ 106).

Output

Output two composite integers x and y (1 < x, y < n) such that x + y = n. If there are multiple solutions, you can output any of them.

Examples

Input

12

Output

4 8

Input

15

Output

6 9

Input

23

Output

8 15

Input

1000000

Output

500000 500000

Note

In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.

In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.

```python
def isprime(k):
    m=0
    for j in range(2,k):
        if k%j==0:
            m=m+1
    if m==0:
        return 0
    else:
        return 1

n=int(input())
for i in range(4,n-3):
    if isprime(i)==1 and isprime(n-i)==1:
        print(i,n-i)
        exit()
```


496_B. Secret Combination

You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.

Output

Print a single line containing n digits — the desired state of the display containing the smallest possible number.

Examples

Input

3
579

Output

024

Input

4
2014

Output

0142

```python
n = int(input())
s = input()
i = 0
min_ = int(s)
s1 = s
i = 0
while (i <= n):
    s = s[1::] + s[0]
    if (int(s[0]) != 0):
        g = (9 - int(s[0])) + 1
        s2 = ''
        for j in range(len(s)):
            h = int(s[j]) + g
            if (h >= 10):
                h = abs(10 - h)
            s2 = s2 + str(h)
        s = s2
    if (int(s) < min_):
        min_ = int(s)
        s1 = s
    i = i + 1
print(s1)
```


547_A. Mike and Frog

Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.

<image>

So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.

Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.

Mike has asked you for your help. Calculate the minimum time or say it will never happen.

Input

The first line of input contains integer m (2 ≤ m ≤ 106).

The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).

The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).

The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).

The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).

It is guaranteed that h1 ≠ a1 and h2 ≠ a2.

Output

Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.

Examples

Input

5
4 2
1 1
0 1
2 3

Output

3

Input

1023
1 2
1 0
1 2
1 1

Output

-1

Note

In the first sample, heights sequences are following:

Xaniar: <image>

Abol: <image>

```python
def main():
    m, tt = int(input()), [0] * 4
    for i in 0, 2:
        h, a = map(int, input().split())
        x, y = map(int, input().split())
        ha = (h, a)
        for t in range(1, m * 2):
            h = (h * x + y) % m
            if h in ha:
                if h == ha[0]:
                    if tt[i]:
                        tt[i] = t - tt[i]
                        break
                    else:
                        tt[i] = t
                else:
                    if tt[i + 1]:
                        tt[i] = t - tt[i + 1]
                        break
                    else:
                        tt[i + 1] = t
    step1, shift1, step2, shift2 = tt if tt[0] > tt[2] else tt[2:] + tt[:2]
    if shift1 == shift2 != 0:
        print(shift1)
        return
    if step1 and not step2 and shift1 and shift1 <= shift2 and not (shift2 - shift1) % step1:
        print(shift2)
        return
    if all(tt):
        if step2 == 1:
            print(shift1 if shift1 >= shift2 else shift2 + (shift2 - shift1) % step1)
            return
        for t in range(shift1 - shift2, shift1 - shift2 + step1 * step2, step1):
            if not t % step2:
                print(t + shift2)
                return
    print(-1)

if __name__ == '__main__':
    main()

```


595_A. Vitaly and Night

One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.

Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.

Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.

Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.

Output

Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.

Examples

Input

2 2
0 0 0 1
1 0 1 1

Output

3

Input

1 3
1 1 0 1 0 0

Output

2

Note

In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.

In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.

```python
etaj, kvart = map(int, input().split())
Okna = []

notsleep = 0

for i in range(0, etaj):
    Okna.append(list(map(int, input().split())))

for i in range(0, etaj):
    for j in range(0, (kvart*2)-1, 2):
        if Okna[i][j] or Okna[i][j+1] == 1:
            notsleep += 1

print(notsleep)

```


616_D. Longest k-Good Segment

The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.

Find any longest k-good segment.

As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The first line contains two integers n, k (1 ≤ k ≤ n ≤ 5·105) — the number of elements in a and the parameter k.

The second line contains n integers ai (0 ≤ ai ≤ 106) — the elements of the array a.

Output

Print two integers l, r (1 ≤ l ≤ r ≤ n) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.

Examples

Input

5 5
1 2 3 4 5

Output

1 5

Input

9 3
6 5 1 2 3 2 1 4 5

Output

3 7

Input

3 1
1 2 3

Output

1 1

```python
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
cat=''.join
catn='\n'.join
mod=1000000007
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################

n,k=ris()
a=ris()
beg=end=i=0
occ=ddict(int)
for j in range(n):
  occ[a[j]]+=1
  while len(occ)>k:
    occ[a[i]]-=1
    if occ[a[i]]==0:
      del occ[a[i]]
    i+=1
  if end-beg<j-i:
    beg,end=i,j

print(beg+1,end+1)

```


689_B. Mike and Shortcuts

Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.

City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number i to intersection j requires |i - j| units of energy. The total energy spent by Mike to visit a sequence of intersections p1 = 1, p2, ..., pk is equal to <image> units of energy.

Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly n shortcuts in Mike's city, the ith of them allows walking from intersection i to intersection ai (i ≤ ai ≤ ai + 1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence p1 = 1, p2, ..., pk then for each 1 ≤ i < k satisfying pi + 1 = api and api ≠ pi Mike will spend only 1 unit of energy instead of |pi - pi + 1| walking from the intersection pi to intersection pi + 1. For example, if Mike chooses a sequence p1 = 1, p2 = ap1, p3 = ap2, ..., pk = apk - 1, he spends exactly k - 1 units of total energy walking around them.

Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1 ≤ i ≤ n Mike is interested in finding minimum possible total energy of some sequence p1 = 1, p2, ..., pk = i.

Input

The first line contains an integer n (1 ≤ n ≤ 200 000) — the number of Mike's city intersection.

The second line contains n integers a1, a2, ..., an (i ≤ ai ≤ n , <image>, describing shortcuts of Mike's city, allowing to walk from intersection i to intersection ai using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from ai to i).

Output

In the only line print n integers m1, m2, ..., mn, where mi denotes the least amount of total energy required to walk from intersection 1 to intersection i.

Examples

Input

3
2 2 3

Output

0 1 2

Input

5
1 2 3 4 5

Output

0 1 2 3 4

Input

7
4 4 4 4 7 7 7

Output

0 1 2 1 2 3 3

Note

In the first sample case desired sequences are:

1: 1; m1 = 0;

2: 1, 2; m2 = 1;

3: 1, 3; m3 = |3 - 1| = 2.

In the second sample case the sequence for any intersection 1 < i is always 1, i and mi = |1 - i|.

In the third sample case — consider the following intersection sequences:

1: 1; m1 = 0;

2: 1, 2; m2 = |2 - 1| = 1;

3: 1, 4, 3; m3 = 1 + |4 - 3| = 2;

4: 1, 4; m4 = 1;

5: 1, 4, 5; m5 = 1 + |4 - 5| = 2;

6: 1, 4, 6; m6 = 1 + |4 - 6| = 3;

7: 1, 4, 5, 7; m7 = 1 + |4 - 5| + 1 = 3.

```python
def amount_of_total_energy(n, a):
    dist = [-1] * n
    dist[0] = 0
    pos = [0]

    for u in pos:
	    for v in [u - 1, u + 1, a[u] - 1]:
		    if v >= 0 and v < n and dist[v] == -1:
			    dist[v] = dist[u] + 1
			    pos.append(v)

    return dist

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

print(*amount_of_total_energy(n, a))
```


731_F. Video Cards

Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.

There are n video cards in the shop, the power of the i-th video card is equal to integer value ai. As Vlad wants to be sure the new game will work he wants to buy not one, but several video cards and unite their powers using the cutting-edge technology. To use this technology one of the cards is chosen as the leading one and other video cards are attached to it as secondary. For this new technology to work it's required that the power of each of the secondary video cards is divisible by the power of the leading video card. In order to achieve that the power of any secondary video card can be reduced to any integer value less or equal than the current power. However, the power of the leading video card should remain unchanged, i.e. it can't be reduced.

Vlad has an infinite amount of money so he can buy any set of video cards. Help him determine which video cards he should buy such that after picking the leading video card and may be reducing some powers of others to make them work together he will get the maximum total value of video power.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards.

Output

The only line of the output should contain one integer value — the maximum possible total power of video cards working together.

Examples

Input

4
3 2 15 9

Output

27

Input

4
8 2 2 7

Output

18

Note

In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as the leading, the powers of all other video cards should be reduced by 1, thus the total power would be 2 + 2 + 14 + 8 = 26, that is less than 27. Please note, that it's not allowed to reduce the power of the leading video card, i.e. one can't get the total power 3 + 1 + 15 + 9 = 28.

In the second sample, the optimal answer is to buy all video cards and pick the one with the power 2 as the leading. The video card with the power 7 needs it power to be reduced down to 6. The total power would be 8 + 2 + 2 + 6 = 18.

```python
n = int(input())
s = list(map(int, input().split()))
h = max(s)
ss = [0] * (h + 1)
for i in s:
    ss[i] += 1
f, x = [0] * h, 0
for j in reversed(ss):
    x += j
    f.append(x)
f.reverse()
res = []
for i, x in enumerate(ss):
    if x:
        summ, x = 0, f[i]
        for j in range(i, h + 1, i):
            o = f[j + i]
            summ += (x - o) * j
            x = o
        res.append(summ)
print(max(res))
```


756_A. Pavel and barbecue

Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.

Pavel has a plan: a permutation p and a sequence b1, b2, ..., bn, consisting of zeros and ones. Each second Pavel move skewer on position i to position pi, and if bi equals 1 then he reverses it. So he hope that every skewer will visit every position in both directions.

Unfortunately, not every pair of permutation p and sequence b suits Pavel. What is the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements? Note that after changing the permutation should remain a permutation as well.

There is no problem for Pavel, if some skewer visits some of the placements several times before he ends to cook. In other words, a permutation p and a sequence b suit him if there is an integer k (k ≥ 2n), so that after k seconds each skewer visits each of the 2n placements.

It can be shown that some suitable pair of permutation p and sequence b exists for any n.

Input

The first line contain the integer n (1 ≤ n ≤ 2·105) — the number of skewers.

The second line contains a sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation, according to which Pavel wants to move the skewers.

The third line contains a sequence b1, b2, ..., bn consisting of zeros and ones, according to which Pavel wants to reverse the skewers.

Output

Print single integer — the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements.

Examples

Input

4
4 3 2 1
0 1 1 1

Output

2

Input

3
2 3 1
0 0 0

Output

1

Note

In the first example Pavel can change the permutation to 4, 3, 1, 2.

In the second example Pavel can change any element of b to 1.

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

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

go = set(range(1,n+1))
reached = set()
ans = 0
while go:
  x = go.pop()
  while x not in reached:
    reached.add(x)
    x = permutation[x-1]
    if x in go:
      go.remove(x)
  ans += 1
if ans == 1:
  ans = 0

permutation = input().split()
if permutation.count('1') % 2 == 0:
  ans += 1
print(ans)#

```


777_B. Game of Credit Cards

After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.

Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if n = 3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.

Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.

Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of digits in the cards Sherlock and Moriarty are going to use.

The second line contains n digits — Sherlock's credit card number.

The third line contains n digits — Moriarty's credit card number.

Output

First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.

Examples

Input

3
123
321

Output

0
2

Input

2
88
00

Output

2
0

Note

First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.

```python
n = int(input())
s = list(map(int, list(input())))
m = map(int, list(input()))

ma = [0] * 10
for dig in m:
    ma[dig] += 1

ma2 = list(ma)

min_f = 0
for nu in s:
    for x in range(nu, 10):
        if ma[x] > 0:
            ma[x] -= 1
            break
    else:
        min_f += 1
        for z in range(len(ma)):
            if ma[z] > 0:
                ma[z] -= 1
                break

print(min_f)

ma = ma2

max_f = 0
for nu in s:
    for x in range(nu+1, 10):
        if ma[x] > 0:
            ma[x] -= 1
            max_f += 1
            break
    else:
        for z in range(len(ma)):
            if ma[z] > 0:
                ma[z] -= 1
                break

print(max_f)
```


822_B. Crossword solving

Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you?

Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.

Guaranteed that the length of the string s doesn't exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.

Input

The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly.

The second line contains n lowercase English letters — string s.

The third line contains m lowercase English letters — string t.

Output

In the first line print single integer k — the minimal number of symbols that need to be replaced.

In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.

Examples

Input

3 5
abc
xaybz

Output

2
2 3

Input

4 10
abcd
ebceabazcd

Output

1
2

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

res = 1001
res_ind = []

b = 0
e = len(s)
while b <= len(t)-len(s):
    sr = t[b:e]
    k = 0
    ind = []
    for i in range(len(s)):
        if s[i] != sr[i]:
            k += 1
        else:
            ind.append(i+1)
    if k < res:
        res = k
        res_ind = ind
    b += 1
    e += 1
print(res)
res_ind = [x for x in range(1, len(s)+1) if x not in res_ind]
print(*res_ind)

```


847_G. University Classes

There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.

The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.

Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.

Input

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

Each of the following n lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.

Output

Print minimum number of rooms needed to hold all groups classes on Monday.

Examples

Input

2
0101010
1010101

Output

1

Input

3
0101011
0011001
0110111

Output

3

Note

In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.

In the second example three rooms is enough, because in the seventh time slot all three groups have classes.

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

schedules = []

for i in range(n):
    schedules.append(input())

minimum = 0

for i in range(7):
    activeSlots = 0
    for j in range(n):
        activeSlots += int(schedules[j][i])
    if activeSlots > minimum:
        minimum = activeSlots

print(minimum)
```


869_B. The Eternal Immortality

Even if the world is full of counterfeits, I still regard it as wonderful.

Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.

The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.

Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.

As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

Input

The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

Output

Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

Examples

Input

2 4

Output

2

Input

0 10

Output

0

Input

107 109

Output

2

Note

In the first example, the last digit of <image> is 2;

In the second example, the last digit of <image> is 0;

In the third example, the last digit of <image> is 2.

```python
# Main maut ko takiya, aur kafan ko chaadar banakkar audhta hoon!

a,b=input().split()

if a[:-1]!=b[:-1]:
	print("0")

else:
	ans=1

	for i in range(int(a[-1])+1,int(b[-1])+1):
		ans*=i
		ans=ans%10
	print(ans)

```


895_A. Pizza Separation

Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.

Input

The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.

The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.

Output

Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.

Examples

Input

4
90 90 90 90

Output

0

Input

3
100 100 160

Output

40

Input

1
360

Output

360

Input

4
170 30 150 10

Output

0

Note

In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.

In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.

In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.

Picture explaning fourth sample:

<image>

Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.

```python
n=int(input())
a=list(map(int,input().split()))
print(2*min(abs(180-sum(a[l:r])) for l in range(n) for r in range(l,n)))

```


916_B. Jamie and Binary Sequence (changed after round)

Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:

Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.

To be more clear, consider all integer sequence with length k (a1, a2, ..., ak) with <image>. Give a value <image> to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.

For definitions of powers and lexicographical order see notes.

Input

The first line consists of two integers n and k (1 ≤ n ≤ 1018, 1 ≤ k ≤ 105) — the required sum and the length of the sequence.

Output

Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence.

It is guaranteed that the integers in the answer sequence fit the range [ - 1018, 1018].

Examples

Input

23 5

Output

Yes
3 3 2 1 0

Input

13 2

Output

No

Input

1 2

Output

Yes
-1 -1

Note

Sample 1:

23 + 23 + 22 + 21 + 20 = 8 + 8 + 4 + 2 + 1 = 23

Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.

Answers like (4, 1, 1, 1, 0) do not have the minimum y value.

Sample 2:

It can be shown there does not exist a sequence with length 2.

Sample 3:

<image>

Powers of 2:

If x > 0, then 2x = 2·2·2·...·2 (x times).

If x = 0, then 2x = 1.

If x < 0, then <image>.

Lexicographical order:

Given two different sequences of the same length, (a1, a2, ... , ak) and (b1, b2, ... , bk), the first one is smaller than the second one for the lexicographical order, if and only if ai < bi, for the first i where ai and bi differ.

```python
n, k = map(int, input().split())
cnt = [0] * 200010
ans = ''
for i in range(64):
  if (n >> i)&1:
    k -= 1
    cnt[i] = 1;
if k < 0:
  print("No")
else:
  print("Yes")
  for i in range(64, -64, -1):
    if k >= cnt[i]:
      cnt[i - 1] += cnt[i] * 2
      k -= cnt[i]
      cnt[i] = 0
    else: break
  for i in range(-64, 64):
    if cnt[i]:
      while k:
        cnt[i] -= 1
        cnt[i - 1] += 2
        i -= 1
        k-= 1
      break
  for i in range(64, -100010, -1): ans += (str(i) + ' ') * cnt[i]
  print(ans)
```


939_C. Convenient For Everybody

In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.

Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.

Help platform select such an hour, that the number of people who will participate in the contest is maximum.

Input

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.

The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).

Output

Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.

Examples

Input

3
1 2 3
1 3

Output

3

Input

5
1 2 3 4 1
1 3

Output

4

Note

In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.

In second example only people from the third and the fourth timezones will participate.

```python
# Problem D
n = int(input())
inp = input().split(" ")
people = [ int(x) for x in inp ]
inp = input().split(" ")
s, f = int(inp[0]), int(inp[1])
r = f-s#+1 # tamaño de la ventana
max_s, idx_max = sum( people[i] for i in range(r) ), 0
sum_ac = max_s
res = (n-idx_max+s)%n if (n-idx_max+s)%n else n
for j in range(n):
    # print(sum_ac, idx_max, res)
    sum_ac = sum_ac - people[j] + people[(r+j)%n]
    if sum_ac>max_s:
        max_s, idx_max = sum_ac, (j+1)%n
        res = (n-(j+1)+s)%n if (n-(j+1)+s)%n else n
    elif sum_ac==max_s:
        res_1 = (n-(j+1)+s)%n if (n-(j+1)+s)%n else n
        if res_1<res:
            res=res_1
# res = (n-idx_max+s)%n if (n-idx_max+s)%n else n
print(res)
```


991_F. Concise and clear

Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the number at the first glance. Could it be shortened? For example, instead of 1000000 you could write 10^{6}, instead of 1000000000 —10^{9}, instead of 1000000007 — 10^{9}+7.

Vasya decided that, to be concise, the notation should follow several rules:

  * the notation should only consist of numbers, operations of addition ("+"), multiplication ("*") and exponentiation ("^"), in particular, the use of braces is forbidden;
  * the use of several exponentiation operations in a row is forbidden, for example, writing "2^3^4" is unacceptable;
  * the value of the resulting expression equals to the initial number;
  * the notation should consist of the minimal amount of symbols.

Given n, find the equivalent concise notation for it.

Input

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

Output

Output a concise notation of the number n. If there are several concise notations, output any of them.

Examples

Input

2018

Output

2018

Input

1000000007

Output

10^9+7

Input

10000000000

Output

100^5

Input

2000000000

Output

2*10^9

Note

The third sample allows the answer 10^10 also of the length 5.

```python
import math
import itertools

pow10 = [1]
for i in range(10):
    pow10.append(pow10[-1] * 10)

def getlen(x):
    """length of the decimal representation of integer x"""
    return int(math.log10(x)) + 1

class ShortestRepresentation:

    def __init__(self, n):
        self.n = n
        self._m = {}
        self._s = [set() for i in range(10)]

        self._generate_powers()
        self._generate_power_and_power(7)
        self._generate_simple_and_power(7)

    def _generate_powers(self):
        """add to the collection all expressions of the form a^b"""
        range_x = itertools.takewhile(
            lambda x: x**2 <= self.n,
            itertools.count(2))
        for x in range_x:
            c = x**2
            p = 2
            while c <= self.n:
                self.update(c, '{}^{}'.format(x, p))
                c *= x
                p += 1

    def _generate_power_and_power(self, maxlen):
        """add to the collection all expressions of the form a^b*c^d"""
        for i in range(1, maxlen + 1):
            range_j = itertools.takewhile(
                lambda j: i + j + 1 <= maxlen,
                itertools.count(i))
            for j in range_j:
                for x, y in itertools.product(self._s[i], self._s[j]):
                    x2 = self.get(x)
                    y2 = self.get(y)
                    self.update(x * y, '{}*{}'.format(x2, y2))

    def _generate_simple_and_power(self, maxlen):
        """add to the collection all expressions of the form a^b*c"""
        for i in range(1, maxlen - 1):
            range_xy = itertools.product(
                range(1, pow10[maxlen - 1 - i]),
                self._s[i])
            for x, y in range_xy:
                y2 = self.get(y)
                self.update(x * y, '{}*{}'.format(x, y2))

    def update(self, x, s):
        """update with s x'th entry of the collection"""
        if x > self.n:
            return

        ls = len(s)
        if ls >= getlen(x):  # length of s should be at least shorter
            return

        if x not in self._m:
            self._m[x] = s
            self._s[ls].add(x)
        else:
            lm = len(self._m[x])
            if ls < lm:
                self._s[lm].remove(x)
                self._m[x] = s
                self._s[ls].add(x)

    def get(self, x):
        """retrieve shortest valid representation of number x"""
        return self._m[x] if x in self._m else str(x)

n = int(input())
if n < 10**10:
    sr = ShortestRepresentation(n)
    ans = sr.get(n)

    # check a*b and a+b
    range_i = itertools.takewhile(
        lambda i: i * 2 + 1 < len(ans),
        itertools.count())
    for i in range_i:
        range_x = itertools.chain(
            range(1, pow10[i] + 1),
            sr._s[i])
        for x in range_x:
            ans = min(
                ans, '{}+{}'.format(sr.get(x), sr.get(n - x)), key=len)
            if n % x > 0:
                continue
            ans = min(
                ans, '{}*{}'.format(sr.get(x), sr.get(n // x)), key=len)

    print(ans)
else:
    print('100^5')

```


p02621 AtCoder Beginner Contest 172 - Calc

Given an integer a as input, print the value a + a^2 + a^3.

Constraints

* 1 \leq a \leq 10
* a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

Print the value a + a^2 + a^3 as an integer.

Examples

Input

2

Output

14

Input

10

Output

1110

```python
a= int(input())
eq= a+(a**2)+(a**3)
print(eq)
```


p02752 Social Infrastructure Information Systems Division  Hitachi Programming Contest 2020 - Preserve Diameter

We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.

Consider adding zero or more edges in G, and let H be the graph resulted.

Find the number of graphs H that satisfy the following conditions, modulo 998244353.

* H does not contain self-loops or multiple edges.
* The diameters of G and H are equal.
* For every pair of vertices in H that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph.

Constraints

* 3 \le N \le 2 \times 10^5
* 1 \le a_i, b_i \le N
* The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
\vdots
a_{N-1} b_{N-1}

Output

Print the answer.

Examples

Input

6
1 6
2 1
5 2
3 4
2 3

Output

3

Input

3
1 2
2 3

Output

1

Input

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

Output

27

Input

19
2 4
15 8
1 16
1 3
12 19
1 18
7 11
11 15
12 9
1 6
7 14
18 2
13 12
13 5
16 13
7 1
11 10
7 17

Output

78732

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

N=int(input())
E=[[] for i in range(N+1)]

for i in range(N-1):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

Q=[1]
D=[-1]*(N+1)
D[1]=0
while Q:
    x=Q.pop()
    for to in E[x]:
        if D[to]==-1:
            D[to]=D[x]+1
            Q.append(to)

f=D.index(max(D))
Q=[f]
D=[-1]*(N+1)
D[f]=0
while Q:
    x=Q.pop()
    for to in E[x]:
        if D[to]==-1:
            D[to]=D[x]+1
            Q.append(to)

MAX=max(D)
l=D.index(MAX)
Q=[l]
D2=[-1]*(N+1)
D2[l]=0
while Q:
    x=Q.pop()
    for to in E[x]:
        if D2[to]==-1:
            D2[to]=D2[x]+1
            Q.append(to)

if MAX%2==0:
    for i in range(N+1):
        if D[i]==MAX//2 and D2[i]==MAX//2:
            c=i
            break

    TOP_SORT=[]

    Q=[c]
    D=[-1]*(N+1)
    P=[-1]*(N+1)
    D[c]=0
    while Q:
        x=Q.pop()
        TOP_SORT.append(x)
        for to in E[x]:
            if D[to]==-1:
                D[to]=D[x]+1
                Q.append(to)
                P[to]=x

    DP=[[[0,0,0] for i in range(3)] for i in range(N+1)]
    # DP[x][p][m]で, plusのものが0個, 1個, 2個以上, minusのものが0個, 1個, 2個以上

    for x in TOP_SORT[::-1]:
        if D[x]==MAX//2:
            DP[x][1][1]=1

        elif len(E[x])==1:
            DP[x][0][0]=1

        else:
            for to in E[x]:
                if to==P[x]:
                    continue

                X=[[0,0,0] for i in range(3)]
                for i in range(3):
                    for j in range(3):
                        X[0][0]+=DP[to][i][j]
                        X[i][0]+=DP[to][i][j]
                        X[0][j]+=DP[to][i][j]

                if DP[x]==[[0,0,0] for i in range(3)]:
                    DP[x]=X

                else:
                    Y=[[0,0,0] for i in range(3)]

                    for i in range(3):
                        for j in range(3):
                            for k in range(3):
                                for l in range(3):
                                    Y[min(2,i+k)][min(2,j+l)]=(Y[min(2,i+k)][min(2,j+l)]+X[i][j]*DP[x][k][l])%mod

                    DP[x]=Y

    #print(DP)
    print(DP[c][1][1]*pow(2,mod-2,mod)%mod)

else:
    for i in range(N+1):
        if D[i]==MAX//2 and D2[i]==MAX//2+1:
            c1=i
        elif D[i]==MAX//2+1 and D2[i]==MAX//2:
            c2=i

    TOP_SORT=[]

    Q=[c1,c2]
    D=[-1]*(N+1)
    P=[-1]*(N+1)
    D[c1]=0
    D[c2]=0
    P[c1]=c2
    P[c2]=c1

    while Q:
        x=Q.pop()
        TOP_SORT.append(x)
        for to in E[x]:
            if D[to]==-1:
                D[to]=D[x]+1
                Q.append(to)
                P[to]=x

    DP=[[[0,0,0] for i in range(3)] for i in range(N+1)]
    # DP[x][p][m]で, plusのものが0個, 1個, 2個以上, minusのものが0個, 1個, 2個以上

    for x in TOP_SORT[::-1]:
        if D[x]==MAX//2:
            DP[x][1][1]=1

        elif len(E[x])==1:
            DP[x][0][0]=1

        else:
            for to in E[x]:
                if to==P[x]:
                    continue

                X=[[0,0,0] for i in range(3)]
                for i in range(3):
                    for j in range(3):
                        X[0][0]+=DP[to][i][j]
                        X[i][0]+=DP[to][i][j]
                        X[0][j]+=DP[to][i][j]

                if DP[x]==[[0,0,0] for i in range(3)]:
                    DP[x]=X

                else:
                    Y=[[0,0,0] for i in range(3)]

                    for i in range(3):
                        for j in range(3):
                            for k in range(3):
                                for l in range(3):
                                    Y[min(2,i+k)][min(2,j+l)]=(Y[min(2,i+k)][min(2,j+l)]+X[i][j]*DP[x][k][l])%mod

                    DP[x]=Y

    #print(DP[c1])
    #print(DP[c2])
    print(sum(DP[c1][1])*sum(DP[c2][1])%mod)
```


p02887 AtCoder Beginner Contest 143 - Slimes

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

Ultimately, how many slimes will be there?

Constraints

* 1 \leq N \leq 10^5
* |S| = N
* S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the final number of slimes.

Examples

Input

10
aabbbbaaca

Output

5

Input

5
aaaaa

Output

1

Input

20
xxzaffeeeeddfkkkkllq

Output

10

```python
n=int(input())
cnt=0
s=input()
for i in range(1,n):
  if s[i]!=s[i-1]:
    cnt+=1
print(cnt+1)
```


p03022 AtCoder Grand Contest 034 - RNG and XOR

Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i. The process of generating an integer is done independently each time the generator is executed.

Snuke has an integer X, which is now 0. He can perform the following operation any number of times:

* Generate an integer v with the generator and replace X with X \oplus v, where \oplus denotes the bitwise XOR.

For each integer i (0 \leq i \leq 2^N-1), find the expected number of operations until X becomes i, and print it modulo 998244353. More formally, represent the expected number of operations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353, so print this R.

We can prove that, for every i, the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined.

Constraints

* 1 \leq N \leq 18
* 1 \leq A_i \leq 1000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_0 A_1 \cdots A_{2^N-1}

Output

Print 2^N lines. The (i+1)-th line (0 \leq i \leq 2^N-1) should contain the expected number of operations until X becomes i, modulo 998244353.

Examples

Input

2
1 1 1 1

Output

0
4
4
4

Input

2
1 2 1 2

Output

0
499122180
4
499122180

Input

4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355

Output

0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908

```python
# Σ(i ^ j = k) ai * bj = ckという形で式が表されるとき
# fwht(a)*fwht(b)=fwht(c)が成り立ち高速化できる
# すごく必死に考えると
# a = [p0 p1 p2 ... p2^N-1]
# b = [x0 x1 x2 ... x2^N-1]
# c = [2^N-1 -1 -1 -1 .... -1]
# とするとうまいことaとcに変数が入らない形になるのでfwht(c)/fwht(a)を計算し
# fwht(b)がわかるのでこれを逆変換すればbが求められる
# なお逆変換は b = fwht(fwht(b)) / 要素数で求められる、なぜかは知らない
# またまたなぜかは知らないがこうして求めた答えは各要素に定数が足されたものになるらしい
# 今回はx0 = 0と分かっているのbを[0 x1-x0 ... x2^N-1-x0]と補正してやればよい

N = int(input())
A = [int(i) for i in input().split()]
MOD = 998244353

NN = 1 << N

def fwht(a) :
    i = 1
    while i < NN :
        j = 0
        while j < NN :
            for k in range(i) :
                x, y = a[j+k], a[i+j+k]
                a[j+k], a[i+j+k] = (x + y) % MOD, (x - y) % MOD
            j += i << 1
        i <<= 1

def inv(x) :
    return pow(x, MOD - 2, MOD)

s = inv(sum(A) % MOD)
for i in range(NN) :
    A[i] = (A[i] * s) % MOD
A[0] = (A[0] - 1) % MOD
fwht(A)

B = [- 1] * (NN)
B[0] = (NN-1) % MOD
fwht(B)

C = [(inv(A[i]) * B[i]) % MOD for i in range(NN)]
fwht(C)

for i in range(NN) :
    C[i] = (C[i] * inv(NN)) % MOD

for i in range(NN) :
    print((C[i] - C[0]) % MOD)
```


p03162 Educational DP Contest - Vacation

Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.

The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:

* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.

As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.

Find the maximum possible total points of happiness that Taro gains.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N

Output

Print the maximum possible total points of happiness that Taro gains.

Examples

Input

3
10 40 70
20 50 80
30 60 90

Output

210

Input

1
100 10 1

Output

100

Input

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

Output

46

```python
n=int(input())
a,b,c=map(int,input().split())
for _ in range(1,n):
    aa,bb,cc=map(int,input().split())
    a,b,c=aa+max(b,c),bb+max(a,c),cc+max(a,b)
print(max(a,b,c))

```


p03305 SoundHound Inc. Programming Contest 2018 -Masters Tournament- - Saving Snuuk

Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally. Any city can be reached from any city by changing trains.

Two currencies are used in the country: yen and snuuk. Any train fare can be paid by both yen and snuuk. The fare of the i-th train is a_i yen if paid in yen, and b_i snuuk if paid in snuuk.

In a city with a money exchange office, you can change 1 yen into 1 snuuk. However, when you do a money exchange, you have to change all your yen into snuuk. That is, if Kenkoooo does a money exchange when he has X yen, he will then have X snuuk. Currently, there is a money exchange office in every city, but the office in City i will shut down in i years and can never be used in and after that year.

Kenkoooo is planning to depart City s with 10^{15} yen in his pocket and head for City t, and change his yen into snuuk in some city while traveling. It is acceptable to do the exchange in City s or City t.

Kenkoooo would like to have as much snuuk as possible when he reaches City t by making the optimal choices for the route to travel and the city to do the exchange. For each i=0,...,n-1, find the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i years. You can assume that the trip finishes within the year.

Constraints

* 2 \leq n \leq 10^5
* 1 \leq m \leq 10^5
* 1 \leq s,t \leq n
* s \neq t
* 1 \leq u_i < v_i \leq n
* 1 \leq a_i,b_i \leq 10^9
* If i\neq j, then u_i \neq u_j  or v_i \neq v_j.
* Any city can be reached from any city by changing trains.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

n m s t
u_1 v_1 a_1 b_1
:
u_m v_m a_m b_m

Output

Print n lines. In the i-th line, print the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i-1 years.

Examples

Input

4 3 2 3
1 4 1 100
1 2 1 10
1 3 20 1

Output

999999999999998
999999999999989
999999999999979
999999999999897

Input

8 12 3 8
2 8 685087149 857180777
6 7 298270585 209942236
2 4 346080035 234079976
2 5 131857300 22507157
4 8 30723332 173476334
2 6 480845267 448565596
1 4 181424400 548830121
4 5 57429995 195056405
7 8 160277628 479932440
1 6 475692952 203530153
3 5 336869679 160714712
2 7 389775999 199123879

Output

999999574976994
999999574976994
999999574976994
999999574976994
999999574976994
999999574976994
999999574976994
999999574976994

```python
import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools
from heapq import heappush, heappop, heappushpop, heapify, heapreplace

N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for _ in range(M)]
G1 = collections.defaultdict(lambda: collections.defaultdict(int))
G2 = collections.defaultdict(lambda: collections.defaultdict(int))

for u, v, a, b in UVAB:
    u -= 1
    v -= 1
    G1[u][v] = G1[v][u] = a
    G2[u][v] = G2[v][u] = b

def dijkstra(V, G, start):
    INF = float('inf')
    D = [INF for _ in range(V)]
    D[start] = 0
    H = [(0, start)]
    while H:
        du, u = heappop(H)
        if D[u] < du:
            continue
        for v, d in G[u].items():
            if D[v] > du + d:
                D[v] = du + d
                heappush(H, (D[v], v))
    return D

D1 = dijkstra(N, G1, S - 1)
D2 = dijkstra(N, G2, T - 1)

D = [10**15 - sum(_) for _ in zip(D1, D2)]
for i in range(N - 1, 0, -1):
    D[i - 1] = max(D[i - 1], D[i])
print(*D, sep='\n')

```


p03465 AtCoder Grand Contest 020 - Median Sum

You are given N integers A_1, A_2, ..., A_N.

Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.

Let the list of these sums in non-decreasing order be S_1, S_2, ..., S_{2^N - 1}.

Find the median of this list, S_{2^{N-1}}.

Constraints

* 1 \leq N \leq 2000
* 1 \leq A_i \leq 2000
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the median of the sorted list of the sums of all non-empty subsequences of A.

Examples

Input

3
1 2 1

Output

2

Input

1
58

Output

58

```python
n = int(input())
a = list(map(int, input().split()))
d = (sum(a)+1)//2
c = 1
for x in a:
  c |= c << x
c >>= d
for i in range(d+5):
  if c & (1 << i):
    print(d+i)
    break
```


p03625 AtCoder Beginner Contest 071 - Make a Rectangle

We have N sticks with negligible thickness. The length of the i-th stick is A_i.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.

Constraints

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

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.

Examples

Input

6
3 1 2 4 2 1

Output

2

Input

4
1 2 3 4

Output

0

Input

10
3 3 3 3 4 4 4 5 5 5

Output

20

```python
N = int(input())
A = sorted([int(_) for _ in input().split()], reverse=True)

e = []
pre = 0
for i in range(N):
    if pre == A[i]:
        e.append(A[i])
        if len(e) >= 2: break
        pre = 0
    else:
        pre = A[i]
if len(e) < 2: print(0)
else: print(e[0] * e[1])
```


p03785 AtCoder Grand Contest 011 - Airport Bus

Every day, N passengers arrive at Takahashi Airport. The i-th passenger arrives at time T_i.

Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers. Naturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport. Also, a passenger will get angry if he/she is still unable to take a bus K units of time after the arrival of the airplane. For that reason, it is necessary to arrange buses so that the i-th passenger can take a bus departing at time between T_i and T_i + K (inclusive).

When setting the departure times for buses under this condition, find the minimum required number of buses. Here, the departure time for each bus does not need to be an integer, and there may be multiple buses that depart at the same time.

Constraints

* 2 \leq N \leq 100000
* 1 \leq C \leq 10^9
* 1 \leq K \leq 10^9
* 1 \leq T_i \leq 10^9
* C, K and T_i are integers.

Input

The input is given from Standard Input in the following format:

N C K
T_1
T_2
:
T_N

Output

Print the minimum required number of buses.

Examples

Input

5 3 5
1
2
3
6
12

Output

3

Input

6 3 3
7
6
2
8
10
6

Output

3

```python
N,C,K=map(int,input().split())
T=[int(input()) for i in range(N)]
T.sort()
S=[[T[0]]]
t=T[0]
k=0
for i in range(1,N):
    if T[i]<=t+K and len(S[k])<C:
        S[k].append(T[i])
    else:
        k+=1
        S.append([T[i]])
        t=T[i]
print(len(S))

```


p03953 AtCoder Grand Contest 006 - Rabbit Exercise

There are N rabbits on a number line. The rabbits are conveniently numbered 1 through N. The coordinate of the initial position of rabbit i is x_i.

The rabbits will now take exercise on the number line, by performing sets described below. A set consists of M jumps. The j-th jump of a set is performed by rabbit a_j (2≤a_j≤N-1). For this jump, either rabbit a_j-1 or rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit x), then rabbit a_j will jump to the symmetric point of its current position with respect to rabbit x.

The rabbits will perform K sets in succession. For each rabbit, find the expected value of the coordinate of its eventual position after K sets are performed.

Constraints

* 3≤N≤10^5
* x_i is an integer.
* |x_i|≤10^9
* 1≤M≤10^5
* 2≤a_j≤N-1
* 1≤K≤10^{18}

Input

The input is given from Standard Input in the following format:

N
x_1 x_2 ... x_N
M K
a_1 a_2 ... a_M

Output

Print N lines. The i-th line should contain the expected value of the coordinate of the eventual position of rabbit i after K sets are performed. The output is considered correct if the absolute or relative error is at most 10^{-9}.

Examples

Input

3
-1 0 2
1 1
2

Output

-1.0
1.0
2.0

Input

3
1 -1 1
2 2
2 2

Output

1.0
-1.0
1.0

Input

5
0 1 3 6 10
3 10
2 3 4

Output

0.0
3.0
7.0
8.0
10.0

```python
n = int(input())
x = list(map(int,input().split()))
m,k = map(int,input().split())
a = list(map(int,input().split()))
b = []
x2 = []
c = []
for i in range(1,n):
  b.append(i-1)
  x2.append(x[i]-x[i-1])
for i in range(m):
  to = a[i]-1
  b[to],b[to-1] = b[to-1],b[to]
c = [-1] * (n-1)
for i in range(n-1):
  c[b[i]] = i
for i in range(60):
  x3 = [0]*(n-1)
  if k&(1<<i):
    for i in range(n-1):
      x3[c[i]] = x2[i]
    x2 = x3
  c2 = [-1] * (n-1)
  for i in range(n-1):
    c2[i] = c[c[i]]
  c = c2
s = x[0]
print(s)
for i in x2:
  s += i
  print(s)
```


p00043 Puzzle

There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.

The conditions for completing the puzzle are

* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.

Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.

For example, if the given string is 3456666777999

If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999

And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.

Input

The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.

Output

For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.

Example

Input

3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246

Output

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

```python
import sys
def f(c):
 if sum(c)in c:return 1
 if 5 in c:return 0
 if 4 in c:
  k=c.index(4);c[k]-=3
  if f(c):return 1
  c[k]+=3
 if 3 in c:
  k=c.index(3);c[k]-=3
  if f(c):return 1
  c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
   c[i]-=1;c[i+1]-=1;c[i+2]-=1
   if f(c):return 1
   c[i]+=1;c[i+1]+=1;c[i+2]+=1
n='123456789'
for e in sys.stdin:
 e=list(e)
 a=[i for i in n if f([(e+[i]).count(j)for j in n])]
 if a:print(*a)
 else:print(0)

```


p00175 Quaternary Notation

Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.

Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.

Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".

Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...

In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.

Create a program that converts the integer n input in decimal to decimal and outputs it.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.

The number of datasets does not exceed 2000.

Output

The result of conversion to quaternary number for each input data set is output on one line.

Example

Input

7
4
0
12
10
10000
-1

Output

13
10
0
30
22
2130100

```python
while True:
    v = int(input())
    if v == -1:
        break
    if v < 4:
        print(v)
    else:
        b = str(bin(v))[2:]
        bb = [b[i:i+2] for i in range(len(b)-2, -1, -2)]
        if len(b) % 2 != 0:
            bb.append(b[0])
        ans = []
        for t in bb:
            tmp = 0
            for i, v in enumerate(t[::-1]):
                tmp += pow(2, i) * int(v)
            ans.append(tmp)
        print(''.join(map(str, ans[::-1])))
```


p00331 Sunrise and Sunset

The appearance of the sun is called "sunrise" and the hiding is called "sunset". What is the exact time when the sun is on the horizon?

As shown in the figure below, we will represent the sun as a circle and the horizon as a straight line. At this time, the time of "sunrise" and "sunset" of the sun is the moment when the upper end of the circle representing the sun coincides with the straight line representing the horizon. After sunrise, the daytime is when the top of the circle is above the straight line, and nighttime is when the circle is completely hidden below the straight line.

<image>

Create a program that inputs the height from the horizon to the center of the sun at a certain time and the radius of the sun, and outputs whether the time is "daytime", "sunrise or sunset", or "nighttime".

Input

The input is given in the following format.

H R

The input consists of one line and is given the integer H (-1000 ≤ H ≤ 1000), which represents the height from the horizon at a certain time to the center of the sun, and the integer R (1 ≤ R ≤ 1000), which represents the radius. However, H is 0 when the center of the sun is on the horizon, positive when it is above it, and negative when it is below it.

Output

Outputs "1" in the daytime, "0" in the sunrise or sunset, and "-1" in the nighttime on one line.

Examples

Input

-3 3

Output

0

Input

3 3

Output

1

Input

-4 3

Output

-1

```python
h,r=map(int,input().split())
if h>=0:
    print(1)
elif h+r==0:
    print(0)
else:
    print(-1)

```


p00688 Factorization of Quadratic Formula

As the first step in algebra, students learn quadratic formulas and their factorization. Often, the factorization is a severe burden for them. A large number of students cannot master the factorization; such students cannot be aware of the elegance of advanced algebra. It might be the case that the factorization increases the number of people who hate mathematics.

Your job here is to write a program which helps students of an algebra course. Given a quadratic formula, your program should report how the formula can be factorized into two linear formulas. All coefficients of quadratic formulas and those of resultant linear formulas are integers in this problem.

The coefficients a, b and c of a quadratic formula ax2 + bx + c are given. The values of a, b and c are integers, and their absolute values do not exceed 10000. From these values, your program is requested to find four integers p, q, r and s, such that ax2 + bx + c = (px + q)(rx + s).

Since we are considering integer coefficients only, it is not always possible to factorize a quadratic formula into linear formulas. If the factorization of the given formula is impossible, your program should report that fact.

Input

The input is a sequence of lines, each representing a quadratic formula. An input line is given in the following format.

> a b c

Each of a, b and c is an integer. They satisfy the following inequalities.

> 0 < a <= 10000
>  -10000 <= b <= 10000
>  -10000 <= c <= 10000

The greatest common divisor of a, b and c is 1. That is, there is no integer k, greater than 1, such that all of a, b and c are divisible by k.

The end of input is indicated by a line consisting of three 0's.

Output

For each input line, your program should output the four integers p, q, r and s in a line, if they exist. These integers should be output in this order, separated by one or more white spaces. If the factorization is impossible, your program should output a line which contains the string "Impossible" only.

The following relations should hold between the values of the four coefficients.

> p > 0
>  r > 0
>  (p > r) or (p = r and q >= s)

These relations, together with the fact that the greatest common divisor of a, b and c is 1, assure the uniqueness of the solution. If you find a way to factorize the formula, it is not necessary to seek another way to factorize it.

Example

Input

2 5 2
1 1 1
10 -7 0
1 0 -3
0 0 0

Output

2 1 1 2
Impossible
10 -7 1 0
Impossible

```python
import fractions

while True:
    a, b, c = map(int, input().split())
    if not a:
        break
    d = (b ** 2 - 4 * a * c) ** 0.5
    if isinstance(d, complex) or d - int(d) > 1e-6:
        print('Impossible')
        continue
    num1, num2 = -b + int(d), -b - int(d)
    den = 2 * a
    cmn1, cmn2 = fractions.gcd(num1, den), fractions.gcd(num2, den)
    p, q, r, s = den // cmn1, -num1 // cmn1, den // cmn2, -num2 // cmn2
    if (p, q) < (r, s):
        p, q, r, s = r, s, p, q
    print(p, q, r, s)
```