### Prompt

Construct a cpp code solution to the problem outlined:

Snuke has an integer sequence A of length N.

He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen.

Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller. Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.

Constraints

* 4 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.

Examples

Input

5
3 2 4 1 2

Output

2

Input

10
10 71 84 33 6 47 23 25 52 64

Output

36

Input

7
1 2 3 1000000000 4 5 6

Output

999999994

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
long long sum[200005],res=1e18;
void get(int l,int r,long long &x,long long &y)
{
	long long res=1e18;
	int lef=l,rig=r-1;
	while (lef<=rig)
	{
		int m=lef+rig>>1;
		long long a=sum[m]-sum[l-1];
		long long b=sum[r]-sum[m];
		if (abs(a-b)<res)
		{
			res=abs(a-b);
			x=a;y=b;
		}
		if (a<=b) lef=m+1;
		else rig=m-1;
	}
}
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		sum[i]=x+sum[i-1];
	}
	for (int i=2;i<=n-2;i++)
	{
		long long a,b,c,d;
		get(1,i,a,b);
		get(i+1,n,c,d);
		res=min(res,max({a,b,c,d})-min({a,b,c,d}));
	}
	cout<<res<<endl;
	return 0;
}
```


### Prompt

Please provide a cpp coded solution to the problem described below:

A rabbit who came to the fair found that the prize for a game at a store was a carrot cake. The rules for this game are as follows.

There is a grid-like field of vertical h squares x horizontal w squares, and each block has at most one block. Each block is a color represented by one of the uppercase letters ('A'-'Z'). When n or more blocks of the same color are lined up in a straight line vertically or horizontally, those blocks disappear.

Participants can select two adjacent cells next to each other and switch their states to each other. When blocks are exchanged, disappeared, or dropped and there are no blocks in the cell below the cell with the block, this block At this time, it disappears when n or more blocks of the same color are lined up again. However, the disappearance of the blocks does not occur while the falling blocks exist, and occurs at the same time when all the blocks have finished falling.

If you eliminate all the blocks on the field with one operation, this game will be successful and you will get a free gift cake. Rabbit wants to get the cake with one entry fee, can not do it If you don't want to participate. From the state of the field at the beginning of the game, answer if the rabbit should participate in this game.

Input

The first line of input is given h, w, n separated by spaces.

2 ≤ h, w, n ≤ 30

In the following h lines, the state of the field is given in order from the top. Uppercase letters represent blocks, and'.' Represents an empty space. The state of the given field is n or more consecutive blocks of the same color in the vertical or horizontal direction. No, no blocks are in a falling state. There is one or more blocks.

Output

Output "YES" if the rabbit should participate in this game, otherwise output "NO" on one line.

Examples

Input

4 6 3
......
...Y..
...Y..
RRYRYY

Output

YES

Input

4 6 3
......
...Y..
...Y..
RRYRY.

Output

NO

### Response

```cpp
#include<iostream>
#include<vector>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int di[2] = {0,1};
int dj[2] = {1,0};

int h, w, n;

bool check(vector<string> v){
    // まず落下
    for(int i = h-2; i >= 0; i--){
        for(int j = 0; j < w; j++){
            if(v[i][j] == '.')  continue;
            int cp = i;
            while(cp+1 < h && v[cp+1][j] == '.'){
                swap(v[cp][j], v[cp+1][j]);
                cp++;
            }
        }
    }
    bool update = true;
    while(update){
        update = false;
        vector<vector<bool>> erase(h, vector<bool>(w, 0));
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(v[i][j] == '.')  continue;
                for(int k = 0; k < 2; k++){
                    int ni = i+di[k], nj = j+dj[k], cnt = 1;
                    while(inRange(ni,0,h)&&inRange(nj,0,w)&&v[ni][nj]==v[i][j]){
                        ni += di[k], nj += dj[k], cnt++;
                    }
                    if(cnt < n) continue;
                    update = true;
                    do{
                        ni -= di[k], nj -= dj[k];
                        erase[ni][nj] = true;
                    }while(ni != i || nj != j);
                }
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(erase[i][j]) v[i][j] = '.';
            }
        }
        for(int i = h-2; i >= 0; i--){
            for(int j = 0; j < w; j++){
                if(v[i][j] == '.')  continue;
                int cp = i;
                while(cp+1 < h && v[cp+1][j] == '.'){
                    update = true;
                    swap(v[cp][j], v[cp+1][j]);
                    cp++;
                }
            }
        }
    }
    bool ret = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            ret &= v[i][j]=='.';
        }
    }
    return ret;
}

int main(){
    cin >> h >> w >> n;
    vector<string> v(h);
    for(int i = 0; i < h; i++)  cin >> v[i];
    bool valid = false;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int ni = i+di[0], nj = j+dj[0];
            if(!inRange(ni,0,h) || !inRange(nj,0,w) || v[i][j]==v[ni][nj]){
                continue;
            }
            swap(v[i][j], v[ni][nj]);
            valid |= check(v);
            swap(v[i][j], v[ni][nj]);
        }
    }
    cout << (valid ? "YES" : "NO") << endl;
    return 0;
}

```


### Prompt

Your task is to create a Cpp solution to the following problem:

Dreamoon likes coloring cells very much.

There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.

You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)

Dreamoon will perform m operations.

In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.

Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.

Input

The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).

The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).

Output

If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).

Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.

If there are several possible solutions, you can print any.

Examples

Input

5 3
3 2 2

Output

2 4 1

Input

10 1
1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long ans[+400500], l[+400500], sum, n, i, m, j;
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  iostream::sync_with_stdio(0);
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (i = 1; i <= m; i++) cin >> l[i], sum += l[i];
  if (sum < n)
    cout << "-1";
  else {
    ans[1] = 1;
    sum -= l[1];
    i = 2;
    j = 2;
    while (i <= n) {
      if (sum < n - i + 1)
        i++;
      else
        ans[j++] = i, sum -= l[j - 1], i++;
    }
    if (j <= m) {
      cout << "-1";
      return 0;
    }
    for (i = 1; i <= m; i++) {
      if (ans[i] + l[i] - 1 > n) {
        cout << "-1";
        return 0;
      }
    }
    for (i = 1; i <= m; i++) cout << ans[i] << " ";
  }
}

```


### Prompt

Your task is to create a Cpp solution to the following problem:

Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something.

Denis bought a mysterious item and it was... Random permutation generator! Denis could not believed his luck.

When he arrived home, he began to study how his generator works and learned the algorithm. The process of generating a permutation consists of n steps. At the i-th step, a place is chosen for the number i (1 ≤ i ≤ n). The position for the number i is defined as follows:

  * For all j from 1 to n, we calculate r_j — the minimum index such that j ≤ r_j ≤ n, and the position r_j is not yet occupied in the permutation. If there are no such positions, then we assume that the value of r_j is not defined.
  * For all t from 1 to n, we calculate count_t — the number of positions 1 ≤ j ≤ n such that r_j is defined and r_j = t.
  * Consider the positions that are still not occupied by permutation and among those we consider the positions for which the value in the count array is maximum.
  * The generator selects one of these positions for the number i. The generator can choose any position.

Let's have a look at the operation of the algorithm in the following example:

<image>

Let n = 5 and the algorithm has already arranged the numbers 1, 2, 3 in the permutation. Consider how the generator will choose a position for the number 4:

  * The values of r will be r = [3, 3, 3, 4, ×], where × means an indefinite value.
  * Then the count values will be count = [0, 0, 3, 1, 0].
  * There are only two unoccupied positions in the permutation: 3 and 4. The value in the count array for position 3 is 3, for position 4 it is 1.
  * The maximum value is reached only for position 3, so the algorithm will uniquely select this position for number 4.

Satisfied with his purchase, Denis went home. For several days without a break, he generated permutations. He believes that he can come up with random permutations no worse than a generator. After that, he wrote out the first permutation that came to mind p_1, p_2, …, p_n and decided to find out if it could be obtained as a result of the generator.

Unfortunately, this task was too difficult for him, and he asked you for help. It is necessary to define whether the written permutation could be obtained using the described algorithm if the generator always selects the position Denis needs.

Input

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

The first line of the test case contains a single integer n (1 ≤ n ≤ 10^5) — the size of the permutation.

The second line of the test case contains n different integers p_1, p_2, …, p_n (1 ≤ p_i ≤ n) — the permutation written by Denis.

It is guaranteed that the sum of n over all test cases doesn't exceed 10^5.

Output

Print "Yes" if this permutation could be obtained as a result of the generator. Otherwise, print "No".

All letters can be displayed in any case.

Example

Input

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

Output

Yes
Yes
No
Yes
No

Note

Let's simulate the operation of the generator in the first test.

At the 1 step, r = [1, 2, 3, 4, 5], count = [1, 1, 1, 1, 1]. The maximum value is reached in any free position, so the generator can choose a random position from 1 to 5. In our example, it chose 5.

At the 2 step, r = [1, 2, 3, 4, ×], count = [1, 1, 1, 1, 0]. The maximum value is reached in positions from 1 to 4, so the generator can choose a random position among them. In our example, it chose 1.

At the 3 step, r = [2, 2, 3, 4, ×], count = [0, 2, 1, 1, 0]. The maximum value is 2 and is reached only at the 2 position, so the generator will choose this position.

At the 4 step, r = [3, 3, 3, 4, ×], count = [0, 0, 3, 1, 0]. The maximum value is 3 and is reached only at the 3 position, so the generator will choose this position.

At the 5 step, r = [4, 4, 4, 4, ×], count = [0, 0, 0, 4, 0]. The maximum value is 4 and is reached only at the 4 position, so the generator will choose this position.

In total, we got a permutation of 2, 3, 4, 5, 1, that is, a generator could generate it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int cnt[N + 100], vis[N + 100];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    set<pair<int, int> > stp;
    set<int> sti;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      int p;
      scanf("%d", &p);
      vis[p] = i;
      stp.insert(make_pair(1, i));
      sti.insert(i);
      cnt[i] = 1;
    }
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      auto e = stp.end();
      e--;
      int cur = vis[i];
      if (e->first != cnt[cur]) {
        flag = false;
        break;
      }
      sti.erase(cur);
      stp.erase(make_pair(cnt[cur], cur));
      auto nxt = sti.lower_bound(cur);
      if (nxt != sti.end()) {
        int del = *nxt;
        stp.erase(make_pair(cnt[del], del));
        cnt[del] += cnt[cur];
        stp.insert(make_pair(cnt[del], del));
      }
    }
    if (flag == true) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Given is a string S, where each character is `0`, `1`, or `?`.

Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows:

* (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\}

Find the minimum possible unbalancedness of S'.

Constraints

* 1 \leq |S| \leq 10^6
* Each character of S is `0`, `1`, or `?`.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum possible unbalancedness of S'.

Examples

Input

0??

Output

1

Input

0??0

Output

2

Input

??00????0??0????0?0??00??1???11?1?1???1?11?111???1

Output

4

### Response

```cpp
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int INF=1e9;

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>>S;
    int N = S.size();
    vi sum(N+1);
    rep(i,N){
        if (S[i]=='0') sum[i+1]=sum[i]+1;
        else sum[i+1]=sum[i]-1;
    }
    vi maxi(N+1,-INF);
    RFOR(i,N-1,0){
        maxi[i] = max(maxi[i+1],sum[i+1]);
    }

    auto getDiff = [&](int x){
        int res=0;
        int c=0;
        rep(i,N){
            if (S[i]=='?' && maxi[i]+c+2<=x) c+=2;
            chmin(res,sum[i+1]+c);
        }
        return x-res;
    };
    int minMax = max(0,maxi[0]);
    int ans=min(getDiff(minMax), getDiff(minMax+1));
    cout<<ans<<"\n";
    return 0;
}

```


### Prompt

In Cpp, your task is to solve the following problem:

problem

One day in the cold winter, JOI Taro decided to break the thin ice in the plaza and play. The square is rectangular and is divided into m sections in the east-west direction and n sections in the north-south direction, that is, m × n. In addition, there are sections with and without thin ice. JOI Taro decided to move the plot while breaking the thin ice according to the following rules.

* You can start breaking thin ice from any compartment with thin ice.
* Adjacent to either north, south, east, or west, you can move to a section with thin ice that has not yet been broken.
* Be sure to break the thin ice in the area you moved to.

Create a program to find the maximum number of sections that JOI Taro can move while breaking thin ice. However, 1 ≤ m ≤ 90 and 1 ≤ n ≤ 90. With the input data given, there are no more than 200,000 ways to move.

input

The input consists of multiple datasets. Each dataset is given in the following format.

The input is n + 2 lines. The integer m is written on the first line. The integer n is written on the second line. In each line from the 3rd line to the n + 2nd line, m 0s or 1s are written, separated by blanks, and indicates whether or not there is thin ice in each section. If we write the i-th section from the north and the j-th section from the west as (i, j) (1 ≤ i ≤ n, 1 ≤ j ≤ m), the j-th value on the second line of i + 2 is It is 1 if there is thin ice in compartment (i, j) and 0 if there is no thin ice in compartment (i, j).

When both m and n are 0, it indicates the end of input. The number of data sets does not exceed 5.

output

Output the maximum number of sections that can be moved for each data set on one line.

Examples

Input

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

Output

5
5

Input

None

Output

None

### Response

```cpp
#include<stdio.h>

bool map[ 92 ][ 92 ] ;

int mx[] = { 0 ,1 ,-1 ,0 } ;
int my[] = { 1 ,0 ,0 ,-1 } ;

int ans ;

int move( int y ,int x ,int cnt )
{
	map[ y ][ x ] = false ;

	if( cnt > ans )
	{
		ans = cnt ;
	}

	for( int i = 0 ; i < 4 ; i++ )
	{
		int yy = y + my[ i ] ;
		int xx = x + mx[ i ] ;

		if( map[ yy ][ xx ] == true )
		{
			move( yy ,xx ,cnt + 1 )	;
		}
	}

	map[ y ][ x ] = true ;

	return ans ;
}

int main()
{
	int h ,w ;

	while( true )
	{
		scanf( "%d %d" ,&h ,&w ) ;

		if( w == h && !w )
		{
			return 0 ;
		}

		ans = 0 ;

		for( int i = 1 ; i <= h ; i++ )
		{
			for( int j = 1 ; j <= w ; j++ )
			{
				scanf( "%d" ,&map[ i ][ j ] ) ;
			}
		}

		for( int i = 1 ; i <= h ; i++ )
		{
			for( int j = 1 ; j <= w ; j++ )
			{
				if( map[ i ][ j ] == 1 )
				{
					int ans_ = move( i ,j ,1 ) ;
					ans = ans < ans_ ? ans_ : ans ;
				}
			}
		}

		printf( "%d\n" ,ans ) ;
	}
}
```


### Prompt

Your challenge is to write a cpp solution to the following problem:

Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.

Ivan represent his array with increasing sequences with help of the following algorithm.

While there is at least one unused number in array Ivan repeats the following procedure:

  * iterate through array from the left to the right;
  * Ivan only looks at unused numbers on current iteration;
  * if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down.

For example, if Ivan's array looks like [1, 3, 2, 5, 4] then he will perform two iterations. On first iteration Ivan will use and write numbers [1, 3, 5], and on second one — [2, 4].

Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of elements in Ivan's array.

The second line contains a sequence consisting of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — Ivan's array.

Output

Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line.

Examples

Input

5
1 3 2 5 4

Output

1 3 5
2 4

Input

4
4 3 2 1

Output

4
3
2
1

Input

4
10 30 50 101

Output

10 30 50 101

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn];
vector<int> g[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    int pos = lower_bound(b + 1, b + n + 1, a[i]) - b;
    pos--;
    b[pos] = a[i];
    g[pos].push_back(a[i]);
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < g[i].size(); j++) {
      cout << g[i][j] << " ";
    }
    cout << endl;
  }
}

```


### Prompt

Your challenge is to write a cpp solution to the following problem:

A pitch-black room

When I woke up, Mr. A was in a pitch-black room. Apparently, Mr. A got lost in a dungeon consisting of N rooms. You couldn't know which room A got lost in, but fortunately he got a map of the dungeon. Let's show A the way to go and lead to a bright room.

It is known that M of the N rooms are pitch black, and the D_1, D_2, ..., and D_Mth rooms are pitch black, respectively. Also, there are exactly K one-way streets from all the rooms in order, and the roads from the i-th room are v_ {i, 1}, v_ {i, 2}, ..., v_ {i, respectively. , K} Connected to the third room. You can follow the a_1, a_2, ..., a_lth roads in order from the room you are in for Mr. A. However, when Mr. A reaches the bright room, he ignores the subsequent instructions. You cannot know the information of the room where Mr. A is currently before and after the instruction, so you must give the instruction sequence so that you can reach the bright room no matter which room you are in. Answer the length of the shortest of such instructions.

Constraints

* 2 ≤ N ≤ 100
* 1 ≤ M ≤ min (16, N − 1)
* 1 ≤ K ≤ N
* 1 ≤ D_i ≤ N
* D_i are all different
* 1 ≤ v_ {i, j} ≤ N
* All dark rooms can reach at least one bright room

Input Format

Input is given from standard input in the following format.

NMK
D_1 D_2 ... D_M
v_ {1,1} v_ {1,2} ... v_ {1,K}
v_ {2,1} v_ {2,2} ... v_ {2, K}
...
v_ {N, 1} v_ {N, 2} ... v_ {N, K}

Output Format

Print the answer in one line.

Sample Input 1

4 2 2
1 2
twenty four
3 1
4 2
13

Sample Output 1

2

<image>
If you give the instruction 1, 1

* If A's initial position is room 1, the second move will reach room 3.
* If A's initial position is room 2, the first move will reach room 3.

Sample Input 2

3 2 2
1 2
twenty three
1 2
twenty one

Sample Output 2

3

<image>
If you give instructions 2, 1, 2

* If A's initial position is room 1, the first move will reach room 3.
* If A's initial position is room 2, the third move will reach room 3.

Sample Input 3

6 3 3
one two Three
4 1 1
2 5 2
3 3 6
4 4 4
5 5 5
6 6 6

Sample Output 3

3

<image>
Beware of unconnected cases and cases with self-edges and multiple edges.

Example

Input

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

Output

2

### Response

```cpp
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m,k;
    cin>>n>>m>>k;
    vi d(m);
    rep(i,m){
        cin>>d[i];
        d[i]--;
    }
    vvi v(n,vi(k));
    rep(i,n)rep(j,k){
        cin>>v[i][j];
        v[i][j]--;
    }
    int id[n];
    memset(id,-1,sizeof(id));
    rep(i,m)id[d[i]]=i;
    int dp[1<<m];
    memset(dp,-1,sizeof(dp));
    dp[(1<<m)-1]=0;
    queue<int> q;
    q.push((1<<m)-1);
    while(!q.empty()){
        int s=q.front();
        q.pop();
        rep(i,k){
            int ns=s;
            int mask=0;
            rep(j,m){
                if((s>>j)&1){
                    ns^=(1<<j);
                    if(~id[v[d[j]][i]])mask|=1<<id[v[d[j]][i]];
                }
            }
            ns|=mask;
            if(!~dp[ns]&&s!=ns){
                dp[ns]=dp[s]+1;
                q.push(ns);
            }
        }
    }
    cout<<dp[0]<<endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

There are n balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the i-th ball is ci and the value of the i-th ball is vi.

Squirrel Liss chooses some balls and makes a new sequence without changing the relative order of the balls. She wants to maximize the value of this sequence.

The value of the sequence is defined as the sum of following values for each ball (where a and b are given constants):

  * If the ball is not in the beginning of the sequence and the color of the ball is same as previous ball's color, add (the value of the ball)  ×  a.
  * Otherwise, add (the value of the ball)  ×  b.

You are given q queries. Each query contains two integers ai and bi. For each query find the maximal value of the sequence she can make when a = ai and b = bi.

Note that the new sequence can be empty, and the value of an empty sequence is defined as zero.

Input

The first line contains two integers n and q (1 ≤ n ≤ 105; 1 ≤ q ≤ 500). The second line contains n integers: v1, v2, ..., vn (|vi| ≤ 105). The third line contains n integers: c1, c2, ..., cn (1 ≤ ci ≤ n).

The following q lines contain the values of the constants a and b for queries. The i-th of these lines contains two integers ai and bi (|ai|, |bi| ≤ 105).

In each line integers are separated by single spaces.

Output

For each query, output a line containing an integer — the answer to the query. The i-th line contains the answer to the i-th query in the input order.

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

Examples

Input

6 3
1 -2 3 4 0 -1
1 2 1 2 1 1
5 1
-2 1
1 0

Output

20
9
4

Input

4 1
-3 6 -1 2
1 2 3 1
1 -1

Output

5

Note

In the first example, to achieve the maximal value:

  * In the first query, you should select 1st, 3rd, and 4th ball.
  * In the second query, you should select 3rd, 4th, 5th and 6th ball.
  * In the third query, you should select 2nd and 4th ball.

Note that there may be other ways to achieve the maximal value.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b;
long long pd[110000];
long long v[110000], c[110000];
int prox[110000];
long long best[110000];
map<int, int> mapa;
bool ja[110000];
pair<long long, long long> atualiza(pair<long long, long long> a, long long x,
                                    long long ant) {
  if (a.first == ant) return make_pair(x, a.second);
  if (a.second == ant) {
    long long c = a.first, d = x;
    return make_pair(max(c, d), min(c, d));
  }
  if (x > a.first) return make_pair(x, a.first);
  return make_pair(a.first, max(a.second, x));
}
int main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) cin >> c[i], c[i]--;
  multiset<int> S;
  while (q--) {
    memset(pd, -1, sizeof pd);
    cin >> a >> b;
    memset(best, 0, sizeof best);
    for (int i = 0; i < n; i++) best[i] = -(1LL << 50);
    memset(ja, 0, sizeof ja);
    S.clear();
    pair<long long, long long> ans = make_pair(0, 0);
    for (int i = 0; i < n; i++) {
      long long sem;
      if (ans.first == best[c[i]])
        sem = ans.second;
      else
        sem = ans.first;
      long long aux = sem + b * v[i];
      if (ja[c[i]]) aux = max(aux, best[c[i]] + a * v[i]);
      long long ant = best[c[i]];
      best[c[i]] = max(best[c[i]], aux);
      ja[c[i]] = 1;
      if (ant != best[c[i]]) ans = atualiza(ans, best[c[i]], ant);
    }
    long long ret = 0;
    for (int i = 0; i < n; i++) ret = max(ret, best[i]);
    cout << ret << endl;
  }
  return 0;
}

```


### Prompt

Your task is to create a cpp solution to the following problem:

One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.

Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.

Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.

More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that <image> is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).

Input

The first line contains two integers n and m (1 ≤ m ≤ n ≤ 109) — the range of numbers in the game, and the number selected by Misha respectively.

Output

Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.

Examples

Input

3 1

Output

2

Input

4 3

Output

2

Note

In the first sample test: Andrew wins if c is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses a = 3, the probability of winning will be 1 / 3. If a = 1, the probability of winning is 0.

In the second sample test: Andrew wins if c is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of a the probability of winning is less.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  scanf("%lld%lld", &n, &m);
  int i, j;
  if (n == 1) {
    printf("1\n");
    return 0;
  } else if (n == 2) {
    if (m == 1)
      printf("2\n");
    else
      printf("1\n");
    return 0;
  }
  long long int d = n / 2;
  if (n % 2 == 0) {
    if (m == d)
      printf("%lld\n", d + 1);
    else if (m > d)
      printf("%lld\n", m - 1);
    else
      printf("%lld\n", m + 1);
  } else {
    d = d + 1;
    if (m == d)
      printf("%lld\n", d - 1);
    else if (m > d)
      printf("%lld\n", m - 1);
    else
      printf("%lld\n", m + 1);
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

<image>

A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You can obtain the proper sequence of all the tasks by a topological sort.

Given a DAG $G$, print the order of vertices after the topological sort.

Constraints

* $1 \leq |V| \leq 10,000$
* $0 \leq |E| \leq 100,000$
* There are no parallel edges in $G$
* There are no self loops in $G$

Input

A directed graph $G$ is given in the following format:
$|V|\;|E|$
$s_0 \; t_0$
$s_1 \; t_1$
:
$s_{|E|-1} \; t_{|E|-1}$

$|V|$ is the number of vertices and $|E|$ is the number of edges in the graph. The graph vertices are named with the numbers $0, 1,..., |V|-1$ respectively.

$s_i$ and $t_i$ represent source and target nodes of $i$-th edge (directed).

Output

Print the vertices numbers in order. Print a number in a line.

If there are multiple possible solutions, print any one of them (the solution is judged by a special validator).

Example

Input

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

Output

0
3
1
4
5
2

### Response

```cpp
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int V, E; cin >> V >> E;

  vector<vector<bool>> edge(V, vector<bool>(V, false));
  vector<int> in(V, 0);

  queue<int> no_incoming_edge;
  rep(i, E) {
    int s, t;
    cin >> s >> t;
    edge[s][t] = true;
    ++in[t];
  }
  rep(i, V) {
    if (in[i] == 0)
      no_incoming_edge.push(i);
  }
  vector<int> ans;
  while (!no_incoming_edge.empty()) {
    int p = no_incoming_edge.front(); no_incoming_edge.pop();
    ans.push_back(p);
    rep(to, V) {
      if (edge[p][to] == 1) {
        --in[to];
        if (in[to] == 0)
          no_incoming_edge.push(to);
      }
    }
  }
  rep(i, V)
    out(ans[i]);

  return 0;
}

```


### Prompt

Your challenge is to write a cpp solution to the following problem:

Lena is a programmer. She got a task to solve at work.

There is an empty set of pairs of integers and n queries to process. Each query is one of three types:

  1. Add a pair (a, b) to the set.
  2. Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
  3. For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set.

Help Lena to process the queries.

Input

The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries.

Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query.

A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type.

An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed.

An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.

Output

For the queries of the third type print on a separate line the desired maximal value of x·q + y.

If there are no pairs in the set print "EMPTY SET".

Example

Input

7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1

Output

EMPTY SET
5
99
5

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 3e5 + 5, oo = 2e18;
long long n, block_size, ans[N], a[N], b[N], type[N], time_end[N], n1, n2,
    process[N], n3, del[N];
pair<long long, long long> lines[N];
struct Line {
  long long a, b;
  Line() {}
  Line(long long _a, long long _b) : a(_a), b(_b) {}
  long long val(long long x) { return a * x + b; }
} st[N];
long long bad(Line a, Line b, Line c) {
  return (c.b - a.b) * (b.a - c.a) <= (c.b - b.b) * (a.a - c.a);
}
void addLine(Line a) {
  if (n3 && st[n3 - 1].a == a.a && st[n3 - 1].b == a.b) n3--;
  while (n3 >= 2 && bad(a, st[n3 - 1], st[n3 - 2])) n3--;
  st[n3++] = a;
}
long long query(long long x) {
  long long ans = -oo, l = 0, r = n3 - 1;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    ans = max(ans, st[mid].val(x));
    long long lmid = (mid == 0 ? -oo : st[mid - 1].val(x)),
              rmid = (mid == n3 - 1 ? -oo : st[mid + 1].val(x));
    if (lmid > rmid)
      r = mid - 1;
    else if (rmid > lmid)
      l = mid + 1;
    else
      break;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  clock_t T = clock();
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> type[i] >> a[i];
    if (type[i] == 1) cin >> b[i];
  }
  block_size = 3000;
  vector<long long> willadd, cur;
  cur.clear();
  for (long long L = 1; L <= n; L += block_size) {
    willadd.clear();
    n3 = 0;
    long long R = min(n, L + block_size - 1);
    for (long long i = L; i <= R; ++i)
      if (type[i] == 2 && a[i] < L) willadd.push_back(a[i]), del[a[i]] = 2;
    vector<pair<long long, long long> > V;
    V.clear();
    for (long long r : cur)
      if (del[r] == 0) V.push_back({a[r], b[r]});
    sort(V.begin(), V.end());
    for (pair<long long, long long> d : V) addLine(Line(d.first, d.second));
    for (long long j = L; j <= R; ++j) {
      if (type[j] == 1) willadd.push_back(j);
      if (type[j] == 2) del[a[j]] = 1;
      if (type[j] == 3) {
        ans[j] = -oo;
        for (long long r : willadd)
          if (del[r] != 1) ans[j] = max(ans[j], a[r] * a[j] + b[r]);
        ans[j] = max(ans[j], query(a[j]));
      }
    }
    for (long long r : willadd)
      if (del[r] == 0) cur.push_back(r);
  }
  for (long long i = 1; i <= n; ++i)
    if (type[i] == 3) {
      if (ans[i] == -oo)
        cout << "EMPTY SET" << '\n';
      else
        cout << ans[i] << '\n';
    }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.

Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.

Your task is to determine the number of options for the score the participant could have before the judges rated the participant.

Input

The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.

The second line contains k integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order.

The third line contains n distinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.

Output

Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).

Examples

Input

4 1
-5 5 0 20
10

Output

3

Input

2 2
-2000 -2000
3998000 4000000

Output

1

Note

The answer for the first example is 3 because initially the participant could have  - 10, 10 or 15 points.

In the second example there is only one correct initial score equaling to 4 002 000.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, k, ans = 0;
  cin >> k >> n;
  vector<int> a(k), b(n);
  vector<int> ps(k + 1, 0);
  for (int i = 0; i < k; i++) {
    cin >> a[i];
    ps[i + 1] = ps[i] + a[i];
  }
  multiset<int> s;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    s.insert(b[i]);
  }
  int b0 = b[0];
  set<int> ans1;
  for (int i = 0; i < k; i++) {
    multiset<int> cur(s);
    int stval = b0 - ps[i + 1];
    cur.erase(b0);
    for (int j = 0; j < k; j++) {
      if (j == i) continue;
      int crval = ps[j + 1] + stval;
      if (cur.size() == 0) {
        break;
      }
      if (cur.find(crval) != cur.end()) cur.erase(cur.find(crval));
    }
    if (cur.size() == 0) ans1.insert(stval);
  }
  cout << ans1.size() << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.

A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers b1, b2, ..., bm (m ≤ n). All numbers from the message and from the key belong to the interval from 0 to c - 1, inclusive, and all the calculations are performed modulo c.

Encryption is performed in n - m + 1 steps. On the first step we add to each number a1, a2, ..., am a corresponding number b1, b2, ..., bm. On the second step we add to each number a2, a3, ..., am + 1 (changed on the previous step) a corresponding number b1, b2, ..., bm. And so on: on step number i we add to each number ai, ai + 1, ..., ai + m - 1 a corresponding number b1, b2, ..., bm. The result of the encryption is the sequence a1, a2, ..., an after n - m + 1 steps.

Help the Beaver to write a program that will encrypt messages in the described manner.

Input

The first input line contains three integers n, m and c, separated by single spaces.

The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message.

The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key.

The input limitations for getting 30 points are:

  * 1 ≤ m ≤ n ≤ 103
  * 1 ≤ c ≤ 103

The input limitations for getting 100 points are:

  * 1 ≤ m ≤ n ≤ 105
  * 1 ≤ c ≤ 103

Output

Print n space-separated integers — the result of encrypting the original message.

Examples

Input

4 3 2
1 1 1 1
1 1 1

Output

0 1 1 0

Input

3 1 5
1 2 3
4

Output

0 1 2

Note

In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100000], b[100000], s[100000], s2[100000];
int main() {
  int n, m, c;
  cin >> n >> m >> c;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  s[0] = b[0];
  for (int i = 1; i < m; i++) s[i] = (s[i - 1] + b[i]);
  s2[0] = b[m - 1];
  for (int i = m - 2; i >= 0; i--) s2[m - i - 1] = (s2[m - i - 2] + b[i]);
  int r1 = m - 1, l2 = n - m;
  if (r1 <= l2) {
    for (int i = 0; i < r1; i++) a[i] = (s[i] + a[i]) % c;
    for (int i = r1; i <= l2; i++) a[i] = (a[i] + s[m - 1]) % c;
    for (int i = n - 1; i > l2; i--) a[i] = (a[i] + s2[n - 1 - i]) % c;
  } else {
    for (int i = 0; i <= l2; i++) a[i] = (a[i] + s[i]) % c;
    for (int i = l2 + 1; i <= r1; i++) a[i] = (a[i] + s[i] - s[i - l2 - 1]) % c;
    for (int i = n - 1; i > r1; i--) a[i] = (a[i] + s2[n - i - 1]) % c;
  }
  for (int i = 0; i < n; i++) cout << a[i] << " ";
}

```


### Prompt

Please provide a cpp coded solution to the problem described below:

The Bubble Cup hypothesis stood unsolved for 130 years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem:

Given a number m, how many polynomials P with coefficients in set {\{0,1,2,3,4,5,6,7\}} have: P(2)=m?

Help Jerry Mao solve the long standing problem!

Input

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

On next line there are t numbers, m_i (1 ≤ m_i ≤ 10^{18}) - meaning that in case i you should solve for number m_i.

Output

For each test case i, print the answer on separate lines: number of polynomials P as described in statement such that P(2)=m_i, modulo 10^9 + 7.

Example

Input

2
2 4

Output

2
4

Note

In first case, for m=2, polynomials that satisfy the constraint are x and 2.

In second case, for m=4, polynomials that satisfy the constraint are x^2, x + 2, 2x and 4.

### Response

```cpp
#include <bits/stdc++.h>
struct MI {
 private:
  char bb[4096];
  FILE* f;
  char *bs, *be;
  char e;
  bool o, l;

 public:
  MI() : f(stdin) {}
  inline char get() {
    if (o) {
      o = 0;
      return e;
    }
    if (bs == be) be = (bs = bb) + fread(bb, 1, sizeof(bb), f);
    if (bs == be) {
      l = 1;
      return -1;
    };
    return *bs++;
  }
  inline void unget(char c) {
    o = 1;
    e = c;
  }
  template <class T>
  inline T read() {
    T r;
    *this > r;
    return r;
  }
  template <class T>
  inline MI& operator>(T&);
};
template <class T>
struct Q {
  const static bool U = T(-1) >= T(0);
  inline void operator()(MI& t, T& r) const {
    r = 0;
    char c;
    bool y = 0;
    if (U)
      for (;;) {
        c = t.get();
        if (c == -1) goto E;
        if (isdigit(c)) break;
      }
    else
      for (;;) {
        c = t.get();
        if (c == -1) goto E;
        if (c == '-') {
          c = t.get();
          if (isdigit(c)) {
            y = 1;
            break;
          };
        } else if (isdigit(c))
          break;
        ;
      };
    for (;;) {
      if (c == -1) goto E;
      if (isdigit(c))
        r = r * 10 + (c ^ 48);
      else
        break;
      c = t.get();
    }
    t.unget(c);
  E:;
    if (y) r = -r;
  }
};
template <>
struct Q<char> {};
template <class T>
inline MI& MI::operator>(T& t) {
  Q<T>()(*this, t);
  return *this;
}
template <class T>
inline std::ostream& operator<(std::ostream& out, const T& t) {
  return out << t;
}
using std::cout;
MI cin;
const long long lp = 1000000007;
const long long inv4 = 250000002;
int main() {
  int T = (cin.read<int>());
  while (T--) {
    const long long n = cin.read<long long>();
    long long ret = ((n >> 1) + 2) % lp;
    ret = ret * ret % lp;
    int rem = ((n >> 1) + 2) & 3;
    rem = (rem * rem) & 3;
    cout < ((ret - rem + lp) % lp * inv4 % lp) < ('\n');
  }
  return 0;
}

```


### Prompt

Please provide a cpp coded solution to the problem described below:

It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.

According to the borscht recipe it consists of n ingredients that have to be mixed in proportion <image> litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately?

Input

The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100).

Output

Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4.

Examples

Input

1 100
1
40

Output

40.0

Input

2 100
1 1
25 30

Output

50.0

Input

2 100
1 1
60 60

Output

100.0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int v;
  cin >> v;
  double a[n + 1];
  double b[n + 1];
  double m = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    m += a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  double x = 100000000;
  for (int i = 1; i <= n; i++) {
    x = min(x, b[i] / a[i]);
  }
  if (v < x * m) {
    cout << v;
  } else {
    cout << x * m;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

The Ohgas are a prestigious family based on Hachioji. The head of the family, Mr. Nemochi Ohga, a famous wealthy man, wishes to increase his fortune by depositing his money to an operation company. You are asked to help Mr. Ohga maximize his profit by operating the given money during a specified period.

From a given list of possible operations, you choose an operation to deposit the given fund to. You commit on the single operation throughout the period and deposit all the fund to it. Each operation specifies an annual interest rate, whether the interest is simple or compound, and an annual operation charge. An annual operation charge is a constant not depending on the balance of the fund. The amount of interest is calculated at the end of every year, by multiplying the balance of the fund under operation by the annual interest rate, and then rounding off its fractional part. For compound interest, it is added to the balance of the fund under operation, and thus becomes a subject of interest for the following years. For simple interest, on the other hand, it is saved somewhere else and does not enter the balance of the fund under operation (i.e. it is not a subject of interest in the following years). An operation charge is then subtracted from the balance of the fund under operation. You may assume here that you can always pay the operation charge (i.e. the balance of the fund under operation is never less than the operation charge). The amount of money you obtain after the specified years of operation is called ``the final amount of fund.'' For simple interest, it is the sum of the balance of the fund under operation at the end of the final year, plus the amount of interest accumulated throughout the period. For compound interest, it is simply the balance of the fund under operation at the end of the final year.

Operation companies use C, C++, Java, etc., to perform their calculations, so they pay a special attention to their interest rates. That is, in these companies, an interest rate is always an integral multiple of 0.0001220703125 and between 0.0001220703125 and 0.125 (inclusive). 0.0001220703125 is a decimal representation of 1/8192. Thus, interest rates' being its multiples means that they can be represented with no errors under the double-precision binary representation of floating-point numbers.

For example, if you operate 1000000 JPY for five years with an annual, compound interest rate of 0.03125 (3.125 %) and an annual operation charge of 3000 JPY, the balance changes as follows.

The balance of the fund under operation (at the beginning of year) | Interest|  The balance of the fund under operation (at the end of year)
---|---|---
A| B = A × 0.03125 (and rounding off fractions) | A + B - 3000
1000000| 31250| 1028250
1028250| 32132| 1057382
1057382| 33043| 1087425
1087425| 33982| 1118407
1118407| 34950| 1150357

After the five years of operation, the final amount of fund is 1150357 JPY.

If the interest is simple with all other parameters being equal, it looks like:

The balance of the fund under operation (at the beginning of year) | Interest | The balance of the fund under operation (at the end of year) | Cumulative interest
---|---|---|---
A| B = A × 0.03125 (and rounding off fractions)| A - 3000|
1000000| 31250| 997000| 31250
997000| 31156| 994000| 62406
994000| 31062| 991000| 93468
991000| 30968| 988000| 124436
988000| 30875| 985000| 155311

In this case the final amount of fund is the total of the fund under operation, 985000 JPY, and the cumulative interests, 155311 JPY, which is 1140311 JPY.

Input

The input consists of datasets. The entire input looks like:

> the number of datasets (=m)
>  1st dataset
>  2nd dataset
>  ...
>  m-th dataset
>

The number of datasets, m, is no more than 100. Each dataset is formatted as follows.

> the initial amount of the fund for operation
>  the number of years of operation
>  the number of available operations (=n)
>  operation 1
>  operation 2
>  ...
>  operation n
>

The initial amount of the fund for operation, the number of years of operation, and the number of available operations are all positive integers. The first is no more than 100000000, the second no more than 10, and the third no more than 100.

Each ``operation'' is formatted as follows.

> simple-or-compound annual-interest-rate annual-operation-charge

where simple-or-compound is a single character of either '0' or '1', with '0' indicating simple interest and '1' compound. annual-interest-rate is represented by a decimal fraction and is an integral multiple of 1/8192. annual-operation-charge is an integer not exceeding 100000.

Output

For each dataset, print a line having a decimal integer indicating the final amount of fund for the best operation. The best operation is the one that yields the maximum final amount among the available operations. Each line should not have any character other than this number.

You may assume the final balance never exceeds 1000000000. You may also assume that at least one operation has the final amount of the fund no less than the initial amount of the fund.

Example

Input

4
1000000
5
2
0 0.03125 3000
1 0.03125 3000
6620000
7
2
0 0.0732421875 42307
1 0.0740966796875 40942
39677000
4
4
0 0.0709228515625 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 98193
0 0.0887451171875 78966

Output

1150357
10559683
50796918
20829397

### Response

```cpp
#include<stdio.h>

int main(){
	double a,b,unyou[100][5],syoki,max;
	int i,j,k,m,nen,n;

	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%lf%d%d",&syoki,&nen,&n);
//		printf("i %d\n",i);
		for(j=0;j<n;j++){
			scanf("%lf%lf%lf",&unyou[j][0],&unyou[j][1],&unyou[j][2]);
			a=syoki;
			b=0;
//			printf("j %d\n",j);
			switch(int(unyou[j][0])){
			case 0:
				for(k=0;k<nen;k++){
//					printf("k %d nen %d\n",k,nen);
					b+=int(a*unyou[j][1]);
					a=a-unyou[j][2];
				}
				unyou[j][3]=a+b;
//				printf("%d %lf\n",j,unyou[j][3]);
				break;
			case 1:
				for(k=0;k<nen;k++){
//					printf("k %d nen %d\n",k,nen);
					b=int(a*unyou[j][1]);
					a=a-unyou[j][2]+b;
				}
				unyou[j][3]=a;
//				printf("%d %lf\n",j,unyou[j][3]);
				break;
			}
		}

		max=0;
		for(j=0;j<n;j++){
			if(max<unyou[j][3]){
				max=unyou[j][3];
			}
		}
		printf("%.0f\n",max);
	}
	return 0;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.

Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid (<image>), each column of the grid (<image>), and the two long diagonals of the grid (the main diagonal — <image> and the secondary diagonal — <image>) are equal.

Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.

n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.

It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.

Output

Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output  - 1 instead.

If there are multiple solutions, you may print any of them.

Examples

Input

3
4 0 2
3 5 7
8 1 6

Output

9

Input

4
1 1 1 1
1 1 0 1
1 1 1 1
1 1 1 1

Output

1

Input

4
1 1 1 1
1 1 0 1
1 1 2 1
1 1 1 1

Output

-1

Note

In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,

The sum of numbers in each row is:

4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.

The sum of numbers in each column is:

4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.

The sum of numbers in the two diagonals is:

4 + 5 + 6 = 2 + 5 + 8 = 15.

In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.

### Response

```cpp
#include <bits/stdc++.h>
int x, y, n;
long long c[505][505], sum, temp;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%I64d", &c[i][j]);
      if (c[i][j] == 0) {
        x = i;
        y = j;
      }
    }
  }
  sum = 0;
  if (n == 1) {
    printf("1\n");
  } else {
    if (x == 1) {
      for (int i = 1; i <= n; i++) {
        sum += c[2][i];
      }
    } else {
      for (int i = 1; i <= n; i++) {
        sum += c[1][i];
      }
    }
    temp = sum;
    for (int i = 1; i <= n; i++) {
      sum -= c[x][i];
    }
    c[x][y] = sum;
    sum = temp;
    int flag = 1;
    for (int i = 1; i <= n && flag; i++) {
      temp = 0;
      for (int j = 1; j <= n; j++) {
        temp += c[i][j];
      }
      if (temp != sum) flag = 0;
    }
    for (int i = 1; i <= n && flag; i++) {
      temp = 0;
      for (int j = 1; j <= n; j++) {
        temp += c[j][i];
      }
      if (temp != sum) flag = 0;
    }
    temp = 0;
    for (int i = 1; i <= n && flag; i++) temp += c[i][i];
    if (temp != sum) flag = 0;
    temp = 0;
    for (int i = 1; i <= n && flag; i++) temp += c[i][n + 1 - i];
    if (temp != sum) flag = 0;
    if (flag && c[x][y] > 0) {
      printf("%I64d\n", c[x][y]);
    } else
      printf("-1\n");
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.

The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.

Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.

Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!

Input

The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.

Output

In t lines, print the actions the programmers need to make. In the i-th line print:

  * "LEFT" (without the quotes), if the i-th action was "move the ladder to the left";
  * "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right";
  * "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder".

The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.

Examples

Input

2 2
R1

Output

PRINT 1
LEFT
PRINT R

Input

2 1
R1

Output

PRINT R
RIGHT
PRINT 1

Input

6 4
GO?GO!

Output

RIGHT
RIGHT
PRINT !
LEFT
PRINT O
LEFT
PRINT G
LEFT
PRINT ?
LEFT
PRINT O
LEFT
PRINT G

Note

Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n, k, i, mark, t;
  char s[110];
  while (scanf("%d%d", &n, &k) != EOF) {
    scanf("%s", s);
    t = n / 2;
    mark = 0;
    if (k <= t) {
      if (k != 1)
        for (i = 0; i < k - 1; i++) printf("LEFT\n");
    } else {
      mark = 1;
      if (k != n)
        for (i = 0; i < n - k; i++) printf("RIGHT\n");
    }
    if (mark)
      for (i = n - 1; i >= 0; i--) {
        printf("PRINT %c\n", s[i]);
        if (i != 0) printf("LEFT\n");
      }
    else
      for (i = 0; i < n; i++) {
        printf("PRINT %c\n", s[i]);
        if (i != n - 1) printf("RIGHT\n");
      }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:

* $update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$.
* $getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$.

Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.

Constraints

* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$

Input

$n$ $q$
$query_1$
$query_2$
:
$query_q$

In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$-th query $query_i$ is given in the following format:

0 $s$ $t$ $x$

or

1 $s$ $t$

The first digit represents the type of the query. '0' denotes $update(s, t, x)$ and '1' denotes $find(s, t)$.

Output

For each $getSum$ query, print the sum in a line.

Example

Input

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

Output

-5
1
6
8

### Response

```cpp
#include "bits/stdc++.h"

class LazySegmentTree
{
    int n;
    using T1 = long long;
    using T2 = long long;
    T1 id1 = 0;
    T2 id2 = -INT_MAX;
    std::vector<T1> node; // sum
    std::vector<T2> lazy; // update

    // 遅延評価
    void eval(int k, int l, int r)
    {
        // 遅延配列が空なら終了
        if (lazy[k] == id2)
            return;
        // 遅延配列を適用
        node[k] = lazy[k];
        if (r - l > 1)
        {
            lazy[2 * k + 1] = lazy[k] / 2;
            lazy[2 * k + 2] = lazy[k] / 2;
        }
        // 遅延配列初期化
        lazy[k] = id2;
    }

  public:
    LazySegmentTree(int _n)
    {
        int sz = _n;
        n = 1;
        while (n < sz)
            n *= 2;
        // 配列初期化
        node.resize(2 * n - 1, id1);
        lazy.resize(2 * n - 1, id2);
    }
    // 半開区間 [a, b) に対して値 val を反映させる
    void update(int a, int b, T2 val, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        // ノード k で遅延評価
        eval(k, l, r);
        if (b <= l || r <= a)
            return;
        // 区間が被覆されている場合
        if (a <= l && r <= b)
        {
            // 遅延配列更新, 評価
            lazy[k] = (r - l) * val;
            eval(k, l, r);
        }
        else
        {
            // 子ノードの値を評価し, 更新
            int mid = (l + r) / 2;
            update(a, b, val, l, mid, 2 * k + 1);
            update(a, b, val, mid, r, 2 * k + 2);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    // 半開区間 [a, b) に対してクエリを投げる
    T1 query(int a, int b, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        eval(k, l, r);
        // 範囲外なら単位元返す
        if (b <= l || r <= a)
            return id1;
        if (a <= l && r <= b)
            return node[k];
        int mid = (l + r) / 2;
        T1 vl = query(a, b, l, mid, 2 * k + 1);
        T1 vr = query(a, b, mid, r, 2 * k + 2);
        return vl + vr;
    }
};

using namespace std;

void solve_dsl_2_i()
{
    int n, q;
    cin >> n >> q;
    LazySegmentTree lst(n);
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 0)
        {
            int s, t, x;
            cin >> s >> t >> x;
            t++;
            lst.update(s, t, x);
        }
        else
        {
            int s, t;
            cin >> s >> t;
            t++;
            cout << lst.query(s, t) << endl;
        }
    }
}

int main()
{
    solve_dsl_2_i();
}

```


### Prompt

Your challenge is to write a cpp solution to the following problem:

In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.

We will consider an extremely simplified subset of Python with only two types of statements.

Simple statements are written in a single line, one per line. An example of a simple statement is assignment.

For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.

You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.

Input

The first line contains a single integer N (1 ≤ N ≤ 5000) — the number of commands in the program. N lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.

Output

Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109 + 7.

Examples

Input

4
s
f
f
s

Output

1

Input

4
f
s
f
s

Output

2

Note

In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.

    simple statement
    for statement
        for statement
            simple statement

In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.

    for statement
        simple statement
        for statement
            simple statement

or

    for statement
        simple statement
    for statement
        simple statement

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
const int md = 1e9 + 7;
int n;
char c[N];
int dp[N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf(" %c", &c[i]);
  dp[0][1] = 1;
  c[0] = 's';
  for (int i = 1; i <= n; i++) {
    int tmp = 0;
    for (int j = n; j >= 1; j--) {
      if (c[i - 1] == 'f') dp[i][j] = dp[i - 1][j - 1];
      if (c[i - 1] == 's') {
        tmp += dp[i - 1][j], tmp %= md, dp[i][j] = tmp;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += dp[n][i], ans %= md;
  cout << ans;
  return 0;
}

```


### Prompt

Your task is to create a Cpp solution to the following problem:

After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simple survey created a map of the area around the planned residence. The planned place of residence has a rectangular shape of M km north-south and N km east-west, and is divided into square sections of 1 km square. There are MN compartments in total, and the compartments in the p-th row from the north and the q-th column from the west are represented by (p, q). The northwest corner section is (1, 1) and the southeast corner section is (M, N). The terrain of each section is one of "jungle", "sea", and "ice". "Jungle" is represented by J, "sea" is represented by O, and "ice" is represented by one letter I.

Now, in making a detailed migration plan, I decided to investigate how many sections of "jungle," "sea," and "ice" are included in the rectangular area at K.

input

Read the following input from standard input.

* The integers M and N are written on the first line, separated by blanks, indicating that the planned residence is M km north-south and N km east-west.
* The integer K is written on the second line, which indicates the number of regions to be investigated.
* The following M line contains information on the planned residence. The second line of i + (1 ≤ i ≤ M) contains an N-character string consisting of J, O, and I that represents the information of the N section located on the i-th line from the north of the planned residence. ..
* The following K line describes the area to be investigated. On the second line of j + M + (1 ≤ j ≤ K), the positive integers aj, bj, cj, and dj representing the jth region are written with blanks as delimiters. (aj, bj) represents the northwest corner section of the survey area, and (cj, dj) represents the southeast corner section of the survey area. However, aj, bj, cj, and dj satisfy 1 ≤ aj ≤ cj ≤ M, 1 ≤ bj ≤ dj ≤ N.

output

Output K lines representing the results of the survey to standard output. Line j of the output contains three integers representing the number of "jungle" (J) compartments, the "sea" (O) compartment, and the "ice" (I) compartment in the jth survey area. , In this order, separated by blanks.

Example

Input

4 7
4
JIOJOIJ
IOJOIJO
JOIJOOI
OOJJIJO
3 5 4 7
2 2 3 6
2 2 2 2
1 1 4 7

Output

1 3 2
3 5 2
0 1 0
10 11 7

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX = 1001;
int H, W, K;
int J[MAX][MAX], O[MAX][MAX], I[MAX][MAX];
char field[MAX][MAX];

int main(void) {
  while(cin >> H >> W >> K) {
    memset(J, 0, sizeof(J));
    memset(O, 0, sizeof(O));
    memset(I, 0, sizeof(I));

    for(int i = 1; i <= H; i++){
      cin >> &field[i][1];
      for(int j = 1 ; j <= W ; j++){
        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1];

        if(field[i][j] == 'J')      J[i][j]++;
        else if(field[i][j] == 'O') O[i][j]++;
        else if(field[i][j] == 'I') I[i][j]++;
      }
    }

    for(int i = 0 ; i < K ; i++) {
      int px, py, qx, qy;
      cin >> px >> py >> qx >> qy;
      int ansJ, ansO, ansI;
      ansJ = J[qx][qy] - J[px-1][qy] - J[qx][py-1] + J[px-1][py-1];
      ansO = O[qx][qy] - O[px-1][qy] - O[qx][py-1] + O[px-1][py-1];
      ansI = I[qx][qy] - I[px-1][qy] - I[qx][py-1] + I[px-1][py-1];
      printf("%d %d %d\n", ansJ, ansO, ansI);
    }
  }
}
```


### Prompt

Create a solution in Cpp for the following problem:

Eric is the teacher of graph theory class. Today, Eric teaches independent set and edge-induced subgraph.

Given a graph G=(V,E), an independent set is a subset of vertices V' ⊂ V such that for every pair u,v ∈ V', (u,v) not ∈ E (i.e. no edge in E connects two vertices from V').

An edge-induced subgraph consists of a subset of edges E' ⊂ E and all the vertices in the original graph that are incident on at least one edge in the subgraph.

Given E' ⊂ E, denote G[E'] the edge-induced subgraph such that E' is the edge set of the subgraph. Here is an illustration of those definitions:

<image>

In order to help his students get familiar with those definitions, he leaves the following problem as an exercise:

Given a tree G=(V,E), calculate the sum of w(H) over all except null edge-induced subgraph H of G, where w(H) is the number of independent sets in H. Formally, calculate ∑ _{∅ not= E' ⊂ E} w(G[E']).

Show Eric that you are smarter than his students by providing the correct answer as quickly as possible. Note that the answer might be large, you should output the answer modulo 998,244,353.

Input

The first line contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5), representing the number of vertices of the graph G.

Each of the following n-1 lines contains two integers u and v (1 ≤ u,v ≤ n, u not= v), describing edges of the given tree.

It is guaranteed that the given edges form a tree.

Output

Output one integer, representing the desired value modulo 998,244,353.

Examples

Input

2
2 1

Output

3

Input

3
1 2
3 2

Output

11

Note

For the second example, all independent sets are listed below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 3e5 + 7;
const long long mod = 998244353;
long long dp[3][N];
int n;
vector<int> g[N];
void dfs(int v, int p = 0) {
  dp[0][v] = dp[1][v] = dp[2][v] = 1;
  for (int to : g[v]) {
    if (to != p) {
      dfs(to, v);
      dp[0][v] *= (2 * dp[0][to] + 2 * dp[1][to] - dp[2][to]) % mod;
      dp[0][v] %= mod;
      dp[1][v] *= (2 * dp[0][to] + dp[1][to] - dp[2][to]) % mod;
      dp[1][v] %= mod;
      dp[2][v] *= (dp[0][to] + dp[1][to] - dp[2][to]) % mod;
      dp[2][v] %= mod;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1);
  cout << (dp[0][1] + dp[1][1] - dp[2][1] - 1 + 2 * mod) % mod;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)

[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)

Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.

One day, Nora's adoptive father, Phoenix Wyle, brought Nora n boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.

She labelled all n boxes with n distinct integers a_1, a_2, …, a_n and asked ROBO to do the following action several (possibly zero) times:

  * Pick three distinct indices i, j and k, such that a_i ∣ a_j and a_i ∣ a_k. In other words, a_i divides both a_j and a_k, that is a_j mod a_i = 0, a_k mod a_i = 0.
  * After choosing, Nora will give the k-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty.
  * After doing so, the box k becomes unavailable for any further actions.

Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.

Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?

As the number of such piles can be very large, you should print the answer modulo 10^9 + 7.

Input

The first line contains an integer n (3 ≤ n ≤ 60), denoting the number of boxes.

The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 60), where a_i is the label of the i-th box.

Output

Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo 10^9 + 7.

Examples

Input

3
2 6 8

Output

2

Input

5
2 3 4 9 12

Output

4

Input

4
5 7 2 9

Output

1

Note

Let's illustrate the box pile as a sequence b, with the pile's bottommost box being at the leftmost position.

In the first example, there are 2 distinct piles possible:

  * b = [6] ([2, 6, 8] \xrightarrow{(1, 3, 2)} [2, 8])
  * b = [8] ([2, 6, 8] \xrightarrow{(1, 2, 3)} [2, 6])

In the second example, there are 4 distinct piles possible:

  * b = [9, 12] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 3, 4)} [2, 3, 4])
  * b = [4, 12] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 3, 4)} [2, 3, 9])
  * b = [4, 9] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 4, 3)} [2, 3, 12])
  * b = [9, 4] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 4, 3)} [2, 3, 12])

In the third sequence, ROBO can do nothing at all. Therefore, there is only 1 valid pile, and that pile is empty.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MN = 62, MOD = 1000 * 1000 * 1000 + 7;
long long C[MN][MN], mark[MN], a[MN], mask[MN], dp[(1 << 16)][MN];
vector<long long> srs, oth, jda[MN], adj[MN], vec;
long long sol() {
  long long n = srs.size(), m = oth.size();
  long long num[MN] = {};
  if (m == 0) return 1;
  vec.push_back(m - 1);
  for (long long i = 0; i < MN; i++) num[i] = -1;
  long long cnt = 0;
  for (long long i : srs) num[i] = cnt++;
  for (long long cn = 1; cn <= m; cn++)
    for (long long msk = 0; msk < (1 << n); msk++) dp[msk][cn] = 0;
  for (long long i = 0; i < m; i++) {
    mask[i] = 0;
    for (long long u : jda[oth[i]])
      if (num[u] != -1) mask[i] |= (1 << num[u]);
    dp[mask[i]][1]++;
  }
  for (long long cn = 1; cn < m; cn++)
    for (long long msk = 0; msk < (1 << n); msk++) {
      vector<long long> gd, bd;
      for (long long i = 0; i < m; i++) {
        if ((mask[i] | msk) == msk)
          gd.push_back(i);
        else if (mask[i] & msk)
          bd.push_back(i);
      }
      if (cn > gd.size()) continue;
      (dp[msk][cn + 1] += (dp[msk][cn] * (gd.size() - cn)) % MOD) %= MOD;
      for (long long u : bd) dp[msk | mask[u]][cn + 1] += dp[msk][cn];
    }
  return dp[(1 << n) - 1][m];
}
void dfs(long long v) {
  mark[v] = 1 + (jda[v].size() ? 0 : 1);
  for (long long i : adj[v])
    if (!mark[i]) dfs(i);
  for (long long i : jda[v])
    if (!mark[i]) dfs(i);
  (jda[v].size() ? oth : srs).push_back(v);
}
void pre() {
  for (long long i = 0; i < MN; i++) {
    C[i][i] = C[i][0] = 1;
    for (long long j = 1; j < i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
}
long long solve(vector<long long> &vec) {
  if (!vec.size()) return 1;
  long long sum = 0;
  for (long long u : vec) sum += u;
  long long x = vec.back();
  vec.pop_back();
  return C[sum][x] * solve(vec);
}
int32_t main() {
  pre();
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++)
      if (a[i] % a[j] == 0 && i != j) {
        jda[i].push_back(j);
        adj[j].push_back(i);
      }
  long long ans = 1;
  for (long long i = 0; i < n; i++)
    if (!mark[i]) {
      dfs(i);
      ans = ans * sol() % MOD;
      srs.clear();
      oth.clear();
    }
  ans = ans * solve(vec);
  cout << ans;
}

```


### Prompt

Your task is to create a CPP solution to the following problem:

Mr. Bill is shopping at the store. There are some coins in his wallet (10-yen coins, 50-yen coins, 100-yen coins, 500-yen coins), but he is now trying to consume as much of this coin as possible. In other words, by paying for the goods with an appropriate number of coins, we are trying to minimize the total number of coins after receiving the change.

Fortunately, the clerk at this store is so disciplined and kind that change is always delivered in the best possible way. Therefore, for example, five 100-yen coins will not be given instead of one 500-yen coin. You can also take out 5 10-yen coins and receive 50-yen coins as change. However, you must not pay the coins of the same type as the coins you issued so that they will be returned as change. For example, if a 10-yen coin is paid out and another 10-yen coin is returned as change, a completely meaningless exchange will occur.

However, Mr. Bill was not good at calculating, so he could not find out how many coins he should actually use. So he asked you for help. Your job is to write a program to determine the type and number of coins to use based on the number of coins in his wallet and the payment price. The clerk does not use banknotes for change.

Input

The input contains several test cases.

Each test case consists of two lines. The first line contains a single integer representing Mr. Bill's payment in yen. The second line contains four integers, which in turn represent the number of 10-yen coins, 50-yen coins, 100-yen coins, and 500-yen coins in your wallet.

The payment amount is always in units of 10 yen. That is, the one-yen place of the payment amount is always 0. You can also assume that you can only have up to 20 coins of the same type in your wallet. No non-payable cases are given during input.

The end of input is represented by a line containing a single 0.

Output

For each test case, print out the type and number of coins that Mr. Bill should use.

Each line of output contains the two integers ci and ki. This means using ki coins for ci yen when paying. When using multiple types of coins, output as many lines as necessary in order from the smallest ci. Refer to the output example below.

The output must not include extra space. Separate consecutive test cases with a blank line.

Example

Input

160
1 1 2 0
160
1 0 2 10
0

Output

10 1
50 1
100 1

10 1
100 2

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

const int units[4] = {10, 50, 100, 500};

int main() {
	int p;
	bool first = true;
	while(cin >> p, p) {
		if(!first) {
			cout << endl;
		}
		first = false;

		int c[4];
		int sum = 0;
		for(int i = 0; i < 4; i++) {cin >> c[i]; sum += units[i]*c[i];}

		sum -= p;
		for(int i = 3; i >= 0; i--) {
			while(sum >= units[i]) {
				sum -= units[i]; c[i]--;
			}
		}

		for(int i = 0; i < 4; i++) {
			if(c[i] > 0)
				cout << units[i] << " " << c[i] << endl;
		}
	}

	return 0;
}
```


### Prompt

Your challenge is to write a CPP solution to the following problem:

According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?

The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE

Input

The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.

Only the drinks from the list given above should be considered alcohol.

Output

Print a single number which is the number of people Vasya should check to guarantee the law enforcement.

Examples

Input

5
18
VODKA
COKE
19
17

Output

2

Note

In the sample test the second and fifth clients should be checked.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string trollface[29] = {"ABSINTH", "BEER", "BRANDY",  "CHAMPAGNE", "GIN",
                        "RUM",     "SAKE", "TEQUILA", "VODKA",     "WHISKEY",
                        "WINE",    "0",    "1",       "2",         "3",
                        "4",       "5",    "6",       "7",         "8",
                        "9",       "10",   "11",      "12",        "13",
                        "14",      "15",   "16",      "17"};
int troll(string s) {
  for (int i = 0; i < 29; i++) {
    if (s == trollface[i]) return 1;
  }
  return 0;
}
int main() {
  int n, ans = 0;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (troll(s)) ans++;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

In CPP, your task is to solve the following problem:

On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.

There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors.

Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are k bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure).

So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo 998 244 353.

Input

The first and only line contains three integers n, m and k (1 ≤ n,m ≤ 2000, 0 ≤ k ≤ n-1) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it.

Output

Print one integer — the number of ways to color bricks modulo 998 244 353.

Examples

Input

3 3 0

Output

3

Input

3 2 1

Output

4

Note

In the first example, since k=0, the color of every brick should be the same, so there will be exactly m=3 ways to color the bricks.

In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all 4 possible colorings.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long min2(long long a, long long b) {
  return (a) < (b) ? (a) : (b);
}
inline long long max2(long long a, long long b) {
  return (a) > (b) ? (a) : (b);
}
inline long long max3(long long a, long long b, long long c) {
  return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long min3(long long a, long long b, long long c) {
  return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));
}
using namespace std::chrono;
long long int n, m, k;
long long int dp[2001][2001];
long long int fun(long long int i, long long int c) {
  if (i == n + 1) {
    if (c == k)
      return 1;
    else
      return 0;
  }
  if (dp[i][c] != -1) return dp[i][c];
  if (i == 1)
    dp[i][c] = (m * fun(i + 1, c)) % 998244353;
  else
    dp[i][c] = (((m - 1) * fun(i + 1, c + 1)) % 998244353 +
                (1 * fun(i + 1, c)) % 998244353) %
               998244353;
  return dp[i][c];
}
void process() {
  cin >> n >> m >> k;
  memset(dp, -1, sizeof(dp));
  cout << fun(1, 0) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  process();
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Gildong is experimenting with an interesting machine Graph Traveler. In Graph Traveler, there is a directed graph consisting of n vertices numbered from 1 to n. The i-th vertex has m_i outgoing edges that are labeled as e_i[0], e_i[1], …, e_i[m_i-1], each representing the destination vertex of the edge. The graph can have multiple edges and self-loops. The i-th vertex also has an integer k_i written on itself.

A travel on this graph works as follows.

  1. Gildong chooses a vertex to start from, and an integer to start with. Set the variable c to this integer.
  2. After arriving at the vertex i, or when Gildong begins the travel at some vertex i, add k_i to c.
  3. The next vertex is e_i[x] where x is an integer 0 ≤ x ≤ m_i-1 satisfying x ≡ c \pmod {m_i}. Go to the next vertex and go back to step 2.

It's obvious that a travel never ends, since the 2nd and the 3rd step will be repeated endlessly.

For example, assume that Gildong starts at vertex 1 with c = 5, and m_1 = 2, e_1[0] = 1, e_1[1] = 2, k_1 = -3. Right after he starts at vertex 1, c becomes 2. Since the only integer x (0 ≤ x ≤ 1) where x ≡ c \pmod {m_i} is 0, Gildong goes to vertex e_1[0] = 1. After arriving at vertex 1 again, c becomes -1. The only integer x satisfying the conditions is 1, so he goes to vertex e_1[1] = 2, and so on.

Since Gildong is quite inquisitive, he's going to ask you q queries. He wants to know how many distinct vertices will be visited infinitely many times, if he starts the travel from a certain vertex with a certain value of c. Note that you should not count the vertices that will be visited only finite times.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 1000), the number of vertices in the graph.

The second line contains n integers. The i-th integer is k_i (-10^9 ≤ k_i ≤ 10^9), the integer written on the i-th vertex.

Next 2 ⋅ n lines describe the edges of each vertex. The (2 ⋅ i + 1)-st line contains an integer m_i (1 ≤ m_i ≤ 10), the number of outgoing edges of the i-th vertex. The (2 ⋅ i + 2)-nd line contains m_i integers e_i[0], e_i[1], …, e_i[m_i-1], each having an integer value between 1 and n, inclusive.

Next line contains an integer q (1 ≤ q ≤ 10^5), the number of queries Gildong wants to ask.

Next q lines contains two integers x and y (1 ≤ x ≤ n, -10^9 ≤ y ≤ 10^9) each, which mean that the start vertex is x and the starting value of c is y.

Output

For each query, print the number of distinct vertices that will be visited infinitely many times, if Gildong starts at vertex x with starting integer y.

Examples

Input

4
0 0 0 0
2
2 3
1
2
3
2 4 1
4
3 1 2 1
6
1 0
2 0
3 -1
4 -2
1 1
1 5

Output

1
1
2
1
3
2

Input

4
4 -5 -3 -1
2
2 3
1
2
3
2 4 1
4
3 1 2 1
6
1 0
2 0
3 -1
4 -2
1 1
1 5

Output

1
1
1
3
1
1

Note

The first example can be shown like the following image:

<image>

Three integers are marked on i-th vertex: i, k_i, and m_i respectively. The outgoing edges are labeled with an integer representing the edge number of i-th vertex.

The travel for each query works as follows. It is described as a sequence of phrases, each in the format "vertex (c after k_i added)".

  * 1(0) → 2(0) → 2(0) → …
  * 2(0) → 2(0) → …
  * 3(-1) → 1(-1) → 3(-1) → …
  * 4(-2) → 2(-2) → 2(-2) → …
  * 1(1) → 3(1) → 4(1) → 1(1) → …
  * 1(5) → 3(5) → 1(5) → …

The second example is same as the first example, except that the vertices have non-zero values. Therefore the answers to the queries also differ from the first example.

<image>

The queries for the second example works as follows:

  * 1(4) → 2(-1) → 2(-6) → …
  * 2(-5) → 2(-10) → …
  * 3(-4) → 1(0) → 2(-5) → 2(-10) → …
  * 4(-3) → 1(1) → 3(-2) → 4(-3) → …
  * 1(5) → 3(2) → 1(6) → 2(1) → 2(-4) → …
  * 1(9) → 3(6) → 2(1) → 2(-4) → …

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int M = 1e9 + 7;
const int inf = 1e9 + 7;
const long long INF = 1e18;
int n;
int a[N];
int d[N];
vector<int> b[N];
int vis[N][2550];
pair<int, int> his[N * 2550];
long long ans[N][2550];
int num[N];
int cur, top;
int solve(int x, int y) {
  if (ans[x][y]) return ans[x][y];
  ++cur;
  his[top = 1] = {x, y};
  vis[x][y] = cur;
  while (1) {
    x = b[x][y % d[x]];
    y += a[x];
    if (y < 0) {
      y = -y;
      y %= 2520;
      y = 2520 - y;
    } else {
      y %= 2520;
    }
    if (vis[x][y]) break;
    vis[x][y] = cur;
    his[++top] = {x, y};
  }
  if (vis[x][y] != cur) {
    for (int k = 1; k <= top; k++) {
      ans[his[k].first][his[k].second] = ans[x][y];
    }
  } else {
    int sz = 0;
    for (int k = top; k >= 1; k--) {
      if (num[his[k].first] != cur) {
        num[his[k].first] = cur;
        sz++;
      }
      if (his[k].first == x && his[k].second == y) break;
    }
    for (int k = 1; k <= top; k++) {
      ans[his[k].first][his[k].second] = sz;
    }
  }
  return ans[x][y];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    b[i].resize(d[i]);
    for (int j = 0; j < d[i]; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 2520; j++) {
      vis[i][j] = 0;
    }
  int q;
  cin >> q;
  int x, y;
  cur = 0;
  while (q--) {
    cin >> x >> y;
    y += a[x];
    if (y < 0) {
      y = -y;
      y %= 2520;
      y = 2520 - y;
    } else {
      y %= 2520;
    }
    cout << solve(x, y) << "\n";
  }
}

```


### Prompt

Your challenge is to write a cpp solution to the following problem:

Let's assume that set S consists of m distinct intervals [l1, r1], [l2, r2], ..., [lm, rm] (1 ≤ li ≤ ri ≤ n; li, ri are integers).

Let's assume that f(S) is the maximum number of intervals that you can choose from the set S, such that every two of them do not intersect. We assume that two intervals, [l1, r1] and [l2, r2], intersect if there is an integer x, which meets two inequalities: l1 ≤ x ≤ r1 and l2 ≤ x ≤ r2.

Sereja wonders, how many sets S are there, such that f(S) = k? Count this number modulo 1000000007 (109 + 7).

Input

The first line contains integers n, k (1 ≤ n ≤ 500; 0 ≤ k ≤ 500).

Output

In a single line, print the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

3 1

Output

23

Input

3 2

Output

32

Input

2 0

Output

1

Input

2 2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int modulo = 1e9 + 7;
long long int eleva(long long int b, long long int e) {
  if (e == 0) return 1;
  if (e % 2 == 0) return eleva(b * b % modulo, e / 2);
  return b * eleva(b * b % modulo, e / 2) % modulo;
}
long long int memcomputa[1000][1000];
int calculado[1000][1000];
long long int computa(int n, int k) {
  if (n < k) return 0;
  if (k == 0) return 1;
  long long int &mem = memcomputa[n][k];
  if (calculado[n][k]) return mem;
  calculado[n][k] = 1;
  mem = 0;
  for (int i = 1; i <= n; i++)
    mem = (mem + (eleva(2, i) - 1 + modulo) * eleva(2, i * (n - i)) % modulo *
                     computa(n - i, k - 1)) %
          modulo;
  return mem;
}
int main() {
  int n, k;
  cin >> n >> k;
  cout << computa(n, k) << endl;
}

```


### Prompt

Your task is to create a cpp solution to the following problem:

For given n points in metric space, find the distance of the closest points.

Constraints

* 2 ≤ n ≤ 100,000
* -100 ≤ x, y ≤ 100

Input

n
x0 y0
x1 y1
:
xn-1 yn-1

The first integer n is the number of points.

In the following n lines, the coordinate of the i-th point is given by two real numbers xi and yi. Each value is a real number with at most 6 digits after the decimal point.

Output

Print the distance in a line. The output values should be in a decimal fraction with an error less than 0.000001.

Examples

Input

2
0.0 0.0
1.0 0.0

Output

1.000000

Input

3
0.0 0.0
2.0 0.0
1.0 1.0

Output

1.41421356237

### Response

```cpp
#include<iostream>
using namespace std;
#include<utility>
#include<algorithm>
#include<cstdio>
#include<cmath>

typedef pair<double, double> point;
typedef point* data;

inline double dist(const point &a, const point &b)
{
    double dx = a.first - b.first, dy = a.second - b.second;
    return sqrt(dx * dx + dy * dy);
}

bool y_less(const point &P1, const point &P2){ return P1.second < P2.second; }
bool y_greater(const point &P1, const point &P2){ return P1.second > P2.second; }

double closest(data P, int n)
{
    if(n <= 1) return 1000;
    if(n == 2) return dist(P[0], P[1]);
    int m = n / 2;
    sort(P, P + n, y_less); // y_sort, down to up.
	double median = P[m].second;
    double d = min(closest(P, m), closest(P + m, n - m));

    sort(P, P + m, y_less);
    sort(P + m, P + n, y_greater);
    int a, b;
    for(a = m - 1; a > 0; a--){ if(P[a].second < median - d) break; }
    for(b = n - 1; b > m; b--){ if(P[b].second > median + d) break; }
    sort(P + a, P + m);
    sort(P + b, P + n);

    // x_sort, left to right.
    int u, v, i, j;
    u = i = a, v = j = b;
    while(i < m && j < n){
        if(P[u].first < P[v].first){
            for(i = a; i < m; i++){
                if(P[i].first >= P[v].first){ u = i; break; }
                if(P[v].first - P[i].first >= d){ a++; }
                else{
                    d = min(d, dist(P[v], P[i]));
                }
            }
        }else{
            for(j = b; j < n; j++){
                if(P[j].first > P[u].first){ v = j; break; }
                if(P[u].first - P[j].first >= d){ b++; }
                else{
                    d = min(d, dist(P[u], P[j]));
                }
            }
        }
    };
    return d;
}

int main()
{
	int i, n;
	double x, y;
	scanf("%d", &n);
	data P;
	P = new point [n];

	for(i = 0; i < n; i++){
		scanf("%lf %lf", &x, &y);
		P[i] = make_pair(x, y);
	}
	printf("%.12f\n", closest(P, n));

	return 0;
}
```