### Prompt

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

Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:

* add(s, t, x): add x to as, as+1, ..., at.
* getSum(s, t): report the sum of as, as+1, ..., at.

Note that the initial values of ai (i = 1, 2, . . . , n) are 0.

Constraints

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

Input

n q
query1
query2
:
queryq

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:

0 s t x

or

1 s t

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

Output

For each getSum operation, print the sum;

Examples

Input

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

Output

4
8

Input

4 3
1 1 4
0 1 4 1
1 1 4

Output

0
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I=ll(A);I<ll(B);++I)

int main(){
	ll n,q,rn,bn;
	cin >> n >> q;
	rn = sqrt(n);
	bn = ceil((double)n/rn);
	vector<ll> a(n,0),ba(bn,0),bs(bn,0);
	while(q--){
		ll com;
		cin >> com;
		if(com==0){//add
			ll s,t,x;
			cin >> s >> t >> x;
			s--;t--;
			FOR(i,s,t+1){
				if(i%rn==0 && (i+rn-1)<=t){
					ba[i/rn] += x;
					i += rn - 1;
				}else{
					a[i] += x;
					if((i+1)%rn==0 || i==t){
						ll bi = i/rn;
						bs[bi] = 0;
						FOR(j,rn*bi,(bi+1)*rn){
							bs[bi] += a[j];
						}
					}
				}
			}
		}else{//getsum
			ll s,t;
			cin >> s >> t;
			s--;t--;
			ll ans = 0;
			FOR(i,s,t+1){
				if(i%rn==0 && (i+rn-1)<=t){
					ans += bs[i/rn]+rn*ba[i/rn];
					i += rn-1;
				}else{
					ans += a[i]+ba[i/rn];
				}
			}
			cout << ans << endl;
		}
	}
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a tree with n vertices; its root is vertex 1. Also there is a token, initially placed in the root. You can move the token to other vertices. Let's assume current vertex of token is v, then you make any of the following two possible moves:

  * move down to any leaf in subtree of v;
  * if vertex v is a leaf, then move up to the parent no more than k times. In other words, if h(v) is the depth of vertex v (the depth of the root is 0), then you can move to vertex to such that to is an ancestor of v and h(v) - k ≤ h(to).

Consider that root is not a leaf (even if its degree is 1). Calculate the maximum number of different leaves you can visit during one sequence of moves.

Input

The first line contains two integers n and k (1 ≤ k < n ≤ 10^6) — the number of vertices in the tree and the restriction on moving up, respectively.

The second line contains n - 1 integers p_2, p_3, ..., p_n, where p_i is the parent of vertex i.

It is guaranteed that the input represents a valid tree, rooted at 1.

Output

Print one integer — the maximum possible number of different leaves you can visit.

Examples

Input

7 1
1 1 3 3 4 4

Output

4

Input

8 2
1 1 2 3 4 5 5

Output

2

Note

The graph from the first example:

<image>

One of the optimal ways is the next one: 1 → 2 → 1 → 5 → 3 → 7 → 4 → 6.

The graph from the second example:

<image>

One of the optimal ways is the next one: 1 → 7 → 5 → 8. Note that there is no way to move from 6 to 7 or 8 and vice versa.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> child[1000001];
int dep[1000001];
int mnc[1000001];
void dfs(int x) {
  mnc[x] = 9 * n;
  if (child[x].empty()) mnc[x] = dep[x];
  for (int i : child[x]) {
    dep[i] = dep[x] + 1;
    dfs(i);
    mnc[x] = min(mnc[x], mnc[i]);
  }
}
int dp1[1000001];
int dp2[1000001];
void dfs2(int x) {
  if (child[x].empty()) {
    dp1[x] = 1;
    dp2[x] = 1;
  } else {
    int sum = 0, mx = 0;
    for (int i : child[x]) {
      dfs2(i);
      sum += dp1[i];
      mx = max(mx, dp2[i] - dp1[i]);
    }
    dp1[x] = mnc[x] - k < dep[x] ? sum : 0;
    dp2[x] = sum + mx;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    child[p].push_back(i);
  }
  dfs(1);
  dfs2(1);
  printf("%d\n", dp2[1]);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Interest rates are attached to the money deposited in banks, and the calculation method and interest rates vary from bank to bank. The combination of interest and principal is called principal and interest, but as a method of calculating principal and interest, there are "single interest" that calculates without incorporating interest into the principal and "compound interest" that calculates by incorporating interest into the principal. Yes, you must understand this difference in order to get more principal and interest. The calculation method of principal and interest is as follows.

<image>

<image>

Enter the number of banks, the number of years to deposit money, and the information of each bank (bank number, interest rate type, annual interest rate (percentage)), and create a program that outputs the bank number with the highest principal and interest. However, only one bank has the highest principal and interest.

input

Given multiple datasets. The end of the input is indicated by a single zero. Each dataset is given in the following format:

n
y
b1 r1 t1
b2 r2 t2
::
bn rn tn

The first line gives the number of banks n (1 ≤ n ≤ 50) and the second line gives the number of years to deposit money y (1 ≤ y ≤ 30). The next n lines are given the bank number bi of the i-th bank, the integer ri (1 ≤ ri ≤ 100) representing the annual interest rate, and the interest rate type ti (1 or 2). The interest rate type ti is given as 1 for simple interest and 2 for compound interest.

The number of datasets does not exceed 100.

output

For each dataset, the bank number with the highest principal and interest is output on one line.

Example

Input

2
8
1 5 2
2 6 1
2
9
1 5 2
2 6 1
0

Output

2
1

### Response

```cpp
#include<iostream>

double simulate(int year, int rate, int type){
	if(type == 1){//単利
		return 1 + 1.0 * year * rate / 100;
	}else{//複利
		double res = 1;
		for(int i=year;i--;){
			res *= (1 + 1.0 * rate / 100);
		}
		return res;
	}
}

int main(){
	int n, y, max_atm;
	double max_ir;
	while(std::cin >> n >> y, n){
		max_atm = 0;
		max_ir = 0;
		for(;n--;){
			int b, r, t;
			std::cin >> b >> r >> t;
			double ir = simulate(y, r, t);
			if(ir > max_ir){
				max_ir = ir;
				max_atm = b;
			}
		}
		std::cout << max_atm << std::endl;
	}
}
```


### Prompt

Please formulate a cpp solution to the following problem:

Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied:

* The bitwise AND of the chosen numbers is S.
* The bitwise OR of the chosen numbers is T.

Constraints

* 1 \leq N \leq 50
* 1 \leq K \leq N
* 0 \leq A_i < 2^{18}
* 0 \leq S < 2^{18}
* 0 \leq T < 2^{18}
* A_i \neq A_j (1 \leq i < j \leq N)

Input

Input is given from Standard Input in the following format:

N K S T
A_1 A_2 ... A_N

Output

Print the answer.

Examples

Input

3 3 0 3
1 2 3

Output

2

Input

5 3 1 7
3 4 9 1 5

Output

2

Input

5 4 0 15
3 4 9 1 5

Output

3

### Response

```cpp
#include <cstdio>
#include <iostream>
#include <cstring>
#define MN 55

typedef long long ll;

char cnt[400000000];
ll C[MN][MN], ans = 0;
bool ok[MN]; int N = 0;
int n, m, S, T;
int a[MN], tot = 0;

int main()
{
	scanf("%d%d%d%d", &n, &m, &S, &T);
	if((S & T) != S) return 0 * puts("0");
	for(int i = 0; i <= n; i++) C[i][0] = C[i][i] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j < i; j++)
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
	for(int i = 1; i <= n; i++)
		for(int j = 2; j <= m; j++)
			C[i][j] += C[i][j - 1];

	for(int i = 0; i < 18; i++) if(((S >> i) & 1) != ((T >> i) & 1)) N++, ok[i] = 1;
	for(int i = 1; i <= n; i++)
	{
		int x; scanf("%d", &x);
		if((x & S) != S || (x | T) != T) continue;
		++tot;
		for(int j = 17; j >= 0; j--)
			if(ok[j]) a[tot] = a[tot] * 2 + ((x >> j) & 1);
		for(int S = 0; S < (1 << N); S++)
		{
			int T = 0, w = 0;
			for(int j = N - 1; j >= 0; j--)
			{
				T *= 3;
				if((S >> j) & 1) w++, T += (a[tot] >> j) & 1;
				else T += 2;
			}
			ll v = 0;
			v -= C[cnt[T]][m];
			cnt[T]++;
			v += C[cnt[T]][m];
			if(w & 1) ans -= v;
			else ans += v;
		}
	}
	printf("%lld\n", ans);
}
```


### Prompt

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

You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.

Notes

Constraints

* Elements in S is sorted in ascending order
* n ≤ 100000
* q ≤ 50000
* 0 ≤ an element in S ≤ 109
* 0 ≤ an element in T ≤ 109

Input

In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.

Output

Print C in a line.

Examples

Input

5
1 2 3 4 5
3
3 4 1

Output

3

Input

3
1 2 3
1
5

Output

0

Input

5
1 1 2 2 3
2
1 2

Output

2

### Response

```cpp
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n,q;
  cin>>n;

  int S[100010],T[50010];
  rep(i,n) cin>>S[i];

  cin>>q;
  rep(i,q) cin>>T[i];

  ll ans=0;
  rep(i,q){
    if(binary_search(S,S+n,T[i])) ans++;
  }
  cout<<ans<<endl;

  return 0;
}

```


### Prompt

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

You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.

* `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c.
* `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353.

Constraints

* 1 \leq N, Q \leq 500000
* 0 \leq a_i, c < 998244353
* 1 \leq b < 998244353
* 0 \leq l < r \leq N
* All values in Input are integer.

Input

Input is given from Standard Input in the following format:

N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1}

Output

For each query of the latter type, print the answer.

Example

Input

5 7
1 2 3 4 5
1 0 5
0 2 4 100 101
1 0 3
0 1 3 102 103
1 2 5
0 2 5 104 105
1 0 5

Output

15
404
41511
4317767

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a >= b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename X, typename M>
struct SegTreeLazyProportional {
    using FX = function<X(X, X)>;
    using FA = function<X(X, M, int)>;
    using FM = function<M(M, M)>;
    //using FP = function<M(M, int)>;
    int n;
    FX fx;
    FA fa;
    FM fm;
    //FP fp;
    const X ex;
    const M em;
    vector<X> dat;
    vector<M> lazy;
    SegTreeLazyProportional(int n_, FX fx_, FA fa_, FM fm_, X ex_, M em_)
        : n(), fx(fx_), fa(fa_), fm(fm_), ex(ex_), em(em_), dat(n_ * 4, ex), lazy(n_ * 4, em) {
        int x = 1;
        while (n_ > x) x *= 2;
        n = x;
    }
    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }
    /* lazy eval */
    void eval(int k, int len) {
        if (lazy[k] == em) return;  // 更新するものが無ければ終了
        if (k < n - 1) {            // 葉でなければ子に伝搬
            lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]);
            lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]);
        }
        // 自身を更新
        dat[k] = fa(dat[k],lazy[k],len);//fa(dat[k], fp(lazy[k], len));
        lazy[k] = em;
    }
    void update(int a, int b, M x, int k, int l, int r) {
        eval(k, r - l);
        if (a <= l && r <= b) {  // 完全に内側の時
            lazy[k] = fm(lazy[k], x);
            eval(k, r - l);
        } else if (a < r && l < b) {                     // 一部区間が被る時
            update(a, b, x, k * 2 + 1, l, (l + r) / 2);  // 左の子
            update(a, b, x, k * 2 + 2, (l + r) / 2, r);  // 右の子
            dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    void update(int a, int b, M x) { update(a, b, x, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        eval(k, r - l);
        if (r <= a || b <= l) {  // 完全に外側の時
            return ex;
        } else if (a <= l && r <= b) {  // 完全に内側の時
            return dat[k];
        } else {  // 一部区間が被る時
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
};
int main(){
    int n,q;cin >> n >>q;
    auto fx=[](pl a,pl b){return make_pair((a.fi+b.fi)%MOD9,(a.se+b.se)%MOD9);};
    auto fa=[](pl a,pl b,int len){return make_pair((a.fi+a.se)*b.fi%MOD9,b.se*len%MOD9);};
    auto fm=[](pl a,pl b){return make_pair(a.fi*b.fi%MOD9,(a.se*b.fi+b.se)%MOD9);};
    SegTreeLazyProportional<pl,pl> st(n,fx,fa,fm,make_pair(0,0),make_pair(1,0));
    rep(i,n){
        ll a;cin >> a;
        st.set(i,make_pair(a,0LL));
    }
    st.build();
    while(q--){
        ll t;cin >> t;
        if(t){
            ll l,r;cin >> l >>r;
            pl p=st.query(l,r);
            cout << (p.fi+p.se)%MOD9 <<endl;
        }
        else{
            ll l,r;cin >> l >>r;
            ll a,b;cin >> a >> b;
            st.update(l,r,{a,b});
        }
    }
}
```


### Prompt

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

Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction <image> is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).

During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button ( + ) instead of division button (÷) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation.

Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction <image> such that sum of its numerator and denominator equals n. Help Petya deal with this problem.

Input

In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.

Output

Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.

Examples

Input

3

Output

1 2

Input

4

Output

1 3

Input

12

Output

5 7

### Response

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

```


### Prompt

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

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq P_i \leq N
* 1 \leq Y_i \leq 10^9
* Y_i are all different.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Examples

Input

2 3
1 32
2 63
1 12

Output

000001000002
000002000001
000001000001

Input

2 3
2 55
2 77
2 99

Output

000002000001
000002000002
000002000003

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	unsigned long long p[m+1],y[m+1],x[m+1];
	for(int i=0;i<m;i++){
		cin>>p[i]>>y[i];
		x[i]=(p[i]<<47)+(y[i]<<17)+i;
	}
	sort(x,x+m);
	int c=1;
	y[(x[0]<<47)>>47]=c;
	for(int i=1;i<m;i++){
		if(x[i]>>47==x[i-1]>>47)
		   c++;
		else
		   c=1;
		y[(x[i]<<47)>>47]=c;
	}
	for(int i=0;i<m;i++){
		x[i]=p[i]*1000000+y[i];
		printf("%012lu\n",x[i]);
	}
	return 0;
}

```


### Prompt

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

n heroes fight against each other in the Arena. Initially, the i-th hero has level a_i.

Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were fighting during the last minute).

When two heroes of equal levels fight, nobody wins the fight. When two heroes of different levels fight, the one with the higher level wins, and his level increases by 1.

The winner of the tournament is the first hero that wins in at least 100^{500} fights (note that it's possible that the tournament lasts forever if no hero wins this number of fights, then there is no winner). A possible winner is a hero such that there exists a sequence of fights that this hero becomes the winner of the tournament.

Calculate the number of possible winners among n heroes.

Input

The first line contains one integer t (1 ≤ t ≤ 500) — the number of test cases.

Each test case consists of two lines. The first line contains one integer n (2 ≤ n ≤ 100) — the number of heroes. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the initial level of the i-th hero.

Output

For each test case, print one integer — the number of possible winners among the given n heroes.

Example

Input

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

Output

1
0
3

Note

In the first test case of the example, the only possible winner is the first hero.

In the second test case of the example, each fight between the heroes results in nobody winning it, so the tournament lasts forever and there is no winner.

### Response

```cpp
#include<stdio.h>
int main(){
    int t,i,j,k,n,a[100],temp,win;
    scanf("%d",&t);
    for(i=0;i<t;i++){
        scanf("%d",&n);
        win=0;
        for(j=0;j<n;j++){
            scanf("%d",&a[j]);
        }
        for(j=0;j<n;j++){
            for(k=j+1;k<n;k++){
                if(a[k]>a[j])
                {
                    temp=a[j];
                    a[j]=a[k];
                    a[k]=temp;
                }
            }
        }
        for(j=0;j<n;j++){
            if(a[j]>a[n-1])
                win++;
        }
        printf("%d\n",win);
    }
    return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.

Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:

  * First, he will jump from island 0 to island d.
  * After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.

Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.

Input

The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.

The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤ p1 ≤ p2 ≤ ... ≤ pn ≤ 30000), denoting the number of the island that contains the i-th gem.

Output

Print the maximum number of gems that Mr. Kitayuta can collect.

Examples

Input

4 10
10
21
27
27

Output

3

Input

8 8
9
19
28
36
45
55
66
78

Output

6

Input

13 7
8
8
9
16
17
17
18
21
23
24
24
26
30

Output

4

Note

In the first sample, the optimal route is 0  →  10 (+1 gem)  →  19  →  27 (+2 gems)  → ...

In the second sample, the optimal route is 0  →  8  →  15  →  21 →  28 (+1 gem)  →  36 (+1 gem)  →  45 (+1 gem)  →  55 (+1 gem)  →  66 (+1 gem)  →  78 (+1 gem)  → ...

In the third sample, the optimal route is 0  →  7  →  13  →  18 (+1 gem)  →  24 (+2 gems)  →  30 (+1 gem)  → ...

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int T = 30000;
const int N = T + 10;
const int INF = 1e9 + 19;
int n, d;
vector<int> dp[N];
int c[N];
int l[N];
int r[N];
void read() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    c[x]++;
  }
}
void upd(int& a, int b) { a = max(a, b); }
void solve() {
  for (int i = 0; i <= T; i++) {
    l[i] = INF;
    r[i] = -INF;
  }
  l[d] = d;
  r[d] = d;
  for (int i = 0; i < T; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      for (int dx = -1; dx <= 1; dx++) {
        int step = j + dx;
        if (step > 0 && i + step <= T) {
          l[i + step] = min(l[i + step], step);
          r[i + step] = max(r[i + step], step);
        }
      }
    }
  }
  for (int i = 0; i <= T; i++) {
    if (r[i] - l[i] + 1 > 0) dp[i].resize(r[i] - l[i] + 1);
  }
  dp[d][d - l[d]] = c[d];
  for (int i = 0; i < T; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      for (int dx = -1; dx <= 1; dx++) {
        int step = j + dx;
        int pos = i + step;
        if (step > 0 && pos <= T) {
          upd(dp[pos][step - l[pos]], dp[i][j - l[i]] + c[pos]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= T; i++)
    for (auto x : dp[i]) ans = max(ans, x);
  cout << ans << endl;
  cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;
}
void printAns() {}
void stress() {}
int main() {
  if (1) {
    int k = 1;
    for (int tt = 0; tt < k; tt++) {
      read();
      solve();
      printAns();
    }
  } else {
    stress();
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

The circle line of the Roflanpolis subway has n stations.

There are two parallel routes in the subway. The first one visits stations in order 1 → 2 → … → n → 1 → 2 → … (so the next stop after station x is equal to (x+1) if x < n and 1 otherwise). The second route visits stations in order n → (n-1) → … → 1 → n → (n-1) → … (so the next stop after station x is equal to (x-1) if x>1 and n otherwise). All trains depart their stations simultaneously, and it takes exactly 1 minute to arrive at the next station.

Two toads live in this city, their names are Daniel and Vlad.

Daniel is currently in a train of the first route at station a and will exit the subway when his train reaches station x.

Coincidentally, Vlad is currently in a train of the second route at station b and he will exit the subway when his train reaches station y.

Surprisingly, all numbers a,x,b,y are distinct.

Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.

Input

The first line contains five space-separated integers n, a, x, b, y (4 ≤ n ≤ 100, 1 ≤ a, x, b, y ≤ n, all numbers among a, x, b, y are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.

Output

Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).

Examples

Input

5 1 4 3 2

Output

YES

Input

10 2 1 9 10

Output

NO

Note

In the first example, Daniel and Vlad start at the stations (1, 3). One minute later they are at stations (2, 2). They are at the same station at this moment. Note that Vlad leaves the subway right after that.

Consider the second example, let's look at the stations Vlad and Daniel are at. They are:

  * initially (2, 9),
  * after 1 minute (3, 8),
  * after 2 minutes (4, 7),
  * after 3 minutes (5, 6),
  * after 4 minutes (6, 5),
  * after 5 minutes (7, 4),
  * after 6 minutes (8, 3),
  * after 7 minutes (9, 2),
  * after 8 minutes (10, 1),
  * after 9 minutes (1, 10).

After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, a, x, b, y;
  cin >> n >> a >> x >> b >> y;
  while (a != x && b != y) {
    if (a < n)
      a++;
    else
      a = 1;
    if (b > 1)
      b--;
    else
      b = n;
    if (a == b) {
      cout << "YES"
           << "\n";
      return 0;
    }
  }
  cout << "NO"
       << "\n";
  return 0;
}

```


### Prompt

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

Jaroslav owns a small courier service. He has recently got and introduced a new system of processing parcels. Each parcel is a box, the box has its weight and strength. The system works as follows. It originally has an empty platform where you can put boxes by the following rules:

  * If the platform is empty, then the box is put directly on the platform, otherwise it is put on the topmost box on the platform.
  * The total weight of all boxes on the platform cannot exceed the strength of platform S at any time.
  * The strength of any box of the platform at any time must be no less than the total weight of the boxes that stand above.

You can take only the topmost box from the platform.

The system receives n parcels, the i-th parcel arrives exactly at time ini, its weight and strength are equal to wi and si, respectively. Each parcel has a value of vi bourles. However, to obtain this value, the system needs to give the parcel exactly at time outi, otherwise Jaroslav will get 0 bourles for it. Thus, Jaroslav can skip any parcel and not put on the platform, formally deliver it at time ini and not get anything for it.

Any operation in the problem is performed instantly. This means that it is possible to make several operations of receiving and delivering parcels at the same time and in any order.

Please note that the parcel that is delivered at time outi, immediately gets outside of the system, and the following activities taking place at the same time are made without taking it into consideration.

Since the system is very complex, and there are a lot of received parcels, Jaroslav asks you to say what maximum amount of money he can get using his system.

Input

The first line of the input contains two space-separated integers n and S (1 ≤ n ≤ 500, 0 ≤ S ≤ 1000). Then n lines follow, the i-th line contains five space-separated integers: ini, outi, wi, si and vi (0 ≤ ini < outi < 2n, 0 ≤ wi, si ≤ 1000, 1 ≤ vi ≤ 106). It is guaranteed that for any i and j (i ≠ j) either ini ≠ inj, or outi ≠ outj.

Output

Print a single number — the maximum sum in bourles that Jaroslav can get.

Examples

Input

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

Output

3

Input

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

Output

5

Note

Note to the second sample (T is the moment in time):

  * T = 0: The first parcel arrives, we put in on the first platform.
  * T = 1: The second and third parcels arrive, we put the third one on the current top (i.e. first) parcel on the platform, then we put the secod one on the third one. Now the first parcel holds weight w2 + w3 = 2 and the third parcel holds w2 = 1.
  * T = 2: We deliver the second parcel and get v2 = 1 bourle. Now the first parcel holds weight w3 = 1, the third one holds 0.
  * T = 3: The fourth parcel comes. First we give the third parcel and get v3 = 1 bourle. Now the first parcel holds weight 0. We put the fourth parcel on it — the first one holds w4 = 2.
  * T = 4: The fifth parcel comes. We cannot put it on the top parcel of the platform as in that case the first parcel will carry weight w4 + w5 = 3, that exceed its strength s1 = 2, that's unacceptable. We skip the fifth parcel and get nothing for it.
  * T = 5: Nothing happens.
  * T = 6: We deliver the fourth, then the first parcel and get v1 + v4 = 3 bourles for them.

Note that you could have skipped the fourth parcel and got the fifth one instead, but in this case the final sum would be 4 bourles.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, dp[505][505 * 2], b[505][505 * 2];
struct odp {
  int l, r, w, s, v;
} r[505];
bool cmp(odp a, odp b) { return a.r != b.r ? a.r < b.r : a.l > b.l; }
int go(int x, int y) {
  if (dp[x][y] > -1) return dp[x][y];
  for (int i = (1); i <= (r[x].r + 1); i++) b[x][i] = 0;
  for (int i = (0); i < (x); i++)
    if (r[i].l >= r[x].l && r[i].r <= r[x].r) {
      if (y < r[i].w) continue;
      int v = go(i, min(r[i].s, y - r[i].w)) + r[i].v;
      int ret = 0;
      for (int j = r[i].l + 1; j; j ^= j & -j) ret = max(ret, b[x][j]);
      for (int j = r[i].r + 1; j <= r[x].r + 1; j += j & -j)
        b[x][j] = max(b[x][j], v + ret);
    }
  for (int i = r[x].r + 1; i; i ^= i & -i) dp[x][y] = max(dp[x][y], b[x][i]);
  return dp[x][y];
}
int main() {
  scanf("%d %d", &n, &r[0].s);
  r[0].r = n + n;
  for (int i = (1); i <= (n); i++)
    scanf("%d %d %d %d %d", &r[i].l, &r[i].r, &r[i].w, &r[i].s, &r[i].v);
  sort(r, r + n + 1, cmp);
  for (int i = (0); i <= (n); i++)
    for (int j = (0); j <= (r[i].s); j++) dp[i][j] = -1;
  printf("%d\n", go(n, r[n].s));
  scanf("\n");
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.

More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print  - 1.

Input

The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).

The second line contains string s1 of length n, consisting of lowercase English letters.

The third line contain string s2 of length n, consisting of lowercase English letters.

Output

Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.

Examples

Input

3 2
abc
xyc

Output

ayd

Input

1 0
c
b

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000000;
const ll mxr = 1e6 + 10;
int req(int cnt, int t) {
  for (int i = 0; i <= t; i++) {
    if (cnt - i == (2 * (t - i))) return i;
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, cnt = 0, t;
  cin >> n >> t;
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < n; i++)
    if (s1[i] != s2[i]) cnt++;
  string ans = "";
  if (cnt <= t) {
    for (int i = 0; i < n; i++) {
      if (s1[i] == s2[i])
        ans += s1[i];
      else if (t) {
        if (s1[i] != 'a' && s2[i] != 'a')
          ans += 'a';
        else if (s1[i] != 'b' && s2[i] != 'b')
          ans += 'b';
        else if (s1[i] != 'c' && s2[i] != 'c')
          ans += 'c';
        t--;
      }
    }
    if (t) {
      for (int i = 0; i < n; i++) {
        if (ans[i] == s1[i] && ans[i] == s2[i] && t) {
          if (s1[i] != 'a' && s2[i] != 'a')
            ans[i] = 'a';
          else if (s1[i] != 'b' && s2[i] != 'b')
            ans[i] = 'b';
          else if (s1[i] != 'c' && s2[i] != 'c')
            ans[i] = 'c';
          t--;
        }
      }
    }
  } else {
    int p = req(cnt, t);
    if (p == -1) {
      cout << p;
      return 0;
    }
    int rr = (cnt - p) / 2, fo = 0, ft = 0;
    for (int i = 0; i < n; i++) {
      if (s1[i] != s2[i]) {
        if (fo < rr) {
          ans += s1[i];
          fo++;
        } else if (ft < rr) {
          ans += s2[i];
          ft++;
        } else {
          if (s1[i] != 'a' && s2[i] != 'a')
            ans += 'a';
          else if (s1[i] != 'b' && s2[i] != 'b')
            ans += 'b';
          else if (s1[i] != 'c' && s2[i] != 'c')
            ans += 'c';
        }
      } else
        ans += s1[i];
    }
  }
  cout << ans << "\n";
  return 0;
}

```


### Prompt

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

Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:

Given two binary numbers a and b of length n. How many different ways of swapping two digits in a (only in a, not b) so that bitwise OR of these two numbers will be changed? In other words, let c be the bitwise OR of a and b, you need to find the number of ways of swapping two bits in a so that bitwise OR will not be equal to c.

Note that binary numbers can contain leading zeros so that length of each number is exactly n.

[Bitwise OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR) is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, 01010_2 OR 10011_2 = 11011_2.

Well, to your surprise, you are not Rudolf, and you don't need to help him… You are the security staff! Please find the number of ways of swapping two bits in a so that bitwise OR will be changed.

Input

The first line contains one integer n (2≤ n≤ 10^5) — the number of bits in each number.

The second line contains a binary number a of length n.

The third line contains a binary number b of length n.

Output

Print the number of ways to swap two bits in a so that bitwise OR will be changed.

Examples

Input

5
01011
11001

Output

4

Input

6
011000
010011

Output

6

Note

In the first sample, you can swap bits that have indexes (1, 4), (2, 3), (3, 4), and (3, 5).

In the second example, you can swap bits that have indexes (1, 2), (1, 3), (2, 4), (3, 4), (3, 5), and (3, 6).

### Response

```cpp
#include <bits/stdc++.h>
const double eps = 1e-10;
const float epsf = 1e-6;
using namespace std;
inline long long int __gcd(long long int a, long long int b) {
  if (a == 0 || b == 0) {
    return max(a, b);
  }
  long long int tempa, tempb;
  while (1) {
    if (a % b == 0)
      return b;
    else {
      tempa = a;
      tempb = b;
      a = tempb;
      b = tempa % tempb;
    }
  }
}
inline int compfloat(float& x, float& y) {
  if (fabs(x - y) < epsf)
    return 0;
  else if (x - y > 0)
    return 1;
  return -1;
}
inline int compdouble(double x, double y) {
  if (fabs(x - y) < eps)
    return 0;
  else if (x - y > 0)
    return 1;
  else
    return -1;
}
bool prime(long long int k) {
  for (long long int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      return false;
    }
  return true;
}
void pdash(int n = 1) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 30; j++) {
      cout << "-";
    }
    cout << "\n";
  }
}
long long int power(long long int x, long long int y) {
  long long int result = 1;
  while (y > 0) {
    if (y & 1) {
      result = (result * x);
    }
    y = y >> 1;
    x = (x * x);
  }
  return result;
}
long long int power(long long int x, long long int y, long long int z) {
  long long int result = 1;
  x = x % z;
  while (y > 0) {
    if (y & 1) {
      result = (result * x) % z;
    }
    y = y >> 1;
    x = (x * x) % z;
  }
  return result;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int nCrF(long long int n, long long int r, long long int p) {
  if (r == 0) return 1;
  long long int f[n + 1];
  f[0] = 1;
  for (long long int i = 1; i <= n; i++) f[i] = f[i - 1] * i % p;
  return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p) % p;
}
void cordinate_compression(vector<int>& v) {
  vector<int> p = v;
  sort(p.begin(), p.end());
  p.erase(unique(p.begin(), p.end()), p.end());
  for (int i = 0; i < (int)((v).size()); i++)
    v[i] = (int)(lower_bound(p.begin(), p.end(), v[i]) - p.begin());
}
int n;
char a[100010], b[100010];
void solve() {
  scanf("%d%s%s", &n, a, b);
  int c[2][2] = {0};
  for (int i = 0; i < n; i++) c[a[i] - '0'][b[i] - '0']++;
  printf("%lld\n",
         1ll * c[0][0] * (c[1][0] + c[1][1]) + 1ll * c[0][1] * c[1][0]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}

```


### Prompt

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

In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:

  * overall, there must be m dances;
  * exactly three people must take part in each dance;
  * each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).

The agency has n dancers, and their number can be less than 3m. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.

You considered all the criteria and made the plan for the m dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the n dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.

Input

The first line contains two space-separated integers n (3 ≤ n ≤ 105) and m (1 ≤ m ≤ 105) — the number of dancers and the number of dances, correspondingly. Then m lines follow, describing the dances in the order of dancing them. The i-th line contains three distinct integers — the numbers of the dancers that take part in the i-th dance. The dancers are numbered from 1 to n. Each dancer takes part in at least one dance.

Output

Print n space-separated integers: the i-th number must represent the color of the i-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.

Examples

Input

7 3
1 2 3
1 4 5
4 6 7

Output

1 2 3 3 2 2 1

Input

9 3
3 6 9
2 5 8
1 4 7

Output

1 1 1 2 2 2 3 3 3

Input

5 2
4 1 5
3 1 2

Output

2 3 1 1 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int vis[100000 + 100];
int col[100000 + 100];
int a[100000 + 100], b[100000 + 100], c[100000 + 100];
int main() {
  int n, m;
  int i, j;
  cin >> n >> m;
  memset(vis, 0, sizeof(vis));
  memset(col, 0, sizeof(col));
  for (i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (i = 1; i <= m; i++) {
    if (!vis[a[i]] && !vis[b[i]] && !vis[c[i]]) {
      vis[a[i]] = vis[b[i]] = vis[c[i]] = 1;
      col[a[i]] = 1;
      col[b[i]] = 2;
      col[c[i]] = 3;
    } else if (!vis[a[i]] && !vis[b[i]] && vis[c[i]]) {
      vis[a[i]] = vis[b[i]] = vis[c[i]] = 1;
      if (col[c[i]] == 1) {
        col[a[i]] = 2;
        col[b[i]] = 3;
      }
      if (col[c[i]] == 2) {
        col[a[i]] = 3;
        col[b[i]] = 1;
      }
      if (col[c[i]] == 3) {
        col[a[i]] = 1;
        col[b[i]] = 2;
      }
    } else if (!vis[a[i]] && vis[b[i]] && !vis[c[i]]) {
      vis[a[i]] = vis[b[i]] = vis[c[i]] = 1;
      if (col[b[i]] == 1) {
        col[a[i]] = 2;
        col[c[i]] = 3;
      }
      if (col[b[i]] == 2) {
        col[a[i]] = 3;
        col[c[i]] = 1;
      }
      if (col[b[i]] == 3) {
        col[a[i]] = 1;
        col[c[i]] = 2;
      }
    } else if (vis[a[i]] && !vis[b[i]] && !vis[c[i]]) {
      vis[a[i]] = vis[b[i]] = vis[c[i]] = 1;
      if (col[a[i]] == 1) {
        col[b[i]] = 2;
        col[c[i]] = 3;
      }
      if (col[a[i]] == 2) {
        col[b[i]] = 3;
        col[c[i]] = 1;
      }
      if (col[a[i]] == 3) {
        col[b[i]] = 1;
        col[c[i]] = 2;
      }
    }
  }
  for (i = 1; i <= n; i++) cout << col[i] << " ";
  cout << endl;
}

```


### Prompt

Please create a solution in cpp to the following problem:

A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:

x2 + 2bx + c = 0 where b, c are natural numbers.

Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.

Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 ≤ b ≤ n, 1 ≤ c ≤ m. Help Petya find that number.

Input

The single line contains two integers n and m. (1 ≤ n, m ≤ 5000000).

Output

Print a single number which is the number of real roots of the described set of equations.

Examples

Input

3 3

Output

12

Input

1 2

Output

1

Note

In the second test from the statement the following equations are analysed:

b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1

b = 1, c = 2: x2 + 2x + 2 = 0; No roots

Overall there's one root

In the second test the following equations are analysed:

b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1

b = 1, c = 2: x2 + 2x + 2 = 0; No roots

b = 1, c = 3: x2 + 2x + 3 = 0; No roots

b = 2, c = 1: x2 + 4x + 1 = 0; The roots are <image>

b = 2, c = 2: x2 + 4x + 2 = 0; The roots are <image>

b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 = - 3, x2 = - 1

b = 3, c = 1: x2 + 6x + 1 = 0; The roots are <image>

b = 3, c = 2: x2 + 6x + 2 = 0; The roots are <image>

b = 3, c = 3: x2 + 6x + 3 = 0; The roots are <image> Overall there are 13 roots and as the root  - 1 is repeated twice, that means there are 12 different roots.

### Response

```cpp
#include <bits/stdc++.h>
using ll = long long;
const int MAX = 5003000;
ll f;
int B, C;
std::bitset<2 * MAX> a;
int main() {
  scanf("%d%d", &B, &C);
  for (int i = 1; i <= B; ++i) {
    ll x = (ll)i * i;
    int v = 0;
    for (int j = i - 1; j >= 0; --j) {
      ll y = (ll)j * j;
      if (x - y > C) break;
      a[MAX - i - j] = 1;
      a[MAX - i + j] = 1;
      ++v;
    }
    f += std::min<ll>(C, x) - v;
  }
  f *= 2;
  f += a.count();
  printf("%lld\n", f);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Everlasting Sa-Ga, a new, hot and very popular role-playing game, is out on October 19, 2008. Fans have been looking forward to a new title of Everlasting Sa-Ga.

Little Jimmy is in trouble. He is a seven-year-old boy, and he obtained the Everlasting Sa-Ga and is attempting to reach the end of the game before his friends. However, he is facing difficulty solving the riddle of the first maze in this game -- Everlasting Sa-Ga is notorious in extremely hard riddles like Neverending Fantasy and Forever Quest.

The riddle is as follows. There are two doors on the last floor of the maze: the door to the treasure repository and the gate to the hell. If he wrongly opens the door to the hell, the game is over and his save data will be deleted. Therefore, he should never open the wrong door.

So now, how can he find the door to the next stage? There is a positive integer given for each door -- it is a great hint to this riddle. The door to the treasure repository has the integer that gives the larger key number. The key number of a positive integer n is the largest prime factor minus the total sum of any other prime factors, where the prime factors are the prime numbers that divide into n without leaving a remainder. Note that each prime factor should be counted only once.

As an example, suppose there are doors with integers 30 and 20 respectively. Since 30 has three prime factors 2, 3 and 5, its key number is 5 - (2 + 3) = 0. Similarly, since 20 has two prime factors 2 and 5, its key number 20 is 5 - 2 = 3. Jimmy therefore should open the door with 20.

Your job is to write a program to help Jimmy by solving this riddle.

Input

The input is a sequence of datasets. Each dataset consists of a line that contains two integers a and b separated by a space (2 ≤ a, b ≤ 106 ). It is guaranteed that key numbers of these integers are always different.

The input is terminated by a line with two zeros. This line is not part of any datasets and thus should not be processed.

Output

For each dataset, print in a line ‘a’ (without quotes) if the door with the integer a is connected to the treasure repository; print ‘b’ otherwise. No extra space or character is allowed.

Example

Input

10 15
30 20
0 0

Output

a
b

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
bool e[1000005];
int a,b,c,d;
vector<int>s;
int main(){
  for(int i=2;i<1000005;i++)
    if(!e[i])for(int j=i+i;j<1000005;j+=i)e[j]=1;
  for(int i=2;i<1000005;i++)
    if(!e[i])s.push_back(i);
  while(cin>>a>>b,a||b){
    c=d=0;
    for(int i=0;i<s.size()&&s[i]<=a;i++){
      int f1=0;
      while(a%s[i]==0)a/=s[i],f1++;
      if(f1)c-=s[i];
      if(a==1){
        c+=s[i]*2;
        break;
      }
    }
    for(int i=0;i<s.size()&&s[i]<=b;i++){
      int f1=0;
      while(b%s[i]==0)b/=s[i],f1++;
      if(f1)d-=s[i];
      if(b==1){
        d+=s[i]*2;
        break;
      }
    }
    if(c>d)cout<<"a"<<endl;
    else cout<<"b"<<endl;
  }
}
```


### Prompt

Please create a solution in cpp to the following problem:

Dr. Asimov, a robotics researcher, loves to research, but hates houseworks and his house were really dirty. So, he has developed a cleaning robot.

As shown in the following figure, his house has 9 rooms, where each room is identified by an alphabet:

<image>

The robot he developed operates as follows:

* If the battery runs down, the robot stops.
* If not so, the robot chooses a direction from four cardinal points with the equal probability, and moves to the room in that direction. Then, the robot clean the room and consumes 1 point of the battery.
* However, if there is no room in that direction, the robot does not move and remains the same room. In addition, there is a junk room in the house where the robot can not enter, and the robot also remains when it tries to enter the junk room. The robot also consumes 1 point of the battery when it remains the same place.

A battery charger for the robot is in a room. It would be convenient for Dr. Asimov if the robot stops at the battery room when its battery run down.

Your task is to write a program which computes the probability of the robot stopping at the battery room.

Constraints

* Judge data includes at most 100 data sets.
* n ≤ 15
* s, t, b are distinct.

Input

The input consists of several datasets. Each dataset consists of:

n
s t b

n is an integer that indicates the initial battery point. s, t, b are alphabets respectively represent the room where the robot is initially, the battery room, and the junk room.

The input ends with a dataset which consists of single 0 for n. Your program should not output for this dataset.

Output

For each dataset, print the probability as a floating point number in a line. The answer may not have an error greater than 0.000001.

Example

Input

1
E A C
1
E B C
2
E A B
0

Output

0.00000000
0.25000000
0.06250000

### Response

```cpp
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
using namespace std;

long cnt,as;
char s,t,b;
const int dy[]={-1,0,1,0};
const int dx[]={0,1,0,-1};
int main(){
  int n,tx,ty;
  long field[2][5][5];
  for(;cin>>n,n;){
    cin.ignore();
    cnt=as=0;
    scanf(" %c %c %c ",&s,&t,&b);
    memset(field,0,sizeof(field));
    int x= s=='A'||s=='D'||s=='G'?1:s=='B'||s=='E'||s=='H'?2:3;
    int y= s=='A'||s=='B'||s=='C'?1:s=='D'||s=='E'||s=='F'?2:3;

    int p= t=='A'||t=='D'||t=='G'?1:t=='B'||t=='E'||t=='H'?2:3;
    int q= t=='A'||t=='B'||t=='C'?1:t=='D'||t=='E'||t=='F'?2:3;

    int u= b=='A'||b=='D'||b=='G'?1:b=='B'||b=='E'||b=='H'?2:3;
    int t= b=='A'||b=='B'||b=='C'?1:b=='D'||b=='E'||b=='F'?2:3;

    field[0][y][x]=1;
    field[0][0][0]=field[0][0][1]=field[0][0][2]=field[0][0][3]=field[0][0][4]=1;
    field[0][4][0]=field[0][4][1]=field[0][4][2]=field[0][4][3]=field[0][4][4]=1;
    field[0][1][0]=field[0][2][0]=field[0][3][0]=1;
    field[0][1][4]=field[0][2][4]=field[0][3][4]=1;
    for(int k=0;k<n;k++){
      for(int i=1;i<4;i++){
        for(int j=1;j<4;j++){
          if(i==t && j==u)continue;

          for(int g=0;g<4;g++){
            tx=j+dx[g];
            ty=i+dy[g];
            if(tx<1 || ty<1 || tx>=4 || ty>=4)continue;
            field[1][i][j]+=field[0][ty][tx];
          }
          /*
          if(field[0][i][j]!=0 && (i-1==t&&j==u || i+1==t&&j==u ||
                                   i==t&&j-1==u || i==t&&j+1==u) ){
            field[1][i][j]++;
          }*/
          int uguu=0;
          if(field[0][i][j]>0){
            for(int g=0;g<4;g++){
              tx=j+dx[g];
              ty=i+dy[g];
              if((tx<1 || ty<1 || tx>=4 || ty>=4) || ty==t&&tx==u){
                uguu++;
              }
            }

            field[1][i][j]+=field[0][i][j]*uguu;
          }
        }
      }
      /*
      for(int ii=1;ii<4;ii++){
        for(int jj=1;jj<4;jj++){
          printf("%7ld ",field[1][ii][jj]);
        }
        puts("");
      }
      puts("");*/
      for(int i=1;i<4;i++)for(int j=1;j<4;j++)field[0][i][j]=field[1][i][j],field[1][i][j]=0;
    }

    printf("%.8lf\n",(double)field[0][q][p]/pow(4.0,(double)n));
  }
  return 0;
}
```


### Prompt

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

As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.

We call a set S of tree nodes valid if following conditions are satisfied:

  1. S is non-empty.
  2. S is connected. In other words, if nodes u and v are in S, then all nodes lying on the simple path between u and v should also be presented in S.
  3. <image>.

Your task is to count the number of valid sets. Since the result can be very large, you must print its remainder modulo 1000000007 (109 + 7).

Input

The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000).

The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000).

Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is guaranteed that these edges form a tree.

Output

Print the number of valid sets modulo 1000000007.

Examples

Input

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

Output

8

Input

0 3
1 2 3
1 2
2 3

Output

3

Input

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

Output

41

Note

In the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 2e3;
long long int mpow(long long int base, long long int exp) {
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long int)result * base) % MOD;
    base = ((long long int)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}
vector<int> graph[N];
int a[N];
long long int dp[N];
int vis[N];
void readGraph(long long int m) {
  int u, v;
  for (int i = (0); 0 < m ? i < m : i > m; 0 < m ? i++ : i--) {
    cin >> u >> v;
    u--, v--;
    graph[u].push_back(v), graph[v].push_back(u);
  }
}
void dfs(int u, int par, int d, long long int minVal) {
  long long int ans = 1;
  for (auto& v : graph[u]) {
    if (v == par) continue;
    if (a[v] < minVal) continue;
    if (a[v] == minVal && vis[v]) continue;
    if (a[v] - minVal > d) continue;
    dfs(v, u, d, minVal);
    ans *= (dp[v] + 1);
    ans %= MOD;
  }
  dp[u] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int d, n;
  cin >> d >> n;
  for (int i = (0); 0 < n ? i < n : i > n; 0 < n ? i++ : i--) cin >> a[i];
  readGraph(n - 1);
  long long int sum = 0;
  for (int i = (0); 0 < n ? i < n : i > n; 0 < n ? i++ : i--) {
    dfs(i, -1, d, a[i]);
    sum = (sum + dp[i]) % MOD;
    vis[i] = 1;
  }
  cout << sum;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edges with an endpoint in this vertex change the color to red.

Find the minimum possible number of moves required to make the colors of all edges equal.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of vertices and edges, respectively.

The following m lines provide the description of the edges, as the i-th of them contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the indices of the vertices connected by the i-th edge, and a character ci (<image>) providing the initial color of this edge. If ci equals 'R', then this edge is initially colored red. Otherwise, ci is equal to 'B' and this edge is initially colored blue. It's guaranteed that there are no self-loops and multiple edges.

Output

If there is no way to make the colors of all edges equal output  - 1 in the only line of the output. Otherwise first output k — the minimum number of moves required to achieve the goal, then output k integers a1, a2, ..., ak, where ai is equal to the index of the vertex that should be used at the i-th move.

If there are multiple optimal sequences of moves, output any of them.

Examples

Input

3 3
1 2 B
3 1 R
3 2 B

Output

1
2

Input

6 5
1 3 R
2 3 R
3 4 B
4 5 R
4 6 R

Output

2
3 4

Input

4 5
1 2 R
1 3 R
2 3 B
3 4 B
1 4 B

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int SET(int n, int pos) { return n = n | (1 << pos); }
int RESET(int n, int pos) { return n = n & ~(1 << pos); }
int CHECK(int n, int pos) { return (bool)(n & (1 << pos)); }
int str2int(string s) {
  stringstream ss(s);
  int x;
  ss >> x;
  return x;
}
string int2str(int a) {
  stringstream ss;
  ss << a;
  string str = ss.str();
  return str;
}
string char2str(char a) {
  stringstream ss;
  ss << a;
  string str = ss.str();
  return str;
}
long long int bigMod(long long int n, long long int power, long long int MOD) {
  if (power == 0) return 1;
  if (power % 2 == 0) {
    long long int ret = bigMod(n, power / 2, MOD);
    return ((ret % MOD) * (ret % MOD)) % MOD;
  } else
    return ((n % MOD) * (bigMod(n, power - 1, MOD) % MOD)) % MOD;
}
long long int modInverse(long long int n, long long int MOD) {
  return bigMod(n, MOD - 2, MOD);
}
int POW(int x, int y) {
  int res = 1;
  for (; y;) {
    if ((y & 1)) {
      res *= x;
    }
    x *= x;
    y >>= 1;
  }
  return res;
}
int inverse(int x) {
  double p = ((double)1.0) / x;
  return (p) + 1e-9;
}
int gcd(int a, int b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
int nC2(int n) { return n * (n - 1) / 2; }
long long int MOD(long long int n, long long int mod) {
  if (n >= 0)
    return n % mod;
  else if (-n == mod)
    return 0;
  else
    return mod + (n % mod);
}
vector<pair<int, char> > g[100005];
vector<int> part[4], red, blue;
int vis[100005], n, m;
bool dfs(int u, int col, char c) {
  if (vis[u]) {
    return vis[u] == col;
  }
  vis[u] = col;
  part[col].push_back(u);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (g[u][i].second == c) {
      if (dfs(v, col, c) == false) return false;
    } else {
      if (dfs(v, 3 - col, c) == false) return false;
    }
  }
  return true;
}
int main() {
  int t, cas = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int p, q;
    char c;
    cin >> p >> q >> c;
    g[p].push_back(make_pair(q, c));
    g[q].push_back(make_pair(p, c));
  }
  memset(vis, 0, sizeof(vis));
  bool red_ff = 0, blue_ff = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      part[1].clear();
      part[2].clear();
      if (dfs(i, 1, 'R')) {
        if (part[1].size() < part[2].size()) {
          for (int j = 0; j < part[1].size(); j++) red.push_back(part[1][j]);
        } else {
          for (int j = 0; j < part[2].size(); j++) red.push_back(part[2][j]);
        }
      } else {
        red_ff = 1;
        break;
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      part[1].clear();
      part[2].clear();
      if (dfs(i, 1, 'B')) {
        if (part[1].size() < part[2].size()) {
          for (int j = 0; j < part[1].size(); j++) blue.push_back(part[1][j]);
        } else {
          for (int j = 0; j < part[2].size(); j++) blue.push_back(part[2][j]);
        }
      } else {
        blue_ff = 1;
        break;
      }
    }
  }
  if (red_ff == 1 && blue_ff == 1) {
    cout << "-1" << endl;
  } else if (red_ff == 1) {
    cout << blue.size() << endl;
    for (int i = 0; i < blue.size(); i++) cout << blue[i] << " ";
  } else if (blue_ff == 1) {
    cout << red.size() << endl;
    for (int i = 0; i < red.size(); i++) cout << red[i] << " ";
  } else if (red.size() < blue.size()) {
    cout << red.size() << endl;
    for (int i = 0; i < red.size(); i++) cout << red[i] << " ";
  } else {
    cout << blue.size() << endl;
    for (int i = 0; i < blue.size(); i++) cout << blue[i] << " ";
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)

You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.

You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:

$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$

Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.

Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.

Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.

Input

The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.

The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.

Output

In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.

Note that you do not have to output the value f(b_1,…,b_n).

Examples

Input

10 32
1 2 3 4 5 5 5 5 5 5

Output

1 2 3 3 3 4 4 4 4 4

Input

5 8
4 4 8 2 1

Output

2 2 2 1 1

Note

For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.

For the second test, the optimal answer is f=9.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
using namespace std;
const int MAX_N = 1e5 + 5;
long long n, k;
long long a[MAX_N], b[MAX_N];
bool use[MAX_N];
long long cal(int i, long long x) { return a[i] - 3 * x * x + 3 * x - 1; }
long long check(long long delta) {
  long long sum = 0;
  for (register int i = 1; i <= n; ++i) {
    if (cal(i, 1) < delta) {
      b[i] = 0, use[i] = false;
      continue;
    }
    long long l = 1, r = a[i], mid, ans;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (cal(i, mid) >= delta)
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    b[i] = ans;
    use[i] = (cal(i, ans) == delta);
    sum += ans;
  }
  return sum;
}
int main() {
  scanf("%lld", &n), scanf("%lld", &k);
  for (register int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  long long l = -4e18, r = 1e9, mid, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid) >= k)
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  k -= check(ans);
  for (int i = 1; i <= n && k < 0; i++)
    if (use[i] && b[i]) ++k, --b[i];
  for (register int i = 1; i <= n; ++i)
    printf("%lld%c", b[i], i == n ? '\n' : ' ');
  return 0;
}

```


### Prompt

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

Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·162 + 13·161 + 11·160). Alexander lived calmly until he tried to convert the number back to the decimal number system.

Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.

Input

The first line contains the integer n (2 ≤ n ≤ 109). The second line contains the integer k (0 ≤ k < 1060), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n.

Alexander guarantees that the answer exists and does not exceed 1018.

The number k doesn't contain leading zeros.

Output

Print the number x (0 ≤ x ≤ 1018) — the answer to the problem.

Examples

Input

13
12

Output

12

Input

16
11311

Output

475

Input

20
999

Output

3789

Input

17
2016

Output

594

Note

In the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·130 or 15 = 1·131 + 2·130.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long base, now, n, ans;
string s;
long long num(int x, int y) {
  long long now = 1, ret = 0;
  for (int i = y; i >= x; i--) {
    ret += now * (s[i] - '0');
    now *= 10;
  }
  return ret;
}
int main() {
  cin >> base;
  long long test = base;
  int m = 0;
  while (test) {
    m++;
    test /= 10;
  }
  now = 1;
  cin >> s;
  n = s.length();
  s = 'a' + s;
  for (int i = n; i >= 1; i--) {
    int j = max(1, i - m + 1);
    if (num(j, i) >= base) j++;
    while (j < i && s[j] == '0') j++;
    ans += num(j, i) * now;
    now *= base;
    i = j;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

There are m people living in a city. There are n dishes sold in the city. Each dish i has a price p_i, a standard s_i and a beauty b_i. Each person j has an income of inc_j and a preferred beauty pref_j.

A person would never buy a dish whose standard is less than the person's income. Also, a person can't afford a dish with a price greater than the income of the person. In other words, a person j can buy a dish i only if p_i ≤ inc_j ≤ s_i.

Also, a person j can buy a dish i, only if |b_i-pref_j| ≤ (inc_j-p_i). In other words, if the price of the dish is less than the person's income by k, the person will only allow the absolute difference of at most k between the beauty of the dish and his/her preferred beauty.

Print the number of dishes that can be bought by each person in the city.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5), the number of dishes available in the city and the number of people living in the city.

The second line contains n integers p_i (1 ≤ p_i ≤ 10^9), the price of each dish.

The third line contains n integers s_i (1 ≤ s_i ≤ 10^9), the standard of each dish.

The fourth line contains n integers b_i (1 ≤ b_i ≤ 10^9), the beauty of each dish.

The fifth line contains m integers inc_j (1 ≤ inc_j ≤ 10^9), the income of every person.

The sixth line contains m integers pref_j (1 ≤ pref_j ≤ 10^9), the preferred beauty of every person.

It is guaranteed that for all integers i from 1 to n, the following condition holds: p_i ≤ s_i.

Output

Print m integers, the number of dishes that can be bought by every person living in the city.

Examples

Input

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

Output

1 2 0

Input

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

Output

0 2 3

Note

In the first example, the first person can buy dish 2, the second person can buy dishes 1 and 2 and the third person can buy no dishes.

In the second example, the first person can buy no dishes, the second person can buy dishes 1 and 4, and the third person can buy dishes 1, 2 and 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxN = (int)1e5 + 100;
int n, m;
int p[maxN], s[maxN], b[maxN], inc[maxN], pref[maxN];
vector<pair<int, int> > cordX;
int idD[maxN], idP[maxN];
vector<int> allFenw[2 * maxN];
int val[maxN];
struct Fenw {
  int n;
  vector<int> f;
  Fenw(int nn) {
    n = nn + 1;
    f.resize(n + 1);
  }
  Fenw() { n = 1; }
  void addFenw(int pos) {
    while (pos <= n) {
      f[pos]++;
      pos = (pos | (pos - 1)) + 1;
    }
  }
  int getFenw(int x) {
    int ans = 0;
    while (x > 0) {
      ans += f[x];
      x = x & (x - 1);
    }
    return ans;
  }
};
Fenw t[4 * maxN];
vector<int> allPts[4 * maxN];
void build(int v, int tl, int tr) {
  if (tl == tr) {
    allPts[v].emplace_back(val[tl]);
    t[v] = Fenw(allPts[v].size());
    return;
  }
  int tm = (tl + tr) / 2;
  build(v + v, tl, tm);
  build(v + v + 1, tm + 1, tr);
  merge(allPts[v * 2].begin(), allPts[v * 2].end(), allPts[v * 2 + 1].begin(),
        allPts[v * 2 + 1].end(), back_inserter(allPts[v]));
  t[v] = Fenw(allPts[v].size());
}
void add(int v, int tl, int tr, int pos) {
  auto it = lower_bound(allPts[v].begin(), allPts[v].end(), val[pos]) -
            allPts[v].begin() + 1;
  t[v].addFenw(it);
  if (tl == tr) return;
  int tm = (tl + tr) / 2;
  if (pos <= tm)
    add(v + v, tl, tm, pos);
  else
    add(v + v + 1, tm + 1, tr, pos);
}
int get(int v, int tl, int tr, int l, int r, int val) {
  if (l > r) return 0;
  if (tl == l && tr == r) {
    if (allPts[v].empty()) return 0;
    auto it = upper_bound(allPts[v].begin(), allPts[v].end(), val) -
              allPts[v].begin() + 1;
    return t[v].getFenw(it - 1);
  }
  int tm = (tl + tr) / 2;
  return get(v + v, tl, tm, l, min(r, tm), val) +
         get(v + v + 1, tm + 1, tr, max(l, tm + 1), r, val);
}
int ans[maxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  vector<pair<int, int> > all;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    all.emplace_back(s[i], m + i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    cordX.emplace_back(make_pair(b[i] + p[i], i));
  }
  for (int i = 1; i <= m; i++) {
    cin >> inc[i];
    all.emplace_back(inc[i], i);
  }
  for (int i = 1; i <= m; i++) {
    cin >> pref[i];
  }
  sort(all.begin(), all.end());
  reverse(all.begin(), all.end());
  sort(cordX.begin(), cordX.end());
  for (int i = 0; i < n; i++) {
    idD[cordX[i].second] = i + 1;
    val[i + 1] = p[cordX[i].second] - b[cordX[i].second];
  }
  build(1, 1, n);
  for (auto it : all) {
    int id = it.second;
    if (id <= m) {
      int what = inc[id] + pref[id];
      if (cordX[0].first > what) continue;
      int x = lower_bound(cordX.begin(), cordX.end(), make_pair(what + 1, -1)) -
              cordX.begin() + 1;
      ans[id] = get(1, 1, n, 1, x - 1, inc[id] - pref[id]);
    } else {
      add(1, 1, n, idD[id - m]);
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}

```


### Prompt

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

Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.

A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebroids and sequence (red; red) is not a zebroid.

Now Polycarpus wonders, how many ways there are to pick a zebroid subsequence from this sequence. Help him solve the problem, find the number of ways modulo 1000000007 (109 + 7).

Input

The first line contains a single integer n (1 ≤ n ≤ 106) — the number of marbles in Polycarpus's sequence.

Output

Print a single number — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

3

Output

6

Input

4

Output

11

Note

Let's consider the first test sample. Let's assume that Polycarpus initially had sequence (red; blue; red), so there are six ways to pick a zebroid:

  * pick the first marble;
  * pick the second marble;
  * pick the third marble;
  * pick the first and second marbles;
  * pick the second and third marbles;
  * pick the first, second and third marbles.

It can be proven that if Polycarpus picks (blue; red; blue) as the initial sequence, the number of ways won't change.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int mo = pow(10, 9) + 7;
  vector<vector<int>> dp(n + 1, vector<int>(2));
  dp[1][0] = 1;
  for (int i = 2; i <= n; i++) {
    if (i % 2 == 0) {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = ((dp[i - 1][1] + dp[i - 1][0]) % mo + 1) % mo;
    } else {
      dp[i][1] = dp[i - 1][1];
      dp[i][0] = ((dp[i - 1][0] + dp[i - 1][1]) % mo + 1) % mo;
    }
  }
  cout << (dp[n][0] + dp[n][1]) % mo << endl;
  return 0;
}

```


### Prompt

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

You are given a number k and a string s of length n, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met:

  * The first character '*' in the original string should be replaced with 'x';
  * The last character '*' in the original string should be replaced with 'x';
  * The distance between two neighboring replaced characters 'x' must not exceed k (more formally, if you replaced characters at positions i and j (i < j) and at positions [i+1, j-1] there is no "x" symbol, then j-i must be no more than k).

For example, if n=7, s=.**.*** and k=3, then the following strings will satisfy the conditions above:

  * .xx.*xx;
  * .x*.x*x;
  * .xx.xxx.

But, for example, the following strings will not meet the conditions:
  * .**.*xx (the first character '*' should be replaced with 'x');
  * .x*.xx* (the last character '*' should be replaced with 'x');
  * .x*.*xx (the distance between characters at positions 2 and 6 is greater than k=3).

Given n, k, and s, find the minimum number of '*' characters that must be replaced with 'x' in order to meet the above conditions.

Input

The first line contains one integer t (1 ≤ t ≤ 500). Then t test cases follow.

The first line of each test case contains two integers n and k (1 ≤ k ≤ n ≤ 50).

The second line of each test case contains a string s of length n, consisting of the characters '.' and '*'.

It is guaranteed that there is at least one '*' in the string s.

It is guaranteed that the distance between any two neighboring '*' characters does not exceed k.

Output

For each test case output the minimum number of '*' characters that must be replaced with 'x' characters in order to satisfy the conditions above.

Example

Input

5
7 3
.**.***
5 1
..*..
5 2
*.*.*
3 2
*.*
1 1
*

Output

3
1
3
2
1

### Response

```cpp
#pragma comment(linker, "/STACK:10000000000")
#define forn(from, to, i) for (int i = from; i < to; ++i)
#define fron(from, to, i) for (int i = from; i >= to; --i)
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <stdint.h>
#include <cstdint>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <time.h>
#include <deque>
#include <functional>
#include <iomanip>
#include <chrono>
using namespace std;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
#define int long long
#define m_p make_pair
#define all(x) x.begin(), x.end()
#define pii pair <int, int>
#define pb push_back
#define ff first
#define x1 x11337
#define y1 y11337
#define x0 x01337
#define y0 y01337
#define xn xn1337
#define yn yn1337
#define ss second
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define GG return 0
#define vi vector<int>
#define si set<int>
#define spii set<pair<int, int> >
#define mii map<int, int>
#define vvi vector<vi>
#define vpii vector<pii>
#define qi queue<int>
#define qpii queue<pii>
#define pq priority_queue<int>
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T> ostream& operator<<(ostream& o, vector<T> x) { for (auto it : x) o << it << ' '; return o; }
template<typename T> istream& operator>>(istream& i, vector<T>& x) { for (auto& it : x) i >> it; return i; }
template <typename T1, typename T2> void chkmin(T1& a, T2 b) { a > b ? a = b : 0; }
template <typename T1, typename T2> void chkmax(T1& a, T2 b) { a < b ? a = b : 0; }
const int INF = 1000000007;
const int INF2 = 100000000000000007;
const int mINF = 1e16;
const int MOD1 = 998244353;
const int MOD = 1000000007;
const int SIZE = 100010;
const int base = 53;
const ldb eps = 1e-6;
const ldb pi = acosl(-1.0);
int add(int a, int b) {
    return ((a + b) % MOD + MOD) % MOD;
}
int mult(int a, int b) {
    return ((a % MOD) * (b % MOD)) % MOD;
}
int binpow(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) res = mult(res, a);
        a = mult(a, a);
        n >>= 1;
    }
    return res;
}
int binpow1(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
        }
        a *= a;
        n >>= 1;
    }
    return res;
}
int inv(int a) {
    return binpow(a, MOD - 2);
}
int del(int a, int b) {
    return mult(a, inv(b));
}
int gcd(int a, int b) {
    return (b == 0 ? a : gcd(b, a % b));
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
template <typename T>
T sqr(T x) {
    return x * x;
}
int q, n, m, k, x, d, rs, ind;
string s;
bool ok;
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    double cl = clock();
#endif
    cin >> q;
    while (q--) {
        cin >> n >> k;
        cin >> s;
        vi kek;
        forn(0, n, i) {
            if (s[i] == '*') kek.push_back(i);
        }
        if (kek.empty()) {
            cout << 0 << endl;
            continue;
        }
        rs = 0;
        n = kek.size();
        forn(0, n, i) {
            ok = 0;
            rs++;
            forn(i + 1, n, j) {
                if (kek[j] - kek[i] > k) {
                    i = j-2;
                    ok = 1;
                    break;
                }
            }
            if (!ok) {
                if (i != n - 1) rs++;
                break;
            }
        }
        cout << rs << endl;
    }
#ifdef _DEBUG
    cout << "\n\n" << (clock() - cl) / CLOCKS_PER_SEC << " s.\n";
#endif
    GG;
}

//====== READ THIS ======
// 1. Read all the tasks
// 2. Read all the tasks MINDFULLY AGAIN
// 3. Check extreme cases (e.g. N <= 2)
// 4. Check value of SIZE before send an attempt
// 5. Don't sit on a task for a long time if there are no ideas at all
// 6. No tilt, only desire to win
// 7. Remember: #define int long long
//=======================

```


### Prompt

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

You are given a connected undirected weighted graph consisting of n vertices and m edges.

You need to print the k-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from i to j and from j to i are counted as one).

More formally, if d is the matrix of shortest paths, where d_{i, j} is the length of the shortest path between vertices i and j (1 ≤ i < j ≤ n), then you need to print the k-th element in the sorted array consisting of all d_{i, j}, where 1 ≤ i < j ≤ n.

Input

The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, n - 1 ≤ m ≤ min\Big((n(n-1))/(2), 2 ⋅ 10^5\Big), 1 ≤ k ≤ min\Big((n(n-1))/(2), 400\Big) — the number of vertices in the graph, the number of edges in the graph and the value of k, correspondingly.

Then m lines follow, each containing three integers x, y and w (1 ≤ x, y ≤ n, 1 ≤ w ≤ 10^9, x ≠ y) denoting an edge between vertices x and y of weight w.

It is guaranteed that the given graph is connected (there is a path between any pair of vertices), there are no self-loops (edges connecting the vertex with itself) and multiple edges (for each pair of vertices x and y, there is at most one edge between this pair of vertices in the graph).

Output

Print one integer — the length of the k-th smallest shortest path in the given graph (paths from the vertex to itself are not counted, paths from i to j and from j to i are counted as one).

Examples

Input

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

Output

3

Input

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

Output

9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const long double eps = 1e-9;
const int mod = 998244353;
const int maxn = 200 + 10;
const int N = 5e5 + 10;
const int M = N * 20;
const long long mm = (1LL << 32);
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  x = f ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  T y = 1;
  int len = 1;
  for (; y <= x / 10; y *= 10) ++len;
  for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
long long qpow(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % MOD;
    b >>= 1;
    a = (a * a) % MOD;
  }
  return ans;
}
long long dp[805][805], dis[N];
int tot = 0, n, m, k, b[N], cnt = 0;
struct node {
  int u, v, w;
  bool operator<(const node &b) const { return w < b.w; }
} a[N];
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= m; i++) scanf("%d %d %d", &a[i].u, &a[i].v, &a[i].w);
  sort(a + 1, a + m + 1);
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 1; i <= min(k, m); i++) b[++cnt] = a[i].u, b[++cnt] = a[i].v;
  sort(b + 1, b + cnt + 1);
  int qwq = unique(b + 1, b + cnt + 1) - b - 1;
  for (int i = 1; i <= min(k, m); i++) {
    int from = lower_bound(b + 1, b + qwq + 1, a[i].u) - b,
        to = lower_bound(b + 1, b + qwq + 1, a[i].v) - b;
    dp[from][to] = dp[to][from] = a[i].w;
  }
  for (int k = 1; k <= qwq; k++)
    for (int i = 1; i <= qwq; i++)
      for (int j = 1; j <= qwq; j++)
        if (dp[i][k] + dp[k][j] < dp[i][j]) dp[i][j] = dp[i][k] + dp[k][j];
  for (int i = 1; i <= qwq; i++)
    for (int j = i + 1; j <= qwq; j++)
      if (dp[i][j] != inf) dis[++tot] = dp[i][j];
  sort(dis + 1, dis + tot + 1);
  printf("%lld\n", dis[k]);
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from  - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor  - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.

In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8, - 180, 808 are all lucky while 42, - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).

Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.

Input

The only line of input contains an integer a ( - 109 ≤ a ≤ 109).

Output

Print the minimum b in a line.

Examples

Input

179

Output

1

Input

-1

Output

9

Input

18

Output

10

Note

For the first sample, he has to arrive at the floor numbered 180.

For the second sample, he will arrive at 8.

Note that b should be positive, so the answer for the third sample is 10, not 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool y(long long n) {
  while (n > 0) {
    long long temp = n % 10;
    if (temp == 8) return 1;
    n = n / 10;
  }
  return 0;
}
long long n, arr[101], c;
int main() {
  long long n, cnt = 1;
  ;
  cin >> n;
  while (1) {
    long long t = n + cnt;
    if (y(abs(t))) {
      cout << cnt;
      return 0;
    }
    cnt++;
  }
}

```


### Prompt

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

For a given sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, find a specific value $k$ given as a query.

Constraints

* $1 \leq n \leq 100,000$
* $1 \leq q \leq 200,000$
* $0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$
* $0 \leq k_i \leq 1,000,000,000$

Input

The input is given in the following format.

$n$
$a_0 \; a_1 \; ,..., \; a_{n-1}$
$q$
$k_1$
$k_2$
:
$k_q$

The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries.

Output

For each query, print 1 if any element in $A$ is equivalent to $k$, and 0 otherwise.

Example

Input

4
1 2 2 4
3
2
3
5

Output

1
0
0

### Response

```cpp
#include <iostream>
#include <algorithm>

int main()
{
	int n; std::cin >> n;

	int* A = new int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];

	int q; std::cin >> q;
	for (int i=0; i<q; i++) {
		int k; std::cin >> k;
		if (std::binary_search(A, A+n, k)) std::cout << 1 << std::endl;
		else std::cout << 0 << std::endl;
	}

	delete[] A;

	return 0;
}

```


### Prompt

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

Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 rectangles.

Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?

Input

The first line contains two space-separated numbers a1 and b1 — the sides of the board. Next two lines contain numbers a2, b2, a3 and b3 — the sides of the paintings. All numbers ai, bi in the input are integers and fit into the range from 1 to 1000.

Output

If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).

Examples

Input

3 2
1 3
2 1

Output

YES

Input

5 5
3 3
3 3

Output

NO

Input

4 2
2 3
1 2

Output

YES

Note

That's how we can place the pictures in the first test:

<image>

And that's how we can do it in the third one.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
int main() {
  int a1, b1, a2, b2, a3, b3;
  int x, y, a, b, c, d, tmp;
  bool ans = false;
  cin >> x >> y >> a >> b >> c >> d;
  for (int i = 0; i < 2; ++i) {
    if (b + c <= x && max(a, d) <= y) ans = true;
    if (b + d <= x && max(a, c) <= y) ans = true;
    if (a + d <= x && max(b, c) <= y) ans = true;
    if (a + c <= x && max(b, d) <= y) ans = true;
    tmp = x;
    x = y;
    y = tmp;
  }
  if (ans) cout << "YES" << endl;
  if (!ans) cout << "NO" << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height ai meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all i (1 ≤ i < n), ai + 1 - ai = k, where k is the number the Queen chose.

Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?

Input

The first line contains two space-separated integers: n, k (1 ≤ n, k ≤ 1000). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the heights of the trees in the row.

Output

In the first line print a single integer p — the minimum number of minutes the gardener needs. In the next p lines print the description of his actions.

If the gardener needs to increase the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, print on the corresponding line "- j x".

If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.

Examples

Input

4 1
1 2 1 5

Output

2
+ 3 2
- 4 1

Input

4 1
1 2 3 4

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main() {
  int n, k, minl, cnt, add;
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    minl = 1 << 29;
    ;
    for (int i = 1; i <= 10000; i++) {
      cnt = 0;
      int temp = i;
      for (int j = 0; j < n; j++) {
        if (temp != a[j]) cnt++;
        temp += k;
      }
      if (minl > cnt) {
        minl = cnt;
        add = i;
      }
    }
    printf("%d\n", minl);
    for (int i = 0; i < n; i++) {
      if (add > a[i]) printf("+ %d %d\n", i + 1, add - a[i]);
      if (add < a[i]) printf("- %d %d\n", i + 1, a[i] - add);
      add += k;
    }
  }
  return 0;
}

```


### Prompt

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

Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells.

In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as follows:

<image>

Each pipe segment has two ends, illustrated by the arrows in the picture above. For example, segment 1 has ends at top and left side of it.

Little John considers the piping system to be leaking if there is at least one pipe segment inside the grid whose end is not connected to another pipe's end or to the border of the grid. The image below shows an example of leaking and non-leaking systems of size 1 × 2.

<image>

Now, you will be given the grid that has been partially filled by Little John. Each cell will either contain one of the four segments above, or be empty. Find the number of possible different non-leaking final systems after Little John finishes filling all of the empty cells with pipe segments. Print this number modulo 1000003 (106 + 3).

Note that rotations or flipping of the grid are not allowed and so two configurations that are identical only when one of them has been rotated or flipped either horizontally or vertically are considered two different configurations.

Input

The first line will contain two single-space separated integers n and m (1 ≤ n, m, n·m ≤ 5·105) — the number of rows and columns respectively. Then n lines follow, each contains exactly m characters — the description of the grid. Each character describes a cell and is either one of these:

  * "1" - "4" — a pipe segment of one of four types as described above
  * "." — an empty cell

Output

Print a single integer denoting the number of possible final non-leaking pipe systems modulo 1000003 (106 + 3). If there are no such configurations, print 0.

Examples

Input

2 2
13
..

Output

2

Input

3 1
1
4
.

Output

0

Input

2 2
3.
.1

Output

1

Note

For the first example, the initial configuration of the grid is as follows.

<image>

The only two possible final non-leaking pipe configurations are as follows:

<image> <image>

For the second example, the initial grid is already leaking, so there will be no final grid that is non-leaking.

For the final example, there's only one possible non-leaking final grid as follows.

<image>

### Response

```cpp
#include <bits/stdc++.h>
const bool vertical[4][4] = {
    {0, 1, 1, 0}, {1, 0, 0, 1}, {1, 0, 0, 1}, {0, 1, 1, 0}};
const bool horizontal[4][4] = {
    {0, 0, 1, 1}, {0, 0, 1, 1}, {1, 1, 0, 0}, {1, 1, 0, 0}};
const int maxn = 500000 + 5;
const int mod = 1000003;
bool row[maxn][4];
bool col[maxn][4];
int r[maxn][4], c[maxn][4];
char str[maxn];
int n, m, ans;
int main() {
  int i, j, k, first, pre, totr, totc;
  scanf("%d%d", &n, &m);
  for (k = 0; k < 4; k++) {
    for (i = 0; i < n; i++) row[i][k] = true;
    for (j = 0; j < m; j++) col[j][k] = true;
  }
  for (i = 0; i < n; i++) {
    scanf("%s", &str);
    for (j = 0; j < m; j++)
      if (str[j] != '.') {
        if (i == 0) {
          for (k = 0; k < 4; k++)
            if (k != str[j] - '1') col[j][k] = false;
        } else
          for (k = 0; k < 4; k++)
            if ((i & 1) ^ vertical[str[j] - '1'][k]) col[j][k] = false;
        if (j == 0) {
          for (k = 0; k < 4; k++)
            if (k != str[j] - '1') row[i][k] = false;
        } else
          for (k = 0; k < 4; k++)
            if ((j & 1) ^ horizontal[str[j] - '1'][k]) row[i][k] = false;
      }
  }
  ans = 0;
  for (first = 0; first < 4; first++)
    if (col[0][first] && row[0][first]) {
      for (k = 0; k < 4; k++)
        if (k != first)
          r[0][k] = c[0][k] = 0;
        else
          r[0][k] = c[0][k] = 1;
      if (n == 1)
        totr = 1;
      else
        totr = 0;
      for (i = 1; i < n; i++)
        for (k = 0; k < 4; k++)
          if (row[i][k]) {
            r[i][k] = 0;
            for (pre = 0; pre < 4; pre++)
              if (row[i - 1][pre] && vertical[pre][k])
                r[i][k] = (r[i][k] + r[i - 1][pre]) % mod;
            if (i == n - 1) totr = (totr + r[i][k]) % mod;
          }
      if (m == 1)
        totc = 1;
      else
        totc = 0;
      for (j = 1; j < m; j++)
        for (k = 0; k < 4; k++)
          if (col[j][k]) {
            c[j][k] = 0;
            for (pre = 0; pre < 4; pre++)
              if (col[j - 1][pre] && horizontal[pre][k])
                c[j][k] = (c[j][k] + c[j - 1][pre]) % mod;
            if (j == m - 1) totc = (totc + c[j][k]) % mod;
          }
      long long temp = totr * (long long)totc % mod;
      ans = (ans + temp) % mod;
    }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:

  1. All cells in a set have the same color.
  2. Every two cells in a set share row or column.

Input

The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly.

The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.

Output

Output single integer — the number of non-empty sets from the problem description.

Examples

Input

1 1
0

Output

1

Input

2 3
1 0 1
0 1 0

Output

8

Note

In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int n, m;
bool mp[maxn][maxn];
int num1[maxn];
int num2[maxn];
long long c[maxn][maxn];
void init() {
  memset(c, 0, sizeof c);
  for (int i = 0; i <= 100; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
}
int main() {
  init();
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mp[i][j];
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mp[i][j])
        num1[i]++;
      else
        num2[i]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= num1[i]; j++) {
      ans += c[num1[i]][j];
    }
    for (int j = 1; j <= num2[i]; j++) {
      ans += c[num2[i]][j];
    }
  }
  memset(num1, 0, sizeof num1);
  memset(num2, 0, sizeof num2);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (mp[j][i])
        num1[i]++;
      else
        num2[i]++;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 2; j <= num1[i]; j++) {
      ans += c[num1[i]][j];
    }
    for (int j = 2; j <= num2[i]; j++) {
      ans += c[num2[i]][j];
    }
  }
  cout << ans;
  return 0;
}

```