### Prompt

Generate a cpp solution to the following problem:

For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree.

Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to search his whole tree to determine this; Jacob knows that she will examine the first k nodes in a DFS-order traversal of the tree. She will then assign Jacob a grade equal to the minimum ai she finds among those k nodes.

Though Jacob does not have enough time to rebuild his model, he can choose the root node that his teacher starts from. Furthermore, he can rearrange the list of neighbors of each node in any order he likes. Help Jacob find the best grade he can get on this assignment.

A DFS-order traversal is an ordering of the nodes of a rooted tree, built by a recursive DFS-procedure initially called on the root of the tree. When called on a given node v, the procedure does the following:

  1. Print v.
  2. Traverse the list of neighbors of the node v in order and iteratively call DFS-procedure on each one. Do not call DFS-procedure on node u if you came to node v directly from u.

Input

The first line of the input contains two positive integers, n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ n) — the number of balls in Jacob's tree and the number of balls the teacher will inspect.

The second line contains n integers, ai (1 ≤ ai ≤ 1 000 000), the time Jacob used to build the i-th ball.

Each of the next n - 1 lines contains two integers ui, vi (1 ≤ ui, vi ≤ n, ui ≠ vi) representing a connection in Jacob's tree between balls ui and vi.

Output

Print a single integer — the maximum grade Jacob can get by picking the right root of the tree and rearranging the list of neighbors.

Examples

Input

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

Output

3

Input

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

Output

1

Note

In the first sample, Jacob can root the tree at node 2 and order 2's neighbors in the order 4, 1, 5 (all other nodes have at most two neighbors). The resulting preorder traversal is 2, 4, 1, 3, 5, and the minimum ai of the first 3 nodes is 3.

In the second sample, it is clear that any preorder traversal will contain node 1 as either its first or second node, so Jacob cannot do better than a grade of 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
vector<int> val, adj[N];
int sz[N], big[N], p[N], mm[N], mn[N], ok[N], a[N], ans[N], mx[N], found, n, k,
    lim;
void get(int u, int sum, int root) {
  if (a[u] < lim) return;
  if (2 + sum + mx[root] >= k) found = 1;
  for (int v : adj[u]) get(v, sum + 1 + ans[u] - ok[v] * (ans[v] + 1), root);
}
void add(int u, int sum, int root) {
  if (a[u] < lim) return;
  mx[root] = max(mx[root], sum + 1);
  for (int v : adj[u]) add(v, sum + ans[u] - ok[v] * (ans[v] + 1), root);
}
void dsu(int u) {
  if (found) return;
  for (int v : adj[u]) {
    if (v == big[u]) continue;
    dsu(v);
    if (ans[v] == sz[v] - 1 && a[v] >= lim)
      ok[v] = 1, ans[u] += ans[v] + 1;
    else
      ok[v] = 0;
  }
  if (big[u]) {
    dsu(big[u]);
    if (ans[big[u]] == sz[big[u]] - 1 && a[big[u]] >= lim)
      ok[big[u]] = 1, ans[u] += ans[big[u]] + 1;
    else
      ok[big[u]] = 0;
  }
  if (a[u] >= lim) {
    mx[u] = mx[big[u]] - ok[big[u]] * (ans[big[u]] + 1);
    if (mn[u] >= lim) ans[u] += (n - sz[u]);
    if (ans[u] + 1 >= k || 1 + ans[u] + mx[u] >= k) found = 1;
    for (int v : adj[u]) {
      if (v == big[u] || a[v] < lim) continue;
      if (mx[u] + ans[u] - ok[v] * (ans[v] + 1) + 1 + mx[v] >= k) found = 1;
      mx[u] = max(mx[u], mx[v] - ok[v] * (ans[v] + 1));
    }
    if (mn[u] >= lim) ans[u] -= (n - sz[u]);
    mx[u] += (ans[u] + 1);
  } else
    ans[u] = mx[u] = 0;
  if (mx[u] >= k) found = 1;
}
bool check() {
  found = 0;
  fill_n(ans, n + 1, 0);
  fill_n(mx, n + 1, 0);
  dsu(1);
  return found;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  if (fopen("test"
            ".inp",
            "r")) {
    freopen(
        "test"
        ".inp",
        "r", stdin);
    freopen(
        "test"
        ".out",
        "w", stdout);
  }
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i], val.emplace_back(a[i]);
  sort(val.begin(), val.end());
  val.erase(unique(val.begin(), val.end()), val.end());
  if (k == 1) return cout << val.back(), 0;
  for (int u, v, i = 1; i < n; ++i) {
    cin >> u >> v;
    adj[u].emplace_back(v), adj[v].emplace_back(u);
  }
  function<void(int, int)> dfs = [&](int u, int par) {
    sz[u] = 1, big[u] = 0, p[u] = par;
    mm[u] = a[u];
    for (int& v : adj[u]) {
      if (v == par) swap(v, adj[u].back());
      if (v == par) continue;
      dfs(v, u);
      sz[u] += sz[v];
      mm[u] = min(mm[u], mm[v]);
      if (sz[big[u]] < sz[v]) big[u] = v;
    }
    if (par != -1) adj[u].pop_back();
  };
  mn[1] = 1e9;
  function<void(int)> minimize = [&](int u) {
    int tmp = min(a[u], mn[u]);
    for (int v : adj[u]) {
      mn[v] = tmp;
      tmp = min(tmp, mm[v]);
    }
    reverse(adj[u].begin(), adj[u].end());
    tmp = min(a[u], mn[u]);
    for (int v : adj[u]) {
      mn[v] = min(mn[v], tmp);
      tmp = min(tmp, mm[v]);
      minimize(v);
    }
  };
  dfs(1, -1), minimize(1);
  int low = 0, mid, high = val.size() - 1;
  while (low <= high) {
    mid = low + high >> 1;
    lim = val[mid];
    if (check())
      low = mid + 1;
    else
      high = mid - 1;
  }
  cout << val[high];
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Shrimpy Duc is a fat and greedy boy who is always hungry. After a while of searching for food to satisfy his never-ending hunger, Shrimpy Duc finds M&M candies lying unguarded on a L × L grid. There are n M&M candies on the grid, the i-th M&M is currently located at (x_i + 0.5, y_i + 0.5), and has color c_i out of a total of k colors (the size of M&Ms are insignificant).

Shrimpy Duc wants to steal a rectangle of M&Ms, specifically, he wants to select a rectangle with integer coordinates within the grid and steal all candies within the rectangle. Shrimpy Duc doesn't need to steal every single candy, however, he would like to steal at least one candy for each color.

In other words, he wants to select a rectangle whose sides are parallel to the coordinate axes and whose left-bottom vertex (X_1, Y_1) and right-top vertex (X_2, Y_2) are points with integer coordinates satisfying 0 ≤ X_1 < X_2 ≤ L and 0 ≤ Y_1 < Y_2 ≤ L, so that for every color 1 ≤ c ≤ k there is at least one M&M with color c that lies within that rectangle.

How many such rectangles are there? This number may be large, so you only need to find it modulo 10^9 + 7.

Input

The first line contains three positive integers n, k, L (1 ≤ k ≤ n ≤ 2 ⋅ 10^3, 1 ≤ L ≤ 10^9 ) — the number of M&Ms, the number of colors and the length of the grid respectively.

The following n points describe the M&Ms. Each line contains three integers x_i, y_i, c_i (0 ≤ x_i, y_i < L, 1 ≤ c_i ≤ k) — the coordinates and color of the i-th M&M respectively.

Different M&Ms have different coordinates (x_i ≠ x_j or y_i ≠ y_j for every i ≠ j), and for every 1 ≤ c ≤ k there is at least one M&M with color c.

Output

Output a single integer — the number of rectangles satisfying Shrimpy Duc's conditions, modulo 10^9 + 7.

Examples

Input

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

Output

20

Input

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

Output

300

Input

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

Output

226

Note

Grid for the first sample:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 5;
const int MAXD = 2e3 + 5;
const int mod = 1e9 + 7;
inline void add_mod(int &a, int b) {
  if ((a += b) >= mod) a -= mod;
}
struct Solver {
  set<pair<int, int> > t;
  int res;
  Solver(void) : res(0) {}
  inline int chose2(int l, int r) {
    return l > r ? 0 : ((long long)(r - l + 1) * (r - l + 1 + 1) / 2) % mod;
  }
  inline void update(set<pair<int, int> >::iterator it, int k) {
    set<pair<int, int> >::iterator pre = it, nxt = it;
    ++nxt;
    if (it != t.begin())
      --pre, res = (res - (long long)k * chose2(it->first, -pre->second)) % mod;
    if (nxt != t.end())
      res = (res - (long long)k * chose2(nxt->first, -it->second)) % mod;
    if (it != t.begin() && nxt != t.end())
      res = (res + (long long)k * chose2(nxt->first, -pre->second)) % mod;
    res = (res + (long long)k * chose2(it->first, -it->second)) % mod;
    if (res < 0) res += mod;
  }
  inline int query(void) { return res; }
  inline void erase(set<pair<int, int> >::iterator it) {
    update(it, -1);
    t.erase(it);
  }
  inline void insert(int l, int r) {
    if (l > r) return;
    pair<int, int> cur = make_pair(l, -r);
    set<pair<int, int> >::iterator it = t.lower_bound(cur);
    while (it != t.end() && -it->second <= r)
      erase(it), it = t.lower_bound(cur);
    if (it != t.begin() && -((--it)->second) >= r) return;
    update(t.insert(cur).first, 1);
  }
};
struct Node {
  int x, y, clr;
} p[MAXN];
inline bool cmp_x(const Node &p, const Node &q) { return p.x < q.x; }
int main(void) {
  int n, d, L;
  scanf("%d%d%d", &n, &d, &L);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].clr), ++p[i].x, ++p[i].y;
  sort(p + 1, p + n + 1, cmp_x);
  p[n + 1].x = L + 1;
  long long tot = ((long long)L * (L + 1) / 2) % mod;
  long long ans = 0;
  for (int k = 1; k <= n; ++k)
    if (p[k].x != p[k + 1].x) {
      static multiset<int> t[MAXD];
      for (int i = 1; i <= d; ++i)
        t[i].clear(), t[i].insert(0), t[i].insert(L + 1);
      for (int i = 1; i <= k; ++i) t[p[i].clr].insert(p[i].y);
      Solver solver;
      bool flag = 1;
      for (int i = 1; i <= d; ++i) {
        if ((int)t[i].size() <= 2) {
          flag = 0;
          break;
        }
        multiset<int>::iterator it = t[i].begin();
        while (*it <= L) {
          int l = *it + 1;
          ++it;
          solver.insert(l, *it - 1);
        }
      }
      if (!flag) continue;
      for (int i = 1; i <= k; ++i) {
        if (p[i].x != p[i - 1].x) {
          long long res = (tot + mod - solver.query()) % mod;
          if (!res) break;
          ans = (ans +
                 res * (p[k + 1].x - p[k].x) % mod * (p[i].x - p[i - 1].x)) %
                mod;
        }
        multiset<int> &tt = t[p[i].clr];
        multiset<int>::iterator it = tt.lower_bound(p[i].y), pre = it, nxt = it;
        --pre;
        ++nxt;
        tt.erase(it);
        solver.insert(*pre + 1, *nxt - 1);
      }
    }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Old MacDonald has a farm and a large potato field, (1010 + 1) × (1010 + 1) square meters in size. The field is divided into square garden beds, each bed takes up one square meter.

Old McDonald knows that the Colorado potato beetle is about to invade his farm and can destroy the entire harvest. To fight the insects, Old McDonald wants to spray some beds with insecticides.

So Old McDonald went to the field, stood at the center of the central field bed and sprayed this bed with insecticides. Now he's going to make a series of movements and spray a few more beds. During each movement Old McDonald moves left, right, up or down the field some integer number of meters. As Old McDonald moves, he sprays all the beds he steps on. In other words, the beds that have any intersection at all with Old McDonald's trajectory, are sprayed with insecticides.

When Old McDonald finished spraying, he wrote out all his movements on a piece of paper. Now he wants to know how many beds won't be infected after the invasion of the Colorado beetles.

It is known that the invasion of the Colorado beetles goes as follows. First some bed on the field border gets infected. Than any bed that hasn't been infected, hasn't been sprayed with insecticides and has a common side with an infected bed, gets infected as well. Help Old McDonald and determine the number of beds that won't be infected by the Colorado potato beetle.

Input

The first line contains an integer n (1 ≤ n ≤ 1000) — the number of Old McDonald's movements.

Next n lines contain the description of Old McDonald's movements. The i-th of these lines describes the i-th movement. Each movement is given in the format "di xi", where di is the character that determines the direction of the movement ("L", "R", "U" or "D" for directions "left", "right", "up" and "down", correspondingly), and xi (1 ≤ xi ≤ 106) is an integer that determines the number of meters in the movement.

Output

Print a single integer — the number of beds that won't be infected by the Colorado potato beetle.

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
R 8
U 9
L 9
D 8
L 2

Output

101

Input

7
R 10
D 2
L 7
U 9
D 2
R 3
D 10

Output

52

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void read(int &digit) {
  digit = 0;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  bool type = false;
  if (c == '-') type = true, c = getchar();
  for (; c >= '0' && c <= '9'; digit = digit * 10 + c - '0', c = getchar())
    ;
  if (type == true) digit = -digit;
}
int n;
int bo[4010][4010];
int numx[4010], cx;
int numy[4010], cy;
int posx[4010];
int posy[4010];
int lx[4010], rx[4010];
int ly[4010], ry[4010];
int cnt_x;
int cnt_y;
int x[4010], y[4010], tot;
queue<pair<int, int> > Q;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int main() {
  read(n);
  int _x = 0, _y = 0;
  cx = 1, cy = 1;
  tot = 1;
  for (int i = 1; i <= n; i++) {
    char ch = getchar();
    int op;
    while (ch != 'L' && ch != 'R' && ch != 'U' && ch != 'D') ch = getchar();
    read(op);
    if (ch == 'L') {
      _x -= op;
      numx[++cx] = _x;
    } else if (ch == 'R') {
      _x += op;
      numx[++cx] = _x;
    } else if (ch == 'U') {
      _y += op;
      numy[++cy] = _y;
    } else if (ch == 'D') {
      _y -= op;
      numy[++cy] = _y;
    }
    tot++;
    x[tot] = _x, y[tot] = _y;
  }
  sort(numx + 1, numx + cx + 1);
  cx = unique(numx + 1, numx + cx + 1) - (numx + 1);
  sort(numy + 1, numy + cy + 1);
  cy = unique(numy + 1, numy + cy + 1) - (numy + 1);
  cnt_x = 2;
  lx[1] = rx[1] = numx[1] - 1;
  lx[2] = rx[2] = numx[1];
  posx[1] = 2;
  for (int i = 2; i <= cx; i++) {
    if (numx[i] != numx[i - 1] + 1) {
      cnt_x++;
      lx[cnt_x] = numx[i - 1] + 1;
      rx[cnt_x] = numx[i] - 1;
    }
    cnt_x++;
    lx[cnt_x] = numx[i];
    rx[cnt_x] = numx[i];
    posx[i] = cnt_x;
  }
  cnt_x++;
  lx[cnt_x] = rx[cnt_x] = numx[cx] + 1;
  cnt_y = 2;
  ly[1] = ry[1] = numy[1] - 1;
  ly[2] = ry[2] = numy[1];
  posy[1] = 2;
  for (int i = 2; i <= cy; i++) {
    if (numy[i] != numy[i - 1] + 1) {
      cnt_y++;
      ly[cnt_y] = numy[i - 1] + 1;
      ry[cnt_y] = numy[i] - 1;
    }
    cnt_y++;
    ly[cnt_y] = numy[i];
    ry[cnt_y] = numy[i];
    posy[i] = cnt_y;
  }
  cnt_y++;
  ly[cnt_y] = ry[cnt_y] = numy[cy] + 1;
  for (int i = 1; i <= tot; i++) {
    int _x = lower_bound(numx + 1, numx + cx + 1, x[i]) - numx;
    int _y = lower_bound(numy + 1, numy + cy + 1, y[i]) - numy;
    x[i] = posx[_x], y[i] = posy[_y];
  }
  bo[x[1]][y[1]] = 1;
  for (int i = 2; i <= tot; i++) {
    if (x[i] == x[i - 1]) {
      int _y = y[i], _y2 = y[i - 1];
      if (_y > _y2) swap(_y, _y2);
      for (int j = _y; j <= _y2; j++) bo[x[i]][j] = 1;
    } else {
      int _x = x[i], _x2 = x[i - 1];
      if (_x > _x2) swap(_x, _x2);
      for (int j = _x; j <= _x2; j++) bo[j][y[i]] = 1;
    }
  }
  bo[1][1] = -1;
  Q.push(make_pair(1, 1));
  while (!Q.empty()) {
    int x = Q.front().first, y = Q.front().second;
    Q.pop();
    for (int i = 0; i < 4; i++) {
      _x = x + dx[i];
      _y = y + dy[i];
      if (_x <= cnt_x && _x >= 1 && _y <= cnt_y && _y >= 1)
        if (bo[_x][_y] == 0) {
          bo[_x][_y] = -1;
          Q.push(make_pair(_x, _y));
        }
    }
  }
  long long mjy = 0;
  for (int i = 1; i <= cnt_x; i++)
    for (int j = 1; j <= cnt_y; j++)
      if (bo[i][j] != -1)
        mjy += 1LL * (rx[i] - lx[i] + 1) * (ry[j] - ly[j] + 1);
  printf("%I64d\n", mjy);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.

For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.

You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.

Input

The first line contains an integer n — the number of cards with digits that you have (1 ≤ n ≤ 100).

The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, …, s_n. The string will not contain any other characters, such as leading or trailing spaces.

Output

If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.

Examples

Input

11
00000000008

Output

1

Input

22
0011223344556677889988

Output

2

Input

11
31415926535

Output

0

Note

In the first example, one phone number, "8000000000", can be made from these cards.

In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".

In the third example you can't make any phone number from the given cards.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '8') count++;
  }
  if (n < 11)
    cout << "0" << endl;
  else {
    cout << min(count, n / 11) << endl;
  }
  return 0;
}

```


### Prompt

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

Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.

Constraints

* 0 < a, b ≤ 2,000,000,000
* LCM(a, b) ≤ 2,000,000,000
* The number of data sets ≤ 50

Input

Input consists of several data sets. Each data set contains a and b separated by a single space in a line. The input terminates with EOF.

Output

For each data set, print GCD and LCM separated by a single space in a line.

Example

Input

8 6
50000000 30000000

Output

2 24
10000000 150000000

### Response

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

int gcd(int a, int b) {
return a % b ? gcd(b, a % b) : b;
}
int lcm(int a, int b) {
return a / gcd(a,b) * b;
}

int main() {
int a, b;
while(cin >> a >> b) {
cout << gcd(a,b) << " " << lcm(a,b) << endl;
}
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all n roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other?

Input

The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 100) — road is directed from city ai to city bi, redirecting the traffic costs ci.

Output

Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.

Examples

Input

3
1 3 1
1 2 1
3 2 1

Output

1

Input

3
1 3 1
1 2 5
3 2 1

Output

2

Input

6
1 5 4
5 3 8
2 4 15
1 6 16
2 3 23
4 6 42

Output

39

Input

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

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d\n", &n);
  set<int> in, x;
  long totalCost(0), cost(0);
  while (n--) {
    int a, b, c;
    scanf("%d %d %d\n", &a, &b, &c);
    totalCost += c;
    if (in.count(a) || x.count(b)) {
      cost += c;
      x.insert(a);
      in.insert(b);
    } else {
      in.insert(a);
      x.insert(b);
    }
  }
  if (totalCost - cost < cost) {
    cost = totalCost - cost;
  }
  printf("%ld\n", cost);
  return 0;
}

```


### Prompt

Please create a solution in Cpp 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 <iostream>
#include <map>
using namespace std;

int N, Q;

int main() {
  while (cin >> N >> Q) {
    if (N == 0) break;
    map<int,int> ma;
    for (int i = 0; i < N; ++i) {
      int M; cin >> M;
      for (int j = 0; j < M; ++j) {
	int a; cin >> a;
	ma[a]++;
      }
    }
    int Max = -1, pMax = -1;
    for (map<int,int>::iterator it = ma.begin(); it != ma.end(); ++it) {
      if (it->second > Max && it->second >= Q) {
	Max = it->second;
	pMax = it->first;
      }
    }
    cout << (pMax != -1 ? pMax : 0)  << endl;
  }
}

```


### Prompt

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

There is a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects Vertex U_i and V_i. Also, Vertex i has two predetermined integers A_i and B_i. You will play the following game on this graph.

First, choose one vertex and stand on it, with W yen (the currency of Japan) in your pocket. Here, A_s \leq W must hold, where s is the vertex you choose. Then, perform the following two kinds of operations any number of times in any order:

* Choose one vertex v that is directly connected by an edge to the vertex you are standing on, and move to vertex v. Here, you need to have at least A_v yen in your pocket when you perform this move.
* Donate B_v yen to the vertex v you are standing on. Here, the amount of money in your pocket must not become less than 0 yen.

You win the game when you donate once to every vertex. Find the smallest initial amount of money W that enables you to win the game.

Constraints

* 1 \leq N \leq 10^5
* N-1 \leq M \leq 10^5
* 1 \leq A_i,B_i \leq 10^9
* 1 \leq U_i < V_i \leq N
* The given graph is connected and simple (there is at most one edge between any pair of vertices).

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
:
A_N B_N
U_1 V_1
U_2 V_2
:
U_M V_M

Output

Print the smallest initial amount of money W that enables you to win the game.

Examples

Input

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

Output

6

Input

5 8
6 4
15 13
15 19
15 1
20 7
1 3
1 4
1 5
2 3
2 4
2 5
3 5
4 5

Output

44

Input

9 10
131 2
98 79
242 32
231 38
382 82
224 22
140 88
209 70
164 64
6 8
1 6
1 4
1 3
4 7
4 9
3 7
3 9
5 9
2 5

Output

582

### Response

```cpp
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=100007;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
vector<int> G[N];
int n,m,a[N],b[N],fa[N],rk[N],vis[N];
LL f[N],sum[N],ans;
bool cmp(int x,int y)
{
	return a[x]<a[y];
}
int getfa(int x)
{
	return fa[x]==x ? x : fa[x]=getfa(fa[x]);
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++){
		a[i]=read(),b[i]=read();
		a[i]=max(a[i]-b[i],0);
	}
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		G[u].push_back(v);G[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		rk[i]=fa[i]=i; f[i]=a[i]; sum[i]=b[i];
	}
	sort(rk+1,rk+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		int u=rk[i]; vis[u]=1;
		for(int j=0;j<G[u].size();j++)
		{
			int v=G[u][j];
			if(!vis[v]) continue;
			int x=getfa(u),y=getfa(v);
			if(x!=y){
				fa[y]=x; sum[x]+=sum[y];
//				f[x]=min(f[x],f[y]+max(f[y],a[x]-sum[y]));
				f[x]=min(f[x],max(f[y],a[x]-sum[y]));
			}
		}
	}
	int rt=getfa(1);
	printf("%lld\n",f[rt]+sum[rt]);
	return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Alice wants to send an important message to Bob. Message a = (a1, ..., an) is a sequence of positive integers (characters).

To compress the message Alice wants to use binary Huffman coding. We recall that binary Huffman code, or binary prefix code is a function f, that maps each letter that appears in the string to some binary string (that is, string consisting of characters '0' and '1' only) such that for each pair of different characters ai and aj string f(ai) is not a prefix of f(aj) (and vice versa). The result of the encoding of the message a1, a2, ..., an is the concatenation of the encoding of each character, that is the string f(a1)f(a2)... f(an). Huffman codes are very useful, as the compressed message can be easily and uniquely decompressed, if the function f is given. Code is usually chosen in order to minimize the total length of the compressed message, i.e. the length of the string f(a1)f(a2)... f(an).

Because of security issues Alice doesn't want to send the whole message. Instead, she picks some substrings of the message and wants to send them separately. For each of the given substrings ali... ari she wants to know the minimum possible length of the Huffman coding. Help her solve this problem.

Input

The first line of the input contains the single integer n (1 ≤ n ≤ 100 000) — the length of the initial message. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000) — characters of the message.

Next line contains the single integer q (1 ≤ q ≤ 100 000) — the number of queries.

Then follow q lines with queries descriptions. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the position of the left and right ends of the i-th substring respectively. Positions are numbered from 1. Substrings may overlap in any way. The same substring may appear in the input more than once.

Output

Print q lines. Each line should contain a single integer — the minimum possible length of the Huffman encoding of the substring ali... ari.

Example

Input

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

Output

10
3
3
5
0

Note

In the first query, one of the optimal ways to encode the substring is to map 1 to "0", 2 to "10" and 3 to "11".

Note that it is correct to map the letter to the empty substring (as in the fifth query from the sample).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
}
void et() {
  puts("-1");
  exit(0);
}
int SZ;
struct mb {
  int l, r, id;
  void rd(int i) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    id = i;
  }
  bool operator<(const mb &o) const {
    if (l / SZ == o.l / SZ) {
      return (l / SZ) & 1 ? r > o.r : r < o.r;
    }
    return l / SZ < o.l / SZ;
  }
} q[100005];
int a[100005], cnt[100005], fre[100005], tfre[100005];
long long ans[100005];
vector<int> big;
void add(int val, int c) {
  fre[cnt[val]]--;
  cnt[val] += c;
  fre[cnt[val]]++;
}
void fmain() {
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(n); (i)++) scanf("%d", a + i);
  SZ = sqrt(n) * max(1, (int)log(n));
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    cnt[a[i]]++;
    if (cnt[a[i]] == SZ) big.push_back(a[i]);
  }
  memset(cnt, 0, sizeof cnt);
  scanf("%d", &m);
  for (int(i) = 1; (i) <= (int)(m); (i)++) q[i].rd(i);
  sort(q, q + m);
  int L = q[1].l, R = q[1].l - 1;
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    while (R < q[i].r) add(a[++R], 1);
    while (L > q[i].l) add(a[--L], 1);
    while (R > q[i].r) add(a[R--], -1);
    while (L < q[i].l) add(a[L++], -1);
    long long tmp = 0;
    priority_queue<int, std::vector<int>, std::greater<int>> qu;
    for (int b : big)
      if (cnt[b] >= SZ) qu.push(cnt[b]);
    int pre = -1;
    for (int(j) = 0; (j) < (int)(SZ); (j)++) tfre[j] = fre[j];
    for (int j = 1; j < SZ; j++)
      if (tfre[j] > 0) {
        if (pre != -1) {
          tmp += pre + j;
          tfre[j]--;
          if (pre + j < SZ)
            tfre[pre + j]++;
          else
            qu.push(pre + j);
          pre = -1;
        }
        if (tfre[j] & 1) {
          tfre[j]--;
          pre = j;
        }
        tmp += tfre[j] * j;
        if (j + j < SZ) {
          tfre[j + j] += tfre[j] / 2;
        } else {
          for (int(z) = 0; (z) < (int)(tfre[j] / 2); (z)++) qu.push(j + j);
        }
      }
    if (pre != -1) qu.push(pre);
    while (qu.size() > 1) {
      int x = qu.top();
      qu.pop();
      x += qu.top();
      qu.pop();
      tmp += x;
      qu.push(x);
    }
    ans[q[i].id] = tmp;
  }
  for (int(i) = 1; (i) <= (int)(m); (i)++) printf("%lld\n", ans[i]);
}
int main() {
  fmain();
  return 0;
}

```


### Prompt

In CPP, your task is to solve 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 several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?

Constraints

* 1 ≦ |s| ≦ 10 (|s| denotes the length of s)
* s consists of the letters `0`, `1` and `B`.
* The correct answer is not an empty string.

Input

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

s

Output

Print the string displayed in the editor in the end.

Examples

Input

01B0

Output

00

Input

0BB1

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	string b("");
	int i;
	cin>>a;
	for(i=0;i<a.size();i++){
		if(a[i]=='B'){
			if(b!=""){
			    b.erase(b.size()-1);
			}
		}else{
			b=b+a[i];
		}
	}
	cout<<b<<endl;
	return 0;
}

```


### Prompt

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

A class of students wrote a multiple-choice test.

There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question i worth a_i points. Incorrect answers are graded with zero points.

The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 1000) — the number of students in the class and the number of questions in the test.

Each of the next n lines contains string s_i (|s_i| = m), describing an answer of the i-th student. The j-th character represents the student answer (A, B, C, D or E) on the j-th question.

The last line contains m integers a_1, a_2, …, a_m (1 ≤ a_i ≤ 1000) — the number of points for the correct answer for every question.

Output

Print a single integer — the maximum possible total score of the class.

Examples

Input

2 4
ABCD
ABCE
1 2 3 4

Output

16

Input

3 3
ABC
BCD
CDE
5 4 12

Output

21

Note

In the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be 16.

In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is 5 + 4 + 12 = 21.

### Response

```cpp
#include <bits/stdc++.h>
char s[1001][1001];
int main() {
  int n, q, i, num[1001], sum = 0, k, j, max;
  scanf("%d%d", &n, &q);
  for (i = 0; i < n; i++) {
    scanf("%s", &s[i]);
  }
  for (i = 0; i < q; i++) {
    scanf("%d", &num[i]);
  }
  for (j = 0; j < q; j++) {
    int a[10] = {0};
    for (i = 0; i < n; i++) {
      if (s[i][j] == 'A') {
        a[1]++;
      } else if (s[i][j] == 'B') {
        a[2]++;
      } else if (s[i][j] == 'C') {
        a[3]++;
      } else if (s[i][j] == 'D') {
        a[4]++;
      } else if (s[i][j] == 'E') {
        a[5]++;
      }
    }
    for (k = 1, max = 0; k <= 5; k++) {
      if (a[k] > max) {
        max = a[k];
      }
    }
    sum += max * num[j];
  }
  printf("%d", sum);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a letter, either 'A', or the letter 'B'. Then they began to remove the cards one by one from left to right, every time they removed a card with the letter 'A', Alice gave Bob all the fruits she had at that moment and took out of the bag as many apples and as many oranges as she had before. Thus the number of oranges and apples Alice had, did not change. If the card had written letter 'B', then Bob did the same, that is, he gave Alice all the fruit that he had, and took from the bag the same set of fruit. After the last card way removed, all the fruit in the bag were over.

You know how many oranges and apples was in the bag at first. Your task is to find any sequence of cards that Alice and Bob could have played with.

Input

The first line of the input contains two integers, x, y (1 ≤ x, y ≤ 1018, xy > 1) — the number of oranges and apples that were initially in the bag.

Output

Print any sequence of cards that would meet the problem conditions as a compressed string of characters 'A' and 'B. That means that you need to replace the segments of identical consecutive characters by the number of repetitions of the characters and the actual character. For example, string AAABAABBB should be replaced by string 3A1B2A3B, but cannot be replaced by 2A1A1B2A3B or by 3AB2A3B. See the samples for clarifications of the output format. The string that you print should consist of at most 106 characters. It is guaranteed that if the answer exists, its compressed representation exists, consisting of at most 106 characters. If there are several possible answers, you are allowed to print any of them.

If the sequence of cards that meet the problem statement does not not exist, print a single word Impossible.

Examples

Input

1 4

Output

3B

Input

2 2

Output

Impossible

Input

3 2

Output

1A1B

Note

In the first sample, if the row contained three cards with letter 'B', then Bob should give one apple to Alice three times. So, in the end of the game Alice has one orange and three apples, and Bob has one apple, in total it is one orange and four apples.

In second sample, there is no answer since one card is not enough for game to finish, and two cards will produce at least three apples or three oranges.

In the third sample, cards contain letters 'AB', so after removing the first card Bob has one orange and one apple, and after removal of second card Alice has two oranges and one apple. So, in total it is three oranges and two apples.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int mod = 1000000007;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
long long x, y;
void solve() {
  scanf("%I64d%I64d", &x, &y);
  if (gcd(x, y) != 1) {
    printf("Impossible");
    return;
  }
  bool flag = 1;
  while (y != 0) {
    long long d = x / y;
    x %= y;
    swap(x, y);
    if (y == 0) d--;
    if (d > 0) printf("%I64d%c", d, flag ? 'A' : 'B');
    flag ^= 1;
  }
}
int main() {
  solve();
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a seconds to swipe from photo to adjacent.

For each photo it is known which orientation is intended for it — horizontal or vertical. Phone is in the vertical orientation and can't be rotated. It takes b second to change orientation of the photo.

Vasya has T seconds to watch photos. He want to watch as many photos as possible. If Vasya opens the photo for the first time, he spends 1 second to notice all details in it. If photo is in the wrong orientation, he spends b seconds on rotating it before watching it. If Vasya has already opened the photo, he just skips it (so he doesn't spend any time for watching it or for changing its orientation). It is not allowed to skip unseen photos.

Help Vasya find the maximum number of photos he is able to watch during T seconds.

Input

The first line of the input contains 4 integers n, a, b, T (1 ≤ n ≤ 5·105, 1 ≤ a, b ≤ 1000, 1 ≤ T ≤ 109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.

Second line of the input contains a string of length n containing symbols 'w' and 'h'.

If the i-th position of a string contains 'w', then the photo i should be seen in the horizontal orientation.

If the i-th position of a string contains 'h', then the photo i should be seen in vertical orientation.

Output

Output the only integer, the maximum number of photos Vasya is able to watch during those T seconds.

Examples

Input

4 2 3 10
wwhw

Output

2

Input

5 2 4 13
hhwhh

Output

4

Input

5 2 4 1000
hhwhh

Output

5

Input

3 1 100 10
whw

Output

0

Note

In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.

Note that in the last sample test the time is not enough even to watch the first photo, also you can't skip it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, a, b, T;
long long s[N];
char c[N];
bool check(int x) {
  for (int i = 1; i <= x; i++) {
    long long s1 = s[i] + s[n] - s[n + i - x];
    long long s2 = min(a * (i + x - 2), a * (2 * x - i - 1));
    if (s1 + s2 <= T) return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d%d%d", &n, &a, &b, &T);
  scanf("%s", c + 1);
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + 1;
    if (c[i] == 'w') s[i] += b;
  }
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d", l);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm.

........#
........#
........#
........#

Constraints

* 3 ≤ H ≤ 300
* 3 ≤ W ≤ 300

Input

The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.

The input ends with two 0 (when both H and W are zero).

Output

For each dataset, print the frame made of '#' and '.'.

Print a blank line after each dataset.

Example

Input

3 4
5 6
3 3
0 0

Output

####
#..#
####

######
#....#
#....#
#....#
######

###
#.#
###

### Response

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

using namespace std;

int main(){
	while(true){
		int h,w;
		cin >> h >> w;
		if(h==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(i==0 || i==h-1 || j==0 || j==w-1)cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Constraints

* 1 \leq N \leq 100
* S consists of lowercase English letters.
* |S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

If S is a concatenation of two copies of some string, print `Yes`; otherwise, print `No`.

Examples

Input

6
abcabc

Output

Yes

Input

6
abcadc

Output

No

Input

1
z

Output

No

### Response

```cpp
#include<cstdio>
int n;
char S[1010];
int main(){
	scanf("%d",&n);
	scanf("%s",S+1);
	if(n%2==1)return puts("No"),0;
	for(int i=1;i<=n/2;i++)
		if(S[i]!=S[i+n/2])return puts("No"),0;
	puts("Yes");
}
```


### Prompt

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

It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.

Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.

Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.

Each door has 4 parts. The first part is an integer number a. The second part is either an integer number b or some really odd sign which looks like R. The third one is an integer c and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.

c is an integer written in base a, to open the door we should write it in base b. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!

Here's an explanation of this really weird number system that even doesn't have zero:

Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:

  * I=1
  * V=5
  * X=10
  * L=50
  * C=100
  * D=500
  * M=1000

Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1, 000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.

Also in bases greater than 10 we use A for 10, B for 11, etc.

Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.

Input

The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system.

The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103.

It is guaranteed that if we have Roman numerals included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.

Output

Write a single line that contains integer c in base b. You must omit leading zeros.

Examples

Input

10 2
1

Output

1

Input

16 R
5

Output

V

Input

5 R
4

Output

IV

Input

2 2
1111001

Output

1111001

Input

12 13
A

Output

A

Note

You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char f(long long x) {
  string s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  return s[x];
}
long long of(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  } else {
    return c - 'A' + 10;
  }
}
int main() {
  ios::sync_with_stdio(false);
  long long a;
  string s;
  cin >> a >> s;
  string x;
  cin >> x;
  if (s == "R") {
    vector<long long> st(x.length());
    st[0] = 1;
    for (long long i = 1; i < x.length(); i++) {
      st[i] = st[i - 1] * a;
    }
    long long y = 0;
    for (long long i = 0; i < x.length(); i++) {
      y += of(x[i]) * st[x.length() - i - 1];
    }
    vector<char> res;
    long long t = y / 1000;
    y %= 1000;
    for (long long i = 0; i < t; i++) {
      res.push_back('M');
    }
    t = y / 100;
    y %= 100;
    if (t < 4) {
      for (long long i = 0; i < t; i++) {
        res.push_back('C');
      }
    } else if (t == 4) {
      res.push_back('C');
      res.push_back('D');
    } else if (t == 5) {
      res.push_back('D');
    } else if (t < 9) {
      res.push_back('D');
      t -= 5;
      for (long long i = 0; i < t; i++) {
        res.push_back('C');
      }
    } else {
      res.push_back('C');
      res.push_back('M');
    }
    t = y / 10;
    y %= 10;
    if (t < 4) {
      for (long long i = 0; i < t; i++) {
        res.push_back('X');
      }
    } else if (t == 4) {
      res.push_back('X');
      res.push_back('L');
    } else if (t == 5) {
      res.push_back('L');
    } else if (t < 9) {
      res.push_back('L');
      t -= 5;
      for (long long i = 0; i < t; i++) {
        res.push_back('X');
      }
    } else {
      res.push_back('X');
      res.push_back('C');
    }
    t = y;
    if (t < 4) {
      for (long long i = 0; i < t; i++) {
        res.push_back('I');
      }
    } else if (t == 4) {
      res.push_back('I');
      res.push_back('V');
    } else if (t == 5) {
      res.push_back('V');
    } else if (t < 9) {
      res.push_back('V');
      t -= 5;
      for (long long i = 0; i < t; i++) {
        res.push_back('I');
      }
    } else {
      res.push_back('I');
      res.push_back('X');
    }
    for (long long i = 0; i < res.size(); i++) {
      cout << res[i];
    }
  } else {
    long long b = 0;
    for (long long i = 0; i < s.length(); i++) {
      b *= 10;
      b += s[i] - '0';
    }
    vector<long long> st(x.length());
    st[0] = 1;
    for (long long i = 1; i < x.length(); i++) {
      st[i] = st[i - 1] * a;
    }
    long long y = 0;
    for (long long i = 0; i < x.length(); i++) {
      y += of(x[i]) * st[x.length() - i - 1];
    }
    vector<long long> res;
    while (y) {
      res.push_back(y % b);
      y /= b;
    }
    reverse(res.begin(), res.end());
    if (res.size() == 0) {
      cout << 0;
      return 0;
    }
    for (long long i = 0; i < res.size(); i++) {
      cout << f(res[i]);
    }
  }
  return 0;
}

```


### Prompt

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

You are given a directed graph with N vertices and M edges. The vertices are numbered 1, 2, ..., N, and the edges are numbered 1, 2, ..., M. Edge i points from Vertex a_i to Vertex b_i.

For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph.

Here, the reversion of Edge i means deleting Edge i and then adding a new edge that points from Vertex b_i to Vertex a_i.

Constraints

* 2 \leq N \leq 1000
* 1 \leq M \leq 200,000
* 1 \leq a_i, b_i \leq N
* a_i \neq b_i
* If i \neq j, then a_i \neq a_j or b_i \neq b_j.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print M lines. In the i-th line, if the reversion of Edge i would change the number of the strongly connected components in the graph, print `diff`; if it would not, print `same`.

Examples

Input

3 3
1 2
1 3
2 3

Output

same
diff
same

Input

2 2
1 2
2 1

Output

diff
diff

Input

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

Output

same
same
same
same
same
diff
diff
diff
diff

### Response

```cpp
#include <cstdio>
#include <algorithm>
#include <vector>

const int MN = 1005, MM = 200005;

int N, M, eu[MM], ev[MM], Ans[MM];
std::vector<int> G[MN];
bool vis[MN], rch[MN][MN]; int col[MN];
void DFS(int u, int c) {
	vis[u] = 1, col[u] ^= c;
	for (auto i : G[u]) if (!vis[ev[i]]) DFS(ev[i], c);
}

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= M; ++i) {
		scanf("%d%d", &eu[i], &ev[i]);
		G[eu[i]].push_back(i);
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) vis[j] = 0;
		DFS(i, 0);
		for (int j = 1; j <= N; ++j) if (vis[j]) rch[i][j] = 1;
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) col[j] = vis[j] = 0; vis[i] = 1;
		for (auto j : G[i]) if (!vis[ev[j]]) DFS(ev[j], ev[j]);
		std::reverse(G[i].begin(), G[i].end());
		for (int j = 1; j <= N; ++j) vis[j] = 0; vis[i] = 1;
		for (auto j : G[i]) if (!vis[ev[j]]) DFS(ev[j], ev[j]);
		for (auto j : G[i]) Ans[j] = rch[ev[j]][i] ^ !!col[ev[j]];
	}
	for (int i = 1; i <= M; ++i) puts(Ans[i] ? "diff" : "same");
	return 0;
}
```


### Prompt

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

E: Binary Sequence-Binary Sequence-

story

I love binaries Bonald.Brvin.Bnuth! He is known as Uncle Bnuth, who is studying the nature of binary sequences at Offtunford University! By the way, if my name "Bonald.Brvin.Bnuth" is binarized from ASCII code, it will be "1000010 1101111 1101110 1100001 1101100 1100100 101110 1000010 1110010 1110110 1101001 1101110 101110 1000010 1101110 1110101 1110100 1101000"! It's fun!

I'm looking forward to it from the morning because my disciples are going to do some interesting experiments today! What are you doing?

What! I want to discover some properties by continuing to rewrite binary strings! HM! This is the scent of an important discovery! Let's start the experiment! Let's summarize more detailed settings as sentences!

problem

Given a binary sequence of length n x = (x_1, ..., x_n) (x_i \ in \\ {0,1 \\}, i = 1, ..., n). For the binary string x, we define two functions f (x) and g (x) as follows.

f (x) = Σ_ {i = 1} ^ {n} x_i = x_1 + x_2 + ... + x_n
g (x) = Σ_ {i = 1} ^ {n-1} x_i x_ {i + 1} = x_1 x_2 + x_2 x_3 + ... x_ {n-1} x_n

Now, perform the following change operation on the binary string x q times. The jth change operation is given by l_j, r_j, b_j (1 \ leq l_j \ leq r_j \ leq n, b_j \ in \\ {0,1 \\}, j = 1, ..., q). This corresponds to the operation of replacing the l_jth to r_jths of the binary string x with b_j. Find f (x) --g (x) after each change operation.

Input format

n
x
q
l_1 r_1 b_1
...
l_q r_q b_q

The first line is given the integer n that represents the length of the binary column. The second line is given a string that represents the binary column x. The third line is given the integer q, which represents the number of queries. In the following q lines, the i-th line is given information about the i-th query l_i, r_i, b_i in this order, separated by blanks.

Constraint

* 2 \ leq n \ leq 100000
* x is a character string consisting of ‘0’ and ‘1’
* | x | = n
* 1 \ leq q \ leq 100000
* 1 \ leq l_j \ leq r_j \ leq n, b_j \ in \\ {0,1 \\}, j = 1, ..., q

Output format

For each i = 1, ..., q, output the value of f (x) --g (x) after processing the i-th query on the i-line.

Input example 1

Ten
0101100110
3
3 3 1
1 6 0
2 5 1

Output example 1

2
1
2

Input example 2

8
00111100
3
8 8 1
4 5 0
7 8 1

Output example 2

2
3
2

Example

Input

10
0101100110
3
3 3 1
1 6 0
2 5 1

Output

2
1
2

### Response

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct node{
    int pc,g,l,r;
    node(int a,int b,int c,int d):pc(a),g(b),l(c),r(d){}
    node(){pc=g=l=r=-1;}
};
node e;
inline node add(const node &a,const node &b){
    if(a.pc==-1)return b;
    if(b.pc==-1)return a;
    node c;
    c.pc=a.pc+b.pc;
    c.g=a.g+b.g+a.r*b.l;
    c.l=a.l;
    c.r=b.r;
    return c;
}

struct segtree{
    static const int SEG=1<<17;
    vector<node>dat;
    vector<int>put;
    segtree(string &s):dat(SEG*2),put(SEG*2,-1){
        for(int i=0;i<s.size();i++){
            node d;
            int a=s[i]-'0';
            d.pc=a;
            d.g=0;
            d.l=d.r=a;
            dat[i+SEG-1]=d;
        }
        for(int i=SEG-2;i>=0;i--){
            dat[i]=add(dat[i*2+1],dat[i*2+2]);
        }
    }
    inline void push(int k,int l,int r){
        if(put[k]==-1)return;
        dat[k].pc=(r-l)*put[k];
        dat[k].g=(r-l-1)*put[k];
        dat[k].l=dat[k].r=put[k];

        if(k<SEG-1){
            put[k*2+1]=put[k*2+2]=put[k];
        }
        put[k]=-1;
    }
    void update(int a,int b,int x,int k=0,int l=0,int r=SEG){
        push(k,l,r);
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            put[k]=x;
            push(k,l,r);
            return;
        }
        update(a,b,x,k*2+1,l,(l+r)/2);
        update(a,b,x,k*2+2,(l+r)/2,r);
        dat[k]=add(dat[k*2+1],dat[k*2+2]);
    }
    node query(int a,int b,int k=0,int l=0,int r=SEG){
        push(k,l,r);
        if(r<=a||b<=l)return e;
        if(a<=l&&r<=b)return dat[k];
        return add(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int N;
    string S;
    cin>>N>>S;
    segtree seg(S);

     int Q;cin>>Q;
     while(Q--){
        int l,r,b;
        cin>>l>>r>>b;
        l--;
        seg.update(l,r,b);
        node d=seg.query(0,N);
        cout<<d.pc-d.g<<endl;
     }
    return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals.

A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: axis X is positive and axis Y is negative.

Experienced laboratory worker marked n points with integer coordinates (xi, yi) on the plane and stopped the time. Sasha should use "atomic tweezers" to place elementary particles in these points. He has an unlimited number of electrons (negatively charged elementary particles) and protons (positively charged elementary particles). He can put either an electron or a proton at each marked point. As soon as all marked points are filled with particles, laboratory worker will turn on the time again and the particles will come in motion and after some time they will stabilize in equilibrium. The objective of the laboratory work is to arrange the particles in such a way, that the diameter of the resulting state (the maximum distance between the pairs of points of the set) is as small as possible.

Since Sasha is a programmer, he naively thinks that all the particles will simply "fall" into their projections on the corresponding axes: electrons will fall on axis X, while protons will fall on axis Y. As we are programmers too, we will consider the same model as Sasha. That is, a particle gets from point (x, y) to point (x, 0) if it is an electron and to point (0, y) if it is a proton.

As the laboratory has high background radiation and Sasha takes care of his laptop, he did not take it with him, and now he can't write a program that computes the minimum possible diameter of the resulting set. Therefore, you will have to do it for him.

Print a square of the minimum possible diameter of the set.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of points marked on the plane.

Each of the next n lines contains two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — the coordinates of the i-th point. It is guaranteed that no two points coincide.

Output

Print a single integer — the square of the minimum possible diameter of the set.

Examples

Input

3
1 10
1 20
1 30

Output

0

Input

2
1 10
10 1

Output

2

Note

In the first sample Sasha puts electrons at all points, all particles eventually fall at a single point (1, 0).

In the second sample Sasha puts an electron at point (1, 10), and a proton at point (10, 1). The result is a set of two points (1, 0) and (0, 1), which has a diameter of <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 200000000;
struct punct {
  int x, y;
  bool operator<(const punct &aux) const { return x < aux.x; }
} v[100010];
int vmax[100010], vmin[100010], n;
long long solve() {
  long long st = 0, dr = 1LL * inf * inf;
  while (st <= dr) {
    long long mid = (st + dr) / 2;
    int maxx = -inf, minn = inf, ok = 0;
    for (int i = 1, j = 1; j <= n; j++) {
      while (1LL * (v[j].x - v[i].x) * (v[j].x - v[i].x) > mid) {
        maxx = max(maxx, v[i].y);
        minn = min(minn, v[i].y);
        i++;
      }
      int a = max(maxx, vmax[j + 1]), b = min(minn, vmin[j + 1]);
      if (a < b) {
        ok = 1;
        break;
      }
      if (1LL * (a - b) * (a - b) > mid) continue;
      if (1LL * a * a + 1LL * v[i].x * v[i].x > mid) continue;
      if (1LL * a * a + 1LL * v[j].x * v[j].x > mid) continue;
      if (1LL * b * b + 1LL * v[i].x * v[i].x > mid) continue;
      if (1LL * b * b + 1LL * v[j].x * v[j].x > mid) continue;
      ok = 1;
      break;
    }
    if (ok)
      dr = mid - 1;
    else
      st = mid + 1;
  }
  return st;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &v[i].x, &v[i].y);
  sort(v + 1, v + 1 + n);
  vmax[n + 1] = -inf;
  vmin[n + 1] = inf;
  for (int i = n; i; i--) {
    vmax[i] = max(vmax[i + 1], v[i].y);
    vmin[i] = min(vmin[i + 1], v[i].y);
  }
  long long sol = min(1LL * (v[n].x - v[1].x) * (v[n].x - v[1].x),
                      1LL * (vmax[1] - vmin[1]) * (vmax[1] - vmin[1]));
  sol = min(sol, solve());
  for (int i = 1; i <= n; i++) swap(v[i].x, v[i].y);
  sort(v + 1, v + 1 + n);
  vmax[n + 1] = -inf;
  vmin[n + 1] = inf;
  for (int i = n; i; i--) {
    vmax[i] = max(vmax[i + 1], v[i].y);
    vmin[i] = min(vmin[i + 1], v[i].y);
  }
  sol = min(sol, solve());
  printf("%I64d", sol);
  return 0;
}

```


### Prompt

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

Let's define a function f(x) (x is a positive integer) as follows: write all digits of the decimal representation of x backwards, then get rid of the leading zeroes. For example, f(321) = 123, f(120) = 21, f(1000000) = 1, f(111) = 111.

Let's define another function g(x) = (x)/(f(f(x))) (x is a positive integer as well).

Your task is the following: for the given positive integer n, calculate the number of different values of g(x) among all numbers x such that 1 ≤ x ≤ n.

Input

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

Each test case consists of one line containing one integer n (1 ≤ n < 10^{100}). This integer is given without leading zeroes.

Output

For each test case, print one integer — the number of different values of the function g(x), if x can be any integer from [1, n].

Example

Input

5
4
37
998244353
1000000007
12345678901337426966631415

Output

1
2
9
10
26

Note

Explanations for the two first test cases of the example:

  1. if n = 4, then for every integer x such that 1 ≤ x ≤ n, (x)/(f(f(x))) = 1;
  2. if n = 37, then for some integers x such that 1 ≤ x ≤ n, (x)/(f(f(x))) = 1 (for example, if x = 23, f(f(x)) = 23,(x)/(f(f(x))) = 1); and for other values of x, (x)/(f(f(x))) = 10 (for example, if x = 30, f(f(x)) = 3, (x)/(f(f(x))) = 10). So, there are two different values of g(x).

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll t;
    cin>>t;

    while(t--){
        string s;
        cin>>s;

        cout<<s.size()<<endl;
    }
}

```


### Prompt

Generate a Cpp solution to the following problem:

There are n students who have taken part in an olympiad. Now it's time to award the students.

Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.

You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.

Input

The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.

Output

Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.

It's possible that there are no winners.

Examples

Input

18 2

Output

3 6 9

Input

9 10

Output

0 0 9

Input

1000000000000 5

Output

83333333333 416666666665 500000000002

Input

1000000000000 499999999999

Output

1 499999999999 500000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k, h;
int main() {
  cin >> n >> k;
  if (k >= n / 2)
    cout << "0 0 " << n;
  else if (k == (n / 2 - 1))
    cout << 1 << " " << k << " " << n - (k + 1);
  else if (k < n / 2) {
    h = n / 2;
    if (h % (k + 1) != 0) {
      h -= h % (k + 1);
    }
    cout << h / (k + 1) << " " << k * (h / (k + 1)) << " " << n - h;
  }
}

```


### Prompt

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

For two permutations p and q of the integers from 1 through N, let f(p,q) be the permutation that satisfies the following:

* The p_i-th element (1 \leq i \leq N) in f(p,q) is q_i. Here, p_i and q_i respectively denote the i-th element in p and q.

You are given two permutations p and q of the integers from 1 through N. We will now define a sequence {a_n} of permutations of the integers from 1 through N, as follows:

* a_1=p, a_2=q
* a_{n+2}=f(a_n,a_{n+1}) ( n \geq 1 )

Given a positive integer K, find a_K.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq K \leq 10^9
* p and q are permutations of the integers from 1 through N.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N
q_1 ... q_N

Output

Print N integers, with spaces in between. The i-th integer (1 \leq i \leq N) should be the i-th element in a_K.

Examples

Input

3 3
1 2 3
3 2 1

Output

3 2 1

Input

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

Output

4 3 2 1 5

Input

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

Output

7 9 4 8 2 5 1 6 10 3

### Response

```cpp
#include <iostream>
#include <vector>

using namespace std;

vector<int> inv(const vector<int>& p){
    vector<int> res(p.size());
    for(int i=0;i<p.size();i++) res[p[i]] = i;
    return res;
}

vector<int> mul(const vector<int>& p, const vector<int>& q){
    vector<int> res(p.size());
    for(int i=0;i<p.size();i++) res[i] = p[q[i]];
    return res;
}

vector<int> pow(const vector<int>& p, int K){
    const int N = p.size();
    if(K == 0){
        vector<int> res(N);
        for(int i=0;i<N;i++) res[i] = i;
        return res;
    }
    auto res = pow(p, K/2);
    res = mul(res, res);
    if(K%2 == 1) res = mul(res, p);
    return res;
}

int main(){
    int N, K; cin >> N >> K;
    vector<int> p(N), q(N);
    for(auto& t : p){ cin >> t; --t; }
    for(auto& t : q){ cin >> t; --t; }
    auto pInv = inv(p);
    auto qInv = inv(q);
    auto r = mul(mul(mul(q, pInv), qInv), p);
    r = pow(r, (K-1)/6);
    auto rInv = inv(r);
    auto cur = mul(mul(r, p), rInv);
    auto next = mul(mul(r, q), rInv);
    int k = (K-1)/6*6+1;
    while(k < K){
        auto tmp = next;
        next = mul(next, inv(cur));
        cur = tmp;
        ++k;
    }
    for(auto& t : cur) cout << t+1 << " ";
    cout << endl;
}
```


### Prompt

Create a solution in CPP for the following problem:

Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging from the i-th node.

Before beginning the game, a special integer k is chosen. The game proceeds as follows:

  * Alice begins the game, with moves alternating each turn;
  * in any move, the current player may choose some node (for example, i) which has depth at least k. Then, the player picks some positive number of presents hanging from that node, let's call it m (1 ≤ m ≤ a_i);
  * the player then places these m presents on the k-th ancestor (let's call it j) of the i-th node (the k-th ancestor of vertex i is a vertex j such that i is a descendant of j, and the difference between the depth of j and the depth of i is exactly k). Now, the number of presents of the i-th node (a_i) is decreased by m, and, correspondingly, a_j is increased by m;
  * Alice and Bob both play optimally. The player unable to make a move loses the game.

For each possible root of the tree, find who among Alice or Bob wins the game.

Note: The depth of a node i in a tree with root r is defined as the number of edges on the simple path from node r to node i. The depth of root r itself is zero.

Input

The first line contains two space-separated integers n and k (3 ≤ n ≤ 10^5, 1 ≤ k ≤ 20).

The next n-1 lines each contain two integers x and y (1 ≤ x, y ≤ n, x ≠ y), denoting an undirected edge between the two nodes x and y. These edges form a tree of n nodes.

The next line contains n space-separated integers denoting the array a (0 ≤ a_i ≤ 10^9).

Output

Output n integers, where the i-th integer is 1 if Alice wins the game when the tree is rooted at node i, or 0 otherwise.

Example

Input

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

Output

1 0 0 1 1

Note

Let us calculate the answer for sample input with root node as 1 and as 2.

Root node 1

Alice always wins in this case. One possible gameplay between Alice and Bob is:

  * Alice moves one present from node 4 to node 3.
  * Bob moves four presents from node 5 to node 2.
  * Alice moves four presents from node 2 to node 1.
  * Bob moves three presents from node 2 to node 1.
  * Alice moves three presents from node 3 to node 1.
  * Bob moves three presents from node 4 to node 3.
  * Alice moves three presents from node 3 to node 1.

Bob is now unable to make a move and hence loses.

Root node 2

Bob always wins in this case. One such gameplay is:

  * Alice moves four presents from node 4 to node 3.
  * Bob moves four presents from node 5 to node 2.
  * Alice moves six presents from node 3 to node 1.
  * Bob moves six presents from node 1 to node 2.

Alice is now unable to make a move and hence loses.

### Response

```cpp
using namespace std;

#include <iostream>
#include <vector>

#define MAXN 100005
#define MAXK 45

int N,K,K2,dp[MAXN][MAXK],parent[MAXN];
vector<int> edges[MAXN];

void dfs(int v) {
	for(int u : edges[v]) {
		if(u == parent[v]) continue;
		parent[u] = v;
		dfs(u);
		for(int i = 0;i < K2;++i) {
			dp[v][(i + 1) % K2] ^= dp[u][i];
		}
	}
	return;
}

void dfs2(int v) {
	for(int u : edges[v]) {
		if(u == parent[v]) continue;
		int tmp[MAXK];
		for(int i = 0;i < K2;++i) {
			tmp[i] = dp[u][i];
		}
		for(int i = 0;i < K2;++i) {
			dp[u][(i + 2) % K2] ^= tmp[i] ^ dp[v][(i + 1) % K2];
		}
		dfs2(u);
	}
	return;
}

int main() {
	cin >> N >> K;
	K2 = 2 * K;
	for(int i = 0;i < N - 1;++i) {
		int a,b;
		cin >> a >> b;
		a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	for(int i = 0;i < N;++i) {
		cin >> dp[i][0];
	}
	dfs(0);
	dfs2(0);
	for(int i = 0;i < N;++i) {
		int cur = 0;
		for(int j = K;j < K2;++j) {
			cur ^= dp[i][j];
		}
		cout << !!cur << " ";
	}
	cout << endl;
	return 0;
}
```


### Prompt

Generate a CPP solution to the following problem:

In computer science, there is a method called "Divide And Conquer By Node" to solve some hard problems about paths on a tree. Let's desribe how this method works by function:

solve(t) (t is a tree):

  1. Chose a node x (it's common to chose weight-center) in tree t. Let's call this step "Line A".
  2. Deal with all paths that pass x.
  3. Then delete x from tree t.
  4. After that t becomes some subtrees.
  5. Apply solve on each subtree.

This ends when t has only one node because after deleting it, there's nothing.

Now, WJMZBMR has mistakenly believed that it's ok to chose any node in "Line A". So he'll chose a node at random. To make the situation worse, he thinks a "tree" should have the same number of edges and nodes! So this procedure becomes like that.

Let's define the variable totalCost. Initially the value of totalCost equal to 0. So, solve(t) (now t is a graph):

  1. totalCost = totalCost + (size of t). The operation "=" means assignment. (Size of t) means the number of nodes in t.
  2. Choose a node x in graph t at random (uniformly among all nodes of t).
  3. Then delete x from graph t.
  4. After that t becomes some connected components.
  5. Apply solve on each component.

He'll apply solve on a connected graph with n nodes and n edges. He thinks it will work quickly, but it's very slow. So he wants to know the expectation of totalCost of this procedure. Can you help him?

Input

The first line contains an integer n (3 ≤ n ≤ 3000) — the number of nodes and edges in the graph. Each of the next n lines contains two space-separated integers ai, bi (0 ≤ ai, bi ≤ n - 1) indicating an edge between nodes ai and bi.

Consider that the graph nodes are numbered from 0 to (n - 1). It's guaranteed that there are no self-loops, no multiple edges in that graph. It's guaranteed that the graph is connected.

Output

Print a single real number — the expectation of totalCost. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Examples

Input

5
3 4
2 3
2 4
0 4
1 2

Output

13.166666666666666

Input

3
0 1
1 2
0 2

Output

6.000000000000000

Input

5
0 1
1 2
2 0
3 0
4 1

Output

13.166666666666666

Note

Consider the second example. No matter what we choose first, the totalCost will always be 3 + 2 + 1 = 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int vis[3010];
vector<int> ne[3010];
int n, siz;
int du[3010];
queue<int> q;
double ans;
void dfs(int u, int siza, int sizb, int top) {
  if (du[u] == 2)
    sizb++;
  else
    siza++;
  vis[u] = top;
  if (sizb == siz)
    ans += 1.0 / (siza + 2);
  else if (sizb <= 2)
    ans += 1.0 / (siza + sizb);
  else
    ans += 1.0 / (siza + sizb) + 1.0 / (siza + siz - sizb + 2) -
           1.0 / (siza + siz);
  for (int v : ne[u])
    if (vis[v] != top) dfs(v, siza, sizb, top);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x++, y++;
    ne[x].push_back(y);
    ne[y].push_back(x);
    du[x]++, du[y]++;
  }
  for (int i = 1; i <= n; i++)
    if (du[i] == 1) q.push(i);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int v : ne[u])
      if ((--du[v]) == 1) q.push(v);
  }
  for (int i = 1; i <= n; i++)
    if (du[i] == 2) siz++;
  for (int i = 1; i <= n; i++) dfs(i, 0, 0, i);
  printf("%.10f\n", ans);
}

```


### Prompt

Generate a cpp solution to the following problem:

In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.

In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.

The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

Input

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.

The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Output

Print a single number — the sought number of days.

Examples

Input

4
10 3 5 10

Output

5

Input

5
10 2 8 3 5

Output

5

Note

In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.

In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void in(long long int *a, long long int n) {
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
}
void out(long long int *a, long long int n) {
  for (long long int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
unsigned long long int expmod(long long int a, long long int n,
                              long long int M) {
  if (n == 0) return 1;
  if (n == 1) return a;
  unsigned long long int temp = expmod(a, n / 2, M);
  if (n % 2 == 0)
    return ((temp) * (temp)) % M;
  else
    return (a * (temp) * (temp)) % M;
}
int main() {
  fast();
  int tc = 1;
  while (tc--) {
    long long int n;
    cin >> n;
    long long int a[n];
    in(a, n);
    long long int d = a[0];
    for (long long int i = 0; i < n - 2;) {
      if (a[i + 1] < a[i + 2]) {
        d = min(a[i + 2], d);
        i++;
        i++;
      } else {
        d = min(a[i + 1], d);
        i++;
      }
    }
    cout << min(a[0], min(a[n - 1], d)) << "\n";
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

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

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

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

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

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

Constraints

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

Input

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

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

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

Examples

Input

3 2
1 2
2 3

Output

3

Input

2 2
1 1
1 2

Output

4

Input

4 3
1 2
1 3
4 4

Output

3

### Response

```cpp
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=100005;
int n,m;
struct ex{int num,next,w;}map[N*2];
int head[N],col[N],len;
inline void link(int x,int y)
{
  len++;map[len]=(ex){y,head[x],1};head[x]=len;
  len++;map[len]=(ex){x,head[y],2};head[y]=len;
}
bool vis[N],NO;int num[3],tot,bot;
inline void dfs(int k)
{
  vis[k]=1;num[col[k]]++;tot++;
  int i,x,u=col[k],y;
  for(i=head[k];i;i=map[i].next)
    {
      x=map[i].num;bot++;
      y=(u+map[i].w)%3;
      if(vis[x]) NO|=(col[x]!=y);
      else col[x]=y,dfs(x);
    }
}
int main( )
{
  int i,x,y;LL ans=0;
  n=read( );m=read( );
  for(i=1;i<=m;i++) x=read( ),y=read( ),link(x,y);
  for(i=1;i<=n;i++)
    {
      if(vis[i]) continue;
      num[0]=num[1]=num[2]=0;
      NO=0;tot=0;bot=0;dfs(i);
      if(NO) ans+=1LL*tot*tot;
      else if(num[0]&&num[1]&&num[2]) ans+=1LL*num[0]*num[1]+1LL*num[1]*num[2]+1LL*num[2]*num[0];
      else ans+=bot>>1;
    }
  printf("%lld",ans);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Example

Input

ACM

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
pair<string, string> split(const string &s) {
  int p = s.find('=');
  string l = s.substr(0, p);
  string r = s.substr(p + 1);
  return make_pair(l, r);
}
bool check(const string &s) {
  int p = s.find('=');
  if(p == -1) return false;
  pair<string, string> sp = split(s);
  if(sp.first.size() == 0 || sp.second.size() == 0) return false;
  int k = 0;
  for(char c : sp.first) {
    if(c == '(') ++k;
    if(c == ')') --k;
    if(k < 0) return false;
  }
  if(k != 0) return false;
  for(char c : sp.second) {
    if(c == '(') ++k;
    if(c == ')') --k;
    if(k < 0) return false;
  }
  return true;
}
typedef string::const_iterator iter;
struct Result {
  bool valid;
  int value;
  Result(bool valid_, int value_) : valid(valid_), value(value_) {}
};
Result fail(false, 114514);
bool Q(iter &p);
Result E(iter &p);
Result T(iter &p);
Result F(iter &p);
Result N(iter &p);
Result B(iter &p);
bool Q(iter &p) {
  Result l = E(p);
  // if(!l.valid) {
  //   cerr << "l = No" << endl;
  // }
  // else {
  //   cerr << "l = " << l.value << endl;
  // }
  if(!l.valid) return false;
  if(*p != '=') return false;
  ++p;
  Result r = E(p);
  // if(!l.valid) {
  //   cerr << "r = No" << endl;
  // }
  // else {
  //   cerr << "r = " << r.value << endl;
  // }
  if(!r.valid) return false;
  if(*p != '\0') return false;
  return l.value == r.value;
}
Result E(iter &p) {
  Result t = T(p);
  if(!t.valid) return fail;
  while(true) {
    if(*p == '+') {
      ++p;
      Result s = T(p);
      if(!s.valid) return fail;
      t.value += s.value;
    }
    else if(*p == '-') {
      ++p;
      Result s = T(p);
      if(!s.valid) return fail;
      t.value -= s.value;
    }
    else {
      break;
    }
  }
  return t;
}
Result T(iter &p) {
  Result t = F(p);
  if(!t.valid) return fail;
  while(true) {
    if(*p == '*') {
      ++p;
      Result s = F(p);
      if(!s.valid) return fail;
      t.value *= s.value;
    }
    else {
      break;
    }
  }
  return t;
}
Result F(iter &p) {
  if(*p == '(') {
    ++p;
    Result e = E(p);
    if(*p != ')') {
      return fail;
    }
    ++p;
    return e;
  }
  else if(*p == '-') {
    ++p;
    Result e = F(p);
    if(!e.valid) return fail;
    e.value *= -1;
    return e;
  }
  return N(p);
}
Result N(iter &p) {
  if(!isdigit(*p)) {
    return fail;
  }
  int n = 0;
  int i = 0;
  while(isdigit(*p)) {
    n *= 2;
    if(i > 0 && n == 0) return fail;
    n += *p - '0';
    ++p;
    ++i;
  }
  // DEBUG(n);
  return Result(true, n);
}
void dbg() {
  string S; cin >> S;
  iter p = S.cbegin();
  bool r = Q(p);
  cout << (r ? "Yes" : "No") << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  if(false) {
    dbg();
  }
  else {
    string S; cin >> S;
    vector<char> ch;
    string ops = "01+-*=()";
    sort(ops.begin(), ops.end());
    REP(i,S.size()) {
      if(ops.find(S[i]) == string::npos) {
        ch.push_back(S[i]);
      }
    }
    sort(ch.begin(), ch.end());
    ch.erase(unique(ch.begin(), ch.end()), ch.end());
    if(ch.size() > 8) {
      cout << 0 << endl;
      return 0;
    }
    map<char, int> replacer;
    REP(i,ch.size()) {
      replacer[ch[i]] = i;
      // DEBUG(ch[i]);
    }
    set<string> ans;
    do {
      string T = S;
      REP(i,T.size()) {
        if(replacer.count(T[i])) T[i] = ops[replacer[T[i]]];
      }
      // if(T == "-0=(0)") DEBUG(T);
      iter p = T.cbegin();
      bool r = Q(p);
      if(r) {
        ans.insert(ops.substr(0,ch.size()));
        // DEBUG(T);
      }
    } while(next_permutation(ops.begin(), ops.end()));
    cout << ans.size() << endl;
  }
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.

We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integers: the number of the starting vertex, the number of the final vertex and the edge's weight. So, as Vasya was trying to represent characteristics of a recently invented robot in his program, he faced the following problem.

Vasya is not a programmer, so he asked his friend Gena, what the convenient way to store n integers is. Gena used to code in language X-- and so he can use only the types that occur in this language. Let's define, what a "type" is in language X--:

  * First, a type is a string "int".
  * Second, a type is a string that starts with "pair", then followed by angle brackets listing exactly two comma-separated other types of language X--. This record contains no spaces.
  * No other strings can be regarded as types.

More formally: type := int | pair<type,type>. For example, Gena uses the following type for graph edges: pair<int,pair<int,int>>.

Gena was pleased to help Vasya, he dictated to Vasya a type of language X--, that stores n integers. Unfortunately, Gena was in a hurry, so he omitted the punctuation. Now Gena has already left and Vasya can't find the correct punctuation, resulting in a type of language X--, however hard he tries.

Help Vasya and add the punctuation marks so as to receive the valid type of language X--. Otherwise say that the task is impossible to perform.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), showing how many numbers the type dictated by Gena contains.

The second line contains space-separated words, said by Gena. Each of them is either "pair" or "int" (without the quotes).

It is guaranteed that the total number of words does not exceed 105 and that among all the words that Gena said, there are exactly n words "int".

Output

If it is possible to add the punctuation marks so as to get a correct type of language X-- as a result, print a single line that represents the resulting type. Otherwise, print "Error occurred" (without the quotes). Inside the record of a type should not be any extra spaces and other characters.

It is guaranteed that if such type exists, then it is unique.

Note that you should print the type dictated by Gena (if such type exists) and not any type that can contain n values.

Examples

Input

3
pair pair int int int

Output

pair<pair<int,int>,int>

Input

1
pair int

Output

Error occurred

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename A>
string to_string(A* ptr) {
  stringstream ss;
  ss << "0x" << std::setw(16) << std::setfill('0') << std::hex
     << (uint64_t)(uintptr_t)ptr;
  return ss.str();
}
string to_string(char c) { return ((string) "'" + c) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const string PAIR = "pair";
const string INT = "int";
const string ERR = "Error occurred";
string solve(int n, vector<string> v) {
  stringstream res;
  int sz = (int)v.size();
  vector<int> ST;
  for (int idx = 0; idx < sz; idx++) {
    42;
    const string& s = v[idx];
    assert(s == PAIR || s == INT);
    if (s == PAIR) {
      ST.push_back(0);
      res << PAIR << '<';
    } else {
      res << INT;
      while (true) {
        if (ST.empty()) {
          if (idx == sz - 1)
            break;
          else
            return ERR;
        }
        ST.back() += 1;
        assert(ST.back() == 1 || ST.back() == 2);
        if (ST.back() == 1) {
          res << ',';
          break;
        } else {
          res << '>';
          ST.pop_back();
        }
      }
      if (ST.empty() && idx != sz - 1) return ERR;
    }
  }
  if (!ST.empty()) return ERR;
  return res.str();
}
int main() {
  int TTT = 1;
  for (int ttt = 0; ttt < TTT; ttt++) {
    int n;
    cin >> n;
    vector<string> v;
    string s;
    while (cin >> s) {
      v.push_back(s);
    }
    42;
    42;
    cout << solve(n, v);
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

In this problem you will meet the simplified model of game Pudding Monsters.

An important process in developing any game is creating levels. A game field in Pudding Monsters is an n × n rectangular grid, n of its cells contain monsters and some other cells contain game objects. The gameplay is about moving the monsters around the field. When two monsters are touching each other, they glue together into a single big one (as they are from pudding, remember?).

<image>

Statistics showed that the most interesting maps appear if initially each row and each column contains exactly one monster and the rest of map specifics is set up by the correct positioning of the other game objects.

A technique that's widely used to make the development process more efficient is reusing the available resources. For example, if there is a large n × n map, you can choose in it a smaller k × k square part, containing exactly k monsters and suggest it as a simplified version of the original map.

You wonder how many ways there are to choose in the initial map a k × k (1 ≤ k ≤ n) square fragment, containing exactly k pudding monsters. Calculate this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 3 × 105) — the size of the initial field.

Next n lines contain the coordinates of the cells initially containing monsters. The i-th of the next lines contains two numbers ri, ci (1 ≤ ri, ci ≤ n) — the row number and the column number of the cell that initially contains the i-th monster.

It is guaranteed that all ri are distinct numbers and all ci are distinct numbers.

Output

Print the number of distinct square fragments of the original field that can form a new map.

Examples

Input

5
1 1
4 3
3 2
2 4
5 5

Output

10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N];
int lmx[N], lmn[N], rmx[N], rmn[N];
int cnt[N << 1];
long long ovo(int l, int r) {
  if (l == r) return 1;
  int mid = l + r >> 1;
  long long ret = ovo(l, mid) + ovo(mid + 1, r);
  lmx[mid] = lmn[mid] = a[mid];
  for (int i = mid - 1; i >= l; --i) {
    lmx[i] = max(lmx[i + 1], a[i]);
    lmn[i] = min(lmn[i + 1], a[i]);
  }
  rmx[mid + 1] = rmn[mid + 1] = a[mid + 1];
  for (int i = mid + 2; i <= r; ++i) {
    rmx[i] = max(rmx[i - 1], a[i]);
    rmn[i] = min(rmn[i - 1], a[i]);
  }
  for (int i = l, j; i <= mid; ++i) {
    j = i + lmx[i] - lmn[i];
    if (j > mid && j <= r)
      if (rmx[j] < lmx[i] && rmn[j] > lmn[i]) ++ret;
  }
  for (int i = mid + 1, j; i <= r; ++i) {
    j = i - rmx[i] + rmn[i];
    if (j <= mid && j >= l)
      if (lmx[j] < rmx[i] && lmn[j] > rmn[i]) ++ret;
  }
  for (int i = mid, u = mid, v = mid + 1; i >= l; --i) {
    for (; u < r && rmn[u + 1] > lmn[i]; ++u) ++cnt[rmx[u + 1] - (u + 1) + N];
    for (; v <= min(u, r) && rmx[v] < lmx[i]; ++v) --cnt[rmx[v] - v + N];
    ret += max(0, cnt[lmn[i] - i + N]);
  }
  for (int i = mid + 1; i <= r; ++i) cnt[rmx[i] - i + N] = 0;
  for (int i = mid, u = mid, v = mid + 1; i >= l; --i) {
    for (; u < r && rmx[u + 1] < lmx[i]; ++u) ++cnt[rmn[u + 1] + (u + 1)];
    for (; v <= min(u, r) && rmn[v] > lmn[i]; ++v) --cnt[rmn[v] + v];
    ret += max(0, cnt[lmx[i] + i]);
  }
  for (int i = mid + 1; i <= r; ++i) cnt[rmn[i] + i] = 0;
  return ret;
}
int main() {
  cin >> n;
  for (int i = 1, x, y; i <= n; ++i) scanf("%d%d", &x, &y), a[y] = x;
  cout << ovo(1, n) << endl;
  return 0;
}

```


### Prompt

In CPP, your task is to solve 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;
void onami(long long n, long long b, long long a) {
  map<long long, long long> m;
  map<long long, long long>::iterator it;
  while (n % 2 == 0) {
    m[2]++;
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      m[i]++;
      n = n / i;
    }
  }
  if (n > 2) {
    m[n]++;
  }
  long long xx, y;
  xx = 1;
  y = 1;
  for (it = m.begin(); it != m.end(); it++) {
    long long nnn = a;
    while (nnn % b == 0) {
      nnn = nnn / (*it).first;
    }
    xx = max(nnn, xx);
  }
  n = b;
  vector<long long> v;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i) {
        v.push_back(i);
      } else {
        v.push_back(i);
        v.push_back(n / i);
      }
    }
  }
  sort(v.rbegin(), v.rend());
  y = v[1];
  cout << max(xx, y);
}
int main() {
  int Tt;
  cin >> Tt;
  for (int i = 0; i < Tt; i++) {
    long long a, b, c;
    cin >> a;
    cin >> b;
    if (b <= a && a % b == 0) {
      onami(b, b, a);
      printf("\n");
    } else {
      cout << a;
      printf("\n");
    }
  }
}

```


### Prompt

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

Give you N cards. Only one natural number is written on each card. However, the same number is never written.

From now on, as a question, I will say an appropriate natural number. Please answer the largest remainder you get when you divide the number on the card you have by the number I said.

For example, suppose you have three cards with 9, 3, and 8, respectively. If I say "4", find the remainder of 9 and 3 and 8 divided by 4, respectively. The remainders are 1, 3, and 0, respectively, but the largest remainder is 3, so 3 is the correct answer.

Let's get started. e? Is it hard to have a lot of cards? It can not be helped. Now let's use the computer to find the largest remainder. Create a program that finds the largest of the remainders of the number on the card divided by the number asked. Ask the question many times, not just once, but never ask the same number more than once.

input

The input consists of one dataset. Input data is given in the following format.

N Q
c1 c2 ... cN
q1
q2
::
qQ

The number of cards N (2 ≤ N ≤ 300000) and the number of questions Q (2 ≤ Q ≤ 100000) are given in the first line, separated by one space, and the number ci (1 ≤ 100000) written on the card in the second line. ci ≤ 300000) is given with one space delimiter. The following Q line is given the number qi (1 ≤ qi ≤ 300000) given as a question.

output

Output the maximum remainder on one line for each question.

Example

Input

3 3
9 3 8
4
6
5

Output

3
3
4

### Response

```cpp
#include <iostream>
#include <algorithm>
using namespace std;
int n, q, x, s[300003]; bool a[300003];
int sum(int l, int r) {
	return s[r - 1] - s[l - 1];
}
int main() {
	scanf("%d%d", &n, &q);
	for(int i = 0; i < n; i++) scanf("%d", &x), a[x] = true;
	for(int i = 1; i <= 300000; i++) s[i] = s[i - 1] + (a[i] ? 1 : 0);
	for(int i = 0; i < q; i++) {
		scanf("%d", &x);
		int ret = 0;
		for(int j = x; j <= 300000; j += x) {
			if(sum(j - x, j) == 0) continue;
			int l = j - x, r = j;
			while(r - l > 1) {
				int m = (l + r) / 2;
				if(sum(m, j) != 0) l = m;
				else r = m;
			}
			ret = max(ret, l - (j - x));
		}
		printf("%d\n", ret);
	}
}
```