### Prompt

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

Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k × k consisting entirely of broken pixels. She knows that q pixels are already broken, and for each of them she knows the moment when it stopped working. Help Luba to determine when the monitor became broken (or tell that it's still not broken even after all q pixels stopped working).

Input

The first line contains four integer numbers n, m, k, q (1 ≤ n, m ≤ 500, 1 ≤ k ≤ min(n, m), 0 ≤ q ≤ n·m) — the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pixels.

Each of next q lines contain three integer numbers xi, yi, ti (1 ≤ xi ≤ n, 1 ≤ yi ≤ m, 0 ≤ t ≤ 109) — coordinates of i-th broken pixel (its row and column in matrix) and the moment it stopped working. Each pixel is listed at most once.

We consider that pixel is already broken at moment ti.

Output

Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these q pixels stopped working.

Examples

Input

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

Output

8

Input

3 3 2 5
1 2 2
2 2 1
2 3 5
3 2 10
2 1 100

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct order {
  int row;
  int column;
  long time;
};
int main() {
  int n, m, k, qq;
  long(*A)[600] = new long[600][600];
  int(*B)[600] = new int[600][600];
  order *all_order = new order[300000];
  cin >> n >> m >> k >> qq;
  int i, j;
  for (i = 0; i < 600; i++) {
    for (j = 0; j < 600; j++) {
      A[i][j] = -1;
    }
  }
  long max_num = 0;
  for (i = 0; i < qq; i++) {
    cin >> all_order[i].row >> all_order[i].column >> all_order[i].time;
    A[all_order[i].row][all_order[i].column] = all_order[i].time;
    if (all_order[i].time > max_num) {
      max_num = all_order[i].time;
    }
  }
  long left = 0;
  long right = max_num;
  long try_num;
  for (i = 0; i < 600; i++) {
    for (j = 0; j < 600; j++) {
      B[i][j] = 0;
    }
  }
  while (left <= right) {
    long mid = (left + right) / 2;
    int flag = 0;
    long temp_num;
    try_num = mid;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        B[i][j] = B[i - 1][j] + B[i][j - 1] - B[i - 1][j - 1] +
                  (A[i][j] <= try_num) * (A[i][j] != -1);
      }
    }
    for (i = 1; i <= n - k + 1; i++) {
      for (j = 1; j <= m - k + 1; j++) {
        temp_num = B[i + k - 1][j + k - 1] - B[i - 1][j + k - 1] -
                   B[i + k - 1][j - 1] + B[i - 1][j - 1];
        if (temp_num == k * k) {
          flag = 1;
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag) {
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  if (left > max_num) {
    cout << -1;
    return 0;
  }
  int flag = 0;
  long temp_num;
  try_num = left;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      B[i][j] = B[i - 1][j] + B[i][j - 1] - B[i - 1][j - 1] +
                (A[i][j] <= try_num) * (A[i][j] != -1);
    }
  }
  for (i = 1; i <= n - k + 1; i++) {
    for (j = 1; j <= m - k + 1; j++) {
      temp_num = B[i + k - 1][j + k - 1] - B[i - 1][j + k - 1] -
                 B[i + k - 1][j - 1] + B[i - 1][j - 1];
      if (temp_num == k * k) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      break;
    }
  }
  if (flag) {
    cout << left;
    return 0;
  }
  cout << -1;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any direction takes the same time.

All residents of Berland are very lazy people, and so when they want to get from city v to city u, they always choose one of the shortest paths (no matter which one).

The Berland government wants to make this country's road network safer. For that, it is going to put a police station in one city. The police station has a rather strange property: when a citizen of Berland is driving along the road with a police station at one end of it, the citizen drives more carefully, so all such roads are considered safe. The roads, both ends of which differ from the city with the police station, are dangerous.

Now the government wonders where to put the police station so that the average number of safe roads for all the shortest paths from the cultural capital to the main capital would take the maximum value.

Input

The first input line contains two integers n and m (2 ≤ n ≤ 100, <image>) — the number of cities and the number of roads in Berland, correspondingly. Next m lines contain pairs of integers vi, ui (1 ≤ vi, ui ≤ n, vi ≠ ui) — the numbers of cities that are connected by the i-th road. The numbers on a line are separated by a space.

It is guaranteed that each pair of cities is connected with no more than one road and that it is possible to get from any city to any other one along Berland roads.

Output

Print the maximum possible value of the average number of safe roads among all shortest paths from the culture capital to the main one. The answer will be considered valid if its absolute or relative inaccuracy does not exceed 10 - 6.

Examples

Input

4 4
1 2
2 4
1 3
3 4

Output

1.000000000000

Input

11 14
1 2
1 3
2 4
3 4
4 5
4 6
5 11
6 11
1 8
8 9
9 7
11 7
1 10
10 4

Output

1.714285714286

Note

In the first sample you can put a police station in one of the capitals, then each path will have exactly one safe road. If we place the station not in the capital, then the average number of safe roads will also make <image>.

In the second sample we can obtain the maximum sought value if we put the station in city 4, then 6 paths will have 2 safe roads each, and one path will have 0 safe roads, so the answer will equal <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 + 1;
int n, m;
vector<int> a[maxN], mark[maxN];
int d1[maxN], dN[maxN], f[maxN];
void bfs(int v, int d[]) {
  memset(f, 0, sizeof f);
  memset(d, -1, sizeof d);
  vector<int> q;
  f[v] = 1;
  d[v] = 0;
  q.push_back(v);
  for (int i = 0; i < q.size(); i++) {
    int x = q[i];
    for (int j = 0; j < a[x].size(); j++)
      if (!f[a[x][j]]) {
        f[a[x][j]] = 1;
        d[a[x][j]] = d[x] + 1;
        q.push_back(a[x][j]);
      }
  }
}
double t[maxN][maxN], pc[maxN];
void dfs(int v) {
  cerr << "dfs " << v << endl;
  f[v] = 1;
  for (int i = 0; i < a[v].size(); i++) {
    if (!mark[v][i]) continue;
    int x = a[v][i];
    if (!f[x]) dfs(x);
    cerr << v << ' ' << x << ' ' << pc[x] << endl;
    pc[v] += pc[x];
    for (int j = 0; j < n; j++) t[v][j] += t[x][j];
    t[v][v] += pc[x];
  }
  if (v == n - 1) pc[v] = 1, t[v][v] = 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  bfs(0, d1);
  bfs(n - 1, dN);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < a[i].size(); j++) {
      mark[i].push_back(0);
      int x = a[i][j];
      if (d1[i] + dN[i] == dN[0] && d1[x] + dN[x] == dN[0] &&
          d1[x] == d1[i] + 1)
        cerr << i << ' ' << x << endl, mark[i][j] = true;
    }
  memset(f, 0, sizeof f);
  dfs(0);
  for (int i = 0; i < n; i++) cerr << pc[i] << ' ';
  cerr << endl;
  double best = 1;
  for (int i = 1; i < n - 1; i++) {
    best = max(best, t[0][i] * 2 / pc[0]);
  }
  cout << fixed << setprecision(20) << best << endl;
  return 0;
}

```


### Prompt

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

Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make k consecutive trips in the lift.

Let us suppose that at the moment you are on the floor number x (initially, you were on floor a). For another trip between floors you choose some floor with number y (y ≠ x) and the lift travels to this floor. As you cannot visit floor b with the secret lab, you decided that the distance from the current floor x to the chosen y must be strictly less than the distance from the current floor x to floor b with the secret lab. Formally, it means that the following inequation must fulfill: |x - y| < |x - b|. After the lift successfully transports you to floor y, you write down number y in your notepad.

Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of k trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 (109 + 7).

Input

The first line of the input contains four space-separated integers n, a, b, k (2 ≤ n ≤ 5000, 1 ≤ k ≤ 5000, 1 ≤ a, b ≤ n, a ≠ b).

Output

Print a single integer — the remainder after dividing the sought number of sequences by 1000000007 (109 + 7).

Examples

Input

5 2 4 1

Output

2

Input

5 2 4 2

Output

2

Input

5 3 4 1

Output

0

Note

Two sequences p1, p2, ..., pk and q1, q2, ..., qk are distinct, if there is such integer j (1 ≤ j ≤ k), that pj ≠ qj.

Notes to the samples:

  1. In the first sample after the first trip you are either on floor 1, or on floor 3, because |1 - 2| < |2 - 4| and |3 - 2| < |2 - 4|.
  2. In the second sample there are two possible sequences: (1, 2); (1, 3). You cannot choose floor 3 for the first trip because in this case no floor can be the floor for the second trip.
  3. In the third sample there are no sought sequences, because you cannot choose the floor for the first trip.

### Response

```cpp
#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 5100;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 500;
long long dp[2][maxn];
long long par[2][maxn];
long long finds(bool b, long long l, long long r) {
  if (l <= 1) {
    return par[b][r];
  }
  return (par[b][r] - par[b][l - 1] + mod) % mod;
}
int main() {
  long long n, a, b, k;
  cin >> n >> a >> b >> k;
  if (a < b) {
    n = b;
  } else {
    a = n - (a - 1);
    n = n - (b - 1);
  }
  for (long long i = 1; i < n; i++) {
    par[0][i] = i;
    dp[0][i] = 1;
  }
  for (long long i = 1; i <= k; i++) {
    for (long long j = 1; j < n; j++) {
      long long f = n - j;
      dp[i & 1][j] =
          (finds((i & 1) ^ 1, j - f + 1, n - 1) - dp[i & 1 ^ 1][j] + mod) % mod;
    }
    par[i & 1][1] = dp[i & 1][1];
    for (long long j = 2; j < n; j++) {
      par[i & 1][j] = (par[i & 1][j - 1] + dp[i & 1][j]) % mod;
    }
  }
  cout << dp[k & 1][a];
}

```


### Prompt

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

You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m > 0), so that for every pair of the remaining integers (ai, aj), the following unequality holds: <image>.

Input

The first line contains two integers n and k (1 ≤ n ≤ 5000, 0 ≤ k ≤ 4), which we have mentioned above.

The second line contains n distinct integers a1, a2, ..., an (0 ≤ ai ≤ 106).

Output

Print a single positive integer — the minimum m.

Examples

Input

7 0
0 2 3 6 7 12 18

Output

13

Input

7 1
0 2 3 6 7 12 18

Output

7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 10, maxc = 1000000 + 10;
struct node {
  node *nex;
  pair<short, short> p;
  node(const pair<short, short> &_p) {
    nex = NULL;
    p = _p;
  }
};
int a[maxn];
int fa[maxn];
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
node *v[maxc];
int n, k;
vector<int> tmp;
bool check(int m) {
  tmp.clear();
  int cnt = 0, ok = 1;
  for (int i = m; ok && i < maxc; i += m)
    for (node *j = v[i]; j; j = j->nex) {
      int x = getfa(j->p.first), y = getfa(j->p.second);
      if (x == y) continue;
      if (cnt++ == k) {
        ok = 0;
        break;
      }
      fa[x] = y;
      tmp.push_back(x);
    }
  for (auto i : tmp) fa[i] = i;
  return ok;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      node *u = v[a[j] - a[i]];
      node *r = new node(make_pair(i, j));
      r->nex = u;
      v[a[j] - a[i]] = r;
    }
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i < maxc; i++)
    if (check(i)) {
      printf("%d\n", i);
      return 0;
    }
}

```


### Prompt

Create a solution in cpp for the following problem:

Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows:

  * F(k, n) = 0, for integer n, 1 ≤ n < k;
  * F(k, k) = 1;
  * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k.

Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k.

You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers.

Input

The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1).

Output

In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s.

It is guaranteed that the answer exists. If there are several possible answers, print any of them.

Examples

Input

5 2

Output

3
0 2 3

Input

21 5

Output

3
4 1 16

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long f[100050];
long long n, k;
long long ans[5000];
int tot;
int main() {
  scanf("%I64d%I64d", &n, &k);
  long long temp = 1;
  f[0] = 1;
  int i;
  for (i = 1;; ++i) {
    f[i] = temp;
    temp += f[i];
    if (i - k >= 0) {
      temp -= f[i - k];
    }
    if (f[i] >= n) break;
  }
  tot = 0;
  for (; i >= 0; --i) {
    if (f[i] > n) continue;
    n -= f[i];
    ans[tot++] = f[i];
    if (n == 0) break;
  }
  if (tot == 1) {
    ans[tot++] = 0;
  }
  printf("%d\n", tot);
  for (int i = 0; i < tot; ++i) {
    if (i) printf(" ");
    printf("%I64d", ans[i]);
  }
  puts("");
  return 0;
}

```


### Prompt

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

In the advanced algorithm class, n2 students sit in n rows and n columns. One day, a professor who teaches this subject comes into the class, asks the shortest student in each row to lift up his left hand, and the tallest student in each column to lift up his right hand. What is the height of the student whose both hands are up ? The student will become a target for professor’s questions.

Given the size of the class, and the height of the students in the class, you have to print the height of the student who has both his hands up in the class.

Input

The input will consist of several cases. the first line of each case will be n(0 < n < 100), the number of rows and columns in the class. It will then be followed by a n-by-n matrix, each row of the matrix appearing on a single line. Note that the elements of the matrix may not be necessarily distinct. The input will be terminated by the case n = 0.

Output

For each input case, you have to print the height of the student in the class whose both hands are up. If there is no such student, then print 0 for that case.

Example

Input

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

Output

7
7

### Response

```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int t[100][100];
int u[100],v[100];

void solve(){
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(u[i]!=v[j])continue;
      cout<<t[i][j]<<endl;
      return;
    }
  }
  cout<<0<<endl;
}

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      u[i]=1e8;v[i]=-1;
      for(int j=0;j<n;j++){
	cin>>t[i][j];
      }
    }

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	u[i]=min(u[i],t[i][j]);
	v[j]=max(v[j],t[i][j]);
      }
    }

    solve();

  }
  return 0;
}
```


### Prompt

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

In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.

The trajectory of a camel's spit is an arc, i.e. if the camel in position x spits d meters right, he can hit only the camel in position x + d, if such a camel exists.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of di correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.

Output

If there are two camels, which spitted at each other, output YES. Otherwise, output NO.

Examples

Input

2
0 1
1 -1

Output

YES

Input

3
0 1
1 1
2 -2

Output

NO

Input

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

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[101], b[101], c[101];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    c[i] = a[i] + b[i];
  }
  bool check = false;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if ((c[i] == a[j]) && c[j] == a[i]) {
        check = true;
        break;
      }
    }
  }
  if (check == true)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≤ i < n there is an edge between the vertices of i and i+1.

Denote the function f(l, r), which takes two integers l and r (l ≤ r):

  * We leave in the tree only vertices whose values range from l to r.
  * The value of the function will be the number of connected components in the new graph.

Your task is to calculate the following sum: $$$∑_{l=1}^{n} ∑_{r=l}^{n} f(l, r) $$$

Input

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

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — the values of the vertices.

Output

Print one number — the answer to the problem.

Examples

Input

3
2 1 3

Output

7

Input

4
2 1 1 3

Output

11

Input

10
1 5 2 5 5 3 10 6 5 1

Output

104

Note

In the first example, the function values will be as follows:

  * f(1, 1)=1 (there is only a vertex with the number 2, which forms one component)
  * f(1, 2)=1 (there are vertices 1 and 2 that form one component)
  * f(1, 3)=1 (all vertices remain, one component is obtained)
  * f(2, 2)=1 (only vertex number 1)
  * f(2, 3)=2 (there are vertices 1 and 3 that form two components)
  * f(3, 3)=1 (only vertex 3)

Totally out 7.

In the second example, the function values will be as follows:

  * f(1, 1)=1
  * f(1, 2)=1
  * f(1, 3)=1
  * f(1, 4)=1
  * f(2, 2)=1
  * f(2, 3)=2
  * f(2, 4)=2
  * f(3, 3)=1
  * f(3, 4)=1
  * f(4, 4)=0 (there is no vertex left, so the number of components is 0)

Totally out 11.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N;
long long lst, n;
int main() {
  cin >> N;
  long long tot = 0;
  for (int i = 1; i <= N; i++) {
    cin >> n;
    if (lst < n) {
      tot += (n - lst) * (N - n + 1);
    } else if (lst > n) {
      tot += (lst - n) * (n);
    }
    lst = n;
  }
  cout << tot << endl;
}

```


### Prompt

Please provide a CPP coded solution 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 rest=a+b+c-max({a,b,c});
  cout<<rest+max({a,b,c})*powf(2,k)<<endl;
}

```


### Prompt

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

As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lowercase English letter.

<image>

Max and Lucas are playing the game. Max goes first, then Lucas, then Max again and so on. Each player has a marble, initially located at some vertex. Each player in his/her turn should move his/her marble along some edge (a player can move the marble from vertex v to vertex u if there's an outgoing edge from v to u). If the player moves his/her marble from vertex v to vertex u, the "character" of that round is the character written on the edge from v to u. There's one additional rule; the ASCII code of character of round i should be greater than or equal to the ASCII code of character of round i - 1 (for i > 1). The rounds are numbered for both players together, i. e. Max goes in odd numbers, Lucas goes in even numbers. The player that can't make a move loses the game. The marbles may be at the same vertex at the same time.

Since the game could take a while and Lucas and Max have to focus on finding Dart, they don't have time to play. So they asked you, if they both play optimally, who wins the game?

You have to determine the winner of the game for all initial positions of the marbles.

Input

The first line of input contains two integers n and m (2 ≤ n ≤ 100, <image>).

The next m lines contain the edges. Each line contains two integers v, u and a lowercase English letter c, meaning there's an edge from v to u written c on it (1 ≤ v, u ≤ n, v ≠ u). There's at most one edge between any pair of vertices. It is guaranteed that the graph is acyclic.

Output

Print n lines, a string of length n in each one. The j-th character in i-th line should be 'A' if Max will win the game in case her marble is initially at vertex i and Lucas's marble is initially at vertex j, and 'B' otherwise.

Examples

Input

4 4
1 2 b
1 3 a
2 4 c
3 4 b

Output

BAAA
ABAA
BBBA
BBBB

Input

5 8
5 3 h
1 2 c
3 1 c
3 2 r
5 1 r
4 3 z
5 4 r
5 2 h

Output

BABBB
BBBBB
AABBB
AAABA
AAAAB

Note

Here's the graph in the first sample test case:

<image>

Here's the graph in the second sample test case:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
struct node {
  int to, v;
};
vector<node> edge[N];
int dp[N][N][30];
bool check(int x, int y, int la) {
  if (~dp[x][y][la]) return dp[x][y][la];
  for (int i = 0; i < edge[x].size(); i++) {
    int to = edge[x][i].to, z = edge[x][i].v;
    if (z < la) continue;
    if (!check(y, to, z)) return dp[x][y][la] = 1;
  }
  return dp[x][y][la] = 0;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) {
    char s[2];
    scanf("%d%d%s", &u, &v, s);
    int tmp = s[0] - 'a' + 1;
    edge[u].push_back(node<% v, tmp %>);
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (check(i, j, 0))
        cout << 'A';
      else
        cout << 'B';
    cout << endl;
  }
  return 0;
}

```


### Prompt

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

After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The balls are numbered with numbers from 1 to n.

Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which <image> is minimum, where i is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number.

For every ball print the number of the basket where it will go according to Valeric's scheme.

Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on.

Input

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of balls and baskets, correspondingly.

Output

Print n numbers, one per line. The i-th line must contain the number of the basket for the i-th ball.

Examples

Input

4 3

Output

2
1
3
2

Input

3 1

Output

1
1
1

### Response

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

```


### Prompt

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

Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated).

The weight of a is defined as the maximum number of elements you can remove.

You must answer q independent queries (x, y): after replacing the x first elements of a and the y last elements of a by n+1 (making them impossible to remove), what would be the weight of a?

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 3 ⋅ 10^5) — the length of the array and the number of queries.

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

The i-th of the next q lines contains two integers x and y (x, y ≥ 0 and x+y < n).

Output

Print q lines, i-th line should contain a single integer — the answer to the i-th query.

Examples

Input

13 5
2 2 3 9 5 4 6 5 7 8 3 11 13
3 1
0 0
2 4
5 0
0 12

Output

5
11
6
1
0

Input

5 2
1 4 1 2 4
0 0
1 0

Output

2
0

Note

Explanation of the first query:

After making first x = 3 and last y = 1 elements impossible to remove, a becomes [×, ×, ×, 9, 5, 4, 6, 5, 7, 8, 3, 11, ×] (we represent 14 as × for clarity).

Here is a strategy that removes 5 elements (the element removed is colored in red):

  * [×, ×, ×, 9, \color{red}{5}, 4, 6, 5, 7, 8, 3, 11, ×]
  * [×, ×, ×, 9, 4, 6, 5, 7, 8, 3, \color{red}{11}, ×]
  * [×, ×, ×, 9, 4, \color{red}{6}, 5, 7, 8, 3, ×]
  * [×, ×, ×, 9, 4, 5, 7, \color{red}{8}, 3, ×]
  * [×, ×, ×, 9, 4, 5, \color{red}{7}, 3, ×]
  * [×, ×, ×, 9, 4, 5, 3, ×] (final state)

It is impossible to remove more than 5 elements, hence the weight is 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char& s) {
  string res = "'";
  res += s;
  res += "'";
  return res;
}
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (i) res += ", ";
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
vector<long long> t, d, t2, d2;
vector<long long> upd;
void push2(long long v, long long l, long long r) {
  t2[v] += d2[v];
  if (l + 1 != r) {
    d2[v * 2 + 1] += d2[v];
    d2[v * 2 + 2] += d2[v];
  }
  d2[v] = 0;
}
void update2(long long v, long long l, long long r, long long i, long long x) {
  push2(v, l, r);
  if (l + 1 == r) {
    t2[v] = x;
    return;
  }
  long long m = (l + r) / 2;
  if (i < m)
    update2(v * 2 + 1, l, m, i, x);
  else
    update2(v * 2 + 2, m, r, i, x);
  t2[v] = min(t2[v * 2 + 1], t2[v * 2 + 2]);
}
void update4(long long v, long long l, long long r) {
  push2(v, l, r);
  if (t2[v] > 0) return;
  if (l + 1 == r) {
    upd.push_back(l);
    return;
  }
  long long m = (l + r) / 2;
  update4(v * 2 + 1, l, m);
  update4(v * 2 + 2, m, r);
}
void update3(long long v, long long l, long long r, long long l1,
             long long r1) {
  push2(v, l, r);
  if (l >= r1 || l1 >= r) return;
  if (l1 <= l && r <= r1) {
    d2[v] -= 1;
    push2(v, l, r);
    if (t2[v] > 1) return;
    update4(v, l, r);
    return;
  }
  long long m = (l + r) / 2;
  update3(v * 2 + 1, l, m, l1, r1);
  update3(v * 2 + 2, m, r, l1, r1);
  t2[v] = min(t2[v * 2 + 1], t2[v * 2 + 2]);
}
void push(long long v, long long l, long long r) {
  if (l + 1 != r) {
    d[v * 2 + 1] += d[v];
    d[v * 2 + 2] += d[v];
  }
  t[v] += d[v];
  d[v] = 0;
}
long long get(long long v, long long l, long long r, long long l1,
              long long r1) {
  push(v, l, r);
  if (l1 >= r || l >= r1) return 0;
  if (l1 <= l && r <= r1) return t[v];
  long long m = (l + r) / 2;
  return get(v * 2 + 1, l, m, l1, r1) + get(v * 2 + 2, m, r, l1, r1);
}
void update(long long v, long long l, long long r, long long l1, long long r1,
            long long x) {
  push(v, l, r);
  if (l1 >= r || l >= r1) return;
  if (l1 <= l && r <= r1) {
    d[v] += x;
    push(v, l, r);
    return;
  }
  long long m = (l + r) / 2;
  update(v * 2 + 1, l, m, l1, r1, x);
  update(v * 2 + 2, m, r, l1, r1, x);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, q;
  cin >> n >> q;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    a[i]--;
    a[i] = i - a[i];
  }
  vector<pair<long long, long long> > query[n + 1];
  for (long long i = 0; i < q; i++) {
    long long x, y;
    cin >> x >> y;
    query[x].push_back({y, i});
  }
  t.resize(4 * n, 0);
  d.resize(4 * n, 0);
  t2.resize(4 * n, 1e18);
  d2.resize(4 * n, 0);
  vector<long long> ans(q);
  for (long long j = n - 1; j >= 0; j--) {
    if (a[j] == 0) {
      upd.push_back(j);
    } else {
      if (a[j] < 0) a[j] = 1e18;
      update2(0, 0, n, j, a[j]);
    }
    while (upd.size() > 0) {
      long long x = upd.back();
      upd.pop_back();
      update(0, 0, n, x, n, 1);
      update2(0, 0, n, x, 1e18);
      update3(0, 0, n, x + 1, n);
    }
    for (auto el : query[j]) {
      ans[el.second] = get(0, 0, n, n - el.first - 1, n - el.first);
    }
  }
  for (long long i = 0; i < q; i++) cout << ans[i] << '\n';
}

```


### Prompt

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

M-kun is a competitor in AtCoder, whose highest rating is X.
In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:

* From 400 through 599: 8-kyu
* From 600 through 799: 7-kyu
* From 800 through 999: 6-kyu
* From 1000 through 1199: 5-kyu
* From 1200 through 1399: 4-kyu
* From 1400 through 1599: 3-kyu
* From 1600 through 1799: 2-kyu
* From 1800 through 1999: 1-kyu

What kyu does M-kun have?

Constraints

* 400 \leq X \leq 1999
* X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the kyu M-kun has, as an integer. For example, if he has 8-kyu, print `8`.

Examples

Input

725

Output

7

Input

1600

Output

2

### Response

```cpp

#include <iostream>

using namespace std;

int main(){

    int x;
  	cin >> x;
    cout <<  10 - x / 200 << endl;

    return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Takahashi has an empty string S and a variable x whose initial value is 0.

Also, we have a string T consisting of `0` and `1`.

Now, Takahashi will do the operation with the following two steps |T| times.

* Insert a `0` or a `1` at any position of S of his choice.
* Then, increment x by the sum of the digits in the odd positions (first, third, fifth, ...) of S. For example, if S is `01101`, the digits in the odd positions are `0`, `1`, `1` from left to right, so x is incremented by 2.

Print the maximum possible final value of x in a sequence of operations such that S equals T in the end.

Constraints

* 1 \leq |T| \leq 2 \times 10^5
* T consists of `0` and `1`.

Input

Input is given from Standard Input in the following format:

T

Output

Print the maximum possible final value of x in a sequence of operations such that S equals T in the end.

Examples

Input

1101

Output

5

Input

0111101101

Output

26

### Response

```cpp
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<(int)(n); ++i)
#define repeq(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1eq(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define rrep1(i,n) for (int i=(int)(n)-1; i>0; --i)
#define rrepeq(i,n) for (int i=(int)(n); i>=0; --i)
#define rrep1eq(i,n) for (int i=(int)(n); i>0; --i)
#define REP(i,a,b) for (int i=(int)(a); i<=(int)(b); ++i)
#define RREP(i,a,b) for (int i=(int)(a); i>=(int)(b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
// const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string interval[2] = {" ", "\n"}; // {" ", "\n"}

template<typename T> struct is_plural : false_type{};
template<typename T1, typename T2> struct is_plural<pair<T1, T2>> : true_type{};
template<typename T> struct is_plural<vector<T>> : true_type{};
template<typename T> struct is_plural<complex<T>> : true_type{};

template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << " " << p.second; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { if (vec.empty()) return os; bool pl = is_plural<T>(); os << vec.front(); for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) os << interval[pl] << *itr; return os; }

bool CoutYN(bool a, string y = "Yes", string n = "No") { cout << (a ? y : n) << "\n"; return a; }

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

long long modpow(int a, long long n, int mod = MOD) { long long ret = 1; do { if (n & 1) ret = ret * a % mod; a = 1LL * a * a % mod; } while (n >>= 1); return ret; }

template<typename T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; }

template<typename T1, typename T2> bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) { return a.second != b.second ? a.second < b.second : a.first < b.first; }
template<typename T1, typename T2> bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) { return a.first != b.first ? a.first < b.first : a.second > b.second; }

/* -------- <templates end> -------- */

void solve() {
  string t; cin >> t;

  int n = t.size();
  vi pos;
  ll sum = 0;
  rep(i,n) {
    if (t[i] == '1') sum++;
    else pos.emplace_back(sum);
  }
  ll x = ((sum + 1) / 2) * ((sum + 2) / 2);

  int sz = pos.size();
  int cnt = 0;
  vi res;

  rep(i,sz) {
    if ((pos[i] & 1) ^ (cnt & 1)) {
      sum++;
      cnt++;
      x += (sum + 1) / 2;
    } else {
      res.emplace_back(i);
    }
  }

  int odd = 0, even = 0;

  reverse(ALL(res));

  rep(i,res.size()) {
    sum++;
    if (i & 1) {
      odd = sz - res[i] - even;
      x += (sum + 1) / 2 - odd;
    } else {
      even = sz - res[i] - odd;
      x += (sum + 1) / 2 - even;
    }
  }

  cout << x << endl;
}

/* -------- <programs end> -------- */

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}

```


### Prompt

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

<image>

Input

The input contains a single integer a (1 ≤ a ≤ 18257).

Output

Print a single integer output (1 ≤ output ≤ 2·109).

Examples

Input

2

Output

13

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, Output, i, k, j;
  while (cin >> a) {
    i = 0;
    j = 0;
    Output = 1;
    for (k = 1; k <= a; k++) {
      i++;
      Output += j;
      j = 12 * i;
    }
    cout << Output << endl;
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

You are given a rooted tree. Let's denote d(x) as depth of node x: depth of the root is 1, depth of any other node x is d(y) + 1, where y is a parent of x.

The tree has the following property: every node x with d(x) = i has exactly ai children. Maximum possible depth of a node is n, and an = 0.

We define fk as the number of unordered pairs of vertices in the tree such that the number of edges on the simple path between them is equal to k.

Calculate fk modulo 109 + 7 for every 1 ≤ k ≤ 2n - 2.

Input

The first line of input contains an integer n (2 ≤ n ≤ 5 000) — the maximum depth of a node.

The second line of input contains n - 1 integers a1, a2, ..., an - 1 (2 ≤ ai ≤ 109), where ai is the number of children of every node x such that d(x) = i. Since an = 0, it is not given in the input.

Output

Print 2n - 2 numbers. The k-th of these numbers must be equal to fk modulo 109 + 7.

Examples

Input

4
2 2 2

Output

14 19 20 20 16 16

Input

3
2 3

Output

8 13 6 9

Note

This the tree from the first sample:

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T, class U>
using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V<V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class A, class B>
ostream& operator<<(ostream& out, const P<A, B>& p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <class A>
ostream& operator<<(ostream& out, const V<A>& v) {
  out << '[';
  for (int i = 0; i < int(v.size()); i++) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << ']';
}
const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;
const int N = 5000;
vvii down(N, vii(N, 0)), up(2, vii(2 * N, 0));
vii ans(2 * N, 0);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vii a(n);
  for (ll i = 0; i < n - 1; i++) cin >> a[i];
  vii cha(n, 1);
  for (ll i = 1; i < n; i++) cha[i] = ll(cha[i - 1]) * a[i - 1] % MOD;
  down[n - 1][0] = 1;
  for (ll i = n - 2; i > -1; i--) {
    down[i][0] = 1;
    for (ll j = 1; j < n; j++) {
      down[i][j] += ll(a[i]) * down[i + 1][j - 1] % MOD;
      if (down[i][j] >= MOD) down[i][j] -= MOD;
      ans[j] += ll(cha[i]) * down[i][j] % MOD;
      if (ans[j] >= MOD) ans[j] -= MOD;
    }
  }
  up[0][0] = 1;
  for (ll i = 1; i < n; i++) {
    up[1] = vii(2 * N, 0);
    up[1][0] = 1;
    for (ll j = 1; j < 2 * n; j++) {
      up[1][j] += up[0][j - 1];
      if (up[1][j] >= MOD) up[1][j] -= MOD;
      if (j >= 2 and j - 2 < n) {
        up[1][j] += ll(a[i - 1] - 1) * down[i][j - 2] % MOD;
        if (up[1][j] >= MOD) up[1][j] -= MOD;
      }
      ans[j] += ll(cha[i]) * up[1][j] % MOD;
      if (ans[j] >= MOD) ans[j] -= MOD;
    }
    swap(up[0], up[1]);
  }
  const int div2 = (MOD + 1) / 2;
  for (ll i = 1; i < 2 * n - 1; i++)
    cout << ll(ans[i]) * div2 % MOD << (i == 2 * n - 2 ? '\n' : ' ');
  return 0;
}

```


### Prompt

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

Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".

Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.

After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.

<image>

Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!

Input

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to

  * "L", if the i-th domino has been pushed to the left;
  * "R", if the i-th domino has been pushed to the right;
  * ".", if the i-th domino has not been pushed.

It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

Examples

Input

14
.L.R...LR..L..

Output

4

Input

5
R....

Output

0

Input

1
.

Output

1

Note

The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.

In the second example case, all pieces fall down since the first piece topples all the other pieces.

In the last example case, a single piece has not been pushed in either direction.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  if (n == 1 && str[0] == '.') {
    cout << "1";
    return 0;
  }
  int co = 0, i;
  for (i = 0; i < n; i++)
    if (str[i] == 'R' || str[i] == 'L') break;
  if (i == n) {
    cout << n;
    return 0;
  }
  if (str[i] == 'R') {
    co += i;
  }
  int j = i, k;
  for (k = i + 1; k < n; k++) {
    if (str[k] == 'L' && str[j] == 'R') {
      if ((k - j - 1) % 2 != 0) co++;
      j = k;
    }
    if (str[k] == 'R' && str[j] == 'L') {
      co += k - j - 1;
      j = k;
    }
    if (str[k] == 'L' && str[j] == 'L') {
      j = k;
    }
    if (str[k] == 'R' && str[j] == 'R') {
      j = k;
    }
  }
  if (j < n && str[j] == 'L') co += n - j - 1;
  cout << co;
  return 0;
}

```


### Prompt

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

Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.

Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.

Jzzhu wonders how to get the maximum possible number of groups. Can you help him?

Input

A single integer n (1 ≤ n ≤ 105), the number of the apples.

Output

The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.

If there are several optimal answers you can print any of them.

Examples

Input

6

Output

2
6 3
2 4

Input

9

Output

3
9 3
2 4
6 8

Input

2

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
bool prim[maxn];
bool vis[maxn];
int last[maxn];
vector<int> ve[2];
vector<int> tmp;
int main() {
  int n;
  scanf("%d", &n);
  int cot = 0;
  for (int i = 2; i <= n / 2; i++) {
    if (!prim[i]) {
      for (int j = 2 * i; j <= n; j += i) prim[j] = 1;
    }
  }
  for (int i = n / 2; i >= 2; i--) {
    if (!prim[i]) {
      tmp.clear();
      for (int j = 1; j * i <= n; j++) {
        if (vis[j * i]) continue;
        if (j != 2) {
          tmp.push_back(j * i);
          vis[j * i] = 1;
        }
      }
      if ((tmp.size()) & 1) {
        tmp.push_back(2 * i);
        vis[2 * i] = 1;
      }
      for (int j = 0; j < tmp.size(); j += 2) {
        ve[0].push_back(tmp[j]);
        ve[1].push_back(tmp[j + 1]);
      }
    }
  }
  printf("%d\n", ve[0].size());
  for (int i = 0; i < ve[0].size(); i++) printf("%d %d\n", ve[0][i], ve[1][i]);
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Fibonacci strings are defined as follows:

  * f1 = «a»
  * f2 = «b»
  * fn = fn - 1 fn - 2, n > 2

Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".

You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as a substring.

Input

The first line contains two space-separated integers k and m — the number of a Fibonacci string and the number of queries, correspondingly.

Next m lines contain strings si that correspond to the queries. It is guaranteed that strings si aren't empty and consist only of characters "a" and "b".

The input limitations for getting 30 points are:

  * 1 ≤ k ≤ 3000
  * 1 ≤ m ≤ 3000
  * The total length of strings si doesn't exceed 3000

The input limitations for getting 100 points are:

  * 1 ≤ k ≤ 1018
  * 1 ≤ m ≤ 104
  * The total length of strings si doesn't exceed 105

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

Output

For each string si print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo 1000000007 (109 + 7). Print the answers for the strings in the order in which they are given in the input.

Examples

Input

6 5
a
b
ab
ba
aba

Output

3
5
3
3
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct kieu {
  long long mang[5][5];
};
string need, s[10], p, xau;
int n, f[3001], base = 1000000007, full;
kieu matrix;
long long dp[10];
int tinh() {
  int q, i, ans;
  q = 0;
  ans = 0;
  for (i = 0; i <= int(need.length()) - 1; i++) {
    while ((q != 0) && (need[i] != p[q])) q = f[q];
    if (need[i] == p[q]) q++;
    if (q == int(p.length())) {
      ans++;
      q = f[q];
    }
  }
  return ans;
}
void init() {
  int i, q;
  memset(f, 0, sizeof(f));
  q = 0;
  f[1] = 0;
  for (i = 2; i <= int(p.length()); i++) {
    while ((q != 0) && (p[i - 1] != p[q])) q = f[q];
    if (p[i - 1] == p[q]) q++;
    f[i] = q;
  }
}
kieu nhan(kieu u, kieu v) {
  int i, j, t;
  kieu c;
  memset(c.mang, 0, sizeof(c.mang));
  for (i = 1; i <= 4; i++)
    for (j = 1; j <= 4; j++)
      for (t = 1; t <= 4; t++)
        c.mang[i][j] = (c.mang[i][j] + u.mang[i][t] * v.mang[t][j]) % base;
  return c;
}
kieu power(int x) {
  if (x == 1)
    return matrix;
  else {
    kieu p;
    p = power(x / 2);
    p = nhan(p, p);
    if (x & 1) p = nhan(p, matrix);
    return p;
  }
}
void solve() {
  kieu q;
  int j, t;
  long long ans;
  n = full;
  if (n <= 2) {
    need = s[n];
    cout << tinh();
    return;
  }
  n -= 2;
  while (s[1].length() < p.length()) {
    xau = s[2] + s[1];
    s[1] = s[2];
    s[2] = xau;
    n--;
    if (n == 0) break;
  }
  if (n == 0) {
    need = s[2];
    cout << tinh();
    return;
  }
  s[3] = s[2] + s[1];
  s[4] = s[3] + s[2];
  need = s[1];
  dp[1] = tinh();
  need = s[2];
  dp[2] = tinh();
  need = s[3];
  dp[3] = tinh();
  need = s[4];
  dp[4] = tinh();
  if (n + 2 <= 4) {
    cout << dp[n + 2];
    return;
  }
  q = power(n - 2);
  ans = 0;
  for (j = 4; j <= 4; j++)
    for (t = 1; t <= 4; t++) ans = (ans + dp[t] * q.mang[t][j]) % base;
  cout << ans;
}
void khoitaomatran() {
  memset(matrix.mang, 0, sizeof(matrix.mang));
  matrix.mang[4][4] = 1;
  matrix.mang[3][4] = 2;
  matrix.mang[2][4] = base - 1;
  matrix.mang[1][4] = base - 1;
  matrix.mang[4][3] = 1;
  matrix.mang[3][2] = 1;
  matrix.mang[2][1] = 1;
}
int main() {
  int test, ntest;
  scanf("%d%d\n", &n, &test);
  full = n;
  for (ntest = 1; ntest <= test; ntest++) {
    s[1] = "a";
    s[2] = "b";
    getline(cin, p);
    khoitaomatran();
    init();
    solve();
    cout << endl;
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

You are given an integer a that consists of n digits. You are also given a sequence of digits s of length m. The digit in position j (1 ≤ j ≤ m) of sequence s means that you can choose an arbitrary position i (1 ≤ i ≤ n) in a and replace the digit in the chosen position i with sj. Each element in the sequence s can participate in no more than one replacing operation.

Your task is to perform such sequence of replacements, that the given number a gets maximum value. You are allowed to use not all elements from s.

Input

The first line contains positive integer a. Its length n is positive and doesn't exceed 105. The second line contains sequence of digits s. Its length m is positive and doesn't exceed 105. The digits in the sequence s are written consecutively without any separators.

The given number a doesn't contain leading zeroes.

Output

Print the maximum value that can be obtained from a after a series of replacements. You are allowed to use not all elements from s. The printed number shouldn't contain any leading zeroes.

Examples

Input

1024
010

Output

1124

Input

987
1234567

Output

987

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
stack<char> sortStack(stack<char> &input) {
  stack<char> tmpStack;
  while (!input.empty()) {
    int tmp = input.top();
    input.pop();
    while (!tmpStack.empty() && tmpStack.top() > tmp) {
      input.push(tmpStack.top());
      tmpStack.pop();
    }
    tmpStack.push(tmp);
  }
  return tmpStack;
}
int main() {
  string n, s;
  cin >> n >> s;
  int i, j = 0;
  sort(s.rbegin(), s.rend());
  for (i = 0; n[i]; i++) {
    if (s[j] && s[j] > n[i]) {
      n[i] = s[j++];
    }
  }
  cout << n;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.

The forest

The Biridian Forest is a two-dimensional grid consisting of r rows and c columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.

The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example):

<image>

Moves

Breeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions:

  * Do nothing.
  * Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees.
  * If you are located on the exit cell, you may leave the forest. Only you can perform this move — all other mikemon breeders will never leave the forest by using this type of movement.

After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).

Mikemon battle

If you and t (t > 0) mikemon breeders are located on the same cell, exactly t mikemon battles will ensue that time (since you will be battling each of those t breeders once). After the battle, all of those t breeders will leave the forest to heal their respective mikemons.

Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders — there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).

Your goal

You would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.

Goal of other breeders

Because you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.

Your task

Print the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make.

Input

The first line consists of two integers: r and c (1 ≤ r, c ≤ 1000), denoting the number of rows and the number of columns in Biridian Forest. The next r rows will each depict a row of the map, where each character represents the content of a single cell:

  * 'T': A cell occupied by a tree.
  * 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map.
  * 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map.
  * A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder).

It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves.

Output

A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number.

Examples

Input

5 7
000E0T3
T0TT0T0
010T0T0
2T0T0T0
0T0S000

Output

3

Input

1 4
SE23

Output

2

Note

The following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog:

<image>

The three breeders on the left side of the map will be able to battle you — the lone breeder can simply stay in his place until you come while the other two breeders can move to where the lone breeder is and stay there until you come. The three breeders on the right does not have a way to battle you, so they will stay in their place.

For the second example, you should post this sequence in your Blog:

<image>

Here's what happens. First, you move one cell to the right.

<image>

Then, the two breeders directly to the right of the exit will simultaneously move to the left. The other three breeder cannot battle you so they will do nothing.

<image>

You end up in the same cell with 2 breeders, so 2 mikemon battles are conducted. After those battles, all of your opponents leave the forest.

<image>

Finally, you make another move by leaving the forest.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];
  bool v[1000][1000] = {0};
  vector<vector<int> > p;
  p.resize(n);
  for (int i = 0; i < n; ++i) p[i].resize(m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) p[i][j] = 100000000;
  ;
  ;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) v[i][j] = false;
  ;
  int sx, sy, ex, ey;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (d[i][j] == 'E')
        ex = i, ey = j;
      else if (d[i][j] == 'S')
        sx = i, sy = j;
  p[ex][ey] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(ex, ey));
  while (!q.empty()) {
    pair<int, int> c = q.front();
    q.pop();
    int x = c.first, y = c.second;
    int cr = p[x][y] + 1;
    if (x + 1 < n && d[x + 1][y] != 'T' && !v[x + 1][y]) {
      p[x + 1][y] = cr;
      v[x + 1][y] = true;
      q.push(make_pair(x + 1, y));
    }
    if (x - 1 >= 0 && d[x - 1][y] != 'T' && !v[x - 1][y]) {
      p[x - 1][y] = cr;
      v[x - 1][y] = true;
      q.push(make_pair(x - 1, y));
    }
    if (y + 1 < m && d[x][y + 1] != 'T' && !v[x][y + 1]) {
      p[x][y + 1] = cr;
      v[x][y + 1] = true;
      q.push(make_pair(x, y + 1));
    }
    if (y - 1 >= 0 && d[x][y - 1] != 'T' && !v[x][y - 1]) {
      p[x][y - 1] = cr;
      v[x][y - 1] = true;
      q.push(make_pair(x, y - 1));
    }
  }
  int ret = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (p[i][j] <= p[sx][sy] && d[i][j] != 'T' && d[i][j] != 'S' &&
          d[i][j] != 'E') {
        ret += d[i][j] - '0';
      }
  cout << ret << endl;
}

```


### Prompt

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

The Oak has n nesting places, numbered with integers from 1 to n. Nesting place i is home to b_i bees and w_i wasps.

Some nesting places are connected by branches. We call two nesting places adjacent if there exists a branch between them. A simple path from nesting place x to y is given by a sequence s_0, …, s_p of distinct nesting places, where p is a non-negative integer, s_0 = x, s_p = y, and s_{i-1} and s_{i} are adjacent for each i = 1, …, p. The branches of The Oak are set up in such a way that for any two pairs of nesting places x and y, there exists a unique simple path from x to y. Because of this, biologists and computer scientists agree that The Oak is in fact, a tree.

A village is a nonempty set V of nesting places such that for any two x and y in V, there exists a simple path from x to y whose intermediate nesting places all lie in V.

A set of villages \cal P is called a partition if each of the n nesting places is contained in exactly one of the villages in \cal P. In other words, no two villages in \cal P share any common nesting place, and altogether, they contain all n nesting places.

The Oak holds its annual Miss Punyverse beauty pageant. The two contestants this year are Ugly Wasp and Pretty Bee. The winner of the beauty pageant is determined by voting, which we will now explain. Suppose P is a partition of the nesting places into m villages V_1, …, V_m. There is a local election in each village. Each of the insects in this village vote for their favorite contestant. If there are strictly more votes for Ugly Wasp than Pretty Bee, then Ugly Wasp is said to win in that village. Otherwise, Pretty Bee wins. Whoever wins in the most number of villages wins.

As it always goes with these pageants, bees always vote for the bee (which is Pretty Bee this year) and wasps always vote for the wasp (which is Ugly Wasp this year). Unlike their general elections, no one abstains from voting for Miss Punyverse as everyone takes it very seriously.

Mayor Waspacito, and his assistant Alexwasp, wants Ugly Wasp to win. He has the power to choose how to partition The Oak into exactly m villages. If he chooses the partition optimally, determine the maximum number of villages in which Ugly Wasp wins.

Input

The first line of input contains a single integer t (1 ≤ t ≤ 100) denoting the number of test cases. The next lines contain descriptions of the test cases.

The first line of each test case contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 3000). The second line contains n space-separated integers b_1, b_2, …, b_n (0 ≤ b_i ≤ 10^9). The third line contains n space-separated integers w_1, w_2, …, w_n (0 ≤ w_i ≤ 10^9). The next n - 1 lines describe the pairs of adjacent nesting places. In particular, the i-th of them contains two space-separated integers x_i and y_i (1 ≤ x_i, y_i ≤ n, x_i ≠ y_i) denoting the numbers of two adjacent nesting places. It is guaranteed that these pairs form a tree.

It is guaranteed that the sum of n in a single file is at most 10^5.

Output

For each test case, output a single line containing a single integer denoting the maximum number of villages in which Ugly Wasp wins, among all partitions of The Oak into m villages.

Example

Input

2
4 3
10 160 70 50
70 111 111 0
1 2
2 3
3 4
2 1
143 420
214 349
2 1

Output

2
0

Note

In the first test case, we need to partition the n = 4 nesting places into m = 3 villages. We can make Ugly Wasp win in 2 villages via the following partition: \{\{1, 2\}, \{3\}, \{4\}\}. In this partition,

  * Ugly Wasp wins in village \{1, 2\}, garnering 181 votes as opposed to Pretty Bee's 170;
  * Ugly Wasp also wins in village \{3\}, garnering 111 votes as opposed to Pretty Bee's 70;
  * Ugly Wasp loses in the village \{4\}, garnering 0 votes as opposed to Pretty Bee's 50.

Thus, Ugly Wasp wins in 2 villages, and it can be shown that this is the maximum possible number.

In the second test case, we need to partition the n = 2 nesting places into m = 1 village. There is only one way to do this: \{\{1, 2\}\}. In this partition's sole village, Ugly Wasp gets 563 votes, and Pretty Bee also gets 563 votes. Ugly Wasp needs strictly more votes in order to win. Therefore, Ugly Wasp doesn't win in any village.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long b) {
  if (!b) return 1;
  long long ns = ksm(a, b >> 1);
  ns = ns * ns % 998244353;
  if (b & 1) ns = ns * a % 998244353;
  return ns;
}
int w[3010], b[3010], sz[3010];
vector<int> eg[3010];
pair<int, long long> dp[3010][3010];
pair<int, long long> add(pair<int, long long> a, pair<int, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
const long long inf = 1e18;
void upd(int a) {
  dp[a][sz[a]] = make_pair(0, -inf);
  for (int i = sz[a] - 1; i >= 0; i--)
    dp[a][i + 1] = max(dp[a][i + 1],
                       make_pair(dp[a][i].first + (dp[a][i].second > 0), 0ll));
}
pair<int, long long> r[3010];
void dfs(int a, int fa) {
  dp[a][0] = make_pair(0, w[a]);
  sz[a] = 1;
  for (auto v : eg[a]) {
    if (v == fa) continue;
    dfs(v, a);
    upd(v);
    for (int i = 0; i < sz[v] + sz[a]; i++) r[i] = make_pair(0, -inf);
    for (int i = 0; i <= sz[v]; i++)
      for (int j = 0; j < sz[a]; j++)
        r[i + j] = max(r[i + j], add(dp[v][i], dp[a][j]));
    sz[a] += sz[v];
    for (int i = 0; i < sz[a]; i++) dp[a][i] = r[i];
  }
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
      eg[i].clear();
    }
    for (int i = 1; i <= n; i++) scanf("%d", &w[i]), w[i] -= b[i];
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      eg[u].push_back(v), eg[v].push_back(u);
    }
    dfs(1, 0);
    int ans = dp[1][m - 1].first + (dp[1][m - 1].second > 0);
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

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

Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?

If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.

Input

The first line of the input contains integers n and m (1 ≤ n, m ≤ 100) — the number of buttons and the number of bulbs respectively.

Each of the next n lines contains xi (0 ≤ xi ≤ m) — the number of bulbs that are turned on by the i-th button, and then xi numbers yij (1 ≤ yij ≤ m) — the numbers of these bulbs.

Output

If it's possible to turn on all m bulbs print "YES", otherwise print "NO".

Examples

Input

3 4
2 1 4
3 1 3 1
1 2

Output

YES

Input

3 3
1 1
1 2
1 1

Output

NO

Note

In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
int vis[400007];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int c;
      cin >> c;
      vis[c] = 1;
    }
  }
  int f = 0;
  for (int i = 1; i < m + 1; i++) {
    if (!vis[i]) f++;
  }
  if (!f)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

```


### Prompt

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

Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'.

You are given a set of q possible operations. Limak can perform them in any order, any operation may be applied any number of times. The i-th operation is described by a string ai of length two and a string bi of length one. No two of q possible operations have the same string ai.

When Limak has a string s he can perform the i-th operation on s if the first two letters of s match a two-letter string ai. Performing the i-th operation removes first two letters of s and inserts there a string bi. See the notes section for further clarification.

You may note that performing an operation decreases the length of a string s exactly by 1. Also, for some sets of operations there may be a string that cannot be compressed any further, because the first two letters don't match any ai.

Limak wants to start with a string of length n and perform n - 1 operations to finally get a one-letter string "a". In how many ways can he choose the starting string to be able to get "a"? Remember that Limak can use only letters he knows.

Input

The first line contains two integers n and q (2 ≤ n ≤ 6, 1 ≤ q ≤ 36) — the length of the initial string and the number of available operations.

The next q lines describe the possible operations. The i-th of them contains two strings ai and bi (|ai| = 2, |bi| = 1). It's guaranteed that ai ≠ aj for i ≠ j and that all ai and bi consist of only first six lowercase English letters.

Output

Print the number of strings of length n that Limak will be able to transform to string "a" by applying only operations given in the input.

Examples

Input

3 5
ab a
cc c
ca a
ee c
ff d

Output

4

Input

2 8
af e
dc d
cc f
bc b
da b
eb a
bb b
ff c

Output

1

Input

6 2
bb a
ba a

Output

0

Note

In the first sample, we count initial strings of length 3 from which Limak can get a required string "a". There are 4 such strings: "abb", "cab", "cca", "eea". The first one Limak can compress using operation 1 two times (changing "ab" to a single "a"). The first operation would change "abb" to "ab" and the second operation would change "ab" to "a".

Other three strings may be compressed as follows:

  * "cab" <image> "ab" <image> "a"
  * "cca" <image> "ca" <image> "a"
  * "eea" <image> "ca" <image> "a"

In the second sample, the only correct initial string is "eb" because it can be immediately compressed to "a".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int inf_int = 2e9;
long long inf_ll = 2e18;
const double pi = 3.1415926535898;
template <typename T, typename T1>
void prin(vector<pair<T, T1> >& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i].first << " " << a[i].second << "\n";
  }
}
template <typename T>
void prin(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i];
    if (i < a.size() - 1)
      cout << " ";
    else
      cout << "\n";
  }
}
template <typename T>
void prin(set<T>& a) {
  for (auto it = a.begin(); it != a.end(); it++) {
    cout << *it << " ";
  }
}
template <typename T>
void prin_new_line(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << "\n";
  }
}
template <typename T, typename T1>
void prin_new_line(vector<pair<T, T1> >& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i].first << " " << a[i].second << "\n";
  }
}
int sum_vec(vector<int>& a) {
  int s = 0;
  for (int i = 0; i < a.size(); i++) {
    s += a[i];
  }
  return s;
}
template <typename T>
T max(vector<T>& a) {
  T ans = a[0];
  for (int i = 1; i < a.size(); i++) {
    ans = max(ans, a[i]);
  }
  return ans;
}
template <typename T>
T min(vector<T>& a) {
  T ans = a[0];
  for (int i = 1; i < a.size(); i++) {
    ans = min(ans, a[i]);
  }
  return ans;
}
template <typename T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <typename T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
double s_triangle(double x1, double y1, double x2, double y2, double x3,
                  double y3) {
  return abs(((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2);
}
bool overflow(long long a, long long b) {
  if (a * b / b != a) return true;
  return false;
}
bool debug = 0;
const int maxn = 1e5 + 7;
vector<string> let[26];
map<string, int> mp;
int n;
long long ans = 0;
void dfs(string a) {
  if (mp.find(a) != mp.end()) {
    return;
  }
  if (a.size() == n) {
    if (mp[a] != 1) ans++;
    mp[a] = 1;
    return;
  }
  mp[a] = 1;
  int x = a[0] - 'a';
  int res = 0;
  for (int i = 0; i < let[x].size(); i++) {
    string c = let[x][i];
    for (int e = 1; e < a.size(); e++) {
      c.push_back(a[e]);
    }
    dfs(c);
  }
}
void solve() {
  int q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    string a;
    cin >> a;
    char t;
    cin >> t;
    let[t - 'a'].push_back(a);
  }
  dfs("a");
  cout << ans;
}
int main() {
  if (!debug) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  int t = 1;
  while (t--) solve();
  return 0;
}

```


### Prompt

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

We have a grid with N rows and M columns of squares. Initially, all the squares are white.

There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted.

Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

Constraints

* 1 \leq N,M \leq 1000
* 0 \leq K \leq NM

Input

Input is given from Standard Input in the following format:

N M K

Output

If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`.

Examples

Input

2 2 2

Output

Yes

Input

2 2 1

Output

No

Input

3 5 8

Output

Yes

Input

7 9 20

Output

No

### Response

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

int main(){
	int N,K,M;
	cin >> N >> M >> K;

	for(int i=0;i<=N;i++){
		for(int j=0;j<=M;j++){
			if(j*N + i*M - i*j*2 == K){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

<image>

At the request of a friend who started learning abacus, you decided to create a program to display the abacus beads. Create a program that takes a certain number as input and outputs a row of abacus beads. However, the number of digits of the abacus to be displayed is 5 digits, and the arrangement of beads from 0 to 9 is as follows using'*' (half-width asterisk),''(half-width blank), and'=' (half-width equal). It shall be expressed as.

<image>

Input

Multiple test cases are given. Up to 5 digits (integer) are given on one line for each test case.

The number of test cases does not exceed 1024.

Output

Output the abacus bead arrangement for each test case. Insert a blank line between the test cases.

Example

Input

2006
1111

Output

****
    *
=====
 *  *
****
* ***
*****
*****

*****

=====
 ****
*
*****
*****
*****

### Response

```cpp
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	char s[5];
	string list[10];
	bool flag = true;

	list[0] = "* = ****";
	list[1] = "* =* ***";
	list[2] = "* =** **";
	list[3] = "* =*** *";
	list[4] = "* =**** ";
	list[5] = " *= ****";
	list[6] = " *=* ***";
	list[7] = " *=** **";
	list[8] = " *=*** *";
	list[9] = " *=**** ";

	while(scanf("%s", s) != EOF){
		if(!flag) puts("");
		string str = s;
		int len = str.size();
		string num;
		for(int i = 0; i < 5 - len; i++){
			num += "0";
		}
		num += str;

		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 5; j++){
				cout << list[num[j] - '0'][i];
			}
			puts("");
		}
		flag = false;
	}

	return(0);
}
```


### Prompt

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

To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.

The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following:

  * aij — the cost of buying an item;
  * bij — the cost of selling an item;
  * cij — the number of remaining items.

It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind.

Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get.

Input

The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 10, 1 ≤ m, k ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.

Then follow n blocks describing each planet.

The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≤ bij < aij ≤ 1000, 0 ≤ cij ≤ 100) — the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces.

It is guaranteed that the names of all planets are different.

Output

Print a single number — the maximum profit Qwerty can get.

Examples

Input

3 3 10
Venus
6 5 3
7 6 5
8 6 10
Earth
10 9 0
8 6 4
10 9 3
Mars
4 3 0
8 4 12
7 2 5

Output

16

Note

In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3·6 + 7·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3·9 + 7·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 10000002, INF = 1000 * 1000 * 1000;
const long double eps = 1e-9;
struct node {
  int a, b, c, idx;
  node(int aa, int bb, int cc, int i) {
    a = aa;
    c = cc;
    b = bb;
    idx = i;
  }
  node(){};
};
vector<vector<node>> p;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  p.resize(n);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    p[i].resize(m);
    for (int j = 0; j < m; ++j) {
      int a, b, c;
      cin >> a >> b >> c;
      p[i][j] = node(a, b, c, i);
    }
  }
  int ans = 0;
  for (int f = 0; f < n; ++f) {
    for (int s = 0; s < n; ++s) {
      vector<pair<int, int>> a(m);
      int tmp = 0;
      for (int i = 0; i < m; ++i) {
        a[i] = make_pair(p[s][i].b - p[f][i].a, i);
      }
      sort(a.begin(), a.end());
      reverse(a.begin(), a.end());
      int cnt = k;
      for (int i = 0; i < m; ++i) {
        if (a[i].first < 0) break;
        int kol = min(p[f][a[i].second].c, cnt);
        tmp += kol * a[i].first;
        cnt -= kol;
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size n × m, consisting of positive integers such that the sum of the squares of numbers for each row and each column was also a square.

Since checking the correctness of the table manually is difficult, Misha asks you to make each number in the table to not exceed 108.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the size of the table.

Output

Print the table that meets the condition: n lines containing m integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer.

Examples

Input

1 1

Output

1

Input

1 2

Output

3 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int power(int a, int b, int c = mod) {
  int ans = 1;
  for (; b; b >>= 1, a = (LL)a * a % c) {
    if (b & 1) ans = (LL)ans * a % c;
  }
  return ans;
}
int a[111][111];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n == 1) {
    if (m == 2) {
      puts("3 4");
      return 0;
    }
    if (m == 1) {
      puts("1");
      return 0;
    }
    if (m % 2)
      a[1][m - 1] = 2;
    else
      a[1][m - 1] = 1;
    for (int i = 1; i < m - 1; i++) a[1][i] = 1;
    int s = m - 1;
    if (s % 2 == 0) s += 3;
    s /= 2;
    a[1][m] = s;
    for (int i = 1; i <= m; i++) cout << a[1][i] << ' ';
    return 0;
  }
  if (n == 2) {
    if (m == 2) {
      puts("3 4");
      puts("4 3");
      return 0;
    }
    if (m == 1) {
      puts("3\n4");
      return 0;
    }
    if (m % 2)
      a[1][m - 1] = 2;
    else
      a[1][m - 1] = 1;
    for (int i = 1; i < m - 1; i++) a[1][i] = 1;
    int s = m - 1;
    if (s % 2 == 0) s += 3;
    s /= 2;
    a[1][m] = s;
    for (int i = 1; i <= m; i++) cout << a[1][i] * 3 << ' ';
    cout << endl;
    for (int i = 1; i <= m; i++) cout << a[1][i] * 4 << ' ';
    return 0;
  }
  if (m == 2) {
    if (n % 2)
      a[n - 1][1] = 2;
    else
      a[n - 1][1] = 1;
    for (int i = 1; i < n - 1; i++) a[i][1] = 1;
    int s = n - 1;
    if (s % 2 == 0) s += 3;
    s /= 2;
    a[n][1] = s;
    for (int i = 1; i <= n; i++)
      cout << a[i][1] * 3 << ' ' << a[i][1] * 4 << endl;
    return 0;
  }
  if (n % 2)
    a[n - 1][1] = 2;
  else
    a[n - 1][1] = 1;
  for (int i = 1; i < n - 1; i++) a[i][1] = 1;
  int s = n - 1;
  if (s % 2 == 0) s += 3;
  s /= 2;
  a[n][1] = s;
  if (m == 1) {
    for (int i = 1; i <= n; i++) cout << a[i][1] << endl;
    return 0;
  }
  if (m % 2)
    a[1][m - 1] = 2;
  else
    a[1][m - 1] = 1;
  for (int i = 1; i < m - 1; i++) a[1][i] = 1;
  s = m - 1;
  if (s % 2 == 0) s += 3;
  s /= 2;
  a[1][m] = s;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%d ", a[i][1] * a[1][j]);
    puts("");
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building.

Submitted designs will look like a screenshot of a well known game as shown below.

<image>

This is because the center specifies that the building should be constructed by stacking regular units called pieces, each of which consists of four cubic blocks. In addition, the center requires the competitors to submit designs that satisfy the following restrictions.

* All the pieces are aligned. When two pieces touch each other, the faces of the touching blocks must be placed exactly at the same position.
* All the pieces are stable. Since pieces are merely stacked, their centers of masses must be carefully positioned so as not to collapse.
* The pieces are stacked in a tree-like form in order to symbolize boundless potentiality of young artists. In other words, one and only one piece touches the ground, and each of other pieces touches one and only one piece on its bottom faces.
* The building has a flat shape. This is because the construction site is a narrow area located between a straight moat and an expressway where no more than one block can be placed between the moat and the expressway as illustrated below.

<image>

It will take many days to fully check stability of designs as it requires complicated structural calculation. Therefore, you are asked to quickly check obviously unstable designs by focusing on centers of masses. The rules of your quick check are as follows.

Assume the center of mass of a block is located at the center of the block, and all blocks have the same weight. We denote a location of a block by xy-coordinates of its left-bottom corner. The unit length is the edge length of a block.

Among the blocks of the piece that touch another piece or the ground on their bottom faces, let xL be the leftmost x-coordinate of the leftmost block, and let xR be the rightmost x-coordinate of the rightmost block. Let the x-coordinate of its accumulated center of mass of the piece be M, where the accumulated center of mass of a piece P is the center of the mass of the pieces that are directly and indirectly supported by P, in addition to P itself. Then the piece is stable, if and only if xL < M < xR. Otherwise, it is unstable. A design of a building is unstable if any of its pieces is unstable.

Note that the above rules could judge some designs to be unstable even if it would not collapse in reality. For example, the left one of the following designs shall be judged to be unstable.

<image> |  | <image>
---|---|---

Also note that the rules judge boundary cases to be unstable. For example, the top piece in the above right design has its center of mass exactly above the right end of the bottom piece. This shall be judged to be unstable.

Write a program that judges stability of each design based on the above quick check rules.

Input

The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset, which represents a front view of a building, is formatted as follows.

> w h
>  p0(h-1)p1(h-1)...p(w-1)(h-1)
>  ...
>  p01p11...p(w-1)1
>  p00p10...p(w-1)0
>

The integers w and h separated by a space are the numbers of columns and rows of the layout, respectively. You may assume 1 ≤ w ≤ 10 and 1 ≤ h ≤ 60. The next h lines specify the placement of the pieces. The character pxy indicates the status of a block at (x,y), either ``.`', meaning empty, or one digit character between ``1`' and ``9`', inclusive, meaning a block of a piece. (As mentioned earlier, we denote a location of a block by xy-coordinates of its left-bottom corner.)

When two blocks with the same number touch each other by any of their top, bottom, left or right face, those blocks are of the same piece. (Note that there might be two different pieces that are denoted by the same number.) The bottom of a block at (x,0) touches the ground.

You may assume that the pieces in each dataset are stacked in a tree-like form.

Output

For each dataset, output a line containing a word `STABLE` when the design is stable with respect to the above quick check rules. Otherwise, output `UNSTABLE`. The output should be written with uppercase letters, and should not contain any other extra characters.

Sample Input

4 5
..33
..33
2222
..1.
.111
5 7
....1
.1..1
.1..1
11..1
.2222
..111
...1.
3 6
.3.
233
23.
22.
.11
.11
4 3
2222
..11
..11
4 5
.3..
33..
322.
2211
.11.
3 3
222
2.1
111
3 4
11.
11.
.2.
222
3 4
.11
.11
.2.
222
2 7
11
.1
21
22
23
.3
33
2 3
1.
11
.1
0 0

Output for the Sample Input

STABLE
STABLE
STABLE
UNSTABLE
STABLE
STABLE
UNSTABLE
UNSTABLE
UNSTABLE
UNSTABLE

Example

Input

4 5
..33
..33
2222
..1.
.111
5 7
....1
.1..1
.1..1
11..1
.2222
..111
...1.
3 6
.3.
233
23.
22.
.11
.11
4 3
2222
..11
..11
4 5
.3..
33..
322.
2211
.11.
3 3
222
2.1
111
3 4
11.
11.
.2.
222
3 4
.11
.11
.2.
222
2 7
11
.1
21
22
23
.3
33
2 3
1.
11
.1
0 0

Output

STABLE
STABLE
STABLE
UNSTABLE
STABLE
STABLE
UNSTABLE
UNSTABLE
UNSTABLE
UNSTABLE

### Response

```cpp
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)
const double eps = 1e-8;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

template<typename T> inline void chmax(T& t, T f){if(t < f)t = f;}
template<typename T> inline void chmin(T& t, T f){if(t > f)t = f;}

int h, w;
vector<string> bldg;
vector<vector<bool> > vis;

inline bool inrect(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

pair<double, int> dfs(int sx, int sy){
    vis[sx][sy] = true;
    vector<double> ys;
    vector<pair<int, int> > on;
    int ly = w, ry = 0;
    queue<pair<int, int> > q;
    for(q.emplace(sx, sy); !q.empty();){
        int x = q.front().first, y = q.front().second; q.pop();
        ys.emplace_back(y + .5);
        if(x && !vis[x-1][y] && bldg[x-1][y] != '.' && bldg[x-1][y] != bldg[sx][sy]){
            on.emplace_back(x-1, y);
        }
        if(x == h-1 || (bldg[x+1][y] != '.' && bldg[x+1][y] != bldg[sx][sy])){
            chmin(ly, y); chmax(ry, y+1);
        }
        rep(i, 4){
            int nx = x + dx[i], ny = y + dy[i];
            if(!inrect(nx, ny) || vis[nx][ny] || bldg[nx][ny] != bldg[sx][sy])continue;
            vis[nx][ny] = true;
            q.emplace(nx, ny);
        }
    }
    double M = accumulate(all(ys), 0.);
    int n = (int)ys.size();
    for(auto p: on)if(!vis[p.first][p.second]){
        pair<double, int> t = dfs(p.first, p.second);
        if(t.second == -1)return mp(M, -1);
        M += t.first; n += t.second;
    }
    return ly < M/n - eps && M/n + eps < ry? mp(M, n): mp(M, -1);
}

const char* solve(){
    vis.assign(h, vector<bool>(w, false));
    int y = find_if_not(all(bldg[h-1]), [](const char& c){return c == '.';}) - bldg[h-1].begin();
    return dfs(h-1, y).second != -1? "STABLE": "UNSTABLE";
}

int main(){
    while(cin >> w >> h, w|h){
        bldg.assign(h, "");
        rep(i, h)cin >> bldg[i];
        cout << solve() << '\n';
    }
    return 0;
}
```


### Prompt

Please formulate a CPP solution to the following problem:

Alfred wants to buy a toy moose that costs c dollars. The store doesn’t give change, so he must give the store exactly c dollars, no more and no less. He has n coins. To make c dollars from his coins, he follows the following algorithm: let S be the set of coins being used. S is initially empty. Alfred repeatedly adds to S the highest-valued coin he has such that the total value of the coins in S after adding the coin doesn’t exceed c. If there is no such coin, and the value of the coins in S is still less than c, he gives up and goes home. Note that Alfred never removes a coin from S after adding it.

As a programmer, you might be aware that Alfred’s algorithm can fail even when there is a set of coins with value exactly c. For example, if Alfred has one coin worth $3, one coin worth $4, and two coins worth $5, and the moose costs $12, then Alfred will add both of the $5 coins to S and then give up, since adding any other coin would cause the value of the coins in S to exceed $12. Of course, Alfred could instead combine one $3 coin, one $4 coin, and one $5 coin to reach the total.

Bob tried to convince Alfred that his algorithm was flawed, but Alfred didn’t believe him. Now Bob wants to give Alfred some coins (in addition to those that Alfred already has) such that Alfred’s algorithm fails. Bob can give Alfred any number of coins of any denomination (subject to the constraint that each coin must be worth a positive integer number of dollars). There can be multiple coins of a single denomination. He would like to minimize the total value of the coins he gives Alfred. Please find this minimum value. If there is no solution, print "Greed is good". You can assume that the answer, if it exists, is positive. In other words, Alfred's algorithm will work if Bob doesn't give him any coins.

Input

The first line contains c (1 ≤ c ≤ 200 000) — the price Alfred wants to pay. The second line contains n (1 ≤ n ≤ 200 000) — the number of coins Alfred initially has. Then n lines follow, each containing a single integer x (1 ≤ x ≤ c) representing the value of one of Alfred's coins.

Output

If there is a solution, print the minimum possible total value of the coins in a solution. Otherwise, print "Greed is good" (without quotes).

Examples

Input

12
3
5
3
4

Output

5

Input

50
8
1
2
4
8
16
37
37
37

Output

Greed is good

Note

In the first sample, Bob should give Alfred a single coin worth $5. This creates the situation described in the problem statement.

In the second sample, there is no set of coins that will cause Alfred's algorithm to fail.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native")
using namespace std;
namespace output {
void __(short x) { cout << x; }
void __(unsigned x) { cout << x; }
void __(int x) { cout << x; }
void __(long long x) { cout << x; }
void __(unsigned long long x) { cout << x; }
void __(double x) { cout << x; }
void __(long double x) { cout << x; }
void __(char x) { cout << x; }
void __(const char* x) { cout << x; }
void __(const string& x) { cout << x; }
void __(bool x) { cout << (x ? "true" : "false"); }
template <class S, class T>
void __(const pair<S, T>& x) {
  __(1 ? "(" : ""), __(x.first), __(1 ? ", " : " "), __(x.second),
      __(1 ? ")" : "");
}
template <class T>
void __(const vector<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class T>
void __(const set<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class T>
void __(const multiset<T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
template <class S, class T>
void __(const map<S, T>& x) {
  __(1 ? "{" : "");
  bool _ = 0;
  for (const auto& v : x) __(_ ? 1 ? ", " : " " : ""), __(v), _ = 1;
  __(1 ? "}" : "");
}
void pr() { cout << "\n"; }
template <class S, class... T>
void pr(const S& a, const T&... b) {
  __(a);
  if (sizeof...(b)) __(' ');
  pr(b...);
}
}  // namespace output
using namespace output;
const int MN = 2e5 + 5;
int N, C, T, i, j, arr[MN], cnt[MN], nxt[MN], ans;
map<int, int> pos;
bool solve(int n, int lim) {
  if (!n) return 1;
  auto it = pos.upper_bound(min(n, lim));
  if (it == pos.begin()) return 0;
  it--;
  int c = it->first;
  int r = min(cnt[c], n / c);
  return solve(n - r * c, c - 1);
}
int main() {
  scanf("%d%d", &C, &N);
  for (i = 1; i <= N; i++) {
    scanf("%d", &arr[i]);
    cnt[arr[i]]++;
    pos[arr[i]]++;
  }
  for (i = 1; i <= C; i++) {
    pos[i]++;
    cnt[i]++;
    if (!solve(C, C)) {
      printf("%d\n", i);
      return 0;
    }
    pos[i]--;
    cnt[i]--;
    if (!pos[i]) pos.erase(i);
  }
  printf("Greed is good\n");
  return 0;
}

```