### Prompt

Generate a Cpp solution to the following problem:

There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting sequence, i.e. the number of such index pairs (i, j), that i < j and pi > pj.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of swap operations applied to the sequence.

Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109, ai ≠ bi) — the arguments of the swap operation.

Output

Print a single integer — the number of inversions in the resulting sequence.

Examples

Input

2
4 2
1 4

Output

4

Input

3
1 6
3 4
2 5

Output

15

Note

In the first sample the sequence is being modified as follows: <image>. It has 4 inversions formed by index pairs (1, 4), (2, 3), (2, 4) and (3, 4).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int bd = 18, bdv = 1 << bd;
int n;
map<int, int> mp;
vector<int> arrx;
int rsq[bdv * 2];
int segtree_plus(int pos) {
  pos += bdv;
  rsq[pos] = 1;
  pos /= 2;
  while (pos) {
    rsq[pos] = rsq[pos * 2] + rsq[pos * 2 + 1];
    pos /= 2;
  }
  return 0;
}
int segtree_sum(int v, int vl, int vr, int l, int r) {
  if (r < vl || vr < l) {
    return 0;
  }
  if (l <= vl && vr <= r) {
    return rsq[v];
  }
  int vm = (vl + vr) / 2;
  return segtree_sum(v * 2, vl, vm, l, r) +
         segtree_sum(v * 2 + 1, vm + 1, vr, l, r);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    arrx.push_back(a);
    arrx.push_back(b);
    if (!mp.count(a)) {
      mp[a] = a;
    }
    if (!mp.count(b)) {
      mp[b] = b;
    }
    int tmp = mp[a];
    mp[a] = mp[b];
    mp[b] = tmp;
  }
  sort((arrx).begin(), (arrx).end());
  arrx.resize(unique((arrx).begin(), (arrx).end()) - arrx.begin());
  long long ans = 0;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    int where = it->first;
    int what = it->second;
    ans += segtree_sum(
        1, 0, bdv - 1,
        lower_bound((arrx).begin(), (arrx).end(), what) - arrx.begin() + 1,
        bdv - 1);
    if (what > where) {
      ans += what - where -
             (upper_bound((arrx).begin(), (arrx).end(), what) -
              upper_bound((arrx).begin(), (arrx).end(), where));
    } else {
      ans += where - what -
             (upper_bound((arrx).begin(), (arrx).end(), where) -
              upper_bound((arrx).begin(), (arrx).end(), what));
    }
    segtree_plus(lower_bound((arrx).begin(), (arrx).end(), what) -
                 arrx.begin());
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a1, a2, ..., an. The number ak represents that the kth destination is at distance ak kilometers from the starting point. No two destinations are located in the same place.

Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination.

The distance between destination located at kilometer x and next destination, located at kilometer y, is |x - y| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all n destinations and he doesn't visit a destination more than once.

Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him.

Input

The first line contains integer n (2 ≤ n ≤ 105). Next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 107).

Output

Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.

Examples

Input

3
2 3 5

Output

22 3

Note

Consider 6 possible routes:

  * [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5;
  * [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7;
  * [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7;
  * [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8;
  * [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9;
  * [5, 3, 2]: |5 – 0| + |3 – 5| + |2 – 3| = 8.

The average travel distance is <image> = <image> = <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcdof(long long int a, long long int b) {
  if (a == 0) return b;
  return gcdof(b % a, a);
}
int main() {
  int n, i;
  cin >> n;
  long long int a[n];
  long long int num = 0, sum = 0, gcd;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  sort(a, a + n);
  num = num + sum;
  for (i = 0; i < n - 1; i++) {
    sum = sum - a[i];
    num = num + 2 * (sum - ((n - (i + 1)) * a[i]));
  }
  gcd = gcdof(n, num);
  num = num / gcd;
  n = n / gcd;
  cout << num << " " << n << endl;
}

```


### Prompt

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

The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.

The main school of the capital is located in (s_x, s_y). There are n students attending this school, the i-th of them lives in the house located in (x_i, y_i). It is possible that some students live in the same house, but no student lives in (s_x, s_y).

After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the i-th student goes from the school to his house is |s_x - x_i| + |s_y - y_i|.

The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the i-th student will buy a shawarma if at least one of the shortest paths from the school to the i-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).

You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.

Input

The first line contains three integers n, s_x, s_y (1 ≤ n ≤ 200 000, 0 ≤ s_x, s_y ≤ 10^{9}) — the number of students and the coordinates of the school, respectively.

Then n lines follow. The i-th of them contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^{9}) — the location of the house where the i-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.

Output

The output should consist of two lines. The first of them should contain one integer c — the maximum number of students that will buy shawarmas at the tent.

The second line should contain two integers p_x and p_y — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of p_x and p_y should be not less than 0 and not greater than 10^{9}.

Examples

Input

4 3 2
1 3
4 2
5 1
4 1

Output

3
4 2

Input

3 100 100
0 0
0 0
100 200

Output

2
99 100

Input

7 10 12
5 6
20 23
15 4
16 5
4 54
12 1
4 15

Output

4
10 11

Note

In the first example, If we build the shawarma tent in (4, 2), then the students living in (4, 2), (4, 1) and (5, 1) will visit it.

In the second example, it is possible to build the shawarma tent in (1, 1), then both students living in (0, 0) will visit it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  T = 1;
start:
  while (T--) {
    long long n, sx, sy;
    cin >> n >> sx >> sy;
    long long u = 0, d = 0, l = 0, r = 0;
    for (long long i = 0; i < n; i++) {
      long long x, y;
      cin >> x >> y;
      if (x == sx) {
        if (y > sy) {
          u++;
        } else {
          d++;
        }
      } else if (y == sy) {
        if (x > sx) {
          r++;
        } else {
          l++;
        }
      } else if (x < sx && y > sy) {
        l++;
        u++;
      } else if (x < sx && y < sy) {
        l++;
        d++;
      } else if (x > sx && y > sy) {
        r++;
        u++;
      } else if (x > sx && y < sy) {
        r++;
        d++;
      }
    }
    long long e = max(max(l, r), max(u, d));
    cout << e << endl;
    if (e == u) {
      cout << sx << " " << sy + 1 << endl;
    } else if (e == l) {
      cout << sx - 1 << " " << sy << endl;
    } else if (e == r) {
      cout << sx + 1 << " " << sy << endl;
    } else {
      cout << sx << " " << sy - 1 << endl;
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).

Constraints

* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* 0 ≤ wi ≤ 10,000
* G has arborescence(s) with the root r

Input

|V| |E| r
s0 t0 w0
s1 t1 w1
:
s|E|-1 t|E|-1 w|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence.

si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.

Output

Print the sum of the weights the Minimum-Cost Arborescence.

Examples

Input

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

Output

6

Input

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

Output

11

### Response

```cpp
// 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1060290#1

#include <iostream>
#include <vector>
using namespace std;

const int MAX = 105;
const int INF = 10001;

void visit(int V, int G[MAX][MAX], int v, int s, int r,
    vector<int> &no, vector< vector<int> > &comp,
    vector<int> &prev, vector< vector<int> > &next,
    vector<int> &mcost, vector<int> &mark,
    int &cost, bool &found) {
  if (mark[v]) {
    vector<int> temp = no;
    found = true;
    do {
      cost += mcost[v];
      v = prev[v];
      if (v != s) {
        while (comp[v].size() > 0) {
          no[comp[v].back()] = s;
          comp[s].push_back(comp[v].back());
          comp[v].pop_back();
        }
      }
    } while (v != s);

    //REP(i, V){
    for(int i = 0;i < V;++i){
      if(i != r && no[i] == s)
        //REP(j, V){
        for(int j = 0;j < V;++j){
          if (no[j] != s && G[j][i] < INF) G[j][i] -= mcost[temp[i]];
        }
    }
  }
  mark[v] = true;
  //REP(i, next[v].size())
  for(int i = 0;i < next[v].size();++i)
    if(no[next[v][i]] != no[v] && prev[no[next[v][i]]] == v)
      if (!mark[no[next[v][i]]] || next[v][i] == s)
        visit(V, G, next[v][i], s, r, no, comp, prev, next, mcost, mark, cost, found);

}

int minimumSpanningArborescence(int V, int E, int G[MAX][MAX], int r) {
  vector<int> no(V);
  vector< vector<int> > comp(V);
  for(int i = 0;i < V;++i) comp[i].push_back(no[i] = i);

  for(int cost = 0; ;) {
    vector<int> prev(V, -1);
    vector<int> mcost(V, INF);

    for(int i = 0;i < V;++i){
      for(int j = 0;j < V;++j){
        if(j == r || G[i][j] == INF || no[i] == no[j] || G[i][j] > mcost[no[j]]) continue;
        mcost[no[j]] = G[i][j];
        prev[no[j]] = no[i];
      }
    }
    vector< vector<int> > next(V);
    //REP(i, V)
    for(int i = 0;i < V;++i)
      if(prev[i] >= 0)
        next[prev[i]].push_back(i);

    bool stop = true;
    vector<int> mark(V, false);

    for(int i = 0;i < V;++i)
      if(i != r && !mark[i] && !comp[i].empty()) {
        bool found = false;
        visit(V, G, i, i, r, no, comp, prev, next, mcost, mark, cost, found);
        if (found) stop = false;
      }
    if (stop) {
      for(int i = 0;i < V;++i) if (prev[i] >= 0) cost += mcost[i];
      return cost;
    }
  }
}

int main() {
  int vNum,eNum,s;
  cin >> vNum >> eNum >> s;
  int G[MAX][MAX];
  for(int i = 0;i < vNum;++i)
    for(int j = 0;j < vNum;++j)
        G[i][j] = (i == j ? 0 : INF);

  for(int i = 0;i < eNum;++i){
    int v,e,w;
    cin >> v >> e >> w;
    G[v][e] = w;
  }
  cout <<minimumSpanningArborescence(vNum,eNum, G, s) <<endl;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime".

In each move, a slime can move to east, west, south and north direction until it enters a cell occupied by another slime or hit the surrounding wall. If two slimes come together, they unite and become a new slime.

Your task is write a program which calculates the minimum number of moves that all the slimes unite and become a King Slime. Suppose slimes move one by one and they never move simultaneously.

Input

The first line contains three integers N (2 ≤ N ≤ 40,000), W and H (1 ≤ W, H ≤ 100,000), which denote the number of slimes, the width and the height of the grid respectively.

The following N lines describe the initial coordinates of the slimes. The i-th line contains two integers xi (1 ≤ xi ≤ W) and yi (1 ≤ yi ≤ H), which indicate the coordinates of the i-th slime . All the coordinates are 1-based.

You may assume that each cell is occupied by at most one slime initially.

Output

Output the minimum number of moves that all the slimes unite and become a King Slime.

Examples

Input

4 3 3
1 1
1 3
3 1
3 3

Output

3

Input

2 3 3
2 2
3 3

Output

2

Input

2 4 4
2 2
3 3

Output

3

Input

2 4 4
2 2
2 3

Output

1

### Response

```cpp
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, w, h;
vector<int> xIndex[100010];
vector<int> yIndex[100010];
int xs[100010];
int ys[100010];
bool visit[100010];

int main() {
  while (scanf("%d %d %d", &n, &w, &h) > 0) {
    MEMSET(visit, false);
    REP(i, 100010) { xIndex[i].clear(); yIndex[i].clear(); }
    int edge = 0;
    int ans = n - 2;
    REP(i, n) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (x == 1 || x == w || y == 1 || y == h) { edge = 1; }
      x--; y--;
      xs[i] = x; ys[i] = y;
      xIndex[x].push_back(i);
      yIndex[y].push_back(i);
    }
    REP(i, n) {
      if (visit[i]) { continue; }
      visit[i] = true;
      ans++;
      queue<int> que;
      que.push(i);
      while (!que.empty()) {
        int index = que.front();
        que.pop();
        FORIT(it, xIndex[xs[index]]) {
          if (visit[*it]) { continue; }
          visit[*it] = true;
          que.push(*it);
        }
        FORIT(it, yIndex[ys[index]]) {
          if (visit[*it]) { continue; }
          visit[*it] = true;
          que.push(*it);
        }
      }
    }
    if (ans != n - 1 && !edge) { ans++; }
    printf("%d\n", ans);
  }
}
```


### Prompt

Generate a Cpp solution to the following problem:

You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the expected value of the number of inversions in the resulting permutation.

Input

The first line of input contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 109). The next line contains n integers p1, p2, ..., pn — the given permutation. All pi are different and in range from 1 to n.

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

  * In subproblem G1 (3 points), the constraints 1 ≤ n ≤ 6, 1 ≤ k ≤ 4 will hold.
  * In subproblem G2 (5 points), the constraints 1 ≤ n ≤ 30, 1 ≤ k ≤ 200 will hold.
  * In subproblem G3 (16 points), the constraints 1 ≤ n ≤ 100, 1 ≤ k ≤ 109 will hold.

Output

Output the answer with absolute or relative error no more than 1e - 9.

Examples

Input

3 1
1 2 3

Output

0.833333333333333

Input

3 4
1 3 2

Output

1.458333333333334

Note

Consider the first sample test. We will randomly pick an interval of the permutation (1, 2, 3) (which has no inversions) and reverse the order of its elements. With probability <image>, the interval will consist of a single element and the permutation will not be altered. With probability <image> we will inverse the first two elements' order and obtain the permutation (2, 1, 3) which has one inversion. With the same probability we might pick the interval consisting of the last two elements which will lead to the permutation (1, 3, 2) with one inversion. Finally, with probability <image> the randomly picked interval will contain all elements, leading to the permutation (3, 2, 1) with 3 inversions. Hence, the expected number of inversions is equal to <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int p[6], n, k, ans, total;
void att(int z) {
  if (z == k) {
    total++;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) ans += p[i] > p[j];
    return;
  }
  for (int i = 0; i < n; i++)
    for (int j = i; j < n; j++) {
      reverse(p + i, p + j + 1);
      att(z + 1);
      reverse(p + i, p + j + 1);
    }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i];
  att(0);
  cout << fixed << setprecision(12) << 1. * ans / total << endl;
}

```


### Prompt

Create a solution in cpp for the following problem:

Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares.

For example, the correct field to play looks like that: 001*2***101*. The cells that are marked with "*" contain bombs. Note that on the correct field the numbers represent the number of bombs in adjacent cells. For example, field 2* is not correct, because cell with value 2 must have two adjacent cells with bombs.

Valera wants to make a correct field to play "Minesweeper 1D". He has already painted a squared field with width of n cells, put several bombs on the field and wrote numbers into some cells. Now he wonders how many ways to fill the remaining cells with bombs and numbers are there if we should get a correct field in the end.

Input

The first line contains sequence of characters without spaces s1s2... sn (1 ≤ n ≤ 106), containing only characters "*", "?" and digits "0", "1" or "2". If character si equals "*", then the i-th cell of the field contains a bomb. If character si equals "?", then Valera hasn't yet decided what to put in the i-th cell. Character si, that is equal to a digit, represents the digit written in the i-th square.

Output

Print a single integer — the number of ways Valera can fill the empty cells and get a correct field.

As the answer can be rather large, print it modulo 1000000007 (109 + 7).

Examples

Input

?01???

Output

4

Input

?

Output

2

Input

**12

Output

0

Input

1

Output

0

Note

In the first test sample you can get the following correct fields: 001**1, 001***, 001*2*, 001*10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline void smin(P &a, Q b) {
  if (b < a) a = b;
}
template <class P, class Q>
inline void smax(P &a, Q b) {
  if (a < b) a = b;
}
const int mod = 1000000000 + 7;
const int maxn = 1000000 + 100;
int n;
string s;
int dp[maxn][3];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s;
  if (isdigit(s.front())) s.front()++;
  if (isdigit(s.back())) s.back()++;
  s = '*' + s + '*';
  n = (int((s).size()));
  dp[1][2] = 1;
  for (int i = (int)(2), _n = (int)(n + 1); i < _n; i++) {
    char c = s[i - 1];
    char p = s[i - 2];
    if (c == '*' || c == '?') {
      dp[i][2] = dp[i - 1][2];
      if (p == '2' || p == '?') dp[i][2] = (dp[i][2] + dp[i - 1][1]) % mod;
      if (p == '1' || p == '?') dp[i][2] = (dp[i][2] + dp[i - 1][0]) % mod;
    }
    if (isdigit(c) || c == '?') {
      dp[i][1] = dp[i - 1][2];
      if (p == '1' || p == '?') dp[i][0] = (dp[i][0] + dp[i - 1][1]) % mod;
      if (p == '0' || p == '?') dp[i][0] = (dp[i][0] + dp[i - 1][0]) % mod;
    }
  }
  cout << (dp[n][0] + (long long)dp[n][1] + dp[n][2]) % mod << endl;
  { return 0; }
}

```


### Prompt

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

Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible improvements he can think of during the day (he now prefers to sleep at night). However, his assistants have found a solution and they now draw an imaginary city on a paper sheet and suggest the mayor can propose its improvements.

Right now he has a map of some imaginary city with n subway stations. Some stations are directly connected with tunnels in such a way that the whole map is a tree (assistants were short on time and enthusiasm). It means that there exists exactly one simple path between each pair of station. We call a path simple if it uses each tunnel no more than once.

One of Sergey Semyonovich's favorite quality objectives is the sum of all pairwise distances between every pair of stations. The distance between two stations is the minimum possible number of tunnels on a path between them.

Sergey Semyonovich decided to add new tunnels to the subway map. In particular, he connected any two stations u and v that were not connected with a direct tunnel but share a common neighbor, i.e. there exists such a station w that the original map has a tunnel between u and w and a tunnel between w and v. You are given a task to compute the sum of pairwise distances between all pairs of stations in the new map.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 200 000) — the number of subway stations in the imaginary city drawn by mayor's assistants. Each of the following n - 1 lines contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), meaning the station with these indices are connected with a direct tunnel.

It is guaranteed that these n stations and n - 1 tunnels form a tree.

Output

Print one integer that is equal to the sum of distances between all pairs of stations after Sergey Semyonovich draws new tunnels between all pairs of stations that share a common neighbor in the original map.

Examples

Input

4
1 2
1 3
1 4

Output

6

Input

4
1 2
2 3
3 4

Output

7

Note

In the first sample, in the new map all pairs of stations share a direct connection, so the sum of distances is 6.

In the second sample, the new map has a direct tunnel between all pairs of stations except for the pair (1, 4). For these two stations the distance is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long ans;
long long num[2][200010], sz[2][200010];
vector<int> edge[200010];
void dfs1(int u, int r) {
  num[0][u] = num[1][u] = sz[1][u] = 0;
  sz[0][u] = 1;
  for (auto v : edge[u]) {
    if (v == r) continue;
    dfs1(v, u);
    num[0][u] += num[1][v];
    num[1][u] += num[0][v] + sz[0][v];
    sz[0][u] += sz[1][v];
    sz[1][u] += sz[0][v];
  }
}
void dfs2(int u, int r) {
  ans += num[0][u] + num[1][u];
  for (auto v : edge[u]) {
    if (v == r) continue;
    num[0][v] += num[1][u] - num[0][v] - sz[0][v];
    num[1][v] += num[0][u] - num[1][v] + sz[0][u] - sz[1][v];
    sz[0][v] += sz[1][u] - sz[0][v];
    sz[1][v] += sz[0][u] - sz[1][v];
    dfs2(v, u);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  ans = 0;
  dfs1(1, 1);
  dfs2(1, 1);
  printf("%lld\n", ans >> 1);
}

```


### Prompt

Please create a solution in cpp to the following problem:

Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.

To improve his division skills, Oleg came up with t pairs of integers p_i and q_i and for each pair decided to find the greatest integer x_i, such that:

  * p_i is divisible by x_i;
  * x_i is not divisible by q_i.

Oleg is really good at division and managed to find all the answers quickly, how about you?

Input

The first line contains an integer t (1 ≤ t ≤ 50) — the number of pairs.

Each of the following t lines contains two integers p_i and q_i (1 ≤ p_i ≤ 10^{18}; 2 ≤ q_i ≤ 10^{9}) — the i-th pair of integers.

Output

Print t integers: the i-th integer is the largest x_i such that p_i is divisible by x_i, but x_i is not divisible by q_i.

One can show that there is always at least one value of x_i satisfying the divisibility conditions for the given constraints.

Example

Input

3
10 4
12 6
179 822

Output

10
4
179

Note

For the first pair, where p_1 = 10 and q_1 = 4, the answer is x_1 = 10, since it is the greatest divisor of 10 and 10 is not divisible by 4.

For the second pair, where p_2 = 12 and q_2 = 6, note that

  * 12 is not a valid x_2, since 12 is divisible by q_2 = 6;
  * 6 is not valid x_2 as well: 6 is also divisible by q_2 = 6.

The next available divisor of p_2 = 12 is 4, which is the answer, since 4 is not divisible by 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long aa, bb;
    cin >> aa >> bb;
    if (aa % bb != 0) {
      cout << aa << endl;
      continue;
    }
    long long ans = 1;
    vector<long long> jj;
    for (long long i = 1; i * i <= bb; i++) {
      if (bb % i == 0) {
        jj.push_back(bb / i);
        jj.push_back(i);
      }
    }
    for (auto i : jj) {
      if (i == 1) {
        continue;
      }
      long long st = 0;
      for (long long j = 2; j * j <= i; j++) {
        if (i % j == 0) {
          st = 1;
          break;
        }
      }
      if (st) {
        continue;
      }
      long long co = 0;
      long long dd = aa;
      while (dd % i == 0) {
        co++;
        dd /= i;
      }
      long long co2 = 0;
      dd = bb;
      while (dd % i == 0) {
        co2++;
        dd /= i;
      }
      long long kk = 1;
      for (long long j = 0; j < max(co - co2 + 1, (long long)0); j++) {
        kk *= i;
      }
      ans = max(ans, aa / (kk));
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day — exactly 2 problems, during the third day — exactly 3 problems, and so on. During the k-th day he should solve k problems.

Polycarp has a list of n contests, the i-th contest consists of a_i problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly k problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least k problems that Polycarp didn't solve yet during the k-th day, then Polycarp stops his training.

How many days Polycarp can train if he chooses the contests optimally?

Input

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

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5) — the number of problems in the i-th contest.

Output

Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.

Examples

Input

4
3 1 4 1

Output

3

Input

3
1 1 1

Output

1

Input

5
1 1 1 2 2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  multiset<long long int> s;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    s.insert(x);
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    while (s.size()) {
      long long int x = *(s.begin());
      if (x >= i) break;
      s.erase(s.begin());
    }
    if (!s.size()) break;
    ans++;
    s.erase(s.begin());
  }
  cout << ans;
}

```


### Prompt

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

Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is n.

There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains 2 apartments, every other floor contains x apartments each. Apartments are numbered starting from one, from the first floor. I.e. apartments on the first floor have numbers 1 and 2, apartments on the second floor have numbers from 3 to (x + 2), apartments on the third floor have numbers from (x + 3) to (2 ⋅ x + 2), and so on.

Your task is to find the number of floor on which Petya lives. Assume that the house is always high enough to fit at least n apartments.

You have to answer t independent test cases.

Input

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

The only line of the test case contains two integers n and x (1 ≤ n, x ≤ 1000) — the number of Petya's apartment and the number of apartments on each floor of the house except the first one (there are two apartments on the first floor).

Output

For each test case, print the answer: the number of floor on which Petya lives.

Example

Input

4
7 3
1 5
22 5
987 13

Output

3
1
5
77

Note

Consider the first test case of the example: the first floor contains apartments with numbers 1 and 2, the second one contains apartments with numbers 3, 4 and 5, the third one contains apartments with numbers 6, 7 and 8. Therefore, Petya lives on the third floor.

In the second test case of the example, Petya lives in the apartment 1 which is on the first floor.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1e9 + 7;
const long long MOD2 = 5e6;
long long t, n, x;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> x;
    if (n <= 2) {
      cout << 1 << "\n";
      continue;
    }
    n -= 2;
    long long ans = 1;
    ans += (n + x - 1) / x;
    cout << ans << "\n";
  }
}

```


### Prompt

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

The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, the chairperson requested every member to send back a list of convenient dates by E-mail. Your mission is to help the chairperson, who is now dedicated to other issues of the contest, by writing a program that chooses the best date from the submitted lists. Your program should find the date convenient for the most members. If there is more than one such day, the earliest is the best.

Input

The input has multiple data sets, each starting with a line containing the number of committee members and the quorum of the meeting.

> N Q

Here, N, meaning the size of the committee, and Q meaning the quorum, are positive integers. N is less than 50, and, of course, Q is less than or equal to N.

N lines follow, each describing convenient dates for a committee member in the following format.

> M Date1 Date2 ... DateM

Here, M means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 100, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces.

A line containing two zeros indicates the end of the input.

Output

For each data set, print a single line containing the date number convenient for the largest number of committee members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead.

Example

Input

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

Output

4
5
0
2

### Response

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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  int N, Q;
  int M;
  while(cin >> N >> Q, N||Q){
    vector<int> P(100, 0);
    for(int i = 0; i < N; i++){
      cin >> M;
      vector<int> Date(M);
      for(int j = 0; j < M; j++){
        cin >> Date[j];
        P[Date[j]]++;
      }
    }

    int m = 0, ans = 0;
    for(int i = 0; i < P.size(); i++){
      if(P[i] > m){
        ans = i;
        m = P[i];
      }
    }
    if(m >= Q)cout << ans << endl;
    else cout << 0 << endl;
  }
}
```


### Prompt

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

Takahashi has a lot of peculiar devices. These cylindrical devices receive balls from left and right. Each device is in one of the two states A and B, and for each state, the device operates as follows:

* When a device in state A receives a ball from either side (left or right), the device throws out the ball from the same side, then immediately goes into state B.
* When a device in state B receives a ball from either side, the device throws out the ball from the other side, then immediately goes into state A.

The transition of the state of a device happens momentarily and always completes before it receives another ball.

Takahashi built a contraption by concatenating N of these devices. In this contraption,

* A ball that was thrown out from the right side of the i-th device from the left (1 \leq i \leq N-1) immediately enters the (i+1)-th device from the left side.
* A ball that was thrown out from the left side of the i-th device from the left (2 \leq i \leq N) immediately enters the (i-1)-th device from the right side.

The initial state of the i-th device from the left is represented by the i-th character in a string S. From this situation, Takahashi performed the following K times: put a ball into the leftmost device from the left side, then wait until the ball comes out of the contraption from either end. Here, it can be proved that the ball always comes out of the contraption after a finite time. Find the state of each device after K balls are processed.

Constraints

* 1 \leq N \leq 200,000
* 1 \leq K \leq 10^9
* |S|=N
* Each character in S is either `A` or `B`.

Input

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

N K
S

Output

Print a string that represents the state of each device after K balls are processed. The string must be N characters long, and the i-th character must correspond to the state of the i-th device from the left.

Examples

Input

5 1
ABAAA

Output

BBAAA

Input

5 2
ABAAA

Output

ABBBA

Input

4 123456789
AABB

Output

BABA

### Response

```cpp
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}

int n, k, p;
string s;

int main()
{
	n = read();
	k = read();
	cin >> s;
	if (k > n << 1)
		k = (n << 1) + ((k - (n << 1)) & 1);

	char ch = 'A';
	for (int i = 1; i <= k; i++) {
		if (s[p] == ch) {
			s[p] = 'A' + 'B' - ch;
		} else {
			ch = 'A' + 'B' - ch;
			p = (p + 1) % n;
		}
	}

	for (int i = p; i < n; i++) {
		if (s[i] == ch)
			printf("A");
		else
			printf("B");
	}
	for (int i = 0; i < p; i++) {
		if (s[i] == ch)
			printf("A");
		else
			printf("B");
	}
	printf("\n");
	return 0;
}

```


### Prompt

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

According to the legends the king of Berland Berl I was noted for his love of beauty and order. One day he ordered to tile the palace hall's floor where balls and receptions used to take place with black and white tiles according to a regular geometrical pattern invented by him. However, as is after the case, due to low financing there were only a black and b white tiles delivered to the palace. The other c tiles were black and white (see the picture).

<image>

The initial plan failed! Having learned of that, the king gave a new command: tile the floor with the available tiles so that no black side of a tile touched a white one. The tiles are squares of one size 1 × 1, every black and white tile can be rotated in one of the four ways.

The court programmer was given the task to work out the plan of tiling and he coped with the task and didn't suffer the consequences of disobedience. And can you cope with it?

Input

The first line contains given integers n and m (1 ≤ n, m ≤ 100) which represent the sizes of the rectangle that needs to be tiled. The next line contains non-negative numbers a, b and c, a + b + c = nm, c ≥ m.

Output

Print 2n lines containing 2m characters each — the tiling scheme. Every tile is represented by a square 2 × 2 in the following manner (the order corresponds to the order of the picture above):

<image> If multiple solutions exist, output any.

Examples

Input

2 2
0 0 4

Output

\../
#\/#
\##/
.\/.

Input

2 3
1 2 3

Output

###/\#
##/..\
#/....
/.....

### Response

```cpp
#include <bits/stdc++.h>
struct Tblock {
  char order;
  bool L, R, U, D;
};
const int maxn = 207;
int n, m;
int a, b, c;
int x, y;
Tblock block[maxn][maxn];
char Map[maxn][maxn];
void empty() {
  for (int i = 0; i <= n; i++) block[i][0].R = true, block[i][m + 1].L = false;
  for (int j = 0; j <= m; j++) block[0][j].D = true, block[n + 1][j].U = false;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) block[i][j].order = 'N';
}
void prepare_black() {
  x = 1, y = 0;
  if (a == 0) return;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      block[i][j].order = 'B';
      block[i][j].L = block[i][j].R = block[i][j].U = block[i][j].D = true;
      if (--a == 0) {
        x = i, y = j;
        return;
      }
    }
}
void prepare_get_other(int i, int j) {
  block[i][j].order = 'O';
  if (block[i][j - 1].R == block[i - 1][j].D) {
    block[i][j].L = block[i][j].U = block[i][j - 1].R;
    block[i][j].R = block[i][j].D = !block[i][j].L;
  } else {
    block[i][j].L = block[i][j].D = block[i][j - 1].R;
    block[i][j].R = block[i][j].U = block[i - 1][j].D;
  }
  --c;
}
void prepare_check_other(int i, int j) {
  if (block[i][j + 1].L == block[i - 1][j].D) {
    block[i][j].R = block[i][j].U = block[i][j + 1].L;
    block[i][j].L = block[i][j].D = !block[i][j].R;
  } else {
    block[i][j].R = block[i][j].D = block[i][j + 1].L;
    block[i][j].L = block[i][j].U = block[i - 1][j].D;
  }
}
void prepare_other_1() {
  if (c == 0) return;
  for (int j = 1; j <= y; j++) {
    prepare_get_other(x + 1, j);
    if (c == 0) return;
  }
  if (x > 1) {
    for (int j = y + 1; j <= m; j++) {
      prepare_get_other(x, j);
      if (c == 0) return;
    }
    x = x + 1, y = y + 1;
  } else {
    if (y < m) {
      prepare_get_other(x, y + 1);
      x = x, y = y + 2;
    }
  }
}
void prepare_white() {
  while (b > 0) {
    if (y > m) x++, y = 1;
    if (block[x][y].order == 'N') {
      block[x][y].order = 'W';
      block[x][y].L = block[x][y].R = block[x][y].U = block[x][y].D = false;
      --b;
    }
    y++;
  }
}
void prepare_other_2() {
  while (c > 0) {
    if (y > m) x++, y = 1;
    if (block[x][y].order == 'N') prepare_get_other(x, y);
    y++;
  }
}
void prepare_check() {
  for (int i = n; i >= 1; i--)
    for (int j = m - 1; j >= 1; j--)
      if (block[i][j].order == 'O') prepare_check_other(i, j);
}
void work() {
  scanf("%d%d%d", &a, &b, &c);
  empty();
  prepare_black();
  prepare_other_1();
  prepare_white();
  prepare_other_2();
  prepare_check();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x = (i - 1) * 2 + 1, y = (j - 1) * 2 + 1;
      if (block[i][j].order == 'B') {
        Map[x][y] = Map[x + 1][y] = Map[x][y + 1] = Map[x + 1][y + 1] = '#';
      }
      if (block[i][j].order == 'W') {
        Map[x][y] = Map[x + 1][y] = Map[x][y + 1] = Map[x + 1][y + 1] = '.';
      }
      if (block[i][j].order == 'O') {
        if (block[i][j].U == block[i][j].L) {
          Map[x + 1][y] = Map[x][y + 1] = '/';
          if (block[i][j].U)
            Map[x][y] = '#', Map[x + 1][y + 1] = '.';
          else
            Map[x][y] = '.', Map[x + 1][y + 1] = '#';
        } else {
          Map[x][y] = Map[x + 1][y + 1] = '\\';
          if (block[i][j].U)
            Map[x][y + 1] = '#', Map[x + 1][y] = '.';
          else
            Map[x][y + 1] = '.', Map[x + 1][y] = '#';
        }
      }
    }
  for (int i = 1; i <= 2 * n; i++) {
    for (int j = 1; j <= 2 * m; j++) printf("%c", Map[i][j]);
    puts("");
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) work();
}

```


### Prompt

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

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

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

Find the maximum number of integers that Snuke can circle.

Constraints

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

Input

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

N
s_1
:
s_N

Output

Print the maximum number of integers that Snuke can circle.

Examples

Input

8
1
2
3
4
5
6
7
8

Output

6

Input

6
2
4
8
16
32
64

Output

3

Input

10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999

Output

9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n,s[100005],s1[100005],maxn=2e3+50,ans;
map<long long,long long> dem,used;
int main() {
	scanf("%lld",&n);
	for(long long i=0;i<n;i++){
		scanf("%lld",&s[i]);
		long long x=s[i];
		s[i]=s1[i]=1;
		for(long long j=2;j<=maxn;j++){
			if(x%j==0){
				long long cnt=0;
				while(x%j==0){
					x/=j;
					cnt++;
				}
				if(cnt%3==1){
					s[i]*=j;
					s1[i]*=j*j;
				}else if(cnt%3==2){
					s[i]*=j*j;
					s1[i]*=j;
				}
			}
		}
		if(x!=1){
			long long y=ceil(sqrt(x));
			s[i]*=x;
			if(y*y==x) s1[i]*=y;
			else s1[i]*=x*x;
		}
		dem[s[i]]++;
	}
	for(long long i=0;i<n;i++){
		if(!used[s[i]]){
			used[s[i]]=used[s1[i]]=1;
			if(s[i]==1) ans++;
			else ans+=max(dem[s[i]],dem[s1[i]]);
		}
	}
	printf("%lld",ans);
	return 0;
}

```


### Prompt

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

You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

For instance, if we are given an array [10, 20, 30, 40], we can permute it so that it becomes [20, 40, 10, 30]. Then on the first and the second positions the integers became larger (20>10, 40>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 2. Read the note for the first example, there is one more demonstrative test case.

Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the length of the array.

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

Output

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

Examples

Input

7
10 1 1 1 5 5 3

Output

4

Input

5
1 1 1 1 1

Output

0

Note

In the first sample, one of the best permutations is [1, 5, 5, 3, 10, 1, 1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; (i) < int(n); ++(i)) scanf("%d", &a[i]);
  map<int, int> b;
  for (int a_i : a) {
    b[a_i] += 1;
  }
  int answer = 0;
  int place = 0;
  for (auto it : b) {
    int cnt = it.second;
    int delta = min(place, cnt);
    answer += delta;
    place += cnt - delta;
  }
  printf("%d\n", answer);
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types:

  1. 1 l r x — increase all integers on the segment from l to r by values x;
  2. 2 l r — find <image>, where f(x) is the x-th Fibonacci number. As this number may be large, you only have to find it modulo 109 + 7.

In this problem we define Fibonacci numbers as follows: f(1) = 1, f(2) = 1, f(x) = f(x - 1) + f(x - 2) for all x > 2.

Sasha is a very talented boy and he managed to perform all queries in five seconds. Will you be able to write the program that performs as well as Sasha?

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of elements in the array and the number of queries respectively.

The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Then follow m lines with queries descriptions. Each of them contains integers tpi, li, ri and may be xi (1 ≤ tpi ≤ 2, 1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 109). Here tpi = 1 corresponds to the queries of the first type and tpi corresponds to the queries of the second type.

It's guaranteed that the input will contains at least one query of the second type.

Output

For each query of the second type print the answer modulo 109 + 7.

Examples

Input

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

Output

5
7
9

Note

Initially, array a is equal to 1, 1, 2, 1, 1.

The answer for the first query of the second type is f(1) + f(1) + f(2) + f(1) + f(1) = 1 + 1 + 1 + 1 + 1 = 5.

After the query 1 2 4 2 array a is equal to 1, 3, 4, 3, 1.

The answer for the second query of the second type is f(3) + f(4) + f(3) = 2 + 3 + 2 = 7.

The answer for the third query of the second type is f(1) + f(3) + f(4) + f(3) + f(1) = 1 + 2 + 3 + 2 + 1 = 9.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", 3, "inline")
using namespace std;
const long long Mod = 1e9 + 7;
const long long MAX_N = 100005;
struct mat {
  long long A[2][2];
  mat() { memset(A, 0, sizeof(A)); }
  long long* operator[](long long i) { return A[i]; }
};
bool operator==(mat a, mat b) {
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      if (a[i][j] != b[i][j]) return false;
    }
  }
  return true;
}
long long n, Q;
mat start, matrix, one;
mat operator+(mat a, mat b) {
  mat c = a;
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      c[i][j] += b[i][j];
      c[i][j] %= Mod;
    }
  }
  return c;
}
mat operator*(mat a, mat b) {
  mat c;
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      for (long long k = 0; k < 2; k++) {
        c[i][j] += a[i][k] * b[k][j];
        c[i][j] %= Mod;
      }
    }
  }
  return c;
}
mat bin_pow(mat a, long long b) {
  mat ret = a;
  b--;
  while (b > 0) {
    if (b % 2) ret = ret * a;
    a = a * a;
    b /= 2;
  }
  return ret;
}
void init() {
  start[0][0] = 1;
  start[0][1] = 0;
  matrix[0][0] = 1;
  matrix[0][1] = 1;
  matrix[1][0] = 1;
  one[0][0] = 1;
  one[1][1] = 1;
}
struct node {
  long long l, r;
  mat data;
  mat tag;
} T[MAX_N << 2];
void pushup(long long rt) {
  if (T[rt].l == T[rt].r) return;
  T[rt].data = T[(rt << 1)].data + T[(rt << 1 | 1)].data;
}
void pushdown(long long rt) {
  if (T[rt].l == T[rt].r) return;
  if (T[rt].tag == one) return;
  T[(rt << 1)].data = T[(rt << 1)].data * T[rt].tag;
  T[(rt << 1)].tag = T[(rt << 1)].tag * T[rt].tag;
  T[(rt << 1 | 1)].data = T[(rt << 1 | 1)].data * T[rt].tag;
  T[(rt << 1 | 1)].tag = T[(rt << 1 | 1)].tag * T[rt].tag;
  T[rt].tag = one;
}
long long A[MAX_N];
void build(long long rt, long long l, long long r) {
  T[rt].l = l;
  T[rt].r = r;
  T[rt].tag = one;
  if (l == r) {
    if (A[l] > 1)
      T[rt].data = start * bin_pow(matrix, A[l] - 1);
    else
      T[rt].data = start;
    return;
  }
  long long mid = (l + r) / 2;
  build((rt << 1), l, mid);
  build((rt << 1 | 1), mid + 1, r);
  pushup(rt);
}
mat query(long long rt, long long l, long long r) {
  pushdown(rt);
  if (T[rt].l == l && T[rt].r == r) return T[rt].data;
  if (r <= T[(rt << 1)].r)
    return query((rt << 1), l, r);
  else if (l >= T[(rt << 1 | 1)].l)
    return query((rt << 1 | 1), l, r);
  else
    return query((rt << 1), l, T[(rt << 1)].r) +
           query((rt << 1 | 1), T[(rt << 1 | 1)].l, r);
}
long long query(long long l, long long r) {
  mat ret = query(1, l, r);
  return ret[0][0];
}
mat mt;
void modify(long long rt, long long l, long long r) {
  if (T[rt].l == l && T[rt].r == r) {
    T[rt].data = T[rt].data * mt;
    T[rt].tag = T[rt].tag * mt;
    return;
  }
  pushdown(rt);
  if (r <= T[(rt << 1)].r)
    modify((rt << 1), l, r);
  else if (l >= T[(rt << 1 | 1)].l)
    modify((rt << 1 | 1), l, r);
  else
    modify((rt << 1), l, T[(rt << 1)].r),
        modify((rt << 1 | 1), T[(rt << 1 | 1)].l, r);
  pushup(rt);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  init();
  cin >> n >> Q;
  for (long long i = 1; i <= n; i++) cin >> A[i];
  build(1, 1, n);
  while (Q--) {
    long long op;
    cin >> op;
    if (op == 1) {
      long long l, r, x;
      cin >> l >> r >> x;
      mt = bin_pow(matrix, x);
      modify(1, l, r);
    } else {
      long long l, r;
      cin >> l >> r;
      cout << query(l, r) << endl;
    }
  }
  return 0;
}

```


### Prompt

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

You are given an integer N. Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes.

* Assume that, for each integer i between 1 and N (inclusive), Vertex i and N+i have the weight i. Then, for each integer i between 1 and N, the bitwise XOR of the weights of the vertices on the path between Vertex i and N+i (including themselves) is i.

Constraints

* N is an integer.
* 1 \leq N \leq 10^{5}

Input

Input is given from Standard Input in the following format:

N

Output

If there exists a tree satisfying the condition in the statement, print `Yes`; otherwise, print `No`. Then, if such a tree exists, print the 2N-1 edges of such a tree in the subsequent 2N-1 lines, in the following format:

a_{1} b_{1}
\vdots
a_{2N-1} b_{2N-1}

Here each pair (a_i, b_i) means that there is an edge connecting Vertex a_i and b_i. The edges may be printed in any order.

Examples

Input

3

Output

Yes
1 2
2 3
3 4
4 5
5 6

Input

1

Output

No

### Response

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

int main(){
	int N; cin >> N;
	if(1 << (int)(log2(N + 0.1)) == N){puts("No"); return 0;}
	puts("Yes");
	for(int i = 1 ; i < 3 ; ++i){
		cout << i << ' ' << i + 1 << endl;
		cout << i + N << ' ' << i + N + 1 << endl;
	}
	cout << 3 << ' ' << N + 1 << endl;
	for(int i = 4 ; i < N ; i += 2){
		cout << i << ' ' << i + 1 << endl;
		cout << i + 1 << ' ' << N + 1 << endl;
		cout << N + 1 << ' ' << i + N << endl;
		cout << i + N << ' ' << i + N + 1 << endl;
	}
	if(!(N & 1)){
		int t = 1 << (int)(log2(N + 0.1));
		cout << N << ' ' << t + N << endl; cout << N - t + 1 << ' ' << 2 * N << endl;
	}
	return 0;
}
```


### Prompt

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

One day Petya got a set of wooden cubes as a present from his mom. Petya immediately built a whole city from these cubes.

The base of the city is an n × n square, divided into unit squares. The square's sides are parallel to the coordinate axes, the square's opposite corners have coordinates (0, 0) and (n, n). On each of the unit squares Petya built a tower of wooden cubes. The side of a wooden cube also has a unit length.

After that Petya went an infinitely large distance away from his masterpiece and looked at it in the direction of vector v = (vx, vy, 0). Petya wonders, how many distinct cubes are visible from this position. Help him, find this number.

Each cube includes the border. We think that a cube is visible if there is a ray emanating from some point p, belonging to the cube, in the direction of vector  - v, that doesn't contain any points, belonging to other cubes.

Input

The first line contains three integers n, vx and vy (1 ≤ n ≤ 103, |vx|, |vy| ≤ |104|, |vx| + |vy| > 0).

Next n lines contain n integers each: the j-th integer in the i-th line aij (0 ≤ aij ≤ 109, 1 ≤ i, j ≤ n) represents the height of the cube tower that stands on the unit square with opposite corners at points (i - 1, j - 1) and (i, j).

Output

Print a single integer — the number of visible cubes.

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

Examples

Input

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

Output

20

Input

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

Output

15

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
vector<int> md, rel;
void relax(int idx, int l, int r) {
  if (rel[idx]) {
    md[idx] = max(md[idx], rel[idx]);
    if (l != r) {
      rel[idx << 1] = max(rel[idx << 1], rel[idx]);
      rel[idx << 1 | 1] = max(rel[idx << 1 | 1], rel[idx]);
    }
    rel[idx] = 0;
  }
}
int get(int idx, int l, int r, int a, int b) {
  relax(idx, l, r);
  if (b < l || r < a) return INF;
  if (a <= l && r <= b) return md[idx];
  int mid = (l + r) >> 1;
  return min(get(idx << 1, l, mid, a, b), get(idx << 1 | 1, mid + 1, r, a, b));
}
void update(int idx, int l, int r, int a, int b, int val) {
  relax(idx, l, r);
  if (b < l || r < a) return;
  if (a <= l && r <= b) {
    rel[idx] = val;
    return relax(idx, l, r);
  }
  int mid = (l + r) >> 1;
  update(idx << 1, l, mid, a, b, val);
  update(idx << 1 | 1, mid + 1, r, a, b, val);
  md[idx] = min(md[idx << 1], md[idx << 1 | 1]);
}
int a[1100][1100], l[1100][1100], r[1100][1100], h[1100][1100];
int main() {
  int n, vx, vy;
  cin >> n >> vx >> vy;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++) scanf("%d", &a[i][j]);
  vector<int> xs;
  xs.reserve(n * n * 2);
  vector<pair<int, pair<int, int> > > e;
  e.reserve(n * n);
  for (int x = 0; x < (int)(n); x++)
    for (int y = 0; y < (int)(n); y++) {
      l[x][y] = +INF;
      r[x][y] = -INF;
      h[x][y] = +INF;
      for (int dx = 0; dx < (int)(2); dx++)
        for (int dy = 0; dy < (int)(2); dy++) {
          l[x][y] = min(l[x][y], (x + dx) * vy - (y + dy) * vx);
          r[x][y] = max(r[x][y], (x + dx) * vy - (y + dy) * vx);
          h[x][y] = min(h[x][y], (x + dx) * vx + (y + dy) * vy);
        }
      xs.push_back(l[x][y]);
      xs.push_back(r[x][y]);
      e.push_back(make_pair(h[x][y], make_pair(x, y)));
    }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  sort(e.begin(), e.end());
  md.assign(xs.size() * 4, 0);
  rel.assign(xs.size() * 4, 0);
  long long ans = 0;
  for (int i = 0; i < (int)(e.size()); i++) {
    int x = e[i].second.first;
    int y = e[i].second.second;
    int lf = int(lower_bound(xs.begin(), xs.end(), l[x][y]) - xs.begin());
    int rg = int(lower_bound(xs.begin(), xs.end(), r[x][y]) - xs.begin()) - 1;
    int h = get(1, 0, (int)xs.size() - 1, lf, rg);
    if (h < a[x][y]) {
      ans += a[x][y] - h;
      update(1, 0, (int)xs.size() - 1, lf, rg, a[x][y]);
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Generalized leap year

Normally, whether or not the year x is a leap year is defined as follows.

1. If x is a multiple of 400, it is a leap year.
2. Otherwise, if x is a multiple of 100, it is not a leap year.
3. Otherwise, if x is a multiple of 4, it is a leap year.
4. If not, it is not a leap year.

This can be generalized as follows. For a sequence A1, ..., An, we define whether the year x is a "generalized leap year" as follows.

1. For the smallest i (1 ≤ i ≤ n) such that x is a multiple of Ai, if i is odd, it is a generalized leap year, and if it is even, it is not a generalized leap year.
2. When such i does not exist, it is not a generalized leap year if n is odd, but a generalized leap year if n is even.

For example, when A = [400, 100, 4], the generalized leap year for A is equivalent to a normal leap year.

Given the sequence A1, ..., An and the positive integers l, r. Answer the number of positive integers x such that l ≤ x ≤ r such that year x is a generalized leap year for A.

Input

The input consists of up to 50 datasets. Each dataset is represented in the following format.

> n l r A1 A2 ... An

The integer n satisfies 1 ≤ n ≤ 50. The integers l and r satisfy 1 ≤ l ≤ r ≤ 4000. For each i, the integer Ai satisfies 1 ≤ Ai ≤ 4000.

The end of the input is represented by a line of three zeros.

Output

Print the answer in one line for each dataset.

Sample Input

3 1988 2014
400
100
Four
1 1000 1999
1
2 1111 3333
2
2
6 2000 3000
Five
7
11
9
3
13
0 0 0

Output for the Sample Input

7
1000
2223
785

Example

Input

3 1988 2014
400
100
4
1 1000 1999
1
2 1111 3333
2
2
6 2000 3000
5
7
11
9
3
13
0 0 0

Output

7
1000
2223
785

### Response

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

int main(){
    ll n,l,r;
    while(1){
        cin>>n>>l>>r;
        if(n==0&&r==0&&l==0)break;
        ll a[n];
        for(ll i=0;i<n;i++)cin>>a[i];
        ll res = 0;
        bool flag=false;
        for(ll i=l;i<=r;i++){
            flag=false;
            for(ll j=0;j<n;j++){
                if(i%a[j]==0){
                    if((j+1)%2==1){
                        res++;
                        //cout<<i<<endl;
                        flag=true;
                    }else{
                        flag=true;
                    }
                    break;
                }
            }
            if(!flag){
                if(n%2==0)res++;
            }
        }
        cout<<res<<endl;
    }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison.

Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.

Find the maximum number of tasty cookies that Takahashi can eat.

Constraints

* 0 \leq A,B,C \leq 10^9
* A,B and C are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum number of tasty cookies that Takahashi can eat.

Examples

Input

3 1 4

Output

5

Input

5 2 9

Output

10

Input

8 8 1

Output

9

### Response

```cpp
#include <iostream>
#define ll long long
using namespace std;
ll x,y,z;
int main()
{
	cin >>x>>y>>z;
	cout <<y+min(x+y+1,z);
	return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

I decided to play rock-paper-scissors with a group of five good friends. Rock-paper-scissors has three hands: goo, choki, and par. If the game between goo and choki is a match between goo and choki, goo is "winning" and choki is "losing". , Par and Goo have the rule that Par is "winning" and Goo is "losing". If everyone has the same hand, or if all of Goo, Choki, and Par come out, it will be "Aiko".

Create a program that inputs the hands of five rock-paper-scissors players and outputs the wins and losses of each person. Rock-paper-scissors hands are represented by the numbers 1 for goo, 2 for choki, and 3 for par. Win / loss is represented by a number of 1, "win" is 1, "los" is 2, and "Aiko" is 3, and they are output according to the input order.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

h1
h2
h3
h4
h5

The i-th line is given the i-th hand hi (1, 2 or 3).

The number of datasets does not exceed 200.

Output

Outputs the wins and losses of 5 players for each input dataset. Output the win / loss (1, 2 or 3) of the i-th person on the i-line.

Example

Input

1
2
3
2
1
1
2
2
2
1
0

Output

3
3
3
3
3
1
2
2
2
1

### Response

```cpp
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<int>V(5);
    while(cin>>V[0],V[0]){
         vector<int>cnt(3,0);
         cnt[--V[0]]++;
         for(int i=1;i<5;i++){
            cin>>V[i];
            cnt[--V[i]]++;
         }
         bool flag=false;
         if(cnt[0]==5||cnt[1]==5||cnt[2]==5)flag=true;
         else if(cnt[0]&&cnt[1]&&cnt[2])flag=true;

         if(flag)for(int i=0;i<5;i++)cout<<3<<endl;
         else for(int i=0;i<5;i++)cout<<((cnt[V[i]]&&cnt[(V[i]+1)%3])?1:2)<<endl;
    }
    return 0;
}
```


### Prompt

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

This is an interactive problem. In the output section below you will see the information about flushing the output.

On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.

In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.

The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 ≤ x, y ≤ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says «TAK» to Leha, if <image>, and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.

Help Leha to solve this problem!

Input

There are two numbers n and k (2 ≤ k ≤ n ≤ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.

Output

If you want to provide an answer, output a string of the form 2 x y (1 ≤ x, y ≤ n, x ≠ y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.

Interaction

While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 ≤ x, y ≤ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.

After each query jury's program will print one line «TAK» or «NIE» (without quotes) in input stream depending on the girl's answer.

To flush you can use (just after printing an integer and end-of-line):

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

Hacking

For hacking you should write numbers n and k (2 ≤ k ≤ n ≤ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 ≤ ai ≤ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.

Example

Input

3 2
NIE
TAK
NIE
TAK
TAK
TAK

Output

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

Note

There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.

Let Leha asks Noora about the next couple of dishes:

  * x = 1, y = 2, then he'll recieve «NIE» answer, because |1 - 2| > |2 - 2|
  * x = 2, y = 1, then he'll recieve «TAK» answer, because |2 - 2| ≤ |1 - 2|
  * x = 1, y = 3, then he'll recieve «NIE» answer, because |1 - 2| > |3 - 3|
  * x = 3, y = 1, then he'll recieve «TAK» answer, because |3 - 3| ≤ |1 - 2|
  * x = 2, y = 3, then he'll recieve «TAK» answer, because |2 - 2| ≤ |3 - 3|
  * x = 3, y = 2, then he'll recieve «TAK» answer, because |3 - 3| ≤ |2 - 2|

According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class htpe, class cmp>
using heap = priority_queue<htpe, vector<htpe>, cmp>;
template <class htpe>
using min_heap = heap<htpe, greater<htpe> >;
template <class htpe>
using max_heap = heap<htpe, less<htpe> >;
const int INF = 1791791791;
const long long INFLL = 1791791791791791791ll;
bool query(int x, int y) {
  cout << 1 << " " << x << " " << y << endl;
  cout.flush();
  string s;
  cin >> s;
  return s == "TAK";
}
bool is_two_answers(int a, int b) { return query(a, b) && query(b, a); }
int find_on_segment(int l, int r, int tr) {
  l--;
  while (l < r - 1) {
    int mid = (l + r + tr) >> 1;
    if (!query(mid, mid + 1))
      l = mid;
    else
      r = mid;
  }
  return r;
}
int main() {
  int n, k;
  cin >> n >> k;
  int a = find_on_segment(1, n, 0);
  int b = find_on_segment(a + 1, n, 1);
  if (a + 1 > n || !is_two_answers(a, b)) b = find_on_segment(1, a - 1, 0);
  cout << 2 << " " << a << " " << b << endl;
  cout.flush();
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Levko loves strings of length n, consisting of lowercase English letters, very much. He has one such string s. For each string t of length n, Levko defines its beauty relative to s as the number of pairs of indexes i, j (1 ≤ i ≤ j ≤ n), such that substring t[i..j] is lexicographically larger than substring s[i..j].

The boy wondered how many strings t are there, such that their beauty relative to s equals exactly k. Help him, find the remainder after division this number by 1000000007 (109 + 7).

A substring s[i..j] of string s = s1s2... sn is string sisi + 1... sj.

String x = x1x2... xp is lexicographically larger than string y = y1y2... yp, if there is such number r (r < p), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. The string characters are compared by their ASCII codes.

Input

The first line contains two integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 2000).

The second line contains a non-empty string s of length n. String s consists only of lowercase English letters.

Output

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

Examples

Input

2 2
yz

Output

26

Input

2 3
yx

Output

2

Input

4 7
abcd

Output

21962

### Response

```cpp
#include <bits/stdc++.h>
const int MOD = 1E9 + 7;
int N, K;
char str[5000];
int dp[4000][4000];
int sum[4000];
int main() {
  scanf("%d%d", &N, &K);
  scanf("%s", str + 1);
  dp[0][0] = 1;
  sum[0] = 1;
  for (int i = 1; i <= N; ++i)
    for (int j = 0; j <= K; ++j) {
      dp[i][j] = 1ll * (str[i] - 'a') * sum[j] % MOD;
      for (int k = i - 1; k >= 0 && j - 1ll * (i - k) * (N - i + 1) >= 0; --k)
        dp[i][j] = (dp[i][j] + 1ll * (25 - (str[i] - 'a')) *
                                   dp[k][j - (i - k) * (N - i + 1)]) %
                   MOD;
      sum[j] = (sum[j] + dp[i][j]) % MOD;
    }
  int tot = 0;
  for (int i = 0; i <= N; ++i) tot = (tot + dp[i][K]) % MOD;
  printf("%d\n", tot);
}

```


### Prompt

Please create a solution in CPP to the following problem:

Indiana Jones found ancient Aztec catacombs containing a golden idol. The catacombs consists of n caves. Each pair of caves is connected with a two-way corridor that can be opened or closed. The entrance to the catacombs is in the cave 1, the idol and the exit are in the cave n.

When Indiana goes from a cave x to a cave y using an open corridor, all corridors connected to the cave x change their state: all open corridors become closed, all closed corridors become open. Indiana wants to go from cave 1 to cave n going through as small number of corridors as possible. Help him find the optimal path, or determine that it is impossible to get out of catacombs.

Input

The first line contains two integers n and m (2 ≤ n ≤ 3⋅ 10^5, 0 ≤ m ≤ 3 ⋅ 10^5) — the number of caves and the number of open corridors at the initial moment.

The next m lines describe the open corridors. The i-th of these lines contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) — the caves connected by the i-th open corridor. It is guaranteed that each unordered pair of caves is presented at most once.

Output

If there is a path to exit, in the first line print a single integer k — the minimum number of corridors Indians should pass through (1 ≤ k ≤ 10^6). In the second line print k+1 integers x_0, …, x_k — the number of caves in the order Indiana should visit them. The sequence x_0, …, x_k should satisfy the following:

  * x_0 = 1, x_k = n;
  * for each i from 1 to k the corridor from x_{i - 1} to x_i should be open at the moment Indiana walks along this corridor.

If there is no path, print a single integer -1.

We can show that if there is a path, there is a path consisting of no more than 10^6 corridors.

Examples

Input

4 4
1 2
2 3
1 3
3 4

Output

2
1 3 4

Input

4 2
1 2
2 3

Output

4
1 2 3 1 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<int> edges[N];
set<int> record[N];
int n, m;
bool bfs() {
  queue<int> q;
  q.push(1);
  vector<pair<int, int>> dist(n + 1, {-1, -1});
  dist[1] = {0, 0};
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int next : edges[cur]) {
      if (dist[next].first == -1) {
        dist[next].first = dist[cur].first + 1;
        dist[next].second = cur;
        q.push(next);
      }
    }
  }
  if (dist[n].first > 0 && dist[n].first <= 4) {
    cout << dist[n].first << endl;
    int cur = n;
    vector<int> ans;
    while (cur != 0) {
      ans.push_back(cur);
      cur = dist[cur].second;
    }
    for (int i = ans.size() - 1; i >= 0; i -= 1) cout << ans[i] << " ";
    cout << endl;
    return true;
  } else {
    for (int i = 1; i <= n; i += 1) {
      if (dist[i].first == 2) {
        cout << 4 << endl;
        cout << 1 << " " << dist[i].second << " " << i << " 1 " << n << endl;
        return true;
      }
    }
  }
  return false;
}
void dfs(int root, vector<bool> &flag, vector<pair<int, int>> &mm) {
  flag[root] = false;
  pair<int, int> cur{root, edges[root].size()};
  for (int next : edges[root]) {
    if (next == 1) cur.second -= 1;
    if (flag[next]) dfs(next, flag, mm);
  }
  mm.push_back(cur);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i += 1) {
    int u, v;
    cin >> u >> v;
    edges[u].push_back(v);
    edges[v].push_back(u);
    record[u].insert(v);
    record[v].insert(u);
  }
  if (bfs()) return 0;
  vector<bool> flag(n + 1, true);
  flag[1] = false;
  for (int cur : edges[1]) {
    if (!flag[cur]) continue;
    vector<pair<int, int>> mm;
    dfs(cur, flag, mm);
    for (int i = 0; i < mm.size(); i += 1) {
      if (mm[i].second + 1 < mm.size()) {
        int x = mm[i].first;
        for (int y : edges[x]) {
          if (y == 1) continue;
          for (int z : edges[y]) {
            if (z != 1 && z != x && record[z].count(x) == 0) {
              cout << 5 << endl;
              cout << "1 " << x << " " << y << " " << z << " " << x << " " << n
                   << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << -1 << endl;
}

```


### Prompt

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

We have a string S consisting of lowercase English letters.

If the length of S is at most K, print S without change.

If the length of S exceeds K, extract the first K characters in S, append `...` to the end of them, and print the result.

Constraints

* K is an integer between 1 and 100 (inclusive).
* S is a string consisting of lowercase English letters.
* The length of S is between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

K
S

Output

Print a string as stated in Problem Statement.

Examples

Input

7
nikoandsolstice

Output

nikoand...

Input

40
ferelibenterhominesidquodvoluntcredunt

Output

ferelibenterhominesidquodvoluntcredunt

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;
int main()
{
   unsigned int x;
   string s;
  cin>>x;
  cin>>s;
  if (s.size()<=x)cout<<s;
  else cout<<s.substr(0, x)<<"...";
}

```


### Prompt

Please create a solution in cpp to the following problem:

Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.

To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:

* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.

Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.

Constraints

* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.

Input

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

N
s

Output

Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.

Examples

Input

3
0

Output

5

Input

300
1100100

Output

519054663

Input

5000
01000001011101000100001101101111011001000110010101110010000

Output

500886057

### Response

```cpp
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef double db;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
const int N=5e3+5,mo=1e9+7,rt=3;
ll f[N][N],i,j,n,m;
char s[N];
int main()
{
	scanf("%lld %s",&n,s+1);
	m=strlen(s+1);
	f[0][0]=1;
	fo(i,0,n-1)
		fo(j,0,i)
		{
			(f[i+1][j+1]+=f[i][j])%=mo;
			if (j)
				(f[i+1][j-1]+=f[i][j]*2)%=mo;
			else (f[i+1][j]+=f[i][j])%=mo;
		}
	printf("%lld\n",f[n][m]);
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!

You are given n nonnegative integers a_1, a_2, ..., a_n arranged in a circle, where n must be odd (ie. n-1 is divisible by 2). Formally, for all i such that 2 ≤ i ≤ n, the elements a_{i - 1} and a_i are considered to be adjacent, and a_n and a_1 are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.

Help Danny find the maximum possible circular value after some sequences of operations.

Input

The first line contains one odd integer n (1 ≤ n < 2 ⋅ 10^5, n is odd) — the initial size of the circle.

The second line contains n integers a_{1},a_{2},...,a_{n} (0 ≤ a_{i} ≤ 10^9) — the initial numbers in the circle.

Output

Output the maximum possible circular value after applying some sequence of operations to the given circle.

Examples

Input

3
7 10 2

Output

17

Input

1
4

Output

4

Note

For the first test case, here's how a circular value of 17 is obtained:

Pick the number at index 3. The sum of adjacent elements equals 17. Delete 7 and 10 from the circle and replace 2 with 17.

Note that the answer may not fit in a 32-bit integer.

### Response

```cpp
#include <bits/stdc++.h>
long long int oddsum[100020], evensum[100020];
int main() {
  memset(oddsum, 0, sizeof(oddsum));
  memset(evensum, 0, sizeof(evensum));
  int n, i;
  long long int x, ans = 0, sum;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &x);
    if (i & 1)
      oddsum[(i >> 1) + 1] = oddsum[i >> 1] + x;
    else
      evensum[(i >> 1) + 1] = evensum[i >> 1] + x;
  }
  for (i = 0; i < n; i++) {
    if (i & 1)
      sum =
          oddsum[(i >> 1) + 1] + evensum[(n >> 1) + 1] - evensum[(i >> 1) + 1];
    else
      sum = evensum[(i >> 1) + 1] + oddsum[n >> 1] - oddsum[i >> 1];
    if (ans < sum) ans = sum;
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

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

You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.

Output

Print a single line containing n digits — the desired state of the display containing the smallest possible number.

Examples

Input

3
579

Output

024

Input

4
2014

Output

0142

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
string s, t, ans;
int main() {
  int n;
  scanf("%d", &n);
  cin >> s;
  ans = s;
  for (int i = 0; i < n; i++) {
    t = s.substr(i, n) + s.substr(0, i);
    int x = 10 - (t[0] - '0');
    for (int j = 0; j < n; j++) {
      int nx = (t[j] - '0' + x) % 10;
      t[j] = nx + '0';
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
}

```


### Prompt

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

The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space.

In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 15 as shown below.

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

You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps).

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

Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle.

Constraints

* The given puzzle is solvable in at most 45 steps.

Input

The $4 \times 4$ integers denoting the pieces or space are given.

Output

Print the fewest steps in a line.

Example

Input

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

Output

8

### Response

```cpp
#include <iostream>
#define rep(i, n) for(int i=0;i<n;i++)
#define N 16
#define SQRTN 4
#define LIMIT 100
using namespace std;

int limit;
int searchV[4][2] = {{0, 1},{1, 0},{0, -1},{-1, 0}};

struct Board{
  int b[N], h;
  int calcHeust(void){
    h = 0;
    for(int i = 0; i < SQRTN; i++){
      for(int j = 0; j < SQRTN; j++){
        if(b[i*SQRTN + j] == N-1) continue;
        h += abs(b[i*SQRTN + j]/SQRTN-i) + abs(b[i*SQRTN + j]%SQRTN-j);
      }
    }
    return h;
  }
};

void printBoard(Board b){
    rep(i, SQRTN){
     rep(j, SQRTN){
       cout << b.b[i*SQRTN + j];
     }
     cout << endl;
    }
}

Board currentState;

bool dfs(int depth, int prev, int cbX, int cbY){
  currentState.calcHeust();
  if ( currentState.h == 0) return true;
  if ( depth + currentState.h > limit ) return false;

  for (int d = 0 ; d < 4 ; d++ ){
    int sx = cbX + searchV[d][0];
    int sy = cbY + searchV[d][1];
    if ( abs(d - prev) == 2 ) continue;
    if ( sx < 0 || sy < 0 || sx >= SQRTN || sy >= SQRTN) continue;

    swap(currentState.b[cbY*SQRTN + cbX], currentState.b[sy*SQRTN + sx]);
    if (dfs(depth+1, d, sx, sy)) return true;
    swap(currentState.b[cbY*SQRTN + cbX], currentState.b[sy*SQRTN + sx]);
  }

  return false;
}

int idastar(Board in, int px, int py){
  for (limit=0;limit < LIMIT;limit++){
    currentState = in;
    if (dfs(0, 100, px, py)) return limit;
  }
  return -1;
}

int main(void){
  Board init;
  int p0x, p0y;
  rep(i, N){
    cin >> init.b[i];
    if (init.b[i]==0){
      init.b[i] = N;
      p0y = i/SQRTN;
      p0x = i%SQRTN;
    }
    init.b[i]--;
  }
  cout << idastar(init, p0x, p0y) << endl;;
}

```


### Prompt

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

We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, ..., N. Here, the following conditions should be satisfied:

* For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W.
* For each i (1 ≤ i ≤ N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.

Constraints

* 1 ≤ H, W ≤ 100
* 1 ≤ N ≤ H W
* a_i ≥ 1
* a_1 + a_2 + ... + a_N = H W

Input

Input is given from Standard Input in the following format:

H W
N
a_1 a_2 ... a_N

Output

Print one way to paint the squares that satisfies the conditions. Output in the following format:

c_{1 1} ... c_{1 W}
:
c_{H 1} ... c_{H W}

Here, c_{i j} is the color of the square at the i-th row from the top and j-th column from the left.

Examples

Input

2 2
3
2 1 1

Output

1 1
2 3

Input

3 5
5
1 2 3 4 5

Output

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

Input

1 1
1
1

Output

1

### Response

```cpp
#include<iostream>
#include<vector>
using namespace std;
int N,H,W;
int val;
int V[10005];
int C[105][105];
int ind=1;
int main()
{
    cin>>H>>W>>N;for(int i=1;i<=N;i++)cin>>V[i];
    for(int i=1;i<=H;i++)
    {
        for(int j=(i%2 ? 1:W);j&&j<=W;j+=(i%2 ? 1:-1))
        {
            C[i][j]=ind;
            V[ind]--;
            while(!V[ind])ind++;
        }
    }
    for(int i=1;i<=H;i++,cout<<"\n")for(int j=1;j<=W;j++)cout<<C[i][j]<<" ";
    return 0;
}
```


### Prompt

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

Arkady coordinates rounds on some not really famous competitive programming platform. Each round features n problems of distinct difficulty, the difficulties are numbered from 1 to n.

To hold a round Arkady needs n new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the problems himself, but unfortunately, he can't just create a problem of a desired difficulty. Instead, when he creates a problem, he evaluates its difficulty from 1 to n and puts it into the problems pool.

At each moment when Arkady can choose a set of n new problems of distinct difficulties from the pool, he holds a round with these problems and removes them from the pool. Arkady always creates one problem at a time, so if he can hold a round after creating a problem, he immediately does it.

You are given a sequence of problems' difficulties in the order Arkady created them. For each problem, determine whether Arkady held the round right after creating this problem, or not. Initially the problems pool is empty.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of difficulty levels and the number of problems Arkady created.

The second line contains m integers a_1, a_2, …, a_m (1 ≤ a_i ≤ n) — the problems' difficulties in the order Arkady created them.

Output

Print a line containing m digits. The i-th digit should be 1 if Arkady held the round after creation of the i-th problem, and 0 otherwise.

Examples

Input

3 11
2 3 1 2 2 2 3 2 2 3 1

Output

00100000001

Input

4 8
4 1 3 3 2 3 3 3

Output

00001000

Note

In the first example Arkady held the round after the first three problems, because they are of distinct difficulties, and then only after the last problem.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int m, n, num, cnt[100500];
int main() {
  cin >> m >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (cnt[a] == 0) num++;
    cnt[a]++;
    if (num == m) {
      cout << 1;
      for (int j = 1; j <= m; j++) {
        cnt[j]--;
        if (cnt[j] == 0) num--;
      }
    } else
      cout << 0;
  }
  return 0;
}

```


### Prompt

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

You have a set of n discs, the i-th disc has radius i. Initially, these discs are split among m towers: each tower contains at least one disc, and the discs in each tower are sorted in descending order of their radii from bottom to top.

You would like to assemble one tower containing all of those discs. To do so, you may choose two different towers i and j (each containing at least one disc), take several (possibly all) top discs from the tower i and put them on top of the tower j in the same order, as long as the top disc of tower j is bigger than each of the discs you move. You may perform this operation any number of times.

For example, if you have two towers containing discs [6, 4, 2, 1] and [8, 7, 5, 3] (in order from bottom to top), there are only two possible operations:

  * move disc 1 from the first tower to the second tower, so the towers are [6, 4, 2] and [8, 7, 5, 3, 1];
  * move discs [2, 1] from the first tower to the second tower, so the towers are [6, 4] and [8, 7, 5, 3, 2, 1].

Let the difficulty of some set of towers be the minimum number of operations required to assemble one tower containing all of the discs. For example, the difficulty of the set of towers [[3, 1], [2]] is 2: you may move the disc 1 to the second tower, and then move both discs from the second tower to the first tower.

You are given m - 1 queries. Each query is denoted by two numbers a_i and b_i, and means "merge the towers a_i and b_i" (that is, take all discs from these two towers and assemble a new tower containing all of them in descending order of their radii from top to bottom). The resulting tower gets index a_i.

For each k ∈ [0, m - 1], calculate the difficulty of the set of towers after the first k queries are performed.

Input

The first line of the input contains two integers n and m (2 ≤ m ≤ n ≤ 2 ⋅ 10^5) — the number of discs and the number of towers, respectively.

The second line contains n integers t_1, t_2, ..., t_n (1 ≤ t_i ≤ m), where t_i is the index of the tower disc i belongs to. Each value from 1 to m appears in this sequence at least once.

Then m - 1 lines follow, denoting the queries. Each query is represented by two integers a_i and b_i (1 ≤ a_i, b_i ≤ m, a_i ≠ b_i), meaning that, during the i-th query, the towers with indices a_i and b_i are merged (a_i and b_i are chosen in such a way that these towers exist before the i-th query).

Output

Print m integers. The k-th integer (0-indexed) should be equal to the difficulty of the set of towers after the first k queries are performed.

Example

Input

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

Output

5
4
2
0

Note

The towers in the example are:

  * before the queries: [[5, 1], [2], [7, 4, 3], [6]];
  * after the first query: [[2], [7, 5, 4, 3, 1], [6]];
  * after the second query: [[7, 5, 4, 3, 2, 1], [6]];
  * after the third query, there is only one tower: [7, 6, 5, 4, 3, 2, 1].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a, b, aa, bb, n, m, xx, group[N], la, ans;
int fa[N];
vector<int> s[N];
int find(int x) {
  if (x == fa[x]) return x;
  fa[x] = find(fa[x]);
  return fa[x];
}
inline int read() {
  int sum = 0, naga = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') naga = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
  return sum * naga;
}
int main() {
  n = read(), m = read();
  ans = n - 1;
  for (int i = 1; i <= n; i++) {
    xx = read();
    if (xx == la) ans--;
    s[xx].push_back(i);
    group[i] = xx;
    fa[i] = i;
    la = xx;
  }
  cout << ans << endl;
  for (int i = 1; i < m; i++) {
    aa = read(), bb = read();
    a = find(aa), b = find(bb);
    if (s[a].size() > s[b].size()) swap(a, b);
    for (int j = 0; j < s[a].size(); j++) {
      if (find(group[s[a][j] - 1]) == b) ans--;
      if (find(group[s[a][j] + 1]) == b) ans--;
      s[b].push_back(s[a][j]);
    }
    fa[a] = b;
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.

The New Year tree is an undirected tree with n vertices and root in the vertex 1.

You should process the queries of the two types:

  1. Change the colours of all vertices in the subtree of the vertex v to the colour c.
  2. Find the number of different colours in the subtree of the vertex v.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 4·105) — the number of vertices in the tree and the number of the queries.

The second line contains n integers ci (1 ≤ ci ≤ 60) — the colour of the i-th vertex.

Each of the next n - 1 lines contains two integers xj, yj (1 ≤ xj, yj ≤ n) — the vertices of the j-th edge. It is guaranteed that you are given correct undirected tree.

The last m lines contains the description of the queries. Each description starts with the integer tk (1 ≤ tk ≤ 2) — the type of the k-th query. For the queries of the first type then follows two integers vk, ck (1 ≤ vk ≤ n, 1 ≤ ck ≤ 60) — the number of the vertex whose subtree will be recoloured with the colour ck. For the queries of the second type then follows integer vk (1 ≤ vk ≤ n) — the number of the vertex for which subtree you should find the number of different colours.

Output

For each query of the second type print the integer a — the number of different colours in the subtree of the vertex given in the query.

Each of the numbers should be printed on a separate line in order of query appearing in the input.

Examples

Input

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

Output

2
3
4
5
1
2

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
int n, m, dfs_clock;
vector<int> G[MAXN];
int node[MAXN], tim[MAXN][2];
void dfs(int cur, int fa) {
  tim[cur][0] = ++dfs_clock;
  for (int i = 0; i < G[cur].size(); i++) {
    int u = G[cur][i];
    if (u == fa) continue;
    dfs(u, cur);
  }
  tim[cur][1] = dfs_clock;
}
long long col[MAXN << 2], setv[MAXN << 2];
int cal_col(long long col) {
  int cnt = 0;
  for (int i = 0; i < 63; i++) {
    if ((1LL << i) & col) cnt++;
  }
  return cnt;
}
void pushdown(int o) {
  if (setv[o] > 0) {
    setv[o << 1] = setv[(o << 1) | 1] = setv[o];
    setv[o] = 0;
  }
}
void maintain(int o, int L, int R) {
  col[o] = 0;
  if (R > L) col[o] = col[o << 1] | col[(o << 1) | 1];
  if (setv[o] > 0) col[o] = setv[o];
}
void update(int o, int L, int R, int ql, int qr, int c) {
  if (ql <= L && qr >= R)
    setv[o] = 1LL << c;
  else {
    pushdown(o);
    int M = (L + R) >> 1;
    if (ql <= M)
      update(o << 1, L, M, ql, qr, c);
    else
      maintain(o << 1, L, M);
    if (qr > M)
      update((o << 1) | 1, M + 1, R, ql, qr, c);
    else
      maintain((o << 1) | 1, M + 1, R);
  }
  maintain(o, L, R);
}
long long query(int o, int L, int R, int ql, int qr) {
  if (setv[o] > 0)
    return setv[o];
  else if (ql <= L && qr >= R)
    return col[o];
  int M = (L + R) >> 1;
  long long ans = 0;
  if (ql <= M) ans |= query(o << 1, L, M, ql, qr);
  if (qr > M) ans |= query((o << 1) | 1, M + 1, R, ql, qr);
  return ans;
}
int main() {
  dfs_clock = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &node[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1);
  for (int i = 1; i <= n; i++) {
    update(1, 1, n, tim[i][0], tim[i][0], node[i]);
  }
  for (int i = 1; i <= m; i++) {
    int op, u, v;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &u, &v);
      update(1, 1, n, tim[u][0], tim[u][1], v);
    } else {
      scanf("%d", &u);
      long long ans = query(1, 1, n, tim[u][0], tim[u][1]);
      printf("%d\n", cal_col(ans));
    }
  }
  return 0;
}

```