### Prompt

Create a solution in CPP for the following problem:

The only difference between easy and hard versions is a number of elements in the array.

You are given an array a consisting of n integers. The value of the i-th element of the array is a_i.

You are also given a set of m segments. The j-th segment is [l_j; r_j], where 1 ≤ l_j ≤ r_j ≤ n.

You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array a = [0, 0, 0, 0, 0] and the given segments are [1; 3] and [2; 4] then you can choose both of them and the array will become b = [-1, -2, -2, -1, 0].

You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array a and obtain the array b then the value max_{i=1}^{n}b_i - min_{i=1}^{n}b_i will be maximum possible.

Note that you can choose the empty set.

If there are multiple answers, you can print any.

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

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 10^5, 0 ≤ m ≤ 300) — the length of the array a and the number of segments, respectively.

The second line of the input contains n integers a_1, a_2, ..., a_n (-10^6 ≤ a_i ≤ 10^6), where a_i is the value of the i-th element of the array a.

The next m lines are contain two integers each. The j-th of them contains two integers l_j and r_j (1 ≤ l_j ≤ r_j ≤ n), where l_j and r_j are the ends of the j-th segment.

Output

In the first line of the output print one integer d — the maximum possible value max_{i=1}^{n}b_i - min_{i=1}^{n}b_i if b is the array obtained by applying some subset of the given segments to the array a.

In the second line of the output print one integer q (0 ≤ q ≤ m) — the number of segments you apply.

In the third line print q distinct integers c_1, c_2, ..., c_q in any order (1 ≤ c_k ≤ m) — indices of segments you apply to the array a in such a way that the value max_{i=1}^{n}b_i - min_{i=1}^{n}b_i of the obtained array b is maximum possible.

If there are multiple answers, you can print any.

Examples

Input

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

Output

6
2
4 1

Input

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

Output

7
2
3 2

Input

1 0
1000000

Output

0
0

Note

In the first example the obtained array b will be [0, -4, 1, 1, 2] so the answer is 6.

In the second example the obtained array b will be [2, -3, 1, -1, 4] so the answer is 7.

In the third example you cannot do anything so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  int nm = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
  return nm * f;
}
struct Note {
  int l, r, pl, v, id;
  bool operator<(const Note &b) const { return this->pl < b.pl; }
} sta[100010 << 3];
int tp;
const int inf = 0x3e3e3e3e;
int id[100010 << 2], maxx[100010 << 2], laz[100010 << 2], pa[100010];
int ans[100010];
void add(int now, int x) {
  laz[now] += x;
  maxx[now] += x;
}
int pllll = 0;
int as = -inf;
int main() {
  maxx[0] = -inf;
  int n = read(), q = read();
  for (int i = 1; i <= n; i++) ans[i] = read();
  for (int i = 1; i <= q; i++) {
    int l = read(), r = read();
    tp++;
    sta[tp].l = l, sta[tp].r = r;
    sta[tp].v = -1;
    sta[tp].pl = l;
    sta[tp].id = i;
    tp++;
    sta[tp] = sta[tp - 1];
    sta[tp].v = 1;
    sta[tp].pl = r + 1;
    sta[tp].id = 0;
  }
  sort(sta + 1, sta + tp + 1);
  int now = 1;
  int mama = -inf;
  for (int i = 1; i <= n; i++) {
    int f = 0;
    while (now <= tp && sta[now].pl == i) {
      f = 1;
      int l = sta[now].l, r = sta[now].r, v = sta[now].v;
      for (int j = l; j <= r; j++) ans[j] += v;
      now++;
    }
    if (f || i == 1) {
      mama = -inf;
      for (int j = 1; j <= n; j++) {
        mama = max(mama, ans[j]);
      }
    }
    if (as < mama - ans[i]) pllll = i;
    as = max(as, mama - ans[i]);
  }
  int tmp = as;
  while (now <= tp) {
    int l = sta[now].l, r = sta[now].r, v = sta[now].v;
    for (int j = l; j <= r; j++) ans[j] += v;
    now++;
  }
  now = 1;
  int i = pllll;
  cout << as << "\n";
  int tot = 0;
  for (int j = 1; j <= tp; j++) {
    if (sta[j].l <= i && sta[j].r >= i) tot++;
  }
  tot >>= 1;
  cout << tot << "\n";
  if (tot == 0) return 0;
  for (int j = 1; j <= tp; j++) {
    if (sta[j].l <= i && sta[j].r >= i && sta[j].id) cout << sta[j].id << " ";
  }
  cout << "\n";
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.

The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.

Input

The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.

The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.

Output

Print the maximum number of teams of three people the coach can form.

Examples

Input

4
1 1 2 1

Output

1

Input

2
2 2

Output

0

Input

7
2 2 2 1 1 1 1

Output

3

Input

3
1 1 1

Output

1

Note

In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.

In the second example he can't make a single team.

In the third example the coach can form three teams. For example, he can do this in the following way:

  * The first group (of two people) and the seventh group (of one person),
  * The second group (of two people) and the sixth group (of one person),
  * The third group (of two people) and the fourth group (of one person).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r, one = 0, two = 0, team;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> r;
    if (r == 1)
      one++;
    else
      two++;
  }
  if (one > two) {
    team = two;
    one = one - two;
    team += (one / 3);
  } else if (one < two) {
    team = one;
  } else {
    team = two;
  }
  cout << team;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Let's play Amidakuji.

In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.

<image>

In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom.

Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.

Hint

Try it. -->

Input

w
n
a1,b1
a2,b2
.
.
an,bn

w (w ≤ 30) is the number of vertical lines. n (n ≤ 30) is the number of horizontal lines. A pair of two integers ai and bi delimited by a comma represents the i-th horizontal line.

Output

The number which should be under the 1st (leftmost) vertical line
The number which should be under the 2nd vertical line
:
The number which should be under the w-th vertical line

Example

Input

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

Output

4
1
2
5
3

### Response

```cpp
#include <iostream>

using namespace std;

int main() {
	int a[31];
	for(int i=0;i<31;i++){
		a[i] = i;
	}
	int w,n;
	cin >> w;
	cin >> n;
	int k,l;
	while(scanf("%d,%d",&k,&l)+1){
		a[0] = a[k];
		a[k] = a[l];
		a[l] = a[0];
	}
	for(int i=1;i<=w;i++){
		cout << a[i] << endl;
	}
	return 0;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

KM country has N kinds of coins and each coin has its value a_i.

The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins.

A currency system is called beautiful if each coin has an integer value and the (i+1)-th smallest value is divisible by the i-th smallest value for all i (1 \leq i \leq N-1).

For example, the set {1, 5, 10, 50, 100, 500} is considered as a beautiful system, while the set {1, 5, 10, 25, 50, 100} is NOT, because 25 is not divisible by 10.

Since changing the currency system may confuse citizens, the king, Kita_masa, wants to minimize the maximum value of the confusion ratios. Here, the confusion ratio for the change in the i-th coin is defined as |a_i - b_i| / a_i, where a_i and b_i is the value of i-th coin before and after the structure changes, respectively.

Note that Kita_masa can change the value of each existing coin, but he cannot introduce new coins nor eliminate existing coins. After the modification, the values of two or more coins may coincide.

Input

Each dataset contains two lines. The first line contains a single integer, N, and the second line contains N integers, {a_i}.

You may assume the following constraints:

1 \leq N \leq 20

1 \leq a_1 \lt a_2 \lt... \lt a_N \lt 10^5

Output

Output one number that represents the minimum of the maximum value of the confusion ratios. The value may be printed with an arbitrary number of decimal digits, but may not contain an absolute error greater than or equal to 10^{-8}.

Examples

Input

3
6 11 12

Output

0.090909090909

Input

3
6 11 24

Output

0.090909090909

Input

3
6 11 30

Output

0.166666666667

### Response

```cpp
 #include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                               #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,double>
                                        #define ppap pair<pa,int>

                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
                                        using namespace std;
                               			class pa3{
                                        	public:
                                        	int x,y,z;
                                        	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                        	bool operator < (const pa3 &p) const{
                                        		if(x!=p.x) return x<p.x;
                                        		if(y!=p.y) return y<p.y;
                                        		 return z<p.z;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                               				bool operator > (const pa3 &p) const{
                                        		if(x!=p.x) return x>p.x;
                                        		if(y!=p.y) return y>p.y;
                                        		 return z>p.z;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pa3 &p) const{
                                        		return x==p.x && y==p.y && z==p.z;
                                        	}
                                        		bool operator != (const pa3 &p) const{
                                        			return !( x==p.x && y==p.y && z==p.z);
                                        	}

                                        };

                                        class pa4{
                                        	public:
                                        	double x;
                                        	int y,z,w;
                                        	pa4(double x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                        	bool operator < (const pa4 &p) const{
                                        		if(x!=p.x) return x<p.x;
                                        		if(y!=p.y) return y<p.y;
                                        		if(z!=p.z)return z<p.z;
                                        		return w<p.w;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator > (const pa4 &p) const{
                                        		if(x!=p.x) return x>p.x;
                                        		if(y!=p.y) return y>p.y;
                                        		if(z!=p.z)return z>p.z;
                                        		return w>p.w;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pa4 &p) const{
                                        		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                        	}

                                        };
                                        class pa2{
                                        	public:
                                        	int x,y;
                                        	pa2(int x=0,int y=0):x(x),y(y) {}
                                        	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                        	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                        	bool operator < (const pa2 &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pa2 &p) const{
                                        		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                        	}
                                        	bool operator != (const pa2 &p) const{
                                        		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                        	}

                                        };

                                               #define ppa pair<int,pas>
                                        class Point{
                                        	public:
                                        	double x,y;
                                        	Point(double x=0,double y=0):x(x),y(y) {}
                                        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
                                        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
                                        	Point operator * (double a) {return Point(x*a,y*a);}
                                        	Point operator / (double a) {return Point(x/a,y/a);}
                                        	double absv() {return sqrt(norm());}
                                        	double norm() {return x*x+y*y;}
                                        	bool operator < (const Point &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const Point &p) const{
                                        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
                                        	}
                                        };
                                        typedef Point Vector;
                                 #define pl pair<int,pas>
                                        struct Segment{
                                        Point p1,p2;
                                        };
                                         double dot(Vector a,Vector b){
                                        	return a.x*b.x+a.y*b.y;
                                        }
                                        double cross(Vector a,Vector b){
                                        	return a.x*b.y-a.y*b.x;
                                        }

            bool parareru(Point a,Point b,Point c,Point d){
            //	if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl;
            	return abs(cross(a-b,d-c))<EPS;
            }
            double distance_ls_p(Point a, Point b, Point c) {
              if ( dot(b-a, c-a) < EPS ) return (c-a).absv();
              if ( dot(a-b, c-b) < EPS ) return (c-b).absv();
              return abs(cross(b-a, c-a)) / (b-a).absv();
            }
            bool is_intersected_ls(Segment a,Segment b) {
            	if(a.p1==b.p1||a.p2==b.p1||a.p1==b.p2||a.p2==b.p2) return false;
            	if(parareru((a.p2),(a.p1),(a.p1),(b.p2))&&parareru((a.p2),(a.p1),(a.p1),(b.p1))){
            //		cout<<"sss"<<endl;
            		if(dot(a.p1-b.p1,a.p1-b.p2)<EPS) return true;
            		if(dot(a.p2-b.p1,a.p2-b.p2)<EPS) return true;
            		if(dot(a.p1-b.p1,a.p2-b.p1)<EPS) return true;
            		if(dot(a.p1-b.p2,a.p2-b.p2)<EPS) return true;
            		return false;
            	}
              else return ( cross(a.p2-a.p1, b.p1-a.p1) * cross(a.p2-a.p1, b.p2-a.p1) < EPS ) && ( cross(b.p2-b.p1, a.p1-b.p1) * cross(b.p2-b.p1, a.p2-b.p1) < EPS );
            }

            double segment_dis(Segment a,Segment b){
            	if(is_intersected_ls(a,b))return 0;
            	double r=distance_ls_p(a.p1, a.p2, b.p1);
            	r=min(r,distance_ls_p(a.p1, a.p2, b.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p1));
            	return r;
            }
            Point intersection_ls(Segment a, Segment b) {
              Point ba = b.p2-b.p1;
              double d1 = abs(cross(ba, a.p1-b.p1));
              double d2 = abs(cross(ba, a.p2-b.p1));
              double t = d1 / (d1 + d2);

              return a.p1 + (a.p2-a.p1) * t;
            }

                            string itos( int i ) {
                            ostringstream s ;
                            s << i ;
                            return s.str() ;
                            }

                            int gcd(int v,int b){
                            	if(v>b) return gcd(b,v);
                            	if(v==b) return b;
                            	if(b%v==0) return v;
                            	return gcd(v,b%v);
                            }

                            double distans(double x1,double y1,double x2,double y2){
                            	double rr=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
                            	return sqrt(rr);

                            }

   //         int pr[2000010];
     //       int inv[2000010];

            int beki(int wa,int rr,int warukazu){
            	if(rr==0) return 1ll;
            	if(rr==1) return wa%warukazu;
            	if(rr%2==1) return (beki(wa,rr-1,warukazu)*wa)%warukazu;
            	int zx=beki(wa,rr/2,warukazu);
            	return (zx*zx)%warukazu;
            }
            /*
			int comb(int nn,int rr){
				int r=pr[nn]*inv[rr];
				r%=inf;
				r*=inv[nn-rr];
				r%=inf;
				return r;
			}

            void gya(int ert){
            	pr[0]=1;
            	for(int i=1;i<ert;i++){
            		pr[i]=(pr[i-1]*i)%inf;
            	}
            	for(int i=0;i<ert;i++) inv[i]=beki(pr[i],inf-2,inf);

            }
             */
			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
             //sort(ve.begin(),ve.end(),greater<int>());
                                     //----------------kokomade tenpure------------
            //vector<double> ans(100000000),ans2(100000000);
vector<int> ve[200003];
double dp[25][200003]={0};
int a[30];

int n;
double dfs(int i,int j){
	if(dp[i][j]>-0.001) return dp[i][j];
	if(i==n){
		dp[i][j]=abs(j-a[i]+0.0)/a[i]*1.0;
		return dp[i][j];
	}
double w=abs(j-a[i]+0.0)/a[i]*1.0;
	double e=1000000;
	for(auto v:ve[j]){
		e=min(e,dfs(i+1,v));
	}
	dp[i][j]=max(w,e);
//	cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
	return dp[i][j];

}

   signed main(){
   	for(int i=0;i<25;i++)for(int j=0;j<200003;j++)dp[i][j]=-100;
   	for(int i=1;i<=200000;i++){
   		int j=1;
   		while(j*j<=i){
   			if(j*j==i){
   				ve[i].pb(j);
   				break;
   			}
   			if(i%j==0){
   				ve[i].pb(j);
   				ve[i].pb(i/j);
   			}
   			j++;
   		}
   		sort(ve[i].begin(),ve[i].end());
   	}

   	cin>>n;
   	for(int i=0;i<n;i++){
   		cin>>a[n-i];
   	}
   	double ans=1000000000;
   	for(int i=1;i<=2*a[1];i++)ans=min(ans,dfs(1,i));
   	printf("%.10lf\n",ans);

   	return 0;
        }

```


### Prompt

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

We have N locked treasure boxes, numbered 1 to N.

A shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each key purchased can be used any number of times.

Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.

Constraints

* All values in input are integers.
* 1 \leq N \leq 12
* 1 \leq M \leq 10^3
* 1 \leq a_i \leq 10^5
* 1 \leq b_i \leq N
* 1 \leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \leq N

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
c_{11} c_{12} ... c_{1{b_1}}
:
a_M b_M
c_{M1} c_{M2} ... c_{M{b_M}}

Output

Print the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.

Examples

Input

2 3
10 1
1
15 1
2
30 2
1 2

Output

25

Input

12 1
100000 1
2

Output

-1

Input

4 6
67786 3
1 3 4
3497 1
2
44908 3
2 3 4
2156 3
2 3 4
26230 1
2
86918 1
3

Output

69942

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int n,m,a[200001],b[200001],c[1001][13];
    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i];
        rep(j,b[i]) cin>>c[i][j];
    }
    int dp[1<<n],INF=1e9;
    fill(dp,dp+(1<<n),INF);
    dp[(1<<n)-1]=0;
    for(int i=(1<<n)-2;i>=0;i--)rep(j,m){
        int x=0;
        rep(k,b[j]) x=x|1<<c[j][k]-1;
        if(~i&x) dp[i]=min(dp[i],dp[i|x]+a[j]);
    }
    if(dp[0]==INF) cout<<-1;
    else cout<<dp[0];
}
```


### Prompt

Please formulate a cpp solution to the following problem:

Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered from 1 to n. Buber requires k CPU cores each day.

The cloud provider offers m tariff plans, the i-th tariff plan is characterized by the following parameters:

  * l_i and r_i — the i-th tariff plan is available only on days from l_i to r_i, inclusive,
  * c_i — the number of cores per day available for rent on the i-th tariff plan,
  * p_i — the price of renting one core per day on the i-th tariff plan.

Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to c_i) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.

Find the minimum amount of money that Buber will pay for its work for n days from 1 to n. If on a day the total number of cores for all available tariff plans is strictly less than k, then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly k cores this day.

Input

The first line of the input contains three integers n, k and m (1 ≤ n,k ≤ 10^6, 1 ≤ m ≤ 2⋅10^5) — the number of days to analyze, the desired daily number of cores, the number of tariff plans.

The following m lines contain descriptions of tariff plans, one description per line. Each line contains four integers l_i, r_i, c_i, p_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ c_i, p_i ≤ 10^6), where l_i and r_i are starting and finishing days of the i-th tariff plan, c_i — number of cores, p_i — price of a single core for daily rent on the i-th tariff plan.

Output

Print a single integer number — the minimal amount of money that Buber will pay.

Examples

Input

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

Output

44

Input

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

Output

462

Input

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

Output

64

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
struct Vertex {
  long long cnt;
  long long sum;
  Vertex() { cnt = sum = 0; }
};
struct SegmentTree {
  Vertex tree[4 * MAXN];
  SegmentTree() = default;
  void calc(int v) {
    int lv = 2 * v + 1;
    int rv = 2 * v + 2;
    tree[v].cnt = tree[lv].cnt + tree[rv].cnt;
    tree[v].sum = tree[lv].sum + tree[rv].sum;
  }
  void modify(int v, int l, int r, int pos, long long c) {
    if (l == r) {
      tree[v].cnt += c;
      tree[v].sum += c * (long long)pos;
      return;
    }
    int med = (l + r) / 2;
    if (pos <= med) {
      modify(2 * v + 1, l, med, pos, c);
    } else {
      modify(2 * v + 2, med + 1, r, pos, c);
    }
    calc(v);
  }
  long long rec(int v, int l, int r, long long need) {
    if (tree[v].cnt <= need) {
      return tree[v].sum;
    }
    if (l == r) {
      return (long long)l * (long long)need;
    }
    int lv = 2 * v + 1;
    int rv = 2 * v + 2;
    int med = (l + r) / 2;
    if (tree[lv].cnt >= need) {
      return rec(lv, l, med, need);
    } else {
      long long rest = need - tree[lv].cnt;
      long long L = rec(lv, l, med, need);
      long long R = rec(rv, med + 1, r, rest);
      return L + R;
    }
  }
};
vector<pair<int, int>> events[MAXN];
SegmentTree tr;
int main() {
  int n, k, m;
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= m; i++) {
    int l, r, c, p;
    scanf("%d%d%d%d", &l, &r, &c, &p);
    events[l].emplace_back(p, c);
    events[r + 1].emplace_back(p, -c);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (auto& ev : events[i]) {
      tr.modify(0, 1, 1000000, ev.first, ev.second);
    }
    long long result = tr.rec(0, 1, 1000000, k);
    ans += result;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.

He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):

    ###      ..#      .#.      #..
    .#.      ###      .#.      ###
    .#.      ..#      ###      #..

Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.

Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?

Input

The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).

Output

In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.

Examples

Input

3 3

Output

1
AAA
.A.
.A.

Input

5 6

Output

4
A..C..
AAAC..
ABCCCD
.B.DDD
BBB..D

Input

2 2

Output

0
..
..

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
const int dx[4][5] = {0,  0,  0, 1, 2, -1, 0, 0, 0, 1,
                      -2, -1, 0, 0, 0, -1, 0, 0, 0, 1};
const int dy[4][5] = {-1, 0, 1,  0, 0, 0, -2, -1, 0, 0,
                      0,  0, -1, 0, 1, 0, 0,  1,  2, 0};
char Ans[N][N], a[N][N];
int n, m, ans;
bool check(int x, int y) {
  for (int t = 0; t < 4; ++t) {
    bool ovo = 1;
    for (int i = 0; i < 5; ++i) {
      int X = x + dx[t][i], Y = y + dy[t][i];
      if (X <= 0 || X > n || Y <= 0 || Y > m || a[X][Y] != '.') ovo = 0;
    }
    if (ovo) return 1;
  }
  return 0;
}
bool dfs(int x, int y, int s, int num) {
  if (y > m) y = 1, x++;
  if (s == ans) return 1;
  if (num / 6 + s < ans) return 0;
  for (; !check(x, y) && x <= n;) {
    y++;
    if (y > m) y = 1, x++;
  }
  if (x > n) return 0;
  for (int t = 0; t < 4; ++t) {
    bool ovo = 1;
    for (int i = 0; i < 5; ++i) {
      int X = x + dx[t][i], Y = y + dy[t][i];
      if (X <= 0 || X > n || Y <= 0 || Y > m || a[X][Y] != '.') ovo = 0;
    }
    if (ovo) {
      char c = s + 'A';
      for (int i = 0; i < 5; ++i) {
        int X = x + dx[t][i], Y = y + dy[t][i];
        a[X][Y] = c;
      }
      if (dfs(x, y + 1, s + 1, num - 5)) return 1;
      for (int i = 0; i < 5; ++i) {
        int X = x + dx[t][i], Y = y + dy[t][i];
        a[X][Y] = '.';
      }
    }
  }
  return dfs(x, y + 1, s, num);
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == 9 && m == 9) {
    puts("13");
    puts("AAABBBCCC");
    puts(".AD.BE.C.");
    puts(".AD.BE.C.");
    puts("FDDDEEE.H");
    puts("FFFGGGHHH");
    puts("FIIIGJJJH");
    puts(".LIKG.JM.");
    puts(".LIKKKJM.");
    puts("LLLK..MMM");
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) a[i][j] = '.';
  for (ans = 0; ans < 20 && dfs(0, 0, 0, n * m); ++ans) {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) Ans[i][j] = a[i][j], a[i][j] = '.';
  }
  printf("%d\n", ans - 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) cout << Ans[i][j];
    puts("");
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.

Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya.

If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.

Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.

Input

The first line contains the integer n (1 ≤ n ≤ 105).

n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.

Output

In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.

You can print the stones in arbitrary order. If there are several answers print any of them.

Examples

Input

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

Output

1
1

Input

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

Output

2
1 5

Note

In the first example we can connect the pairs of stones:

  * 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
  * 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.
  * 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5
  * 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
  * 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5

Or take only one stone:

  * 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5
  * 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
  * 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5
  * 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5
  * 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
  * 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5

It is most profitable to take only the first stone.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, pair<int, int> > mp;
int ans = 0, idx1 = -1, idx2 = -1;
int n;
int main(void) {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
    if (a > ans) {
      ans = a;
      idx1 = i;
      idx2 = -1;
    }
    if (mp.find({b, c}) == mp.end()) {
      mp[{b, c}] = {a, i};
    } else {
      auto it = mp.find({b, c});
      int val = min(b, it->second.first + a);
      if (val > ans) {
        ans = val;
        idx1 = it->second.second;
        idx2 = i;
      }
      if (a > it->second.first) {
        it->second = {a, i};
      }
    }
  }
  cout << 1 + (idx2 != -1) << endl;
  cout << idx1;
  if (idx2 != -1) cout << " " << idx2;
  cout << endl;
  return 0;
}

```


### Prompt

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

You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph.

You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices x and y is a_x + a_y coins. There are also m special offers, each of them is denoted by three numbers x, y and w, and means that you can add an edge connecting vertices x and y and pay w coins for it. You don't have to use special offers: if there is a pair of vertices x and y that has a special offer associated with it, you still may connect these two vertices paying a_x + a_y coins for it.

What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.

Input

The first line contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ 2 ⋅ 10^5) — the number of vertices in the graph and the number of special offers, respectively.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^{12}) — the numbers written on the vertices.

Then m lines follow, each containing three integers x, y and w (1 ≤ x, y ≤ n, 1 ≤ w ≤ 10^{12}, x ≠ y) denoting a special offer: you may add an edge connecting vertex x and vertex y, and this edge will cost w coins.

Output

Print one integer — the minimum number of coins you have to pay to make the graph connected.

Examples

Input

3 2
1 3 3
2 3 5
2 1 1

Output

5

Input

4 0
1 3 3 7

Output

16

Input

5 4
1 2 3 4 5
1 2 8
1 3 10
1 4 7
1 5 15

Output

18

Note

In the first example it is possible to connect 1 to 2 using special offer 2, and then 1 to 3 without using any offers.

In next two examples the optimal answer may be achieved without using special offers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
struct node1 {
  long long v;
  int flag;
} a[1000000];
struct node {
  int x, y;
  long long v;
} b[1000000];
bool cmp(node a, node b) { return a.v < b.v; }
int c[1000000];
int find(int x) { return x != c[x] ? find(c[x]) : x; }
int main() {
  init();
  int n, m;
  cin >> n >> m;
  a[n].v = 1000000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i].v;
    a[i].flag = i + 1;
    if (a[n].v >= a[i].v) {
      a[n].v = a[i].v;
      a[n].flag = a[i].flag;
    }
  }
  for (int i = 0; i < m; i++) cin >> b[i].x >> b[i].y >> b[i].v;
  for (int i = 0; i < n; i++) {
    if (a[n].flag != a[i].flag) {
      b[m].x = a[n].flag;
      b[m].y = a[i].flag;
      b[m++].v = a[n].v + a[i].v;
    }
  }
  sort(b, b + m, cmp);
  long long ans = 0;
  for (int i = 0; i <= n; i++) c[i] = i;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    if (cnt == n - 1) break;
    int x = find(b[i].x);
    int y = find(b[i].y);
    c[b[i].x] = x;
    c[b[i].y] = y;
    if (x != y) {
      c[x] = y;
      ans += b[i].v;
      cnt++;
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You are given an array A, consisting of n positive integers a_1, a_2, ..., a_n, and an array B, consisting of m positive integers b_1, b_2, ..., b_m.

Choose some element a of A and some element b of B such that a+b doesn't belong to A and doesn't belong to B.

For example, if A = [2, 1, 7] and B = [1, 3, 4], we can choose 1 from A and 4 from B, as number 5 = 1 + 4 doesn't belong to A and doesn't belong to B. However, we can't choose 2 from A and 1 from B, as 3 = 2 + 1 belongs to B.

It can be shown that such a pair exists. If there are multiple answers, print any.

Choose and print any such two numbers.

Input

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

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 200) — the elements of A.

The third line contains one integer m (1≤ m ≤ 100) — the number of elements of B.

The fourth line contains m different integers b_1, b_2, ..., b_m (1 ≤ b_i ≤ 200) — the elements of B.

It can be shown that the answer always exists.

Output

Output two numbers a and b such that a belongs to A, b belongs to B, but a+b doesn't belong to nor A neither B.

If there are multiple answers, print any.

Examples

Input

1
20
2
10 20

Output

20 20

Input

3
3 2 2
5
1 5 7 7 9

Output

3 1

Input

4
1 3 5 7
4
7 5 3 1

Output

1 1

Note

In the first example, we can choose 20 from array [20] and 20 from array [10, 20]. Number 40 = 20 + 20 doesn't belong to any of those arrays. However, it is possible to choose 10 from the second array too.

In the second example, we can choose 3 from array [3, 2, 2] and 1 from array [1, 5, 7, 7, 9]. Number 4 = 3 + 1 doesn't belong to any of those arrays.

In the third example, we can choose 1 from array [1, 3, 5, 7] and 1 from array [7, 5, 3, 1]. Number 2 = 1 + 1 doesn't belong to any of those arrays.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, c, d = 0, m;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) cin >> x;
  cin >> m;
  vector<int> b(m);
  for (auto &y : b) cin >> y;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << a[n - 1] << " " << b[m - 1] << endl;
}

```


### Prompt

Create a solution in CPP for the following problem:

Alice and Bob have a tree (undirected acyclic connected graph). There are ai chocolates waiting to be picked up in the i-th vertex of the tree. First, they choose two different vertices as their starting positions (Alice chooses first) and take all the chocolates contained in them.

Then, they alternate their moves, selecting one vertex at a time and collecting all chocolates from this node. To make things more interesting, they decided that one can select a vertex only if he/she selected a vertex adjacent to that one at his/her previous turn and this vertex has not been already chosen by any of them during other move.

If at any moment one of them is not able to select the node that satisfy all the rules, he/she will skip his turns and let the other person pick chocolates as long as he/she can. This goes on until both of them cannot pick chocolates any further.

Due to their greed for chocolates, they want to collect as many chocolates as possible. However, as they are friends they only care about the total number of chocolates they obtain together. What is the maximum total number of chocolates they may pick?

Input

The first line of the input contains the single integer n (2 ≤ n ≤ 100 000) — the number of vertices in the tree.

The second line contains n integers ai (1 ≤ ai ≤ 109), i-th of these numbers stands for the number of chocolates stored at the node i.

Then follow n - 1 lines that describe the tree. Each of them contains two integers ui and vi (1 ≤ ui, vi ≤ n) — indices of vertices connected by the i-th edge.

Output

Print the number of chocolates Alice and Bob can collect together if they behave optimally.

Examples

Input

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

Output

25

Input

2
20 10
1 2

Output

30

Note

In the first sample, Alice may start at the vertex 9 and Bob at vertex 8. Alice will select vertex 1 and Bob has no options now. Alice selects the vertex 7 and they both stop.

In the second sample, both of them will pick either of the nodes alternately.

### Response

```cpp
#include <bits/stdc++.h>
int N, head[100001], next[199999], to[199999], E, q[100001], fa[100001];
long long w[100001], f0[100001], f1[100001], g0[100001], g1[100001];
inline void cover(long long &x, long long &y, long long z) {
  if (z > x)
    y = x, x = z;
  else if (z > y)
    y = z;
}
inline void cover(long long &x, long long &y, long long &z, long long w) {
  if (w > x)
    z = y, y = x, x = w;
  else if (w > y)
    z = y, y = w;
  else if (w > z)
    z = w;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%lld", w + i);
  for (int i = 1, u, v; i < N; i++) {
    scanf("%d%d", &u, &v);
    next[++E] = head[u], to[E] = v, head[u] = E;
    next[++E] = head[v], to[E] = u, head[v] = E;
  }
  int H = 0, T = 1, u;
  q[1] = 1;
  while (H < T)
    for (int e = head[u = q[++H]]; e; e = next[e])
      if (to[e] != fa[u]) fa[q[++T] = to[e]] = u;
  for (int i = N; i; i--) {
    int u = q[i];
    long long f0_0 = 0, f0_1 = 0, f0_2 = 0;
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u]) {
        cover(f0_0, f0_1, f0_2, f0[to[e]]);
        g0[u] = std::max(g0[u], g0[to[e]]);
      }
    f0[u] = f0_0 + w[u];
    g0[u] = std::max(g0[u], f0_0 + f0_1 + w[u]);
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u])
        f1[u] = std::max(
            f1[u],
            std::max(g0[to[e]] + (f0_0 == f0[to[e]] ? f0_1 : f0_0), f1[to[e]]));
    f1[u] += w[u];
    long long g0_0 = 0, g0_1 = 0;
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u]) {
        cover(g0_0, g0_1, g0[to[e]]);
        g1[u] = std::max(g1[u], g1[to[e]]);
      }
    g1[u] = std::max(g1[u], g0_0 + g0_1);
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u])
        g1[u] = std::max(
            g1[u],
            w[u] +
                std::max(f1[to[e]] + (f0[to[e]] == f0_0 ? f0_1 : f0_0),
                         g0[to[e]] + (f0_0 == f0[to[e]] ? f0_1 : f0_0) +
                             (f0_0 == f0[to[e]] || f0_1 == f0[to[e]] ? f0_2
                                                                     : f0_1)));
  }
  printf("%lld\n", std::max(std::max(f0[1], f1[1]), std::max(g0[1], g1[1])));
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Misha has a tree with characters written on the vertices. He can choose two vertices s and t of this tree and write down characters of vertices lying on a path from s to t. We'll say that such string corresponds to pair (s, t).

Misha has m queries of type: you are given 4 vertices a, b, c, d; you need to find the largest common prefix of the strings that correspond to pairs (a, b) and (c, d). Your task is to help him.

Input

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

Next follows a line consisting of n small English letters. The i-th character of the string corresponds to the character written on the i-th vertex.

Next n - 1 lines contain information about edges. An edge is defined by a pair of integers u, v (1 ≤ u, v ≤ n, u ≠ v), separated by spaces.

The next line contains integer m (1 ≤ m ≤ 1 000 000) — the number of queries.

Next m lines contain information about queries. A query is defined by four integers a, b, c, d (1 ≤ a, b, c, d ≤ n), separated by spaces.

Output

For each query print the length of the largest common prefix on a separate line.

Examples

Input

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

Output

2
2
2
0
1
0

### Response

```cpp
#include <bits/stdc++.h>
inline int read(void) {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') f = c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c & 15), c = getchar();
  return x * f;
}
inline int getm(long long x, int mod) { return (x % mod + mod) % mod; }
const int N = 300005;
const int mod1 = 998244353, mod2 = 1000000007;
const int inv1 = 729486258, inv2 = 576923081;
int n, m;
int pw[N][2], inv[N][2];
char s[N];
struct Edge {
  int to, nxt;
} E[N << 1];
int head[N], tot;
inline void add(int f, int t) {
  E[++tot] = (Edge){t, head[f]}, head[f] = tot;
  return;
}
int hh1[N][2], hh2[N][2];
int lg[N << 1], dep[N], fa[N][20], len[N], son[N], dfn[N], tt, st[N << 1][21];
int top[N], *up[N], *down[N];
void init(void) {
  pw[0][0] = pw[0][1] = inv[0][0] = inv[0][1] = 1;
  for (int i = 1; i <= n; ++i)
    pw[i][0] = 26ll * pw[i - 1][0] % mod1,
    pw[i][1] = 26ll * pw[i - 1][1] % mod2,
    inv[i][0] = 1ll * inv1 * inv[i - 1][0] % mod1,
    inv[i][1] = 1ll * inv2 * inv[i - 1][1] % mod2;
  for (int i = 1; i <= n << 1; ++i) lg[i] = lg[i >> 1] + 1;
  return;
}
void dfs1(int x, int from) {
  dep[x] = dep[from] + 1, fa[x][0] = from, st[dfn[x] = ++tt][0] = x;
  hh1[x][0] = (26ll * hh1[fa[x][0]][0] + (s[x] - 'a')) % mod1;
  hh1[x][1] =
      (hh1[fa[x][0]][1] + 1ll * pw[dep[x] - 1][0] * (s[x] - 'a')) % mod1;
  hh2[x][0] = (26ll * hh2[fa[x][0]][0] + (s[x] - 'a')) % mod2;
  hh2[x][1] =
      (hh2[fa[x][0]][1] + 1ll * pw[dep[x] - 1][1] * (s[x] - 'a')) % mod2;
  for (int i = 1; i < lg[dep[x]]; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = head[x]; i; i = E[i].nxt) {
    int y = E[i].to;
    if (y == from) continue;
    dfs1(y, x);
    st[++tt][0] = x, son[x] = len[son[x]] > len[y] ? son[x] : y;
  }
  len[x] = len[son[x]] + 1;
  return;
}
void dfs2(int x, int tp) {
  top[x] = tp;
  if (tp == x) {
    up[x] = new int[len[x] + 5], down[x] = new int[len[x] + 5];
    for (int y = x, l = 0; y != 0 && l <= len[x]; y = fa[y][0], ++l)
      up[x][l] = y;
  }
  down[tp][dep[x] - dep[tp]] = x;
  if (son[x]) dfs2(son[x], tp);
  for (int i = head[x]; i; i = E[i].nxt) {
    int y = E[i].to;
    if (y == fa[x][0] || y == son[x]) continue;
    dfs2(y, y);
  }
  return;
}
inline void init_st(void) {
  for (int k = 1; k < lg[tt]; ++k)
    for (int i = 1; i + (1 << k) - 1 <= tt; ++i)
      st[i][k] = dep[st[i][k - 1]] < dep[st[i + (1 << (k - 1))][k - 1]]
                     ? st[i][k - 1]
                     : st[i + (1 << (k - 1))][k - 1];
  return;
}
inline int lca(int l, int r) {
  l = dfn[l], r = dfn[r];
  if (l > r) std::swap(l, r);
  int k = lg[r - l + 1] - 1;
  return dep[st[l][k]] < dep[st[r - (1 << k) + 1][k]] ? st[l][k]
                                                      : st[r - (1 << k) + 1][k];
}
inline int kth(int x, int k) {
  if (k == 0)
    return x;
  else if (k >= dep[x])
    return 0;
  x = fa[x][lg[k] - 1], k ^= 1 << (lg[k] - 1);
  if (dep[top[x]] <= dep[x] - k)
    return down[top[x]][dep[x] - k - dep[top[x]]];
  else
    return up[top[x]][dep[top[x]] - dep[x] + k];
}
inline std::pair<int, int> hashh(int a, int b, int k) {
  int f = lca(a, b), l = dep[a] + dep[b] - dep[f] * 2 + 1;
  int hash1 = 0, hash2 = 0;
  if (k <= dep[a] - dep[f] + 1)
    hash1 = getm(hh1[a][0] - 1ll * pw[k][0] * hh1[kth(a, k)][0], mod1),
    hash2 = getm(hh2[a][0] - 1ll * pw[k][1] * hh2[kth(a, k)][0], mod2);
  else
    hash1 =
        (getm(hh1[a][0] - 1ll * pw[dep[a] - dep[f] + 1][0] * hh1[fa[f][0]][0],
              mod1) +
         1ll * inv[dep[f]][0] * pw[dep[a] - dep[f] + 1][0] % mod1 *
             getm(hh1[kth(b, l - k)][1] - hh1[f][1], mod1) % mod1) %
        mod1,
    hash2 =
        (getm(hh2[a][0] - 1ll * pw[dep[a] - dep[f] + 1][1] * hh2[fa[f][0]][0],
              mod2) +
         1ll * inv[dep[f]][1] * pw[dep[a] - dep[f] + 1][1] % mod2 *
             getm(hh2[kth(b, l - k)][1] - hh2[f][1], mod2) % mod2) %
        mod2;
  return std::make_pair(hash1, hash2);
}
inline int solve(int a, int b, int c, int d) {
  int f1 = lca(a, b), f2 = lca(c, d), l1 = dep[a] + dep[b] - dep[f1] * 2 + 1,
      l2 = dep[c] + dep[d] - dep[f2] * 2 + 1;
  int l = 1, r = std::min(l1, l2), res = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (hashh(a, b, mid) == hashh(c, d, mid))
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return res;
}
int main(void) {
  n = read();
  scanf("%s", s + 1);
  for (int i = 1, u, v; i < n; ++i)
    u = read(), v = read(), add(u, v), add(v, u);
  init();
  dfs1(1, 0), dfs2(1, 1);
  init_st();
  m = read();
  for (int i = 1, a, b, c, d; i <= m; ++i)
    a = read(), b = read(), c = read(), d = read(),
    printf("%d\n", solve(a, b, c, d));
  return 0;
}

```


### Prompt

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

We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:

* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.

Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.

Constraints

* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.

Examples

Input

xabxa

Output

2

Input

ab

Output

-1

Input

a

Output

0

Input

oxxx

Output

3

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int i,j,bo,ans;
string st;
int main()
{
	getline(cin,st);
	i=0;j=st.size()-1;
	while(i<=j)
	{
		if(st[i]==st[j]) {i++;j--;continue;}
		if(st[i]=='x') {i++;ans++;continue;}
		if(st[j]=='x') {j--;ans++;continue;}
		bo=1;break;
	}
	if(bo!=1) cout<<ans<<"\n";
	  else cout<<-1<<"\n";
	return 0;
 }
```


### Prompt

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

Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.

Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" <image> "nastya" <image> "nastya" <image> "nastya" <image> "nastya" <image> "nastya" <image> "nastya".

Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.

It is guaranteed that the word p can be obtained by removing the letters from word t.

Input

The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.

Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, all ai are distinct).

Output

Print a single integer number, the maximum number of letters that Nastya can remove.

Examples

Input

ababcba
abb
5 3 4 1 7 6 2

Output

3

Input

bbbabb
bb
1 6 3 4 2 5

Output

4

Note

In the first sample test sequence of removing made by Nastya looks like this:

"ababcba" <image> "ababcba" <image> "ababcba" <image> "ababcba"

Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".

So, Nastya will remove only three letters.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BM(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T mdINV(T a, T M) {
  return BM(a, M - 2, M);
}
template <class T>
inline T PW(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
template <class T>
string NTS(T Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
template <class T>
T stringtonumber(const string &Text) {
  istringstream ss(Text);
  T result;
  return ss >> result ? result : 0;
}
template <class T>
bool ISLEFT(T a, T b, T c) {
  if (((a.first.first - b.first.first) * (b.second.second - c.second.second) -
       (b.first.first - c.first.first) * (a.second.second - b.second.second)) <
      0.0)
    return 1;
  else
    return 0;
}
char a[2000000 + 2], b[2000000 + 2];
int main() {
  scanf("%s%s", a + 1, b + 1);
  int l = strlen(a + 1);
  int l1 = strlen(b + 1);
  int ar[l + 2];
  for (int i = 1; i <= l; i++) scanf("%d", &ar[i]);
  int lo = 1, hi = l;
  int ans = 0;
  bool op[l + 2];
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int st = 1;
    memset(op, 0, sizeof op);
    for (int i = 1; i <= mid; i++) op[ar[i]] = 1;
    bool fl = 0;
    for (int i = 1; i <= l1; i++) {
      while (st <= l && (b[i] != a[st] || op[st] == 1)) st++;
      if (st > l) fl = 1;
      st++;
    }
    if (!fl) {
      lo = mid + 1;
      ans = mid;
    } else
      hi = mid - 1;
  }
  printf("%d", ans);
  return 0;
}

```


### Prompt

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

Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (xi, yi) of the plane. As the player visits station number i, he increases the current time on his timer by ai. The stations are for one-time use only, so if the player visits some station another time, the time on his timer won't grow.

A player spends d·dist time units to move between stations, where dist is the distance the player has covered and d is some constant. The distance between stations i and j is determined as |xi - xj| + |yi - yj|.

Initially, the player is at station number 1, and the player has strictly more than zero and strictly less than one units of time. At station number 1 one unit of money can increase the time on the timer by one time unit (you can buy only integer number of time units).

Now Yaroslav is wondering, how much money he needs to get to station n. Help Yaroslav. Consider the time to buy and to increase the timer value negligibly small.

Input

The first line contains integers n and d (3 ≤ n ≤ 100, 103 ≤ d ≤ 105) — the number of stations and the constant from the statement.

The second line contains n - 2 integers: a2, a3, ..., an - 1 (1 ≤ ai ≤ 103). The next n lines contain the coordinates of the stations. The i-th of them contains two integers xi, yi (-100 ≤ xi, yi ≤ 100).

It is guaranteed that no two stations are located at the same point.

Output

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

Examples

Input

3 1000
1000
0 0
0 1
0 3

Output

2000

Input

3 1000
1000
1 0
1 1
1 2

Output

1000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[105][105] = {0};
int a[105], x[105], y[105];
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  for (int i = 2; i <= n - 1; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = d * (abs(x[i] - x[j]) + abs(y[i] - y[j])) - a[i];
    }
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i != j && j != k && i != k && dp[i][j] > dp[i][k] + dp[k][j])
          dp[i][j] = dp[i][k] + dp[k][j];
      }
    }
  }
  if (dp[1][n] < 0)
    printf("0\n");
  else
    printf("%d\n", dp[1][n]);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Vasya owns three big integers — a, l, r. Let's define a partition of x such a sequence of strings s_1, s_2, ..., s_k that s_1 + s_2 + ... + s_k = x, where + is a concatanation of strings. s_i is the i-th element of the partition. For example, number 12345 has the following partitions: ["1", "2", "3", "4", "5"], ["123", "4", "5"], ["1", "2345"], ["12345"] and lots of others.

Let's call some partition of a beautiful if each of its elements contains no leading zeros.

Vasya want to know the number of beautiful partitions of number a, which has each of s_i satisfy the condition l ≤ s_i ≤ r. Note that the comparison is the integer comparison, not the string one.

Help Vasya to count the amount of partitions of number a such that they match all the given requirements. The result can be rather big, so print it modulo 998244353.

Input

The first line contains a single integer a~(1 ≤ a ≤ 10^{1000000}).

The second line contains a single integer l~(0 ≤ l ≤ 10^{1000000}).

The third line contains a single integer r~(0 ≤ r ≤ 10^{1000000}).

It is guaranteed that l ≤ r.

It is also guaranteed that numbers a, l, r contain no leading zeros.

Output

Print a single integer — the amount of partitions of number a such that they match all the given requirements modulo 998244353.

Examples

Input

135
1
15

Output

2

Input

10000
0
9

Output

1

Note

In the first test case, there are two good partitions 13+5 and 1+3+5.

In the second test case, there is one good partition 1+0+0+0+0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
const int inf = 1e9 + 7;
const long long INF = 1e18;
const int N = 1e6 + 10;
string s, l, r;
long long f[N];
int L, R, n;
int inc[N], decr[N];
vector<int> z_f(const string &s) {
  int n = ((int)s.size());
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;
    if (i + z[i] - 1 > r) {
      l = i, r = i + z[i] - 1;
    }
  }
  return z;
}
long long dp(int idx) {
  if (idx > n) return 0;
  if (idx == n) return 1;
  long long &ans = f[idx];
  if (~ans) return ans;
  ans = 0;
  if (s[idx] == '0') {
    ans = dp(idx + 1);
    if (l == "0") {
      ans += dp(idx + 1) - dp(idx + 2);
    }
    ans += M;
    ans %= M;
    return ans;
  }
  int lidx = idx + L + inc[idx];
  int ridx = min(n, idx + R - decr[idx]);
  if (lidx <= n) {
    ans += dp(lidx) - dp(ridx + 1);
  }
  ans += M;
  ans %= M;
  ans += dp(idx + 1);
  ans %= M;
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> l >> r;
  memset(f, -1, sizeof f);
  n = ((int)s.size());
  L = ((int)l.size());
  R = ((int)r.size());
  string tmp = l + '#' + s;
  vector<int> zl, zr;
  zl = z_f(tmp);
  for (int i = 0; i < (n); i++) {
    int idx = zl[i + L + 1];
    if (idx < L && i + idx < n && s[i + idx] < l[idx]) inc[i]++;
  }
  tmp = r + '#' + s;
  zr = z_f(tmp);
  for (int i = 0; i < (n); i++) {
    int idx = zr[i + R + 1];
    if (idx < R && i + idx < n && s[i + idx] > r[idx]) decr[i]++;
  }
  int ans = dp(0) - dp(1);
  ans += M;
  ans %= M;
  cout << ans << endl;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.

First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.

Then, Aoki gave him M queries. The i-th of them is as follows:

* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.

After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries.

Determine whether there exists a tree that has the property mentioned by Takahashi.

Constraints

* 2 ≤ N ≤ 10^5
* 1 ≤ M ≤ 10^5
* 1 ≤ a_i,b_i ≤ N
* a_i ≠ b_i

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
:
a_M b_M

Output

Print `YES` if there exists a tree that has the property mentioned by Takahashi; print `NO` otherwise.

Examples

Input

4 4
1 2
2 4
1 3
3 4

Output

YES

Input

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

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
int main(){int a,b,m;scanf("%d%d",&a,&m);std::bitset<100005>c;while(m--){scanf("%d%d",&a,&b);c[a]=!c[a];c[b]=!c[b];}printf(c.any()?"NO":"YES");}
```


### Prompt

Construct a cpp code solution to the problem outlined:

This is the easy version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 2000. The hard version of this challenge is not offered in the round for the second division.

Let's define a correct bracket sequence and its depth as follow:

  * An empty string is a correct bracket sequence with depth 0.
  * If "s" is a correct bracket sequence with depth d then "(s)" is a correct bracket sequence with depth d + 1.
  * If "s" and "t" are both correct bracket sequences then their concatenation "st" is a correct bracket sequence with depth equal to the maximum depth of s and t.

For a (not necessarily correct) bracket sequence s, we define its depth as the maximum depth of any correct bracket sequence induced by removing some characters from s (possibly zero). For example: the bracket sequence s = "())(())" has depth 2, because by removing the third character we obtain a correct bracket sequence "()(())" with depth 2.

Given a string a consists of only characters '(', ')' and '?'. Consider all (not necessarily correct) bracket sequences obtained by replacing all characters '?' in a by either '(' or ')'. Calculate the sum of all the depths of all these bracket sequences. As this number can be large, find it modulo 998244353.

Hacks in this problem in the first division can be done only if easy and hard versions of this problem was solved.

Input

The only line contains a non-empty string consist of only '(', ')' and '?'. The length of the string is at most 2000.

Output

Print the answer modulo 998244353 in a single line.

Examples

Input

??

Output

1

Input

(?(?))

Output

9

Note

In the first test case, we can obtain 4 bracket sequences by replacing all characters '?' with either '(' or ')':

  * "((". Its depth is 0;
  * "))". Its depth is 0;
  * ")(". Its depth is 0;
  * "()". Its depth is 1.

So, the answer is 1 = 0 + 0 + 0 + 1.

In the second test case, we can obtain 4 bracket sequences by replacing all characters '?' with either '(' or ')':

  * "(((())". Its depth is 2;
  * "()()))". Its depth is 2;
  * "((()))". Its depth is 3;
  * "()(())". Its depth is 2.

So, the answer is 9 = 2 + 2 + 3 + 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int mod = 998244353;
char str[N];
long long l[N], r[N], s[N];
long long q_pow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) (res *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return res;
}
long long c(long long a, long long b) {
  if (a < b) return 0;
  long long x = 1, y = 1;
  for (long long i = a, j = 1; j <= b; i--, j++)
    x = x * i % mod, y = y * j % mod;
  return (x * q_pow(y, mod - 2)) % mod;
}
long long lu(long long a, long long b) {
  if (a < mod && b < mod) return c(a, b);
  return (long long)c(a % mod, b % mod) * lu(a / mod, b / mod) % mod;
}
long long cal[2][N];
void init(long long n, long long a[]) {
  a[0] = 1;
  for (long long i = 1; i <= n; i++) {
    a[i] = (((a[i - 1] * (n - i + 1)) % mod) * q_pow(i, mod - 2)) % mod;
  }
  for (long long i = 1; i <= n; i++) {
    (a[i] += a[i - 1]) %= mod;
  }
}
int main() {
  long long ans = 0;
  scanf("%s", str + 1);
  long long n = strlen(str + 1);
  for (int i = 1; i <= n; i++) {
    l[i] = l[i - 1];
    r[i] = r[i - 1];
    s[i] = s[i - 1];
    if (str[i] == '(')
      l[i]++;
    else if (str[i] == ')')
      r[i]++;
    else if (str[i] == '?')
      s[i]++;
  }
  init(s[n], cal[s[n] & 1]);
  init(s[n] - 1, cal[(s[n] - 1) & 1]);
  long long ss = s[n];
  for (int i = 1; i <= n; i++) {
    long long le = -l[i] + r[n] - r[i] + s[n] - s[i];
    if (str[i] == '(') {
      le = min(le, ss);
      if (le < 0) continue;
      (ans += (cal[ss & 1][le])) %= mod;
    } else if (str[i] == '?') {
      le = min(le - 1, ss - 1);
      if (le < 0) continue;
      (ans += (cal[(ss - 1) & 1][le])) %= mod;
    }
  }
  cout << ans << endl;
}

```


### Prompt

Please create a solution in cpp to the following problem:

One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.

Input

The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.

Output

It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.

Examples

Input

A>B
C<B
A>C

Output

CBA

Input

A<B
B>C
C>A

Output

ACB

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 10e6 + 5;
const long long oo = 1000000005;
string a[6] = {"ABC", "ACB", "BAC", "BCA", "CAB", "CBA"};
string b[6] = {"ABACBC", "ABACCB", "ACBABC", "BABCCA", "ABCACB", "BACACB"};
string s[3];
void in() {
  for (int i = 0; i < 3; i++) {
    string temp;
    cin >> temp;
    if (temp[1] == '>') swap(temp[0], temp[2]);
    temp.erase(1, 1);
    s[i] = temp;
  }
  sort(s, s + 3);
}
void sol() {
  string t = "";
  for (int i = 0; i < 3; i++) t += s[i];
  for (int i = 0; i < 6; i++)
    if (t == b[i]) {
      cout << a[i] << endl;
      return;
    }
  cout << "Impossible";
}
int main() {
  in();
  sol();
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If string s contains no two consecutive periods, then nothing happens.

Let's define f(s) as the minimum number of operations of replacement to perform, so that the string does not have any two consecutive periods left.

You need to process m queries, the i-th results in that the character at position xi (1 ≤ xi ≤ n) of string s is assigned value ci. After each operation you have to calculate and output the value of f(s).

Help Daniel to process all queries.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 300 000) the length of the string and the number of queries.

The second line contains string s, consisting of n lowercase English letters and period signs.

The following m lines contain the descriptions of queries. The i-th line contains integer xi and ci (1 ≤ xi ≤ n, ci — a lowercas English letter or a period sign), describing the query of assigning symbol ci to position xi.

Output

Print m numbers, one per line, the i-th of these numbers must be equal to the value of f(s) after performing the i-th assignment.

Examples

Input

10 3
.b..bz....
1 h
3 c
9 f

Output

4
3
1

Input

4 4
.cc.
2 .
3 .
2 a
1 a

Output

1
3
1
1

Note

Note to the first sample test (replaced periods are enclosed in square brackets).

The original string is ".b..bz....".

  * after the first query f(hb..bz....) = 4 ("hb[..]bz...."  →  "hb.bz[..].."  →  "hb.bz[..]."  →  "hb.bz[..]"  →  "hb.bz.")
  * after the second query f(hbс.bz....) = 3 ("hbс.bz[..].."  →  "hbс.bz[..]."  →  "hbс.bz[..]"  →  "hbс.bz.")
  * after the third query f(hbс.bz..f.) = 1 ("hbс.bz[..]f."  →  "hbс.bz.f.")

Note to the second sample test.

The original string is ".cc.".

  * after the first query: f(..c.) = 1 ("[..]c."  →  ".c.")
  * after the second query: f(....) = 3 ("[..].."  →  "[..]."  →  "[..]"  →  ".")
  * after the third query: f(.a..) = 1 (".a[..]"  →  ".a.")
  * after the fourth query: f(aa..) = 1 ("aa[..]"  →  "aa.")

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000;
string s;
int main() {
  long long n, m, ans = 0, i, x;
  char c;
  cin >> n >> m >> s;
  for (i = 1; i < n; i++)
    if ((s[i] == '.') && (s[i - 1] == '.')) ans++;
  for (i = 0; i < m; i++) {
    scanf("%I64d", &x);
    x--;
    cin >> c;
    if (((c == '.') && (s[x] == '.')) || ((c != '.') && (s[x] != '.'))) {
      printf("%I64d\n", ans);
      continue;
    }
    if (s[x] == '.') {
      if ((x - 1 >= 0) && (s[x - 1] == '.')) ans--;
      if ((x + 1 < n) && (s[x + 1] == '.')) ans--;
      s[x] = c;
      printf("%I64d\n", ans);
      continue;
    }
    if ((x - 1 >= 0) && (s[x - 1] == '.')) ans++;
    if ((x + 1 < n) && (s[x + 1] == '.')) ans++;
    s[x] = c;
    printf("%I64d\n", ans);
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

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

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

Input

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

Output

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

Examples

Input

13

Output

17

Input

4

Output

4

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _f(const char* name, T&& arg) {
  cout << name << ": " << arg << '\n';
}
template <typename T, typename... Args>
void _f(const char* names, T&& arg, Args&&... args) {
  const char* split = strchr(names + 1, ',');
  cout.write(names, split - names) << ": " << arg << " |";
  _f(split, args...);
}
double tick() {
  static clock_t oldtick;
  clock_t newtick = clock();
  double diff = 1.0 * (newtick - oldtick) / CLOCKS_PER_SEC;
  oldtick = newtick;
  return diff;
}
int main(int argc, char** argv) {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(5);
  cout << fixed;
  int n;
  cin >> n >> ws;
  long long d = 0, x = n, y = 1;
  while (x) {
    d++;
    x /= 10;
  }
  long long ret = 0;
  while (d) {
    x = d;
    y = 1;
    while (--x) y = y * 10;
    ret += (n - y + 1) * d;
    n = y - 1;
    --d;
  }
  cout << (ret) << '\n';
  return 0;
}

```


### Prompt

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

Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.

The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.

There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.

The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.

On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.

Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.

Input

The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.

Output

On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.

If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.

Examples

Input

2

Output

white
1 2

Input

3

Output

black

Note

In the first sample test the white queen can capture the black queen at the first move, so the white player wins.

In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).

Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.

During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).

In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
long long n, q;
int mat[20][200002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  if (n % 2 == 0) {
    cout << "white\n";
    cout << "1 2";
  } else
    cout << "black";
  return 0;
}

```


### Prompt

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

Example

Input

4 3
1000 1
2000 2
3000 3

Output

2 3 4 4

### Response

```cpp
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = (ll)1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int a[200000], b[200000];

int main(){
  int n, m;
  vector<pair<int, int>> v;
  cin >> n >> m;
  rep(i, m){
    int x, y;
    cin >> x >> y;
    v.emplace_back(x, y);
  }
  sort(all(v));
  rep(i, n) a[i] = b[i] = i;
  each(p, v){
    b[p.second - 1] = b[p.second];
    a[p.second] = a[p.second - 1];
  }
  rep(i, n) cout << b[i] - a[i] + 1 << "\n "[i + 1 < n];
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.

Input

The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.

Output

Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.

Examples

Input

4
2 10
0 20
1 5
1 3

Output

8

Input

3
0 1
0 10
0 100

Output

111

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long dp[4005][2005], ar[2][2005], n;
long long f(long long t, long long i) {
  if (i == n + 1 && t < 0) return (1ll << 62);
  if (i == n + 1) return 0;
  if (t > 2000) t = 2000;
  if (dp[t + 2000][i] != -1) return dp[t + 2000][i];
  long long res = (1ll << 62);
  res = (res < f(t - 1, i + 1) ? res : f(t - 1, i + 1));
  res = (res < f(t + ar[0][i], i + 1) + ar[1][i]
             ? res
             : f(t + ar[0][i], i + 1) + ar[1][i]);
  return dp[t + 2000][i] = res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ar[0][i] >> ar[1][i];
  memset(dp, -1, sizeof dp);
  cout << f(0, 1);
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If string s contains no two consecutive periods, then nothing happens.

Let's define f(s) as the minimum number of operations of replacement to perform, so that the string does not have any two consecutive periods left.

You need to process m queries, the i-th results in that the character at position xi (1 ≤ xi ≤ n) of string s is assigned value ci. After each operation you have to calculate and output the value of f(s).

Help Daniel to process all queries.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 300 000) the length of the string and the number of queries.

The second line contains string s, consisting of n lowercase English letters and period signs.

The following m lines contain the descriptions of queries. The i-th line contains integer xi and ci (1 ≤ xi ≤ n, ci — a lowercas English letter or a period sign), describing the query of assigning symbol ci to position xi.

Output

Print m numbers, one per line, the i-th of these numbers must be equal to the value of f(s) after performing the i-th assignment.

Examples

Input

10 3
.b..bz....
1 h
3 c
9 f

Output

4
3
1

Input

4 4
.cc.
2 .
3 .
2 a
1 a

Output

1
3
1
1

Note

Note to the first sample test (replaced periods are enclosed in square brackets).

The original string is ".b..bz....".

  * after the first query f(hb..bz....) = 4 ("hb[..]bz...."  →  "hb.bz[..].."  →  "hb.bz[..]."  →  "hb.bz[..]"  →  "hb.bz.")
  * after the second query f(hbс.bz....) = 3 ("hbс.bz[..].."  →  "hbс.bz[..]."  →  "hbс.bz[..]"  →  "hbс.bz.")
  * after the third query f(hbс.bz..f.) = 1 ("hbс.bz[..]f."  →  "hbс.bz.f.")

Note to the second sample test.

The original string is ".cc.".

  * after the first query: f(..c.) = 1 ("[..]c."  →  ".c.")
  * after the second query: f(....) = 3 ("[..].."  →  "[..]."  →  "[..]"  →  ".")
  * after the third query: f(.a..) = 1 (".a[..]"  →  ".a.")
  * after the fourth query: f(aa..) = 1 ("aa[..]"  →  "aa.")

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:667772160")
using namespace std;
struct __isoff {
  __isoff() {
    if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
    srand(time(0));
  }
  ~__isoff() {}
} __osafwf;
const unsigned long long p1 = 31;
const unsigned long long p2 = 29;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long inf = 1e17 + 7;
const int infi = 1e9 + 7;
const long long dd = 3e5 + 7;
const long long mod = 1e9 + 7;
string s;
char t = '.';
int n, m;
int num, group;
bool ok[dd];
int main() {
  cin >> n >> m >> s;
  for (long long i = 0; i < (long long)n; i++) {
    if (s[i] == t) {
      num++;
      if (i == 0 || s[i - 1] != t) group++;
      ok[i + 1] = 1;
    }
  }
  for (long long i = 0; i < (long long)m; i++) {
    int d;
    char c;
    scanf("%d %c", &d, &c);
    bool a = ok[d], b = c == t;
    if (a != b) {
      if (a) {
        num--;
      } else {
        num++;
      }
      if (ok[d - 1] && ok[d + 1] && !b) {
        group++;
      }
      if (ok[d - 1] && ok[d + 1] && b) {
        group--;
      }
      if (!ok[d - 1] && !ok[d + 1] && !b) {
        group--;
      }
      if (!ok[d - 1] && !ok[d + 1] && b) {
        group++;
      }
    }
    ok[d] = b;
    printf("%d\n", num - group);
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm.

Let's consider that initially array contains n numbers from 1 to n and the number i is located in the cell with the index 2i - 1 (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number written in it to the nearest empty cell to the left of the selected one. The process continues until all n numbers will appear in the first n cells of the array. For example if n = 4, the array is changing as follows:

<image>

You have to write a program that allows you to determine what number will be in the cell with index x (1 ≤ x ≤ n) after Dima's algorithm finishes.

Input

The first line contains two integers n and q (1 ≤ n ≤ 1018, 1 ≤ q ≤ 200 000), the number of elements in the array and the number of queries for which it is needed to find the answer.

Next q lines contain integers xi (1 ≤ xi ≤ n), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes.

Output

For each of q queries output one integer number, the value that will appear in the corresponding array cell after Dima's algorithm finishes.

Examples

Input

4 3
2
3
4

Output

3
2
4

Input

13 4
10
5
4
8

Output

13
3
8
9

Note

The first example is shown in the picture.

In the second example the final array is [1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, st, v, x, ans;
int m;
int main() {
  scanf("%lld", &n);
  scanf("%d", &m);
  while (m--) {
    scanf("%lld", &x);
    st = 0;
    v = 2;
    ans = 0;
    x--;
    while (true) {
      if (x % v == st % v) {
        ans += (x - st) / v + 1;
        break;
      }
      ans += (n - 1 - st) / v + 1;
      long long b = ((n - 1 - st) % v), z = v - (n - 1 - st) % v, y;
      long long dx = 1;
      st = (st + (n - 1 - st) / v * v + v);
      while (st >= n) {
        st -= n;
        st = st * 2 + 1;
        v *= 2;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}

```


### Prompt

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

You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.

You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:

  * Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
  * move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).

Note that it's allowed to move chips to any integer coordinate, including negative and zero.

Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).

Input

The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.

The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.

Output

Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.

Examples

Input

3
1 2 3

Output

1

Input

5
2 2 2 3 3

Output

2

Note

In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.

In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> num(n);
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int val = num[i];
    int partial = 0;
    for (int j = 0; j < n; j++) {
      if ((abs(num[j] - val)) % 2 == 1) {
        partial++;
      }
    }
    if (partial < ans) {
      ans = partial;
    }
  }
  cout << ans << endl;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of the points painted on the plane.

Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100) — the coordinates of the i-th point. It is guaranteed that no two given points coincide.

Output

In the first line print an integer — the number of triangles with the non-zero area among the painted points.

Examples

Input

4
0 0
1 1
2 0
2 2

Output

3

Input

3
0 0
1 1
2 0

Output

1

Input

1
1 1

Output

0

Note

Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).

Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).

Note to the third sample test. A single point doesn't form a single triangle.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long OO = (long long)1e14 + 7;
const int mod = (int)1e9 + 9;
const int MAX = (int)2 * 1e3 + 5;
const int NMAX = (int)2 * 1e5 + 5;
int x[MAX], y[MAX];
int main(void) {
  ios_base::sync_with_stdio(false);
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k < n; k++) {
          if ((y[i] - y[j]) * (x[j] - x[k]) == (y[j] - y[k]) * (x[i] - x[j]))
            continue;
          cnt++;
        }
      }
    }
    cout << cnt << "\n";
  }
  return 0;
}

```


### Prompt

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

We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.

However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.

Can you win the prize? Hurry up, the bags are waiting!

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.

Output

Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.

Examples

Input

5
1 2 1 2 1

Output

1 1 1 2 2

Input

9
1 1 2 1 1 1 2 1 1

Output

1 1 1 2 1 1 1 2 1

Note

The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, count = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 1) count++;
  }
  for (int i = 0; i < count; ++i) a[i] = 1;
  for (int i = count; i < n; ++i) a[i] = 2;
  if (count % 2 == 0 && count != 0) swap(a[count - 1], a[n - 1]);
  if ((count == 1 || count == 2) && n != 1) swap(a[0], a[1]);
  for (int i = 0; i < n; ++i) cout << a[i] << " ";
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.

Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order they came.

The i-th request is characterized by two values: si — the day when a client wants to start the repair of his car, di — duration (in days) to repair the car. The days are enumerated from 1, the first day is tomorrow, the second day is the day after tomorrow and so on.

Polycarp is making schedule by processing requests in the order from the first to the n-th request. He schedules the i-th request as follows:

  * If the car repair shop is idle for di days starting from si (si, si + 1, ..., si + di - 1), then these days are used to repair a car of the i-th client.
  * Otherwise, Polycarp finds the first day x (from 1 and further) that there are di subsequent days when no repair is scheduled starting from x. In other words he chooses the smallest positive x that all days x, x + 1, ..., x + di - 1 are not scheduled for repair of any car. So, the car of the i-th client will be repaired in the range [x, x + di - 1]. It is possible that the day x when repair is scheduled to start will be less than si.

Given n requests, you are asked to help Polycarp schedule all of them according to the rules above.

Input

The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.

The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number of days to repair the i-th car.

The requests should be processed in the order they are given in the input.

Output

Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car.

Examples

Input

3
9 2
7 3
2 4

Output

9 10
1 3
4 7

Input

4
1000000000 1000000
1000000000 1000000
100000000 1000000
1000000000 1000000

Output

1000000000 1000999999
1 1000000
100000000 100999999
1000001 2000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class car {
 public:
  long long s, t;
};
bool cmp(car a, car b) { return a.s < b.s; }
int main() {
  long long n, flag, x, flag2, q1, q2;
  car now;
  cin >> n;
  vector<car> did, ans;
  while (n--) {
    cin >> now.s >> now.t;
    flag = 0;
    if (did.size() == 0) {
      now.t += now.s - 1;
      did.push_back(now);
      ans.push_back(now);
      continue;
    }
    for (int i = 0; i < did.size(); i++) {
      if (i == 0) {
        if (now.t + now.s - 1 < did[i].s) {
          flag = 1;
          break;
        }
      } else if ((now.s > did[i - 1].t and now.t + now.s - 1 < did[i].s)) {
        flag = 1;
        break;
      }
    }
    if (now.s > did[did.size() - 1].t) {
      flag = 1;
    }
    if (!flag) {
      x = 1;
      flag2 = 0;
      for (int i = 0; i < did.size(); i++) {
        if (x + now.t - 1 < did[i].s) {
          now.s = x;
          now.t = now.s + now.t - 1;
          did.push_back(now);
          ans.push_back(now);
          flag2 = 1;
          break;
        }
        x = did[i].t + 1;
      }
      if (!flag2) {
        now.s = x;
        now.t = now.s + now.t - 1;
        did.push_back(now);
        ans.push_back(now);
      }
    } else {
      now.t += now.s - 1;
      did.push_back(now);
      ans.push_back(now);
    }
    sort(did.begin(), did.end(), cmp);
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].s << " " << ans[i].t << endl;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.

There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.

Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.

Help him.

Constraints

* 3 ≤ N ≤ 200 000
* 1 ≤ M ≤ 200 000
* 1 ≤ a_i < b_i ≤ N
* (a_i, b_i) \neq (1, N)
* If i \neq j, (a_i, b_i) \neq (a_j, b_j).

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.

Examples

Input

3 2
1 2
2 3

Output

POSSIBLE

Input

4 3
1 2
2 3
3 4

Output

IMPOSSIBLE

Input

100000 1
1 99999

Output

IMPOSSIBLE

Input

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

Output

POSSIBLE

### Response

```cpp
#include <iostream>
#include <map>
using namespace std;

int main(){
	int N,M;
	cin >> N >> M;
	map<int,int> c;
	for(int i = 0 ; i < M ; i++){
		int a,b;
		cin >> a >> b;
		if( a > b ) swap(a,b);
		if( a == 1 ) c[b]++;
		if( b == N ) c[a]++;
	}
	for( auto i : c ){
		if( i.second == 2 ){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}
```