### Prompt

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

Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.

Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to:

  1. dr(n) = S(n), if S(n) < 10;
  2. dr(n) = dr( S(n) ), if S(n) ≥ 10.

For example, dr(4098) = dr(21) = 3.

Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that dr(n) = S( S( S( S(n) ) ) ) (n ≤ 101000).

Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers k and d, find the number consisting of exactly k digits (the leading zeroes are not allowed), with digital root equal to d, or else state that such number does not exist.

Input

The first line contains two integers k and d (1 ≤ k ≤ 1000; 0 ≤ d ≤ 9).

Output

In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.

The chosen number must consist of exactly k digits. We assume that number 0 doesn't contain any leading zeroes.

Examples

Input

4 4

Output

5881

Input

5 1

Output

36172

Input

1 0

Output

0

Note

For the first test sample dr(5881) = dr(22) = 4.

For the second test sample dr(36172) = dr(19) = dr(10) = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double pi = 2 * acos(0.0);
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class TT>
bool pal(T a, TT n) {
  int k = 0;
  for (int i = 0; i <= n / 2; i++) {
    if (a[i] != a[n - i - 1]) {
      k = 1;
      break;
    }
  }
  return k ? 0 : 1;
}
int main() {
  int k, d;
  cin >> k >> d;
  if (d == 0 && k > 1) return cout << "No solution\n", 0;
  k--;
  while (k--) cout << 9;
  cout << d;
  getchar();
  getchar();
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Let's assume that we are given an n × m table filled by integers. We'll mark a cell in the i-th row and j-th column as (i, j). Thus, (1, 1) is the upper left cell of the table and (n, m) is the lower right cell. We'll assume that a circle of radius r with the center in cell (i0, j0) is a set of such cells (i, j) that <image>. We'll consider only the circles that do not go beyond the limits of the table, that is, for which r + 1 ≤ i0 ≤ n - r and r + 1 ≤ j0 ≤ m - r.

<image> A circle of radius 3 with the center at (4, 5).

Find two such non-intersecting circles of the given radius r that the sum of numbers in the cells that belong to these circles is maximum. Two circles intersect if there is a cell that belongs to both circles. As there can be more than one way to choose a pair of circles with the maximum sum, we will also be interested in the number of such pairs. Calculate the number of unordered pairs of circles, for instance, a pair of circles of radius 2 with centers at (3, 4) and (7, 7) is the same pair as the pair of circles of radius 2 with centers at (7, 7) and (3, 4).

Input

The first line contains three integers n, m and r (2 ≤ n, m ≤ 500, r ≥ 0). Each of the following n lines contains m integers from 1 to 1000 each — the elements of the table. The rows of the table are listed from top to bottom at the elements in the rows are listed from left to right. It is guaranteed that there is at least one circle of radius r, not going beyond the table limits.

Output

Print two integers — the maximum sum of numbers in the cells that are located into two non-intersecting circles and the number of pairs of non-intersecting circles with the maximum sum. If there isn't a single pair of non-intersecting circles, print 0 0.

Examples

Input

2 2 0
1 2
2 4

Output

6 2

Input

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

Output

34 3

Input

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

Output

0 0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 555;
int str[N][N];
int rightSum[N][N];
int centerDis[N];
int centerPos[N * 4];
int centerSum[N][N];
int rightMaxSum[N][N];
long long rightMaxNum[N][N];
int ans;
long long ansNum;
int main() {
  int m, n, r, i, j, h;
  while (~scanf("%d%d%d", &n, &m, &r)) {
    ans = 0;
    ansNum = 0;
    for (i = 0; i < n; i++) {
      rightSum[i][0] = 0;
      for (j = 0; j < m; j++) {
        scanf("%d", &str[i][j]);
        rightSum[i][j + 1] = rightSum[i][j] + str[i][j];
      }
    }
    centerDis[0] = r;
    for (i = 1; i <= r; i++) {
      for (centerDis[i] = centerDis[i - 1];
           i * i + centerDis[i] * centerDis[i] > r * r; centerDis[i]--)
        ;
    }
    centerPos[0] = 2 * r + 1;
    for (i = 1; i <= 2 * r; i++) {
      centerPos[i] = 0;
      for (h = 1; h <= r; h++) {
        if (h >= i - r && h <= i) {
          centerPos[i] = max(centerPos[i], centerDis[h] + centerDis[i - h] + 1);
        }
      }
    }
    for (i = r; i < n - r; i++) {
      for (j = r; j < m - r; j++) {
        centerSum[i][j] =
            rightSum[i][j + centerDis[0] + 1] - rightSum[i][j - centerDis[0]];
        for (h = 1; h <= r; h++) {
          centerSum[i][j] += rightSum[i + h][j + centerDis[h] + 1] -
                             rightSum[i + h][j - centerDis[h]];
          centerSum[i][j] += rightSum[i - h][j + centerDis[h] + 1] -
                             rightSum[i - h][j - centerDis[h]];
        }
      }
    }
    for (i = r; i < n - r; i++) {
      rightMaxSum[i][m - r - 1] = centerSum[i][m - r - 1];
      rightMaxNum[i][m - r - 1] = 1;
      for (j = m - r - 2; j >= r; j--) {
        if (centerSum[i][j] <= rightMaxSum[i][j + 1]) {
          rightMaxSum[i][j] = rightMaxSum[i][j + 1];
          rightMaxNum[i][j] = rightMaxNum[i][j + 1];
          if (centerSum[i][j] == rightMaxSum[i][j + 1]) {
            rightMaxNum[i][j]++;
          }
        } else {
          rightMaxSum[i][j] = centerSum[i][j];
          rightMaxNum[i][j] = 1;
        }
      }
    }
    for (i = r; i < n - r; i++) {
      for (j = i + 2 * r + 1; j < n - r; j++) {
        if (rightMaxSum[i][r] + rightMaxSum[j][r] == ans) {
          ansNum += rightMaxNum[i][r] * rightMaxNum[j][r];
        } else if (rightMaxSum[i][r] + rightMaxSum[j][r] > ans) {
          ans = rightMaxSum[i][r] + rightMaxSum[j][r];
          ansNum = rightMaxNum[i][r] * rightMaxNum[j][r];
        }
      }
    }
    for (i = r; i < n - r; i++) {
      for (j = r; j < m - r; j++) {
        for (h = 0; h <= 2 * r; h++) {
          if (j + centerPos[h] + r >= m) {
            continue;
          }
          if (i + h < n - r) {
            int score = centerSum[i][j] + rightMaxSum[i + h][j + centerPos[h]];
            if (score == ans) {
              ansNum += rightMaxNum[i + h][j + centerPos[h]];
            } else if (score > ans) {
              ans = score;
              ansNum = rightMaxNum[i + h][j + centerPos[h]];
            }
          }
          if (h && i - h >= r) {
            int score = centerSum[i][j] + rightMaxSum[i - h][j + centerPos[h]];
            if (score == ans) {
              ansNum += rightMaxNum[i - h][j + centerPos[h]];
            } else if (score > ans) {
              ans = score;
              ansNum = rightMaxNum[i - h][j + centerPos[h]];
            }
          }
        }
      }
    }
    printf("%d %lld\n", ans, ansNum);
  }
  return 0;
}

```


### Prompt

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

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).

DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are m queries, each query has one of the two types:

  1. Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
  2. Format of the query "2 l r". In reply to the query you should output the value of <image> modulo 1000000009 (109 + 9).

Help DZY reply to all the queries.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.

Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.

Output

For each query of the second type, print the value of the sum on a single line.

Examples

Input

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

Output

17
12

Note

After the first query, a = [2, 3, 5, 7].

For the second query, sum = 2 + 3 + 5 + 7 = 17.

After the third query, a = [2, 4, 6, 9].

For the fourth query, sum = 2 + 4 + 6 = 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e5 + 5;
const int MOD = (int)1e9 + 9;
struct Mat {
  long long int m[2][2];
  Mat() {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        m[i][j] = 0;
      }
    }
  }
  Mat(bool id) {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        m[i][j] = 1;
      }
    }
    if (id) {
      m[0][1] = m[1][0] = 0;
    } else {
      m[1][1] = 0;
    }
  }
  Mat operator*(const Mat& a) {
    Mat ans = Mat{};
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        for (int k = 0; k < 2; k++) {
          ans.m[i][j] += m[i][k] * a.m[k][j];
          ans.m[i][j] %= MOD;
        }
      }
    }
    return ans;
  }
  Mat operator+(const Mat& a) {
    Mat ans = Mat{};
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        ans.m[i][j] += m[i][j] + a.m[i][j];
        if (ans.m[i][j] > MOD) {
          ans.m[i][j] -= MOD;
        }
      }
    }
    return ans;
  }
};
struct Node {
  long long int sum;
  long long int Aup, Bup;
  Node() { sum = Aup = Bup = 0; }
};
long long int a[MAXN];
Mat pw[MAXN];
Mat sum_pw[MAXN];
Node tree[4 * MAXN];
void pushdown(int node, int a, int b, long long int Aup, long long int Bup) {
  if (a == b) {
    return;
  }
  int mid = (a + b) / 2;
  tree[node * 2].Aup += Aup;
  tree[node * 2].Bup += Bup;
  tree[node * 2].Aup %= MOD;
  tree[node * 2].Bup %= MOD;
  long long int nAup =
      (pw[mid - a + 1].m[1][0] * Bup + pw[mid - a + 1].m[1][1] * Aup) % MOD;
  long long int nBup =
      (pw[mid - a + 1].m[0][0] * Bup + pw[mid - a + 1].m[0][1] * Aup) % MOD;
  tree[node * 2 + 1].Aup += nAup;
  tree[node * 2 + 1].Aup %= MOD;
  tree[node * 2 + 1].Bup += nBup;
  tree[node * 2 + 1].Bup %= MOD;
  return;
}
void resolve_lazy(int node, int a, int b) {
  if (tree[node].Aup != 0 || tree[node].Bup != 0) {
    tree[node].sum += sum_pw[b - a].m[1][0] * tree[node].Bup +
                      sum_pw[b - a].m[1][1] * tree[node].Aup;
    tree[node].sum %= MOD;
    pushdown(node, a, b, tree[node].Aup, tree[node].Bup);
    tree[node].Aup = tree[node].Bup = 0;
  }
  return;
}
void update(int node, int a, int b, int l, int r, long long int Aup,
            long long int Bup) {
  resolve_lazy(node, a, b);
  if (b < l || a > r || a > b) {
    return;
  }
  if (l <= a && b <= r) {
    tree[node].sum += sum_pw[b - a].m[1][0] * Bup + sum_pw[b - a].m[1][1] * Aup;
    tree[node].sum %= MOD;
    pushdown(node, a, b, Aup, Bup);
    return;
  }
  int mid = (a + b) / 2;
  update(node * 2, a, mid, l, r, Aup, Bup);
  long long int nAup = (pw[max(0, mid - max(a, l) + 1)].m[1][0] * Bup +
                        pw[max(0, mid - max(a, l) + 1)].m[1][1] * Aup) %
                       MOD;
  long long int nBup = (pw[max(0, mid - max(a, l) + 1)].m[0][0] * Bup +
                        pw[max(0, mid - max(a, l) + 1)].m[0][1] * Aup) %
                       MOD;
  update(node * 2 + 1, mid + 1, b, l, r, nAup, nBup);
  tree[node].sum = tree[node * 2].sum + tree[node * 2 + 1].sum;
  tree[node].sum %= MOD;
  return;
}
long long int query(int node, int a, int b, int l, int r) {
  resolve_lazy(node, a, b);
  if (b < l || a > r || a > b) {
    return 0;
  }
  if (l <= a && b <= r) {
    return tree[node].sum;
  }
  int mid = (a + b) / 2;
  long long int q1 = query(node * 2, a, mid, l, r);
  long long int q2 = query(node * 2 + 1, mid + 1, b, l, r);
  return (q1 + q2) % MOD;
}
int main(void) {
  int n, m;
  int op, l, r;
  scanf(" %d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf(" %lld", &a[i]);
    a[i] += a[i - 1];
  }
  pw[0] = Mat(true);
  pw[1] = Mat(false);
  for (int i = 2; i <= n; i++) {
    pw[i] = pw[i - 1] * pw[1];
  }
  sum_pw[0] = Mat(true);
  for (int i = 1; i <= n; i++) {
    sum_pw[i] = pw[i] + sum_pw[i - 1];
  }
  while (m--) {
    scanf(" %d %d %d", &op, &l, &r);
    if (op == 1) {
      update(1, 1, n, l, r, 1, 1);
    } else {
      long long int ans = (a[r] - a[l - 1] + query(1, 1, n, l, r)) % MOD;
      printf("%lld\n", ans);
    }
  }
  return 0;
}

```


### Prompt

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

The Little Elephant enjoys recursive functions.

This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows:

  * If x = 1, exit the function.
  * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a).

The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order.

Input

A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation.

Output

In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces.

It is guaranteed that the answer exists.

Examples

Input

1

Output

1

Input

2

Output

2 1

### Response

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

```


### Prompt

Construct a CPP code solution to the problem outlined:

Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.

They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai.

A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.

Input

The first line contains an integer n (1 ≤ n ≤ 105) — the number of cards Conan has.

The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number on the i-th card.

Output

If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes).

Examples

Input

3
4 5 7

Output

Conan

Input

2
1 1

Output

Agasa

Note

In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.

In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3fLL;
const int EPS = 1e-6;
const long long mod = 1000000007;
int a[100010];
int maior[100010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  int last = a[n - 1];
  int num = 0;
  int ind = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == last) {
      maior[ind]++;
    } else {
      ind++;
      maior[ind]++;
      last = a[i];
    }
  }
  if (num % 2 == 1) {
    puts("Conan");
  } else {
    for (int i = 0; i <= ind; i++) {
      if (maior[i] % 2 == 1) {
        puts("Conan");
        return 0;
      }
    }
    puts("Agasa");
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n.

Bob gave you all the values of ai, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.

Input

The first line of the input will contain a single integer n (2 ≤ n ≤ 50).

The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the information given.

Output

Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.

Examples

Input

2
0 1
1 0

Output

2 1

Input

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

Output

2 5 4 1 3

Note

In the first case, the answer can be {1, 2} or {2, 1}.

In the second case, another possible answer is {2, 4, 5, 1, 3}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int x[100] = {0};
long long int a[100][100];
int solve() {
  long long int i, j, k, y, z, m, n, u, v, l, r, t, mx, mn, p;
  cin >> n;
  u = 0;
  for (i = 0; i < n; i++) {
    for (k = 0; k <= n; k++) x[k] = 0;
    mx = 0;
    for (j = 0; j < n; j++) {
      cin >> a[i][j];
      if (i != j) x[a[i][j]]++;
      if (x[a[i][j]] > mx) {
        mx = x[a[i][j]];
        v = a[i][j];
      }
    }
    if (*max_element(x, x + n + 1) >= 2) {
      cout << v << " ";
    } else {
      if (u == 0) {
        cout << n << " ";
        u++;
      } else if (u == 1) {
        cout << n - 1 << " ";
      }
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.

Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if n = 3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.

Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.

Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of digits in the cards Sherlock and Moriarty are going to use.

The second line contains n digits — Sherlock's credit card number.

The third line contains n digits — Moriarty's credit card number.

Output

First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.

Examples

Input

3
123
321

Output

0
2

Input

2
88
00

Output

2
0

Note

First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const double PI = 3.14159265359;
const int mod = 1e9 + 7;
const int inf = INT_MAX;
const long long inf64 = LLONG_MAX;
const unsigned long long uinf64 = ULLONG_MAX;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string a, b;
  cin >> n >> a >> b;
  vector<int> have_f(10, 0), have_s(10, 0);
  for (int i = 0; i < int(n); ++i) {
    ++have_f[a[i] - '0'];
    ++have_s[b[i] - '0'];
  }
  int min_Moriarty_get = 0;
  int max_Sherlock_get = 0;
  for (int i = 0; i < int(n); ++i) {
    int tg = b[i] - '0';
    while (have_f[tg] == 0 && tg > 0) tg--;
    if (have_f[tg] > 0) {
      have_f[tg]--;
    } else {
      ++min_Moriarty_get;
    }
    tg = a[i] - '0';
    int g = tg + 1;
    if (g == 10) continue;
    while (g < 9 && have_s[g] == 0) ++g;
    if (have_s[g] > 0) {
      --have_s[g];
      ++max_Sherlock_get;
    }
  }
  cout << min_Moriarty_get << "\n";
  cout << max_Sherlock_get << "\n";
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Ashish and Vivek play a game on a matrix consisting of n rows and m columns, where they take turns claiming cells. Unclaimed cells are represented by 0, while claimed cells are represented by 1. The initial state of the matrix is given. There can be some claimed cells in the initial state.

In each turn, a player must claim a cell. A cell may be claimed if it is unclaimed and does not share a row or column with any other already claimed cells. When a player is unable to make a move, he loses and the game ends.

If Ashish and Vivek take turns to move and Ashish goes first, determine the winner of the game if both of them are playing optimally.

Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves.

Input

The first line consists of a single integer t (1 ≤ t ≤ 50) — the number of test cases. The description of the test cases follows.

The first line of each test case consists of two space-separated integers n, m (1 ≤ n, m ≤ 50) — the number of rows and columns in the matrix.

The following n lines consist of m integers each, the j-th integer on the i-th line denoting a_{i,j} (a_{i,j} ∈ \{0, 1\}).

Output

For each test case if Ashish wins the game print "Ashish" otherwise print "Vivek" (without quotes).

Example

Input

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

Output

Vivek
Ashish
Vivek
Ashish

Note

For the first case: One possible scenario could be: Ashish claims cell (1, 1), Vivek then claims cell (2, 2). Ashish can neither claim cell (1, 2), nor cell (2, 1) as cells (1, 1) and (2, 2) are already claimed. Thus Ashish loses. It can be shown that no matter what Ashish plays in this case, Vivek will win.

For the second case: Ashish claims cell (1, 1), the only cell that can be claimed in the first move. After that Vivek has no moves left.

For the third case: Ashish cannot make a move, so Vivek wins.

For the fourth case: If Ashish claims cell (2, 3), Vivek will have no moves left.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[55][55];
int main() {
  int cs;
  scanf("%d", &cs);
  while (cs--) {
    int n, m;
    scanf("%d %d", &n, &m);
    int col = 0, row = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    for (int i = 0; i < n; i++) {
      bool flag = true;
      for (int j = 0; j < m; j++) {
        if (a[i][j] & 1) {
          flag = false;
          break;
        }
      }
      if (flag) row++;
    }
    for (int i = 0; i < m; i++) {
      bool flag = true;
      for (int j = 0; j < n; j++) {
        if (a[j][i] & 1) {
          flag = false;
          break;
        }
      }
      if (flag) col++;
    }
    if (min(col, row) % 2)
      puts("Ashish");
    else
      puts("Vivek");
  }
  return 0;
}

```


### Prompt

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

The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.

Find any longest k-good segment.

As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The first line contains two integers n, k (1 ≤ k ≤ n ≤ 5·105) — the number of elements in a and the parameter k.

The second line contains n integers ai (0 ≤ ai ≤ 106) — the elements of the array a.

Output

Print two integers l, r (1 ≤ l ≤ r ≤ n) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.

Examples

Input

5 5
1 2 3 4 5

Output

1 5

Input

9 3
6 5 1 2 3 2 1 4 5

Output

3 7

Input

3 1
1 2 3

Output

1 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxA = 1000000;
pair<int, int> getMax(pair<int, int> a, pair<int, int> b) {
  if (a.second - a.first > b.second - b.first)
    return a;
  else
    return b;
}
int main() {
  int n, k, i, a;
  pair<int, int> result(-1, -1);
  cin >> n >> k;
  queue<int> q;
  int fr[maxA + 1] = {}, differentValues = 0;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (!fr[a]) {
      differentValues++;
      q.push(a);
      fr[a]++;
      while (differentValues > k) {
        fr[q.front()]--;
        if (!fr[q.front()]) differentValues--;
        q.pop();
      }
    } else
      q.push(a), fr[a]++;
    result = getMax(result, make_pair(i - ((int)q.size() - 1), i));
  }
  cout << result.first + 1 << ' ' << result.second + 1;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.
The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

* C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.
* Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

* N is an integer between 1 and 100 (inclusive).
* x_i and y_i are integers between 0 and 100 (inclusive).
* h_i is an integer between 0 and 10^9 (inclusive).
* The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.
* The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Examples

Input

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

Output

2 2 6

Input

2
0 0 100
1 1 98

Output

0 0 100

Input

3
99 1 191
100 1 192
99 0 192

Output

100 0 193

### Response

```cpp
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x[101],y[101],h[101],X,Y,H,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {scanf("%d%d%d",&x[i],&y[i],&h[i]);if(h[i]) {H=h[i];Y=y[i];X=x[i];}}
	for(int i=0;i<=100;++i) {
		for(int j=0;j<=100;++j) {
			ans=H+abs(X-i)+abs(Y-j);
			bool flag=false;
			for(int k=1;k<=n;++k) if((ans-abs(i-x[k])-abs(j-y[k])!=h[k]&&ans-abs(i-x[k])-abs(j-y[k])>=0)||(ans-abs(i-x[k])-abs(j-y[k])<0&&h[k]!=0))
			{flag=true;break;}
			if(!flag) {printf("%d %d %d\n",i,j,ans);return 0;}
		}
	}
	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.

To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.

Input

The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m (<image>) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names — the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.

Output

The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.

Examples

Input

3 1
Petya
Vasya
Masha
Petya Vasya

Output

2
Masha
Petya

Input

3 0
Pasha
Lesha
Vanya

Output

3
Lesha
Pasha
Vanya

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = (int)1e9;
map<string, int> mm;
const int maxn = 110;
int a[maxn][maxn];
int bc[maxn * maxn * 10];
string ss[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    ss[i] = s;
    mm[s] = i;
  }
  string s1, s2;
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    a[mm[s1]][mm[s2]] = 1;
    a[mm[s2]][mm[s1]] = 1;
  }
  for (int i = 1; i < (1 << n); i++) bc[i] = bc[i >> 1] + (i & 1);
  int res = 0, resm = 0;
  for (int i = 1; i < (1 << n); i++) {
    vector<int> v;
    for (int j = 0; j < n; j++)
      if ((i >> j) & 1) v.push_back(j);
    int good = 1;
    for (int i1 = 0; i1 < ((int)(v).size()) && good; i1++)
      for (int i2 = 0; i2 < ((int)(v).size()) && good; i2++)
        if (a[v[i1]][v[i2]]) good = 0;
    if (good && bc[i] > res) res = bc[i], resm = i;
  }
  cout << res << endl;
  vector<string> vs;
  for (int i = 0; i < n; i++)
    if ((resm >> i) & 1) vs.push_back(ss[i]);
  sort(vs.begin(), vs.end());
  for (int i = 0; i < ((int)(vs).size()); i++) cout << vs[i] << endl;
  return 0;
}

```


### Prompt

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

Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them.

The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification.

Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way.

Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches.

Input

The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present.

The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks.

Output

Print one integer — the square of the largest possible distance from (0, 0) to the tree end.

Examples

Input

3
1 2 3

Output

26

Input

4
1 1 2 2

Output

20

Note

The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20.

<image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.precision(17);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long sa = 0, sb = 0;
  for (long long i = 0; i < n / 2; i++) sa += a[i];
  for (long long i = 0; i < n; i++) sb += a[i];
  sb -= sa;
  cout << sa * sa + sb * sb << endl;
  return 0;
}

```


### Prompt

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

RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1.

<image>
Figure B-1: Layout of the exchange lines

A freight train consists of 2 to 72 freight cars. There are 26 types of freight cars, which are denoted by 26 lowercase letters from "a" to "z". The cars of the same type are indistinguishable from each other, and each car's direction doesn't matter either. Thus, a string of lowercase letters of length 2 to 72 is sufficient to completely express the configuration of a train.

Upon arrival at the exchange lines, a train is divided into two sub-trains at an arbitrary position (prior to entering the storage lines). Each of the sub-trains may have its direction reversed (using the reversal line). Finally, the two sub-trains are connected in either order to form the final configuration. Note that the reversal operation is optional for each of the sub-trains.

For example, if the arrival configuration is "abcd", the train is split into two sub-trains of either 3:1, 2:2 or 1:3 cars. For each of the splitting, possible final configurations are as follows ("+" indicates final concatenation position):

[3:1]
abc+d  cba+d  d+abc  d+cba
[2:2]
ab+cd  ab+dc  ba+cd  ba+dc  cd+ab  cd+ba  dc+ab  dc+ba
[1:3]
a+bcd  a+dcb  bcd+a  dcb+a

Excluding duplicates, 12 distinct configurations are possible.

Given an arrival configuration, answer the number of distinct configurations which can be constructed using the exchange lines described above.

Input

The entire input looks like the following.

> the number of datasets = m
>  1st dataset
>  2nd dataset
>  ...
>  m-th dataset
>

Each dataset represents an arriving train, and is a string of 2 to 72 lowercase letters in an input line.

Output

For each dataset, output the number of possible train configurations in a line. No other characters should appear in the output.

Example

Input

4
aa
abba
abcd
abcde

Output

1
6
12
18

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

int main()
{
	int m; cin >> m;
	rep(_m, 0, m)
	{
		string s; cin >> s;

		set<string> _set;
		_set.insert(s);
		rep(i, 1, s.length())
		{
			string a = s.substr(0, i);
			string b = s.substr(i);

			string aa = a;
			reverse(aa.begin(), aa.end());

			string bb = b;
			reverse(bb.begin(), bb.end());

			_set.insert(a + bb);
			_set.insert(aa + b);
			_set.insert(aa + bb);
			_set.insert(b + a);
			_set.insert(b + aa);
			_set.insert(bb + a);
			_set.insert(bb + aa);
		}

		cout << _set.size() << endl;
	}
}
```


### Prompt

Generate a CPP solution to the following problem:

The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.

<image>

The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.

In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.

Input

The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.

Output

Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.

Examples

Input

9

Output

+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+

Input

20

Output

+------------------------+
|O.O.O.O.O.O.O.#.#.#.#.|D|)
|O.O.O.O.O.O.#.#.#.#.#.|.|
|O.......................|
|O.O.O.O.O.O.#.#.#.#.#.|.|)
+------------------------+

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool b[11][4];
int main() {
  int k;
  cin >> k;
  if (k > 0) b[0][0] = 1;
  if (k > 1) b[0][1] = 1;
  if (k > 2) b[0][2] = 1;
  if (k > 3) b[0][3] = 1;
  if (k > 4) {
    k = k - 4;
    int r = k % 3;
    int x = k / 3;
    for (int i = 1; i <= x; i++) {
      b[i][0] = 1;
      b[i][1] = 1;
      b[i][3] = 1;
    }
    if (r >= 1) b[x + 1][0] = 1;
    if (r >= 2) b[x + 1][1] = 1;
  }
  cout << '+';
  for (int i = 0; i < 24; i++) cout << '-';
  cout << '+';
  cout << endl;
  cout << '|';
  for (int i = 0; i < 11; i++) {
    if (b[i][0] == 1)
      cout << 'O' << '.';
    else
      cout << '#' << '.';
  }
  cout << "|D|)" << endl;
  cout << '|';
  for (int i = 0; i < 11; i++) {
    if (b[i][1] == 1)
      cout << 'O' << '.';
    else
      cout << '#' << '.';
  }
  cout << "|.|" << endl;
  cout << '|';
  if (b[0][2] == 1)
    cout << 'O' << '.';
  else
    cout << '#' << '.';
  for (int i = 0; i < 20; i++) cout << '.';
  cout << "..|" << endl;
  cout << '|';
  for (int i = 0; i < 11; i++) {
    if (b[i][3] == 1)
      cout << 'O' << '.';
    else
      cout << '#' << '.';
  }
  cout << "|.|)" << endl;
  cout << "+------------------------+" << endl;
  return 0;
}

```


### Prompt

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

Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.

He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.

Input

The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.

Output

Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.

Examples

Input

1 1 1 1 1 1

Output

6

Input

1 2 1 2 1 2

Output

13

Note

This is what Gerald's hexagon looks like in the first sample:

<image>

And that's what it looks like in the second sample:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f;
int main() {
  cin >> a >> b >> c >> d >> e >> f;
  long long t = (e + f) * (4ll * a + 2ll * f + 2ll * b);
  long long s = (f * f + e * e + b * b + c * c);
  long long ans = t - s;
  assert(ans % 2ll == 0ll);
  cout << ans / 2ll << endl;
}

```


### Prompt

Generate a Cpp solution to the following problem:

You have to handle a very complex water distribution system. The system consists of n junctions and m pipes, i-th pipe connects junctions x_i and y_i.

The only thing you can do is adjusting the pipes. You have to choose m integer numbers f_1, f_2, ..., f_m and use them as pipe settings. i-th pipe will distribute f_i units of water per second from junction x_i to junction y_i (if f_i is negative, then the pipe will distribute |f_i| units of water per second from junction y_i to junction x_i). It is allowed to set f_i to any integer from -2 ⋅ 10^9 to 2 ⋅ 10^9.

In order for the system to work properly, there are some constraints: for every i ∈ [1, n], i-th junction has a number s_i associated with it meaning that the difference between incoming and outcoming flow for i-th junction must be exactly s_i (if s_i is not negative, then i-th junction must receive s_i units of water per second; if it is negative, then i-th junction must transfer |s_i| units of water per second to other junctions).

Can you choose the integers f_1, f_2, ..., f_m in such a way that all requirements on incoming and outcoming flows are satisfied?

Input

The first line contains an integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of junctions.

The second line contains n integers s_1, s_2, ..., s_n (-10^4 ≤ s_i ≤ 10^4) — constraints for the junctions.

The third line contains an integer m (0 ≤ m ≤ 2 ⋅ 10^5) — the number of pipes.

i-th of the next m lines contains two integers x_i and y_i (1 ≤ x_i, y_i ≤ n, x_i ≠ y_i) — the description of i-th pipe. It is guaranteed that each unordered pair (x, y) will appear no more than once in the input (it means that there won't be any pairs (x, y) or (y, x) after the first occurrence of (x, y)). It is guaranteed that for each pair of junctions there exists a path along the pipes connecting them.

Output

If you can choose such integer numbers f_1, f_2, ..., f_m in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output m lines, i-th line should contain f_i — the chosen setting numbers for the pipes. Pipes are numbered in order they appear in the input.

Otherwise output "Impossible" in the only line.

Examples

Input

4
3 -10 6 1
5
1 2
3 2
2 4
3 4
3 1

Output

Possible
4
-6
8
-7
7

Input

4
3 -10 6 4
5
1 2
3 2
2 4
3 4
3 1

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int Pow(long long int a, long long int b, long long int md,
                  long long int ans = 1) {
  for (; b; b >>= 1, a = a * a % md)
    if (b & 1) ans = ans * a % md;
  return ans % md;
}
const long long int MAXN = 1e6 + 10;
const long long int INF = 8e18;
const long long int MOD = 1e9 + 7;
long long int U[MAXN], V[MAXN], par[MAXN], mark[MAXN], ans[MAXN], deg[MAXN],
    A[MAXN], d[MAXN], n, m, sum = 0;
vector<long long int> adj[2][MAXN];
map<pair<long long int, long long int>, long long int> ind;
void DFS(long long int v) {
  mark[v] = 1;
  for (long long int u : adj[0][v]) {
    if (mark[u] == 1) continue;
    d[u]++, d[v]++;
    adj[1][u].push_back(v);
    adj[1][v].push_back(u);
    par[u] = v;
    DFS(u);
  }
}
void BFS() {
  queue<long long int> Q;
  for (long long int i = 2; i <= n; i++) {
    if ((long long int)adj[1][i].size() == 1) Q.push(i);
  }
  while ((long long int)Q.size()) {
    long long int x, v = Q.front();
    Q.pop();
    x = A[v] - deg[v];
    deg[par[v]] -= x;
    ans[ind[{v, par[v]}]] = ans[ind[{par[v], v}]] = x;
    d[par[v]]--;
    if (d[par[v]] == 1) Q.push(par[v]);
  }
}
int main() {
  scanf("%lld", &n);
  for (long long int i = 1; i <= n; i++) scanf("%lld", &A[i]), sum += A[i];
  scanf("%lld", &m);
  for (long long int i = 1; i <= m; i++) {
    long long int u, v;
    scanf("%lld%lld", &u, &v);
    adj[0][v].push_back(u);
    adj[0][u].push_back(v);
    ind[{u, v}] = ind[{v, u}] = i, U[i] = u, V[i] = v;
  }
  if (sum != 0) return !printf("Impossible\n");
  DFS(1);
  BFS();
  printf("Possible\n");
  for (long long int i = 1; i <= m; i++) {
    long long int u = U[i], v = V[i];
    if (par[u] == v)
      printf("%lld\n", -ans[i]);
    else
      printf("%lld\n", ans[i]);
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx.

You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other?

Constraints

* 2 \leq N \leq 200\,000
* S_i consists of lowercase English letters `a`-`z`.
* S_i \neq S_j
* 1 \leq |S_i|
* |S_1| + |S_2| + \ldots + |S_N| \leq 10^6

Input

Input is given from Standard Input in the following format.

N
S_1
S_2
\vdots
S_N

Output

Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other.

Examples

Input

3
abcxyx
cyx
abc

Output

1

Input

6
b
a
abc
c
d
ab

Output

5

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define mkp make_pair
const ll H1=257,H2=114,M1=1e9+7,M2=19260817;
int n,T;
char c[1000004];
bool ok[1000004][26];
string s[200004];
int p[200004];
map<pii,int>mp;
ll ans=0;
bool cmp(int a,int b){
	return s[a].size()>s[b].size();
}
void reads(string &S){
	S="";register char ch=getchar();
	for(;ch<'a'||ch>'z';ch=getchar());
	for(;ch>='a'&&ch<='z';S+=ch,ch=getchar());
}
int main(){
	cin>>T;
	for(int i=0;i<T;i++)reads(s[i]),p[i]=i;
	sort(p,p+T,cmp);
	while(T>0){
		T--;
		n=s[p[T]].size();
		for(int i=0;i<n;i++)c[n-i-1]=s[p[T]][i];
		for(int i=0;i<26;i++)ok[n][i]=0;
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<26;j++)ok[i][j]=ok[i+1][j];
			ok[i][c[i]-'a']=1;
		}
		ll r1=0,r2=0;
		for(int i=0;i<n-1;i++){
			int msk=mp[mkp(r1,r2)];
			for(int j=0;j<26;j++)if((msk&(1<<j))>0&&ok[i][j])ans++;
			r1=(r1*H1+c[i])%M1,r2=(r2*H2+c[i])%M2;
		}
		mp[mkp(r1,r2)]|=(1<<(c[n-1]-'a'));
	}
	cout<<ans;
}
```


### Prompt

Please create a solution in cpp to the following problem:

We have a grid with N rows and N columns. The cell at the i-th row and j-th column is denoted (i, j).

Initially, M of the cells are painted black, and all other cells are white. Specifically, the cells (a_1, b_1), (a_2, b_2), ..., (a_M, b_M) are painted black.

Snuke will try to paint as many white cells black as possible, according to the following rule:

* If two cells (x, y) and (y, z) are both black and a cell (z, x) is white for integers 1≤x,y,z≤N, paint the cell (z, x) black.

Find the number of black cells when no more white cells can be painted black.

Constraints

* 1≤N≤10^5
* 1≤M≤10^5
* 1≤a_i,b_i≤N
* All pairs (a_i, b_i) are distinct.

Input

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

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print the number of black cells when no more white cells can be painted black.

Examples

Input

3 2
1 2
2 3

Output

3

Input

2 2
1 1
1 2

Output

4

Input

4 3
1 2
1 3
4 4

Output

3

### Response

```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define maxn 100010

using namespace std;
typedef long long llg;

int hd[maxn],nt[maxn<<1],to[maxn<<1],c[maxn<<1],tt;
int n,m,co[maxn],SIZ,cm,du[maxn];
bool vis[maxn],su;
llg ans,ci[3];

void dfs(int u){
	vis[u]=1; SIZ++; ci[co[u]]++; cm+=du[u];
	for(int i=hd[u],v;v=to[i],i;i=nt[i])
		if(!vis[v]) co[v]=(co[u]+c[i])%3,dfs(v);
		else if(co[v]!=(co[u]+c[i])%3) su=1;
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1,x,y;i<=m;i++){
		scanf("%d %d",&x,&y);
		to[++tt]=y;nt[tt]=hd[x];hd[x]=tt;
		to[++tt]=x;nt[tt]=hd[y];hd[y]=tt;
		c[tt-1]=1; c[tt]=2; du[x]++,du[y]++;
	}
	for(int i=1,now;i<=n;i++)
		if(!vis[i]){
			dfs(i);
			if(su) ans+=1ll*SIZ*SIZ;
			else{
				now=(!ci[0])+(!ci[1])+(!ci[2]);
				if(!now) ans+=ci[0]*ci[1]+ci[1]*ci[2]+ci[2]*ci[0];
				else ans+=cm>>1;
			}
			ci[0]=ci[1]=ci[2]=0; SIZ=cm=0; su=0;
		}
	printf("%lld",ans);
	return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n - 1 operations of the two kinds:

  * divide the number x by 3 (x must be divisible by 3);
  * multiply the number x by 2.

After each operation, Polycarp writes down the result on the board and replaces x by the result. So there will be n numbers on the board after all.

You are given a sequence of length n — the numbers that Polycarp wrote down. This sequence is given in arbitrary order, i.e. the order of the sequence can mismatch the order of the numbers written on the board.

Your problem is to rearrange (reorder) elements of this sequence in such a way that it can match possible Polycarp's game in the order of the numbers written on the board. I.e. each next number will be exactly two times of the previous number or exactly one third of previous number.

It is guaranteed that the answer exists.

Input

The first line of the input contatins an integer number n (2 ≤ n ≤ 100) — the number of the elements in the sequence. The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 3 ⋅ 10^{18}) — rearranged (reordered) sequence that Polycarp can wrote down on the board.

Output

Print n integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board.

It is guaranteed that the answer exists.

Examples

Input

6
4 8 6 3 12 9

Output

9 3 6 12 4 8

Input

4
42 28 84 126

Output

126 42 84 28

Input

2
1000000000000000000 3000000000000000000

Output

3000000000000000000 1000000000000000000

Note

In the first example the given sequence can be rearranged in the following way: [9, 3, 6, 12, 4, 8]. It can match possible Polycarp's game which started with x = 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
  out << "(" << p.first << "," << p.second << ")";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  for (auto a : v) out << a << " ";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
  for (auto a : S) cout << a << " ";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
  for (auto a : S) cout << a << " ";
  return out;
}
template <typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
  for (auto m : M) cout << "(" << m.first << "->" << m.second << ") ";
  return out;
}
template <typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
template <typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
vector<long long> solve(vector<long long>& A) {
  int n = A.size();
  vector<pair<int, int>> B;
  for (auto a : A) {
    int order_2 = 0;
    int order_3 = 0;
    while (a % 2 == 0) {
      a /= 2;
      order_2++;
    }
    while (a % 3 == 0) {
      a /= 3;
      order_3++;
    }
    B.emplace_back(order_2, order_3);
  }
  vector<int> sa(n);
  for (int i = 0; i < n; i++) sa[i] = i;
  sort(sa.begin(), sa.end(), [&](int x, int y) {
    if (B[x].first != B[y].first) return B[x].first < B[y].first;
    return B[x].second > B[y].second;
  });
  vector<long long> ans(n);
  for (int i = 0; i < n; i++) ans[i] = A[sa[i]];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  vector<long long> A;
  cin >> n;
  A.resize(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  auto ans = solve(A);
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given a grid, consisting of 2 rows and n columns. Each cell of this grid should be colored either black or white.

Two cells are considered neighbours if they have a common border and share the same color. Two cells A and B belong to the same component if they are neighbours, or if there is a neighbour of A that belongs to the same component with B.

Let's call some bicoloring beautiful if it has exactly k components.

Count the number of beautiful bicolorings. The number can be big enough, so print the answer modulo 998244353.

Input

The only line contains two integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ 2n) — the number of columns in a grid and the number of components required.

Output

Print a single integer — the number of beautiful bicolorings modulo 998244353.

Examples

Input

3 4

Output

12

Input

4 1

Output

2

Input

1 2

Output

2

Note

One of possible bicolorings in sample 1:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
const int mod = 998244353;
long long dp[1005][2005][4];
int main() {
  scanf("%d%d", &n, &k);
  dp[1][1][0] = 1;
  dp[1][2][1] = 1;
  dp[1][2][2] = 1;
  dp[1][1][3] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= (i << 1); j++) {
      dp[i][j][0] = (dp[i][j][0] + dp[i - 1][j][0] + dp[i - 1][j][1] +
                     dp[i - 1][j][2] + dp[i - 1][j - 1][3]) %
                    mod;
      dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - 1][0] + dp[i - 1][j][1] +
                     dp[i - 1][j - 2][2] + dp[i - 1][j - 1][3]) %
                    mod;
      dp[i][j][2] = (dp[i][j][2] + dp[i - 1][j - 1][0] + dp[i - 1][j - 2][1] +
                     dp[i - 1][j][2] + dp[i - 1][j - 1][3]) %
                    mod;
      dp[i][j][3] = (dp[i][j][3] + dp[i - 1][j - 1][0] + dp[i - 1][j][1] +
                     dp[i - 1][j][2] + dp[i - 1][j][3]) %
                    mod;
    }
  }
  printf("%lld\n",
         (dp[n][k][0] + dp[n][k][1] + dp[n][k][2] + dp[n][k][3]) % mod);
}

```


### Prompt

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

You are given an array a consisting of n integers numbered from 1 to n.

Let's define the k-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length k (recall that a subsegment of a of length k is a contiguous part of a containing exactly k elements). If there is no integer occuring in all subsegments of length k for some value of k, then the k-amazing number is -1.

For each k from 1 to n calculate the k-amazing number of the array a.

Input

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

The first line of each test case contains one integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of elements in the array. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the elements of the array.

It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5.

Output

For each test case print n integers, where the i-th integer is equal to the i-amazing number of the array.

Example

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int a[N], last[N], res[N], resk[N];
int main() {
  resk[0] = 0x3f3f3f3f;
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
      scanf("%d", &a[i]), last[a[i]] = -1, resk[i] = 0x3f3f3f3f;
    for (int i = 1; i <= n; ++i) {
      if (last[a[i]] == -1)
        res[a[i]] = i;
      else
        res[a[i]] = max(res[a[i]], i - last[a[i]]);
      last[a[i]] = i;
    }
    for (int i = 1; i <= n; ++i) res[a[i]] = max(res[a[i]], n - last[a[i]] + 1);
    for (int i = 1; i <= n; ++i) {
      resk[res[a[i]]] = min(resk[res[a[i]]], a[i]);
    }
    for (int i = 1; i <= n; ++i) resk[i] = min(resk[i], resk[i - 1]);
    for (int i = 1; i <= n; ++i)
      printf("%d ", (resk[i] == 0x3f3f3f3f ? -1 : resk[i]));
    puts("");
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many!

Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size x × y × z, consisting of undestructable cells 1 × 1 × 1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value.

All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut.

Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most k times.

Vasya's character uses absolutely thin sword with infinite length.

Input

The first line of input contains four integer numbers x, y, z, k (1 ≤ x, y, z ≤ 106, 0 ≤ k ≤ 109).

Output

Output the only number — the answer for the problem.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples

Input

2 2 2 3

Output

8

Input

2 2 2 1

Output

2

Note

In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k, i, j;
  vector<long long> x, cuts(3, 0);
  for (int i = 0; i < 3; ++i) {
    int f;
    cin >> f;
    x.push_back(f);
  }
  cin >> k;
  sort(x.begin(), x.end());
  j = 0;
  while (k) {
    if (cuts[0] == x[0] - 1 && cuts[1] == x[1] - 1 && cuts[2] == x[2] - 1)
      break;
    if (cuts[j] < x[j] - 1) {
      cuts[j]++;
      k--;
    }
    j = (j + 1) % 3;
  }
  cout << (cuts[0] + 1) * (cuts[1] + 1) * (cuts[2] + 1) << "\n";
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor.

Heidi figured out that Madame Kovarian uses a very complicated hashing function in order to change the names of the babies she steals. In order to prevent this from happening to future Doctors, Heidi decided to prepare herself by learning some basic hashing techniques.

The first hashing function she designed is as follows.

Given two positive integers (x, y) she defines H(x,y):=x^2+2xy+x+1.

Now, Heidi wonders if the function is reversible. That is, given a positive integer r, can you find a pair (x, y) (of positive integers) such that H(x, y) = r?

If multiple such pairs exist, output the one with smallest possible x. If there is no such pair, output "NO".

Input

The first and only line contains an integer r (1 ≤ r ≤ 10^{12}).

Output

Output integers x, y such that H(x,y) = r and x is smallest possible, or "NO" if no such pair exists.

Examples

Input

19

Output

1 8

Input

16

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) {
  if (a > b) return b;
  return a;
}
int main() {
  unsigned long long n;
  std::cin >> n;
  if (n == 1) {
    std::cout << "NO" << '\n';
    return 0;
  }
  if (n % 2 == 0) {
    std::cout << "NO" << '\n';
    return 0;
  }
  for (unsigned long long x = 1; x <= (sqrt(4 * n - 3) - 1) / 2; x++) {
    unsigned long long t = x * x + x + 1;
    if (t < n && t % 2 != 0) {
      std::cout << x << " " << (n - t) / 2 << '\n';
      return 0;
    }
  }
  std::cout << "NO" << '\n';
  return 0;
}

```


### Prompt

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

Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`.

He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.

Constraints

* 1 \leq |S| \leq 10^5
* S consists of `a`, `b` and `c`.

Input

Input is given from Standard Input in the following format:

S

Output

If the objective is achievable, print `YES`; if it is unachievable, print `NO`.

Examples

Input

abac

Output

YES

Input

aba

Output

NO

Input

babacccabab

Output

YES

### Response

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

int main()
{
    string S;
    cin >> S;
    int num[3] = { 0 };
    for (char c : S) {
        num[c - 'a']++;
    }
    int max_num = INT_MIN, min_num = INT_MAX;
    for (int i = 0; i < 3; i++) {
        max_num = max(max_num, num[i]);
        min_num = min(min_num, num[i]);
    }
    if (max_num - min_num >= 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You are given two n × m matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly increasing. A matrix is increasing if all rows are strictly increasing and all columns are strictly increasing.

For example, the matrix \begin{bmatrix} 9&10&11\\\ 11&12&14\\\ \end{bmatrix} is increasing because each individual row and column is strictly increasing. On the other hand, the matrix \begin{bmatrix} 1&1\\\ 2&3\\\ \end{bmatrix} is not increasing because the first row is not strictly increasing.

Let a position in the i-th row (from top) and j-th column (from left) in a matrix be denoted as (i, j).

In one operation, you can choose any two numbers i and j and swap the number located in (i, j) in the first matrix with the number in (i, j) in the second matrix. In other words, you can swap two numbers in different matrices if they are located in the corresponding positions.

You would like to make both matrices increasing by performing some number of operations (possibly none). Determine if it is possible to do this. If it is, print "Possible", otherwise, print "Impossible".

Input

The first line contains two integers n and m (1 ≤ n,m ≤ 50) — the dimensions of each matrix.

Each of the next n lines contains m integers a_{i1}, a_{i2}, …, a_{im} (1 ≤ a_{ij} ≤ 10^9) — the number located in position (i, j) in the first matrix.

Each of the next n lines contains m integers b_{i1}, b_{i2}, …, b_{im} (1 ≤ b_{ij} ≤ 10^9) — the number located in position (i, j) in the second matrix.

Output

Print a string "Impossible" or "Possible".

Examples

Input

2 2
2 10
11 5
9 4
3 12

Output

Possible

Input

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

Output

Possible

Input

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

Output

Impossible

Note

The first example, we can do an operation on the top left and bottom right cells of the matrices. The resulting matrices will be \begin{bmatrix} 9&10\\\ 11&12\\\ \end{bmatrix} and \begin{bmatrix} 2&4\\\ 3&5\\\ \end{bmatrix}.

In the second example, we don't need to do any operations.

In the third example, no matter what we swap, we can't fix the first row to be strictly increasing in both matrices.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll N = 1e9 + 7, N1 = 1e6 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  ll n, m;
  cin >> n >> m;
  ll a[n][m], b[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n - 1; j++) {
      if (a[j + 1][i] <= a[j][i]) {
        if (b[j + 1][i] > a[j][i] && a[j + 1][i] > b[j][i]) {
          swap(b[j + 1][i], a[j + 1][i]);
        } else {
          cout << "Impossible"
               << "\n";
          return 0;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m - 1; j++) {
      if (a[i][j + 1] <= a[i][j]) {
        if (b[i][j + 1] > a[i][j] && a[i][j + 1] > b[i][j]) {
          swap(b[i][j + 1], a[i][j + 1]);
        } else {
          cout << "Impossible"
               << "\n";
          return 0;
        }
      }
    }
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n - 1; j++) {
      if (b[j + 1][i] <= b[j][i]) {
        if (a[j + 1][i] > b[j][i] && b[j + 1][i] > a[j][i]) {
          swap(b[j + 1][i], a[j + 1][i]);
        } else {
          cout << "Impossible"
               << "\n";
          return 0;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m - 1; j++) {
      if (b[i][j + 1] <= b[i][j]) {
        if (a[i][j + 1] > b[i][j] && b[i][j + 1] > a[i][j]) {
          swap(b[i][j + 1], a[i][j + 1]);
        } else {
          cout << "Impossible"
               << "\n";
          return 0;
        }
      }
    }
  }
  cout << "Possible"
       << "\n";
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

A stowaway and a controller play the following game.

The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move.

The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move.

The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back.

Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train.

If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again.

At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner.

Input

The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≤ n ≤ 50, 1 ≤ m, k ≤ n, m ≠ k).

The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail.

The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station.

Output

If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught.

Examples

Input

5 3 2
to head
0001001

Output

Stowaway

Input

3 2 1
to tail
0001

Output

Controller 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dx[2] = {1, -1};
void go(char s[], int n, int stowaway, int controller, int dir) {
  int T = 0;
  for (int i = 1; s[i]; ++i) {
    if (s[i] == '1') {
      controller += dx[dir];
      if (controller == n || controller == 1) dir ^= 1;
      if (controller == 1) {
        stowaway = n;
      } else if (controller == n) {
        stowaway = 1;
      } else {
        if (dir == 0)
          stowaway = 1;
        else
          stowaway = n;
      }
    } else {
      if (controller > stowaway && dir == 1 ||
          controller < stowaway && dir == 0) {
        stowaway += dx[dir];
        if (stowaway < 1 || stowaway > n) stowaway -= dx[dir];
      }
      controller += dx[dir];
      if (controller == n || controller == 1) dir ^= 1;
    }
    if (controller == stowaway) {
      T = i;
      break;
    }
  }
  if (T) {
    printf("Controller %d\n", T);
  } else {
    puts("Stowaway");
  }
}
int main() {
  char buf[210];
  int n, m, k;
  while (cin >> n >> m >> k) {
    scanf("%s%s", buf, buf);
    int dir = buf[0] == 'h';
    scanf("%s", buf + 1);
    go(buf, n, m, k, dir);
  }
  return 0;
}

```


### Prompt

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

Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!

Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.

<image>

To reach the goal, Egor should research the next topic:

There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.

In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:

  1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
  2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
  3. If all cells are already visited, the process is stopped.

Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.

Input

The only line contains one integer N — the size of the board, 1≤ N ≤ 500.

Output

The output should contain N lines.

In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.

On your board rook must pay strictly less vuns than the queen.

If there are no solutions, print -1.

If there are several solutions, you can output any of them.

Examples

Input

1

Output

-1

Input

4

Output

4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2

Note

In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.

In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.

Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.

As a result rook pays 1 vun and queen pays 2 vuns.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  if (n < 3) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n - 3; i++) {
    for (int j = 1; j <= n; j++) {
      if ((n % 2 && !(i % 2)) || (!(n % 2) && i % 2))
        cout << j + i * n << " ";
      else
        cout << (i + 1) * n - j + 1 << " ";
    }
    cout << "\n";
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n - 3; j++) {
      cout << n * n - 9 - i * (n - 3) - j << " ";
    }
    if (i == 0)
      cout << 1 + n * n - 9 << " " << 7 + n * n - 9 << " " << 9 + n * n - 9
           << "\n";
    if (i == 1)
      cout << 3 + n * n - 9 << " " << 2 + n * n - 9 << " " << 5 + n * n - 9
           << "\n";
    if (i == 2)
      cout << 4 + n * n - 9 << " " << 8 + n * n - 9 << " " << 6 + n * n - 9
           << "\n";
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:

<image>

Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).

Input

The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn is the number of permutations of length n with maximum possible value of f(p).

The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.

  * In subproblem B1 (3 points), the constraint 1 ≤ n ≤ 8 will hold.
  * In subproblem B2 (4 points), the constraint 1 ≤ n ≤ 50 will hold.

Output

Output n number forming the required permutation.

Examples

Input

2 2

Output

2 1

Input

3 2

Output

1 3 2

Note

In the first example, both permutations of numbers {1, 2} yield maximum possible f(p) which is equal to 4. Among them, (2, 1) comes second in lexicographical order.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
vector<pair<int, string> > v;
int x[10], n, m;
bool d[10];
void makep() {
  int res;
  string s;
  res = 0;
  s = "0";
  for (int i = 1; i <= n; i++) {
    s += "0";
    s[i] = (char)(x[i] + 48);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int t = 1000;
      for (int k = i; k <= j; k++) t = min(t, x[k]);
      res += t;
    }
  }
  v.push_back(pair<int, string>(res, s));
}
void make(int pos) {
  for (int l = 1; l <= n; l++)
    if (!d[l]) {
      x[pos] = l;
      d[l] = 1;
      if (pos == n)
        makep();
      else
        make(pos + 1);
      d[l] = 0;
    }
}
bool smaller(string X, string y) {
  for (int i = 1; i < X.length(); i++)
    if (X[i] < y[i])
      return true;
    else if (X[i] > y[i])
      return false;
  return false;
}
bool comp(pair<int, string> X, pair<int, string> y) {
  if (X.first > y.first) return true;
  if ((X.first == y.first) && smaller(X.second, y.second)) {
    return true;
  }
  return false;
}
int main() {
  cin >> n >> m;
  make(1);
  sort(v.begin(), v.end(), comp);
  string s = v[m - 1].second;
  for (int i = 1; i <= n; i++) {
    cout << s[i] << ' ';
  }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Write a program which prints multiplication tables in the following format:

1x1=1
1x2=2
.
.
9x8=72
9x9=81

Input

No input.

Output

1x1=1
1x2=2
.
.
9x8=72
9x9=81

Example

Input

Output

### Response

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

int main(){
	for(int a=0;a<9;a++){
		for(int b=0;b<9;b++)cout<<a+1<<'x'<<b+1<<'='<<(a+1)*(b+1)<<endl;
		}
	}
```


### Prompt

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

PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.

He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:

Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertex x + k or x + k - n depending on which of these is a valid index of polygon's vertex.

Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.

Input

There are only two numbers in the input: n and k (5 ≤ n ≤ 106, 2 ≤ k ≤ n - 2, gcd(n, k) = 1).

Output

You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.

Examples

Input

5 2

Output

2 3 5 8 11

Input

10 3

Output

2 3 4 6 9 12 16 21 26 31

Note

The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.

For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.

<image> <image> <image> <image> <image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
string toBin(long long a) {
  string res = "";
  while (a) {
    res += char((a & 1) + '0');
    a >>= 1;
  }
  reverse(res.begin(), res.end());
  return res;
}
const int mod = 1e9 + 7;
long long expo(long long base, long long pow) {
  long long ans = 1;
  while (pow != 0) {
    if (pow & 1 == 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base *= base;
    base %= mod;
    pow /= 2;
  }
  return ans;
}
long long inv(long long x) { return expo(x, mod - 2); }
bool isPal(string ss) {
  int len = ss.length();
  for (int i = 0; i < len / 2; i++) {
    int comp = len - i - 1;
    if (ss[i] != ss[comp]) return false;
  }
  return true;
}
double pi = 3.141592653589793238462643;
double error = 0.0000001;
const int M = 1001111;
vector<int> BIT(M);
long long res = 1;
int isP[222];
int N, K, X = 0;
void sieve() {
  isP[1] = 1;
  for (int i = 2; i < 100; i++) {
    if (isP[i]) continue;
    for (long long j = i * 1LL * i; j < 100; j += i) {
      isP[j] = 1;
    }
  }
}
long long dofor(int a, int b) {
  long long ult = 0;
  for (int r = b + 1; r > 0; r -= r & -r) ult += BIT[r];
  for (int l = a; l > 0; l -= l & -l) ult -= BIT[l];
  if (a > b) {
    for (int r = N; r > 0; r -= r & -r) ult += BIT[r];
  }
  return ult;
}
void read() {
  cin >> N >> K;
  K = min(K, N - K);
}
void print(long long ans) { printf("%lld ", ans); }
void up(int we) {
  we = we + 1;
  for (; we < M; we += we & -we) BIT[we]++;
}
void solve() {
  for (int i = 0; i < N; i++) {
    int st = (X + 1) % N;
    int en = (X + K - 1) % N;
    res += dofor(st, en) + 1;
    print(res);
    up(X);
    up((X + K) % N);
    X = (X + K) % N;
  }
}
int main() {
  sieve();
  read();
  solve();
}

```


### Prompt

Please create a solution in CPP to the following problem:

Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.

He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.

Find the maximum number of integers that Snuke can circle.

Constraints

* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.

Input

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

N
s_1
:
s_N

Output

Print the maximum number of integers that Snuke can circle.

Examples

Input

8
1
2
3
4
5
6
7
8

Output

6

Input

6
2
4
8
16
32
64

Output

3

Input

10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999

Output

9

### Response

```cpp
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

typedef long long LL;

const int N=100005;

int n;
LL a[N],b[N];
map<LL,int> ma;

LL sqr(LL x)
{
    return x*x;
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        LL x;scanf("%lld",&x);
        for (LL j=2;j*j*j<=x;j++)
            while (x%(j*j*j)==0) x/=j*j*j;
        ma[x]++;a[i]=x;
        LL y=1;
        for (LL j=2;j*j*j<=x;j++)
            if (x%j==0)
            {
                y*=(x%(j*j)==0)?j:j*j;
                while (x%j==0) x/=j;
            }
        if (sqr((LL)sqrt(x))==x) y*=(LL)sqrt(x);
        else y*=x*x;
        b[i]=y;
    }
    int ans=0;
    if (ma[1]) ans++,ma[1]=0;
    for (int i=1;i<=n;i++) ans+=max(ma[a[i]],ma[b[i]]),ma[a[i]]=ma[b[i]]=0;
    printf("%d",ans);
    return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 109 + 7.

To represent the string as a number in numeral system with base 64 Vanya uses the following rules:

  * digits from '0' to '9' correspond to integers from 0 to 9;
  * letters from 'A' to 'Z' correspond to integers from 10 to 35;
  * letters from 'a' to 'z' correspond to integers from 36 to 61;
  * letter '-' correspond to integer 62;
  * letter '_' correspond to integer 63.

Input

The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.

Output

Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.

Examples

Input

z

Output

3

Input

V_V

Output

9

Input

Codeforces

Output

130653412

Note

For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.

In the first sample, there are 3 possible solutions:

  1. z&_ = 61&63 = 61 = z
  2. _&z = 63&61 = 61 = z
  3. z&z = 61&61 = 61 = z

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[1050] = {0};
long long mod = 1e9 + 7;
string s;
long long ans;
int foo(char c) {
  int tmp;
  if ((c >= '0') && (c <= '9')) tmp = c - '0';
  if ((c >= 'a') && (c <= 'z')) tmp = c - 'a' + 36;
  if ((c >= 'A') && (c <= 'Z')) tmp = c - 'A' + 10;
  if (c == '-') tmp = 62;
  if (c == '_') tmp = 63;
  return tmp;
}
int main() {
  cin >> s;
  for (int i = 0; i <= 63; i++) {
    for (int j = 0; j <= 63; j++) {
      a[i & j]++;
    }
  }
  ans = 1;
  for (int i = 0; i < s.size(); i++) {
    int gg;
    gg = foo(s[i]);
    ans *= a[gg];
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

For a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of its edges is minimum possible.

You are given a graph G. If you run a MST algorithm on graph it would give you only one MST and it causes other edges to become jealous. You are given some queries, each query contains a set of edges of graph G, and you should determine whether there is a MST containing all these edges or not.

Input

The first line contains two integers n, m (2 ≤ n, m ≤ 5·105, n - 1 ≤ m) — the number of vertices and edges in the graph and the number of queries.

The i-th of the next m lines contains three integers ui, vi, wi (ui ≠ vi, 1 ≤ wi ≤ 5·105) — the endpoints and weight of the i-th edge. There can be more than one edges between two vertices. It's guaranteed that the given graph is connected.

The next line contains a single integer q (1 ≤ q ≤ 5·105) — the number of queries.

q lines follow, the i-th of them contains the i-th query. It starts with an integer ki (1 ≤ ki ≤ n - 1) — the size of edges subset and continues with ki distinct space-separated integers from 1 to m — the indices of the edges. It is guaranteed that the sum of ki for 1 ≤ i ≤ q does not exceed 5·105.

Output

For each query you should print "YES" (without quotes) if there's a MST containing these edges and "NO" (of course without quotes again) otherwise.

Example

Input

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

Output

YES
NO
YES
NO

Note

This is the graph of sample:

<image>

Weight of minimum spanning tree on this graph is 6.

MST with edges (1, 3, 4, 6), contains all of edges from the first query, so answer on the first query is "YES".

Edges from the second query form a cycle of length 3, so there is no spanning tree including these three edges. Thus, answer is "NO".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void rd(T &x) {
  int f = 0, c;
  while (!isdigit(c = getchar())) f ^= !(c ^ 45);
  x = (c & 15);
  while (isdigit(c = getchar())) x = x * 10 + (c & 15);
  if (f) x = -x;
}
template <typename T>
void pt(T x, int c = -1) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) pt(x / 10);
  putchar(x % 10 + 48);
  if (c != -1) putchar(c);
}
template <typename T>
void umax(T &x, const T &y) {
  if (x < y) x = y;
}
template <typename T>
void umin(T &x, const T &y) {
  if (x > y) x = y;
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<long, long>;
const int inf = 0x3f3f3f3f;
const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
struct UnionSet {
  int fa[maxn], siz[maxn], N, record;
  pii sta[maxn];
  void setRecord() { record = N; }
  void init(int n) {
    N = 0;
    for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
  }
  int Find(int x) {
    while (x != fa[x]) x = fa[x];
    return x;
  }
  bool merge(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return false;
    if (siz[x] > siz[y]) swap(x, y);
    fa[x] = y;
    siz[y] += siz[x];
    sta[++N] = {x, y};
    return true;
  }
  void step() {
    int x, y;
    tie(x, y) = sta[N--];
    siz[y] -= siz[x];
    fa[x] = x;
  }
  void rallback() {
    while (N > record) step();
  }
} s;
using tpl = tuple<int, int, int>;
using vi = vector<int>;
int n, m, q;
tpl e[maxn], f[maxn];
vector<pair<int, vi> > g[maxn];
bool ok[maxn];
int main() {
  rd(n);
  rd(m);
  for (int i = 1; i <= m; i++) {
    rd(get<1>(e[i]));
    rd(get<2>(e[i]));
    rd(get<0>(e[i]));
    f[i] = e[i];
  }
  sort(f + 1, f + m + 1);
  rd(q);
  for (int i = 1; i <= q; i++) {
    int k;
    rd(k);
    vi v(k, 0);
    for (auto &x : v) rd(x);
    sort((v).begin(), (v).end(), [](int a, int b) {
      int wa = get<0>(e[a]), wb = get<0>(e[b]);
      if (wa == wb) return a < b;
      return wa < wb;
    });
    int j = 0;
    while (j < (int)v.size()) {
      int pos = j, w = get<0>(e[v[j]]);
      vi tmp;
      while (pos < (int)v.size() && get<0>(e[v[pos]]) == w) {
        tmp.push_back(v[pos++]);
      }
      g[w].push_back({i, tmp});
      j = pos;
    }
  }
  s.init(n);
  s.setRecord();
  fill(ok + 1, ok + q + 1, true);
  int pos = 1;
  for (int i = 1; i <= 500000; i++) {
    for (auto &p : g[i]) {
      if (!ok[p.first]) continue;
      for (auto h : p.second) {
        ok[p.first] &= s.merge(get<1>(e[h]), get<2>(e[h]));
      }
      s.rallback();
    }
    while (pos <= m && get<0>(f[pos]) == i) {
      s.merge(get<1>(f[pos]), get<2>(f[pos]));
      pos++;
    }
    s.setRecord();
  }
  for (int i = 1; i <= q; i++) {
    puts(ok[i] ? "YES" : "NO");
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Arkady likes to walk around his kitchen. His labyrinthine kitchen consists of several important places connected with passages. Unfortunately it happens that these passages are flooded with milk so that it's impossible to pass through them. Namely, it's possible to pass through each passage in any direction only during some time interval.

The lengths of all passages are equal and Arkady makes through them in one second. For security reasons, Arkady can never stop, also, he can't change direction while going through a passage. In other words, if he starts walking in some passage, he should reach its end and immediately leave the end.

Today Arkady needs to quickly reach important place n from place 1. He plans to exit the place 1 at time moment 0 and reach the place n as early as he can. Please find the minimum time he should spend on his way.

Input

The first line contains two integers n and m (1 ≤ n ≤ 5·105, 0 ≤ m ≤ 5·105) — the number of important places and the number of passages, respectively.

After that, m lines follow, each of them describe one passage. Each line contains four integers a, b, l and r (1 ≤ a, b ≤ n, a ≠ b, 0 ≤ l < r ≤ 109) — the places the passage connects and the time segment during which it's possible to use this passage.

Output

Print one integer — minimum time Arkady should spend to reach the destination. If he can't reach the place n, print -1.

Examples

Input

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

Output

3

Input

2 1
1 2 1 100

Output

-1

Note

In the first example Arkady should go through important places 1 → 3 → 4 → 5.

In the second example Arkady can't start his walk because at time moment 0 it's impossible to use the only passage.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
int n, m, ans;
int head[MAXN][2];
struct Tnode {
  int v, l, r;
  Tnode() {}
  Tnode(int vv, int ll, int rr) {
    v = vv;
    l = ll;
    r = rr;
  }
  friend bool operator<(Tnode A, Tnode B) { return A.l < B.l; }
};
vector<Tnode> way[MAXN][2];
struct Tp {
  int x, y;
  Tp() {}
  Tp(int xx, int yy) {
    x = xx;
    y = yy;
  }
  friend bool operator<(Tp A, Tp B) { return A.y > B.y; }
};
priority_queue<Tp> q;
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, l, r;
    scanf("%d%d%d%d", &u, &v, &l, &r);
    for (int j = 0; j < 2; ++j) {
      way[u][j].push_back(Tnode(v, l, r));
      way[v][j].push_back(Tnode(u, l, r));
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < 2; ++j) sort(way[i][j].begin(), way[i][j].end());
}
int dij() {
  int now, tim, xx, yy;
  q.push(Tp(1, 0));
  while (!q.empty()) {
    xx = q.top().x;
    yy = now = q.top().y;
    tim = yy & 1;
    q.pop();
    if (xx == n) return yy;
    for (int j = head[xx][tim]; j < way[xx][tim].size(); ++j) {
      Tnode w = way[xx][tim][j];
      if (w.l > now) break;
      head[xx][tim] = j + 1;
      if (w.r < yy) continue;
      now = max(now, w.r);
      if (now - tim & 1) --now;
      int tmp = max(w.l, yy);
      if (tmp % 2 != tim) ++tmp;
      if (tmp + 1 <= w.r && tmp >= w.l) q.push(Tp(w.v, tmp + 1));
    }
  }
  return -1;
}
int main() {
  init();
  printf("%d\n", dij());
  return 0;
}

```