### Prompt

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

Arkady is playing Battleship. The rules of this game aren't really important.

There is a field of n × n cells. There should be exactly one k-decker on the field, i. e. a ship that is k cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.

Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the size of the field and the size of the ship.

The next n lines contain the field. Each line contains n characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).

Output

Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.

If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.

Examples

Input

4 3
#..#
#.#.
....
.###

Output

3 2

Input

10 4
#....##...
.#...#....
..#..#..#.
...#.#....
.#..##.#..
.....#...#
...#.##...
.#...#.#..
.....#..#.
...#.#...#

Output

6 1

Input

19 6
##..............###
#......#####.....##
.....#########.....
....###########....
...#############...
..###############..
.#################.
.#################.
.#################.
.#################.
#####....##....####
####............###
####............###
#####...####...####
.#####..####..#####
...###........###..
....###########....
.........##........
#.................#

Output

1 8

Note

The picture below shows the three possible locations of the ship that contain the cell (3, 2) in the first sample.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1 << 29;
struct node {
  int l = 0, r = 0, u = 0, d = 0;
};
long long int findit(long long int x, long long int y, long long int k) {
  long long int ans = 0;
  for (long long int i = 0; i <= x; i++) {
    if (i > k) break;
    for (long long int j = 0; j <= y; j++) {
      if (i + j == k) {
        ans++;
      }
      if (i + j >= k) break;
    }
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  long long int n, k;
  cin >> n >> k;
  char c[n][n];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      cin >> c[i][j];
    }
  }
  node dp[n][n];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (i != 0) {
        if (c[i - 1][j] == '.') dp[i][j].u = dp[i - 1][j].u + 1;
      }
      if (j != 0) {
        if (c[i][j - 1] == '.') dp[i][j].l = dp[i][j - 1].l + 1;
      }
    }
  }
  for (long long int i = n - 1; i >= 0; i--) {
    for (long long int j = n - 1; j >= 0; j--) {
      if (i != n - 1) {
        if (c[i + 1][j] == '.') dp[i][j].d = dp[i + 1][j].d + 1;
      }
      if (j != n - 1) {
        if (c[i][j + 1] == '.') dp[i][j].r = dp[i][j + 1].r + 1;
      }
    }
  }
  long long int ai = 0, aj = 0;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (c[i][j] == '#') continue;
      long long int v = dp[i][j].d + dp[i][j].u + 1;
      long long int h = dp[i][j].l + dp[i][j].r + 1;
      long long int curr = findit(dp[i][j].d, dp[i][j].u, k - 1) +
                           findit(dp[i][j].l, dp[i][j].r, k - 1);
      if (ans < curr) {
        ans = curr;
        ai = i;
        aj = j;
      }
    }
  }
  cout << ai + 1 << " " << aj + 1;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

The mobile application store has a new game called "Subway Roller".

The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field.

All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel.

Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column.

<image>

Input

Each test contains from one to ten sets of the input data. The first line of the test contains a single integer t (1 ≤ t ≤ 10 for pretests and tests or t = 1 for hacks; see the Notes section for details) — the number of sets.

Then follows the description of t sets of the input data.

The first line of the description of each set contains two integers n, k (2 ≤ n ≤ 100, 1 ≤ k ≤ 26) — the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of n character, representing the row of the field where the game is on. Philip's initial position is marked as 's', he is in the leftmost column. Each of the k trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character '.' represents an empty cell, that is, the cell that doesn't contain either Philip or the trains.

Output

For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise.

Examples

Input

2
16 4
...AAAAA........
s.BBB......CCCCC
........DDDDD...
16 4
...AAAAA........
s.BBB....CCCCC..
.......DDDDD....

Output

YES
NO

Input

2
10 4
s.ZZ......
.....AAABB
.YYYYYY...
10 4
s.ZZ......
....AAAABB
.YYYYYY...

Output

YES
NO

Note

In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the tunnel.

Note that in this problem the challenges are restricted to tests that contain only one testset.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int t, n, k, ans = 0, v[3][maxn];
char s[3][maxn];
struct node {
  int x, y;
} a[3 * maxn];
bool judge(char x) {
  if (isalpha(x)) return false;
  return true;
}
int bfs(node tmp) {
  queue<node> q;
  q.push(tmp);
  while (!q.empty()) {
    node nod = q.front();
    int x = nod.x, y = nod.y;
    q.pop();
    if (y > n - 1) {
      return 1;
    }
    if (isalpha(s[x][++y])) continue;
    for (int i = -1; i <= 1; i++) {
      int tempx = x + i;
      if (tempx < 0 || tempx > 2) continue;
      if (isalpha(s[tempx][y]) || isalpha(s[tempx][y + 1]) ||
          isalpha(s[tempx][y + 2]) || v[tempx][y + 2] == 1)
        continue;
      v[tempx][y + 2] = 1;
      if (y + 2 >= n - 1) return 1;
      node tp;
      tp.x = tempx;
      tp.y = y + 2;
      q.push(tp);
    }
  }
  return 0;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    scanf("%s%s%s", s[0], s[1], s[2]);
    node tmp;
    memset(v, 0, sizeof v);
    for (int i = 0; i < 3; i++) {
      if (s[i][0] == 's') tmp.x = i, tmp.y = 0;
    }
    if (bfs(tmp))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Tanya has n candies numbered from 1 to n. The i-th candy has the weight a_i.

She plans to eat exactly n-1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day.

Your task is to find the number of such candies i (let's call these candies good) that if dad gets the i-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one.

For example, n=4 and weights are [1, 4, 3, 3]. Consider all possible cases to give a candy to dad:

  * Tanya gives the 1-st candy to dad (a_1=1), the remaining candies are [4, 3, 3]. She will eat a_2=4 in the first day, a_3=3 in the second day, a_4=3 in the third day. So in odd days she will eat 4+3=7 and in even days she will eat 3. Since 7 ≠ 3 this case shouldn't be counted to the answer (this candy isn't good).
  * Tanya gives the 2-nd candy to dad (a_2=4), the remaining candies are [1, 3, 3]. She will eat a_1=1 in the first day, a_3=3 in the second day, a_4=3 in the third day. So in odd days she will eat 1+3=4 and in even days she will eat 3. Since 4 ≠ 3 this case shouldn't be counted to the answer (this candy isn't good).
  * Tanya gives the 3-rd candy to dad (a_3=3), the remaining candies are [1, 4, 3]. She will eat a_1=1 in the first day, a_2=4 in the second day, a_4=3 in the third day. So in odd days she will eat 1+3=4 and in even days she will eat 4. Since 4 = 4 this case should be counted to the answer (this candy is good).
  * Tanya gives the 4-th candy to dad (a_4=3), the remaining candies are [1, 4, 3]. She will eat a_1=1 in the first day, a_2=4 in the second day, a_3=3 in the third day. So in odd days she will eat 1+3=4 and in even days she will eat 4. Since 4 = 4 this case should be counted to the answer (this candy is good).

In total there 2 cases which should counted (these candies are good), so the answer is 2.

Input

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

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^4), where a_i is the weight of the i-th candy.

Output

Print one integer — the number of such candies i (good candies) that if dad gets the i-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days.

Examples

Input

7
5 5 4 5 5 5 6

Output

2

Input

8
4 8 8 7 8 4 4 5

Output

2

Input

9
2 3 4 2 2 3 2 2 4

Output

3

Note

In the first example indices of good candies are [1, 2].

In the second example indices of good candies are [2, 3].

In the third example indices of good candies are [4, 5, 9].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a = 0, b = 0, m = 0, x = 0, y = 0, A, B;
  cin >> n;
  int v[n];
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (i % 2 == 0) {
      a += v[i];
    } else {
      b += v[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      x += v[i];
      A = x - v[i] + b - y;
      B = y + a - x;
    } else {
      y += v[i];
      B = y - v[i] + a - x;
      A = x + b - y;
    }
    if (A == B) {
      m++;
    }
  }
  cout << m;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

At the entrance examination for the magistracy of the MSU Cyber-Mechanics Department Sasha got the question about Ford-Fulkerson algorithm. He knew the topic perfectly as he worked with it many times on programming competition. As the task for the question he was given a network with partially build flow that he had to use in order to demonstrate the workflow of the algorithm. He quickly finished to write the text and took a look at the problem only to understand that the given network is incorrect!

Suppose you are given a directed graph G(V, E) with two special nodes s and t called source and sink. We denote as n the number of nodes in the graph, i.e. n = |V| and m stands for the number of directed edges in the graph, i.e. m = |E|. For the purpose of this problem we always consider node 1 to be the source and node n to be the sink. In addition, for each edge of the graph e we define the capacity function c(e) and flow function f(e). Function f(e) represents the correct flow if the following conditions are satisfied:

  1. For each edge <image> the flow is non-negative and does not exceed capacity c(e), i.e. 0 ≤ f(e) ≤ c(e).
  2. For each node <image>, that is not source or sink (v ≠ s and v ≠ t) the sum of flows of all edges going in v is equal to the sum of the flows among all edges going out from v. In other words, there is no flow stuck in v.

It was clear that as the exam was prepared last night and there are plenty of mistakes in the tasks. Sasha asked one of the professors to fix the network or give the correct task, but the reply was that the magistrate student should be able to fix the network himself. As the professor doesn't want the task to become easier, he asks Sasha to fix the network in a such way that the total number of changes is minimum possible. Sasha is not allowed to remove edges, add new ones or reverse the direction of existing edges. The only thing he is able to do is to change capacity function c(e) and flow function f(e). Moreover, all the values should remain non-negative integers. There is no requirement on the flow to be maximum in any sense.

Find the minimum possible total change of the functions f(e) and c(e) that Sasha has to make in order to make the flow correct. The total change is defined as the sum of absolute differences, i.e. if new functions are f * (e) and c * (e), then the total change is <image>.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 100, 0 ≤ m ≤ 100) — the number of nodes and edges in the graph respectively. Each of the following m lines contains the description of the edges, consisting of four integers ui, vi, ci and fi (1 ≤ ui, vi ≤ n, ui ≠ vi, 0 ≤ ci, fi ≤ 1 000 000) — index of the node the edges starts from, the index of the node the edge goes to, current capacity and flow value.

Node number 1 is the source, and node number n is the sink. It's guaranteed that no edge goes to the source, and no edges starts in the sink.

Given graph contains no self-loops but may contain multiple edges.

Output

Print one integer — the minimum total sum of changes that Sasha has to do in order to get the correct flow description.

Examples

Input

2 1
1 2 2 1

Output

0

Input

2 1
1 2 1 2

Output

1

Input

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

Output

1

Input

4 2
2 3 1 1
3 2 1 1

Output

0

Note

In the first sample, the flow is initially correct. Note, that the flow is not maximum, but this is not required.

In the second sample, the flow value of the only edge is greater than its capacity. There are two ways to fix this: either increase the capacity up to 2 or reduce the flow down to 1.

In the third sample, there is only 1 unit of flow coming to vertex 2, but there are 2 units going out of it. One of the possible solutions is to reduce the value of the flow on the second edge by 1.

In the fourth sample, there is isolated circulation of flow, but this description is correct by definition.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int maxn = 1e4 + 20;
const int inf = 0x3f3f3f3f;
struct node {
  int v, next, w, cost;
};
node e[maxn << 1];
int cnt = 1, start[maxn];
inline void addedge(int u, int v, int w, int cost) {
  e[++cnt] = (node){v, start[u], w, cost};
  start[u] = cnt;
}
inline void Addedge(int u, int v, int w, int cost) {
  addedge(u, v, w, cost);
  addedge(v, u, 0, -cost);
}
int n, m;
int ry[maxn];
int ans;
int Sn, Tn, tot;
inline void init() {
  n = read();
  m = read();
  for (int i = (1), _end_ = (m); i <= _end_; i++) {
    int u = read(), v = read(), c = read(), f = read();
    if (f <= c) {
      ry[u] -= f;
      ry[v] += f;
      Addedge(v, u, f, 1);
      Addedge(u, v, c - f, 1);
      Addedge(u, v, inf, 2);
    } else {
      ans += f - c;
      ry[u] -= c;
      ry[v] += c;
      Addedge(v, u, c, 1);
      Addedge(u, v, f - c, 0);
      Addedge(u, v, inf, 2);
    }
  }
  tot = n;
  Addedge(n, 1, inf, 0);
  Sn = ++tot;
  Tn = ++tot;
  for (int i = (1), _end_ = (n); i <= _end_; i++)
    if (ry[i] > 0)
      Addedge(Sn, i, ry[i], 0);
    else
      Addedge(i, Tn, -ry[i], 0);
}
int dist[maxn], pre[maxn], vis[maxn];
queue<int> q;
inline int cost_flow(int S, int T) {
  int ans = 0;
  while (1) {
    for (int i = (1), _end_ = (tot); i <= _end_; i++)
      dist[i] = inf, pre[i] = vis[i];
    q.push(S);
    dist[S] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      vis[u] = 0;
      for (int i = start[(u)]; i; i = e[i].next) {
        int v = e[i].v;
        if (dist[v] > dist[u] + e[i].cost && e[i].w) {
          dist[v] = dist[u] + e[i].cost;
          pre[v] = i;
          if (!vis[v]) q.push(v), vis[v] = 1;
        }
      }
    }
    if (dist[T] == inf) break;
    int flow = inf;
    for (int i = pre[T]; i; i = pre[e[i ^ 1].v]) chkmin(flow, e[i].w);
    for (int i = pre[T]; i; i = pre[e[i ^ 1].v])
      e[i].w -= flow, e[i ^ 1].w += flow;
    ans += dist[T] * flow;
  }
  return ans;
}
inline void doing() { printf("%d\n", cost_flow(Sn, Tn) + ans); }
int main() {
  init();
  doing();
  return 0;
}

```


### Prompt

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

Hanh lives in a shared apartment. There are n people (including Hanh) living there, each has a private fridge.

n fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to it. A fridge can be open only if all chains connected to it are unlocked. For example, if a fridge has no chains connected to it at all, then any of n people can open it.

<image> For exampe, in the picture there are n=4 people and 5 chains. The first person knows passcodes of two chains: 1-4 and 1-2. The fridge 1 can be open by its owner (the person 1), also two people 2 and 4 (acting together) can open it.

The weights of these fridges are a_1, a_2, …, a_n. To make a steel chain connecting fridges u and v, you have to pay a_u + a_v dollars. Note that the landlord allows you to create multiple chains connecting the same pair of fridges.

Hanh's apartment landlord asks you to create exactly m steel chains so that all fridges are private. A fridge is private if and only if, among n people living in the apartment, only the owner can open it (i.e. no other person acting alone can do it). In other words, the fridge i is not private if there exists the person j (i ≠ j) that the person j can open the fridge i.

For example, in the picture all the fridges are private. On the other hand, if there are n=2 fridges and only one chain (which connects them) then both fridges are not private (both fridges can be open not only by its owner but also by another person).

Of course, the landlord wants to minimize the total cost of all steel chains to fulfill his request. Determine whether there exists any way to make exactly m chains, and if yes, output any solution that minimizes the total cost.

Input

Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 10). Then the descriptions of the test cases follow.

The first line of each test case contains two integers n, m (2 ≤ n ≤ 1000, 1 ≤ m ≤ n) — the number of people living in Hanh's apartment and the number of steel chains that the landlord requires, respectively.

The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^4) — weights of all fridges.

Output

For each test case:

  * If there is no solution, print a single integer -1.
  * Otherwise, print a single integer c — the minimum total cost. The i-th of the next m lines contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), meaning that the i-th steel chain connects fridges u_i and v_i. An arbitrary number of chains can be between a pair of fridges.

If there are multiple answers, print any.

Example

Input

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

Output

8
1 2
4 3
3 2
4 1
-1
12
3 2
1 2
3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> x, temp, h;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > v, v1;
    int has[100007];
    int a[100007];
    memset(has, 0, sizeof(has));
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      v.push_back(make_pair(a[i], i));
    }
    if (n == 2) {
      cout << "-1\n";
      continue;
    }
    sort(v.begin(), v.end());
    int flag = 0, ans = 0, cpt = 0;
    for (int i = 0; i < n; i++) {
      int indx = v[i].second;
      int cost = v[i].first;
      if (i < n - 1) {
        v1.push_back(make_pair(indx, v[i + 1].second));
        ans += cost + v[i + 1].first;
        has[indx]++;
        has[v[i + 1].second]++;
        m -= 1;
        cpt += 1;
        if (m == 0) {
          flag = 1;
          break;
        }
      } else {
        v1.push_back(make_pair(indx, v[0].second));
        ans += cost + v[0].first;
        m -= 1;
        cpt += 1;
        has[indx]++;
        has[v[0].second]++;
        if (m == 0) {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      int flg = 0;
      for (int i = 1; i <= n; i++) {
        if (has[i] < 2) {
          flg = 1;
          break;
        }
      }
      if (flg)
        cout << "-1\n";
      else {
        cout << ans << "\n";
        for (int i = 0; i < cpt; i++) {
          cout << v1[i].first << " " << v1[i].second << "\n";
        }
      }
    } else {
      while (m > 0) {
        v1.push_back(make_pair(v[0].second, v[1].second));
        ans += v[0].first + v[1].first;
        cpt += 1;
        m -= 1;
      }
      cout << ans << "\n";
      for (int i = 0; i < cpt; i++) {
        cout << v1[i].first << " " << v1[i].second << "\n";
      }
    }
  }
}

```


### Prompt

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

There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.

You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.

You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?

Note that outcome of a match can not be a draw, it has to be either win or loss.

Input

The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).

Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.

Output

For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).

Examples

Input

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

Output

yes
yes
yes
no
no

Note

Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.

Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".

Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, c;
long long n, k, d1, d2;
bool work(int i) {
  a = n;
  if (i == 1) {
    b = a - d1;
    c = b - d2;
  } else if (i == 2) {
    b = a - d1;
    c = b + d2;
  } else if (i == 3) {
    b = a + d1;
    c = b + d2;
  } else {
    b = a + d1;
    c = b - d2;
  }
  long long q = min(a, min(b, c));
  a -= q;
  b -= q;
  c -= q;
  if ((k - (a + b + c)) % 3 == 0 && a + b + c <= k) return 1;
  return 0;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n >> k >> d1 >> d2;
    bool ch = 0;
    for (int j = 0; j < 4 && !ch; j++) {
      if (work(j)) {
        long long q = max(a, max(b, c));
        if ((n - k - q - q - q + a + b + c) % 3 == 0 &&
            (n - k - q - q - q + a + b + c) >= 0) {
          ch = 1;
          cout << "yes" << endl;
        }
      }
    }
    if (!ch) cout << "no" << endl;
  }
  return 0;
}

```


### Prompt

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

Given an integer x. Your task is to find out how many positive integers n (1 ≤ n ≤ x) satisfy $$$n ⋅ a^n ≡ b   (mod\;p), where a, b, p$$$ are all known constants.

Input

The only line contains four integers a,b,p,x (2 ≤ p ≤ 10^6+3, 1 ≤ a,b < p, 1 ≤ x ≤ 10^{12}). It is guaranteed that p is a prime.

Output

Print a single integer: the number of possible answers n.

Examples

Input

2 3 5 8

Output

2

Input

4 6 7 13

Output

1

Input

233 233 10007 1

Output

1

Note

In the first sample, we can see that n=2 and n=8 are possible answers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, b, p, inv[1000009], ok[1000009];
long long x;
int extgcd(int a, int b, int &x, int &y) {
  int g = a;
  x = 1;
  y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
int main() {
  cin >> a >> b >> p >> x;
  x++;
  inv[1] = 1;
  for (int i = 2; i < p; i++) inv[i] = 1LL * inv[p % i] * (p - p / i) % p;
  for (int i = 0; i < p; i++) ok[i] = -1;
  vector<int> v;
  int mul = 1;
  while (true) {
    ok[mul] = v.size();
    v.push_back(mul);
    mul = 1LL * mul * a % p;
    if (mul == 1) break;
  }
  long long loop = 1LL * p * v.size();
  if (loop <= 10000000) {
    long long ret = 0;
    for (int i = 0; i < loop; i++) {
      int val = 1LL * (i % p) * (v[i % v.size()]) % p;
      if (val == b) ret += x / loop;
      if (val == b && i < x % loop) ret++;
    }
    cout << ret << endl;
  } else {
    long long ret = 0;
    for (int i = 1; i < p; i++) {
      if (ok[i] == -1) continue;
      int val = 1LL * b * inv[i] % p, rvx, rvy;
      extgcd(p, v.size(), rvx, rvy);
      long long vx = rvx, vy = rvy;
      vx *= ok[i] - val;
      vy *= ok[i] - val;
      if (vx < 0) vx = (v.size() - (-vx) % v.size()) % v.size();
      if (vy < 0) vy = (p - (-vy) % p) % p;
      vx %= p;
      vy %= p;
      long long rv = 1LL * vx * p + val;
      ret += x / loop + (x % loop > rv);
    }
    cout << ret << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.

There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for all jury members. For each city from 1 to n there is exactly one jury member living there. Olympiad preparation is a long and demanding process that requires k days of work. For all of these k days each of the n jury members should be present in Metropolis to be able to work on problems.

You know the flight schedule in the country (jury members consider themselves important enough to only use flights for transportation). All flights in Metropolia are either going to Metropolis or out of Metropolis. There are no night flights in Metropolia, or in the other words, plane always takes off at the same day it arrives. On his arrival day and departure day jury member is not able to discuss the olympiad. All flights in Megapolia depart and arrive at the same day.

Gather everybody for k days in the capital is a hard objective, doing that while spending the minimum possible money is even harder. Nevertheless, your task is to arrange the cheapest way to bring all of the jury members to Metrpolis, so that they can work together for k days and then send them back to their home cities. Cost of the arrangement is defined as a total cost of tickets for all used flights. It is allowed for jury member to stay in Metropolis for more than k days.

Input

The first line of input contains three integers n, m and k (1 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ k ≤ 106).

The i-th of the following m lines contains the description of the i-th flight defined by four integers di, fi, ti and ci (1 ≤ di ≤ 106, 0 ≤ fi ≤ n, 0 ≤ ti ≤ n, 1 ≤ ci ≤ 106, exactly one of fi and ti equals zero), the day of departure (and arrival), the departure city, the arrival city and the ticket cost.

Output

Output the only integer that is the minimum cost of gathering all jury members in city 0 for k days and then sending them back to their home cities.

If it is impossible to gather everybody in Metropolis for k days and then send them back to their home cities, output "-1" (without the quotes).

Examples

Input

2 6 5
1 1 0 5000
3 2 0 5500
2 2 0 6000
15 0 2 9000
9 0 1 7000
8 0 2 6500

Output

24500

Input

2 4 5
1 2 0 5000
2 1 0 4500
2 1 0 3000
8 0 1 6000

Output

-1

Note

The optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days 1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day 15, that would cost 2500 more.

In the second sample it is impossible to send jury member from city 2 back home from Metropolis.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, vector<T>& arr) {
  for (int64_t i = 0; i < (int64_t)arr.size() - 1; ++i) {
    out << arr[i] << " ";
  }
  if (arr.size()) {
    out << arr.back() << '\n';
  }
  return out;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& arr) {
  for (auto& i : arr) in >> i;
  return in;
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}
struct race {
  int64_t d, f, t, c;
  friend istream& operator>>(istream& in, race& a) {
    in >> a.d >> a.f >> a.t >> a.c;
    return in;
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t n, m, k;
  cin >> n >> m >> k;
  vector<pair<pair<int64_t, int64_t>, pair<int64_t, int64_t> > > sob;
  vector<multiset<int64_t> > pri(n), ot(n);
  vector<int64_t> min_pri(n, 1000000000000), min_ot(n, 1000000000000);
  int64_t sum = n * 1000000000000;
  for (int64_t i = 0; i < m; ++i) {
    int64_t d, f, t, c;
    cin >> d >> f >> t >> c;
    if (t == 0) {
      sob.push_back(make_pair(make_pair(d, 1), make_pair(f - 1, c)));
    } else {
      sob.push_back(make_pair(make_pair(d - k, -1), make_pair(t - 1, c)));
      ot[t - 1].insert(c);
      min_ot[t - 1] = min(min_ot[t - 1], c);
    }
  }
  for (int64_t j = 0; j < n; ++j) {
    sum += min_ot[j];
    if (min_ot[j] == 1000000000000) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (int64_t i = 0; i < n; ++i) {
    ot[i].insert(1000000000000);
    pri[i].insert(1000000000000);
  }
  sort(sob.begin(), sob.end());
  int64_t ans = 2000000000000000000;
  int64_t cnt = 0;
  for (int64_t i = 0; i < sob.size(); ++i) {
    int64_t t = sob[i].first.second;
    int64_t v = sob[i].second.first;
    int64_t c = sob[i].second.second;
    if (t == 1) {
      if (pri[v].size() == 1) {
        cnt++;
      }
      pri[v].insert(c);
      int64_t nw = *(pri[v].begin());
      sum -= min_pri[v] - nw;
      min_pri[v] = nw;
    } else {
      ot[v].erase(ot[v].find(c));
      if (ot[v].size() < 2) {
        break;
      }
      int64_t nw = *(ot[v].begin());
      sum -= min_ot[v] - nw;
      min_ot[v] = nw;
    }
    if (cnt == n) ans = min(ans, sum);
  }
  if (ans <= 2 * 1000000000000) {
    cout << ans << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.

The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.

Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.

Constraints

* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.

Input

Input is given from Standard Input in the following format:

S

Output

Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.

Examples

Input

oxoxoxoxoxoxox

Output

YES

Input

xxxxxxxx

Output

NO

### Response

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

int main() {
	string s;cin>>s;
	int cnt=0;for(int i=0;i<s.size();i++)cnt+=(s[i]=='x');
	cout<<(cnt>=8?"NO\n":"YES\n");
	return 0;
}
```


### Prompt

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

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

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

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

Input

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

Output

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

Examples

Input

3
1875
1936
1721

Output

1835
1836
1921

Input

4
9999
2000
3000
3011

Output

1999
2000
2000
2011

Input

3
1999
5055
2000

Output

No solution

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1100], ans[1100];
int gao(int pos) {
  int i, j, k, l, tt[4], temp = a[pos], f = 0, t, cnt;
  for (i = 0; i < 4; i++) {
    tt[i] = temp % 10;
    temp /= 10;
  }
  for (i = 2; i >= 1; i--) {
    for (j = 9; j >= 0; j--) {
      for (k = 9; k >= 0; k--) {
        for (l = 9; l >= 0; l--) {
          t = i * 1000 + j * 100 + k * 10 + l, cnt = 0;
          if (t >= 1000 && t <= 2011 && t <= ans[pos + 1]) {
            if (i == tt[3]) cnt++;
            if (j == tt[2]) cnt++;
            if (k == tt[1]) cnt++;
            if (l == tt[0]) cnt++;
            if (cnt > 2) {
              f = 1;
              break;
            }
          }
        }
        if (f) break;
      }
      if (f) break;
    }
    if (f) break;
  }
  if (f) {
    ans[pos] = t;
    return 1;
  }
  return 0;
}
int main() {
  int i, j, n, f = 0;
  scanf("%d", &n);
  for (i = 0; i < 1005; i++) ans[i] = 2011;
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = n - 1; i >= 0; i--)
    if (!gao(i)) {
      f = 1;
      break;
    }
  if (f)
    printf("No solution\n");
  else {
    for (i = 0; i < n; i++) printf("%d\n", ans[i]);
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Hr0d1y has q queries on a binary string s of length n. A binary string is a string containing only characters '0' and '1'.

A query is described by a pair of integers l_i, r_i (1 ≤ l_i < r_i ≤ n).

For each query, he has to determine whether there exists a good subsequence in s that is equal to the substring s[l_i… r_i].

  * A substring s[i… j] of a string s is the string formed by characters s_i s_{i+1} … s_j.
  * String a is said to be a subsequence of string b if a can be obtained from b by deleting some characters without changing the order of the remaining characters.
  * A subsequence is said to be good if it is not contiguous and has length ≥ 2. For example, if s is "1100110", then the subsequences s_1s_2s_4 ("1100110") and s_1s_5s_7 ("1100110") are good, while s_1s_2s_3 ("1100110") is not good.

Can you help Hr0d1y answer each query?

Input

The first line of the input contains a single integer t (1≤ t ≤ 100) — the number of test cases. The description of each test case is as follows.

The first line contains two integers n (2 ≤ n ≤ 100) and q (1≤ q ≤ 100) — the length of the string and the number of queries.

The second line contains the string s.

The i-th of the next q lines contains two integers l_i and r_i (1 ≤ l_i < r_i ≤ n).

Output

For each test case, output q lines. The i-th line of the output of each test case should contain "YES" if there exists a good subsequence equal to the substring s[l_i...r_i], and "NO" otherwise.

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

Example

Input

2
6 3
001000
2 4
1 3
3 5
4 2
1111
1 4
2 3

Output

YES
NO
YES
NO
YES

Note

In the first test case,

  * s[2… 4] =  "010". In this case s_1s_3s_5 ("001000") and s_2s_3s_6 ("001000") are good suitable subsequences, while s_2s_3s_4 ("001000") is not good.
  * s[1… 3] =  "001". No suitable good subsequence exists.
  * s[3… 5] =  "100". Here s_3s_5s_6 ("001000") is a suitable good subsequence.

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	for(int i=1;i<=q;i++){
		int l,r;
		cin>>l>>r;
		int flag1=0,flag2=0;
		for(int j=r;j<n;j++){
			if(s[j]==s[r-1]){
				flag1=1;
			    break;
	        }
	    }
	    for(int j=0;j<(l-1);j++){
			if(s[j]==s[l-1]){
				flag2=1;
				break;
			}
		}
		if(l==1){
			if(r==n)
			cout<<"NO"<<endl;
			else{

				if(flag1==1)
				cout<<"YES"<<endl;
				else
				cout<<"NO"<<endl;
			}
		}
		else if(r==n){
			if(l==1)
			cout<<"NO"<<endl;
			else{
				if(flag2==1){
					cout<<"YES"<<endl;
				}
				else{
					cout<<"NO"<<endl;
				}
			}
		}
		else{
			if(flag1==1||flag2==1){
				cout<<"YES"<<endl;
			}
			else{
				cout<<"NO"<<endl;
			}
		}
	}
}
int main(void){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

The only difference between easy and hard versions is constraints.

A session has begun at Beland State University. Many students are taking exams.

Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:

  * The i-th student randomly chooses a ticket.
  * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
  * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.

Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

The duration of the whole exam for all students is M minutes (max t_i ≤ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.

For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.

For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.

Input

The first line of the input contains two integers n and M (1 ≤ n ≤ 100, 1 ≤ M ≤ 100) — the number of students and the total duration of the exam in minutes, respectively.

The second line of the input contains n integers t_i (1 ≤ t_i ≤ 100) — time in minutes that i-th student spends to answer to a ticket.

It's guaranteed that all values of t_i are not greater than M.

Output

Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.

Examples

Input

7 15
1 2 3 4 5 6 7

Output

0 0 0 0 0 2 3

Input

5 100
80 40 40 40 60

Output

0 1 1 2 3

Note

The explanation for the example 1.

Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.

In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).

In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
long long v[maxn], cnt[107];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &v[i]);
    int l = m - v[i];
    int num = 0;
    for (int j = 1; j <= 100; j++) {
      if (l - cnt[j] * j >= 0) {
        l -= cnt[j] * j;
        num += cnt[j];
      } else {
        num += l / j;
        l = 0;
      }
      if (!l) break;
    }
    printf("%d ", i - 1 - num);
    cnt[v[i]]++;
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).

There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves.

Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.

For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.

Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.

Input

The first line of the input contain two integers n and m (3 ≤ n ≤ 150 000, <image>) — the number of members and the number of pairs of members that are friends.

The i-th of the next m lines contains two distinct integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Members ai and bi are friends with each other. No pair of members will appear more than once in the input.

Output

If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).

Examples

Input

4 3
1 3
3 4
1 4

Output

YES

Input

4 4
3 1
2 3
3 4
1 2

Output

NO

Input

10 4
4 3
5 10
8 9
1 2

Output

YES

Input

3 2
1 2
2 3

Output

NO

Note

The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int parent[150000];
int size[150000];
long long int edges[150000];
struct dsu {
  void init(int n) {
    for (int i = 0; i < n; ++i) {
      parent[i] = i;
      size[i] = 1;
      edges[i] = 0;
    }
  }
  int p(int x) {
    if (parent[x] == x) return x;
    return parent[x] = p(parent[x]);
  }
  void unite(int x, int y) {
    int supx = p(x);
    int supy = p(y);
    if (supx != supy) {
      if (size[x] > size[y]) {
        parent[supy] = supx;
        size[supx] += size[supy];
        edges[supx] += edges[supy] + 1;
      } else {
        parent[supx] = supy;
        size[supy] += size[supx];
        edges[supy] += edges[supx] + 1;
      }
    } else {
      edges[supx]++;
    }
  }
};
int n, m, x, y;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  dsu d;
  d.init(n);
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    x--;
    y--;
    d.unite(x, y);
  }
  for (int i = 0; i < n; ++i) {
    if (parent[i] == i) {
      long long int ed = edges[i];
      long long int vertices = size[i];
      if (ed != (vertices * (vertices - 1)) / 2) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Acacius is studying strings theory. Today he came with the following problem.

You are given a string s of length n consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?

Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".

Occurrence of a string t of length m in the string s of length n as a substring is a index i (1 ≤ i ≤ n - m + 1) such that string s[i..i+m-1] consisting of m consecutive symbols of s starting from i-th equals to string t. For example string "ababa" has two occurrences of a string "aba" as a substring with i = 1 and i = 3, but there are no occurrences of a string "aba" in the string "acba" as a substring.

Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once.

Input

First line of input contains an integer T (1 ≤ T ≤ 5000), number of test cases. T pairs of lines with test case descriptions follow.

The first line of a test case description contains a single integer n (7 ≤ n ≤ 50), length of a string s.

The second line of a test case description contains string s of length n consisting of lowercase English letters and question marks.

Output

For each test case output an answer for it.

In case if there is no way to replace question marks in string s with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No".

Otherwise output "Yes" and in the next line output a resulting string consisting of n lowercase English letters. If there are multiple possible strings, output any.

You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).

Example

Input

6
7
abacaba
7
???????
11
aba?abacaba
11
abacaba?aba
15
asdf???f???qwer
11
abacabacaba

Output

Yes
abacaba
Yes
abacaba
Yes
abadabacaba
Yes
abacabadaba
No
No

Note

In first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.

In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.

In sixth example there are two occurrences of a string "abacaba" as a substring.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const string S = "abacaba";
int main() {
  int TC;
  scanf("%d", &TC);
  for (int tc = 1; tc <= TC; tc++) {
    int n;
    char tmp[55];
    scanf("%d %s", &n, tmp);
    string s = tmp;
    int cnt = 0;
    for (int i = 0; i <= n - 7; i++) {
      if (s.substr(i, 7) == S) cnt++;
    }
    if (cnt >= 2) {
      printf("no\n");
      continue;
    }
    if (cnt == 1) {
      for (int i = 0; i < n; i++) {
        if (s[i] == '?') s[i] = 'z';
      }
      printf("yes\n");
      printf("%s\n", s.c_str());
      continue;
    }
    bool yes = false;
    for (int i = 0; i <= n - 7; i++) {
      bool flag = true;
      for (int j = i; j < i + 7; j++) {
        if (s[j] == '?') continue;
        if (s[j] != S[j - i]) {
          flag = false;
          break;
        }
      }
      if (!flag) continue;
      string tmps = s;
      tmps.replace(i, 7, S);
      cnt = 0;
      for (int j = 0; j <= n - 7; j++) {
        if (tmps.substr(j, 7) == S) cnt++;
      }
      if (cnt == 1) {
        yes = true;
        s.replace(i, 7, S);
        break;
      }
    }
    if (!yes) {
      printf("no\n");
      continue;
    }
    printf("yes\n");
    for (int i = 0; i < n; i++) {
      if (s[i] == '?')
        putchar('z');
      else
        putchar(s[i]);
    }
    putchar('\n');
  }
  return 0;
}

```


### Prompt

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

Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.

The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is 0.

Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.

Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex v:

  * If v has a left subtree whose root is u, then the parity of the key of v is different from the parity of the key of u.
  * If v has a right subtree whose root is w, then the parity of the key of v is the same as the parity of the key of w.

You are given a single integer n. Find the number of perfectly balanced striped binary search trees with n vertices that have distinct integer keys between 1 and n, inclusive. Output this number modulo 998 244 353.

Input

The only line contains a single integer n (1 ≤ n ≤ 10^6), denoting the required number of vertices.

Output

Output the number of perfectly balanced striped binary search trees with n vertices and distinct integer keys between 1 and n, inclusive, modulo 998 244 353.

Examples

Input

4

Output

1

Input

3

Output

0

Note

In the first example, this is the only tree that satisfies the conditions: <image>

In the second example, here are various trees that don't satisfy some condition: <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int MOD = 998244353;
void Add(int& a, int b) {
  a += b;
  a -= a >= MOD ? MOD : 0;
}
int Mul(int a, int b) { return 1ll * a * b % MOD; }
int f[N];
int dp[N][2][2];
int Calc(int l, int first, int k) {
  if (l == 1) return first == k;
  if (l == 2) return first != k;
  if (dp[l][first][k] != -1) return dp[l][first][k];
  int small = (l - 1) / 2, lim1 = f[small], lim2 = lim1 * 2 + 1;
  int& ret = dp[l][first][k] = 0;
  while (true) {
    int mid1 = small, mid2 = l - 1 - small;
    if ((mid1 + first) % 2 == k) {
      if (Calc(mid1, first, 1 - k) && Calc(l - 1 - mid1, 1 - k, k)) {
        ret = 1;
        break;
      }
    }
    if (mid2 != mid1 && (mid2 + first) % 2 == k)
      if (Calc(mid2, first, 1 - k) && Calc(l - 1 - mid2, 1 - k, k)) {
        ret = 1;
        break;
      }
    break;
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  int it = 0;
  for (int i = 1; i <= n; ++i) {
    while (((1 << (it + 1)) - 1) <= i) ++it;
    f[i] = (1 << it) - 1;
  }
  memset(dp, -1, sizeof dp);
  int x = (Calc(n, 1, 0) + Calc(n, 1, 1)) % MOD;
  cout << x << '\n';
}

```


### Prompt

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

I'm the Map, I'm the Map! I'm the MAP!!!

Map

In anticipation of new adventures Boots wanted to do a good deed. After discussion with the Map and Backpack, they decided to gift Dora a connected graph. After a long search, Boots chose t graph's variants, which Dora might like. However fox Swiper wants to spoil his plan.

The Swiper knows, that Dora now is only able to count up to 3, so he has came up with a following idea. He wants to steal some non-empty set of vertices, so that the Dora won't notice the loss. He has decided to steal some non-empty set of vertices, so that after deletion of the stolen vertices and edges adjacent to them, every remaining vertex wouldn't change it's degree modulo 3. The degree of a vertex is the number of edges it is adjacent to. It would've been suspicious to steal all the vertices, so Swiper needs another plan.

Boots are sure, that the crime can not be allowed. However they are afraid, that they won't be able to handle this alone. So Boots decided to ask for your help. Please determine for every graph's variant whether the Swiper can perform the theft or not.

Input

The first line contains a single integer t (1 ≤ t ≤ 100 000) — the number of graph variants.

The first line of each variant contains integers n, m (1 ≤ n ≤ 500 000, 0 ≤ m ≤ 500 000), the number of vertexes and edges in the graph.

Then m lines follow, each containing integers a_i, b_i (1 ≤ a_i, b_i ≤ n), the indices of the vertices connected with a corresponding edge.

It's guaranteed, that the graph is connected and doesn't contain multiple edges or self-loops.

It's guaranteed, that the sum of n over all variants is at most 500 000 and that the sum of m over all variants is at most 500 000.

Descriptions of graph's variants are separated with an empty line.

Output

For each variant:

  * In case the answer exists, print "Yes" and then the answer itself.

The first line should contain an integer c (1 < c < n), the number of vertices the Crook can steal, without Dora noticing the loss. On the next line print c distinct integers, the indices of the graph's vertices in arbitrary order.

  * Otherwise print "No".

In case there are several correct ways to steal the vertices, print any of them.

Please note, that it's not required to maximize the number of stolen vertices.

Example

Input

3
3 3
1 2
2 3
3 1

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

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

Output

No
Yes
3
4 5 6
Yes
3
6 7 8

Note

The picture below shows the third variant from the example test. The set of the vertices the Crook can steal is denoted with bold.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3c3c3c3c;
const long long LINF = 1ll * INF * INF * 2;
const int N = 1000001;
int n, m, x, y;
vector<int> v[N];
queue<int> q;
int dis[N];
int prv[N];
bool vst[N];
int idx;
vector<int> ans;
pair<int, int> Z = {0, 0};
pair<int, int> dfs(int cur, int prv, int h) {
  if (cur == h) return Z;
  if (vst[cur]) return {cur, prv};
  vst[cur] = true;
  for (int nxt : v[cur]) {
    if (nxt == prv) continue;
    pair<int, int> temp = dfs(nxt, cur, h);
    if (temp != Z) return temp;
  }
  return Z;
}
void print();
bool findCycle(int h) {
  for (int i = 1; i <= n; i++) vst[i] = false;
  for (int i = 1; i <= n; i++) {
    if (vst[i]) continue;
    pair<int, int> c = dfs(i, 0, h);
    if (c != Z) {
      int s = c.first, e = c.second;
      for (int j = 1; j <= n; j++) dis[j] = INF;
      dis[s] = 0;
      q.push(s);
      while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (int nxt : v[cur]) {
          if (cur == s && nxt == e) continue;
          if (cur == h) continue;
          if (dis[nxt] == INF)
            dis[nxt] = dis[cur] + 1, prv[nxt] = cur, q.push(nxt);
        }
      }
      for (int j = 1; j <= n; j++) vst[j] = false;
      for (int j = e; j != s; j = prv[j]) vst[j] = true;
      vst[s] = true;
      print();
      return true;
    }
  }
  return false;
}
void print() {
  printf("Yes\n");
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (!vst[i]) cnt++;
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++)
    if (!vst[i]) printf("%d ", i);
  printf("\n");
}
void mark(int cur) {
  if (vst[cur]) return;
  vst[cur] = true;
  for (int nxt : v[cur]) mark(nxt);
}
void unmark(int cur, int x, int y) {
  if (cur == x || cur == y) return;
  if (!vst[cur]) return;
  vst[cur] = false;
  for (int nxt : v[cur]) unmark(nxt, x, y);
}
void proc(int tc) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) v[i].clear();
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  if (n == 1) {
    printf("No\n");
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (((int)((v[i]).size())) % 3 == 0) {
      for (int i = 1; i <= n; i++) vst[i] = false;
      vst[i] = true;
      print();
      return;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (((int)((v[i]).size())) % 3 == 1) cnt++;
  if (cnt > 1) {
    for (int i = 1; i <= n; i++) {
      if (((int)((v[i]).size())) % 3 == 1) {
        for (int i = 1; i <= n; i++) dis[i] = INF;
        dis[i] = 0;
        q.push(i);
        while (!q.empty()) {
          int cur = q.front();
          q.pop();
          for (int nxt : v[cur])
            if (dis[nxt] == INF)
              dis[nxt] = dis[cur] + 1, prv[nxt] = cur, q.push(nxt);
        }
        int tt = INF;
        for (int j = 1; j <= n; j++) {
          if (i != j && ((int)((v[j]).size())) % 3 == 1) tt = min(tt, dis[j]);
        }
        if (tt == n - 1) {
          printf("No\n");
          return;
        }
        for (int j = 1; j <= n; j++) {
          if (i != j && ((int)((v[j]).size())) % 3 == 1 && dis[j] == tt) {
            for (int i = 1; i <= n; i++) vst[i] = false;
            for (int c = j; c != i; c = prv[c]) {
              vst[c] = true;
            }
            vst[i] = true;
            print();
            return;
          }
        }
        printf("No\n");
        return;
      }
    }
  }
  if (cnt == 1) {
    for (int i = 1; i <= n; i++)
      if (((int)((v[i]).size())) % 3 == 1) {
        idx = i;
        break;
      }
    for (int i = 1; i <= n; i++) vst[i] = false;
    if (findCycle(idx)) return;
    for (int i = 1; i <= n; i++) {
      if (i == idx) continue;
      if (((int)((v[i]).size())) > 3) {
        for (int i = 1; i <= n; i++) vst[i] = true;
        int c = 0;
        for (int j = 0; c < 3; j++) {
          if (v[i][j] == idx) continue;
          unmark(v[i][j], i, idx);
          c++;
        }
        print();
        return;
      }
    }
    if (((int)((v[idx]).size())) == 4) {
      printf("No\n");
      return;
    }
    int t = 0;
    vst[idx] = true;
    for (int i = 1; i <= n; i++) vst[i] = false;
    vst[idx] = true;
    for (int i = 0; t < 2; i++) {
      if (vst[v[idx][i]]) continue;
      mark(v[idx][i]);
      t++;
    }
    print();
    return;
  }
  bool flag = true;
  for (int i = 1; i <= n; i++)
    if (((int)((v[i]).size())) != 2) {
      flag = false;
      break;
    }
  if (flag) {
    printf("No\n");
    return;
  }
  findCycle(0);
}
void findTC(int num, int x) {
  for (int tc = 1; tc <= num; tc++) {
    scanf("%d%d", &n, &m);
    if (tc == x) printf("%d %d\n", n, m);
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &x, &y);
      if (tc == x) printf("%d %d\n", x, y);
    }
  }
}
int main(void) {
  int tc;
  scanf("%d", &tc);
  for (int i = 1; i <= tc; i++) proc(i);
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Masha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on the floor x, Egor on the floor y (not on the same floor with Masha).

The house has a staircase and an elevator. If Masha uses the stairs, it takes t_1 seconds for her to walk between adjacent floors (in each direction). The elevator passes between adjacent floors (in each way) in t_2 seconds. The elevator moves with doors closed. The elevator spends t_3 seconds to open or close the doors. We can assume that time is not spent on any action except moving between adjacent floors and waiting for the doors to open or close. If Masha uses the elevator, it immediately goes directly to the desired floor.

Coming out of the apartment on her floor, Masha noticed that the elevator is now on the floor z and has closed doors. Now she has to choose whether to use the stairs or use the elevator.

If the time that Masha needs to get to the Egor's floor by the stairs is strictly less than the time it will take her using the elevator, then she will use the stairs, otherwise she will choose the elevator.

Help Mary to understand whether to use the elevator or the stairs.

Input

The only line contains six integers x, y, z, t_1, t_2, t_3 (1 ≤ x, y, z, t_1, t_2, t_3 ≤ 1000) — the floor Masha is at, the floor Masha wants to get to, the floor the elevator is located on, the time it takes Masha to pass between two floors by stairs, the time it takes the elevator to pass between two floors and the time it takes for the elevator to close or open the doors.

It is guaranteed that x ≠ y.

Output

If the time it will take to use the elevator is not greater than the time it will take to use the stairs, print «YES» (without quotes), otherwise print «NO> (without quotes).

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

Examples

Input

5 1 4 4 2 1

Output

YES

Input

1 6 6 2 1 1

Output

NO

Input

4 1 7 4 1 2

Output

YES

Note

In the first example:

If Masha goes by the stairs, the time she spends is 4 ⋅ 4 = 16, because she has to go 4 times between adjacent floors and each time she spends 4 seconds.

If she chooses the elevator, she will have to wait 2 seconds while the elevator leaves the 4-th floor and goes to the 5-th. After that the doors will be opening for another 1 second. Then Masha will enter the elevator, and she will have to wait for 1 second for the doors closing. Next, the elevator will spend 4 ⋅ 2 = 8 seconds going from the 5-th floor to the 1-st, because the elevator has to pass 4 times between adjacent floors and spends 2 seconds each time. And finally, it will take another 1 second before the doors are open and Masha can come out.

Thus, all the way by elevator will take 2 + 1 + 1 + 8 + 1 = 13 seconds, which is less than 16 seconds, so Masha has to choose the elevator.

In the second example, it is more profitable for Masha to use the stairs, because it will take 13 seconds to use the elevator, that is more than the 10 seconds it will takes to go by foot.

In the third example, the time it takes to use the elevator is equal to the time it takes to walk up by the stairs, and is equal to 12 seconds. That means Masha will take the elevator.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, z, t1, t2, t3, totalstair, totalelevator;
  cin >> x >> y >> z >> t1 >> t2 >> t3;
  totalstair = abs(x - y) * t1;
  if (x == z)
    totalelevator = (abs(x - y) * t2) + (3 * t3);
  else
    totalelevator = (abs(x - z) * t2) + (abs(x - y) * t2) + (3 * t3);
  if (totalelevator <= totalstair)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

The only difference between easy and hard versions is the maximum value of n.

You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.

The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).

For example:

  * 30 is a good number: 30 = 3^3 + 3^1,
  * 1 is a good number: 1 = 3^0,
  * 12 is a good number: 12 = 3^2 + 3^1,
  * but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
  * 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
  * 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).

Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.

For the given positive integer n find such smallest m (n ≤ m) that m is a good number.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. Then q queries follow.

The only line of the query contains one integer n (1 ≤ n ≤ 10^4).

Output

For each query, print such smallest integer m (where n ≤ m) that m is a good number.

Example

Input

7
1
2
6
13
14
3620
10000

Output

1
3
9
13
27
6561
19683

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve(long long n) {
  vector<long long> arr(39);
  long long k = n;
  for (long long i = 0; i < 38; i++) {
    arr[i] = n % 3;
    n /= 3;
  }
  long long last = -1;
  for (long long i = 0; i < 38; i++) {
    if (arr[i] == 2) {
      last = i;
    }
  }
  if (last == -1) {
    cout << k << endl;
    return;
  }
  for (long long i = last; i < 39; i++) {
    if (arr[i] == 0) {
      for (long long j = 0; j < i; j++) {
        arr[j] = 0;
      }
      arr[i] = 1;
      long long ans = 0;
      long long now = 1;
      for (long long j = 0; j < 39; j++) {
        ans += now * arr[j];
        now *= 3;
      }
      cout << ans << endl;
      return;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  for (long long _ = 0; _ < q; _++) {
    long long n;
    cin >> n;
    solve(n);
  }
  return 0;
}

```


### Prompt

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

Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.

Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).

Input

The first line contains a single integer n~(2 ≤ n ≤ 100).

The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s.

Output

If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.

Otherwise print "YES" in the first line.

The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.

If there exist multiple solutions, then print any of them.

Examples

Input

4
3 5 7 1

Output

YES
BABA

Input

3
3 5 1

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  int in[n];
  int count[101] = {0};
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    count[in[i]]++;
  }
  int niceCount = 0;
  int gtTwoInd = -1;
  string res;
  for (int i = 0; i < n; i++) {
    if (count[in[i]] > 0) {
      if (count[in[i]] == 1) {
        niceCount++;
        if (niceCount % 2) {
          res += "A";
        } else {
          res += "B";
        }
      } else {
        if (count[in[i]] > 2) {
          gtTwoInd = i;
        }
        res += "A";
      }
    }
  }
  if (niceCount % 2) {
    if (gtTwoInd == -1) {
      cout << "NO" << endl;
    } else {
      res[gtTwoInd] = 'B';
      cout << "YES" << endl;
      cout << res << endl;
    }
  } else {
    cout << "YES" << endl;
    cout << res << endl;
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Create a program that outputs the surface area S of a square cone with a height of h, with a square with one side x as the base. However, assume that the line segment connecting the apex and the center of the base is orthogonal to the base. Also, x and h are positive integers less than or equal to 100.

Input

Given multiple datasets. Each dataset is given in the following format:

x
h

When both x and h are 0, it indicates the end of input.

Output

Output S (real number) on one line for each data set. The output may contain an error of 0.00001 or less.

Example

Input

6
4
7
9
0
0

Output

96.000000
184.192455

### Response

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

using namespace std;

int main(int argc, char const* argv[])
{
	double x,h,S;

	while( cin >> x >> h && x != 0 ){
		double x2 = x/2;
		double l = sqrt( x2 * x2 + h * h );
		S = l * x * 2 + x * x;
		printf("%.6f\n",S);
	}
	return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

Constraints

* 1 \leq N \leq 10^9
* N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the largest square number not exceeding N.

Examples

Input

10

Output

9

Input

81

Output

81

Input

271828182

Output

271821169

### Response

```cpp
#include<iostream>
#include<cmath>
using namespace std;
int a;
int main(){
  cin>>a;
  a=sqrt(a);
  cout<<a*a<<endl;
}
```


### Prompt

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

Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below carefully and follow it and not the similar rules in real programming languages.

There is a very powerful system of pointers on &K* — you can add an asterisk to the right of the existing type X — that will result in new type X * . That is called pointer-definition operation. Also, there is the operation that does the opposite — to any type of X, which is a pointer, you can add an ampersand — that will result in a type &X, to which refers X. That is called a dereference operation.

The &K* language has only two basic data types — void and errtype. Also, the language has operators typedef and typeof.

  * The operator "typedef A B" defines a new data type B, which is equivalent to A. A can have asterisks and ampersands, and B cannot have them. For example, the operator typedef void** ptptvoid will create a new type ptptvoid, that can be used as void**.
  * The operator "typeof A" returns type of A, brought to void, that is, returns the type void**...*, equivalent to it with the necessary number of asterisks (the number can possibly be zero). That is, having defined the ptptvoid type, as shown above, the typeof ptptvoid operator will return void**.

An attempt of dereferencing of the void type will lead to an error: to a special data type errtype. For errtype the following equation holds true: errtype* = &errtype = errtype. An attempt to use the data type that hasn't been defined before that will also lead to the errtype.

Using typedef, we can define one type several times. Of all the definitions only the last one is valid. However, all the types that have been defined earlier using this type do not change.

Let us also note that the dereference operation has the lower priority that the pointer operation, in other words &T *  is always equal to T.

Note, that the operators are executed consecutively one by one. If we have two operators "typedef &void a" and "typedef a* b", then at first a becomes errtype, and after that b becomes errtype* = errtype, but not &void* = void (see sample 2).

Vasya does not yet fully understand this powerful technology, that's why he asked you to help him. Write a program that analyzes these operators.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of operators. Then follow n lines with operators. Each operator is of one of two types: either "typedef A B", or "typeof A". In the first case the B type differs from void and errtype types, and besides, doesn't have any asterisks and ampersands.

All the data type names are non-empty lines of no more than 20 lowercase Latin letters. The number of asterisks and ampersands separately in one type in any operator does not exceed 10, however if we bring some types to void with several asterisks, their number may exceed 10.

Output

For every typeof operator print on the single line the answer to that operator — the type that the given operator returned.

Examples

Input

5
typedef void* ptv
typeof ptv
typedef &&ptv node
typeof node
typeof &ptv

Output

void*
errtype
void

Input

17
typedef void* b
typedef b* c
typeof b
typeof c
typedef &b b
typeof b
typeof c
typedef &&b* c
typeof c
typedef &b* c
typeof c
typedef &void b
typeof b
typedef b******* c
typeof c
typedef &&b* c
typeof c

Output

void*
void**
void
void**
errtype
void
errtype
errtype
errtype

Note

Let's look at the second sample.

After the first two queries typedef the b type is equivalent to void*, and с — to void**.

The next query typedef redefines b — it is now equal to &b = &void* = void. At that, the с type doesn't change.

After that the с type is defined as &&b* = &&void* = &void = errtype. It doesn't influence the b type, that's why the next typedef defines c as &void* = void.

Then the b type is again redefined as &void = errtype.

Please note that the c type in the next query is defined exactly as errtype******* = errtype, and not &void******* = void******. The same happens in the last typedef.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
string get_type(string s) {
  if (mp.count(s)) return mp[s];
  int n = s.size();
  if (s[0] == '&' && s[n - 1] == '*') return get_type(s.substr(1, n - 2));
  if (s[0] == '&') {
    string ret = get_type(s.substr(1, n - 1));
    int sz = ret.size();
    if (ret == "void" or ret == "errtype")
      return "errtype";
    else {
      if (ret[sz - 1] == '*') return ret.substr(0, sz - 1);
      return s[0] + ret;
    }
  }
  if (s[n - 1] == '*') {
    string ret = get_type(s.substr(0, n - 1));
    if (ret[0] == '&') return ret.substr(1, n - 1);
    if (ret == "errtype") return "errtype";
    return get_type(s.substr(0, n - 1)) + s[n - 1];
  }
  return "errtype";
}
void add_type(string u, string v) { mp[v] = get_type(u); }
int main() {
  mp["void"] = "void";
  mp["&void"] = "errtype";
  mp["errtype"] = "errtype";
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    string fun, u, v;
    cin >> fun;
    if (fun == "typedef") {
      cin >> u >> v;
      add_type(u, v);
    } else {
      cin >> u;
      cout << get_type(u) << "\n";
    }
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.

Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.

Input

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

The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj if i ≠ j.

Output

Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.

Examples

Input

4
1 9
3 1
6 1
7 4

Output

1

Input

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

Output

3

Note

For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.

For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<int, int> > x(n);
  for (int i = 0; i < n; i++) cin >> x[i].first >> x[i].second;
  sort(x.begin(), x.end());
  vector<int> dp(n);
  dp[0] = 1;
  int ma = 1;
  for (int i = 1; i < n; i++) {
    int l = -1, r = i;
    while (r - l > 1) {
      int s = (l + r) / 2;
      if (x[i].first - x[s].first > x[i].second) {
        l = s;
      } else {
        r = s;
      }
    }
    if (r == 0) {
      dp[i] = 1;
    } else {
      dp[i] = dp[r - 1] + 1;
    }
    ma = max(ma, dp[i]);
  }
  cout << n - ma;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters.

Since you spend a lot of time typing it, you want to buy a new keyboard.

A keyboard is a permutation of the first m Latin letters. For example, if m = 3, then there are six possible keyboards: abc, acb, bac, bca, cab and cba.

Since you type your password with one finger, you need to spend time moving your finger from one password character to the next. The time to move from character s_i to character s_{i+1} is equal to the distance between these characters on keyboard. The total time you have to spend typing the password with a keyboard is called the slowness of this keyboard.

More formaly, the slowness of keyboard is equal to ∑_{i=2}^{n} |pos_{s_{i-1}} - pos_{s_i} |, where pos_x is position of letter x in keyboard.

For example, if s is aacabc and the keyboard is bac, then the total time of typing this password is |pos_a - pos_a| + |pos_a - pos_c| + |pos_c - pos_a| + |pos_a - pos_b| + |pos_b - pos_c| = |2 - 2| + |2 - 3| + |3 - 2| + |2 - 1| + |1 - 3| = 0 + 1 + 1 + 1 + 2 = 5.

Before buying a new keyboard you want to know the minimum possible slowness that the keyboard can have.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 20).

The second line contains the string s consisting of n characters. Each character is one of the first m Latin letters (lowercase).

Output

Print one integer – the minimum slowness a keyboard can have.

Examples

Input

6 3
aacabc

Output

5

Input

6 4
aaaaaa

Output

0

Input

15 4
abacabadabacaba

Output

16

Note

The first test case is considered in the statement.

In the second test case the slowness of any keyboard is 0.

In the third test case one of the most suitable keyboards is bacd.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int N, M;
string S;
long long dp[(1 << 20)];
const long long INF = 1e18;
int alp[26][26];
long long cost[(1 << 20)];
long long solve(int state) {
  if (dp[state] != INF) return dp[state];
  if (state == 0) return 0;
  for (int i = 0; i < M; i++) {
    if (state & (1 << i)) {
      dp[state] =
          min(dp[state], solve(state ^ (1 << i)) + cost[state ^ (1 << i)]);
    }
  }
  return dp[state];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  cin >> S;
  for (int i = 0; i < N - 1; i++) {
    if (S[i] != S[i + 1]) {
      alp[S[i] - 'a'][S[i + 1] - 'a']++;
      alp[S[i + 1] - 'a'][S[i] - 'a']++;
    }
  }
  for (int i = 0; i < (1 << M); i++) dp[i] = INF;
  dp[0] = 0;
  for (int i = 1; i < (1 << M) - 1; i++) {
    vector<int> x, y;
    for (int j = 0; j < M; j++) {
      if (i & (1 << j))
        x.push_back(j);
      else
        y.push_back(j);
    }
    for (int j = 0; j < x.size(); j++) {
      for (int k = 0; k < y.size(); k++) {
        cost[i] += alp[x[j]][y[k]];
      }
    }
  }
  cout << solve((1 << M) - 1) << endl;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.

Two pictures are considered to be different if the coordinates of corresponding rectangles are different.

Input

The first line of input contains four space-separated integers r, c, n, k (1 ≤ r, c, n ≤ 3000, 1 ≤ k ≤ min(n, 10)) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.

The next n lines each contain two integers xi and yi (1 ≤ xi ≤ r, 1 ≤ yi ≤ c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.

Output

Print a single integer — the number of photographs Paul can take which include at least k violas.

Examples

Input

2 2 1 1
1 2

Output

4

Input

3 2 3 3
1 1
3 1
2 2

Output

1

Input

3 2 3 2
1 1
3 1
2 2

Output

4

Note

We will use '*' to denote violinists and '#' to denote violists.

In the first sample, the orchestra looks as follows:

    *#
    **

Paul can take a photograph of just the viola, the 1 × 2 column containing the viola, the 2 × 1 row containing the viola, or the entire string section, for 4 pictures total.

In the second sample, the orchestra looks as follows:

    #*
    *#
    #*

Paul must take a photograph of the entire section.

In the third sample, the orchestra looks the same as in the second sample.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
vector<list<int>::iterator> where[N];
vector<int> violas[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int r, c, n, m;
  cin >> r >> c >> n >> m;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    violas[x - 1].push_back(y - 1);
  }
  long long ans = 0;
  for (int i = 0; i < r; ++i) {
    list<int> linked;
    for (int j = i; j < r; ++j) {
      for (auto k : violas[j]) {
        linked.push_back(k);
      }
    }
    linked.sort();
    for (auto it = linked.begin(); it != linked.end(); ++it) {
      where[*it].push_back(it);
    }
    linked.push_front(-1);
    linked.push_back(c);
    int sum = 0, segment = 0;
    for (int j = 0, k = 0; j < c; ++j) {
      for (; k < c && segment + (int)where[k].size() < m; ++k) {
        segment += where[k].size();
      }
      sum += k - j;
      segment -= where[j].size();
    }
    for (int j = r - 1; j >= i; --j) {
      ans += sum;
      for (auto k : violas[j]) {
        auto it = where[k].back();
        where[k].pop_back();
        if ((int)linked.size() - 2 >= m) {
          auto right = it, left = it;
          for (int l = 0; l < m - 1; ++l) {
            if (*(--left) == -1) {
              ++left, ++right;
            }
          }
          while (true) {
            sum += (*left - *prev(left)) * (*next(right) - *right);
            if (left++ == it || *(++right) == c) {
              break;
            }
          }
        }
        linked.erase(it);
      }
    }
  }
  cout << (long long)(r * (r + 1) / 2) * (c * (c + 1) / 2) - ans << "\n";
}

```


### Prompt

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

You have decided to watch the best moments of some movie. There are two buttons on your player:

  1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.
  2. Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x).

Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the li-th minute and ends at the ri-th minute (more formally, the i-th best moment consists of minutes: li, li + 1, ..., ri).

Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?

Input

The first line contains two space-separated integers n, x (1 ≤ n ≤ 50, 1 ≤ x ≤ 105) — the number of the best moments of the movie and the value of x for the second button.

The following n lines contain the descriptions of the best moments of the movie, the i-th line of the description contains two integers separated by a space li, ri (1 ≤ li ≤ ri ≤ 105).

It is guaranteed that for all integers i from 2 to n the following condition holds: ri - 1 < li.

Output

Output a single number — the answer to the problem.

Examples

Input

2 3
5 6
10 12

Output

6

Input

1 1
1 100000

Output

100000

Note

In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie.

In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  cin >> n >> t;
  int total = 0;
  int current = 1;
  int l, r;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    int temp = (l - current) / t;
    current += (t * temp);
    total += ((r - current) + 1);
    current = r + 1;
  }
  cout << total << endl;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!

It is well-known that there are n cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of cities is connected by no more than one road. It is not guaranteed that the road network is connected, i.e. it is possible that you can't reach some city from some other.

The tour will contain several episodes. In each of the episodes:

  * the wizard will disembark at some city x from the Helicopter;
  * he will give a performance and show a movie for free at the city x;
  * he will drive to some neighboring city y using a road;
  * he will give a performance and show a movie for free at the city y;
  * he will drive to some neighboring to y city z;
  * he will give a performance and show a movie for free at the city z;
  * he will embark the Helicopter and fly away from the city z.

It is known that the wizard doesn't like to use roads, so he agrees to use each road at most once (regardless of direction). In other words, for road between a and b he only can drive once from a to b, or drive once from b to a, or do not use this road at all.

The wizards wants to plan as many episodes as possible without violation the above rules. Help the wizard!

Please note that the wizard can visit the same city multiple times, the restriction is on roads only.

Input

The first line contains two integers n, m (1 ≤ n ≤ 2·105, 0 ≤ m ≤ 2·105) — the number of cities and the number of roads in Berland, respectively.

The roads description follow, one in each line. Each description is a pair of two integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), where ai and bi are the ids of the cities connected by the i-th road. It is guaranteed that there are no two roads connecting the same pair of cities. Every road is bidirectional. The cities are numbered from 1 to n.

It is possible that the road network in Berland is not connected.

Output

In the first line print w — the maximum possible number of episodes. The next w lines should contain the episodes in format x, y, z — the three integers denoting the ids of the cities in the order of the wizard's visits.

Examples

Input

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

Output

2
1 4 2
4 3 2

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2e5 + 10;
vector<pair<int, int>> g[MAXN];
bool used[MAXN];
bool edge[MAXN];
struct path {
  int x, y, z;
};
vector<path> ans;
bool dfs(int u, int p) {
  used[u] = 1;
  int x = 0;
  for (auto e : g[u]) {
    int v = e.first;
    bool ok2 = 0;
    if (!used[v])
      ok2 = dfs(v, u);
    else
      ok2 = 1;
    if (ok2 && v != p && !edge[e.second]) {
      if (!x)
        x = v;
      else {
        ans.push_back({x, u, v});
        x = 0;
      }
      edge[e.second] = 1;
    }
  }
  if (x && p != -1) ans.push_back({x, u, p});
  return !x;
}
int main() {
  int n, m;
  cin >> n >> m;
  int num = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back({v, num});
    g[v].push_back({u, num++});
  }
  for (int u = 1; u <= n; u++)
    if (!used[u]) dfs(u, -1);
  cout << ans.size() << "\n";
  for (auto i : ans) cout << i.x << " " << i.y << " " << i.z << "\n";
  return 0;
}

```


### Prompt

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

Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?

Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.

Input

The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.

Output

In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.

Examples

Input

4
5 0 5 0

Output

0

Input

11
5 5 5 5 5 5 5 5 0 5 5

Output

5555555550

Note

In the first test you can make only one number that is a multiple of 90 — 0.

In the second test you can make number 5555555550, it is a multiple of 90.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int nums[2] = {0};
  cin >> n;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0)
      nums[0]++;
    else
      nums[1]++;
  }
  int fives = nums[1] / 9;
  if (fives > 0 && nums[0] > 0) {
    for (int i = 0; i < fives * 9; i++) cout << 5;
    for (int i = 0; i < nums[0]; i++) cout << 0;
  } else {
    cout << (nums[0] > 0 ? 0 : -1);
  }
  cout << endl;
}

```


### Prompt

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

There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies.

Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:

  1. Give m candies to the first child of the line.
  2. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
  3. Repeat the first two steps while the line is not empty.

Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?

Input

The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100).

Output

Output a single integer, representing the number of the last child.

Examples

Input

5 2
1 3 1 4 2

Output

4

Input

6 4
1 1 2 2 3 3

Output

6

Note

Let's consider the first sample.

Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.

Child 4 is the last one who goes home.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  int p = -1;
  int ma = 0;
  for (int i = 0; i < n; ++i) {
    int x = (v[i] + m - 1) / m;
    if (x >= ma) {
      p = i;
      ma = x;
    }
  }
  cout << p + 1 << endl;
}

```


### Prompt

Please create a solution in cpp to the following problem:

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

Input

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

Output

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

Examples

Input

0 0 0
0 1 0

Output

YES

Input

1 1 0
0 1 0

Output

YES

Input

0 0 0
1 1 1

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> v;
  long long a, b, c = 0, d = 0, e = 0, f = 0, g = 0, i, j, k = 1, l = 0, r = 0,
                  n, m[300001], z[400001], h[600001], p[600001];
  string s, t, x, y[1001];
  double q, u, w;
  cin >> a >> b >> c >> d >> e >> f;
  if (a != d && b != e && c != f) {
    cout << "NO";
  } else {
    cout << "YES";
  }
}

```