### Prompt

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

One social network developer recently suggested a new algorithm of choosing ads for users.

There are n slots which advertisers can buy. It is possible to buy a segment of consecutive slots at once. The more slots you own, the bigger are the chances your ad will be shown to users.

Every time it is needed to choose ads to show, some segment of slots is picked by a secret algorithm. Then some advertisers are chosen. The only restriction is that it should be guaranteed for advertisers which own at least p% of slots composing this segment that their ad will be shown.

From the other side, users don't like ads. So it was decided to show no more than <image> ads at once. You are asked to develop a system to sell segments of slots and choose ads in accordance with the rules described above.

Input

The first line of the input contains three integers n, m and p (1 ≤ n, m ≤ 150 000, 20 ≤ p ≤ 100) — the number of slots, the number of queries to your system and threshold for which display of the ad is guaranteed.

Next line contains n integers ai (1 ≤ ai ≤ 150 000), where the i-th number means id of advertiser who currently owns the i-th slot.

Next m lines contain queries descriptions. Each description is of one of the following forms:

  * 1 l r id (1 ≤ l ≤ r ≤ n, 1 ≤ id ≤ 150 000) — advertiser id bought all slots in a range from l to r inclusive;
  * 2 l r (1 ≤ l ≤ r) — you need to choose advertisers for segment [l, r].

Output

For each query of the second type answer should be printed in a separate line. First integer of the answer should be the number of advertisements that will be shown <image>. Next cnt integers should be advertisers' ids.

It is allowed to print one advertiser more than once, but each advertiser that owns at least <image> slots of the segment from l to r should be in your answer.

Example

Input

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

Output

3 1 2 3
2 1 3
2 2 1
3 1 1000 1000
1 5
2 5 3
2 1 5

Note

Samples demonstrate that you actually have quite a lot of freedom in choosing advertisers.

### Response

```cpp
#include <bits/stdc++.h>
const int MAXN = 1.5e5 + 10;
int n, m, p;
int a[MAXN];
struct Node {
  int tot, num[5], cnt[5];
  inline friend Node operator+(Node a, Node b) {
    Node res = a;
    for (int i = 0; i < b.tot; ++i) {
      int flg = 0;
      for (int j = 0; j < res.tot; ++j)
        if (b.num[i] == res.num[j]) {
          res.cnt[j] += b.cnt[i], flg = 1;
          break;
        }
      if (flg) continue;
      if (res.tot < p) {
        res.num[res.tot] = b.num[i], res.cnt[res.tot++] = b.cnt[i];
        continue;
      }
      int num = 0;
      for (int j = 1; j < res.tot; ++j) res.cnt[j] < res.cnt[num] && (num = j);
      if (res.cnt[num] > b.cnt[i]) {
        for (int j = 0; j < res.tot; ++j) res.cnt[j] -= b.cnt[i];
      } else {
        int tmp = res.cnt[num];
        res.num[num] = b.num[i], res.cnt[num] = b.cnt[i];
        for (int j = 0; j < res.tot; ++j) res.cnt[j] -= tmp;
      }
    }
    return res;
  }
};
template <int N>
struct SegmentTree {
  static const int M = N << 2;
  Node t[M];
  int tag[M];
  inline void gai(int x, int L, int R, int val) {
    t[x].tot = 1, t[x].num[0] = tag[x] = val, t[x].cnt[0] = R - L + 1;
  }
  inline void pushUp(int x) { t[x] = t[((x) << 1)] + t[((x) << 1 | 1)]; }
  inline void pushDown(int x, int L, int R) {
    if (tag[x]) {
      int mid = (L + R) >> 1;
      gai(((x) << 1), L, mid, tag[x]), gai(((x) << 1 | 1), mid + 1, R, tag[x]),
          tag[x] = 0;
    }
  }
  void build(int x, int L, int R) {
    if (L == R) {
      t[x].tot = 1, t[x].num[0] = a[L], t[x].cnt[0] = 1;
      return;
    }
    int mid = (L + R) >> 1;
    build(((x) << 1), L, mid), build(((x) << 1 | 1), mid + 1, R), pushUp(x);
  }
  void update(int x, int L, int R, int ql, int qr, int val) {
    if (ql <= L && R <= qr) return gai(x, L, R, val);
    int mid = (L + R) >> 1;
    pushDown(x, L, R);
    if (ql <= mid) update(((x) << 1), L, mid, ql, qr, val);
    if (qr > mid) update(((x) << 1 | 1), mid + 1, R, ql, qr, val);
    pushUp(x);
  }
  Node query(int x, int L, int R, int ql, int qr) {
    if (ql <= L && R <= qr) return t[x];
    int mid = (L + R) >> 1;
    pushDown(x, L, R);
    if (qr <= mid)
      return query(((x) << 1), L, mid, ql, qr);
    else if (ql > mid)
      return query(((x) << 1 | 1), mid + 1, R, ql, qr);
    else
      return query(((x) << 1), L, mid, ql, qr) +
             query(((x) << 1 | 1), mid + 1, R, ql, qr);
  }
};
SegmentTree<MAXN> Tr;
int main() {
  scanf("%d%d%d", &n, &m, &p), p = 100 / p;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  Tr.build(1, 1, n);
  for (int i = 1, opt, L, R, val; i <= m; ++i) {
    scanf("%d%d%d", &opt, &L, &R);
    if (opt == 1)
      scanf("%d", &val), Tr.update(1, 1, n, L, R, val);
    else {
      Node ans = Tr.query(1, 1, n, L, R);
      printf("%d", ans.tot);
      for (int j = 0; j < ans.tot; ++j) printf(" %d", ans.num[j]);
      puts("");
    }
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".

The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.

Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.

  1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
  2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
  3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.

If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.

Please determine the total cost for each of the m customers.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 10^5), representing the number of different kinds of food and the number of customers, respectively.

The second line contains n positive integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.

The third line contains n positive integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^6), where c_i denotes the cost of one dish of the i-th kind.

The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 ≤ t_j ≤ n, 1 ≤ d_j ≤ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.

Output

Print m lines. In the j-th line print the cost for the j-th customer.

Examples

Input

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

Output

22
24
14
10
39

Input

6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66

Output

36
396
3996
39996
399996
0

Input

6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6

Output

36
11058
99996
4333326
0
0

Note

In the first sample, 5 customers will be served as follows.

  1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 ⋅ 3 + 1 ⋅ 2 + 1 ⋅ 2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
  2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 ⋅ 6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
  3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 ⋅ 2 + 3 ⋅ 2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
  4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 ⋅ 3 + 2 ⋅ 2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
  5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 ⋅ 3 + 3 ⋅ 6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.

In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 ⋅ 6 = 396.

In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 ⋅ 6 + 666 ⋅ 6 + 6666 ⋅ 1 = 11058.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v;
long long a[100005], c[100005];
void print(long long n) {
  for (long long i = 0; i < n; i++) {
    cout << "{" << v[i].first << "," << v[i].second << "} ";
  }
  cout << "\n";
}
void pt(long long a[], long long n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, m, i, j, k, tot_dishes = 0;
    cin >> n >> m;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      tot_dishes += a[i];
    }
    for (i = 0; i < n; i++) cin >> c[i];
    for (i = 0; i < n; i++) v.push_back(make_pair(c[i], i));
    sort((v).begin(), (v).end());
    long long ptr = 0;
    for (i = 0; i < m; i++) {
      long long qty, type;
      cin >> type >> qty;
      type--;
      if (qty <= tot_dishes) {
        long long cost = 0;
        if (qty <= a[type]) {
          cost += (qty * c[type]);
          a[type] -= qty;
          tot_dishes -= qty;
          qty = 0;
        } else {
          cost += (a[type] * c[type]);
          tot_dishes -= a[type];
          qty -= a[type];
          a[type] = 0;
          while (qty > 0 && ptr < n) {
            long long idx = v[ptr].second;
            if (qty <= a[idx]) {
              cost += (qty * c[idx]);
              a[idx] -= qty;
              tot_dishes -= qty;
              qty = 0;
            } else {
              cost += (a[idx] * c[idx]);
              qty -= a[idx];
              tot_dishes -= a[idx];
              a[idx] = 0;
              ptr++;
            }
          }
        }
        cout << cost << "\n";
      } else {
        ptr = n;
        tot_dishes = 0;
        cout << "0\n";
      }
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.

Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree with colored vertices.

Now Appleman wonders, what is the number of sets splitting the tree in such a way that each resulting part will have exactly one black vertex? Find this number modulo 1000000007 (109 + 7).

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of tree vertices.

The second line contains the description of the tree: n - 1 integers p0, p1, ..., pn - 2 (0 ≤ pi ≤ i). Where pi means that there is an edge connecting vertex (i + 1) of the tree and vertex pi. Consider tree vertices are numbered from 0 to n - 1.

The third line contains the description of the colors of the vertices: n integers x0, x1, ..., xn - 1 (xi is either 0 or 1). If xi is equal to 1, vertex i is colored black. Otherwise, vertex i is colored white.

Output

Output a single integer — the number of ways to split the tree modulo 1000000007 (109 + 7).

Examples

Input

3
0 0
0 1 1

Output

2

Input

6
0 1 1 0 4
1 1 0 0 1 0

Output

1

Input

10
0 1 2 1 4 4 4 0 8
0 0 0 1 0 1 1 0 0 1

Output

27

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9 + 7;
int p[maxn];
long long d[maxn][2];
int n, x;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) scanf("%d", p + i + 1);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    d[i][x] = 1;
  }
  for (int i = n - 1; i > 0; i--) {
    d[p[i]][1] =
        (d[p[i]][1] * (d[i][0] + d[i][1]) + d[p[i]][0] * d[i][1]) % mod;
    d[p[i]][0] = (d[p[i]][0] * (d[i][0] + d[i][1])) % mod;
  }
  cout << d[0][1] << endl;
}

```


### Prompt

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

Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves:

  * Extract the first character of s and append t with this character.
  * Extract the last character of t and append u with this character.

Petya wants to get strings s and t empty and string u lexicographically minimal.

You should write a program that will help Petya win the game.

Input

First line contains non-empty string s (1 ≤ |s| ≤ 105), consisting of lowercase English letters.

Output

Print resulting string u.

Examples

Input

cab

Output

abc

Input

acdb

Output

abdc

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char strf[100005], strt[100005];
int cnt[26];
stack<int> S;
int main() {
  scanf("%s", strf);
  memset(cnt, 0, sizeof(cnt));
  int len = strlen(strf);
  for (int i = 0; i < len; i++) cnt[strf[i] - 'a']++;
  int pnf = 0, pnt = 0;
  for (int i = 0; i < 26; i++) {
    if (pnt == len) break;
    if (cnt[i] == len) {
      printf("%s\n", strf);
      return 0;
    }
    while ((!S.empty()) && S.top() <= i + 'a') {
      strt[pnt++] = S.top();
      S.pop();
    }
    while (cnt[i] > 0) {
      if (strf[pnf] - 'a' == i) {
        strt[pnt++] = strf[pnf];
        pnf++;
        cnt[i]--;
        continue;
      } else {
        S.push(strf[pnf]);
        cnt[strf[pnf] - 'a']--;
        pnf++;
      }
    }
  }
  while (!S.empty()) {
    strt[pnt++] = S.top();
    S.pop();
  }
  for (int i = 0; i < len; i++) printf("%c", strt[i]);
  printf("\n");
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Haruna is a high school student. She must remember the seating arrangements in her class because she is a class president. It is too difficult task to remember if there are so many students.

That is the reason why seating rearrangement is depress task for her. But students have a complaint if seating is fixed.

One day, she made a rule that all students must move but they don't move so far as the result of seating rearrangement.

The following is the rule. The class room consists of r*c seats. Each r row has c seats. The coordinate of the front row and most left is (1,1). The last row and right most is (r,c). After seating rearrangement, all students must move next to their seat. If a student sit (y,x) before seating arrangement, his/her seat must be (y,x+1) , (y,x-1), (y+1,x) or (y-1,x). The new seat must be inside of the class room. For example (0,1) or (r+1,c) is not allowed.

Your task is to check whether it is possible to rearrange seats based on the above rule.

Hint

For the second case, before seat rearrangement, the state is shown as follows.

1 2
3 4

There are some possible arrangements. For example

2 4
1 3

or

2 1
4 3

is valid arrangement.

Input

Input consists of multiple datasets. Each dataset consists of 2 integers. The last input contains two 0. A dataset is given by the following format.

r c

Input satisfies the following constraint.
1 ≤ r ≤ 19, 1 ≤ c ≤ 19

Output

Print "yes" without quates in one line if it is possible to rearrange the seats, otherwise print "no" without quates in one line.

Example

Input

1 1
2 2
0 0

Output

no
yes

### Response

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

int main(){
    int r, c;
    while(cin >> r >> c, r&&c){
        if( (r*c)%2 ) cout << "no" << endl;
        else cout << "yes" << endl;
    }
    return 0;
}
```


### Prompt

Generate a cpp solution to the following problem:

A tree of size n is an undirected connected graph consisting of n vertices without cycles.

Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the condition holds: "vertices u and v are connected by an edge if and only if vertices pu and pv are connected by an edge".

You are given permutation p of size n. Find some tree size n, invariant relative to the given permutation.

Input

The first line contains number n (1 ≤ n ≤ 105) — the size of the permutation (also equal to the size of the sought tree).

The second line contains permutation pi (1 ≤ pi ≤ n).

Output

If the sought tree does not exist, print "NO" (without the quotes).

Otherwise, print "YES", and then print n - 1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter.

If there are multiple solutions, output any of them.

Examples

Input

4
4 3 2 1

Output

YES
4 1
4 2
1 3

Input

3
3 1 2

Output

NO

Note

In the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree.

It can be shown that in the second sample test no tree satisfies the given condition.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int p[100005], vis[100005];
vector<int> v[100005];
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) v[i].clear();
    ans.clear();
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) cin >> p[i];
    int f = 1, mn = n;
    int rt;
    for (int i = 1; i <= n; i++) {
      if (vis[i]) continue;
      int num = 0, x = i;
      while (!vis[x]) {
        num++;
        vis[x] = 1;
        x = p[x];
      }
      if (num == 1 || (num == 2 && mn > 1)) rt = x;
      mn = min(mn, num);
      v[num].push_back(x);
    }
    if (mn > 2) {
      cout << "NO" << endl;
      continue;
    }
    for (int i = mn; i <= n; i++) {
      if (v[i].size() == 0) continue;
      if (i % mn) {
        f = 0;
        break;
      }
      for (auto u : v[i]) {
        if (u == rt || p[u] == rt) continue;
        int uu = u;
        do {
          ans.push_back(make_pair(rt, uu));
          uu = p[uu];
          if (uu != u)
            ans.push_back(make_pair(p[rt], uu));
          else
            break;
          uu = p[uu];
        } while (uu != u);
      }
    }
    if (mn == 2) ans.push_back(make_pair(rt, p[rt]));
    if (!f)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (auto u : ans) cout << u.first << " " << u.second << endl;
    }
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There are n players sitting at the card table. Each player has a favorite number. The favorite number of the j-th player is f_j.

There are k ⋅ n cards on the table. Each card contains a single integer: the i-th card contains number c_i. Also, you are given a sequence h_1, h_2, ..., h_k. Its meaning will be explained below.

The players have to distribute all the cards in such a way that each of them will hold exactly k cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals h_t if the player holds t cards containing his favorite number. If a player gets no cards with his favorite number (i.e., t=0), his joy level is 0.

Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence h_1, ..., h_k is the same for all the players.

Input

The first line of input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ 10) — the number of players and the number of cards each player will get.

The second line contains k ⋅ n integers c_1, c_2, ..., c_{k ⋅ n} (1 ≤ c_i ≤ 10^5) — the numbers written on the cards.

The third line contains n integers f_1, f_2, ..., f_n (1 ≤ f_j ≤ 10^5) — the favorite numbers of the players.

The fourth line contains k integers h_1, h_2, ..., h_k (1 ≤ h_t ≤ 10^5), where h_t is the joy level of a player if he gets exactly t cards with his favorite number written on them. It is guaranteed that the condition h_{t - 1} < h_t holds for each t ∈ [2..k].

Output

Print one integer — the maximum possible total joy levels of the players among all possible card distributions.

Examples

Input

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

Output

21

Input

3 3
9 9 9 9 9 9 9 9 9
1 2 3
1 2 3

Output

0

Note

In the first example, one possible optimal card distribution is the following:

  * Player 1 gets cards with numbers [1, 3, 8];
  * Player 2 gets cards with numbers [2, 2, 8];
  * Player 3 gets cards with numbers [2, 2, 8];
  * Player 4 gets cards with numbers [5, 5, 5].

Thus, the answer is 2 + 6 + 6 + 7 = 21.

In the second example, no player can get a card with his favorite number. Thus, the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXK = 15;
const int MAXN = 505;
const int MAXC = 100005;
int n, k, h[MAXK], ans;
int cnt[MAXC], p[MAXC];
int dp[MAXN][MAXN * MAXK];
vector<int> like;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n * k; i++) {
    int c;
    scanf("%d", &c);
    cnt[c]++;
  }
  for (int i = 1; i <= n; i++) {
    int f;
    scanf("%d", &f);
    if (!p[f]) like.push_back(f);
    p[f]++;
  }
  for (int i = 1; i <= k; i++) scanf("%d", &h[i]);
  for (int l = 0; l < like.size(); l++) {
    int u = like[l];
    int o = min(p[u] * k, cnt[u]);
    for (int i = 1; i <= p[u]; i++)
      for (int j = 0; j <= min(i * k, o); j++)
        for (int r = 0; r <= min(j, k); r++)
          dp[i][j] = max(dp[i][j], dp[i - 1][j - r] + h[r]);
    ans += dp[p[u]][o];
  }
  printf("%d\n", ans);
}

```


### Prompt

Create a solution in CPP for the following problem:

Peter has a sequence of integers a1, a2, ..., an. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l, r]": add one to all elements of the sequence with indices from l to r (inclusive). At that, Peter never chooses any element as the beginning of the segment twice. Similarly, Peter never chooses any element as the end of the segment twice. In other words, for any two segments [l1, r1] and [l2, r2], where Peter added one, the following inequalities hold: l1 ≠ l2 and r1 ≠ r2.

How many distinct ways are there to make all numbers in the sequence equal h? Print this number of ways modulo 1000000007 (109 + 7). Two ways are considered distinct if one of them has a segment that isn't in the other way.

Input

The first line contains two integers n, h (1 ≤ n, h ≤ 2000). The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 2000).

Output

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

Examples

Input

3 2
1 1 1

Output

4

Input

5 1
1 1 1 1 1

Output

1

Input

4 3
3 2 1 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, h, a[N], b[N];
int main() {
  scanf("%d%d", &n, &h);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] = h - a[i];
  for (int i = 1; i <= n + 1; i++) {
    b[i] = a[i] - a[i - 1];
  }
  long long lcnt = 0, ans = 1;
  for (int i = 1; i <= n + 1; i++) {
    if (b[i] < -1 || b[i] > 1) {
      puts("0");
      return 0;
    }
    if (b[i] == -1) {
      ans *= lcnt, lcnt--;
    }
    if (b[i] == 0) ans *= (lcnt + 1);
    if (b[i] == 1) lcnt++;
    ans %= 1000000007;
  }
  printf("%lld\n", ans);
}

```


### Prompt

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

In order to do some research, n^2 labs are built on different heights of a mountain. Let's enumerate them with integers from 1 to n^2, such that the lab with the number 1 is at the lowest place, the lab with the number 2 is at the second-lowest place, …, the lab with the number n^2 is at the highest place.

To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number u to the lab with the number v if u > v.

Now the labs need to be divided into n groups, each group should contain exactly n labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group A to a group B is equal to the number of pairs of labs (u, v) such that the lab with the number u is from the group A, the lab with the number v is from the group B and u > v. Let's denote this value as f(A,B) (i.e. f(A,B) is the sum of units of water that can be sent from a group A to a group B).

For example, if n=3 and there are 3 groups X, Y and Z: X = \{1, 5, 6\}, Y = \{2, 4, 9\} and Z = \{3, 7, 8\}. In this case, the values of f are equal to:

  * f(X,Y)=4 because of 5 → 2, 5 → 4, 6 → 2, 6 → 4,
  * f(X,Z)=2 because of 5 → 3, 6 → 3,
  * f(Y,X)=5 because of 2 → 1, 4 → 1, 9 → 1, 9 → 5, 9 → 6,
  * f(Y,Z)=4 because of 4 → 3, 9 → 3, 9 → 7, 9 → 8,
  * f(Z,X)=7 because of 3 → 1, 7 → 1, 7 → 5, 7 → 6, 8 → 1, 8 → 5, 8 → 6,
  * f(Z,Y)=5 because of 3 → 2, 7 → 2, 7 → 4, 8 → 2, 8 → 4.

Please, divide labs into n groups with size n, such that the value min f(A,B) over all possible pairs of groups A and B (A ≠ B) is maximal.

In other words, divide labs into n groups with size n, such that minimum number of the sum of units of water that can be transported from a group A to a group B for every pair of different groups A and B (A ≠ B) as big as possible.

Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values f for some division.

If there are many optimal divisions, you can find any.

Input

The only line contains one number n (2 ≤ n ≤ 300).

Output

Output n lines:

In the i-th line print n numbers, the numbers of labs of the i-th group, in any order you want.

If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.

Example

Input

3

Output

2 8 5
9 3 4
7 6 1

Note

In the first test we can divide 9 labs into groups \{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}.

From the first group to the second group we can transport 4 units of water (8 → 3, 8 → 4, 5 → 3, 5 → 4).

From the first group to the third group we can transport 5 units of water (2 → 1, 8 → 7, 8 → 6, 8 → 1, 5 → 1).

From the second group to the first group we can transport 5 units of water (9 → 2, 9 → 8, 9 → 5, 3 → 2, 4 → 2).

From the second group to the third group we can transport 5 units of water (9 → 7, 9 → 6, 9 → 1, 3 → 1, 4 → 1).

From the third group to the first group we can transport 4 units of water (7 → 2, 7 → 5, 6 → 2, 6 → 5).

From the third group to the second group we can transport 4 units of water (7 → 3, 7 → 4, 6 → 3, 6 → 4).

The minimal number of the sum of units of water, that can be transported from one group to another is equal to 4. It can be proved, that it is impossible to make a better division.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, uk[301], flag = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    uk[i] = i;
  }
  vector<vector<int> > v(n + 1);
  for (int i = 1; i <= n * n; i++) {
    if (flag) {
      for (int j = 1; j <= n / 2; j++) {
        swap(uk[j], uk[n + 1 - j]);
      }
      flag = 0;
    }
    v[uk[i % n + n * (i % n == 0)]].push_back(i);
    if (i % n == 0) flag = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (auto x : v[i]) {
      cout << x << " ";
    }
    cout << "\n";
  }
  return 0;
}

```


### Prompt

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

There are n cities in the kingdom X, numbered from 1 through n. People travel between cities by some one-way roads. As a passenger, JATC finds it weird that from any city u, he can't start a trip in it and then return back to it using the roads of the kingdom. That is, the kingdom can be viewed as an acyclic graph.

Being annoyed by the traveling system, JATC decides to meet the king and ask him to do something. In response, the king says that he will upgrade some cities to make it easier to travel. Because of the budget, the king will only upgrade those cities that are important or semi-important. A city u is called important if for every city v ≠ u, there is either a path from u to v or a path from v to u. A city u is called semi-important if it is not important and we can destroy exactly one city v ≠ u so that u becomes important.

The king will start to act as soon as he finds out all those cities. Please help him to speed up the process.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 300 000, 1 ≤ m ≤ 300 000) — the number of cities and the number of one-way roads.

Next m lines describe the road system of the kingdom. Each of them contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), denoting one-way road from u_i to v_i.

It is guaranteed, that the kingdoms' roads make an acyclic graph, which doesn't contain multiple edges and self-loops.

Output

Print a single integer — the number of cities that the king has to upgrade.

Examples

Input

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

Output

4

Input

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

Output

4

Note

In the first example:

<image>

  * Starting at the city 1 we can reach all the other cities, except for the city 6. Also, from the city 6 we cannot reach the city 1. Therefore, if we destroy the city 6 then the city 1 will become important. So 1 is a semi-important city.
  * For city 2, the set of cities that cannot reach 2 and cannot be reached by 2 is \{6\}. Therefore, destroying city 6 will make the city 2 important. So city 2 is also semi-important.
  * For city 3, the set is \{5, 6\}. As you can see, destroying either city 5 or 6 will not make the city 3 important. Therefore, it is neither important nor semi-important.
  * For city 4, the set is empty. So 4 is an important city.
  * The set for city 5 is \{3, 6\} and the set for city 6 is \{3, 5\}. Similarly to city 3, both of them are not important nor semi-important.
  * The city 7 is important since we can reach it from all other cities.

So we have two important cities (4 and 7) and two semi-important cities (1 and 2).

In the second example, the important cities are 1 and 4. The semi-important cities are 2 and 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
int n, m;
vector<int> out[MAXN];
vector<int> in[MAXN];
bool been[MAXN];
int top[MAXN], ntop;
int mxlen[MAXN], nxt[MAXN];
int path[MAXN], npath;
int pathidx[MAXN];
int q[MAXN], qhead, qtail;
int lidx[MAXN], ridx[MAXN];
int cand[MAXN];
int candidx[MAXN];
int numout[MAXN];
int numin[MAXN];
void dfstop(int at) {
  assert(!been[at]);
  been[at] = true;
  for (int i = (0); i < (((int)(out[at]).size())); ++i) {
    int to = out[at][i];
    if (!been[to]) dfstop(to);
  }
  top[ntop++] = at;
}
int solve() {
  ntop = 0;
  for (int i = (0); i < (n); ++i) been[i] = false;
  for (int i = (0); i < (n); ++i)
    if (!been[i]) dfstop(i);
  assert(ntop == n);
  reverse(top, top + ntop);
  for (int i = n - 1; i >= 0; --i) {
    int at = top[i];
    mxlen[at] = 1, nxt[at] = -1;
    for (int j = (0); j < (((int)(out[at]).size())); ++j) {
      int to = out[at][j];
      if (mxlen[to] + 1 > mxlen[at]) mxlen[at] = mxlen[to] + 1, nxt[at] = to;
    }
  }
  int mxgloblen = 0, fst = -1;
  for (int i = (0); i < (n); ++i)
    if (mxlen[i] > mxgloblen) mxgloblen = mxlen[i], fst = i;
  npath = 0;
  for (int at = fst; at != -1; at = nxt[at]) path[npath++] = at;
  for (int i = (0); i < (n); ++i) pathidx[i] = -1;
  for (int i = (0); i < (npath); ++i) pathidx[path[i]] = i;
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) lidx[i] = -1;
  for (int i = npath - 1; i >= 0; --i) {
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(out[at]).size())); ++j) {
        int to = out[at][j];
        if (pathidx[to] != -1 || lidx[to] != -1) continue;
        lidx[to] = i;
        q[qhead++] = to;
      }
    }
  }
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) ridx[i] = -1;
  for (int i = (0); i < (npath); ++i) {
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(in[at]).size())); ++j) {
        int to = in[at][j];
        if (pathidx[to] != -1 || ridx[to] != -1) continue;
        ridx[to] = i;
        q[qhead++] = to;
      }
    }
  }
  for (int i = (0); i < (npath); ++i) cand[i] = -1;
  for (int i = (0); i < (n); ++i)
    if (pathidx[i] == -1) {
      int opt = -1;
      if (lidx[i] == -1 && ridx[i] == 1) opt = 0;
      if (ridx[i] == -1 && lidx[i] == npath - 2) opt = npath - 1;
      if (lidx[i] != -1 && ridx[i] != -1 && lidx[i] + 2 == ridx[i])
        opt = lidx[i] + 1;
      if (opt == -1) continue;
      if (cand[opt] == -1)
        cand[opt] = i;
      else
        cand[opt] = -2;
    }
  for (int i = (0); i < (npath); ++i)
    if (cand[i] == -2) cand[i] = -1;
  for (int i = (0); i < (n); ++i) candidx[i] = -1;
  for (int i = (0); i < (npath); ++i)
    if (cand[i] != -1) candidx[cand[i]] = i;
  for (int i = (0); i < (n); ++i) numout[i] = numin[i] = -1;
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) been[i] = false;
  for (int i = npath - 1; i >= 0; --i) {
    if (cand[i] != -1) {
      int qold = qhead;
      assert(!been[cand[i]]);
      been[cand[i]] = true;
      q[qhead++] = cand[i];
      while (qtail < qhead) {
        int at = q[qtail++];
        for (int j = (0); j < (((int)(out[at]).size())); ++j) {
          int to = out[at][j];
          if (been[to]) continue;
          been[to] = true;
          q[qhead++] = to;
        }
      }
      numout[cand[i]] = qhead;
      for (int j = (qold); j < (qhead); ++j) {
        int at = q[j];
        been[at] = false;
      }
      qtail = qhead = qold;
    }
    assert(!been[path[i]]);
    been[path[i]] = true;
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(out[at]).size())); ++j) {
        int to = out[at][j];
        if (been[to]) continue;
        been[to] = true;
        q[qhead++] = to;
      }
    }
    numout[path[i]] = qhead;
  }
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) been[i] = false;
  for (int i = (0); i < (npath); ++i) {
    if (cand[i] != -1) {
      int qold = qhead;
      assert(!been[cand[i]]);
      been[cand[i]] = true;
      q[qhead++] = cand[i];
      while (qtail < qhead) {
        int at = q[qtail++];
        for (int j = (0); j < (((int)(in[at]).size())); ++j) {
          int to = in[at][j];
          if (been[to]) continue;
          been[to] = true;
          q[qhead++] = to;
        }
      }
      numin[cand[i]] = qhead;
      for (int j = (qold); j < (qhead); ++j) {
        int at = q[j];
        been[at] = false;
      }
      qtail = qhead = qold;
    }
    assert(!been[path[i]]);
    been[path[i]] = true;
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(in[at]).size())); ++j) {
        int to = in[at][j];
        if (been[to]) continue;
        been[to] = true;
        q[qhead++] = to;
      }
    }
    numin[path[i]] = qhead;
  }
  int ret = 0;
  for (int i = (0); i < (n); ++i)
    if ((pathidx[i] != -1 || candidx[i] != -1) && numin[i] + numout[i] >= n)
      ++ret;
  return ret;
}
void run() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    out[a].push_back(b);
    in[b].push_back(a);
  }
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}

```


### Prompt

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

There is a game that involves three variables, denoted A, B, and C.

As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.

After each choice, none of A, B, and C should be negative.

Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

Constraints

* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.

Input

Input is given from Standard Input in the following format:

N A B C
s_1
s_2
:
s_N

Output

If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.

Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.

Examples

Input

2 1 3 0
AB
AC

Output

Yes
A
C

Input

3 1 0 0
AB
BC
AB

Output

No

Input

1 0 9 0
AC

Output

No

Input

8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB

Output

Yes
C
B
B
C
C
B
A
A

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

const int N = 2e5 + 5;

int n;
string str[N];
char res[N];

void dfs(int i, int a, int b, int c) {
    if (i >= n) {
        cout << "Yes" << endl;
        rep(i,n) {
            cout << res[i] << endl;
        }
        exit(0);
    }
    if (str[i] == "AB") {
        if (a) res[i] = 'B', dfs(i + 1, a - 1, b + 1, c);
        if (b) res[i] = 'A', dfs(i + 1, a + 1, b - 1, c);
    } else if (str[i] == "AC") {
        if (a) res[i] = 'C', dfs(i + 1, a - 1, b, c + 1);
        if (c) res[i] = 'A', dfs(i + 1, a + 1, b, c - 1);
    } else {
        if (b) res[i] = 'C', dfs(i + 1, a, b - 1, c + 1);
        if (c) res[i] = 'B', dfs(i + 1, a, b + 1, c - 1);
    }
}

int main() {
    int a, b, c;
    cin >> n >> a >> b >> c;
    rep(i,n) cin >> str[i];
    dfs(0, a, b, c);
    cout << "No" << endl;
    exit(0);
}

```


### Prompt

Create a solution in CPP for the following problem:

Arpa is researching the Mexican wave.

There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.

  * At time 1, the first spectator stands.
  * At time 2, the second spectator stands.
  * ...
  * At time k, the k-th spectator stands.
  * At time k + 1, the (k + 1)-th spectator stands and the first spectator sits.
  * At time k + 2, the (k + 2)-th spectator stands and the second spectator sits.
  * ...
  * At time n, the n-th spectator stands and the (n - k)-th spectator sits.
  * At time n + 1, the (n + 1 - k)-th spectator sits.
  * ...
  * At time n + k, the n-th spectator sits.

Arpa wants to know how many spectators are standing at time t.

Input

The first line contains three integers n, k, t (1 ≤ n ≤ 109, 1 ≤ k ≤ n, 1 ≤ t < n + k).

Output

Print single integer: how many spectators are standing at time t.

Examples

Input

10 5 3

Output

3

Input

10 5 7

Output

5

Input

10 5 12

Output

3

Note

In the following a sitting spectator is represented as -, a standing spectator is represented as ^.

  * At t = 0  ---------- <image> number of standing spectators = 0.
  * At t = 1  ^--------- <image> number of standing spectators = 1.
  * At t = 2  ^^-------- <image> number of standing spectators = 2.
  * At t = 3  ^^^------- <image> number of standing spectators = 3.
  * At t = 4  ^^^^------ <image> number of standing spectators = 4.
  * At t = 5  ^^^^^----- <image> number of standing spectators = 5.
  * At t = 6  -^^^^^---- <image> number of standing spectators = 5.
  * At t = 7  --^^^^^--- <image> number of standing spectators = 5.
  * At t = 8  ---^^^^^-- <image> number of standing spectators = 5.
  * At t = 9  ----^^^^^- <image> number of standing spectators = 5.
  * At t = 10 -----^^^^^ <image> number of standing spectators = 5.
  * At t = 11 ------^^^^ <image> number of standing spectators = 4.
  * At t = 12 -------^^^ <image> number of standing spectators = 3.
  * At t = 13 --------^^ <image> number of standing spectators = 2.
  * At t = 14 ---------^ <image> number of standing spectators = 1.
  * At t = 15 ---------- <image> number of standing spectators = 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, t;
  cin >> n >> k >> t;
  if (t >= k && n >= t) {
    cout << k;
    return 0;
  }
  if (t > n) {
    cout << max((int)0, k - (t - n));
    return 0;
  }
  cout << t;
}

```


### Prompt

Generate a CPP solution to the following problem:

Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.

For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.

There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.

Output

Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.

Examples

Input

4
1 2 1 2

Output

7 3 0 0

Input

3
1 1 1

Output

6 0 0

Note

In the first sample, color 2 is dominant in three intervals:

  * An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
  * An interval [4, 4] contains one ball, with color 2 again.
  * An interval [2, 4] contains two balls of color 2 and one ball of color 1.

There are 7 more intervals and color 1 is dominant in all of them.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[5001], visited[5001], answer[5001];
int main() {
  ios::sync_with_stdio(false);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    int Max = 0, color = 0;
    memset(visited, 0, sizeof visited);
    for (int j = i; j < n; j++) {
      visited[arr[j]]++;
      if (visited[arr[j]] > Max || (visited[arr[j]] == Max && color >= arr[j]))
        Max = visited[arr[j]], color = arr[j];
      answer[color]++;
    }
  }
  for (int i = 1; i <= n; i++) cout << answer[i] << " ";
  cout << "\n";
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.

Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.

Constraints

* 1≦a,b,c≦100

Input

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

a b c

Output

Print the number of different kinds of colors of the paint cans.

Examples

Input

3 1 4

Output

3

Input

3 3 33

Output

2

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
  for (int i=0;i<3;i++){
    int t;cin>>t;
    s.insert(t);
  }cout<<s.size()<<endl;
}
```


### Prompt

Please create a solution in CPP to the following problem:

You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave this level until you've gained the maximum possible number of points there.

The bonus level consists of n small platforms placed in a line and numbered from 1 to n from left to right and (n - 1) bridges connecting adjacent platforms. The bridges between the platforms are very fragile, and for each bridge the number of times one can pass this bridge from one of its ends to the other before it collapses forever is known in advance.

The player's actions are as follows. First, he selects one of the platforms to be the starting position for his hero. After that the player can freely move the hero across the platforms moving by the undestroyed bridges. As soon as the hero finds himself on a platform with no undestroyed bridge attached to it, the level is automatically ended. The number of points scored by the player at the end of the level is calculated as the number of transitions made by the hero between the platforms. Note that if the hero started moving by a certain bridge, he has to continue moving in the same direction until he is on a platform.

Find how many points you need to score to be sure that nobody will beat your record, and move to the next level with a quiet heart.

Input

The first line contains a single integer n (2 ≤ n ≤ 105) — the number of platforms on the bonus level. The second line contains (n - 1) integers ai (1 ≤ ai ≤ 109, 1 ≤ i < n) — the number of transitions from one end to the other that the bridge between platforms i and i + 1 can bear.

Output

Print a single integer — the maximum number of points a player can get on the bonus level.

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
2 1 2 1

Output

5

Note

One possibility of getting 5 points in the sample is starting from platform 3 and consequently moving to platforms 4, 3, 2, 1 and 2. After that the only undestroyed bridge is the bridge between platforms 4 and 5, but this bridge is too far from platform 2 where the hero is located now.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long r[2][N], l[2][N], a[N], n;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  long long mx = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i - 1] < 2) continue;
    l[0][i] = l[0][i - 1] + a[i - 1] - (a[i - 1] & 1);
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] < 2) continue;
    r[0][i] = r[0][i + 1] + a[i] - (a[i] & 1);
  }
  for (int i = 1; i <= n; i++) {
    l[1][i] = l[1][i - 1] + max(0ll, a[i - 1] - (a[i - 1] % 2 == 0));
    l[1][i] = max(l[1][i], l[0][i]);
  }
  for (int i = n; i >= 1; i--) {
    r[1][i] = r[1][i + 1] + max(0ll, a[i] - (a[i] % 2 == 0));
    r[1][i] = max(r[1][i], r[0][i]);
  }
  for (int i = 1; i <= n; i++) {
    mx = max(mx, max(r[0][i] + l[1][i], r[1][i] + l[0][i]));
  }
  cout << mx << endl;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights.

<image> Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1]

Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.

Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).

Input

The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence.

Output

Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them.

Examples

Input

7 3
1 2 6 1 1 7 1

Output

3

Note

In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100 * 1000 + 10, inf = 1e9;
int arr[MAXN];
int sum[MAXN];
int main() {
  int k, n;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= k; i++) {
    sum[1] += arr[i];
  }
  for (int i = 2; i <= n - k + 1; i++) {
    sum[i] = sum[i - 1] - arr[i - 1] + arr[i + k - 1];
  }
  int minn = inf, ans = 0;
  for (int i = 1; i <= n - k + 1; i++) {
    minn = min(sum[i], minn);
    if (minn == sum[i]) {
      ans = i;
    }
  }
  cout << ans;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.

In each spot, if a house has height a, you will gain a^2 dollars from it.

The city has m zoning restrictions. The i-th restriction says that the tallest house from spots l_i to r_i (inclusive) must be at most x_i.

You would like to build houses to maximize your profit. Determine the maximum profit possible.

Input

The first line contains three integers n, h, and m (1 ≤ n,h,m ≤ 50) — the number of spots, the maximum height, and the number of restrictions.

Each of the next m lines contains three integers l_i, r_i, and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i ≤ h) — left and right limits (inclusive) of the i-th restriction and the maximum possible height in that range.

Output

Print a single integer, the maximum profit you can make.

Examples

Input

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

Output

14

Input

4 10 2
2 3 8
3 4 7

Output

262

Note

In the first example, there are 3 houses, the maximum height of a house is 3, and there are 3 restrictions. The first restriction says the tallest house between 1 and 1 must be at most 1. The second restriction says the tallest house between 2 and 2 must be at most 3. The third restriction says the tallest house between 3 and 3 must be at most 2.

In this case, it is optimal to build houses with heights [1, 3, 2]. This fits within all the restrictions. The total profit in this case is 1^2 + 3^2 + 2^2 = 14.

In the second example, there are 4 houses, the maximum height of a house is 10, and there are 2 restrictions. The first restriction says the tallest house from 2 to 3 must be at most 8. The second restriction says the tallest house from 3 to 4 must be at most 7.

In this case, it's optimal to build houses with heights [10, 8, 7, 7]. We get a profit of 10^2+8^2+7^2+7^2 = 262. Note that there are two restrictions on house 3 and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house 1, we must still limit its height to be at most 10 (h=10).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int fx[4] = {1, -1, 0, 0};
int fy[4] = {0, 0, 1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
int a[55];
int n, h, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> h >> m;
  for (int i = 1; i <= n; i++) {
    a[i] = h;
  }
  for (int i = 1; i <= m; i++) {
    int l, r, val;
    cin >> l >> r >> val;
    for (int k = l; k <= r; k++) {
      a[k] = min(a[k], val);
    }
  }
  long long sum = 0LL;
  for (int i = 1; i <= n; i++) {
    sum += (a[i] * a[i]);
  }
  cout << sum << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.

  * For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then degree(v_{1}) = degree(v_{2}), where degree means the number of vertices connected to that vertex, and distance means the number of edges between two vertices.

Determine and find if there is such root vertex in the tree. If there are multiple answers, find any of them.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^{5}) — the number of vertices.

Each of the next n-1 lines contains two integers v_{i} and u_{i} (1 ≤ v_{i} < u_{i} ≤ n) — it means there is an edge exist between v_{i} and u_{i}. It is guaranteed that the graph forms tree.

Output

If there is such root vertex exists, print any of them. Otherwise, print -1.

Examples

Input

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

Output

3

Input

6
1 3
2 3
3 4
4 5
4 6

Output

-1

Note

This is the picture for the first example. 1, 5, 7 also can be a valid answer.

<image>

This is the picture for the second example. You can see that it's impossible to find such root vertex.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int x, y, i, n, d, sz[N], mx, rt, s = 1e9, vis[N];
vector<int> G[N];
void dfs(int u, int fa) {
  sz[u] = 1;
  int mx = 0;
  for (int i = 0, v; i < G[u].size(); i++)
    if ((v = G[u][i]) != fa) dfs(v, u), sz[u] += sz[v], mx = max(mx, sz[v]);
  mx = max(mx, n - sz[u]);
  if (mx < s) s = mx, rt = u;
}
bool chk(int u, int fa, int d) {
  if (!sz[d])
    sz[d] = G[u].size();
  else if (G[u].size() != sz[d])
    return 0;
  for (int i = 0, v; i < G[u].size(); i++)
    if ((v = G[u][i]) != fa && !chk(v, u, d + 1)) return 0;
  return 1;
}
int line(int u, int fa, int d) {
  if (u == rt) return d;
  if (G[u].size() > 2) return 0;
  return line(G[u][G[u][0] == fa], u, d + 1);
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++)
    scanf("%d%d", &x, &y), G[x].push_back(y), G[y].push_back(x);
  dfs(1, 0);
  memset(sz, 0, n + 1 << 2);
  if (chk(rt, 0, 0)) return printf("%d", rt), 0;
  for (i = 1; i <= n; i++)
    if (G[i].size() == 1) {
      d = line(i, 0, 0);
      if (d && !vis[d]) {
        vis[d] = 1, memset(sz, 0, n + 1 << 2);
        if (chk(i, 0, 0)) return printf("%d", i), 0;
      }
    }
  puts("-1");
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given a text consisting of n space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. w_i is the i-th word of text. All words consist only of lowercase Latin letters.

Let's denote a segment of words w[i..j] as a sequence of words w_i, w_{i + 1}, ..., w_j. Two segments of words w[i_1 .. j_1] and w[i_2 .. j_2] are considered equal if j_1 - i_1 = j_2 - i_2, j_1 ≥ i_1, j_2 ≥ i_2, and for every t ∈ [0, j_1 - i_1] w_{i_1 + t} = w_{i_2 + t}. For example, for the text "to be or not to be" the segments w[1..2] and w[5..6] are equal, they correspond to the words "to be".

An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words w[2..4] and w[6..8] with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words w[2..5] and w[6..9] with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c".

What is the minimum length of the text after at most one abbreviation?

Input

The first line of the input contains one integer n (1 ≤ n ≤ 300) — the number of words in the text.

The next line contains n space-separated words of the text w_1, w_2, ..., w_n. Each word consists only of lowercase Latin letters.

It is guaranteed that the length of text does not exceed 10^5.

Output

Print one integer — the minimum length of the text after at most one abbreviation.

Examples

Input

6
to be or not to be

Output

12

Input

10
a ab a a b ab a a b c

Output

13

Input

6
aa bb aa aa bb bb

Output

11

Note

In the first example you can obtain the text "TB or not TB".

In the second example you can obtain the text "a AAAB AAAB c".

In the third example you can obtain the text "AB aa AB bb".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, i = 0, dp[305][305], eq[305][305], sum = 0, curr, total = 0, j = 0,
             k, cnt, ans;
string str[305];
int main(void) {
  for (cin >> n; i < n; i++) cin >> str[i], total += str[i].size();
  total += n - 1;
  ans = total;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) eq[i][j] = eq[j][i] = (str[i] == str[j]);
  }
  for (i = n - 1; i >= 0; i--) {
    for (j = n - 1; j >= 0; j--)
      (eq[i][j] == 1) ? dp[i][j] += dp[i + 1][j + 1] + 1 : 0;
  }
  for (i = 0; i < n; i++) {
    sum = 0;
    for (j = 1; j + i <= n; j++) {
      sum += str[i + j - 1].size();
      cnt = 1;
      for (k = i + j; k < n; k++) {
        if (dp[i][k] >= j) cnt++, k += j - 1;
      }
      curr = total - cnt * sum + j * cnt - (j - 1) * cnt;
      if (curr < ans && cnt > 1) ans = curr;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.

The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.

You have to calculate how many fights will happen and who will win the game, or state that game won't end.

Input

First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.

Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.

Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.

All card values are different.

Output

If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.

If the game won't end and will continue forever output  - 1.

Examples

Input

4
2 1 3
2 4 2

Output

6 2

Input

3
1 2
2 1 3

Output

-1

Note

First sample:

<image>

Second sample:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int k1, k2;
int a[100000], b[100000];
bool k[38000000];
int s1, s2;
int e1, e2, v;
int cantor() {
  int ans = 0;
  int k[10], cnt = 0;
  for (int i = s1; i < e1; i++) k[cnt++] = a[i];
  for (int i = s2; i < e2; i++) k[cnt++] = b[i];
  for (int i = 0; i < n; i++) {
    int x = 0;
    int c = 1, m = 1;
    for (int j = i + 1; j < n; j++) {
      if (k[j] < k[i]) x++;
      m *= c;
      c++;
    }
    ans += x * m;
  }
  return ans;
}
int main() {
  cin >> n;
  cin >> k1;
  for (int i = 0; i < k1; i++) {
    cin >> a[i];
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    cin >> b[i];
  }
  s1 = s2 = 0;
  e1 = k1;
  e2 = k2;
  int cnt = 0;
  while (true) {
    cnt++;
    v = cantor() * 10 + e1 - s1;
    if (k[v]) {
      cout << -1 << endl;
      return 0;
    }
    k[v] = true;
    if (a[s1] > b[s2]) {
      a[e1++] = b[s2];
      a[e1++] = a[s1];
    } else {
      b[e2++] = a[s1];
      b[e2++] = b[s2];
    }
    s1++;
    s2++;
    if (s1 == e1) {
      cout << cnt << ' ' << 2 << endl;
      return 0;
    }
    if (s2 == e2) {
      cout << cnt << ' ' << 1 << endl;
      return 0;
    }
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:

  * Elements of the main diagonal.
  * Elements of the secondary diagonal.
  * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
  * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.

<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.

Help the Smart Beaver count the sum of good elements of the given matrix.

Input

The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.

The input limitations for getting 30 points are:

  * 1 ≤ n ≤ 5

The input limitations for getting 100 points are:

  * 1 ≤ n ≤ 101

Output

Print a single integer — the sum of good matrix elements.

Examples

Input

3
1 2 3
4 5 6
7 8 9

Output

45

Input

5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

Output

17

Note

In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[100 + 13][100 + 13], b[100 + 13][100 + 13], sum;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    b[i][i]++;
    b[i][n - i - 1]++;
  }
  for (int i = 0; i < n; i++) {
    b[n / 2][i]++;
    b[i][n / 2]++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (b[i][j] > 0) {
        sum += a[i][j];
      }
    }
  }
  cout << sum << endl;
}

```


### Prompt

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

You are given a tree consisting of n vertices (numbered from 1 to n). Initially all vertices are white. You have to process q queries of two different types:

  1. 1 x — change the color of vertex x to black. It is guaranteed that the first query will be of this type.
  2. 2 x — for the vertex x, find the minimum index y such that the vertex with index y belongs to the simple path from x to some black vertex (a simple path never visits any vertex more than once).

For each query of type 2 print the answer to it.

Note that the queries are given in modified way.

Input

The first line contains two numbers n and q (3 ≤ n, q ≤ 106).

Then n - 1 lines follow, each line containing two numbers xi and yi (1 ≤ xi < yi ≤ n) and representing the edge between vertices xi and yi.

It is guaranteed that these edges form a tree.

Then q lines follow. Each line contains two integers ti and zi, where ti is the type of ith query, and zi can be used to restore xi for this query in this way: you have to keep track of the answer to the last query of type 2 (let's call this answer last, and initially last = 0); then xi = (zi + last) mod n + 1.

It is guaranteed that the first query is of type 1, and there is at least one query of type 2.

Output

For each query of type 2 output the answer to it.

Example

Input

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

Output

3
2
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long b, long long e, long long mod) {
  long long ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1) ans = ans * b % mod;
  return ans;
}
const int inf = (int)1e9;
const int N = 1000005;
int dp[N], ans = inf, n, q, pai[N], vis[N];
vector<int> g[N];
void dfs(int x, int p = -1) {
  if (p == -1)
    dp[x] = x;
  else
    dp[x] = min(x, dp[p]);
  for (auto w : g[x]) {
    if (w != p) dfs(w, x), pai[w] = x;
  }
}
int32_t main() {
  for (int i = 0; i < (N); ++i) dp[i] = inf;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int last = 0;
  bool jf = false;
  while (q--) {
    int t, x;
    scanf("%d%d", &t, &x);
    if (t == 1) {
      if (jf == 0) {
        jf = 1;
        x = (x + last) % n + 1;
        dfs(x);
      } else {
        x = (x + last) % n + 1;
        while (x && !vis[x]) {
          vis[x] = true;
          ans = min(ans, x);
          x = pai[x];
        }
      }
    } else {
      x = (x + last) % n + 1;
      printf("%d\n", (last = min(dp[x], ans)));
    }
  }
}

```


### Prompt

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

Squid loves painting vertices in graphs.

There is a simple undirected graph consisting of N vertices numbered 1 through N, and M edges. Initially, all the vertices are painted in color 0. The i-th edge bidirectionally connects two vertices a_i and b_i. The length of every edge is 1.

Squid performed Q operations on this graph. In the i-th operation, he repaints all the vertices within a distance of d_i from vertex v_i, in color c_i.

Find the color of each vertex after the Q operations.

Constraints

* 1 ≤ N,M,Q ≤ 10^5
* 1 ≤ a_i,b_i,v_i ≤ N
* a_i ≠ b_i
* 0 ≤ d_i ≤ 10
* 1 ≤ c_i ≤10^5
* d_i and c_i are all integers.
* There are no self-loops or multiple edges in the given graph.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
:
a_{M} b_{M}
Q
v_1 d_1 c_1
:
v_{Q} d_{Q} c_{Q}

Output

Print the answer in N lines. In the i-th line, print the color of vertex i after the Q operations.

Examples

Input

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

Output

2
2
2
2
2
1
0

Input

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

Output

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

### Response

```cpp
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y,w;
}a[500001];
int n,m,t1,tot,ans[500001],mx[500001],e[500001],nt[500001],hd[500001];
void dfs(int x,int dep,int w){
	if(mx[x]>=dep)return;
	mx[x]=dep;
	if(!ans[x])ans[x]=w;
	if(!w)return;
	int i;
	for(i=hd[x];i;i=nt[i])dfs(e[i],dep-1,w);
}
void build(int x,int y){
	tot++;
	e[tot]=y;
	nt[tot]=hd[x];hd[x]=tot;
}
int main(){
	int i,x,y;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)mx[i]=-1;
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		build(x,y);build(y,x);
	}
	scanf("%d",&t1);
	for(i=1;i<=t1;i++)
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
	for(i=t1;i;i--)dfs(a[i].x,a[i].y,a[i].w);
	for(i=1;i<=n;i++)printf("%d\n",ans[i]);
}
```


### Prompt

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

Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.

Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!

Input

The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers the array has. The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the array elements.

Output

Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.

If there are multiple answers, you are allowed to print any of them.

Examples

Input

3
2 2 4

Output

2

Input

5
2 1 3 1 6

Output

1

Input

3
2 3 5

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int min;
  int n, a[100001];
  bool ans = true;
  scanf("%d", &n);
  scanf("%d", &a[0]);
  min = a[0];
  for (int i = 1; i < n; i++) {
    scanf("%d", &a[i]);
    if (min > a[i]) min = a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] % min != 0) {
      ans = false;
      break;
    }
  }
  if (ans)
    printf("%d\n", min);
  else
    printf("-1\n");
}

```


### Prompt

Please formulate a cpp solution to the following problem:

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

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

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

Input

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

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

Output

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

Examples

Input

4
3 1 4 1

Output

3

Input

3
1 1 1

Output

1

Input

5
1 1 1 2 2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::string;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  std::vector<int> a(n);
  for (int& x : a) {
    cin >> x;
  }
  std::sort(a.begin(), a.end());
  int days = 0;
  int i = 0;
  for (; i < n; i++) {
    while (i < n && a[i] <= days) {
      i++;
    }
    if (i == n) {
      break;
    }
    days++;
  }
  cout << days << "\n";
  return 0;
}

```


### Prompt

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

Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at the points (x0, y0, z0), (x1, y1, z1), ..., (xn, yn, zn). At the beginning of the game the snitch is positioned at the point (x0, y0, z0), and then moves along the polyline at the constant speed vs. The twins have not yet found out how the snitch behaves then. Nevertheless, they hope that the retrieved information will help Harry Potter and his team in the upcoming match against Slytherin. Harry Potter learned that at the beginning the game he will be at the point (Px, Py, Pz) and his super fast Nimbus 2011 broom allows him to move at the constant speed vp in any direction or remain idle. vp is not less than the speed of the snitch vs. Harry Potter, of course, wants to catch the snitch as soon as possible. Or, if catching the snitch while it is moving along the polyline is impossible, he wants to hurry the Weasley brothers with their experiments. Harry Potter catches the snitch at the time when they are at the same point. Help Harry.

Input

The first line contains a single integer n (1 ≤ n ≤ 10000). The following n + 1 lines contain the coordinates xi, yi, zi, separated by single spaces. The coordinates of any two consecutive points do not coincide. The next line contains the velocities vp and vs, the last line contains Px, Py, Pz, separated by single spaces. All the numbers in the input are integers, their absolute value does not exceed 104. The speeds are strictly positive. It is guaranteed that vs ≤ vp.

Output

If Harry Potter can catch the snitch while it is moving along the polyline (including the end (xn, yn, zn)), print "YES" in the first line (without the quotes). Print in the second line t, which is the earliest moment of time, when Harry will be able to catch the snitch. On the third line print three numbers X, Y, Z, the coordinates of the point at which this happens. The absolute or relative error in the answer should not exceed 10 - 6. If Harry is not able to catch the snitch during its moving along the described polyline, print "NO".

Examples

Input

4
0 0 0
0 10 0
10 10 0
10 0 0
0 0 0
1 1
5 5 25

Output

YES
25.5000000000
10.0000000000 4.5000000000 0.0000000000

Input

4
0 0 0
0 10 0
10 10 0
10 0 0
0 0 0
1 1
5 5 50

Output

NO

Input

1
1 2 3
4 5 6
20 10
1 2 3

Output

YES
0.0000000000
1.0000000000 2.0000000000 3.0000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long double epsilon = 1e-9;
bool isEq(pair<long double, pair<long double, long double> > x,
          pair<long double, pair<long double, long double> > y) {
  long double x1, x2, y1, y2, z1, z2;
  x1 = x.first;
  x2 = y.first;
  y1 = x.second.first;
  y2 = y.second.first;
  z1 = x.second.second;
  z2 = y.second.second;
  long double temp1 = fabs(x2 - x1);
  long double temp2 = fabs(y2 - y1);
  long double temp3 = fabs(z2 - z1);
  if (temp1 < epsilon && temp2 < epsilon && temp3 < epsilon) return true;
  return false;
}
long double dist(pair<long double, pair<long double, long double> > x,
                 pair<long double, pair<long double, long double> > y) {
  long double dsx = x.first - y.first;
  long double dsy = x.second.first - y.second.first;
  long double dsz = x.second.second - y.second.second;
  long double ds = sqrt(dsx * dsx + dsy * dsy + dsz * dsz);
  return ds;
}
bool check(pair<long double, pair<long double, long double> > x,
           pair<long double, pair<long double, long double> > y,
           pair<long double, pair<long double, long double> > z, int v, int u,
           long double t) {
  long double ds = dist(x, y);
  long double dp = dist(x, z);
  long double ts = ds / v;
  long double tp = dp / u;
  if (tp <= ts + t) return true;
  return false;
}
pair<long double, pair<long double, long double> > bs(
    pair<int, pair<int, int> > x, pair<int, pair<int, int> > y,
    pair<int, pair<int, int> > z, int v, int u, long double t) {
  pair<long double, pair<long double, long double> > st, ed;
  pair<long double, pair<long double, long double> > mid;
  st = x;
  ed = y;
  mid.first = ((ed.first - st.first) / ((long double)2)) + st.first;
  mid.second.first = ((ed.second.first - st.second.first) / ((long double)2)) +
                     st.second.first;
  mid.second.second =
      ((ed.second.second - st.second.second) / ((long double)2)) +
      st.second.second;
  while (!isEq(st, ed)) {
    if (check(mid, x, z, v, u, t)) {
      ed = mid;
    } else
      st = mid;
    mid.first = ((ed.first - st.first) / ((long double)2)) + st.first;
    mid.second.first =
        ((ed.second.first - st.second.first) / ((long double)2)) +
        st.second.first;
    mid.second.second =
        ((ed.second.second - st.second.second) / ((long double)2)) +
        st.second.second;
  }
  return mid;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    pair<int, pair<int, int> > a[n + 2];
    for (int i = 0; i <= n; i++) {
      cin >> a[i].first >> a[i].second.first >> a[i].second.second;
    }
    int vp, vs;
    cin >> vp >> vs;
    pair<int, pair<int, int> > p;
    cin >> p.first >> p.second.first >> p.second.second;
    long double time = 0;
    pair<long double, pair<long double, long double> > ans;
    bool chk = 0;
    for (int i = 0; i < n; i++) {
      if (check(a[i + 1], a[i], p, vs, vp, time)) {
        ans = bs(a[i], a[i + 1], p, vs, vp, time);
        chk = true;
        break;
      }
      time += (dist(a[i + 1], a[i]) / vs);
    }
    if (!chk) {
      cout << "NO" << '\n';
    } else {
      cout << "YES" << '\n';
      cout << setprecision(10) << fixed << (dist(ans, p) / vp) << '\n';
      cout << setprecision(10) << fixed << ans.first << " " << ans.second.first
           << " " << ans.second.second << '\n';
    }
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces.

Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, the treasure cannot be found only by a part of the treasure map that points to the location of the treasure. Therefore, all the descendants of Mr. Yao gathered and tried to collect the map in one place. However, even if I tried to put it into practice, I couldn't get together because I couldn't meet the schedule. However, this information about the treasure is valuable information that has been secretly passed down in the clan. Considering the risk of leakage, exchanging maps using public communication means is out of the question.

Therefore, I decided to collect the map for one descendant by repeating the process of meeting the descendants in person and handing over the map. There is no limit to the number of people that one person can meet in a day, but it is necessary that there is a schedule for each other.

Your job is to write a program that asks for at least how many days it will take to collect a map from a list of open days on schedule for each offspring.

By the way, the unity of the Yao clan is very tight. If the descendants who finally get the entire map betray the other descendants and take away the treasure, they will be sanctioned by the clan. The sanctions are so horrifying that it is virtually impossible for their descendants to actually carry away the treasure.

Input

The input consists of multiple datasets.

Each dataset consists of multiple rows. The first line contains the integer n (1 <n <= 50), which represents the number of people with a piece of the map. The next n lines contain the schedule for each descendant. Line i represents the schedule of the i-th descendant, with some integers separated by a single character space. The first integer fi (0 <= fi <= 30) is an integer that represents the number of days that the descendant's schedule is free. The following fi integers represent dates when the schedule is free. These dates differ from each other and are all greater than or equal to 1 and less than or equal to 30.

There is one line containing only 0 at the end of the input.

Output

Print one integer on one line for each dataset. If you can collect the map within 30 days, output the minimum number of days required to collect the map, otherwise output -1.

Addendum: The above "minimum number of days required to collect maps" means the date when all maps are collected earliest starting from one day.

Example

Input

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

Output

3

### Response

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

bool data[55][31];
int N;

int main() {

  while(cin >> N && N) {
    memset(data, false, sizeof data);
    for(int i=0; i<N; i++) {
      int k; cin >> k;
      while(k--) {
	int h; cin >> h; data[i][h] = true;
      }
    }

    bool flag = false;
    set<int> st[51];
    for(int i=0; i<N; i++) {
      st[i].insert(i);
    }

    for(int i=1; i<31; i++) {
      for(int j=0; j<N; j++) {
	if(!data[j][i]) continue;
	for(int k=j+1; k<N; k++) {
	  if(!data[k][i]) continue;
	  set<int>::iterator it = st[k].begin();
	  for(; it!=st[k].end(); it++) {
	    st[j].insert(*it);
	  }
	  st[k] = st[j];
	}

	if(st[j].size() == N) {
	  cout << i << endl;
	  flag = true;
	  goto EXIT;
	}
      }
    }

  EXIT:;
    if(!flag) cout << -1 << endl;
  }

  return 0;
}
```


### Prompt

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

You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they are not interesting. You want to produce a dataset whose answer is a desired value such as the number representing this year 2010. So you will tweak (which means 'adjust') the cost of the minimum cost path to a given value by changing the costs of some edges. The number of changes should be made as few as possible.

A non-negative integer c and a directed graph G are given. Each edge of G is associated with a cost of a non-negative integer. Given a path from one node of G to another, we can define the cost of the path as the sum of the costs of edges constituting the path. Given a pair of nodes in G, we can associate it with a non-negative cost which is the minimum of the costs of paths connecting them.

Given a graph and a pair of nodes in it, you are asked to adjust the costs of edges so that the minimum cost path from one node to the other will be the given target cost c. You can assume that c is smaller than the cost of the minimum cost path between the given nodes in the original graph.

For example, in Figure G.1, the minimum cost of the path from node 1 to node 3 in the given graph is 6. In order to adjust this minimum cost to 2, we can change the cost of the edge from node 1 to node 3 to 2. This direct edge becomes the minimum cost path after the change.

For another example, in Figure G.2, the minimum cost of the path from node 1 to node 12 in the given graph is 4022. In order to adjust this minimum cost to 2010, we can change the cost of the edge from node 6 to node 12 and one of the six edges in the right half of the graph. There are many possibilities of edge modification, but the minimum number of modified edges is 2.

Input

The input is a sequence of datasets. Each dataset is formatted as follows.

n m c
f1 t1 c1
f2 t2 c2
.
.
.
fm tm cm

<image> | <image>
---|---

Figure G.1: Example 1 of graph

|

Figure G.2: Example 2 of graph

The integers n, m and c are the number of the nodes, the number of the edges, and the target cost, respectively, each separated by a single space, where 2 ≤ n ≤ 100, 1 ≤ m ≤ 1000 and 0 ≤ c ≤ 100000.

Each node in the graph is represented by an integer 1 through n.

The following m lines represent edges: the integers fi, ti and ci (1 ≤ i ≤ m) are the originating node, the destination node and the associated cost of the i-th edge, each separated by a single space. They satisfy 1 ≤ fi, ti ≤ n and 0 ≤ ci ≤ 10000. You can assume that fi ≠ ti and (fi, ti) ≠ (fj, tj) when i ≠ j.

You can assume that, for each dataset, there is at least one path from node 1 to node n, and that the cost of the minimum cost path from node 1 to node n of the given graph is greater than c.

The end of the input is indicated by a line containing three zeros separated by single spaces.

Output

For each dataset, output a line containing the minimum number of edges whose cost(s) should be changed in order to make the cost of the minimum cost path from node 1 to node n equal to the target cost c. Costs of edges cannot be made negative. The output should not contain any other extra characters.

Example

Input

3 3 3
1 2 3
2 3 3
1 3 8
12 12 2010
1 2 0
2 3 3000
3 4 0
4 5 3000
5 6 3000
6 12 2010
2 7 100
7 8 200
8 9 300
9 10 400
10 11 500
11 6 512
10 18 1
1 2 9
1 3 2
1 4 6
2 5 0
2 6 10
2 7 2
3 5 10
3 6 3
3 7 10
4 7 6
5 8 10
6 8 2
6 9 11
7 9 3
8 9 9
8 10 8
9 10 1
8 2 1
0 0 0

Output

1
2
3

### Response

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

using namespace std;

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int g[100][100];
bool memo[100][1000];

typedef pair<int, pair<int, int> > data;
inline data makedata(int a, int b, int c){ return make_pair(a, make_pair(b, c)); }
inline int elim(data d){ return d.f; }
inline int cost(data d){ return d.s.f; }
inline int pos(data d){ return d.s.s; }

int main(){
  int n, m, c;
  while(scanf("%d%d%d", &n, &m, &c), n + m + c){
    REP(i,n) REP(j,n) g[i][j] = -1;
    REP(i,n) REP(j,m) memo[i][j] = false;

    REP(i,m){
      int a, b, d;
      scanf("%d%d%d", &a, &b, &d);
      g[a - 1][b - 1] = d;
    }

    priority_queue<data, vector<data>, greater<data> > pq;
    pq.push(makedata(0, 0, 0));

    while(pq.size()){
      data d = pq.top(); pq.pop();
      int ee = elim(d);
      int cc = cost(d);
      int pp = pos(d);

      if(memo[pp][ee]) continue;
      memo[pp][ee] = true;

      if(pp == n - 1 && cc <= c){
        printf("%d\n", ee);
        break;
      }

      REP(i,n) if(g[pp][i] >= 0){
        if(!memo[i][ee + 1]) pq.push(makedata(ee + 1, cc, i));
        if(!memo[i][ee])     pq.push(makedata(ee, cc + g[pp][i], i));
      }
    }
  }
  return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.

b4ab979900ed647703389d4349eb84ee.png

Constraints

* x and y are integers.
* 1 ≤ x < y ≤ 12

Input

Input is given from Standard Input in the following format:

x y

Output

If x and y belong to the same group, print `Yes`; otherwise, print `No`.

Examples

Input

1 3

Output

Yes

Input

2 4

Output

No

### Response

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

int main() {
  int x, y;
  string a = "0131212112121";
  cin >> x >> y;
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}
```


### Prompt

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

Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:

  * Four sticks represent the animal's legs, these sticks should have the same length.
  * Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.

Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.

Input

The single line contains six space-separated integers li (1 ≤ li ≤ 9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.

Output

If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).

Examples

Input

4 2 5 4 4 4

Output

Bear

Input

4 4 5 4 4 5

Output

Elephant

Input

1 2 3 4 5 6

Output

Alien

Note

If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.

<image>

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int max = 0, min = 7, i, m[10] = {0}, a;
  for (i = 0; i < 6; i++) {
    scanf("%d", &a);
    m[a]++;
  }
  for (i = 0; i < 10; i++) {
    if (m[i] == 0) continue;
    if (m[i] > max) max = m[i];
    if (m[i] < min) min = m[i];
  }
  if (max > 3) {
    if (max == 6 || min == 2)
      printf("Elephant");
    else
      printf("Bear");
  } else
    printf("Alien");
  return 0;
}

```


### Prompt

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

After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.

The potato pie is located in the n-th room and Vitaly needs to go there.

Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key.

In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.

Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.

Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.

Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number.

Input

The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house.

The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one.

The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2.

The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1.

Output

Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n.

Examples

Input

3
aAbB

Output

0

Input

4
aBaCaB

Output

3

Input

5
xYyXzZaZ

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string str;
  cin >> n;
  cin >> str;
  map<char, int> mp;
  int ans = 0;
  for (int i = 0; i < 2 * n - 1; ++i) {
    if (isupper(str[i])) {
      char ch = tolower(str[i]);
      if (mp[ch] == 0) {
        ans += 1;
      } else
        mp[ch]--;
    } else
      mp[str[i]]++;
  }
  cout << ans;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.

Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk.

In the initial moment of time all Packmen begin to move. Each Packman can change direction of its move unlimited number of times, but it is not allowed to go beyond the boundaries of the game field. Packmen do not interfere with the movement of other packmen; in one cell there can be any number of packmen moving in any directions.

Your task is to determine minimum possible time after which Packmen can eat all the asterisks.

Input

The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field.

The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is symbol 'P' in position i — Packman is in the cell i.

It is guaranteed that on the game field there is at least one Packman and at least one asterisk.

Output

Print minimum possible time after which Packmen can eat all asterisks.

Examples

Input

7
*..P*P*

Output

3

Input

10
.**PP.*P.*

Output

2

Note

In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) and then move from the position 5 to the right and eat asterisk in the position 7 (in 2 time units). So in 3 time units Packmen will eat all asterisks on the game field.

In the second example Packman in the position 4 will move to the left and after 2 time units will eat asterisks in positions 3 and 2. Packmen in positions 5 and 8 will move to the right and in 2 time units will eat asterisks in positions 7 and 10, respectively. So 2 time units is enough for Packmen to eat all asterisks on the game field.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool qry(vector<int>& a, vector<int>& b, int k) {
  int t = 0;
  for (int i = 0; i < a.size(); i++) {
    if (t == b.size() || b[t] - a[i] > k) continue;
    if (a[i] - b[t] > k) return 0;
    int j =
        (a[i] > b[t] ? max((k - a[i] + b[t]) / 2 + a[i], k - a[i] + 2 * b[t])
                     : k + a[i]);
    t = upper_bound(b.begin(), b.end(), j) - b.begin();
  }
  return (t == b.size());
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    if (s[i] == '*')
      b.push_back(i);
    else if (s[i] == 'P')
      a.push_back(i);
  }
  int l = 1, r = n + n / 2 + 1;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (qry(a, b, mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?

Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.

Constraints

* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the answer.

Examples

Input

3
1 1
2 4
3 2

Output

4

Input

2
1 1
1 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = (1LL << 62);

int main()
{
  int64_t N, x, y;
  cin >> N;
  int64_t mis = INF, mas = -INF, mid = INF, mad = -INF;
  for (int i = 0; i < N; i++)
  {
    cin >> x >> y;
    mis = min(mis, x + y);
    mas = max(mas, x + y);
    mid = min(mid, x - y);
    mad = max(mad, x - y);
  }
  cout << max(mas - mis, mad - mid) << endl;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

There is an airplane which has n rows from front to back. There will be m people boarding this airplane.

This airplane has an entrance at the very front and very back of the plane.

Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the plane one by one starting with person 1. Each person can independently choose either the front entrance or back entrance to enter the plane.

When a person walks into the plane, they walk directly to their assigned seat and will try to sit in it. If it is occupied, they will continue walking in the direction they walked in until they are at empty seat - they will take the earliest empty seat that they can find. If they get to the end of the row without finding a seat, they will be angry.

Find the number of ways to assign tickets to the passengers and board the plane without anyone getting angry. Two ways are different if there exists a passenger who chose a different entrance in both ways, or the assigned seat is different. Print this count modulo 109 + 7.

Input

The first line of input will contain two integers n, m (1 ≤ m ≤ n ≤ 1 000 000), the number of seats, and the number of passengers, respectively.

Output

Print a single number, the number of ways, modulo 109 + 7.

Example

Input

3 3

Output

128

Note

Here, we will denote a passenger by which seat they were assigned, and which side they came from (either "F" or "B" for front or back, respectively).

For example, one valid way is 3B, 3B, 3B (i.e. all passengers were assigned seat 3 and came from the back entrance). Another valid way would be 2F, 1B, 3F.

One invalid way would be 2B, 2B, 2B, since the third passenger would get to the front without finding a seat.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long ksm(long long a, long long b) {
  long long x = 1;
  while (b != 0) {
    if (b & 1) {
      x *= a;
      x %= mod;
    }
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return x;
}
int n, m;
int main() {
  cin >> n >> m;
  long long ans = ksm(2 * n + 2, m);
  cout << (((ans) * (n + 1 - m) + mod) % mod * ksm(n + 1, mod - 2)) % mod;
  return 0;
}

```