### Prompt

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

Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.

Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.

Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.

Input

The only line of the input contains two integers: n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ n).

Output

Print the minimum possible and the maximum possible number of apartments good for Maxim.

Example

Input

6 3

Output

1 3

Note

In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void alert(T const& t) {
  cout << t << endl;
  exit(0);
}
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INF64 = 1e15;
const double EPS = 1e-8;
const int MANY = -1;
const int NONE = -2;
int main() {
  int n, k;
  cin >> n >> k;
  if (k == 0 || k == n) {
    cout << "0 0";
  } else {
    cout << "1 " << min(2 * k, n - k);
  }
  return 0;
}

```


### Prompt

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

Kleofáš is participating in an n-thlon - a tournament consisting of n different competitions in n different disciplines (numbered 1 through n). There are m participants in the n-thlon and each of them participates in all competitions.

In each of these n competitions, the participants are given ranks from 1 to m in such a way that no two participants are given the same rank - in other words, the ranks in each competition form a permutation of numbers from 1 to m. The score of a participant in a competition is equal to his/her rank in it.

The overall score of each participant is computed as the sum of that participant's scores in all competitions.

The overall rank of each participant is equal to 1 + k, where k is the number of participants with strictly smaller overall score.

The n-thlon is over now, but the results haven't been published yet. Kleofáš still remembers his ranks in each particular competition; however, he doesn't remember anything about how well the other participants did. Therefore, Kleofáš would like to know his expected overall rank.

All competitors are equally good at each discipline, so all rankings (permutations of ranks of everyone except Kleofáš) in each competition are equiprobable.

Input

The first line of the input contains two space-separated integers n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 1000) — the number of competitions and the number of participants respectively.

Then, n lines follow. The i-th of them contains one integer xi (1 ≤ xi ≤ m) — the rank of Kleofáš in the i-th competition.

Output

Output a single real number – the expected overall rank of Kleofáš. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.

Examples

Input

4 10
2
1
2
1

Output

1.0000000000000000

Input

5 5
1
2
3
4
5

Output

2.7500000000000000

Input

3 6
2
4
2

Output

1.6799999999999999

Note

In the first sample, Kleofáš has overall score 6. Nobody else can have overall score less than 6 (but it's possible for one other person to have overall score 6 as well), so his overall rank must be 1.

### Response

```cpp
#include <bits/stdc++.h>
double f[120][120000];
int g[120];
double s;
int i, j, m, n, t;
int main() {
  scanf("%d%d", &n, &m);
  if (m == 1) {
    printf("1");
    return 0;
  }
  for (i = 1; i <= n; i++) scanf("%d", &g[i]);
  f[0][0] = 1, f[0][1] = -1;
  for (i = 0; i < n; i++)
    for (j = 0; j <= n * m; j++) {
      f[i][j] = f[i][j - 1] + f[i][j];
      f[i + 1][j + 1] = f[i + 1][j + 1] + f[i][j] / (m - 1);
      f[i + 1][j + g[i + 1]] = f[i + 1][j + g[i + 1]] - f[i][j] / (m - 1);
      f[i + 1][j + g[i + 1] + 1] =
          f[i + 1][j + g[i + 1] + 1] + f[i][j] / (m - 1);
      f[i + 1][j + m + 1] = f[i + 1][j + m + 1] - f[i][j] / (m - 1);
    }
  for (i = 0; i <= n * m; i++) f[n][i] = f[n][i - 1] + f[n][i];
  for (i = 1; i <= n; i++) t = t + g[i];
  for (i = 0; i < t; i++) s = s + f[n][i];
  printf("%.15lf", s * (m - 1) + 1);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given a binary string s (recall that a string is binary if each character is either 0 or 1).

Let f(t) be the decimal representation of integer t written in binary form (possibly with leading zeroes). For example f(011) = 3, f(00101) = 5, f(00001) = 1, f(10) = 2, f(000) = 0 and f(000100) = 4.

The substring s_{l}, s_{l+1}, ... , s_{r} is good if r - l + 1 = f(s_l ... s_r).

For example string s = 1011 has 5 good substrings: s_1 ... s_1 = 1, s_3 ... s_3 = 1, s_4 ... s_4 = 1, s_1 ... s_2 = 10 and s_2 ... s_4 = 011.

Your task is to calculate the number of good substrings of string s.

You have to answer t independent queries.

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of queries.

The only line of each query contains string s (1 ≤ |s| ≤ 2 ⋅ 10^5), consisting of only digits 0 and 1.

It is guaranteed that ∑_{i=1}^{t} |s_i| ≤ 2 ⋅ 10^5.

Output

For each query print one integer — the number of good substrings of string s.

Example

Input

4
0110
0101
00001000
0001000

Output

4
3
4
3

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 1e5 + 5;
int t, ans;
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> s;
    ans = 0;
    int l = s.size(), cnt = 0;
    for (int i = 0; i < l; i++) {
      if (s[i] == '0') cnt++;
      if (s[i] == '1') {
        long long sum = 0;
        for (int j = i; j < l; j++) {
          sum *= 2;
          sum += int(s[j] - '0');
          if (sum - (j - i + 1) <= cnt)
            ans++;
          else
            break;
        }
        cnt = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.

The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.

One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.

Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.

Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.

Input

The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.

The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.

Output

Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.

Examples

Input

3
2 4 8

Output

14

Input

4
1 -7 -2 3

Output

-3

Note

In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.

In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value  - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be  - 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T multimod(T a, T b, T m) {
  T ans = 0ll;
  a %= m, b %= m;
  while (b) {
    if (b & 1ll) ans = m - ans > a ? (ans + a) : (ans + a - m);
    b >>= 1ll;
    a = (m - a) > a ? a + a : a + a - m;
  }
  return (T)ans;
}
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
long long arr[(200000 + 7)];
long long sum[(200000 + 7)];
long long dp[(200000 + 7)][2];
int n;
long long solve(int ind, bool is) {
  if (ind == n - 1) {
    if (is) return -sum[ind];
    return sum[ind];
  }
  long long &ret = dp[ind][is];
  if (ret + 1) return ret;
  ret = solve(ind + 1, is);
  if (!is) {
    ret = max(ret, sum[ind] + solve(ind + 1, is ^ 1));
  } else {
    ret = min(ret, solve(ind + 1, is ^ 1) - sum[ind]);
  }
  return ret;
}
int main() {
  int j, i;
  int a, t, b, u, v, cases = 1;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &arr[i]);
    sum[0] = arr[0];
    if (i) sum[i] = sum[i - 1] + arr[i];
  }
  memset(dp, -1, sizeof dp);
  long long res = solve(1, 0);
  printf("%64d\n", res);
  return 0;
}

```


### Prompt

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

The farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table, where n is the number of rows, and m is the number of columns in the table. Each cell of the table contains a haystack. The height in meters of the hay located in the i-th row and the j-th column is equal to an integer ai, j and coincides with the number of cubic meters of hay in the haystack, because all cells have the size of the base 1 × 1. Polycarp has decided to tidy up in the warehouse by removing an arbitrary integer amount of cubic meters of hay from the top of each stack. You can take different amounts of hay from different haystacks. Besides, it is allowed not to touch a stack at all, or, on the contrary, to remove it completely. If a stack is completely removed, the corresponding cell becomes empty and no longer contains the stack.

Polycarp wants the following requirements to hold after the reorganization:

  * the total amount of hay remaining in the warehouse must be equal to k,
  * the heights of all stacks (i.e., cells containing a non-zero amount of hay) should be the same,
  * the height of at least one stack must remain the same as it was,
  * for the stability of the remaining structure all the stacks should form one connected region.

The two stacks are considered adjacent if they share a side in the table. The area is called connected if from any of the stack in the area you can get to any other stack in this area, moving only to adjacent stacks. In this case two adjacent stacks necessarily belong to the same area.

Help Polycarp complete this challenging task or inform that it is impossible.

Input

The first line of the input contains three integers n, m (1 ≤ n, m ≤ 1000) and k (1 ≤ k ≤ 1018) — the number of rows and columns of the rectangular table where heaps of hay are lain and the required total number cubic meters of hay after the reorganization.

Then n lines follow, each containing m positive integers ai, j (1 ≤ ai, j ≤ 109), where ai, j is equal to the number of cubic meters of hay making the hay stack on the i-th row and j-th column of the table.

Output

In the first line print "YES" (without quotes), if Polycarpus can perform the reorganisation and "NO" (without quotes) otherwise. If the answer is "YES" (without quotes), then in next n lines print m numbers — the heights of the remaining hay stacks. All the remaining non-zero values should be equal, represent a connected area and at least one of these values shouldn't be altered.

If there are multiple answers, print any of them.

Examples

Input

2 3 35
10 4 9
9 9 7

Output

YES
7 0 7
7 7 7

Input

4 4 50
5 9 1 1
5 1 1 5
5 1 5 5
5 5 7 1

Output

YES
5 5 0 0
5 0 0 5
5 0 5 5
5 5 5 0

Input

2 4 12
1 1 3 1
1 6 2 4

Output

NO

Note

In the first sample non-zero values make up a connected area, their values do not exceed the initial heights of hay stacks. All the non-zero values equal 7, and their number is 5, so the total volume of the remaining hay equals the required value k = 7·5 = 35. At that the stack that is on the second line and third row remained unaltered.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
int n, m, res, dem, Res, pr[N * N], mark[N * N], maxx[N * N];
long long k, a[N][N], re[N][N], b[N * N];
vector<pair<int, int> > vtt[N * N];
vector<int> vt[N * N];
vector<pair<int, pair<int, int> > > adj;
map<int, int> mp;
vector<int> need;
bool ktra = false;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int parent(int x) {
  if (pr[x] < 0) return x;
  return pr[x] = parent(pr[x]);
}
int change(int x, int y) { return m * (x - 1) + y; }
pair<int, int> rechange(int x) {
  int i = x / m + 1;
  int j = x % m;
  if (j == 0) {
    j = m;
    i--;
  }
  return pair<int, int>(i, j);
}
void dfs(int u) {
  dem++;
  mark[u] = 1;
  pair<int, int> aa = rechange(u);
  re[aa.first][aa.second] = Res;
  if (dem == res) return;
  for (int i = 0; i < vt[u].size(); i++) {
    int v = vt[u][i];
    if (mark[v] == 1 || b[v] < Res) continue;
    dfs(v);
    if (dem == res) return;
  }
  if (dem == res) return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int A = change(i, j);
      adj.push_back(pair<int, pair<int, int> >(a[i][j], pair<int, int>(A, A)));
      b[A] = a[i][j];
      pr[A] = -1;
      for (int l = 0; l < 4; l++) {
        int x = i + dx[l];
        int y = j + dy[l];
        if (x == 0 || x > n || y == 0 || y > m) continue;
        int B = change(x, y);
        int r = min(a[i][j], a[x][y]);
        vt[A].push_back(B);
        adj.push_back(pair<int, pair<int, int> >(r, pair<int, int>(A, B)));
      }
    }
  sort(adj.begin(), adj.end());
  int X = 0;
  int dd = 0;
  for (int i = adj.size() - 1; i >= 0; i--) {
    int w = adj[i].first;
    int u = adj[i].second.first;
    int v = adj[i].second.second;
    if (w != X) {
      need.push_back(w);
      dd++;
      mp[w] = dd;
      X = w;
    }
    int c = parent(u), d = parent(v);
    if (c != d) {
      pr[c] += pr[d];
      pr[d] = c;
    }
    if (b[v] == w) swap(u, v);
    vtt[dd].push_back(pair<int, int>(u, -pr[c]));
    maxx[dd] = max(maxx[dd], -pr[c]);
  }
  for (int i = need.size() - 1; i >= 0; i--) {
    int X = mp[need[i]];
    long long cur = k / need[i];
    if (k % need[i] != 0 || maxx[X] < cur) continue;
    if (cur > m * n) break;
    for (int j = 0; j < vtt[X].size(); j++) {
      if (vtt[X][j].second >= cur) {
        ktra = true;
        res = cur;
        Res = need[i];
        dem = 0;
        dfs(vtt[X][j].first);
        break;
      }
    }
    if (ktra == true) break;
  }
  if (ktra == false) {
    cout << "NO";
    exit(0);
  }
  cout << "YES\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << re[i][j] << " ";
    cout << "\n";
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

You have a list of numbers from 1 to n written from left to right on the blackboard.

You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).

<image>

When there are less than i numbers remaining, you stop your algorithm.

Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?

Input

The first line contains one integer T (1 ≤ T ≤ 100) — the number of queries. The next T lines contain queries — one per line. All queries are independent.

Each line contains two space-separated integers n and x (1 ≤ x < n ≤ 10^{9}) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.

Output

Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.

Example

Input

3
3 1
4 2
69 6

Output

2
4
12

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, x, i;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n >> x;
    cout << 2 * x << "\n";
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

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

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

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

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

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

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

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

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

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

Input

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

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

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

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

Output

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

Examples

Input

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

Output

20
10
20
10
20
10

Input

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

Output

2
3
2
3
2
3
1
1
3

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v1(n);
  for (auto &it : v1) cin >> it;
  vector<long long int> v2[n + 1];
  for (long long int i = 0; i <= n - 1; i++) v2[n].push_back(v1[i]);
  for (long long int i = n - 1; i >= 1; i--) {
    long long int a1 = *min_element(v2[i + 1].begin(), v2[i + 1].end());
    long long int a2;
    for (long long int j = 0; j <= v2[i + 1].size() - 1; j++) {
      if (v2[i + 1][j] == a1) a2 = j;
    }
    for (long long int j = 0; j <= v2[i + 1].size() - 1; j++) {
      if (j == a2) continue;
      v2[i].push_back(v2[i + 1][j]);
    }
  }
  long long int q;
  cin >> q;
  while (q) {
    long long int a1, a2;
    cin >> a1 >> a2;
    cout << v2[a1][a2 - 1] << endl;
    q--;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}

```


### Prompt

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

Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!

When building the graph, he needs four conditions to be satisfied:

  * It must be a simple undirected graph, i.e. without multiple (parallel) edges and self-loops.
  * The number of vertices must be exactly n — a number he selected. This number is not necessarily prime.
  * The total number of edges must be prime.
  * The degree (i.e. the number of edges connected to the vertex) of each vertex must be prime.

Below is an example for n = 4. The first graph (left one) is invalid as the degree of vertex 2 (and 4) equals to 1, which is not prime. The second graph (middle one) is invalid as the total number of edges is 4, which is not a prime number. The third graph (right one) is a valid answer for n = 4.

<image>

Note that the graph can be disconnected.

Please help Bob to find any such graph!

Input

The input consists of a single integer n (3 ≤ n ≤ 1 000) — the number of vertices.

Output

If there is no graph satisfying the conditions, print a single line containing the integer -1.

Otherwise, first print a line containing a prime number m (2 ≤ m ≤ (n(n-1))/(2)) — the number of edges in the graph. Then, print m lines, the i-th of which containing two integers u_i, v_i (1 ≤ u_i, v_i ≤ n) — meaning that there is an edge between vertices u_i and v_i. The degree of each vertex must be prime. There must be no multiple (parallel) edges or self-loops.

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

Note that the graph can be disconnected.

Examples

Input

4

Output

5
1 2
1 3
2 3
2 4
3 4

Input

8

Output

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

Note

The first example was described in the statement.

In the second example, the degrees of vertices are [7, 5, 2, 2, 3, 2, 2, 3]. Each of these numbers is prime. Additionally, the number of edges, 13, is also a prime number, hence both conditions are satisfied.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, ver[100010], Next[100010], head[100010], tot;
inline long long read() {
  long long tmp = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') tmp = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return tmp * x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  long long y = 10, len = 1;
  while (y <= x) {
    y *= 10;
    len++;
  }
  while (len--) {
    y /= 10;
    putchar(x / y + 48);
    x %= y;
  }
}
inline void addEdge(long long x, long long y) {
  ver[++tot] = y;
  Next[tot] = head[x];
  head[x] = tot;
}
inline bool prime(long long m) {
  if (m == 1) return 0;
  long long x = sqrt(m) + 1;
  for (long long i = 2; i <= x; i++) {
    if (m % i == 0) return 0;
  }
  return 1;
}
int main() {
  cin >> n;
  m = n;
  if (n < 3) return printf("-1") & 0;
  while (!prime(m)) m++;
  for (long long i = 1; i < n; i++) addEdge(i, i + 1);
  addEdge(1, n);
  long long now = 1;
  while (m > tot) {
    addEdge(now, n - now);
    now++;
    if (now > n / 2) break;
  }
  write(tot);
  putchar('\n');
  for (long long x = 1; x <= n; x++) {
    for (long long i = head[x]; i; i = Next[i]) {
      write(x);
      putchar(' ');
      write(ver[i]);
      putchar('\n');
    }
  }
  return 0;
}

```


### Prompt

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

Vova has won n trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row.

The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as beautiful as possible — that means, to maximize the length of the longest such subsegment.

Help Vova! Tell him the maximum possible beauty of the arrangement if he is allowed to do at most one swap.

Input

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

The second line contains n characters, each of them is either G or S. If the i-th character is G, then the i-th trophy is a golden one, otherwise it's a silver trophy.

Output

Print the maximum possible length of a subsegment of golden trophies, if Vova is allowed to do at most one swap.

Examples

Input

10
GGGSGGGSGG

Output

7

Input

4
GGGG

Output

4

Input

3
SSS

Output

0

Note

In the first example Vova has to swap trophies with indices 4 and 10. Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is 7.

In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is 4.

In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n;
int pre[MAXN], suf[MAXN];
string s, tmp;
int main() {
  cin >> n >> tmp;
  s = " " + tmp;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'G') {
      pre[i] = pre[i - 1] + 1;
      if (s[i - 1] != 'G') ++cnt;
    }
  }
  for (int i = n; i >= 1; --i) {
    if (s[i] == 'G') {
      suf[i] = suf[i + 1] + 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'S') {
      if (s[i - 1] == 'G' && s[i + 1] == 'G') {
        ans = max(ans, pre[i - 1] + suf[i + 1] + (int)(cnt > 2));
      } else {
        ans = max(ans, pre[i - 1] + suf[i + 1] + (int)(cnt >= 2));
      }
    }
  }
  if (ans)
    cout << ans << endl;
  else {
    for (int i = 1; i <= n; ++i) {
      ans = max(ans, pre[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

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

Petya's been bored at work and he is killing the time by watching the parking lot at the office. The parking lot looks from above like an n × m table (a cell of the table corresponds to a single parking spot). Some spots in the parking lot are taken, others are empty.

Petya watches cars riding into the parking lot one by one. After a car settles down at the parking spot, Petya amuzes himself by counting what maximum square of empty spots (i.e. a square subtable) can be seen on the parking lot if we look at it from above. Also, he takes notes of the square's size (side length) in his notebook.

You task is: given the state of the parking lot at the initial moment of time and the information about where the arriving cars park, restore what Petya wrote in his notebook. It is midday, so nobody leaves the lot.

Input

The first line contains three integers n, m and k — the sizes of the parking lot and the number of arriving cars after Petya started his watch (1 ≤ n, m, k ≤ 2000). Each of the following n lines contains m characters 'X' and '.', where 'X' means a taken spot and '.' means an empty spot. Each of the next k lines contains a pair of integers xi, yi — the number of row and column of the spot the corresponding car takes (1 ≤ xi ≤ n, 1 ≤ yi ≤ m). It is guaranteed that this place was empty. You can assume that a car enters a parking lot only after the previous car successfully finds a spot.

Output

Print k integers — the length of the side of the maximum square of empty spots after the corresponding car has entered the parking lot.

Examples

Input

7 8 4
........
X.....X.
........
........
.X......
........
........
1 5
6 4
3 5
4 6

Output

5
4
4
3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n, m, k, first[N], second[N], L[N], R[N];
int tmp, ans[N], l[N][N], r[N][N], f[N][N];
char s[N][N];
bool check(int first, int second, int tmp) {
  L[first] = l[first][second];
  R[first] = r[first][second];
  for (int i = first - 1; i >= 1; i--) {
    L[i] = l[i][second];
    L[i] = min(L[i], L[i + 1]);
    R[i] = r[i][second];
    R[i] = min(R[i], R[i + 1]);
  }
  for (int i = first + 1; i <= n; i++) {
    L[i] = l[i][second];
    L[i] = min(L[i], L[i - 1]);
    R[i] = r[i][second];
    R[i] = min(R[i], R[i - 1]);
  }
  for (int i = first; i <= n; i++) {
    if (i - tmp + 1 <= 0) continue;
    int l = min(L[i], L[i - tmp + 1]);
    int r = min(R[i], R[i - tmp + 1]);
    if (l + r >= tmp) return 1;
  }
  return 0;
}
void modify(int i, int j) {
  s[i][j] = '.';
  int p = 1;
  for (int j = 1; j <= m; j++) {
    if (s[i][j] == 'X')
      p = j + 1, l[i][j] = 0;
    else
      l[i][j] = j - p + 1;
  }
  p = m;
  for (int j = m; j >= 1; j--) {
    if (s[i][j] == 'X')
      p = j - 1, r[i][j] = 0;
    else
      r[i][j] = p - j;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", first + i, second + i);
    s[first[i]][second[i]] = 'X';
  }
  for (int i = 1; i <= n; i++) {
    int p = 1;
    for (int j = 1; j <= m; j++) {
      int d = min(f[i - 1][j], f[i][j - 1]);
      if (s[i][j] == '.') {
        if (s[i - d][j - d] == '.')
          f[i][j] = d + 1;
        else
          f[i][j] = d;
      }
      tmp = max(tmp, f[i][j]);
      if (s[i][j] == 'X')
        p = j + 1;
      else
        l[i][j] = j - p + 1;
    }
    p = m;
    for (int j = m; j >= 1; j--) {
      if (s[i][j] == 'X')
        p = j - 1;
      else
        r[i][j] = p - j;
    }
  }
  ans[k] = tmp;
  for (int i = k; i >= 1; i--) {
    modify(first[i], second[i]);
    while (check(first[i], second[i], tmp + 1)) tmp++;
    ans[i - 1] = tmp;
  }
  for (int i = 1; i <= k; i++) printf("%d\n", ans[i]);
}

```


### Prompt

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

A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.

A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1, and also exists an edge between vertices v1 and vt.

A simple path in a undirected graph is a sequence of not necessarily distinct vertices v1, v2, ..., vt (t > 0), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1 and furthermore each edge occurs no more than once. We'll say that a simple path v1, v2, ..., vt starts at vertex v1 and ends at vertex vt.

You've got a graph consisting of n vertices and m edges, that is a vertex cactus. Also, you've got a list of k pairs of interesting vertices xi, yi, for which you want to know the following information — the number of distinct simple paths that start at vertex xi and end at vertex yi. We will consider two simple paths distinct if the sets of edges of the paths are distinct.

For each pair of interesting vertices count the number of distinct simple paths between them. As this number can be rather large, you should calculate it modulo 1000000007 (109 + 7).

Input

The first line contains two space-separated integers n, m (2 ≤ n ≤ 105; 1 ≤ m ≤ 105) — the number of vertices and edges in the graph, correspondingly. Next m lines contain the description of the edges: the i-th line contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n) — the indexes of the vertices connected by the i-th edge.

The next line contains a single integer k (1 ≤ k ≤ 105) — the number of pairs of interesting vertices. Next k lines contain the list of pairs of interesting vertices: the i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ n; xi ≠ yi) — the indexes of interesting vertices in the i-th pair.

It is guaranteed that the given graph is a vertex cactus. It is guaranteed that the graph contains no loops or multiple edges. Consider the graph vertices are numbered from 1 to n.

Output

Print k lines: in the i-th line print a single integer — the number of distinct simple ways, starting at xi and ending at yi, modulo 1000000007 (109 + 7).

Examples

Input

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

Output

2
2
2
4
4
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n, n2 = 1, m, q, num[100010], depth[100010], len = 0, dou[100010],
             num2[100010], pw[100010], len2 = 0, id[100010];
pair<long long, long long> dat[800010];
bool vis[100010];
stack<long long> st;
vector<long long> g[100010], v[100010], pass;
vector<pair<long long, long long> > e;
long long dfs(long long pos, long long no, long long d) {
  depth[pos] = d;
  vis[pos] = true;
  st.push(pos);
  long long low = d;
  for (int i = 0; i < g[pos].size(); i++) {
    if (g[pos][i] == no) continue;
    if (depth[g[pos][i]] < d)
      low = min(low, depth[g[pos][i]]);
    else if (!vis[g[pos][i]])
      low = min(low, dfs(g[pos][i], pos, d + 1));
  }
  if (low == d) {
    len++;
    int nn = 0;
    while (true) {
      nn++;
      int tmp = st.top();
      st.pop();
      v[len].push_back(tmp);
      num[tmp] = len;
      if (tmp == pos) break;
    }
    if (nn == 1)
      dou[len] = 0;
    else
      dou[len] = 1;
  }
  return low;
}
void dfs2(long long pos, long long no, long long val) {
  num2[pos] = dou[pos] + val;
  id[pos] = len2++;
  pass.push_back(pos);
  for (int i = 0; i < g[pos].size(); i++)
    if (g[pos][i] != no) {
      dfs2(g[pos][i], pos, num2[pos]);
      len2++;
      pass.push_back(pos);
    }
}
void build(long long k, long long lb, long long ub) {
  if (lb == ub) return;
  build(k * 2 + 1, lb, (lb + ub) / 2);
  build(k * 2 + 2, (lb + ub) / 2 + 1, ub);
  dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
pair<long long, long long> query(long long k, long long lb, long long ub,
                                 long long tlb, long long tub) {
  if (ub < tlb || tub < lb) return make_pair(1e18, -1);
  if (tlb <= lb && ub <= tub) return dat[k];
  return min(query(k * 2 + 1, lb, (lb + ub) / 2, tlb, tub),
             query(k * 2 + 2, (lb + ub) / 2 + 1, ub, tlb, tub));
}
long long lca(long long pos, long long pos2) {
  if (id[pos] > id[pos2]) swap(pos, pos2);
  return query(0, 0, n2 - 1, id[pos], id[pos2]).second;
}
int main() {
  pw[0] = 1;
  for (int i = 1; i <= 100005; i++) pw[i] = pw[i - 1] * 2 % MOD;
  cin >> n >> m;
  long long x, y;
  for (int i = 0; i < m; i++) {
    scanf("%I64d%I64d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
    e.push_back(make_pair(x, y));
  }
  for (int i = 0; i < n + 5; i++) depth[i] = 1e18;
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 0; i < m; i++) {
    if (num[e[i].first] == num[e[i].second]) continue;
    g[num[e[i].first]].push_back(num[e[i].second]);
    g[num[e[i].second]].push_back(num[e[i].first]);
  }
  for (int i = 1; i <= len; i++) {
    sort(g[i].begin(), g[i].end());
    g[i].erase(unique(g[i].begin(), g[i].end()), g[i].end());
  }
  dfs2(1, 0, 0);
  while (n2 < len * 2) n2 *= 2;
  for (int i = 0; i < 800005; i++) dat[i] = make_pair(1e18, -1);
  for (int i = 0; i < pass.size(); i++)
    dat[i + n2 - 1] = make_pair(id[pass[i]], pass[i]);
  build(0, 0, n2 - 1);
  cin >> q;
  for (int qn = 0; qn < q; qn++) {
    scanf("%I64d%I64d", &x, &y);
    long long z = lca(num[x], num[y]);
    long long res = num2[num[x]] + num2[num[y]] - num2[z] * 2 + dou[z];
    printf("%I64d\n", pw[res]);
  }
  return 0;
}

```


### Prompt

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

Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.

Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?

Constraints

* 1 ≤ X ≤ 9
* X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.

Examples

Input

5

Output

YES

Input

6

Output

NO

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
   int x;
   cin>>x;
   if(x==3||x==5||x==7)cout<<"YES";
   else cout<<"NO";
}
```


### Prompt

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

After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.

An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.

In the grid shown below, n = 3 and m = 3. There are n + m = 6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n·m = 9 intersection points, numbered from 1 to 9.

<image>

The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).

Assume that both players play optimally. Who will win the game?

Input

The first line of input contains two space-separated integers, n and m (1 ≤ n, m ≤ 100).

Output

Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.

Examples

Input

2 2

Output

Malvika

Input

2 3

Output

Malvika

Input

3 3

Output

Akshat

Note

Explanation of the first sample:

The grid has four intersection points, numbered from 1 to 4.

<image>

If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.

<image>

Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.

In the empty grid, Akshat cannot make any move, hence he will lose.

Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (min(n, m) % 2 == 1)
    cout << "Akshat" << endl;
  else
    cout << "Malvika" << endl;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

The letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop.

Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string s.

There are m friends, the i-th of them is named t_i. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount.

  * For example, for s="arrayhead" and t_i="arya" 5 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="harry" 6 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="ray" 5 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="r" 2 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="areahydra" all 9 letters have to be bought ("arrayhead").

It is guaranteed that every friend can construct her/his name using the letters from the string s.

Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.

Input

The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of showcase string s.

The second line contains string s, consisting of exactly n lowercase Latin letters.

The third line contains one integer m (1 ≤ m ≤ 5 ⋅ 10^4) — the number of friends.

The i-th of the next m lines contains t_i (1 ≤ |t_i| ≤ 2 ⋅ 10^5) — the name of the i-th friend.

It is guaranteed that ∑ _{i=1}^m |t_i| ≤ 2 ⋅ 10^5.

Output

For each friend print the length of the shortest prefix of letters from s s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount.

It is guaranteed that every friend can construct her/his name using the letters from the string s.

Example

Input

9
arrayhead
5
arya
harry
ray
r
areahydra

Output

5
6
5
2
9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int N = (int)1e5 * 4;
const long long INF = (long long)1e18;
const double eps = (double)1e-6;
int n, m;
int used[27][N];
string s, a;
int d[27];
bool check(int x) {
  for (int i = 0; i < 27; ++i) {
    if (d[i] > used[i][x]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> s;
  for (int i = 0; i < (long long)(s.size()); ++i) {
    used[s[i] - 'a'][i]++;
    for (int j = 0; j < 27; ++j) used[j][i] += used[j][i - 1];
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a;
    for (int j = 0; j < (long long)(a.size()); ++j) {
      d[a[j] - 'a']++;
    }
    int l = -1, r = (long long)(s.size());
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (check(mid) && mid >= (long long)(a.size()) - 1)
        r = mid;
      else
        l = mid;
    }
    cout << r + 1 << endl;
    for (int j = 0; j < (long long)(a.size()); ++j) {
      d[a[j] - 'a'] = 0;
    }
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

This is an interactive problem

You are given a grid n× n, where n is odd. Rows are enumerated from 1 to n from up to down, columns are enumerated from 1 to n from left to right. Cell, standing on the intersection of row x and column y, is denoted by (x, y).

Every cell contains 0 or 1. It is known that the top-left cell contains 1, and the bottom-right cell contains 0.

We want to know numbers in all cells of the grid. To do so we can ask the following questions:

"? x_1 y_1 x_2 y_2", where 1 ≤ x_1 ≤ x_2 ≤ n, 1 ≤ y_1 ≤ y_2 ≤ n, and x_1 + y_1 + 2 ≤ x_2 + y_2. In other words, we output two different cells (x_1, y_1), (x_2, y_2) of the grid such that we can get from the first to the second by moving only to the right and down, and they aren't adjacent.

As a response to such question you will be told if there exists a path between (x_1, y_1) and (x_2, y_2), going only to the right or down, numbers in cells of which form a palindrome.

For example, paths, shown in green, are palindromic, so answer for "? 1 1 2 3" and "? 1 2 3 3" would be that there exists such path. However, there is no palindromic path between (1, 1) and (3, 1).

<image>

Determine all cells of the grid by asking not more than n^2 questions. It can be shown that the answer always exists.

Input

The first line contains odd integer (3 ≤ n < 50) — the side of the grid.

Interaction

You begin the interaction by reading n.

To ask a question about cells (x_1, y_1), (x_2, y_2), in a separate line output "? x_1 y_1 x_2 y_2".

Numbers in the query have to satisfy 1 ≤ x_1 ≤ x_2 ≤ n, 1 ≤ y_1 ≤ y_2 ≤ n, and x_1 + y_1 + 2 ≤ x_2 + y_2. Don't forget to 'flush', to get the answer.

In response, you will receive 1, if there exists a path going from (x_1, y_1) to (x_2, y_2) only to the right or down, numbers in cells of which form a palindrome, and 0 otherwise.

In case your query is invalid or you asked more than n^2 queries, program will print -1 and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

When you determine numbers in all cells, output "!".

Then output n lines, the i-th of which is a string of length n, corresponding to numbers in the i-th row of the grid.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

Hack Format

To hack, use the following format.

The first line should contain a single odd integer n (side of your grid).

The i-th of n following lines should contain a string of length n corresponding to the i-th row of the grid. Top left element of the grid has to be equal to 1, bottom right has to be equal to 0.

Example

Input

3
0
1
0
1
1
1
1

Output

? 1 1 1 3
? 1 1 2 3
? 2 1 2 3
? 3 1 3 3
? 2 2 3 3
? 1 2 3 2
? 1 2 3 3
!
100
001
000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int a[55][55], b[55][55];
void go(int x, int y) {
  if (x + 2 <= n && a[x + 2][y] == -1) {
    printf("? %d %d %d %d\n", x, y, x + 2, y);
    fflush(stdout);
    int ans;
    scanf("%d", &ans);
    if (ans == 1)
      a[x + 2][y] = a[x][y];
    else
      a[x + 2][y] = !a[x][y];
    go(x + 2, y);
  }
  if (y + 2 <= n && a[x][y + 2] == -1) {
    printf("? %d %d %d %d\n", x, y, x, y + 2);
    fflush(stdout);
    int ans;
    scanf("%d", &ans);
    if (ans == 1)
      a[x][y + 2] = a[x][y];
    else
      a[x][y + 2] = !a[x][y];
    go(x, y + 2);
  }
  if (x + 1 <= n && y + 1 <= n && a[x + 1][y + 1] == -1) {
    printf("? %d %d %d %d\n", x, y, x + 1, y + 1);
    fflush(stdout);
    int ans;
    scanf("%d", &ans);
    if (ans == 1)
      a[x + 1][y + 1] = a[x][y];
    else
      a[x + 1][y + 1] = !a[x][y];
    go(x + 1, y + 1);
  }
}
void go2(int x, int y);
void get(int x, int y, int x1, int y1);
int w[10], w2[10], ww, ww2;
int ask[4][4] = {{1, 1, 2, 3}, {1, 1, 3, 2}, {1, 2, 3, 3}, {2, 1, 3, 3}};
void pd(int x, int y, int x1, int y1) {
  ++ww;
  if (a[x][y] == a[x1][y1]) {
    if (a[x + 1][y] == a[x1][y1 - 1] || a[x][y + 1] == a[x1 - 1][y1]) w[ww] = 1;
  }
}
void pd2(int x, int y, int x1, int y1) {
  ++ww2;
  if (a[x][y] == a[x1][y1]) {
    if (a[x + 1][y] == a[x1][y1 - 1] || a[x][y + 1] == a[x1 - 1][y1])
      w2[ww2] = 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, _e = n; i <= _e; ++i)
    for (int j = 1, _e = n; j <= _e; ++j) a[i][j] = -1, b[i][j] = -1;
  a[1][1] = 1;
  a[n][n] = 0;
  go(1, 1);
  b[2][3] = 0;
  printf("? 2 1 2 3\n");
  fflush(stdout);
  int ans;
  scanf("%d", &ans);
  if (ans == 1)
    b[2][1] = b[2][3];
  else
    b[2][1] = !b[2][3];
  printf("? 1 2 2 3\n");
  fflush(stdout);
  scanf("%d", &ans);
  if (ans == 1)
    b[1][2] = b[2][3];
  else
    b[1][2] = !b[2][3];
  go2(1, 2);
  go2(2, 3);
  go2(2, 1);
  int xx;
  for (int i = 1, _e = n - 2; i <= _e; ++i)
    if (a[i][i] != a[i + 2][i + 2]) {
      xx = i;
      break;
    }
  for (int j = 0, _e = 3; j <= _e; ++j)
    for (int k = 0, _e = 3; k <= _e; ++k) ask[j][k] += xx - 1;
  for (int i = 1, _e = n; i <= _e; ++i)
    for (int j = 1, _e = n; j <= _e; ++j)
      if (b[i][j] != -1) a[i][j] = b[i][j];
  for (int j = 0, _e = 3; j <= _e; ++j)
    pd(ask[j][0], ask[j][1], ask[j][2], ask[j][3]);
  for (int i = 1, _e = n; i <= _e; ++i)
    for (int j = 1, _e = n; j <= _e; ++j)
      if (b[i][j] != -1) a[i][j] = !b[i][j];
  for (int j = 0, _e = 3; j <= _e; ++j)
    pd2(ask[j][0], ask[j][1], ask[j][2], ask[j][3]);
  for (int j = 0, _e = 3; j <= _e; ++j)
    if (w[j + 1] != w2[j + 1]) {
      printf("? ");
      for (int k = 0, _e = 3; k <= _e; ++k) printf("%d ", ask[j][k]);
      printf("\n");
      fflush(stdout);
      scanf("%d", &ans);
      if (ans == w[j + 1]) {
        for (int i = 1, _e = n; i <= _e; ++i)
          for (int j = 1, _e = n; j <= _e; ++j)
            if (b[i][j] != -1) a[i][j] = b[i][j];
      }
      break;
    }
  printf("!\n");
  fflush(stdout);
  for (int i = 1, _e = n; i <= _e; ++i) {
    for (int j = 1, _e = n; j <= _e; ++j) putchar(a[i][j] + '0');
    printf("\n");
    fflush(stdout);
  }
}
void go2(int x, int y) {
  if (x + 2 <= n && b[x + 2][y] == -1) {
    get(x, y, x + 2, y);
    go2(x + 2, y);
  }
  if (y + 2 <= n && b[x][y + 2] == -1) {
    get(x, y, x, y + 2);
    go2(x, y + 2);
  }
  if (x + 1 <= n && y + 1 <= n && b[x + 1][y + 1] == -1) {
    get(x, y, x + 1, y + 1);
    go2(x + 1, y + 1);
  }
}
void get(int x, int y, int x1, int y1) {
  printf("? %d %d %d %d\n", x, y, x1, y1);
  fflush(stdout);
  int ans;
  scanf("%d", &ans);
  if (ans == 1)
    b[x1][y1] = b[x][y];
  else
    b[x1][y1] = !b[x][y];
}

```


### Prompt

Please formulate a cpp solution to the following problem:

A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.

The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:

  * Is it true that y is strictly larger than number x?
  * Is it true that y is strictly smaller than number x?
  * Is it true that y is larger than or equal to number x?
  * Is it true that y is smaller than or equal to number x?

On each question the host answers truthfully, "yes" or "no".

Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:

  * ">" (for the first type queries),
  * "<" (for the second type queries),
  * ">=" (for the third type queries),
  * "<=" (for the fourth type queries).

All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").

Consequtive elements in lines are separated by a single space.

Output

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

Examples

Input

4
>= 1 Y
< 3 N
<= -3 N
> 55 N

Output

17

Input

2
> 100 Y
< -100 Y

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int main() {
  fast();
  int n;
  cin >> n;
  long long lo = -1e9 * 2, hi = 1e9 * 2, mid = lo + ((hi - lo) >> 1);
  while (n--) {
    string s;
    long long x;
    char c;
    cin >> s >> x >> c;
    if ((s == ">=" && c == 'Y') || (s == "<" && c == 'N')) {
      lo = max(x, lo);
    } else if ((s == ">" && c == 'Y') || (s == "<=" && c == 'N')) {
      lo = max(x + 1, lo);
    } else if ((s == "<=" && c == 'Y') || (s == ">" && c == 'N')) {
      hi = min(x, hi);
    } else if ((s == "<" && c == 'Y') || (s == ">=" && c == 'N')) {
      hi = min(x - 1, hi);
    }
    mid = lo + ((hi - lo) >> 1);
  }
  if (hi < lo)
    cout << "Impossible";
  else
    cout << mid;
  return 0;
}

```


### Prompt

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

You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.

Each vertex has a color, let's denote the color of vertex v by cv. Initially cv = 0.

You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex v and a color x, and then color all vectices in the subtree of v (including v itself) in color x. In other words, for every vertex u, such that the path from root to u passes through v, set cu = x.

It is guaranteed that you have to color each vertex in a color different from 0.

You can learn what a rooted tree is using the link: https://en.wikipedia.org/wiki/Tree_(graph_theory).

Input

The first line contains a single integer n (2 ≤ n ≤ 104) — the number of vertices in the tree.

The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi < i), where pi means that there is an edge between vertices i and pi.

The third line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ n), where ci is the color you should color the i-th vertex into.

It is guaranteed that the given graph is a tree.

Output

Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.

Examples

Input

6
1 2 2 1 5
2 1 1 1 1 1

Output

3

Input

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

Output

5

Note

The tree from the first sample is shown on the picture (numbers are vetices' indices):

<image>

On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):

<image>

On seond step we color all vertices in the subtree of vertex 5 into color 1:

<image>

On third step we color all vertices in the subtree of vertex 2 into color 1:

<image>

The tree from the second sample is shown on the picture (numbers are vetices' indices):

<image>

On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors):

<image>

On second step we color all vertices in the subtree of vertex 3 into color 1:

<image>

On third step we color all vertices in the subtree of vertex 6 into color 2:

<image>

On fourth step we color all vertices in the subtree of vertex 4 into color 1:

<image>

On fith step we color all vertices in the subtree of vertex 7 into color 3:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p[10005], c[10005];
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  int ans = 1, nowColor[10005];
  for (int i = 1; i <= n; i++) {
    nowColor[i] = c[1];
  }
  for (int i = 2; i <= n; i++) {
    if (nowColor[p[i]] != c[i]) {
      ans++;
    }
    nowColor[i] = c[i];
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Ksenia has a chessboard of size n × m. Each cell of the chessboard contains one of the characters: "<", ">", "^", "v", "#". The cells that contain character "#" are blocked. We know that all chessboard cells that touch the border are blocked.

Ksenia is playing with two pawns on this chessboard. Initially, she puts the pawns on the chessboard. One cell of the chessboard can contain two pawns if and only if the cell is blocked. In other cases two pawns can not stand in one cell. The game begins when Ksenia put pawns on the board. In one move, Ksenia moves each pawn to a side adjacent cell in the direction of arrows painted on the cell on which the corresponding pawn sits (if the pawn sits on "#", it does not move). Assume that Ksenia moves pawns simultaneously (see the second test case).

Of course, Ksenia plays for points. How can one calculate the points per game? Very simply! Let's count how many movements the first pawn made and how many movements the second pawn made, sum these two numbers — it will be the resulting score of the game.

Ksenia wonders: what is the maximum number of points she can earn (for that, she should place the pawns optimally well early in the game). Help her and find that number.

Input

The first line contains two integers, n and m (1 ≤ n, m ≤ 2000) — the sizes of the board. Each of the following n lines contains m characters – the board's description. Each character is one of the characters: "<", ">", "^", "v", "#".

It is guaranteed that the border cells of the table are blocked cells (with character "#").

Output

If Ksenia can get infinitely many points, print -1. Otherwise, print the maximum number of points she can get.

Examples

Input

1 1
#

Output

0

Input

3 4
####
#>^{}#
####

Output

3

Input

3 4
####
#><#
####

Output

-1

Input

7 5
#####
##v##
##v##
#####
##^{}##
##^{}##
#####

Output

4

Input

7 5
#####
##v##
##v##
##<##
##^{}##
##^{}##
#####

Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, nex[(2100 * 2000)], trm[(2100 * 2000)], dis[(2100 * 2000)],
    mark[(2100 * 2000)];
void dfs(int x) {
  mark[x] = 1;
  if (mark[nex[x]] == 1 && trm[nex[x]]) {
    cout << -1;
    exit(0);
  }
  if (trm[nex[x]] && !mark[nex[x]]) dfs(nex[x]);
  dis[x] = dis[nex[x]] + (trm[x]);
  mark[x] = 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c == '<')
        nex[i * m + j] = i * m + j - 1, trm[i * m + j] = 1;
      else if (c == '>')
        nex[i * m + j] = i * m + j + 1, trm[i * m + j] = 1;
      else if (c == '^')
        nex[i * m + j] = (i - 1) * m + j, trm[i * m + j] = 1;
      else if (c == 'v')
        nex[i * m + j] = (i + 1) * m + j, trm[i * m + j] = 1;
    }
  for (int i = 0; i < n * m; i++) dfs(i);
  int maxi_in = 0;
  for (int i = 0; i < n * m; i++)
    if (dis[i] > dis[maxi_in]) maxi_in = i;
  int ans = dis[maxi_in];
  while (maxi_in) trm[maxi_in] = 0, maxi_in = nex[maxi_in];
  memset(dis, 0, sizeof dis);
  memset(mark, 0, sizeof mark);
  for (int i = 0; i < n * m; i++) dfs(i);
  maxi_in = 0;
  for (int i = 0; i < n * m; i++)
    if (dis[i] > dis[maxi_in]) maxi_in = i;
  cout << max(ans * 2 - 1, ans + dis[maxi_in]);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Anton likes to play chess, and so does his friend Danik.

Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.

Now Anton wonders, who won more games, he or Danik? Help him determine this.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played.

The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game.

Output

If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.

If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.

If Anton and Danik won the same number of games, print "Friendship" (without quotes).

Examples

Input

6
ADAAAA

Output

Anton

Input

7
DDDAADA

Output

Danik

Input

6
DADADA

Output

Friendship

Note

In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".

In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".

In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, A, D;
  A = 0;
  D = 0;
  cin >> n;
  char letter;
  for (int i = 0; i < n; i++) {
    cin >> letter;
    if (letter == 'A') {
      A++;
    } else {
      D++;
    }
  }
  if (A > D) {
    cout << "Anton";
  } else if (D > A) {
    cout << "Danik";
  } else {
    cout << "Friendship";
  }
  return 0;
}

```


### Prompt

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

There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.

Among them, some K consecutive stones are painted black, and the others are painted white.

Additionally, we know that the stone at coordinate X is painted black.

Print all coordinates that potentially contain a stone painted black, in ascending order.

Constraints

* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

K X

Output

Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.

Examples

Input

3 7

Output

5 6 7 8 9

Input

4 0

Output

-3 -2 -1 0 1 2 3

Input

1 100

Output

100

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,x;
  cin>>k>>x;
  for(int i=x-k+1;i<=(k+x-1);i++){
    cout<<i<<endl;
  }

}
```


### Prompt

Please create a solution in Cpp to the following problem:

A plurality of trampolines are arranged in a line at 10 m intervals. Each trampoline has its own maximum horizontal distance within which the jumper can jump safely. Starting from the left-most trampoline, the jumper jumps to another trampoline within the allowed jumping range. The jumper wants to repeat jumping until he/she reaches the right-most trampoline, and then tries to return to the left-most trampoline only through jumping. Can the jumper complete the roundtrip without a single stepping-down from a trampoline?

Write a program to report if the jumper can complete the journey using the list of maximum horizontal reaches of these trampolines. Assume that the trampolines are points without spatial extent.

Input

The input is given in the following format.

N
d_1
d_2
:
d_N

The first line provides the number of trampolines N (2 ≤ N ≤ 3 × 105). Each of the subsequent N lines gives the maximum allowable jumping distance in integer meters for the i-th trampoline d_i (1 ≤ d_i ≤ 106).

Output

Output "yes" if the jumper can complete the roundtrip, or "no" if he/she cannot.

Examples

Input

4
20
5
10
1

Output

no

Input

3
10
5
10

Output

no

Input

4
20
30
1
20

Output

yes

### Response

```cpp
#include "bits/stdc++.h"

using namespace std;
#define INF 10000000
int main(void)
{
	int a; cin >> a;
	vector<int>arr(a * 2);
	vector<int>arr2(a * 2, 0);
	vector<int>arr3(a * 2, 0);
	for (int i = 1; i <= a; i++)
	{
		int b; cin >> b;
		b /= 10;
		arr[i] = b;
		arr[a * 2 - i] = b;
	}
	for (int i = 1; i < a * 2; i++)
	{
		arr2[i] = max(i + arr[i], arr2[i-1]);
	}
	int ddd = 1;
	for (int i = 0; i < a * 2; i++)
	{
		if (ddd>=a *2)
		{
			break;
		}
		ddd = arr2[ddd];
	}
	if (ddd >= a*2)
	{
		cout << "yes" << "\n";
	}
	else cout << "no" << "\n";
}

```


### Prompt

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

We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).

The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.

You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points.

You now have to take Q practical tests of your ability as a magical girl.

The i-th test will be conducted as follows:

* Initially, a piece is placed on the square where the integer L_i is written.

* Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i.

* Here, it is guaranteed that R_i-L_i is a multiple of D.

For each test, find the sum of magic points consumed during that test.

Constraints

* 1 \leq H,W \leq 300
* 1 \leq D \leq H×W
* 1 \leq A_{i,j} \leq H×W
* A_{i,j} \neq A_{x,y} ((i,j) \neq (x,y))
* 1 \leq Q \leq 10^5
* 1 \leq L_i \leq R_i \leq H×W
* (R_i-L_i) is a multiple of D.

Input

Input is given from Standard Input in the following format:

H W D
A_{1,1} A_{1,2} ... A_{1,W}
:
A_{H,1} A_{H,2} ... A_{H,W}
Q
L_1 R_1
:
L_Q R_Q

Output

For each test, print the sum of magic points consumed during that test.

Output should be in the order the tests are conducted.

Examples

Input

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

Output

5

Input

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

Output

0
0

Input

5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
13 13
2 10
13 13

Output

0
5
0

### Response

```cpp
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAX_A = 90000;
int px[MAX_A+1], py[MAX_A+1], imos[MAX_A];

int main() {
    int h, w, d, a, q, l, r;
    cin >> h >> w >> d;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a;
            px[a] = j, py[a] = i;
        }
    }
    for (int i = d + 1; i <= h * w; i++) {
        imos[i] = imos[i-d] + abs(px[i] - px[i-d]) + abs(py[i] - py[i-d]);
    }
    cin >> q;
    while(q--) {
        cin >> l >> r;
        cout << imos[r] - imos[l] << endl;
    }
    return 0;
}
```


### Prompt

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

You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.

Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".

You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii".

Input

The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name.

The second line contains a string of length n consisting of lowercase Latin letters only — the file name.

Output

Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.

Examples

Input

6
xxxiii

Output

1

Input

5
xxoxx

Output

0

Input

10
xxxxxxxxxx

Output

8

Note

In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, sum = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'x' && s[i + 1] == 'x' && s[i + 2] == 'x') {
      sum++;
    }
  }
  cout << sum;
}

```


### Prompt

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

It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.

He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 × 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.

Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.

Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.

Input

Input data contains multiple test cases. The first line of the input data contains an integer t — the number of test cases (1 ≤ t ≤ 100). The descriptions of test cases follow.

Each test is described by two lines.

The first line contains an integer n (1 ≤ n ≤ 2000) — the number of cards in Borya's present.

The second line contains n integers ai (1 ≤ ai ≤ 109) — numbers written on the cards.

It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.

Output

For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.

Example

Input

4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9

Output

2
2
2
31680

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
const int N = 2050;
const long long MOD = 998244353, r2 = (MOD + 1) / 2;
long long f[2][N][11], g[2][N][11], de[N][N], cur[N << 1], h[N >> 1][N << 1],
    fac[N << 1], t1[N << 1], t2[N << 1], C[N][N];
pair<int, int> a[N];
int b[N], c[N];
int n;
long long pw(long long a, long long b) {
  long long re = 1;
  while (b) {
    if (b & 1) re = re * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return re;
}
long long query(int i, int j) {
  if (i == 0 && j == 0) return 1;
  return C[i + j - 1][j] * fac[j] % MOD;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 2040; i++) fac[i] = fac[i - 1] * i % MOD;
  for (int i = 0; i <= 2040; i++) {
    de[i][0] = 1;
    for (int j = 1; j <= i; j++) de[i][j] = de[i][j - 1] * (i - j + 1) % MOD;
  }
  C[0][0] = 1;
  for (int i = 1; i <= 2040; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
  }
  int cas = read();
  while (cas--) {
    n = read();
    for (int i = 1; i <= n; i++) {
      int u = read();
      a[i].first = a[i].second = 0;
      while (u) {
        if (a[i].second)
          a[i].first -= u % 10;
        else
          a[i].first += u % 10;
        a[i].second ^= 1;
        u /= 10;
      }
      a[i].first = (a[i].first % 11 + 11) % 11;
    }
    int n1 = 0, n2 = 0, s1 = 0, s2 = 0;
    for (int i = 1; i <= n; i++)
      if (a[i].second & 1)
        b[++n1] = a[i].first, s1 += a[i].first;
      else
        c[++n2] = a[i].first, s2 += a[i].first;
    s1 %= 11, s2 %= 11;
    for (int i = 0; i <= n1 / 2; i++)
      for (int j = 0; j < 11; j++) f[0][i][j] = 0;
    f[0][0][0] = 1;
    for (int i = 0; i < n1; i++) {
      int now = i & 1, nxt = !now;
      for (int j = 0; j <= n1 / 2; j++)
        for (int k = 0; k < 11; k++) f[nxt][j][k] = 0;
      for (int j = 0; j <= n1 / 2; j++)
        for (int k = 0; k < 11; k++) {
          (f[nxt][j][k] += f[now][j][k]) %= MOD;
          if (j < n1 / 2)
            (f[nxt][j + 1][(k + b[i + 1]) % 11] += f[now][j][k]) %= MOD;
        }
    }
    for (int i = 0; i <= n2; i++)
      for (int j = 0; j < 11; j++) g[0][i][j] = 0;
    g[0][0][0] = 1;
    for (int i = 0; i < n2; i++) {
      int now = i & 1, nxt = !now;
      for (int j = 0; j <= n2; j++)
        for (int k = 0; k < 11; k++) g[nxt][j][k] = 0;
      for (int j = 0; j <= n2; j++)
        for (int k = 0; k < 11; k++) {
          (g[nxt][j][k] += g[now][j][k]) %= MOD;
          if (j < n2)
            (g[nxt][j + 1][(k + c[i + 1]) % 11] += g[now][j][k]) %= MOD;
        }
    }
    long long ans = 0;
    for (int i = 0; i < 11; i++)
      for (int j = 0; j < 11; j++)
        if ((2 * i - s1 + 2 * j - s2) % 11 == 0)
          for (int k = 0; k <= n2; k++)
            (ans += g[n2 & 1][k][j] * query(n1 / 2 + 1, k) % MOD *
                    query((n1 + 1) / 2, n2 - k) % MOD * f[n1 & 1][n1 / 2][i] %
                    MOD * de[n1 / 2][n1 / 2] % MOD *
                    de[(n1 + 1) / 2][(n1 + 1) / 2] % MOD) %= MOD;
    printf("%lld\n", ans);
  }
}

```


### Prompt

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

Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...

To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's head is a straight line on which n hairlines grow. Let's number them from 1 to n. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length l, given that all hairlines on that segment had length strictly greater than l. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.

Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:

  * 0 — Alice asks how much time the haircut would take if she would go to the hairdresser now.
  * 1 p d — p-th hairline grows by d centimeters.

Note, that in the request 0 Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.

Input

The first line contains three integers n, m and l (1 ≤ n, m ≤ 100 000, 1 ≤ l ≤ 10^9) — the number of hairlines, the number of requests and the favorite number of Alice.

The second line contains n integers a_i (1 ≤ a_i ≤ 10^9) — the initial lengths of all hairlines of Alice.

Each of the following m lines contains a request in the format described in the statement.

The request description starts with an integer t_i. If t_i = 0, then you need to find the time the haircut would take. Otherwise, t_i = 1 and in this moment one hairline grows. The rest of the line than contains two more integers: p_i and d_i (1 ≤ p_i ≤ n, 1 ≤ d_i ≤ 10^9) — the number of the hairline and the length it grows by.

Output

For each query of type 0 print the time the haircut would take.

Example

Input

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

Output

1
2
2
1

Note

Consider the first example:

  * Initially lengths of hairlines are equal to 1, 2, 3, 4 and only 4-th hairline is longer l=3, and hairdresser can cut it in 1 second.
  * Then Alice's second hairline grows, the lengths of hairlines are now equal to 1, 5, 3, 4
  * Now haircut takes two seonds: two swings are required: for the 4-th hairline and for the 2-nd.
  * Then Alice's first hairline grows, the lengths of hairlines are now equal to 4, 5, 3, 4
  * The haircut still takes two seconds: with one swing hairdresser can cut 4-th hairline and with one more swing cut the segment from 1-st to 2-nd hairline.
  * Then Alice's third hairline grows, the lengths of hairlines are now equal to 4, 5, 4, 4
  * Now haircut takes only one second: with one swing it is possible to cut the segment from 1-st hairline to the 4-th.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N, M;
long long int L;
vector<long long int> A;
vector<int> parent;
vector<int> rnk;
int disjointSetsCount;
void initDisjointSets(int n) {
  for (int i = 0; i < n; ++i) {
    parent.push_back(i);
    rnk.push_back(1);
  }
}
int findRoot(int n) {
  return parent[n] == n ? n : (parent[n] = findRoot(parent[n]));
}
bool isSameSet(int p, int q) { return findRoot(p) == findRoot(q); }
void join(int p, int q) {
  int rootP = findRoot(p), rootQ = findRoot(q);
  if (rootP == rootQ) {
    return;
  }
  --disjointSetsCount;
  if (rnk[rootP] < rnk[rootQ]) {
    parent[rootP] = rootQ;
    rnk[rootQ] += rnk[rootP];
    return;
  }
  parent[rootQ] = rootP;
  rnk[rootP] += rnk[rootQ];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int i, x, p;
  long long int d;
  cin >> N >> M >> L;
  initDisjointSets(N);
  for (i = 0; i < N; ++i) {
    cin >> x;
    A.push_back(x);
  }
  for (i = 0; i < N; ++i) {
    if (A[i] > L) {
      ++disjointSetsCount;
      if ((i - 1) >= 0 and A[i - 1] > L) {
        join(i, i - 1);
      }
    }
  }
  for (i = 0; i < M; ++i) {
    cin >> x;
    if (x > 0) {
      cin >> p >> d;
      A[p - 1] += d;
      if (A[p - 1] > L) {
        if ((A[p - 1] - d) <= L) {
          ++disjointSetsCount;
        }
        if (p < N and A[p] > L) {
          join(p - 1, p);
        }
        if ((p - 2) >= 0 and A[p - 2] > L) {
          join(p - 1, p - 2);
        }
      }
    } else {
      cout << disjointSetsCount << '\n';
    }
  }
  return 0;
}

```


### Prompt

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

You have a tree of n vertices. You are going to convert this tree into n rubber bands on infinitely large plane. Conversion rule follows:

  * For every pair of vertices a and b, rubber bands a and b should intersect if and only if there is an edge exists between a and b in the tree.
  * Shape of rubber bands must be a simple loop. In other words, rubber band is a loop which doesn't self-intersect.

Now let's define following things:

  * Rubber band a includes rubber band b, if and only if rubber band b is in rubber band a's area, and they don't intersect each other.
  * Sequence of rubber bands a_{1}, a_{2}, …, a_{k} (k ≥ 2) are nested, if and only if for all i (2 ≤ i ≤ k), a_{i-1} includes a_{i}.

<image> This is an example of conversion. Note that rubber bands 5 and 6 are nested.

It can be proved that is it possible to make a conversion and sequence of nested rubber bands under given constraints.

What is the maximum length of sequence of nested rubber bands can be obtained from given tree? Find and print it.

Input

The first line contains integer n (3 ≤ n ≤ 10^{5}) — the number of vertices in tree.

The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 ≤ a_{i} < b_{i} ≤ n) — it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.

Output

Print the answer.

Examples

Input

6
1 3
2 3
3 4
4 5
4 6

Output

4

Input

4
1 2
2 3
3 4

Output

2

Note

In the first sample, you can obtain a nested sequence of 4 rubber bands(1, 2, 5, and 6) by the conversion shown below. Of course, there are other conversions exist to make a nested sequence of 4 rubber bands. However, you cannot make sequence of 5 or more nested rubber bands with given tree.

<image>

You can see one of the possible conversions for the second sample below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
void precalc() {}
const int maxn = (int)1e5 + 5;
int n;
vector<int> g[maxn];
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  return true;
}
int dp[maxn][2];
void dfs0(int v, int p) {
  auto &cur0 = dp[v][0];
  auto &cur1 = dp[v][1];
  cur0 = 0;
  cur1 = 0;
  for (int i = 0; i < ((int)(g[v]).size()); i++) {
    int u = g[v][i];
    if (u == p) {
      continue;
    }
    dfs0(u, v);
    cur0 = max(cur0, max(dp[u][0], dp[u][1]));
    cur1 = max(cur1, dp[u][0]);
  }
  int deg = ((int)(g[v]).size()) - (p != -1);
  cur0 += max(0, deg - 1);
  cur1++;
}
int res;
void update(int d[2][2], int t, int x) {
  if (d[t][0] < x) {
    d[t][1] = d[t][0];
    d[t][0] = x;
  } else if (d[t][1] < x) {
    d[t][1] = x;
  }
}
void dfs1(int v, int p, int up0, int up1) {
  int d[2][2] = {{0, 0}, {0, 0}};
  update(d, 0, max(up0, up1));
  update(d, 1, up0);
  for (int i = 0; i < ((int)(g[v]).size()); i++) {
    int u = g[v][i];
    if (u == p) {
      continue;
    }
    update(d, 0, max(dp[u][0], dp[u][1]));
    update(d, 1, dp[u][0]);
  }
  res = max(res, d[1][0] + 1);
  for (int i = 0; i < ((int)(g[v]).size()); i++) {
    int u = g[v][i];
    if (u == p) {
      continue;
    }
    int d0 = (d[0][0] == max(dp[u][0], dp[u][1]) ? d[0][1] : d[0][0]);
    int d1 = (d[1][0] == dp[u][0] ? d[1][1] : d[1][0]);
    d0 += max(0, ((int)(g[v]).size()) - 2);
    d1++;
    dfs1(u, v, d0, d1);
  }
}
void solve() {
  dfs0(0, -1);
  res = dp[0][1];
  dfs1(0, -1, 0, 0);
  printf("%d\n", res);
}
int main() {
  precalc();
  while (read()) {
    solve();
  }
  return 0;
}

```


### Prompt

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

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

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

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

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

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

Input

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

This number may contain leading zeros.

Output

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

Examples

Input

11

Output

6

Input

01

Output

2

Input

1

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int pow(long long int a, long long int b) {
  long long int c = mod;
  long long int x = 1, y = a % c;
  while (b > 0) {
    if (b % 2 == 1) x = (x * y) % c;
    y = (y * y) % c;
    b /= 2;
  }
  return x % c;
}
int main() {
  long long int t, k = 0, i, j, c, m, n, h, w;
  string s;
  cin >> s;
  n = 0;
  for (i = s.length() - 1, j = 0; i >= 0; i--, j++)
    if (s[i] == '1')
      k = (2 * k + pow(2LL, 2 * j)) % mod;
    else
      k = (k * 2) % mod;
  cout << k;
  return 0;
}

```


### Prompt

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

In this problem you will meet the simplified model of game King of Thieves.

In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.

<image>

An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.

A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'.

One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1, he can make a sequence of jumps through the platforms i1 < i2 < ... < ik, if i2 - i1 = i3 - i2 = ... = ik - ik - 1. Of course, all segments i1, i2, ... ik should be exactly the platforms, not pits.

Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i1, i2, ..., i5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of segments on the level.

Next line contains the scheme of the level represented as a string of n characters '*' and '.'.

Output

If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).

Examples

Input

16
.**.*..*.***.**.

Output

yes

Input

11
.*.*...*.*.

Output

no

Note

In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, i, j, ok, v[500];
string s;
void verifica(int start, int pas) {
  int steps = 0;
  int oktura = 1;
  while (steps < 4) {
    start = start + pas;
    if (v[start] == 0) oktura = 0;
    steps++;
  }
  if (oktura) ok = 1;
}
int main() {
  cin >> n;
  cin >> s;
  for (i = 1; i <= n; i++) {
    if (s[i - 1] == '*')
      v[i] = 1;
    else
      v[i] = 0;
  }
  ok = 0;
  for (i = 1; i <= n / 2 and ok == 0; i++) {
    for (j = 1; j <= n; j++) {
      if (v[j] == 1) verifica(j, i);
    }
  }
  if (ok)
    cout << "yes";
  else
    cout << "no";
}

```


### Prompt

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

Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.

Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is <image>. His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.

All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.

Input

The first line of the input contains five space-separated integers m1, m2, m3, m4, m5, where mi (0 ≤ mi ≤ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted.

The second line contains five space-separated integers w1, w2, w3, w4, w5, where wi (0 ≤ wi ≤ 10) is Kevin's number of wrong submissions on problem i.

The last line contains two space-separated integers hs and hu (0 ≤ hs, hu ≤ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.

Output

Print a single integer, the value of Kevin's final score.

Examples

Input

20 40 60 80 100
0 1 2 3 4
1 0

Output

4900

Input

119 119 119 119 119
0 0 0 0 0
10 0

Output

4930

Note

In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <image> of the points on each problem. So his score from solving problems is <image>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  float m[5], w[5], hs, hu, total = 0, x[5] = {500, 1000, 1500, 2000, 2500};
  cin >> m[0] >> m[1] >> m[2] >> m[3] >> m[4] >> w[0] >> w[1] >> w[2] >> w[3] >>
      w[4] >> hs >> hu;
  total += (100 * hs) - (50 * hu);
  for (int i = 0; i < 5; i++) {
    total += max(float(0.3 * x[i]), ((1 - (m[i] / 250)) * x[i] - 50 * w[i]));
  }
  cout << int(total) << endl;
}

```


### Prompt

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

For a positive integer n let's define a function f:

f(n) = - 1 + 2 - 3 + .. + ( - 1)nn

Your task is to calculate f(n) for a given integer n.

Input

The single line contains the positive integer n (1 ≤ n ≤ 1015).

Output

Print f(n) in a single line.

Examples

Input

4

Output

2

Input

5

Output

-3

Note

f(4) = - 1 + 2 - 3 + 4 = 2

f(5) = - 1 + 2 - 3 + 4 - 5 = - 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf(" %I64d", &n);
  printf("%I64d\n", (n / 2) - (n & 1 ? n : 0));
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

In an unspecified solar system, there are N planets. A space government company has recently hired space contractors to build M bidirectional Hyperspace™ highways, each connecting two different planets. The primary objective, which was to make sure that every planet can be reached from any other planet taking only Hyperspace™ highways, has been completely fulfilled. Unfortunately, lots of space contractors had friends and cousins in the Space Board of Directors of the company, so the company decided to do much more than just connecting all planets.

In order to make spending enormous amounts of space money for Hyperspace™ highways look neccessary, they decided to enforce a strict rule on the Hyperspace™ highway network: whenever there is a way to travel through some planets and return to the starting point without travelling through any planet twice, every pair of planets on the itinerary should be directly connected by a Hyperspace™ highway. In other words, the set of planets in every simple cycle induces a complete subgraph.

You are designing a Hyperspace™ navigational app, and the key technical problem you are facing is finding the minimal number of Hyperspace™ highways one needs to use to travel from planet A to planet B. As this problem is too easy for Bubble Cup, here is a harder task: your program needs to do it for Q pairs of planets.

Input

The first line contains three positive integers N (1≤ N≤ 100 000), M (1≤ M≤ 500 000) and Q (1≤ Q≤ 200 000), denoting the number of planets, the number of Hyperspace™ highways, and the number of queries, respectively.

Each of the following M lines contains a highway: highway i is given by two integers u_i and v_i (1 ≤ u_i < v_i ≤ N), meaning the planets u_i and v_i are connected by a Hyperspace™ highway. It is guaranteed that the network of planets and Hyperspace™ highways forms a simple connected graph.

Each of the following Q lines contains a query: query j is given by two integers a_j and b_j (1 ≤ a_j < b_j ≤ N ), meaning we are interested in the minimal number of Hyperspace™ highways one needs to take to travel from planet a_j to planet b_j.

Output

Output Q lines: the j-th line of output should contain the minimal number of Hyperspace™ highways one needs to take to travel from planet a_j to planet b_j.

Examples

Input

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

Output

1
2

Input

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

Output

2
2
3
3

Note

The graph from the second sample: <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5, LOGN = 19;
long long n, m, k, l, r, x, y, z, res = 0, tmp = 0, u, v, timer = 0, lvl = -1;
string s, t;
long long in[MAXN], out[MAXN], dubina[MAXN], anc[MAXN][LOGN];
vector<int> adj[MAXN], bfs_stablo[MAXN];
bool visited[MAXN];
queue<int> q;
void dfs(int node, int prev) {
  in[node] = ++timer;
  anc[node][0] = prev;
  for (auto v : bfs_stablo[node]) {
    if (v != prev) {
      dfs(v, node);
    }
  }
  out[node] = ++timer;
}
void bfs() {
  q.push(1);
  dubina[1] = 0;
  anc[1][0] = 1;
  visited[1] = true;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (auto v : adj[node]) {
      if (visited[v]) continue;
      visited[v] = true;
      q.push(v);
      dubina[v] = dubina[node] + 1;
      bfs_stablo[node].push_back(v);
      bfs_stablo[v].push_back(node);
    }
  }
}
bool in_subtree(int u, int v) { return (in[v] <= in[u] && out[u] <= out[v]); }
void preprocess() {
  for (int d = 1; d < LOGN; d++)
    for (int i = 1; i < MAXN; i++) anc[i][d] = anc[anc[i][d - 1]][d - 1];
  for (int i = 1; i <= n; i++) {
  }
}
int lca(int u, int v, bool kk) {
  if (in_subtree(u, v)) return v;
  if (in_subtree(v, u)) return u;
  for (int deg = LOGN - 1; deg >= 0; deg--) {
    if (!in_subtree(v, anc[u][deg])) u = anc[u][deg];
  }
  if (kk) return anc[u][0];
  return u;
}
int distance(int u, int v) {
  return dubina[u] + dubina[v] - 2 * dubina[lca(u, v, true)];
}
void solve() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  bfs();
  dfs(1, 1);
  preprocess();
  for (int i = 1; i <= k; i++) {
    res = 0;
    cin >> u >> v;
    int u_ispod = lca(u, v, false), v_ispod = lca(v, u, false);
    res = distance(u, v);
    if (find(adj[u_ispod].begin(), adj[u_ispod].end(), v_ispod) !=
        adj[u_ispod].end())
      res--;
    cout << res << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

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

Input

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

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

We consider that pixel is already broken at moment ti.

Output

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

Examples

Input

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

Output

8

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
const int INF = 1 << 29;
int const NN = 5e3 + 3;
int const MX = 1e9 + 9;
int a[505][505];
int mx[505][505];
int main() {
  int n, m, K, q;
  cin >> n >> m >> K >> q;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) a[i][j] = MX;
  }
  while (q--) {
    int x, y, t;
    cin >> x >> y >> t;
    a[x][y] = t;
  }
  int ans = MX;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      mx[i][j] = a[i][j];
      for (int k = 2; i + k - 1 <= n && k <= K; ++k) {
        mx[i][j] = max(mx[i][j], a[i + k - 1][j]);
      }
    }
  }
  for (int i = 1; i + K - 1 <= n; ++i) {
    for (int j = 1; j + K - 1 <= m; ++j) {
      int mxx = -1;
      for (int jj = j; jj <= j + K - 1; ++jj) {
        mxx = max(mxx, mx[i][jj]);
      }
      ans = min(ans, mxx);
    }
  }
  if (ans < MX) {
    printf("%d", ans);
    ;
    putchar('\n');
  } else
    puts("-1");
  return 0;
}

```