### Prompt

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

This is the easy version of the problem. The only difference is that in this version q=1. You can make hacks only if all versions of the problem are solved.

Zookeeper has been teaching his q sheep how to write and how to add. The i-th sheep has to write exactly k non-negative integers with the sum n_i.

Strangely, sheep have superstitions about digits and believe that the digits 3, 6, and 9 are lucky. To them, the fortune of a number depends on the decimal representation of the number; the fortune of a number is equal to the sum of fortunes of its digits, and the fortune of a digit depends on its value and position and can be described by the following table. For example, the number 319 has fortune F_{2} + 3F_{0}.

<image>

Each sheep wants to maximize the sum of fortune among all its k written integers. Can you help them?

Input

The first line contains a single integer k (1 ≤ k ≤ 999999): the number of numbers each sheep has to write.

The next line contains six integers F_0, F_1, F_2, F_3, F_4, F_5 (1 ≤ F_i ≤ 10^9): the fortune assigned to each digit.

The next line contains a single integer q (q = 1): the number of sheep.

Each of the next q lines contains a single integer n_i (1 ≤ n_i ≤ 999999): the sum of numbers that i-th sheep has to write. In this version, there is only one line.

Output

Print q lines, where the i-th line contains the maximum sum of fortune of all numbers of the i-th sheep. In this version, you should print only one line.

Examples

Input

3
1 2 3 4 5 6
1
57

Output

11

Input

3
1 2 3 4 5 6
1
63

Output

8

Note

In the first test case, 57 = 9 + 9 + 39. The three 9's contribute 1 ⋅ 3 and 3 at the tens position contributes 2 ⋅ 1. Hence the sum of fortune is 11.

In the second test case, 63 = 35 + 19 + 9. The sum of fortune is 8.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
constexpr int inf32 = 0x3f3f3f3f;
constexpr long long inf64 = 0x3f3f3f3f3f3f3f3f;
constexpr int W = 6;
constexpr int N = 1000000;
int main() {
  int k;
  cin >> k;
  vector<long long> a(W);
  for (int w = 0; w < (W); ++w) cin >> a[w];
  vector<long long> f(N);
  for (int i = 0; i < (N); ++i) {
    int first = i;
    for (int w = 0; w < (W); ++w) {
      if ((first % 10) % 3 == 0) f[i] += a[w] * ((first % 10) / 3);
      first /= 10;
    }
  }
  vector<int> pro;
  int first = 1, m = (k - 1) * 3;
  while (first < m) {
    pro.push_back(first);
    m -= first, first *= 2;
  }
  if (m) pro.push_back(m);
  int now = 3;
  for (int w = 0; w < (W); ++w) {
    for (const int &p : pro) {
      if (1ll * p * now >= N) continue;
      for (int i = (N - p * now) - 1; i >= 0; --i)
        f[i + p * now] = max(f[i + p * now], f[i] + a[w] * p);
    }
    now *= 10;
  }
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    cout << f[n] << '\n';
  }
  return 0;
}

```


### Prompt

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

Write a program which reads two integers a and b, and calculates the following values:

* a ÷ b: d (in integer)
* remainder of a ÷ b: r (in integer)
* a ÷ b: f (in real number)

Constraints

* 1 ≤ a, b ≤ 109

Input

Two integers a and b are given in a line.

Output

Print d, r and f separated by a space in a line. For f, the output should not contain an absolute error greater than 10-5.

Example

Input

3 2

Output

1 1 1.50000

### Response

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

int main(){
    int a,b;
    cin >> a >>b;
    printf("%d %d %f",a/b,a%b,(double)a/b);

    return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Today, Yasser and Adel are at the shop buying cupcakes. There are n cupcake types, arranged from 1 to n on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type i is an integer a_i. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.

Yasser, of course, wants to try them all, so he will buy exactly one cupcake of each type.

On the other hand, Adel will choose some segment [l, r] (1 ≤ l ≤ r ≤ n) that does not include all of cupcakes (he can't choose [l, r] = [1, n]) and buy exactly one cupcake of each of types l, l + 1, ..., r.

After that they will compare the total tastiness of the cupcakes each of them have bought. Yasser will be happy if the total tastiness of cupcakes he buys is strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice.

For example, let the tastinesses of the cupcakes be [7, 4, -1]. Yasser will buy all of them, the total tastiness will be 7 + 4 - 1 = 10. Adel can choose segments [7], [4], [-1], [7, 4] or [4, -1], their total tastinesses are 7, 4, -1, 11 and 3, respectively. Adel can choose segment with tastiness 11, and as 10 is not strictly greater than 11, Yasser won't be happy :(

Find out if Yasser will be happy after visiting the shop.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The description of the test cases follows.

The first line of each test case contains n (2 ≤ n ≤ 10^5).

The second line of each test case contains n integers a_1, a_2, ..., a_n (-10^9 ≤ a_i ≤ 10^9), where a_i represents the tastiness of the i-th type of cupcake.

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

Output

For each test case, print "YES", if the total tastiness of cupcakes Yasser buys will always be strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice. Otherwise, print "NO".

Example

Input

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

Output

YES
NO
NO

Note

In the first example, the total tastiness of any segment Adel can choose is less than the total tastiness of all cupcakes.

In the second example, Adel will choose the segment [1, 2] with total tastiness 11, which is not less than the total tastiness of all cupcakes, which is 10.

In the third example, Adel can choose the segment [3, 3] with total tastiness of 5. Note that Yasser's cupcakes' total tastiness is also 5, so in that case, the total tastiness of Yasser's cupcakes isn't strictly greater than the total tastiness of Adel's cupcakes.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  int a = 0, b = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') b = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    a = (a << 3) + (a << 1) + c - '0';
    c = getchar();
  }
  return a * b;
}
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;
int a[N];
long long sum[N];
int main() {
  int T = read();
  while (T--) {
    memset(sum, 0, sizeof(sum));
    int n = read();
    for (register int i = (1); i <= (n); i++)
      a[i] = read(), sum[i] = sum[i - 1] + a[i];
    int flag = 0;
    for (register int i = (1); i <= (n - 1); i++) {
      if (sum[i] <= 0) flag = 1;
      if (sum[n] - sum[i] <= 0) flag = 1;
    }
    if (flag)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}

```


### Prompt

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

You are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image. You want to choose an integer k > 1 and split the image into k by k blocks. If n and m are not divisible by k, the image is padded with only zeros on the right and bottom so that they are divisible by k. Each pixel in each individual block must have the same value. The given image may not be compressible in its current state. Find the minimum number of pixels you need to toggle (after padding) in order for the image to be compressible for some k. More specifically, the steps are to first choose k, then the image is padded with zeros, then, we can toggle the pixels so it is compressible for this k. The image must be compressible in that state.

Input

The first line of input will contain two integers n, m (2 ≤ n, m ≤ 2 500), the dimensions of the image.

The next n lines of input will contain a binary string with exactly m characters, representing the image.

Output

Print a single integer, the minimum number of pixels needed to toggle to make the image compressible.

Example

Input

3 5
00100
10110
11001

Output

5

Note

We first choose k = 2.

The image is padded as follows:

    001000
    101100
    110010
    000000

We can toggle the image to look as follows:

    001100
    001100
    000000
    000000

We can see that this image is compressible for k = 2.

### Response

```cpp
#include <bits/stdc++.h>
int n, m;
char arr[2547][2547];
bool prime[50];
int check(int k) {
  int ans = 0;
  int loss = k * k;
  int tmp;
  for (int i = 0; i < n / k + 1; ++i) {
    for (int j = 0; j < m / k + 1; ++j) {
      tmp = 0;
      for (int s = 0; s < k; ++s) {
        for (int t = 0; t < k; ++t) {
          tmp += arr[s + i * k][t + j * k];
        }
      }
      if (tmp <= loss / 2) {
        ans += tmp;
      } else {
        ans += loss - tmp;
      }
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  int i, j, k;
  for (i = 0; i < n; ++i) {
    scanf("\n");
    for (int j = 0; j < m; ++j) {
      scanf("%c", &arr[i][j]);
      arr[i][j] -= '0';
    }
  }
  for (i = 2; i < 50; ++i) {
    if (prime[i] == false) {
      for (j = i * 2; j < 50; j += i) {
        prime[j] = true;
      }
    }
  }
  int min = n * m;
  int ans;
  if (m > n) {
    ans = m;
  } else {
    ans = n;
  }
  int tmp;
  for (k = 2; k < 50; ++k) {
    if (prime[k] == false) {
      tmp = check(k);
      if (min >= tmp) {
        min = tmp;
        ans = k;
      }
    }
  }
  printf("%d", min);
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You take part in the testing of new weapon. For the testing a polygon was created. The polygon is a rectangular field n × m in size, divided into unit squares 1 × 1 in size. The polygon contains k objects, each of which is a rectangle with sides, parallel to the polygon sides and entirely occupying several unit squares. The objects don't intersect and don't touch each other.

The principle according to which the weapon works is highly secret. You only know that one can use it to strike any rectangular area whose area is not equal to zero with sides, parallel to the sides of the polygon. The area must completely cover some of the unit squares into which the polygon is divided and it must not touch the other squares. Of course the area mustn't cross the polygon border. Your task is as follows: you should hit no less than one and no more than three rectangular objects. Each object must either lay completely inside the area (in that case it is considered to be hit), or lay completely outside the area.

Find the number of ways of hitting.

Input

The first line has three integers n, m и k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 90) — the sizes of the polygon and the number of objects on it respectively. Next n lines contain m symbols each and describe the polygon. The symbol "*" stands for a square occupied an object, whereas the symbol "." stands for an empty space. The symbols "*" form exactly k rectangular connected areas that meet the requirements of the task.

Output

Output a single number — the number of different ways to hit a target.

Examples

Input

3 3 3
*.*
...
*..

Output

21

Input

4 5 4
.*.**
...**
**...
...**

Output

38

Input

2 2 1
.*
..

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef struct _Object {
  int x1, y1, x2, y2;
} Object;
typedef struct _Line {
  int x;
  int belong;
  int kind;
} Line;
typedef struct _Segment {
  int left, right, nCoveredObject;
} Segment;
const int hang[4] = {-1, 0, 1, 0};
int cot[4] = {0, 1, 0, -1};
Object *List;
Object *savedList;
Line *ListLine, *savedListLine;
Segment *ListSegment, *savedListSegment;
int m, n, k, nListSegment;
long long res;
char **table;
void getInput() {
  scanf("%d%d%d\n", &m, &n, &k);
  table = new char *[m + 1];
  for (int i = 0; i <= m - 1; i++) {
    table[i] = new char[n + 1];
    gets(table[i]);
  }
}
void DFS(int i, int j) {
  table[i][j] = '.';
  List->x1 = min(List->x1, i);
  List->x2 = max(List->x2, i);
  List->y1 = min(List->y1, j);
  List->y2 = max(List->y2, j);
  for (int t = 0; t <= 3; t++) {
    int x = i + hang[t];
    int y = j + cot[t];
    if (0 <= x && x < m && 0 <= y && y < n)
      if (table[x][y] == '*') DFS(x, y);
  }
}
void buildList() {
  List = (Object *)malloc(sizeof(Object) * 100);
  ListLine = (Line *)malloc(sizeof(Line) * 100 * 2);
  savedList = List;
  savedListLine = ListLine;
  int count = 0;
  for (int i = 0; i <= m - 1; i++)
    for (int j = 0; j <= n - 1; j++)
      if (table[i][j] == '*') {
        List->x1 = 10000000;
        List->x2 = -10000000;
        List->y1 = 10000000;
        List->y2 = -10000000;
        DFS(i, j);
        ListLine->belong = count;
        ListLine->kind = 0;
        ListLine->x = List->y1;
        ++ListLine;
        ListLine->belong = count;
        ListLine->kind = 1;
        ListLine->x = List->y2;
        ++count;
        ++ListLine;
        ++List;
      }
  ListLine = savedListLine;
  List = savedList;
}
int cmp(Line a, Line b) {
  return (a.x < b.x || (a.x == b.x && a.kind < b.kind));
}
void sortListLine() { sort(ListLine, ListLine + 2 * k, cmp); }
int cutStrip(Line a, int up, int down) {
  return (!(List[a.belong].x2 < up || List[a.belong].x1 > down));
}
int belongToStrip(Line a, int up, int down) {
  return ((List[a.belong].x1 >= up) && (List[a.belong].x2 <= down));
}
long long pre(int j) {
  if (j == 0)
    return ((long long)(ListSegment[j].left + 1));
  else
    return ((long long)(ListSegment[j].left - ListSegment[j - 1].right));
}
long long next(int i) {
  if (i == nListSegment - 1)
    return ((long long)(n - 1 - ListSegment[i].right + 1));
  else
    return ((long long)(ListSegment[i + 1].left - ListSegment[i].right));
}
void Solve(int up, int down) {
  int nTempObject;
  for (int i = 0; i <= nListSegment - 1; i++) {
    nTempObject = 0;
    for (int j = i; j >= max(0, i - 2); j--) {
      nTempObject += ListSegment[j].nCoveredObject;
      if (nTempObject > 3) break;
      res += pre(j) * next(i);
    }
  };
}
void solve(int up, int down) {
  int nCurrentObject = 0;
  nListSegment = 0;
  ListSegment[nListSegment].nCoveredObject = 0;
  for (int i = 0; i <= 2 * k - 1; i++)
    if (cutStrip(ListLine[i], up, down)) {
      if (ListLine[i].kind == 0) {
        if (nCurrentObject == 0) {
          ListSegment[nListSegment].left = ListLine[i].x;
        }
        ++nCurrentObject;
        if (belongToStrip(ListLine[i], up, down))
          ListSegment[nListSegment].nCoveredObject++;
        else
          ListSegment[nListSegment].nCoveredObject += 10000000;
      } else {
        --nCurrentObject;
        if (nCurrentObject == 0) {
          ListSegment[nListSegment].right = ListLine[i].x;
          nListSegment++;
          ListSegment[nListSegment].nCoveredObject = 0;
        }
      }
    }
  Solve(up, down);
}
int main() {
  getInput();
  buildList();
  sortListLine();
  res = 0;
  ListSegment = (Segment *)malloc(sizeof(Segment) * 100);
  savedListSegment = ListSegment;
  for (int i = 0; i <= m - 1; i++)
    for (int j = i; j <= m - 1; j++) {
      solve(i, j);
    }
  printf("%I64d", res);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array a with indices from [l, r) can be implemented as follows:

  1. If the segment [l, r) is already sorted in non-descending order (that is, for any i such that l ≤ i < r - 1 a[i] ≤ a[i + 1]), then end the function call;
  2. Let <image>;
  3. Call mergesort(a, l, mid);
  4. Call mergesort(a, mid, r);
  5. Merge segments [l, mid) and [mid, r), making the segment [l, r) sorted in non-descending order. The merge algorithm doesn't call any other functions.

The array in this problem is 0-indexed, so to sort the whole array, you need to call mergesort(a, 0, n).

The number of calls of function mergesort is very important, so Ivan has decided to calculate it while sorting the array. For example, if a = {1, 2, 3, 4}, then there will be 1 call of mergesort — mergesort(0, 4), which will check that the array is sorted and then end. If a = {2, 1, 3}, then the number of calls is 3: first of all, you call mergesort(0, 3), which then sets mid = 1 and calls mergesort(0, 1) and mergesort(1, 3), which do not perform any recursive calls because segments (0, 1) and (1, 3) are sorted.

Ivan has implemented the program that counts the number of mergesort calls, but now he needs to test it. To do this, he needs to find an array a such that a is a permutation of size n (that is, the number of elements in a is n, and every integer number from [1, n] can be found in this array), and the number of mergesort calls when sorting the array is exactly k.

Help Ivan to find an array he wants!

Input

The first line contains two numbers n and k (1 ≤ n ≤ 100000, 1 ≤ k ≤ 200000) — the size of a desired permutation and the number of mergesort calls required to sort it.

Output

If a permutation of size n such that there will be exactly k calls of mergesort while sorting it doesn't exist, output  - 1. Otherwise output n integer numbers a[0], a[1], ..., a[n - 1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print any of them.

Examples

Input

3 3

Output

2 1 3

Input

4 1

Output

1 2 3 4

Input

5 6

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
constexpr int sz = 100005;
int n, k;
void solve(const int& l, const int& r, vector<int>& v, int& k) {
  if (k == 0) return;
  if (r > l + 1) {
    swap(v[(l + r) / 2 - 1], v[(l + r) / 2]);
    k -= 2;
    solve(l, (l + r) / 2, v, k);
    solve((l + r) / 2, r, v, k);
  }
}
int main() {
  cin >> n >> k;
  vector<int> v(n);
  if (!(k & 1)) cout << -1, exit(0);
  for (int i = 0; i < n; ++i) {
    v[i] = i + 1;
  }
  k--;
  solve(0, n, v, k);
  if (k == 0)
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
  else
    cout << -1;
}

```


### Prompt

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

Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.

The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).

Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.

Input

First string contains two integer numbers r and d (0 ≤ d < r ≤ 500) — the radius of pizza and the width of crust.

Next line contains one integer number n — the number of pieces of sausage (1 ≤ n ≤ 105).

Each of next n lines contains three integer numbers xi, yi and ri ( - 500 ≤ xi, yi ≤ 500, 0 ≤ ri ≤ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri — radius of i-th peace of sausage.

Output

Output the number of pieces of sausage that lay on the crust.

Examples

Input

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

Output

2

Input

10 8
4
0 0 9
0 0 10
1 0 1
1 0 2

Output

0

Note

Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
std::vector<long long> v;
long long x = 0, y = 0;
int main() {
  float r, d;
  long long ans = 0;
  cin >> r >> d;
  long long n;
  cin >> n;
  while (n--) {
    float x, y, k;
    cin >> x >> y >> k;
    if (k * 2 <= d) {
      float l = sqrt((x * x) + (y * y));
      if (l <= r && l >= (r - d)) {
        if (l + k <= r && l - k >= r - d) {
          ans++;
        }
      }
    }
  }
  cout << ans << "\n";
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions:

* A_i \neq B_i, for every i such that 1\leq i\leq N.
* A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N.

Since the count can be enormous, print it modulo (10^9+7).

Constraints

* 1\leq N \leq M \leq 5\times10^5
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the count modulo (10^9+7).

Examples

Input

2 2

Output

2

Input

2 3

Output

18

Input

141421 356237

Output

881613484

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
ll F[500005];
ll I[500005];
ll exp(ll a, ll x){
    if (x == 0) return 1ll;
    ll p = exp(a,x/2);
    p = (p*p)%mod;
    if (x&1) p = (p*a)%mod;
    return p;
}
ll P(int n, int k){
    return (F[n]*I[n-k])%mod;
}
ll C(int n, int k){
    return (((F[n]*I[k])%mod)*I[n-k])%mod;
}
ll ans = 0;
int n,m;
int main(){
    scanf("%d%d",&n,&m);
    F[0] = I[0] = 1;
    for (int i = 1; i <= 500000; i++){
        F[i] = (F[i-1]*i)%mod;
        I[i] = exp(F[i],mod-2);
    }
    for (int i = 0; i <= n; i++){
        ll EX = (P(n,i)*C(m,i))%mod;
        ll TR = P(m-i,n-i);
        TR = (TR*TR)%mod;
        //printf("%lld %lld\n",EX,TR);
        if (i & 1) ans -= (EX*TR)%mod;
        else ans += (EX*TR)%mod;
        ans %= mod;
    }
    ans = (ans+mod)%mod;
    printf("%lld",ans);

}

```


### Prompt

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

There are N people, conveniently numbered 1 through N. We want to divide them into some number of groups, under the following two conditions:

* Every group contains between A and B people, inclusive.

* Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds.

Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 10^9+7.

Constraints

* 1≤N≤10^3
* 1≤A≤B≤N
* 1≤C≤D≤N

Input

The input is given from Standard Input in the following format:

N A B C D

Output

Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7.

Examples

Input

3 1 3 1 2

Output

4

Input

7 2 3 1 3

Output

105

Input

1000 1 1000 1 1000

Output

465231251

Input

10 3 4 2 5

Output

0

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const int N(1111);
int dp[N], fac[N], inv[N], invFac[N][N];
int modulo(1e9 + 7);
int main() {
	fac[0] = 1;
	invFac[0][1] = 1;
	for(int i(1); i <= 1000; i++) {
		fac[i] = (long long)i * fac[i - 1] % modulo;
		inv[i] = i == 1 ? 1 : inv[i - modulo % i] * (long long)((modulo + i - 1) / i) % modulo;
		invFac[i][1] = (long long)invFac[i - 1][1] * inv[i] % modulo;
		//cout << i << endl;
		for(int j(2); j <= 1000; j++) {
			invFac[i][j] = (long long)invFac[i][j - 1] * invFac[i][1] % modulo;
		}
	}
//	cout << fac[2] << ' ' << invFac[2][1] << endl;
	int n, a, b, c, d;
	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	dp[n] = 1;
	for(int i(a); i <= b; i++) {
		for(int j(0); j <= n; j++) {
			for(int k(max(1, c)); k <= min(d, j / i); k++) {
				dp[j - k * i] = (dp[j - k * i] + (long long)dp[j] * fac[j] % modulo * invFac[i][k] % modulo * invFac[j - k * i][1] % modulo * invFac[k][1]) % modulo;
			}
		}
		//cout << dp[0] << ' ' << dp[3] << endl;
	}
	cout << dp[0] << endl;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.

Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.

There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.

Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.

Input

N K T U V L
D1
...
DN

N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).

1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.

Output

Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.

Examples

Input

1 1 1 2 3 100
50

Output

49.500000000

Input

3 1 1 2 3 100
49
50
51

Output

48.666666667

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(){
    int n,k,t,u,v,l,tmp;
    bool car[10002];
    cin >> n >> k >> t >> u >> v >> l;

    memset(car,false,sizeof(car));

    for(int i=0;i<n;i++){
        cin >> tmp;
        car[tmp] = true;
    }

    int stock = 0,fast = 0, slow = 0, rem = 0;
    for(int i=0;i<l;i++){
        if(rem == 0 && stock > 0){
            rem = v*t;
            stock--;
        }
        if(car[i]){
            if(rem == 0){
                rem = v*t;
            }else{
                if(stock == k){
                    rem = v*t;
                }else{
                    stock++;
                }
            }
        }
        if(rem > 0){
            fast++;
            rem--;
        }else{
            slow++;
        }
    }
    printf("%.10f\n", (double)fast/v + (double)slow/u);
}
```


### Prompt

Please create a solution in Cpp to the following problem:

We all know the problem about the number of ways one can tile a 2 × n field by 1 × 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes.

You are given a 4 × n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 × 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 × 1 as well as 1 × 2 dominoes.

Write a program that finds an arbitrary sought tiling.

Input

The input contains one positive integer n (1 ≤ n ≤ 100) — the number of the field's columns.

Output

If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each — that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling.

Examples

Input

4

Output

yyzz
bccd
bxxd
yyaa

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  scanf("%d", &n);
  if (n % 2 == 0) {
    for (int i = 1; i <= n; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("a");
      else
        printf("b");
    }
    puts("");
    printf("e");
    for (int i = 1; i <= n - 2; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("c");
      else
        printf("d");
    }
    printf("f");
    puts("");
    printf("e");
    for (int i = 1; i <= n - 2; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("d");
      else
        printf("c");
    }
    printf("f");
    puts("");
    for (int i = 1; i <= n; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("a");
      else
        printf("b");
    }
  } else {
    for (int i = 1; i <= n - 1; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("a");
      else
        printf("b");
    }
    printf("e");
    puts("");
    for (int i = 1; i <= n - 1; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("b");
      else
        printf("a");
    }
    printf("e");
    puts("");
    printf("f");
    for (int i = 1; i <= n - 1; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("c");
      else
        printf("d");
    }
    puts("");
    printf("f");
    for (int i = 1; i <= n - 1; ++i) {
      if (i % 4 == 1 || i % 4 == 2)
        printf("d");
      else
        printf("c");
    }
  }
  return 0;
}

```


### Prompt

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

You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle).

Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square.

Input

The first line contains a single integer n (1 ≤ n ≤ 5). Next n lines contain four integers each, describing a single rectangle: x1, y1, x2, y2 (0 ≤ x1 < x2 ≤ 31400, 0 ≤ y1 < y2 ≤ 31400) — x1 and x2 are x-coordinates of the left and right edges of the rectangle, and y1 and y2 are y-coordinates of the bottom and top edges of the rectangle.

No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle).

Output

In a single line print "YES", if the given rectangles form a square, or "NO" otherwise.

Examples

Input

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

Output

YES

Input

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

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void makemin(T &res, const U &x) {
  if (x < res) {
    res = x;
  }
}
template <typename T, typename U>
inline void makemax(T &res, const U &x) {
  if (x > res) {
    res = x;
  }
}
struct Point {
  int x, y;
};
struct Rect {
  int x1, y1, x2, y2;
};
bool inside(const Rect &r, const Point &p) {
  return p.x >= r.x1 && p.x <= r.x2 && p.y >= r.y1 && p.y <= r.y2;
}
bool solve() {
  int n;
  cin >> n;
  vector<Rect> rect(n);
  vector<Point> qpts;
  for (int i = 0; i < n; ++i) {
    Rect &r = rect[i];
    cin >> r.x1 >> r.y1 >> r.x2 >> r.y2;
    r.x1 *= 2;
    r.y1 *= 2;
    r.x2 *= 2;
    r.y2 *= 2;
    for (int dx = -1; dx <= 1; ++dx) {
      for (int dy = -1; dy <= 1; ++dy) {
        qpts.push_back((Point){r.x1 + dx, r.y1 + dy});
        qpts.push_back((Point){r.x2 + dx, r.y2 + dy});
      }
    }
  }
  Rect bbox = rect[0];
  for (int i = 1; i < n; ++i) {
    const Rect &r = rect[i];
    makemin(bbox.x1, r.x1);
    makemax(bbox.x2, r.x2);
    makemin(bbox.y1, r.y1);
    makemax(bbox.y2, r.y2);
  }
  if (bbox.x2 - bbox.x1 != bbox.y2 - bbox.y1) {
    return false;
  }
  for (int i = 0; i < (int)qpts.size(); ++i) {
    const Point &q = qpts[i];
    if (inside(bbox, q)) {
      bool ok = false;
      for (int j = 0; j < n; ++j) {
        ok |= inside(rect[j], q);
      }
      if (!ok) {
        return false;
      }
    }
  }
  return true;
}
int main() {
  cin.sync_with_stdio(0);
  cout << (solve() ? "YES" : "NO") << '\n';
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1.

Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters.

Input

The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000).

Output

If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO".

Examples

Input

abc

Output

YES
abc

Input

abcd

Output

NO

Input

xxxyxxx

Output

YES
xxxxxxy

Note

In the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".

In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).

In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
const long long int N = 1005;
bool prime[N + 1];
long long int kk;
void sieve() {
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= N; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= N; i += p) prime[i] = false;
    }
  }
}
void solve() {
  string s;
  cin >> s;
  map<char, long long int> mp;
  for (auto i : s) mp[i]++;
  vector<char> ans(s.length(), '/');
  for (long long int i = 2; i * 2 <= s.length(); i++) {
    prime[i] = false;
  }
  for (long long int i = 1; i <= s.length(); i++) {
    if (prime[i] == false) kk++;
  }
  long long int k = -1;
  char ch;
  for (auto i : mp) {
    if (i.second > k) {
      k = i.second;
      ch = i.first;
    }
  }
  if (k < kk) {
    cout << "NO" << '\n';
    return;
  }
  for (long long int i = 1; i <= s.length(); i++) {
    if (!prime[i] && mp[ch] > 0) {
      ans[i - 1] = ch;
      mp[ch]--;
    }
  }
  cout << "YES" << '\n';
  k = 0;
  for (auto i : mp) {
    while (i.second > 0 && k < s.length()) {
      if (ans[k] == '/') {
        ans[k] = i.first;
        i.second--;
      }
      k++;
    }
  }
  for (auto i : ans) cout << i;
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  sieve();
  while (t--) {
    solve();
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc.

To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task.

Note that in this problem, it is considered that 00 = 1.

Input

The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point.

The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists.

Output

Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations.

A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞.

Examples

Input

3
1 1 1

Output

1.0 1.0 1.0

Input

3
2 0 0

Output

3.0 0.0 0.0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  long double a, b, c, s;
  cin >> s >> a >> b >> c;
  long double x, y, z;
  if (b == 0 && c == 0 && a == 0) {
    x = s;
  } else {
    x = (a * s * 1.0) / (1.0 * (a + b + c));
  }
  if (c == 0 && a == 0 && b == 0) {
    y = 0;
  } else {
    y = (b * s * 1.0) / (1.0 * (a + b + c));
  }
  if (b == 0 && c == 0 && a == 0) {
    z = 0;
  } else {
    z = (c * s * 1.0) / (1.0 * (c + b + a));
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(10) << x << ' ' << y << ' ' << z << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tests = 1;
  while (tests--) {
    solve();
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides.

Print the answer in degrees, but do not print units.

Constraints

* 3 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print an integer representing the sum of the interior angles of a regular polygon with N sides.

Examples

Input

3

Output

180

Input

100

Output

17640

### Response

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

int main() {
	int N;
	cin >> N;
	cout << 180 * (N - 2);
}
```


### Prompt

Develop a solution in CPP to the problem described below:

A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.

There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowed to place as many magnets as you like, even multiple in the same cell.

An operation is performed as follows. Choose a north magnet and a south magnet to activate. If they are in the same row or the same column and they occupy different cells, then the north magnet moves one unit closer to the south magnet. Otherwise, if they occupy the same cell or do not share a row or column, then nothing changes. Note that the south magnets are immovable.

Each cell of the grid is colored black or white. Let's consider ways to place magnets in the cells so that the following conditions are met.

  1. There is at least one south magnet in every row and every column.
  2. If a cell is colored black, then it is possible for a north magnet to occupy this cell after some sequence of operations from the initial placement.
  3. If a cell is colored white, then it is impossible for a north magnet to occupy this cell after some sequence of operations from the initial placement.

Determine if it is possible to place magnets such that these conditions are met. If it is possible, find the minimum number of north magnets required (there are no requirements on the number of south magnets).

Input

The first line contains two integers n and m (1≤ n,m≤ 1000) — the number of rows and the number of columns, respectively.

The next n lines describe the coloring. The i-th of these lines contains a string of length m, where the j-th character denotes the color of the cell in row i and column j. The characters "#" and "." represent black and white, respectively. It is guaranteed, that the string will not contain any other characters.

Output

Output a single integer, the minimum possible number of north magnets required.

If there is no placement of magnets that satisfies all conditions, print a single integer -1.

Examples

Input

3 3
.#.
###
##.

Output

1

Input

4 2
##
.#
.#
##

Output

-1

Input

4 5
....#
####.
.###.
.#...

Output

2

Input

2 1
.
#

Output

-1

Input

3 5
.....
.....
.....

Output

0

Note

In the first test, here is an example placement of magnets:

<image>

In the second test, we can show that no required placement of magnets exists. Here are three example placements that fail to meet the requirements. The first example violates rule 3 since we can move the north magnet down onto a white square. The second example violates rule 2 since we cannot move the north magnet to the bottom-left black square by any sequence of operations. The third example violates rule 1 since there is no south magnet in the first column.

<image>

In the third test, here is an example placement of magnets. We can show that there is no required placement of magnets with fewer north magnets.

<image>

In the fourth test, we can show that no required placement of magnets exists. Here are two example placements that fail to meet the requirements. The first example violates rule 1 since there is no south magnet in the first row. The second example violates rules 1 and 3 since there is no south magnet in the second row and we can move the north magnet up one unit onto a white square.

<image>

In the fifth test, we can put the south magnet in each cell and no north magnets. Because there are no black cells, it will be a correct placement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[1005][1005];
long long visited[1005][1005];
long long n, m;
long long dirx[] = {1, 0, -1, 0};
long long diry[] = {0, -1, 0, 1};
long long issafe(long long i, long long j) {
  if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] && !visited[i][j]) return 1;
  return 0;
}
void dfs(long long i, long long j) {
  visited[i][j] = 1;
  for (long long k = 0; k < 4; k++) {
    long long i1 = i + dirx[k], j1 = j + diry[k];
    if (issafe(i1, j1)) dfs(i1, j1);
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    cin >> n >> m;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        char c;
        cin >> c;
        if (c == '#')
          a[i][j] = 1;
        else
          a[i][j] = 0;
      }
    }
    long long flag = 0;
    long long row[n], col[m];
    memset(row, 0, sizeof(row));
    memset(col, 0, sizeof(col));
    for (long long i = 0; i < n; i++) {
      long long bb = 0;
      long long j = 0;
      while (j < m) {
        long long j1 = j;
        while (j1 < m && a[i][j1]) j1++;
        if (j != j1) bb++;
        j = j1 + 1;
      }
      if (bb >= 2) {
        flag = 1;
      }
      if (bb == 0) row[i] = 1;
    }
    for (long long j = 0; j < m; j++) {
      long long bb = 0;
      long long i = 0;
      while (i < n) {
        long long i1 = i;
        while (i1 < n && a[i1][j]) i1++;
        if (i != i1) bb++;
        i = i1 + 1;
      }
      if (bb >= 2) {
        flag = 1;
      }
      if (bb == 0) col[j] = 1;
    }
    long long f1 = 0, f2 = 0;
    for (long long i = 0; i < n; i++)
      if (row[i]) f1 = 1;
    for (long long j = 0; j < m; j++)
      if (col[j]) f2 = 1;
    if ((f1 && !f2) || (!f1 && f2)) flag = 1;
    if (flag) {
      cout << -1;
      return 0;
    }
    memset(visited, 0, sizeof(visited));
    long long val = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (issafe(i, j)) {
          dfs(i, j);
          val++;
        }
      }
    }
    cout << val;
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.

During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.

More formally, you are given an array s1, s2, ..., sn of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.

Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.

Input

The first line contains one integer number n (1 ≤ n ≤ 100).

The second line contains n space-separated integer numbers s1, s2, ..., sn (0 ≤ si ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one.

Output

Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.

Examples

Input

4
1 1 0 1

Output

3

Input

6
0 1 0 0 1 0

Output

4

Input

1
0

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], one[N], zero[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    one[i] = one[i - 1];
    zero[i] = zero[i - 1];
    if (a[i])
      one[i]++;
    else
      zero[i]++;
  }
  int ans = n - one[n];
  for (int i = 1; i <= n; i++) {
    int Bef = one[i - 1];
    int Las = zero[n] - zero[i - 1];
    ans = max(ans, n - Bef - Las);
  }
  cout << ans;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

We all know that GukiZ often plays with arrays.

Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: <image>? Here operation <image> means bitwise AND (in Pascal it is equivalent to and, in C/C++/Java/Python it is equivalent to &), operation <image> means bitwise OR (in Pascal it is equivalent to <image>, in C/C++/Java/Python it is equivalent to |).

Because the answer can be quite large, calculate it modulo m. This time GukiZ hasn't come up with solution, and needs you to help him!

Input

First and the only line of input contains four integers n, k, l, m (2 ≤ n ≤ 1018, 0 ≤ k ≤ 1018, 0 ≤ l ≤ 64, 1 ≤ m ≤ 109 + 7).

Output

In the single line print the number of arrays satisfying the condition above modulo m.

Examples

Input

2 1 2 10

Output

3

Input

2 1 1 3

Output

1

Input

3 3 2 10

Output

9

Note

In the first sample, satisfying arrays are {1, 1}, {3, 1}, {1, 3}.

In the second sample, only satisfying array is {1, 1}.

In the third sample, satisfying arrays are {0, 3, 3}, {1, 3, 2}, {1, 3, 3}, {2, 3, 1}, {2, 3, 3}, {3, 3, 0}, {3, 3, 1}, {3, 3, 2}, {3, 3, 3}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
unsigned long long n, K, L, Mo;
struct Mat {
  int nl, ml;
  unsigned long long num[10][10];
  Mat() {
    nl = 0;
    ml = 0;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        num[i][j] = 0;
      }
    }
  }
  void print() {
    cout << "matrix " << endl;
    for (int i = 1; i <= nl; ++i) {
      for (int j = 1; j <= ml; ++j) {
        cout << num[i][j] << ' ';
      }
      cout << endl;
    }
  }
} A, B;
Mat operator*(const Mat &a, const Mat &b) {
  Mat c;
  c.nl = a.nl;
  c.ml = b.ml;
  memset(c.num, 0, sizeof(c.num));
  for (int i = 1; i <= a.nl; ++i) {
    for (int j = 1; j <= b.nl; ++j) {
      for (int k = 1; k <= b.ml; ++k) {
        c.num[i][k] =
            ((c.num[i][k] + a.num[i][j] * b.num[j][k]) % Mo + Mo) % Mo;
      }
    }
  }
  return c;
}
Mat Pow(Mat a, unsigned long long b) {
  Mat c;
  c.nl = 2;
  c.ml = 2;
  for (int i = 1; i <= 2; ++i) c.num[i][i] = 1LL;
  while (b) {
    if (b & 1) c = c * a;
    a = a * a;
    b >>= 1;
  }
  return c;
}
unsigned long long Pow2(unsigned long long a, unsigned long long b) {
  unsigned long long res = 1LL;
  while (b) {
    if (b & 1) res = res * a, res %= Mo;
    a = a * a;
    a %= Mo;
    b >>= 1;
  }
  return res;
}
int main() {
  cin >> n >> K >> L >> Mo;
  if (L < 64 && K >= (1ULL << L)) {
    printf("0");
    return 0;
  }
  A.nl = 1;
  A.ml = 2;
  A.num[1][1] = A.num[1][2] = 1;
  B.nl = B.ml = 2;
  B.num[1][2] = B.num[2][1] = B.num[2][2] = 1;
  B.num[1][1] = 0;
  unsigned long long a = (A * Pow(B, n)).num[1][2];
  unsigned long long b =
      ((long long)((long long)Pow2(2LL, n) - (long long)a) % (long long)Mo +
       (long long)Mo) %
      (long long)Mo;
  a = (a % Mo + Mo) % Mo;
  b = (b % Mo + Mo) % Mo;
  unsigned long long ans = 1LL;
  for (unsigned long long i = 0; i < L; ++i) {
    if (K & (1LL << i)) {
      ans = ans * b;
    } else {
      ans = ans * a;
    }
    ans = (ans % Mo + Mo) % Mo;
  }
  ans = (ans % Mo + Mo) % Mo;
  cout << ans;
  fclose(stdin);
  fclose(stdout);
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

As it has been found out recently, all the Berland's current economical state can be described using a simple table n × m in size. n — the number of days in each Berland month, m — the number of months. Thus, a table cell corresponds to a day and a month of the Berland's year. Each cell will contain either 1, or -1, which means the state's gains in a particular month, on a particular day. 1 corresponds to profits, -1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than max(n, m). However, there is additional information — the product of the numbers in each line and column equaled -1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo p.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 1000). The second line contains the integer k (0 ≤ k < max(n, m)) — the number of cells in which the data had been preserved. The next k lines contain the data on the state of the table in the preserved cells. Each line is of the form "a b c", where a (1 ≤ a ≤ n) — the number of the table row, b (1 ≤ b ≤ m) — the number of the column, c — the value containing in the cell (1 or -1). They are numbered starting from 1. It is guaranteed that no two lines with same a and b values exist. The last line contains an integer p (2 ≤ p ≤ 109 + 7).

Output

Print the number of different tables that could conform to the preserved data modulo p.

Examples

Input

2 2
0
100

Output

2

Input

2 2
1
1 1 -1
100

Output

1

### Response

```cpp
#include <bits/stdc++.h>
const int MaxN = 1010;
int mod_v, pw[MaxN], cnt[MaxN], val[MaxN];
int main() {
  int n, m, t, flag = 0;
  std::scanf("%d %d %d", &n, &m, &t);
  if (n < m) std::swap(n, m), flag = 1;
  for (int i = 0; i != t; ++i) {
    int x, y, v;
    std::scanf("%d %d %d", &x, &y, &v);
    if (flag) std::swap(x, y);
    ++cnt[x];
    if (!val[x])
      val[x] = v;
    else
      val[x] *= v;
  }
  std::scanf("%d", &mod_v);
  for (int i = 1; i <= n; ++i) {
    if (!cnt[i]) {
      std::swap(cnt[i], cnt[n]);
      std::swap(val[i], val[n]);
      break;
    }
  }
  pw[0] = 1;
  for (int i = 1; i <= m; ++i) pw[i] = (pw[i - 1] << 1) % mod_v;
  int ans = 1;
  for (int i = 1; i != n; ++i) {
    if (cnt[i] == m && val[i] == 1)
      ans = 0;
    else if (m != cnt[i])
      ans = (long long)ans * pw[m - cnt[i] - 1] % mod_v;
  }
  if ((n ^ m) & 1)
    std::puts("0");
  else
    std::printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up in a row.

The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise.

Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel.

Solve this problem for each of the T test cases given.

Constraints

* All values in input are integers.
* 1 \leq T \leq 10^5
* 1 \leq N \leq 2 \times 10^{5}
* 1 \leq K_i \leq N
* 1 \leq L_i, R_i \leq 10^9
* The sum of values of N in each input file is at most 2 \times 10^5.

Input

Input is given from Standard Input in the following format:

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

Each case is given in the following format:

N
K_1 L_1 R_1
\vdots
K_N L_N R_N

Output

Print T lines. The i-th line should contain the answer to the i-th test case.

Example

Input

3
2
1 5 10
2 15 5
3
2 93 78
1 71 59
3 57 96
19
19 23 16
5 90 13
12 85 70
19 67 78
12 16 60
18 48 28
5 4 24
12 97 97
4 57 87
19 91 74
18 100 76
7 86 46
9 100 57
3 76 73
6 84 93
1 6 84
11 75 94
19 15 3
12 11 34

Output

25
221
1354

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){

	int T;
	cin>>T;

	for(int _=0;_<T;_++){
		int N;
		cin>>N;

		vector<long long> K(N),L(N),R(N);
		for(int i=0;i<N;i++)cin>>K[i]>>L[i]>>R[i];

		vector<pair<long long,long long>> l,r;
		long long ans = 0LL;
		for(int i=0;i<N;i++){
			if(L[i]>R[i]){
				ans += R[i];
				l.emplace_back(K[i]-1,L[i]-R[i]);
			}
			else{
				ans += L[i];
				r.emplace_back(N-K[i]-1,R[i]-L[i]);
			}
		}
		sort(l.begin(),l.end());
		sort(r.begin(),r.end());
		priority_queue<long long,vector<long long>,greater<long long>> Q;
		for(int i=0;i<l.size();i++){
			if(Q.size()<=l[i].first){
				ans += l[i].second;
				Q.push(l[i].second);
			}
			else{
				if(Q.size()==0)continue;
				if(Q.top()<l[i].second){
					ans -= Q.top();
					Q.pop();
					ans += l[i].second;
					Q.push(l[i].second);
				}
			}
		}

		while(Q.size()!=0)Q.pop();
		for(int i=0;i<r.size();i++){
			if((int)Q.size()<=r[i].first){
				ans += r[i].second;
				Q.push(r[i].second);
			}
			else{
				if(Q.size()==0)continue;
				if(Q.top()<r[i].second){
					ans -= Q.top();
					Q.pop();
					ans += r[i].second;
					Q.push(r[i].second);
				}
			}
		}

		cout<<ans<<endl;

	}

	return 0;
}

```


### Prompt

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

Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree T:

  1. Set pointer to the root of a tree.
  2. Return success if the value in the current vertex is equal to the number you are looking for
  3. Go to the left child of the vertex if the value in the current vertex is greater than the number you are looking for
  4. Go to the right child of the vertex if the value in the current vertex is less than the number you are looking for
  5. Return fail if you try to go to the vertex that doesn't exist

Here is the pseudo-code of the described algorithm:

    bool find(TreeNode t, int x) {
        if (t == null)
            return false;
        if (t.value == x)
            return true;
        if (x < t.value)
            return find(t.left, x);
        else
            return find(t.right, x);
    }
    find(root, x);

The described algorithm works correctly if the tree is binary search tree (i.e. for each node the values of left subtree are less than the value in the node, the values of right subtree are greater than the value in the node). But it can return invalid result if tree is not a binary search tree.

Since the given tree is not necessarily a binary search tree, not all numbers can be found this way. Your task is to calculate, how many times the search will fail being running on every value from the tree.

If the tree has multiple vertices with the same values on them then you should run algorithm on every one of them separately.

Input

First line contains integer number n (1 ≤ n ≤ 105) — number of vertices in the tree.

Each of the next n lines contains 3 numbers v, l, r (0 ≤ v ≤ 109) — value on current vertex, index of the left child of the vertex and index of the right child of the vertex, respectively. If some child doesn't exist then number  - 1 is set instead. Note that different vertices of the tree may contain the same values.

Output

Print number of times when search algorithm will fail.

Examples

Input

3
15 -1 -1
10 1 3
5 -1 -1

Output

2

Input

8
6 2 3
3 4 5
12 6 7
1 -1 8
4 -1 -1
5 -1 -1
14 -1 -1
2 -1 -1

Output

1

Note

In the example the root of the tree in vertex 2. Search of numbers 5 and 15 will return fail because on the first step algorithm will choose the subtree which doesn't contain numbers you are looking for.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 3e6;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
int n;
int l[maxn], r[maxn];
int val[maxn];
int root[maxn];
int ans;
map<int, int> mp;
void dfs(int v, int mn = 0, int mx = 1e9) {
  bool bad = (val[v] > mx or val[v] < mn);
  if (!bad) ans -= mp[val[v]], mp[val[v]] = 0;
  if (l[v] > 0) {
    dfs(l[v], mn, min(mx, val[v]));
  }
  if (r[v] > 0) {
    dfs(r[v], max(mn, val[v]), mx);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> val[i] >> l[i] >> r[i];
    if (l[i] > 0) root[l[i]] = 1;
    if (r[i] > 0) root[r[i]] = 1;
    mp[val[i]]++;
  }
  ans = n;
  int r = min_element(root + 1, root + n + 1) - root;
  dfs(r);
  return (cout << ans, 0);
  ;
  return (0);
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

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

You should answer q queries, the i-th query is to find the shortest distance between vertices u_i and v_i.

Input

The first line contains two integers n and m~(1 ≤ n, m ≤ 10^5, m - n ≤ 20) — the number of vertices and edges in the graph.

Next m lines contain the edges: the i-th edge is a triple of integers v_i, u_i, d_i~(1 ≤ u_i, v_i ≤ n, 1 ≤ d_i ≤ 10^9, u_i ≠ v_i). This triple means that there is an edge between vertices u_i and v_i of weight d_i. It is guaranteed that graph contains no self-loops and multiple edges.

The next line contains a single integer q~(1 ≤ q ≤ 10^5) — the number of queries.

Each of the next q lines contains two integers u_i and v_i~(1 ≤ u_i, v_i ≤ n) — descriptions of the queries.

Pay attention to the restriction m - n ~ ≤ ~ 20.

Output

Print q lines.

The i-th line should contain the answer to the i-th query — the shortest distance between vertices u_i and v_i.

Examples

Input

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

Output

3
4
1

Input

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

Output

7
5
6
7
7
1
2
7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 5;
const int N = 1e5 + 35;
const int DEG = 21;
long long dis[55][N];
struct Edge {
  int u;
  int v;
  int next;
  long long w;
} edge1[N * 2], edge[N * 2];
int tot1;
int head1[N];
int tot;
int head[N];
int f[N];
int fa[N][25];
int deg[N];
long long dep[N];
int n, m;
int se[50];
int scnt;
int vis[N];
vector<Edge> ve[N];
void adde1(int u, int v, long long w) {
  edge1[++tot1].u = u;
  edge1[tot1].v = v;
  edge1[tot1].w = w;
  edge1[tot1].next = head1[u];
  head1[u] = tot1;
}
void add(int u, int v, long long w) {
  edge[++tot].v = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot;
}
void init() {
  tot = tot1 = 0;
  memset(head, -1, sizeof(head));
  memset(head1, -1, sizeof(head1));
}
void bfs(int rt) {
  queue<int> que;
  deg[rt] = 0;
  dep[rt] = 0;
  fa[rt][0] = rt;
  que.push(rt);
  while (!que.empty()) {
    int tmp = que.front();
    que.pop();
    for (int i = 1; i < DEG; i++) {
      fa[tmp][i] = fa[fa[tmp][i - 1]][i - 1];
    }
    for (int i = head[tmp]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      if (v == fa[tmp][0]) continue;
      deg[v] = deg[tmp] + 1;
      dep[v] = dep[tmp] + edge[i].w;
      fa[v][0] = tmp;
      que.push(v);
    }
  }
}
int LCA(int u, int v) {
  if (deg[u] > deg[v]) swap(u, v);
  int hu = deg[u];
  int hv = deg[v];
  int tu = u, tv = v;
  for (int det = hv - hu, i = 0; det; det >>= 1, i++) {
    if (det & 1) tv = fa[tv][i];
  }
  if (tu == tv) return tu;
  for (int i = DEG - 1; i >= 0; i--) {
    if (fa[tu][i] == fa[tv][i]) continue;
    tu = fa[tu][i];
    tv = fa[tv][i];
  }
  return fa[tu][0];
}
bool cmp(Edge a, Edge b) { return a.w < b.w; }
void dij(int id, int s) {
  for (int i = 0; i <= n + 2; i++) {
    vis[i] = 0;
    dis[id][i] = inf;
  }
  dis[id][s] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  q.push(pair<long long, int>(0, s));
  while (!q.empty()) {
    pair<long long, int> tmp = q.top();
    q.pop();
    int u = tmp.second;
    if (tmp.first > dis[id][u]) continue;
    vis[u] = 1;
    for (int i = 0; i < ve[u].size(); i++) {
      int v = ve[u][i].v;
      long long w = ve[u][i].w;
      if (vis[v]) continue;
      if (dis[id][v] > dis[id][u] + w) {
        dis[id][v] = dis[id][u] + w;
        q.push(pair<long long, int>(dis[id][v], v));
      }
    }
  }
}
int getf(int x) { return f[x] == x ? x : (f[x] = getf(f[x])); }
int merge(int x, int y) {
  int t1 = getf(x);
  int t2 = getf(y);
  if (t1 != t2) {
    f[t2] = t1;
    return 1;
  }
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  int u, v;
  long long w;
  init();
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %lld", &u, &v, &w);
    adde1(u, v, w);
    ve[u].push_back((Edge){u, v, 0, w});
    ve[v].push_back((Edge){v, u, 0, w});
  }
  sort(edge1 + 1, edge1 + tot1 + 1, cmp);
  for (int i = 0; i <= n + 2; i++) {
    f[i] = i;
  }
  for (int i = 1; i <= tot1; i++) {
    u = edge1[i].u;
    v = edge1[i].v;
    if (merge(u, v)) {
      add(u, v, edge1[i].w);
      add(v, u, edge1[i].w);
    } else {
      se[++scnt] = u;
      se[++scnt] = v;
    }
  }
  bfs(1);
  sort(se + 1, se + scnt + 1);
  scnt = unique(se + 1, se + scnt + 1) - (se + 1);
  for (int i = 1; i <= scnt; i++) {
    dij(i, se[i]);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &u, &v);
    long long ans = inf;
    int lca = LCA(u, v);
    ans = dep[u] + dep[v] - 2 * dep[lca];
    for (int i = 1; i <= scnt; i++) {
      ans = min(ans, dis[i][u] + dis[i][v]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}

```


### Prompt

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

You went shopping to buy cakes and donuts with X yen (the currency of Japan).

First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.

How much do you have left after shopping?

Constraints

* 1 \leq A, B \leq 1 000
* A + B \leq X \leq 10 000
* X, A and B are integers.

Input

Input is given from Standard Input in the following format:

X
A
B

Output

Print the amount you have left after shopping.

Examples

Input

1234
150
100

Output

84

Input

1000
108
108

Output

28

Input

579
123
456

Output

0

Input

7477
549
593

Output

405

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
ll a,b,c;
int main()
{
	cin>>a>>b>>c;
	cout<<(a-b)%c;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.

A k-tree is an infinite rooted tree where:

  * each vertex has exactly k children;
  * each edge has some weight;
  * if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.

The picture below shows a part of a 3-tree.

<image>

As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".

Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7).

Input

A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).

Output

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

Examples

Input

3 3 2

Output

3

Input

3 3 3

Output

1

Input

4 3 2

Output

6

Input

4 5 2

Output

7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long dp[101][2];
int main() {
  memset(dp, 0, sizeof(dp));
  int n, k, d;
  cin >> n >> k >> d;
  dp[0][0] = 1LL;
  dp[0][1] = 0LL;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i][1] = 0LL;
    for (int j = 1; j <= k; j++) {
      if (i < j) break;
      if (j < d) {
        dp[i][0] = (dp[i][0] + dp[i - j][0]) % (long long)1000000007;
        dp[i][1] = (dp[i][1] + dp[i - j][1]) % (long long)1000000007;
      } else {
        dp[i][1] = (dp[i][1] + dp[i - j][0]) % (long long)1000000007;
        dp[i][1] = (dp[i][1] + dp[i - j][1]) % (long long)1000000007;
      }
    }
  }
  cout << dp[n][1];
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

In Japan, people make offerings called hina arare, colorful crackers, on March 3.

We have a bag that contains N hina arare. (From here, we call them arare.)

It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.

We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: `P`, white: `W`, green: `G`, yellow: `Y`.

If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.

Constraints

* 1 \leq N \leq 100
* S_i is `P`, `W`, `G` or `Y`.
* There always exist i, j and k such that S_i=`P`, S_j=`W` and S_k=`G`.

Input

Input is given from Standard Input in the following format:

N
S_1 S_2 ... S_N

Output

If the number of colors of the arare in the bag was three, print `Three`; if the number of colors was four, print `Four`.

Examples

Input

6
G W Y P Y W

Output

Four

Input

9
G W W G P W P G G

Output

Three

Input

8
P Y W G Y W Y Y

Output

Four

### Response

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

int main(){
	int n;
	cin >> n;
	char s;
	for(int i=0; i<n; i++){
		cin >> s;
		if(s == 'Y') {
			cout << "Four";
			return 0;
		}
	}
	cout << "Three";
	return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Create a program of the square picking method, which is one of the classical random number generation methods. The square harvesting method was proposed by von Neumann in the mid-1940s.

In the square picking method, when the number of digits of the generated random number is n, the square of the initial value s is calculated, and the value is regarded as a 2n digit number (the number of squared digits as shown in the example below). If is not enough, make up for 0.) Let the n numbers in the center be the first random number. Then square this random number and take the n numbers in the center in the same way to get the next random number. For example, if 123 is the initial value

1232 = 00015129 → 0151
1512 = 00022801 → 0228
2282 = 00051984 → 0519
5192 = 00269361 → 2693
26932 = 07252249 → 2522

It will be like. Use this method to create a program that takes the initial value s (a positive integer less than 10000) as an input and generates and outputs 10 random numbers when n = 4.

Input

Given multiple datasets. The first line gives the number of datasets d (d ≤ 10). For each dataset, one row is given the initial value s (integer, 1 ≤ s <10000).

Output

For each dataset

Case x: (x is a dataset number starting with 1)
The first generated random number (integer)
The second generated random number (integer)
:
:
10th generated random number (integer)

Please output.

Example

Input

2
123
567

Output

Case 1:
151
228
519
2693
2522
3604
9888
7725
6756
6435
Case 2:
3214
3297
8702
7248
5335
4622
3628
1623
6341
2082

### Response

```cpp
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n; cin>>n;
  REP(c,n){
    int s; cin>>s;
    printf("Case %d:\n",c+1);
    REP(i,10){
      char buff[16];
      sprintf(buff,"%08d",s*s);
      buff[6] = '\0';
      sscanf(buff+2,"%d",&s);
      printf("%d\n",s);
    }
  }
  return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

A telephone number is a sequence of exactly 11 digits such that its first digit is 8.

Vasya and Petya are playing a game. Initially they have a string s of length n (n is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string s becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.

You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).

Input

The first line contains one integer n (13 ≤ n < 10^5, n is odd) — the length of string s.

The second line contains the string s (|s| = n) consisting only of decimal digits.

Output

If Vasya has a strategy that guarantees him victory, print YES.

Otherwise print NO.

Examples

Input

13
8380011223344

Output

YES

Input

15
807345619350641

Output

NO

Note

In the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.

In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N, K;
string S;
int main() {
  int i, j, k, a;
  cin >> N >> S;
  k = K = (N - 11) / 2;
  a = 0;
  for (i = 0; i < N; i++) {
    if (S[i] != '8') {
      K--;
      if (K < 0) break;
    } else {
      a++;
    }
  }
  if (K > 0) a -= K;
  if (a > k)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Given are two sequences A and B, both of length N. A and B are each sorted in the ascending order. Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.

Constraints

* 1\leq N \leq 2 \times 10^5
* 1\leq A_i,B_i \leq N
* A and B are each sorted in the ascending order.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

Output

If there exist no reorderings that satisfy the condition, print `No`.

If there exists a reordering that satisfies the condition, print `Yes` on the first line. After that, print a reordering of B on the second line, separating terms with a whitespace.

If there are multiple reorderings that satisfy the condition, you can print any of them.

Examples

Input

6
1 1 1 2 2 3
1 1 1 2 2 3

Output

Yes
2 2 3 1 1 1

Input

3
1 1 2
1 1 3

Output

No

Input

4
1 1 2 3
1 2 3 3

Output

Yes
3 3 1 2

### Response

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

int main(){
   int n; cin>>n;
   vector<int> a(n),b(n);
   rep(i,0,n)cin>>a[i];
   rep(i,0,n)cin>>b[i];
   int d=0;
   rep(i,0,n){
      int idx=upper_bound(ALL(b),a[i])-b.begin();
      chmax(d,idx-i);
   }
   rotate(b.begin(),b.begin()+d,b.end());
   rep(i,0,n)if(a[i]==b[i]){
      puts("No"); return 0;
   }
   puts("Yes");
   rep(i,0,n)cout<<b[i]<<(i==n-1?'\n':' ');
   return 0;
}
```


### Prompt

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

Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened.

You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

Input

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

Examples

Input

fixprefixsuffix

Output

fix

Input

abcdabc

Output

Just a legend

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char s[N];
int p[N], k;
void kmp() {
  int n = strlen(s + 1);
  for (int i = 2; i <= n; i++) {
    while (k && s[k + 1] != s[i]) k = p[k];
    if (s[k + 1] == s[i]) k++;
    p[i] = k;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  kmp();
  int x = 0, ans = p[n];
  for (int i = 2; i < n; i++) x = max(x, p[i]);
  while (ans) {
    if (ans <= x)
      break;
    else
      ans = p[ans];
  }
  if (!ans)
    puts("Just a legend");
  else
    for (int i = 1; i <= ans; i++) printf("%c", s[i]);
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

This is an interactive problem.

Vasya and Petya are going to play the following game: Petya has some positive integer number a. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbers (x, y). Petya will answer him:

  * "x", if (x mod a) ≥ (y mod a).
  * "y", if (x mod a) < (y mod a).

We define (x mod a) as a remainder of division x by a.

Vasya should guess the number a using no more, than 60 questions.

It's guaranteed that Petya has a number, that satisfies the inequality 1 ≤ a ≤ 10^9.

Help Vasya playing this game and write a program, that will guess the number a.

Interaction

Your program should play several games.

Before the start of any game your program should read the string:

  * "start" (without quotes) — the start of the new game.
  * "mistake" (without quotes) — in the previous game, you found the wrong answer. Your program should terminate after reading this string and it will get verdict "Wrong answer".
  * "end" (without quotes) — all games finished. Your program should terminate after reading this string.

After reading the string "start" (without quotes) the new game starts.

At the beginning, your program should ask several questions about pairs of non-negative integer numbers (x, y). You can only ask the numbers, that satisfy the inequalities 0 ≤ x, y ≤ 2 ⋅ 10^9. To ask a question print "? x y" (without quotes). As the answer, you should read one symbol:

  * "x" (without quotes), if (x mod a) ≥ (y mod a).
  * "y" (without quotes), if (x mod a) < (y mod a).
  * "e" (without quotes) — you asked more than 60 questions. Your program should terminate after reading this string and it will get verdict "Wrong answer".

After your program asked several questions your program should print the answer in form "! a" (without quotes). You should print the number a satisfying the inequalities 1 ≤ a ≤ 10^9. It's guaranteed that Petya's number a satisfied this condition. After that, the current game will finish.

We recall that your program can't ask more than 60 questions during one game.

If your program doesn't terminate after reading "mistake" (without quotes), "end" (without quotes) or "e" (without quotes), it can get any verdict, because it will continue reading from closed input. Also, if your program prints answer or question in the incorrect format it can get any verdict, too. Be careful.

Don't forget to flush the output after printing questions and answers.

To flush the output, you can use:

  * fflush(stdout) in C++.
  * System.out.flush() in Java.
  * stdout.flush() in Python.
  * flush(output) in Pascal.
  * See the documentation for other languages.

It's guaranteed that you should play at least 1 and no more than 100 games.

Hacks:

In hacks, you can use only one game. To hack a solution with Petya's number a (1 ≤ a ≤ 10^9) in the first line you should write a single number 1 and in the second line you should write a single number a.

Example

Input

start
x
x
start
x
x
y
start
x
x
y
y
end

Output

? 0 0
? 10 1
! 1
? 0 0
? 3 4
? 2 5
! 2
? 2 4
? 2 5
? 3 10
? 9 1
! 3

Note

In the first test, you should play 3 games with Petya's numbers 1, 2 and 3.

In the first game, Petya will answer "x" (without quotes) to any question, because (x mod 1) = 0 for any integer x.

In the second game, if you will ask pair (0, 0), the answer will be "x" (without quotes), because (0 mod 2) ≥ (0 mod 2). But if you will ask pair (2, 5), the answer will be "y" (without quotes), because (2 mod 2) < (5 mod 2), because (2 mod 2) = 0 and (5 mod 2) = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
void ans(int first) {
  cout << "! " << first << "\n";
  fflush(stdout);
}
bool les(int first, int second) {
  if (second > 1e9) {
    return false;
  }
  cout << "? " << first << " " << second << "\n";
  fflush(stdout);
  string s;
  cin >> s;
  return (s == "y");
}
int main() {
  string s;
  while (cin >> s) {
    fflush(stdout);
    if (s == "start") {
      int first = 1;
      bool res = les(0, 1);
      if (res) {
        while (res) {
          res = les(first, first << 1);
          first <<= 1;
        }
        first >>= 1;
        int p = first >> 1;
        while (p) {
          if (les(first, first + p)) {
            first += p;
          }
          p >>= 1;
        }
        first += 1;
        ans(first);
      } else {
        ans(1);
      }
    } else if (s == "end") {
      break;
    }
  }
}

```


### Prompt

Please formulate a CPP solution to the following problem:

BubbleSquare social network is celebrating 13^{th} anniversary and it is rewarding its members with special edition BubbleSquare tokens. Every member receives one personal token. Also, two additional tokens are awarded to each member for every friend they have on the network. Yet, there is a twist – everyone should end up with different number of tokens from all their friends. Each member may return one received token. Also, each two friends may agree to each return one or two tokens they have obtained on behalf of their friendship.

Input

First line of input contains two integer numbers n and k (2 ≤ n ≤ 12500, 1 ≤ k ≤ 1000000) - number of members in network and number of friendships.

Next k lines contain two integer numbers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) - meaning members a_i and b_i are friends.

Output

First line of output should specify the number of members who are keeping their personal token.

The second line should contain space separated list of members who are keeping their personal token.

Each of the following k lines should contain three space separated numbers, representing friend pairs and number of tokens each of them gets on behalf of their friendship.

Examples

Input

2 1
1 2

Output

1
1
1 2 0

Input

3 3
1 2
1 3
2 3

Output

0
1 2 0
2 3 1
1 3 2

Note

In the first test case, only the first member will keep its personal token and no tokens will be awarded for friendship between the first and the second member.

In the second test case, none of the members will keep their personal token. The first member will receive two tokens (for friendship with the third member), the second member will receive one token (for friendship with the third member) and the third member will receive three tokens (for friendships with the first and the second member).

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline char gc(void) {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <class T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  static char c = gc();
  for (; !isdigit(c); c = gc())
    if (c == '-') f = -f;
  for (; isdigit(c); c = gc()) x = (x << 1) + (x << 3) + (c & 15);
  x *= f;
}
inline void readstr(char *s) {
  do *s = gc();
  while ((*s == ' ') || (*s == '\n') || (*s == '\r'));
  do *(++s) = gc();
  while ((~*s) && (*s != ' ') && (*s != '\n') && (*s != '\r'));
  *s = 0;
  return;
}
inline void readch(char &x) {
  while (isspace(x = gc()))
    ;
}
char pf[100000], *o1 = pf, *o2 = pf + 100000;
template <class T>
inline void writeln(T x, char c = '\n') {
  if (x < 0)
    (o1 == o2 ? fwrite(pf, 1, 100000, stdout), *(o1 = pf)++ = 45 : *o1++ = 45),
        x = -x;
  static char s[15], *b;
  b = s;
  if (!x) *b++ = 48;
  for (; x; *b++ = x % 10 + 48, x /= 10)
    ;
  for (; b-- != s; (o1 == o2          ? fwrite(pf, 1, 100000, stdout),
                    *(o1 = pf)++ = *b : *o1++ = *b))
    ;
  (o1 == o2 ? fwrite(pf, 1, 100000, stdout), *(o1 = pf)++ = c : *o1++ = c);
}
template <class T>
inline void chkmax(T &x, const T y) {
  x > y ? x = x : x = y;
}
template <class T>
inline void chkmin(T &x, const T y) {
  x < y ? x = x : x = y;
}
const int N = 1e6 + 100;
int x[N], y[N], w[N], s[N], v[N];
bool in[N * 2];
vector<pair<int, int> > e[N];
vector<int> res;
int n, m;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (register int i = (1); i <= (m); i++) {
    cin >> x[i] >> y[i];
    w[i] = 1;
    s[x[i]]++;
    s[y[i]]++;
    e[max(x[i], y[i])].push_back(make_pair(min(x[i], y[i]), i));
  }
  for (register int i = (1); i <= (n); i++) {
    for (auto it : e[i]) {
      if (!v[it.first]) {
        v[it.first] = 1;
        w[it.second] = 0;
        s[i]--;
      }
      in[s[it.first]] = 1;
    }
    for (auto it : e[i]) {
      if (!in[s[i]]) break;
      s[i]++;
      v[it.first] = 0;
      w[it.second]++;
    }
    for (auto it : e[i]) in[s[it.first]] = 0;
  }
  for (register int i = (1); i <= (n); i++)
    if (v[i]) res.push_back(i);
  cout << int(res.size()) << '\n';
  for (auto it : res) cout << it << ' ';
  cout << '\n';
  for (register int i = (1); i <= (m); i++)
    cout << x[i] << ' ' << y[i] << ' ' << w[i] << '\n';
  return 0;
}

```


### Prompt

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

Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.

Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.

Input

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

Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.

Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.

Output

Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.

Examples

Input

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

Output

3 2

Input

2 2
1 2
2 1
3 4
5 1

Output

1 0

Note

In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1001][1001], b[1001][1001];
int main() {
  int i, j;
  int n, m;
  while (cin >> n >> m) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for (i = 0; i < n; ++i) {
      int p, q;
      cin >> p >> q;
      ++a[p][q];
    }
    for (i = 0; i < m; ++i) {
      int p, q;
      cin >> p >> q;
      ++b[p][q];
    }
    int s1 = 0, s2 = 0;
    for (i = 1; i <= 1000; ++i) {
      int s3 = 0, s4 = 0;
      for (j = 1; j <= 1000; ++j) {
        int p = min(a[j][i], b[j][i]);
        a[j][i] -= p;
        b[j][i] -= p;
        s1 += p;
        s2 += p;
        s3 += a[j][i];
        s4 += b[j][i];
      }
      s1 += min(s3, s4);
    }
    cout << s1 << ' ' << s2 << endl;
  }
  return 0;
}

```


### Prompt

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

Ringo got interested in modern art. He decided to draw a big picture on the board with N+2 rows and M+2 columns of squares constructed in the venue of CODE FESTIVAL 2017, using some people.

The square at the (i+1)-th row and (j+1)-th column in the board is represented by the pair of integers (i,j). That is, the top-left square is (0,0), and the bottom-right square is (N+1,M+1). Initially, the squares (x,y) satisfying 1 \leq x \leq N and 1 \leq y \leq M are painted white, and the other (outermost) squares are painted black.

Ringo arranged people at some of the outermost squares, facing inward. More specifically, the arrangement of people is represented by four strings A, B, C and D, as follows:

* For each row except the top and bottom, if the i-th character (1 \leq i \leq N) in A is `1`, place a person facing right at the square (i,0); otherwise, do nothing.
* For each row except the top and bottom, if the i-th character (1 \leq i \leq N) in B is `1`, place a person facing left at the square (i,M+1); otherwise, do nothing.
* For each column except the leftmost and rightmost, if the i-th character (1 \leq i \leq M) in C is `1`, place a person facing down at the square (0,i); otherwise, do nothing.
* For each column except the leftmost and rightmost, if the i-th character (1 \leq i \leq M) in D is `1`, place a person facing up at the square (N+1,i); otherwise, do nothing.

Each person has a sufficient amount of non-white paint. No two people have paint of the same color.

<image>

An example of an arrangement of people (For convenience, black squares are displayed in gray)

Ringo repeats the following sequence of operations until all people are dismissed from the venue.

* Select a person who is still in the venue.
* The selected person repeats the following action while the square in front of him/her is white: move one square forward, and paint the square he/she enters with his/her paint. When the square in front of him/her is not white, he/she stops doing the action.
* The person is now dismissed from the venue.

<image>

An example of a way the board is painted

How many different states of the board can Ringo obtain at the end of the process? Find the count modulo 998244353.

Two states of the board are considered different when there is a square painted in different colors.

Constraints

* 1 \leq N,M \leq 10^5
* |A|=|B|=N
* |C|=|D|=M
* A, B, C and D consist of `0` and `1`.

Input

Input is given from Standard Input in the following format:

N M
A
B
C
D

Output

Print the number of the different states of the board Ringo can obtain at the end of the process, modulo 998244353.

Examples

Input

2 2
10
01
10
01

Output

6

Input

2 2
11
11
11
11

Output

32

Input

3 4
111
111
1111
1111

Output

1276

Input

17 21
11001010101011101
11001010011010111
111010101110101111100
011010110110101000111

Output

548356548

Input

3 4
000
101
1111
0010

Output

21

Input

9 13
111100001
010101011
0000000000000
1010111111101

Output

177856

Input

23 30
01010010101010010001110
11010100100100101010101
000101001001010010101010101101
101001000100101001010010101000

Output

734524988

### Response

```cpp
#include<cstdio>
#include<algorithm>
#define N_ 301000
using namespace std;
int n, m;
char X1[N_], X2[N_], Y1[N_], Y2[N_];
long long U[N_], D[N_], L[N_], R[N_], F[N_], InvF[N_], UU[N_], LL[N_], res;
long long Mod = 998244353;
long long Pow(long long a, int b){
    long long r = 1;
    while(b){
        if(b&1)r=r*a%Mod;
        a=a*a%Mod;b>>=1;
    }
    return r;
}
long long Comb(int a, int b){
    if(a<b)return 0;
    return F[a] * InvF[b]%Mod*InvF[a-b]%Mod;
}
long long Calc(int a, int b, int c){
    return (Comb(a+b+c,c) - Comb(a+b+c-1, c) + Mod) % Mod;
}
int main(){
    int i;
    scanf("%d%d",&n,&m);
    scanf("%s",X1+1);
    scanf("%s",X2+1);
    scanf("%s",Y1+1);
    scanf("%s",Y2+1);
    F[0]=1;
    int sum = 0;
    for(i=1;i<=n;i++){
        sum += X1[i]-'0';
        sum += X2[i]-'0';
    }
    for(i=1;i<=m;i++){
        sum += Y1[i]-'0';
        sum += Y2[i]-'0';
    }
    if(!sum){
        printf("1\n");
        return 0;
    }
    for(i=1;i<=300000;i++)F[i]=F[i-1]*i%Mod;
    InvF[300000] = Pow(F[300000], Mod-2);
    for(i=300000;i>=1;i--)InvF[i-1] = InvF[i] * i % Mod;
    int s1 = 0, s2 = 0, cc = 0;
    for(i=1;i<=m;i++)if(Y1[i] == '1')cc++;
    U[0] = 1;
    for(i=1;i<=n;i++){
        if(X1[i] == '1')s1++;
        if(X2[i] == '1')s2++;
        U[i] = Calc(s1,s2,cc);
    }
    s1 = s2 = cc = 0;
    for(i=1;i<=m;i++)if(Y2[i] == '1')cc++;
    D[n+1] = 1;
    for(i=n;i>=1;i--){
        if(X1[i] == '1')s1++;
        if(X2[i] == '1')s2++;
        D[i] = Calc(s1,s2,cc);
    }
    s1 = s2 = cc = 0;
    for(i=1;i<=n;i++)if(X1[i] == '1')cc++;
    L[0] = 1;
    for(i=1;i<=m;i++){
        if(Y1[i] == '1')s1++;
        if(Y2[i] == '1')s2++;
        L[i] = Calc(s1,s2,cc);
    }
    s1 = s2 = cc = 0;
    R[m+1] = 1;
    for(i=1;i<=n;i++)if(X2[i] == '1')cc++;
    for(i=m;i>=1;i--){
        if(Y1[i] == '1')s1++;
        if(Y2[i] == '1')s2++;
        R[i] = Calc(s1,s2,cc);
    }
    UU[0] = 1;
    for(i=1;i<=n;i++){
        int t = X1[i]-'0' + X2[i]-'0';
        UU[i] = UU[i-1];
        if(t==2) UU[i] += UU[i-1];
        if(t) UU[i] += U[i];
        UU[i]%=Mod;
    }
    LL[0] = 1;
    for(i=1;i<=m;i++){
        int t = Y1[i]-'0' + Y2[i]-'0';
        LL[i] = LL[i-1];
        if(t==2) LL[i] += LL[i-1];
        if(t) LL[i] += L[i];
        LL[i]%=Mod;
    }
    for(i=1;i<=n;i++){
        int c = X1[i] - '0' + X2[i] - '0';
        res = (res + UU[i-1]*D[i+1]*c) % Mod;
    }
 //   printf("%lld\n",res);
    for(i=1;i<=m;i++){
        int c = Y1[i] - '0' + Y2[i] - '0';
        res = (res + LL[i-1]*R[i+1]*c) % Mod;
    }
    for(i=1;i<=4;i++){
//        printf("%lld %lld %lld %lld %lld %lld\n",U[i],D[i],L[i],R[i],UU[i],LL[i]);
    }
    printf("%lld\n",res);
}
```


### Prompt

Please create a solution in cpp to the following problem:

You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.

Input

First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».

Output

Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.

Examples

Input

2 2
AG
CT

Output

AG
CT

Input

3 5
AGCAG
AGCAG
AGCAG

Output

TGCAT
CATGC
TGCAT

Note

In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const char mat[] = "AGCT";
int n, m;
int go(vector<string> &lis, int n, int m, char ch1, char ch2,
       vector<string> &ret) {
  vector<char> mm[2];
  mm[0] = {ch1, ch2};
  for (int(i) = (0); (i) <= ((4) - 1); (i)++)
    if (mat[i] != mm[0][0] && mat[i] != mm[0][1]) mm[1].emplace_back(mat[i]);
  int res = 0;
  for (int(i) = (0); (i) <= ((n)-1); (i)++) {
    int now[2] = {};
    for (int(j) = (0); (j) <= ((m)-1); (j)++)
      if (lis[i][j] != mm[i & 1][j & 1]) now[0]++;
    for (int(j) = (0); (j) <= ((m)-1); (j)++)
      if (lis[i][j] != mm[i & 1][j & 1 ^ 1]) now[1]++;
    if (now[0] < now[1]) {
      for (int(j) = (0); (j) <= ((m)-1); (j)++) ret[i][j] = mm[i & 1][j & 1];
      res += now[0];
    } else {
      for (int(j) = (0); (j) <= ((m)-1); (j)++)
        ret[i][j] = mm[i & 1][j & 1 ^ 1];
      res += now[1];
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  vector<string> lis(n);
  for (int(i) = (0); (i) <= ((n)-1); (i)++) cin >> lis[i];
  int res = n * m;
  vector<string> ans;
  bool rev = false;
  for (int(i) = (0); (i) <= ((4) - 1); (i)++)
    for (int(j) = (i + 1); (j) <= (3); (j)++) {
      vector<string> tmp(n, string(m, '\0'));
      int cur = go(lis, n, m, mat[i], mat[j], tmp);
      if (cur < res) {
        ans = tmp;
        res = cur;
      }
    }
  vector<string> lis2(m);
  for (int(i) = (0); (i) <= ((m)-1); (i)++)
    for (int(j) = (0); (j) <= ((n)-1); (j)++) lis2[i] += lis[j][i];
  for (int(i) = (0); (i) <= ((4) - 1); (i)++)
    for (int(j) = (i + 1); (j) <= (3); (j)++) {
      vector<string> tmp(m, string(n, '\0'));
      int cur = go(lis2, m, n, mat[i], mat[j], tmp);
      if (cur < res) {
        ans = tmp;
        rev = true;
        res = cur;
      }
    }
  if (rev) {
    for (int(i) = (0); (i) <= ((n)-1); (i)++) {
      for (int(j) = (0); (j) <= ((m)-1); (j)++) cout << ans[j][i];
      cout << '\n';
    }
  } else {
    for (int(i) = (0); (i) <= ((n)-1); (i)++) cout << ans[i] << '\n';
  }
}

```


### Prompt

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

A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Output

Print the maximal number of orders that can be accepted.

Examples

Input

2
7 11
4 7

Output

1

Input

5
1 2
2 3
3 4
4 5
5 6

Output

3

Input

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

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
} s[500001];
bool cmp(node a, node b) {
  if (a.r == b.r)
    return a.l < b.l;
  else
    return a.r < b.r;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &s[i].l, &s[i].r);
  }
  sort(s, s + n, cmp);
  int cnt = 0, p = 0;
  for (int i = 0; i < n; i++) {
    if (s[i].l > p) {
      cnt++;
      p = s[i].r;
    }
  }
  printf("%d\n", cnt);
  return 0;
}

```