### Prompt

Please create a solution in Cpp to the following problem:

Polycarp likes arithmetic progressions. A sequence [a_1, a_2, ..., a_n] is called an arithmetic progression if for each i (1 ≤ i < n) the value a_{i+1} - a_i is the same. For example, the sequences [42], [5, 5, 5], [2, 11, 20, 29] and [3, 2, 1, 0] are arithmetic progressions, but [1, 0, 1], [1, 3, 9] and [2, 3, 1] are not.

It follows from the definition that any sequence of length one or two is an arithmetic progression.

Polycarp found some sequence of positive integers [b_1, b_2, ..., b_n]. He agrees to change each element by at most one. In the other words, for each element there are exactly three options: an element can be decreased by 1, an element can be increased by 1, an element can be left unchanged.

Determine a minimum possible number of elements in b which can be changed (by exactly one), so that the sequence b becomes an arithmetic progression, or report that it is impossible.

It is possible that the resulting sequence contains element equals 0.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in b.

The second line contains a sequence b_1, b_2, ..., b_n (1 ≤ b_i ≤ 10^{9}).

Output

If it is impossible to make an arithmetic progression with described operations, print -1. In the other case, print non-negative integer — the minimum number of elements to change to make the given sequence becomes an arithmetic progression. The only allowed operation is to add/to subtract one from an element (can't use operation twice to the same position).

Examples

Input

4
24 21 14 10

Output

3

Input

2
500 500

Output

0

Input

3
14 5 1

Output

-1

Input

5
1 3 6 9 12

Output

1

Note

In the first example Polycarp should increase the first number on 1, decrease the second number on 1, increase the third number on 1, and the fourth number should left unchanged. So, after Polycarp changed three elements by one, his sequence became equals to [25, 20, 15, 10], which is an arithmetic progression.

In the second example Polycarp should not change anything, because his sequence is an arithmetic progression.

In the third example it is impossible to make an arithmetic progression.

In the fourth example Polycarp should change only the first element, he should decrease it on one. After that his sequence will looks like [0, 3, 6, 9, 12], which is an arithmetic progression.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, inf = 1000000009;
int a[500009];
int check(int id, int val, int last) {
  if (id == n) return 0;
  int ret = 0;
  if (a[id] - last == val)
    ret = check(id + 1, val, a[id]);
  else if (a[id] - last == val + 1)
    ret = check(id + 1, val, a[id] - 1) + 1;
  else if (a[id] - last == val - 1)
    ret = check(id + 1, val, a[id] + 1) + 1;
  else
    ret = inf;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int val = a[1] - a[0];
  int x = min(check(1, val + 1, a[0] - 1) + 1, check(1, val + 2, a[0] - 1) + 1);
  int y = min(check(1, val - 1, a[0] + 1) + 1, check(1, val - 2, a[0] + 1) + 1);
  int u = min(check(1, val + 1, a[0]), check(1, val - 1, a[0]));
  int q = min(check(1, val, a[0] - 1) + 1, check(1, val, a[0] + 1) + 1);
  int z = min(min(check(1, val, a[0]), u), min(x, y));
  z = min(z, q);
  if (z == inf)
    cout << -1 << endl;
  else
    cout << z << endl;
}

```


### Prompt

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

As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.

One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.

The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.

You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).

Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor».

Input

The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100).

This number may contain leading zeros.

Output

Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).

Examples

Input

11

Output

6

Input

01

Output

2

Input

1

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string n;
int sz;
long long mul;
long long ans;
long long powe(long long a, long long b) {
  if (!b) return 1;
  long long tmp = powe(a, b / 2);
  tmp = (tmp * tmp) % 1000000007;
  if (b % 2 == 1)
    return (tmp * a) % 1000000007;
  else
    return tmp;
}
int main() {
  cin >> n;
  sz = ((int)n.size());
  mul = powe(2, sz - 1);
  long long tp = 1;
  for (int i = sz - 1; i >= 0; i--) {
    if (n[i] == '1') {
      ans = (ans + ((tp * mul) % 1000000007)) % 1000000007;
    }
    tp = (tp * 2) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

In a long narrow forest stretching east-west, there are N beasts. Below, we will call the point that is p meters from the west end Point p. The i-th beast from the west (1 ≤ i ≤ N) is at Point x_i, and can be sold for s_i yen (the currency of Japan) if captured.

You will choose two integers L and R (L ≤ R), and throw a net to cover the range from Point L to Point R including both ends, [L, R]. Then, all the beasts in the range will be captured. However, the net costs R - L yen and your profit will be (the sum of s_i over all captured beasts i) - (R - L) yen.

What is the maximum profit that can be earned by throwing a net only once?

Constraints

* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ x_1 < x_2 < ... < x_N ≤ 10^{15}
* 1 ≤ s_i ≤ 10^9
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 s_1
x_2 s_2
:
x_N s_N

Output

When the maximum profit is X yen, print the value of X.

Examples

Input

5
10 20
40 50
60 30
70 40
90 10

Output

90

Input

5
10 2
40 5
60 3
70 4
90 1

Output

5

Input

4
1 100
3 200
999999999999999 150
1000000000000000 150

Output

299

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
ll x[200000], s[200000];

int main() {
    cin >> n;
    rep(i,n) {
        cin >> x[i] >> s[i];
    }
    ll ans = 0;
    ll val = 0;
    rep(i,n) {
        if (i == 0) {
            ans = s[i];
            val = s[i];
            continue;
        }
        val -= x[i]-x[i-1];
        val = max(val, 0LL);
        val += s[i];
        ans = max(ans, val);
    }
    cout << ans << endl;
}

```


### Prompt

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

You are given a permutation a_1, a_2, ..., a_n of numbers from 1 to n. Also, you have n sets S_1,S_2,..., S_n, where S_i=\\{a_i\}. Lastly, you have a variable cnt, representing the current number of sets. Initially, cnt = n.

We define two kinds of functions on sets:

f(S)=min_{u∈ S} u;

g(S)=max_{u∈ S} u.

You can obtain a new set by merging two sets A and B, if they satisfy g(A)<f(B) (Notice that the old sets do not disappear).

Formally, you can perform the following sequence of operations:

  * cnt← cnt+1;

  * S_{cnt}=S_u∪ S_v, you are free to choose u and v for which 1≤ u, v < cnt and which satisfy g(S_u)<f(S_v).

You are required to obtain some specific sets.

There are q requirements, each of which contains two integers l_i,r_i, which means that there must exist a set S_{k_i} (k_i is the ID of the set, you should determine it) which equals \\{a_u∣ l_i≤ u≤ r_i\}, which is, the set consisting of all a_i with indices between l_i and r_i.

In the end you must ensure that cnt≤ 2.2× 10^6. Note that you don't have to minimize cnt. It is guaranteed that a solution under given constraints exists.

Input

The first line contains two integers n,q (1≤ n ≤ 2^{12},1 ≤ q ≤ 2^{16}) — the length of the permutation and the number of needed sets correspondently.

The next line consists of n integers a_1,a_2,⋅⋅⋅, a_n (1≤ a_i≤ n, a_i are pairwise distinct) — given permutation.

i-th of the next q lines contains two integers l_i,r_i (1≤ l_i≤ r_i≤ n), describing a requirement of the i-th set.

Output

It is guaranteed that a solution under given constraints exists.

The first line should contain one integer cnt_E (n≤ cnt_E≤ 2.2× 10^6), representing the number of sets after all operations.

cnt_E-n lines must follow, each line should contain two integers u, v (1≤ u, v≤ cnt', where cnt' is the value of cnt before this operation), meaning that you choose S_u, S_v and perform a merging operation. In an operation, g(S_u)<f(S_v) must be satisfied.

The last line should contain q integers k_1,k_2,⋅⋅⋅,k_q (1≤ k_i≤ cnt_E), representing that set S_{k_i} is the ith required set.

Please notice the large amount of output.

Examples

Input

3 2
1 3 2
2 3
1 3

Output

6
3 2
1 3
5 2
4 6

Input

2 4
2 1
1 2
1 2
1 2
1 1

Output

5
2 1
2 1
2 1
5 3 3 1

Note

In the first sample:

We have S_1=\{1\},S_2=\{3\},S_3=\{2\} initially.

In the first operation, because g(S_3)=2<f(S_2)=3, we can merge S_3,S_2 into S_4=\{2,3\}.

In the second operation, because g(S_1)=1<f(S_3)=2, we can merge S_1,S_3 into S_5=\{1,2\}.

In the third operation, because g(S_5)=2<f(S_2)=3, we can merge S_5,S_2 into S_6=\{1,2,3\}.

For the first requirement, S_4=\{2,3\}=\\{a_2,a_3\}, satisfies it, thus k_1=4.

For the second requirement, S_6=\{1,2,3\}=\\{a_1,a_2,a_3\}, satisfies it, thus k_2=6

Notice that unused sets, identical sets, outputting the same set multiple times, and using sets that are present initially are all allowed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 16) + 7;
int cnt, n, Q, B, ind[N], tmp[N], A[N], ans[N], f[43][503][503];
struct qry {
  int l, r, id;
} q1[N], q2[N];
vector<pair<int, int> > op;
bool cmp(int x, int y) { return A[x] < A[y]; }
bool cmpl(qry A, qry B) { return A.l < B.l; }
bool cmpr(qry A, qry B) { return A.r < B.r; }
int merge(int x, int y) {
  if (!x || !y) return (x | y);
  op.push_back(pair<int, int>(x, y));
  return ++cnt;
}
void solve(int id, int L, int R) {
  if (L == R) {
    f[id][1][1] = ind[L];
    return;
  }
  int mid = (L + R) >> 1;
  solve(id + 1, L, mid), solve(id + 2, mid + 1, R);
  for (int i = L; i <= R; ++i) tmp[i] = ind[i];
  inplace_merge(tmp + L, tmp + mid + 1, tmp + R + 1);
  for (int i = L, pl = L, ql = mid + 1; i <= R; ++i) {
    while (pl <= mid && ind[pl] < tmp[i]) ++pl;
    while (ql <= R && ind[ql] < tmp[i]) ++ql;
    for (int j = L, pr = pl - 1, qr = ql - 1; j <= R; ++j) {
      f[id][i - L + 1][j - L + 1] = 0;
      while (pr + 1 <= mid && ind[pr + 1] <= tmp[j]) ++pr;
      while (qr + 1 <= R && ind[qr + 1] <= tmp[j]) ++qr;
      if (pl > pr)
        f[id][i - L + 1][j - L + 1] = f[id + 2][ql - mid][qr - mid];
      else if (ql > qr)
        f[id][i - L + 1][j - L + 1] = f[id + 1][pl - L + 1][pr - L + 1];
      else
        f[id][i - L + 1][j - L + 1] = merge(f[id + 1][pl - L + 1][pr - L + 1],
                                            f[id + 2][ql - mid][qr - mid]);
    }
  }
  for (int i = L; i <= R; ++i) ind[i] = tmp[i];
}
void work(int L, int R) {
  solve(1, L, R);
  static int lft[N], rht[N];
  for (int i = 1, j = L; i <= Q; ++i) {
    while (j <= R && ind[j] < q1[i].l) ++j;
    lft[q1[i].id] = j;
  }
  for (int i = 1, j = L - 1; i <= Q; ++i) {
    while (j + 1 <= R && ind[j + 1] <= q2[i].r) ++j;
    rht[q2[i].id] = j;
  }
  for (int i = 1; i <= Q; ++i)
    if (lft[i] <= rht[i])
      ans[i] = merge(ans[i], f[1][lft[i] - L + 1][rht[i] - L + 1]);
}
int main() {
  cin >> n >> Q;
  for (int i = 1; i <= n; ++i) cin >> A[i], ind[i] = i;
  B = sqrt(Q);
  sort(ind + 1, ind + n + 1, cmp);
  for (int i = 1; i <= Q; ++i) cin >> q1[i].l >> q1[i].r, q1[i].id = i;
  memcpy(q2, q1, sizeof(q1));
  sort(q1 + 1, q1 + Q + 1, cmpl), sort(q2 + 1, q2 + Q + 1, cmpr);
  cnt = n;
  for (int i = 1; i <= n; i += B) work(i, min(n, i + B - 1));
  cout << op.size() + n << endl;
  for (auto t : op) printf("%d %d\n", t.first, t.second);
  for (int i = 1; i <= Q; ++i) printf("%d ", ans[i]);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.

Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i — is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.

There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one — u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.

<image>

Find the weight of the snowball when it stops moving, that is, it reaches height 0.

Input

First line contains two integers w and h — initial weight and height of the snowball (0 ≤ w ≤ 100; 1 ≤ h ≤ 100).

Second line contains two integers u_1 and d_1 — weight and height of the first stone (0 ≤ u_1 ≤ 100; 1 ≤ d_1 ≤ h).

Third line contains two integers u_2 and d_2 — weight and heigth of the second stone (0 ≤ u_2 ≤ 100; 1 ≤ d_2 ≤ h; d_1 ≠ d_2). Notice that stones always have different heights.

Output

Output a single integer — final weight of the snowball after it reaches height 0.

Examples

Input

4 3
1 1
1 2

Output

8

Input

4 3
9 2
0 1

Output

1

Note

In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:

  * The weight of the snowball increases by 3 (current height), becomes equal to 7.
  * The snowball moves one meter down, the current height becomes equal to 2.
  * The weight of the snowball increases by 2 (current height), becomes equal to 9.
  * The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
  * The snowball moves one meter down, the current height becomes equal to 1.
  * The weight of the snowball increases by 1 (current height), becomes equal to 9.
  * The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
  * The snowball moves one meter down, the current height becomes equal to 0.

Thus, at the end the weight of the snowball is equal to 8.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int w, h, u1, d1, u2, d2;
  cin >> w >> h;
  cin >> u1 >> d1;
  cin >> u2 >> d2;
  for (int i = h; i > 0; i--) {
    w += i;
    if (i == d1) w -= u1;
    if (i == d2) w -= u2;
    if (w < 0) w = 0;
  }
  cout << w << endl;
  return 0;
}

```


### Prompt

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

It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces.

Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question.

Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other.

Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring.

By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure.

Input

The input consists of multiple datasets.

Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30.

There is one line containing only 0 at the end of the input.

Output

Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1.

Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day.

Example

Input

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

Output

3

### Response

```cpp

#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	int n;
	while(cin>>n,n){
		vector<set<int>> sch(30),p(n);
		rep(i,n){
		    int t; cin>>t;
		    rep(j,t){
		        int p; cin>>p;
		        sch[p-1].insert(i);
		    }
		}
		rep(i,30){
		    set<int> t=sch[i],ans;
		    for(auto j:sch[i]){
		        set_union(all(t),all(p[j]),inserter(ans,ans.begin()));
		        t.swap(ans);
		    }
		    for(auto j:sch[i]){
		        p[j]=t;
		    }
		    if(t.size()==n){
		        cout<<i+1<<endl;
		        goto end;
		    }
		}
		cout<<-1<<endl;
		end:;
	}
	return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.

You are a new applicant for his company. Boboniu will test you with the following chess question:

Consider a n× m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 ≤ S_x ≤ n-1 and 2 ≤ S_y ≤ m-1).

From the cell (x,y), you can move your chess piece to (x,y') (1≤ y'≤ m, y' ≠ y) or (x',y) (1≤ x'≤ n, x'≠ x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.

Your goal is to visit each cell exactly once. Can you find a solution?

Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.

Input

The only line of the input contains four integers n, m, S_x and S_y (3≤ n,m≤ 100, 2 ≤ S_x ≤ n-1, 2 ≤ S_y ≤ m-1) — the number of rows, the number of columns, and the initial position of your chess piece, respectively.

Output

You should print n⋅ m lines.

The i-th line should contain two integers x_i and y_i (1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 ≤ x_i ≤ n, 1 ≤ y_i ≤ m.

We can show that under these constraints there always exists a solution. If there are multiple answers, print any.

Examples

Input

3 3 2 2

Output

2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1

Input

3 4 2 2

Output

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

Note

Possible routes for two examples:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1, i, j, k, l;
  while (t--) {
    long long int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<pair<long long int, long long int> > v;
    v.push_back({x, y});
    for (i = 1; i <= m; i++)
      if (i != y) v.push_back({x, i});
    k = 1;
    for (i = x - 1; i >= 1; i--) {
      if (k & 1)
        for (j = m; j >= 1; j--) v.push_back({i, j});
      else
        for (j = 1; j <= m; j++) v.push_back({i, j});
      k++;
    }
    for (i = x + 1; i <= n; i++) {
      if (k & 1)
        for (j = m; j >= 1; j--) v.push_back({i, j});
      else
        for (j = 1; j <= m; j++) v.push_back({i, j});
      k++;
    }
    for (auto r : v) cout << r.first << " " << r.second << "\n";
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.

Input

The input data consists of only one integer x ( - 109 ≤ x ≤ 109).

Output

Output the minimal number of jumps that Jack requires to reach x.

Examples

Input

2

Output

3

Input

6

Output

3

Input

0

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  n = abs(n);
  int m = 0, cnt = 0;
  while (m < n || (n - m) % 2) {
    m += ++cnt;
  }
  cout << cnt << endl;
}

```


### Prompt

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

Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one looks.

Heidi is presented with a screen that shows her a sequence of integers A and a positive integer p. She knows that the encryption code is a single number S, which is defined as follows:

Define the score of X to be the sum of the elements of X modulo p.

Heidi is given a sequence A that consists of N integers, and also given an integer p. She needs to split A into 2 parts such that:

  * Each part contains at least 1 element of A, and each part consists of contiguous elements of A.
  * The two parts do not overlap.
  * The total sum S of the scores of those two parts is maximized. This is the encryption code.

Output the sum S, which is the encryption code.

Input

The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 000, 2 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively.

The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000].

Output

Output the number S as described in the problem statement.

Examples

Input

4 10
3 4 7 2

Output

16

Input

10 12
16 3 24 13 9 8 7 5 12 12

Output

13

Note

In the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of <image>.

In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then, the score is <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int n, p, i, ans, a[100010], ans1[100010], ans2[100010];
int main() {
  cin >> n >> p;
  for (i = 1; i <= n; i++) cin >> a[i], a[i] %= p;
  for (i = 1; i <= n; i++) ans1[i] = (a[i] + ans1[i - 1]) % p;
  for (i = n; i >= 1; i--) ans2[i] = (a[i] + ans2[i + 1]) % p;
  for (i = 1; i < n; i++) ans = max(ans, ans1[i] + ans2[i + 1]);
  cout << ans;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.

a + b + c + d = n

Create a program that outputs the number of combinations that satisfy the conditions.

Input

Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.

The number of datasets does not exceed 50.

Output

For each data set, output the number of combinations of a, b, c, and d on one line.

Example

Input

2
3
35

Output

10
20
8436

### Response

```cpp
//Name: Sum of 4 Integers II
//Level: 2
//Category: 数学,数え上げ,メモ化再帰
//Note:

/**
 * f(k,n) = k個の数を使ってnを作るパターン数
 * として、メモ化再帰を書く。
 *
 * オーダーは O(N^2K)。
 * ただし、Kは使う整数の個数で、K=4。
 */
#include <iostream>
#include <algorithm>

using namespace std;

int memo[5][4001];
bool visited[5][4001];

int calc(int k, int n) {
    if(k == 0) return n == 0;
    if(visited[k][n]) return memo[k][n];

    visited[k][n] = true;
    for(int i = 0; i <= min(n, 1000); ++i) {
        memo[k][n] += calc(k-1, n-i);
    }
    return memo[k][n];
}

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    cout << calc(4, N) << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    while(solve()) ;
    return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory.

Though Ryouko is forgetful, she is also born with superb analyzing abilities. However, analyzing depends greatly on gathered information, in other words, memory. So she has to shuffle through her notebook whenever she needs to analyze, which is tough work.

Ryouko's notebook consists of n pages, numbered from 1 to n. To make life (and this problem) easier, we consider that to turn from page x to page y, |x - y| pages should be turned. During analyzing, Ryouko needs m pieces of information, the i-th piece of information is on page ai. Information must be read from the notebook in order, so the total number of pages that Ryouko needs to turn is <image>.

Ryouko wants to decrease the number of pages that need to be turned. In order to achieve this, she can merge two pages of her notebook. If Ryouko merges page x to page y, she would copy all the information on page x to y (1 ≤ x, y ≤ n), and consequently, all elements in sequence a that was x would become y. Note that x can be equal to y, in which case no changes take place.

Please tell Ryouko the minimum number of pages that she needs to turn. Note she can apply the described operation at most once before the reading. Note that the answer can exceed 32-bit integers.

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 105).

The next line contains m integers separated by spaces: a1, a2, ..., am (1 ≤ ai ≤ n).

Output

Print a single integer — the minimum number of pages Ryouko needs to turn.

Examples

Input

4 6
1 2 3 4 3 2

Output

3

Input

10 5
9 4 3 8 8

Output

6

Note

In the first sample, the optimal solution is to merge page 4 to 3, after merging sequence a becomes {1, 2, 3, 3, 3, 2}, so the number of pages Ryouko needs to turn is |1 - 2| + |2 - 3| + |3 - 3| + |3 - 3| + |3 - 2| = 3.

In the second sample, optimal solution is achieved by merging page 9 to 4.

### Response

```cpp
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
int a[200000];
vector<int> b[200000];
int main() {
  int i, j, k;
  scanf("%d%d", &m, &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n; i++) {
    if (i != 0 && a[i - 1] != a[i]) b[a[i]].push_back(a[i - 1]);
    if (i != n - 1 && a[i] != a[i + 1]) b[a[i]].push_back(a[i + 1]);
  }
  for (i = 0; i <= m; i++) sort(b[i].begin(), b[i].end());
  long long mi = ((1ll << 62) - 1);
  for (i = 0; i <= m; i++) {
    long long tma = 0;
    long long tma2 = 0;
    for (j = 0; j < b[i].size(); j++) {
      tma2 += abs((long long)b[i][j] - i);
      tma += abs((long long)b[i][j] - b[i][b[i].size() / 2]);
    }
    if (mi > tma - tma2) mi = tma - tma2;
  }
  long long dab = 0;
  for (i = 0; i < n - 1; i++) {
    dab += abs((long long)a[i] - a[i + 1]);
  }
  dab += mi;
  printf("%I64d", dab);
  return 0;
}

```


### Prompt

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

In this problem you will write a simple generator of Brainfuck (<https://en.wikipedia.org/wiki/Brainfuck>) calculators.

You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.

We use a fairly standard Brainfuck interpreter for checking the programs:

  * 30000 memory cells.
  * memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.
  * console input (, command) is not supported, but it's not needed for this problem.

Input

The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).

Output

Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.

Examples

Input

2+3

Output

++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.

Input

9-7

Output

+++++++++>
+++++++>
<[<->-]<
++++++++++++++++++++++++++++++++++++++++++++++++.

Note

You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, i, t, op;
char c = 92;
string ch, second;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> second;
  for (i = 0; i < second.length(); i++) {
    if (second[i] >= '0' && second[i] <= '9') {
      a = a * 10 + second[i] - '0';
    } else {
      while (a--) {
        cout << '+';
      }
      a = 0;
      cout << ">\n";
      t++;
      if (t > 1) {
        if (op == '+')
          cout << "<<[->+<]>>\n";
        else {
          cout << "<[<->-]<\n";
          cout << "[->+<]>>\n";
        }
      }
      op = second[i];
    }
  }
  while (a--) {
    cout << '+';
  }
  a = 0;
  cout << ">\n";
  t++;
  if (t > 1) {
    if (op == '+')
      cout << "<<[->+<]>>\n";
    else {
      cout << "<[<->-]<\n";
      cout << "[->+<]>>\n";
    }
  }
  cout << "<";
  cout
      << ">>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->"
         "-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<"
         "[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<";
  return 0;
}

```


### Prompt

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

This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.

You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily go consecutively). For example, for the sequence a=[11,20,11,33,11,20,11]:

  * [11,20,11,33,11,20,11], [11,20,11,33,11,20], [11,11,11,11], [20], [33,20] are subsequences (these are just some of the long list);
  * [40], [33,33], [33,20,20], [20,20,11,11] are not subsequences.

Suppose that an additional non-negative integer k (1 ≤ k ≤ n) is given, then the subsequence is called optimal if:

  * it has a length of k and the sum of its elements is the maximum possible among all subsequences of length k;
  * and among all subsequences of length k that satisfy the previous item, it is lexicographically minimal.

Recall that the sequence b=[b_1, b_2, ..., b_k] is lexicographically smaller than the sequence c=[c_1, c_2, ..., c_k] if the first element (from the left) in which they differ less in the sequence b than in c. Formally: there exists t (1 ≤ t ≤ k) such that b_1=c_1, b_2=c_2, ..., b_{t-1}=c_{t-1} and at the same time b_t<c_t. For example:

  * [10, 20, 20] lexicographically less than [10, 21, 1],
  * [7, 99, 99] is lexicographically less than [10, 21, 1],
  * [10, 21, 0] is lexicographically less than [10, 21, 1].

You are given a sequence of a=[a_1,a_2,...,a_n] and m requests, each consisting of two numbers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j). For each query, print the value that is in the index pos_j of the optimal subsequence of the given sequence a for k=k_j.

For example, if n=4, a=[10,20,30,20], k_j=2, then the optimal subsequence is [20,30] — it is the minimum lexicographically among all subsequences of length 2 with the maximum total sum of items. Thus, the answer to the request k_j=2, pos_j=1 is the number 20, and the answer to the request k_j=2, pos_j=2 is the number 30.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the length of the sequence a.

The second line contains elements of the sequence a: integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

The third line contains an integer m (1 ≤ m ≤ 100) — the number of requests.

The following m lines contain pairs of integers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j) — the requests.

Output

Print m integers r_1, r_2, ..., r_m (1 ≤ r_j ≤ 10^9) one per line: answers to the requests in the order they appear in the input. The value of r_j should be equal to the value contained in the position pos_j of the optimal subsequence for k=k_j.

Examples

Input

3
10 20 10
6
1 1
2 1
2 2
3 1
3 2
3 3

Output

20
10
20
10
20
10

Input

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

Output

2
3
2
3
2
3
1
1
3

Note

In the first example, for a=[10,20,10] the optimal subsequences are:

  * for k=1: [20],
  * for k=2: [10,20],
  * for k=3: [10,20,10].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
void DEBUG(string label, T value) {
  cerr << "[" << label << " = " << value << "]\n";
}
class SegmentTree {
  const int n = 2e5 + 10;
  vector<int> st;

 public:
  SegmentTree() { st.resize(4 * n); }
  void update(int v, int tl, int tr, int pos) {
    if (tl == tr) {
      st[v] = 1;
    } else {
      int tm = (tl + tr) / 2;
      if (pos <= tm) {
        update(2 * v, tl, tm, pos);
      } else {
        update(2 * v + 1, tm + 1, tr, pos);
      }
      st[v] = st[2 * v] + st[2 * v + 1];
    }
  }
  int find_kth(int v, int tl, int tr, int k) {
    if (k > st[v]) {
      return -1;
    }
    if (tl == tr) {
      return tl;
    }
    int tm = (tl + tr) / 2;
    if (k <= st[2 * v]) {
      return find_kth(2 * v, tl, tm, k);
    } else {
      return find_kth(2 * v + 1, tm + 1, tr, k - st[2 * v]);
    }
  }
};
void solve() {
  int n, q;
  cin >> n;
  vector<pair<int, int>> arr(n);
  vector<int> original_array(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first;
    arr[i].second = i;
    original_array[i] = arr[i].first;
  }
  sort(arr.begin(), arr.end(),
       [](const pair<int, int> &lhs, const pair<int, int> &rhs) -> bool {
         if (lhs.first != rhs.first) return lhs.first > rhs.first;
         return lhs.second < rhs.second;
       });
  cin >> q;
  vector<pair<pair<int, int>, int>> queries(q);
  for (int i = 0; i < q; ++i) {
    int k, p;
    cin >> k >> p;
    queries[i] = {{k, p}, i};
  }
  sort(queries.begin(), queries.end());
  int last = 0;
  vector<int> ans(q);
  SegmentTree st;
  const int N = 2e5 + 10;
  for (int i = 0; i < q; ++i) {
    int k = queries[i].first.first;
    int p = queries[i].first.second;
    int idx = queries[i].second;
    while (last < k) {
      st.update(1, 0, N, arr[last].second);
      last++;
    }
    int pos = st.find_kth(1, 0, N, p);
    ans[idx] = original_array[pos];
  }
  for (auto i : ans) {
    cout << i << '\n';
  }
}
int main(int argv, char **argc) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}

```


### Prompt

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

There is a square grid with N rows and M columns. Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}.

Among the 2^{N+M} possible pairs of a subset A of the rows and a subset B of the columns, find the number of the pairs that satisfy the following condition, modulo 998244353:

* The sum of the |A||B| numbers contained in the intersection of the rows belonging to A and the columns belonging to B, is odd.

Constraints

* 1 \leq N,M \leq 300
* 0 \leq a_{i,j} \leq 1(1\leq i\leq N,1\leq j\leq M)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_{11} ... a_{1M}
:
a_{N1} ... a_{NM}

Output

Print the number of the pairs of a subset of the rows and a subset of the columns that satisfy the condition, modulo 998244353.

Examples

Input

2 2
0 1
1 0

Output

6

Input

2 3
0 0 0
0 1 0

Output

8

### Response

```cpp
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 303, Mod = 998244353;
int n, m;
bitset < N > A[N];
inline int Power(int a, int b)
{
    int ret = 1;
    for (; b; b >>= 1, a = 1LL * a * a % Mod)
        if (b & 1) ret = 1LL * ret * a % Mod;
    return (ret);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i ++)
        for (int j = 0, a; j < m; j ++)
            scanf("%d", &a), A[i][j] = a;
    int r = 0;
    for (int i = 0; i < m; i ++)
    {
        for (int j = r; j < n && A[r][i] == 0; j ++)
            if (A[j][i]) swap(A[r], A[j]);
        if (r < n && A[r][i])
        {
            for (int j = 0; j < n; j ++)
                if (r != j && A[j][i])
                    A[j] ^= A[r];
            r ++;
        }
    }
    return !printf("%d\n", (Power(2, n + m - 1) - Power(2, n - 1 + m - r) + Mod) % Mod);
}
```


### Prompt

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

President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.

The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.

Input

The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.

Output

Print the only number — the amount of President's deputies.

Examples

Input

3 4 R
G.B.
.RR.
TTT.

Output

2

Input

3 3 Z
...
.H.
..Z

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char room[100][100];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
void solve() {
  int n, m;
  char boss;
  cin >> n >> m >> boss;
  set<char> ans;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> room[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (room[i][j] == boss)
        for (int k = 0; k < 4; ++k)
          if (j + dx[k] >= 0 && j + dx[k] < m && i + dy[k] >= 0 &&
              i + dy[k] < n && room[i + dy[k]][j + dx[k]] != '.' &&
              room[i + dy[k]][j + dx[k]] != boss)
            ans.insert(room[i + dy[k]][j + dx[k]]);
  cout << ans.size() << endl;
}
int main() {
  solve();
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given n strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.

String a is a substring of string b if it is possible to choose several consecutive letters in b in such a way that they form a. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of strings.

The next n lines contain the given strings. The number of letters in each string is from 1 to 100, inclusive. Each string consists of lowercase English letters.

Some strings might be equal.

Output

If it is impossible to reorder n given strings in required order, print "NO" (without quotes).

Otherwise print "YES" (without quotes) and n given strings in required order.

Examples

Input

5
a
aba
abacaba
ba
aba

Output

YES
a
ba
aba
aba
abacaba

Input

5
a
abacaba
ba
aba
abab

Output

NO

Input

3
qwerty
qwerty
qwerty

Output

YES
qwerty
qwerty
qwerty

Note

In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool cmp(string a, string b) { return a.length() < b.length(); }
bool check(string a, string b) {
  for (int i = 0; i < b.length() - a.length() + 1; ++i) {
    bool ok = true;
    for (int j = 0; j < a.length(); ++j)
      if (b[i + j] != a[j]) ok = false;
    if (ok) return true;
  }
  return false;
}
int main(int argc, char const *argv[]) {
  int n;
  vector<string> a;
  string s;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    a.push_back(s);
  }
  sort(a.begin(), a.end(), cmp);
  bool ok = true;
  for (int i = 1; i < n; ++i) ok = ok & check(a[i - 1], a[i]);
  if (ok) {
    cout << "YES" << endl;
    for (int i = 0; i < n; ++i) cout << a[i] << endl;
  } else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Given is a string S consisting of lowercase English letters. Find the maximum positive integer K that satisfies the following condition:

* There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).

Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this order.

Constraints

* 1 \leq |S| \leq 2 \times 10^5
* S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum positive integer K that satisfies the condition.

Examples

Input

aabbaa

Output

4

Input

aaaccacabaababc

Output

12

### Response

```cpp
#include<iostream>
#include<stack>
using namespace std;
string s;
stack<string>S;
int main()
{
	cin>>s;
	S.push(s.substr(0,1));
	for(int i=1;i<s.size();i++)
	{
		if(S.top()!=s.substr(i,1))
		{
			S.push(s.substr(i,1));
		}
		else
		{
			if(i+1<s.size())
			{
				S.push(s.substr(i,2));
			}
			i++;
		}
	}
	cout<<S.size()<<endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0, d), (d, 0), (n, n - d) and (n - d, n).

<image> An example of a cornfield with n = 7 and d = 2.

Vasya also knows that there are m grasshoppers near the field (maybe even inside it). The i-th grasshopper is at the point (x_i, y_i). Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

Help Vasya! For each grasshopper determine if it is inside the field (including the border).

Input

The first line contains two integers n and d (1 ≤ d < n ≤ 100).

The second line contains a single integer m (1 ≤ m ≤ 100) — the number of grasshoppers.

The i-th of the next m lines contains two integers x_i and y_i (0 ≤ x_i, y_i ≤ n) — position of the i-th grasshopper.

Output

Print m lines. The i-th line should contain "YES" if the position of the i-th grasshopper lies inside or on the border of the cornfield. Otherwise the i-th line should contain "NO".

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

Examples

Input

7 2
4
2 4
4 1
6 3
4 5

Output

YES
NO
NO
YES

Input

8 7
4
4 4
2 8
8 1
6 1

Output

YES
NO
YES
YES

Note

The cornfield from the first example is pictured above. Grasshoppers with indices 1 (coordinates (2, 4)) and 4 (coordinates (4, 5)) are inside the cornfield.

The cornfield from the second example is pictured below. Grasshoppers with indices 1 (coordinates (4, 4)), 3 (coordinates (8, 1)) and 4 (coordinates (6, 1)) are inside the cornfield.

<image>

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n, d, m, i;
  scanf("%d %d", &n, &d);
  scanf("%d", &m);
  int x[m], y[m], L1[m], L2[m], L3[m], L4[m];
  for (i = 0; i < m; i++) {
    scanf("%d %d", &x[i], &y[i]);
    L1[i] = x[i] + y[i] - d;
    L2[i] = x[i] + y[i] - 2 * n + d;
    L3[i] = x[i] - y[i] + d;
    L4[i] = x[i] - y[i] - d;
    if (((L1[i] > 0) || (L1[i] == 0)) && ((L2[i] < 0) || (L2[i] == 0)) &&
        ((L3[i] > 0) || (L3[i] == 0)) && ((L4[i] < 0) || (L4[i] == 0))) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Yae joins a journey plan, in which parties will be held several times during the itinerary. She wants to participate in all of them and will carry several dresses with her. But the number of dresses she can carry with her may be smaller than that of the party opportunities. In that case, she has to wear some of her dresses more than once.

Fashion-conscious Yae wants to avoid that. At least, she wants to reduce the maximum number of times she has to wear the same dress as far as possible.

Given the number of dresses and frequency of parties, make a program to determine how she can reduce the maximum frequency of wearing the most reused dress.

Input

The input is given in the following format.

$A$ $B$

The input line provides the number of dresses $A$ ($1 \leq A \leq 10^5$) and frequency of parties $B$ ($1 \leq B \leq 10^5$).

Output

Output the frequency she has to wear the most reused dress.

Examples

Input

3 5

Output

2

Input

25 10

Output

1

### Response

```cpp
#include <iostream>
using namespace std;
int main(void){
int a,b,x;
cin>>a>>b;
x=b/a;
if(b%a !=0)x++;
cout<<x<<endl;

}

```


### Prompt

Please create a solution in CPP to the following problem:

The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.

So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.

Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.

Input

The first input line contains an integer n (1 ≤ n ≤ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 ≤ yi ≤ 9999).

Output

Print n numbers z1, z2, ..., zn (1000 ≤ zi ≤ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).

Examples

Input

3
1875
1936
1721

Output

1835
1836
1921

Input

4
9999
2000
3000
3011

Output

1999
2000
2000
2011

Input

3
1999
5055
2000

Output

No solution

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0), eps = 1e-4;
const int inf = ~0U >> 2;
int mod = 1e9 + 7;
int Pow(int x, long long t) {
  int r = 1;
  for (; t; t >>= 1, x = (long long)x * x % mod)
    if (t & 1) r = (long long)r * x % mod;
  return r;
}
const int N = 1010;
int n, a[N], b[N];
int d[] = {1, 10, 100, 1000};
bool ok() {
  int cur = 1000;
  for (int i = 0; i < n; ++i) {
    int Min = inf;
    for (int p = 0; p < 4; ++p) {
      int dig = a[i] / d[p] % 10;
      for (int j = 0; j < 10; ++j) {
        if (p == 3 && j == 0) continue;
        int t = a[i] - dig * d[p] + j * d[p];
        if (t >= cur && t < Min) Min = t;
      }
    }
    cur = b[i] = Min;
    if (Min == inf) return false;
  }
  return cur <= 2011;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  if (ok())
    for (int i = 0; i < n; ++i) cout << b[i] << endl;
  else
    cout << "No solution" << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this.

<image>

In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).

Input

The first line contains the chessboard coordinates of square s, the second line — of square t.

Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.

Output

In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.

L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.

Examples

Input

a8
h1

Output

7
RD
RD
RD
RD
RD
RD
RD

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  string a, b;
  cin >> a >> b;
  cout << max(abs(a[0] - b[0]), abs(a[1] - b[1])) << "\n";
  while (a != b) {
    if ((int)a[0] < (int)b[0]) {
      cout << "R";
      a[0]++;
    } else if ((int)a[0] > (int)b[0]) {
      cout << "L";
      a[0]--;
    }
    if ((int)a[1] < (int)b[1]) {
      cout << "U";
      a[1]++;
    } else if ((int)a[1] > (int)b[1]) {
      cout << "D";
      a[1]--;
    }
    cout << "\n";
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  solve();
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Gerald found a table consisting of n rows and m columns. As a prominent expert on rectangular tables, he immediately counted the table's properties, that is, the minimum of the numbers in the corners of the table (minimum of four numbers). However, he did not like the final value — it seemed to be too small. And to make this value larger, he decided to crop the table a little: delete some columns on the left and some on the right, as well as some rows from the top and some from the bottom. Find what the maximum property of the table can be after such cropping. Note that the table should have at least two rows and at least two columns left in the end. The number of cropped rows or columns from each of the four sides can be zero.

Input

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 1000). The following n lines describe the table. The i-th of these lines lists the space-separated integers ai, 1, ai, 2, ..., ai, m (0 ≤ ai, j ≤ 109) — the m numbers standing in the i-th row of the table.

Output

Print the answer to the problem.

Examples

Input

2 2
1 2
3 4

Output

1

Input

3 3
1 0 0
0 1 1
1 0 0

Output

0

Note

In the first test case Gerald cannot crop the table — table contains only two rows and only two columns.

In the second test case if we'll crop the table, the table will contain zero in some corner cell. Also initially it contains two zeros in the corner cells, so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 1e3 + 5;
const long long int inf = 1e9 + 7;
long long int a[maxn][maxn];
bool b[maxn][maxn];
long long int n, m;
bool check(long long int mid) {
  for (long long int i = 0; i < maxn; i++)
    for (long long int j = 0; j < maxn; j++) b[i][j] = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] >= mid) {
        for (long long int k = j + 1; k < m; k++) {
          if (a[i][k] >= mid) {
            if (b[j][k])
              return false;
            else
              b[j][k] = true;
          }
        }
      }
    }
  }
  return true;
}
long long int r, l;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++) cin >> a[i][j];
  l = 0;
  r = inf;
  while (r - l > 1) {
    long long int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << l;
}

```


### Prompt

Generate a cpp solution to the following problem:

Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all.

After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains n space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.

Output

Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.

Examples

Input

5
1 2 3 4 5

Output

1 1 2 3 4

Input

5
2 3 4 5 6

Output

1 2 3 4 5

Input

3
2 2 2

Output

1 2 2

### Response

```cpp
#include <bits/stdc++.h>
const int inf = (1 << 30) - 1;
const double eps = 1e-9;
using namespace std;
int a[100010], ans[100010], n;
bool f = false;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != 1) f = true;
  }
  if (f) {
    sort(a, a + n);
    ans[0] = 1;
    for (int i = 1; i < n; i++) ans[i] = a[i - 1];
  } else {
    for (int i = 0; i < n - 1; i++) ans[i] = 1;
    ans[n - 1] = 2;
  }
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

A and B are preparing themselves for programming contests.

To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.

For each chess piece we know its weight:

  * the queen's weight is 9,
  * the rook's weight is 5,
  * the bishop's weight is 3,
  * the knight's weight is 3,
  * the pawn's weight is 1,
  * the king's weight isn't considered in evaluating position.

The player's weight equals to the sum of weights of all his pieces on the board.

As A doesn't like counting, he asked you to help him determine which player has the larger position weight.

Input

The input contains eight lines, eight characters each — the board's description.

The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.

The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'.

The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.

An empty square of the board is marked as '.' (a dot).

It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.

Output

Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.

Examples

Input

...QK...
........
........
........
........
........
........
...rk...

Output

White

Input

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

Output

Draw

Input

rppppppr
...k....
........
........
........
........
K...Q...
........

Output

Black

Note

In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.

In the second test sample the weights of the positions of the black and the white pieces are equal to 39.

In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[8];
  vector<pair<char, int> > v1;
  vector<pair<char, int> > v2;
  int ctrW = 0;
  int ctrB = 0;
  for (int i = 0; i < 8; i++) {
    cin >> s[i];
  }
  v1.push_back(pair<char, int>('Q', 9));
  v1.push_back(pair<char, int>('R', 5));
  v1.push_back(pair<char, int>('B', 3));
  v1.push_back(pair<char, int>('N', 3));
  v1.push_back(pair<char, int>('P', 1));
  v1.push_back(pair<char, int>('K', 0));
  v2.push_back(pair<char, int>('q', 9));
  v2.push_back(pair<char, int>('r', 5));
  v2.push_back(pair<char, int>('b', 3));
  v2.push_back(pair<char, int>('n', 3));
  v2.push_back(pair<char, int>('p', 1));
  v2.push_back(pair<char, int>('k', 0));
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < s[i].length(); j++) {
      for (int k = 0; k < v1.size(); k++) {
        if (s[i][j] == v1[k].first) {
          ctrW += v1[k].second;
        }
      }
      for (int k = 0; k < v2.size(); k++) {
        if (s[i][j] == v2[k].first) {
          ctrB += v2[k].second;
        }
      }
    }
  }
  if (ctrW > ctrB) {
    cout << "White" << endl;
  } else if (ctrW < ctrB) {
    cout << "Black" << endl;
  } else {
    cout << "Draw" << endl;
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You will receive 5 points for solving this problem.

Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using this operation, Manao converts the string into a structure that has one more level than there were fold operations performed. See the following examples for clarity.

We will denote the positions of folds with '|' characters. For example, the word "ABRACADABRA" written as "AB|RACA|DAB|RA" indicates that it has been folded three times: first, between the leftmost pair of 'B' and 'R' letters; second, between 'A' and 'D'; and third, between the rightmost pair of 'B' and 'R' letters. Here are several examples of folded strings:

    "ABCDEF|GHIJK" |  "A|BCDEFGHIJK" |  "AB|RACA|DAB|RA" |  "X|XXXXX|X|X|XXXXXX"
                   |                 |                   |       XXXXXX
        KJIHG      |   KJIHGFEDCB    |      AR           |       X
       ABCDEF      |            A    |     DAB           |       X
                   |                 |     ACAR          |       XXXXX
                   |                 |       AB          |           X

One last example for "ABCD|EFGH|IJ|K":

     K
    IJ
    HGFE
    ABCD

Manao noticed that each folded string can be viewed as several piles of letters. For instance, in the previous example, there are four piles, which can be read as "AHI", "BGJK", "CF", and "DE" from bottom to top. Manao wonders what is the highest pile of identical letters he can build using fold operations on a given word. Note that the pile should not contain gaps and should start at the bottom level. For example, in the rightmost of the four examples above, none of the piles would be considered valid since each of them has gaps, starts above the bottom level, or both.

Input

The input will consist of one line containing a single string of n characters with 1 ≤ n ≤ 1000 and no spaces. All characters of the string will be uppercase letters.

This problem doesn't have subproblems. You will get 5 points for the correct submission.

Output

Print a single integer — the size of the largest pile composed of identical characters that can be seen in a valid result of folding operations on the given string.

Examples

Input

ABRACADABRA

Output

3

Input

ABBBCBDB

Output

3

Input

AB

Output

1

Note

Consider the first example. Manao can create a pile of three 'A's using the folding "AB|RACAD|ABRA", which results in the following structure:

    ABRA
    DACAR
       AB

In the second example, Manao can create a pile of three 'B's using the following folding: "AB|BB|CBDB".

    CBDB
    BB
    AB

Another way for Manao to create a pile of three 'B's with "ABBBCBDB" is the following folding: "AB|B|BCBDB".

     BCBDB
     B
    AB

In the third example, there are no folds performed and the string is just written in one line.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 3e3 + 10;
const long long MXM = (1LL << 18) + 10;
const long long MX5 = 3e5 + 10;
const long long MX6 = 1e6 + 10;
const long long LOG = 20;
const long long INF = 8e18;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
long long bmm(long long a, long long b) {
  return (a % b == 0 ? b : bmm(b, a % b));
}
string base2(long long n) {
  string a = "";
  while (n >= 2) {
    a += (char)(n % 2 + '0');
    n /= 2;
  }
  a += (char)(n + '0');
  reverse((a).begin(), (a).end());
  return a;
}
long long n, ans;
string s;
vector<long long> vec;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = s.size();
  for (char ch = 'A'; ch <= 'Z'; ch++) {
    long long p = 0, cnt = 0, m;
    vec.clear();
    while (p < n && s[p] != ch) p++;
    p++;
    while (p < n) {
      while (p < n && s[p] != ch) p++, cnt++;
      if (p != n) vec.push_back(cnt);
      p++;
      cnt = 0;
    }
    m = vec.size();
    long long cnt1 = 1, cnt2 = 0, f = 0;
    for (int i = 0; i < m; i++) {
      if (f == 0) {
        if (vec[i] % 2 == 1) {
          f = 1;
          cnt2 -= -1;
        } else {
          cnt1 -= -1;
        }
      } else {
        if (vec[i] % 2 == 0) {
          f = 0;
          cnt1 -= -1;
        } else {
          cnt2 -= -1;
        }
      }
    }
    ans = max(ans, cnt1);
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

You are given a string s consisting of `A`, `B` and `C`.

Snuke wants to perform the following operation on s as many times as possible:

* Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`.

Find the maximum possible number of operations.

Constraints

* 1 \leq |s| \leq 200000
* Each character of s is `A`, `B` and `C`.

Input

Input is given from Standard Input in the following format:

s

Output

Find the maximum possible number of operations.

Examples

Input

ABCABC

Output

3

Input

C

Output

0

Input

ABCACCBABCBCAABCB

Output

6

### Response

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

int main()
{
    string s;
    cin >> s;
    auto n = s.size();
    long long res = 0;
    long long nA = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='A'){ nA++; continue;}
        if(!(s[i]=='B' && s[i+1]=='C')){ nA=0; continue;}
        res += nA;
        i++;
    }
    cout<<res<<endl;

    return 0;
}
```


### Prompt

Please formulate a CPP solution to the following problem:

In the snake exhibition, there are n rooms (numbered 0 to n - 1) arranged in a circle, with a snake in each room. The rooms are connected by n conveyor belts, and the i-th conveyor belt connects the rooms i and (i+1) mod n. In the other words, rooms 0 and 1, 1 and 2, …, n-2 and n-1, n-1 and 0 are connected with conveyor belts.

The i-th conveyor belt is in one of three states:

  * If it is clockwise, snakes can only go from room i to (i+1) mod n.
  * If it is anticlockwise, snakes can only go from room (i+1) mod n to i.
  * If it is off, snakes can travel in either direction.

<image>

Above is an example with 4 rooms, where belts 0 and 3 are off, 1 is clockwise, and 2 is anticlockwise.

Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there?

Input

Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.

The first line of each test case description contains a single integer n (2 ≤ n ≤ 300 000): the number of rooms.

The next line of each test case description contains a string s of length n, consisting of only '<', '>' and '-'.

  * If s_{i} =  '>', the i-th conveyor belt goes clockwise.
  * If s_{i} =  '<', the i-th conveyor belt goes anticlockwise.
  * If s_{i} =  '-', the i-th conveyor belt is off.

It is guaranteed that the sum of n among all test cases does not exceed 300 000.

Output

For each test case, output the number of returnable rooms.

Example

Input

4
4
-><-
5
>>>>>
3
<--
2
<>

Output

3
5
3
0

Note

In the first test case, all rooms are returnable except room 2. The snake in the room 2 is trapped and cannot exit. This test case corresponds to the picture from the problem statement.

In the second test case, all rooms are returnable by traveling on the series of clockwise belts.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int t;
int n;
string s;
bool f[300001];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> s;
    for (int i = 0; i <= n; i++) f[i] = false;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '-') {
        f[i] = true;
        f[(i + 1) % n] = true;
      }
    }
    for (int i = 0; i < n; i++) cnt += f[i];
    bool ok = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '<') ok = false;
    }
    if (!ok) {
      ok = true;
      for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '>') ok = false;
      }
    }
    if (ok) {
      cout << n << "\n";
    } else
      cout << cnt << "\n";
  }
  return 0;
}

```


### Prompt

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

You are given a tree consisting of n vertices. A tree is an undirected connected acyclic graph.

<image> Example of a tree.

You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color.

You have to paint the vertices so that any path consisting of exactly three distinct vertices does not contain any vertices with equal colors. In other words, let's consider all triples (x, y, z) such that x ≠ y, y ≠ z, x ≠ z, x is connected by an edge with y, and y is connected by an edge with z. The colours of x, y and z should be pairwise distinct. Let's call a painting which meets this condition good.

You have to calculate the minimum cost of a good painting and find one of the optimal paintings. If there is no good painting, report about it.

Input

The first line contains one integer n (3 ≤ n ≤ 100 000) — the number of vertices.

The second line contains a sequence of integers c_{1, 1}, c_{1, 2}, ..., c_{1, n} (1 ≤ c_{1, i} ≤ 10^{9}), where c_{1, i} is the cost of painting the i-th vertex into the first color.

The third line contains a sequence of integers c_{2, 1}, c_{2, 2}, ..., c_{2, n} (1 ≤ c_{2, i} ≤ 10^{9}), where c_{2, i} is the cost of painting the i-th vertex into the second color.

The fourth line contains a sequence of integers c_{3, 1}, c_{3, 2}, ..., c_{3, n} (1 ≤ c_{3, i} ≤ 10^{9}), where c_{3, i} is the cost of painting the i-th vertex into the third color.

Then (n - 1) lines follow, each containing two integers u_j and v_j (1 ≤ u_j, v_j ≤ n, u_j ≠ v_j) — the numbers of vertices connected by the j-th undirected edge. It is guaranteed that these edges denote a tree.

Output

If there is no good painting, print -1.

Otherwise, print the minimum cost of a good painting in the first line. In the second line print n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ 3), where the i-th integer should denote the color of the i-th vertex. If there are multiple good paintings with minimum cost, print any of them.

Examples

Input

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

Output

6
1 3 2

Input

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

Output

-1

Input

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

Output

9
1 3 2 1 3

Note

All vertices should be painted in different colors in the first example. The optimal way to do it is to paint the first vertex into color 1, the second vertex — into color 3, and the third vertex — into color 2. The cost of this painting is 3 + 2 + 1 = 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11;
int n, root;
long long boje[5][N];
vector<int> ls[N];
long long res = 1e14 + 11;
vector<int> v;
int r1, r2, r3;
int rez[N];
void dfs(int x, int p) {
  v.push_back(x);
  for (int i = 0; i < ls[x].size(); i++) {
    if (ls[x][i] == p) continue;
    dfs(ls[x][i], x);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%lld", &boje[i][j]);
    }
  }
  for (int i = 0; i < n - 1; i++) {
    int a1, a2;
    scanf("%d%d", &a1, &a2);
    a1--;
    a2--;
    ls[a1].push_back(a2);
    ls[a2].push_back(a1);
  }
  for (int i = 0; i < n; i++) {
    if (ls[i].size() >= 3) {
      cout << -1;
      return 0;
    }
    if (ls[i].size() == 1) root = i;
  }
  dfs(root, -1);
  for (int x = 1; x < 4; x++) {
    for (int y = 1; y < 4; y++) {
      if (x == y) continue;
      int z = 6 - x - y;
      long long sada = 0;
      for (int i = 0; i < n; i++) {
        if (i % 3 == 0)
          sada += boje[x - 1][v[i]];
        else if (i % 3 == 1)
          sada += boje[y - 1][v[i]];
        else
          sada += boje[z - 1][v[i]];
      }
      if (sada < res) {
        res = sada;
        r1 = x;
        r2 = y;
        r3 = z;
      }
    }
  }
  cout << res << endl;
  for (int i = 0; i < n; i++) {
    if (i % 3 == 0)
      rez[v[i]] = r1;
    else if (i % 3 == 1)
      rez[v[i]] = r2;
    else
      rez[v[i]] = r3;
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", rez[i]);
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.

The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.

Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?

Constraints

* All values in input are integers.
* 1 \leq L, A, B < 10^{18}
* 2 \leq M \leq 10^9
* All terms in the arithmetic progression are less than 10^{18}.

Input

Input is given from Standard Input in the following format:

L A B M

Output

Print the remainder when the integer obtained by concatenating the terms is divided by M.

Examples

Input

5 3 4 10007

Output

5563

Input

4 8 1 1000000

Output

891011

Input

107 10000000000007 1000000000000007 998244353

Output

39122908

### Response

```cpp
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define Nmax 55

ll mo;

ll po(ll x,ll y){ if(y<0)cout<<1/0<<endl;
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x;
	x=x*x;
    }
    return res;
}

ll pomo(ll x,ll y){ if(y<0)cout<<1/0<<endl;
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mo;
	x=x*x%mo;
    }
    return res;
}

struct matrix{
    ll t[3][3];
};
matrix mul(matrix a,matrix b){
    matrix c;
    for(int i=0;i<3;i++)for(int j=0;j<3;j++){
	ll res=0;
	for(int k=0;k<3;k++){
	    res+=a.t[i][k]*b.t[k][j];
	}
	c.t[i][j]=res%mo;
    }
    return c;
}
ll solve(ll d,ll a,ll b,ll l){
    matrix r[66];
    ll kei[]={1,b%mo,0,0,po(10,d)%mo,0,1,a%mo,1};
    for(int i=0;i<3;i++)for(int j=0;j<3;j++){
	r[0].t[i][j]=kei[i*3+j];
    }
    for(int i=1;i<62;i++)r[i]=mul(r[i-1],r[i-1]);
    matrix res; bool fi=1;
    for(int i=0;i<62;i++){
	if((1LL<<i)&l){
	    if(fi)res=r[i],fi=0;
	    else res=mul(res,r[i]);
	}
    }
    return res.t[2][1];
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll l,a,b;
    cin>>l>>a>>b>>mo;
    ll ans=0;
    ll ruiketa=1;
    for(int d=18;d>=1;d--){
	if(po(10,d)<=a)continue;
	if(a+b*(l-1)<po(10,d-1))continue;
	ll s=a; if(s<po(10,d-1))s=a+(po(10,d-1)-1-a+b)/b*b;
	ll t=a+b*(l-1); if(po(10,d)<=t)t=a+(po(10,d)-1-a)/b*b;
	ll len=(t-s)/b+1;
	if(len>0){
	    ll res=solve(d,s,b,len); //cout<<d<<" "<<s<<" "<<b<<" "<<len<<" "<<res<<endl;
	    ans=ans+ruiketa*res; ans%=mo;
	    ruiketa=ruiketa*pomo(pomo(10,len),d)%mo;
	}
    }
    cout<<ans<<endl;
}

```


### Prompt

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

We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls.

Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition:

* Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order.
* Then, \sum_j (c_j-a_j) should be as small as possible.

Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.

Constraints

* 1 \leq N \leq 10^5
* |S|=3N
* S consists of `R`, `G`, and `B`, and each of these characters occurs N times in S.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of ways in which Takahashi can distribute the balls, modulo 998244353.

Examples

Input

3
RRRGGGBBB

Output

216

Input

5
BBRGRRGRGGRBBGB

Output

960

### Response

```cpp
#include <bits/stdc++.h>
const int mod=998244353;
using namespace std;
int n;
char a[300010];
int main(){
	int RG=0,GB=0,RB=0,R=0,G=0,B=0,phi,ans=1;
	scanf("%d",&n),phi=n,n*=3;
	scanf("%s",a+1);
	for(int i=1;i<=n;i++){
		if(a[i]=='R'){
			if(GB) ans=1ll*ans*GB%mod,GB--;
			else if(G) ans=1ll*ans*G%mod,G--,RG++;
			else if(B) ans=1ll*ans*B%mod,B--,RB++;
			else ans=1ll*ans*phi%mod,phi--,R++;
		}
		if(a[i]=='G'){
			if(RB) ans=1ll*ans*RB%mod,RB--;
			else if(R) ans=1ll*ans*R%mod,R--,RG++;
			else if(B) ans=1ll*ans*B%mod,B--,GB++;
			else ans=1ll*ans*phi%mod,phi--,G++;
		}
		if(a[i]=='B'){
			if(RG) ans=1ll*ans*RG%mod,RG--;
			else if(R) ans=1ll*ans*R%mod,R--,RB++;
			else if(G) ans=1ll*ans*G%mod,G--,GB++;
			else ans=1ll*ans*phi%mod,phi--,B++;
		}
	}
	printf("%d\n",ans);
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.

Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.

Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Constraints

* 1 \leq N \leq 300
* 1 \leq M \leq 300
* A_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M.

Input

Input is given from Standard Input in the following format:

N M
A_{11} A_{12} ... A_{1M}
A_{21} A_{22} ... A_{2M}
:
A_{N1} A_{N2} ... A_{NM}

Output

Print the minimum possible number of the participants in the sport with the largest number of participants.

Examples

Input

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

Output

2

Input

3 3
2 1 3
2 1 3
2 1 3

Output

3

### Response

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

using namespace std;

const int MAX_N = 300, MAX_M = 300;
int n, m;
int a[MAX_N][MAX_M];

int main()
{
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      cin >> a[i][j];

  vector<bool> valid(m, true);
  int min_q = INT_MAX;
  for (int i = 0; i < m; i++) {
    vector<int> ctr(m, 0);
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if (valid[a[j][k]-1]) {
          ctr[a[j][k]-1]++;
          break;
        }
      }
    }
    int mi = max_element(ctr.begin(), ctr.end()) - ctr.begin();
    min_q = min(min_q, ctr[mi]);
    valid[mi] = false;
  }

  cout << min_q << endl;

  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.

<image>

Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.

Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.

Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.

Input

The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.

Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.

Output

Output a single integer — the number of ways to choose three cards that form a set.

Examples

Input

3 3
SET
ETS
TSE

Output

1

Input

3 4
SETE
ETSE
TSES

Output

0

Input

5 4
SETT
TEST
EEET
ESTE
STES

Output

2

Note

In the third example test, these two triples of cards are sets:

  1. "SETT", "TEST", "EEET"
  2. "TEST", "ESTE", "STES"

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<string> v(n);
  set<string> s;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    s.insert(v[i]);
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      string str(k, ' ');
      for (int u = 0; u < k; ++u) {
        if (v[i][u] == v[j][u]) {
          str[u] = v[i][u];
        } else {
          int ch = 'E' + 'S' + 'T';
          ch -= v[i][u];
          ch -= v[j][u];
          str[u] = static_cast<char>(ch);
        }
      }
      if (s.count(str) > 0) {
        ++res;
      }
    }
  }
  cout << res / 3 << endl;
  return 0;
}

```


### Prompt

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

There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

Recently, they learned the operation called xor (exclusive OR).

What is xor?

For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:

* When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3~\textrm{xor}~5 = 6.

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i. Using this information, restore the integer written on the scarf of each Snuke Cat.

Constraints

* All values in input are integers.
* 2 \leq N \leq 200000
* N is even.
* 0 \leq a_i \leq 10^9
* There exists a combination of integers on the scarfs that is consistent with the given information.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print a line containing N integers separated with space.

The i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.

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

Example

Input

4
20 11 9 24

Output

26 5 7 22

### Response

```cpp
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, ans = 0;
  scanf("%lld", &n);
  ll a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), ans ^= a[i];
  for(i = 0; i < n; ++i) printf("%lld ", ans ^ a[i]);
  return 0;
}
```


### Prompt

Generate a CPP solution to the following problem:

You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0, 0, 0) and (1, 1, 1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube.

Input

The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.

Output

Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO".

Examples

Input

0 0 0
0 1 0

Output

YES

Input

1 1 0
0 1 0

Output

YES

Input

0 0 0
1 1 1

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int x1, y1, z1, x2, y2, z2;
  scanf("%d %d %d", &x1, &y1, &z1);
  scanf("%d %d %d", &x2, &y2, &z2);
  if (x1 == x2 || y1 == y2 || z1 == z2)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:

* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.

What is the largest possible sum of the integers written on the blackboard after K operations?

Constraints

* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

A B C
K

Output

Print the largest possible sum of the integers written on the blackboard after K operations by E869220.

Examples

Input

5 3 11
1

Output

30

Input

3 3 4
2

Output

22

### Response

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

int main(){
  int a,b,c,k;cin>>a>>b>>c>>k;
  int s=a+b+c,m=max({a,b,c});s-=m;
  for(int i=0;i<k;i++)m*=2;
  cout<<s+m<<endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Let N be a positive even number.

We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.

First, let q be an empty sequence. Then, perform the following operation until p becomes empty:

* Select two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.

When p becomes empty, q will be a permutation of (1, 2, ..., N).

Find the lexicographically smallest permutation that can be obtained as q.

Constraints

* N is an even number.
* 2 ≤ N ≤ 2 × 10^5
* p is a permutation of (1, 2, ..., N).

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

Print the lexicographically smallest permutation, with spaces in between.

Examples

Input

4
3 2 4 1

Output

3 1 2 4

Input

2
1 2

Output

1 2

Input

8
4 6 3 2 8 5 7 1

Output

3 1 2 7 4 6 8 5

### Response

```cpp
#include <cstdio>
#include <queue>
#include <algorithm>
int N, p[200001], ref[200001], RMQ[2][18][200001], LOG[200001];
struct tok
{
	int l, r, x, y;
};
struct com
{
	inline bool operator () (const tok &x, const tok &y)
	{
		return p[x.x] > p[y.x];
	}
};
inline int choose(int x, int y)
{
	return p[x] < p[y] ? x : y;
}
inline int Query(int f, int l, int r)
{
	int Log = LOG[r - l + 1];
	return choose(RMQ[f][Log][l], RMQ[f][Log][r - (1 << Log) + 1]);
}
std::priority_queue < tok, std::vector < tok >, com > Q;
tok make(int l, int r)
{
	int x = Query(l & 1, l, r - 1), y = Query(r & 1, x + 1, r);
	return { l, r, x, y };
}
int main()
{
	scanf("%d", &N);
	p[0] = 1000000000;
	for (int i = 1; i <= N; i++)
	{
		scanf("%d", p + i);
		ref[p[i]] = i;
		RMQ[i & 1][0][i] = i;
	}
	for (int i = 2; i <= N; i++)
		LOG[i] = LOG[i >> 1] + 1;
	for (int i = 1, k = 1; k + k <= N; i++, k <<= 1)
		for (int j = 1; j <= N - k - k + 1; j++)
		{
			RMQ[0][i][j] = choose(RMQ[0][i - 1][j], RMQ[0][i - 1][j + k]);
			RMQ[1][i][j] = choose(RMQ[1][i - 1][j], RMQ[1][i - 1][j + k]);
		}
	Q.push(make(1, N));
	for (int T = N >> 1; T--; )
	{
		tok D = Q.top();
		Q.pop();
		printf("%d %d ", p[D.x], p[D.y]);
		if (D.l < D.x)
			Q.push(make(D.l, D.x - 1));
		if (D.x < D.y - 1)
			Q.push(make(D.x + 1, D.y - 1));
		if (D.y < D.r)
			Q.push(make(D.y + 1, D.r));
	}
	puts("");
	return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!

Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.

Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.

Input

The first line contains two numbers n and m (2 ≤ n, m ≤ 100) — the dimensions of the matrix.

The second line contains n numbers a1, a2, ..., an (0 ≤ ai ≤ 109), where ai is the xor of all elements in row i.

The third line contains m numbers b1, b2, ..., bm (0 ≤ bi ≤ 109), where bi is the xor of all elements in column i.

Output

If there is no matrix satisfying the given constraints in the first line, output "NO".

Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cim (0 ≤ cij ≤ 2·109) — the description of the matrix.

If there are several suitable matrices, it is allowed to print any of them.

Examples

Input

2 3
2 9
5 3 13

Output

YES
3 4 5
6 7 8

Input

3 3
1 7 6
2 15 12

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long xall = 0;
long long INF = 1e9;
long long ans[105][105];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, mn;
  cin >> n >> m;
  mn = min(n, m);
  vector<long long> r(n);
  vector<long long> c(m);
  for (int i = 0; i < n; i++) {
    cin >> r[i];
    xall ^= r[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i];
    xall ^= c[i];
  }
  if (xall != 0) {
    cout << "NO";
    return 0;
  }
  for (long long x = 1; x <= INF; x <<= 1) {
    int i = 0, j = 0;
    for (; i < n && j < m;) {
      while (i < n && r[i] % 2 == 0) i++;
      if (i >= n) break;
      while (j < m && c[j] % 2 == 0) j++;
      if (j >= m) break;
      ans[i][j] += x;
      i++;
      j++;
    }
    for (int t = i; t < n; t++)
      if (r[t] % 2 == 1) ans[t][0] += x;
    for (int t = j; t < m; t++)
      if (c[t] % 2 == 1) ans[0][t] += x;
    for (i = 0; i < n; i++) r[i] >>= 1;
    for (i = 0; i < m; i++) c[i] >>= 1;
  }
  cout << "YES\n";
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << ans[i][j] << " ";
    cout << "\n";
  }
  return 0;
}

```


### Prompt

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

Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.

Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.

Help her to do so in finding the total number of such segments.

Input

The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 ≤ n ≤ 105, 1 ≤ |k| ≤ 10).

Next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — affection values of chemicals.

Output

Output a single integer — the number of valid segments.

Examples

Input

4 2
2 2 2 2

Output

8

Input

4 -3
3 -6 -3 12

Output

3

Note

Do keep in mind that k0 = 1.

In the first sample, Molly can get following different affection values:

  * 2: segments [1, 1], [2, 2], [3, 3], [4, 4];

  * 4: segments [1, 2], [2, 3], [3, 4];

  * 6: segments [1, 3], [2, 4];

  * 8: segments [1, 4].

Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.

In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18, mod = 1e9 + 7;
const int N = 3e5, inf = 1e9;
long long n, k, a[N], sum[N], pref[N], ans;
map<long long, long long> m;
vector<long long> v;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = n; i > 0; i--) {
    pref[i] = pref[i + 1] + a[i];
    m[pref[i]]++;
  }
  m[0]++;
  if (k == -1) {
    v.push_back(1);
    v.push_back(-1);
  } else if (k == 1)
    v.push_back(1);
  else {
    v.push_back(1);
    for (int i = 1; v[v.size() - 1] * k <= 1e15 + 1111; i++)
      v.push_back(v[v.size() - 1] * k);
  }
  for (int i = 0; i <= n; i++) {
    m[pref[i + 1]]--;
    for (int j = 0; j < v.size(); j++)
      if (m[sum[n] - (v[j] + sum[i])]) {
        ans += m[sum[n] - (v[j] + sum[i])];
      }
  }
  cout << ans;
  return 0;
}

```