### Prompt

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

Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.

All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by 1. If he manages to finish the level successfully then the number of clears increases by 1 as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).

Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.

So he peeked at the stats n times and wrote down n pairs of integers — (p_1, c_1), (p_2, c_2), ..., (p_n, c_n), where p_i is the number of plays at the i-th moment of time and c_i is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).

Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.

Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.

Help him to check the correctness of his records.

For your convenience you have to answer multiple independent test cases.

Input

The first line contains a single integer T (1 ≤ T ≤ 500) — the number of test cases.

The first line of each test case contains a single integer n (1 ≤ n ≤ 100) — the number of moments of time Polycarp peeked at the stats.

Each of the next n lines contains two integers p_i and c_i (0 ≤ p_i, c_i ≤ 1000) — the number of plays and the number of clears of the level at the i-th moment of time.

Note that the stats are given in chronological order.

Output

For each test case print a single line.

If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES".

Otherwise, print "NO".

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

Example

Input

6
3
0 0
1 1
1 2
2
1 0
1000 3
4
10 1
15 2
10 2
15 2
1
765 432
2
4 4
4 3
5
0 0
1 0
1 0
1 0
1 0

Output

NO
YES
NO
YES
NO
YES

Note

In the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened.

The second test case is a nice example of a Super Expert level.

In the third test case the number of plays decreased, which is impossible.

The fourth test case is probably an auto level with a single jump over the spike.

In the fifth test case the number of clears decreased, which is also impossible.

Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  int n;
  cin >> t;
  int arr[107], brr[107];
  while (t--) {
    cin >> n;
    int flag = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i] >> brr[i];
    }
    if (n == 1) {
      if (arr[0] >= brr[0]) {
        flag = 1;
        cout << "YES" << endl;
        continue;
      } else {
        cout << "NO" << endl;
        flag = 1;
        continue;
      }
    }
    if (arr[0] < brr[0]) {
      cout << "NO" << endl;
      flag = 1;
      continue;
    }
    for (int i = 1; i < n; i++) {
      if (((arr[i] - arr[i - 1]) < (brr[i] - brr[i - 1])) ||
          (arr[i] < arr[i - 1]) || (brr[i] < brr[i - 1])) {
        flag = 1;
        cout << "NO" << endl;
        break;
      }
    }
    if (!flag) cout << "YES" << endl;
  }
  return 0;
}

```


### Prompt

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

Input

The input contains a single integer a (0 ≤ a ≤ 35).

Output

Output a single integer.

Examples

Input

3

Output

8

Input

10

Output

1024

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int factors[1010 + 10];
int main() {
  int n;
  cin >> n;
  int a[10];
  for (int i = 0; i < 6; i++) {
    a[i] = n % 2;
    n >>= 1;
  }
  swap(a[0], a[4]);
  swap(a[2], a[3]);
  int res = 0;
  for (int i = 0, pow = 1; i < 6; i++) {
    res += a[i] * pow;
    pow <<= 1;
  }
  cout << res << endl;
}

```


### Prompt

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

There are n players numbered from 0 to n-1 with ranks. The i-th player has rank i.

Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let i, j, k be the ranks of players in the team and i < j < k, then the rank of the team is equal to A ⋅ i + B ⋅ j + C ⋅ k.

You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 2^{64}.

Input

The first line contains two space-separated integers n and m (3 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ 2 ⋅ 10^5) — the number of players and the number of conflicting pairs.

The second line contains three space-separated integers A, B and C (1 ≤ A, B, C ≤ 10^6) — coefficients for team rank calculation.

Each of the next m lines contains two space-separated integers u_i and v_i (0 ≤ u_i, v_i < n, u_i ≠ v_i) — pair of conflicting players.

It's guaranteed that each unordered pair of players appears in the input file no more than once.

Output

Print single integer — the total sum of ranks over all possible teams modulo 2^{64}.

Examples

Input

4 0
2 3 4

Output

64

Input

4 1
2 3 4
1 0

Output

38

Input

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

Output

164

Note

In the first example all 4 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}.

In the second example teams are following: {0, 2, 3}, {1, 2, 3}.

In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, x[N], y[N], l[N], r[N];
unsigned long long A, B, C, ans;
vector<int> L[N], R[N];
set<pair<int, int> > st;
inline unsigned long long sum(int l, int r) {
  return (unsigned long long)(l + r) * (r - l + 1) / 2;
}
int main() {
  scanf("%d%d%llu%llu%llu", &n, &m, &A, &B, &C);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    if (x[i] > y[i]) swap(x[i], y[i]);
    st.insert(make_pair(x[i], y[i]));
    R[x[i]].push_back(y[i]);
    L[y[i]].push_back(x[i]);
  }
  for (int i = 0; i < n; i++)
    sort(L[i].begin(), L[i].end()), sort(R[i].begin(), R[i].end());
  for (int i = 0; i < n; i++)
    ans += (unsigned long long)(n - i - 1) * (n - i - 2) / 2 * A * i;
  for (int i = 0; i < n; i++)
    ans += (unsigned long long)i * (n - i - 1) * B * i;
  for (int i = 0; i < n; i++)
    ans += (unsigned long long)i * (i - 1) / 2 * C * i;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < R[i].size(); j++) {
      int k = n - R[i][j] - 1;
      if (k < 0) continue;
      ans -= A * i * k + B * R[i][j] * k + C * sum(R[i][j] + 1, n - 1);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < R[i].size(); j++) {
      int k = i;
      if (k < 0) continue;
      ans -= B * i * k + C * R[i][j] * k + A * sum(0, i - 1);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < R[i].size(); j++) {
      int k = R[i][j] - i - 1;
      if (k < 0) continue;
      ans -= A * i * k + C * R[i][j] * k + B * sum(i + 1, R[i][j] - 1);
    }
  for (int i = 0; i < n; i++) {
    ans += (unsigned long long)R[i].size() * (R[i].size() - 1) / 2 * A * i;
    for (int j = 0; j < R[i].size(); j++)
      ans += B * R[i][j] * (R[i].size() - j - 1) + C * R[i][j] * j;
  }
  for (int i = 0; i < n; i++) {
    ans += (unsigned long long)L[i].size() * R[i].size() * B * i;
    for (int j = 0; j < L[i].size(); j++) ans += A * L[i][j] * R[i].size();
    for (int j = 0; j < R[i].size(); j++) ans += C * R[i][j] * L[i].size();
  }
  for (int i = 0; i < n; i++) {
    ans += (unsigned long long)L[i].size() * (L[i].size() - 1) / 2 * C * i;
    for (int j = 0; j < L[i].size(); j++)
      ans += B * L[i][j] * j + A * L[i][j] * (L[i].size() - j - 1);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < L[i].size(); j++) l[L[i][j]] = 1;
    for (int j = 0; j < R[i].size(); j++) r[R[i][j]] = 1;
    if ((unsigned long long)L[i].size() * R[i].size() * 20 <= m) {
      for (int j = 0; j < L[i].size(); j++)
        for (int k = 0; k < R[i].size(); k++)
          if (st.count(make_pair(L[i][j], R[i][k])))
            ans -= A * L[i][j] + B * i + C * R[i][k];
    } else
      for (int j = 0; j < m; j++)
        if (l[x[j]] && r[y[j]]) ans -= A * x[j] + B * i + C * y[j];
    for (int j = 0; j < L[i].size(); j++) l[L[i][j]] = 0;
    for (int j = 0; j < R[i].size(); j++) r[R[i][j]] = 0;
  }
  printf("%llu\n", ans);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree?

Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wanted to see if similar techniques in trees can be used in 1-trees as well. Instead of solving it by himself, he's going to test you by providing queries on 1-trees.

First, he'll provide you a tree (not 1-tree) with n vertices, then he will ask you q queries. Each query contains 5 integers: x, y, a, b, and k. This means you're asked to determine if there exists a path from vertex a to b that contains exactly k edges after adding a bidirectional edge between vertices x and y. A path can contain the same vertices and same edges multiple times. All queries are independent of each other; i.e. the added edge in a query is removed in the next query.

Input

The first line contains an integer n (3 ≤ n ≤ 10^5), the number of vertices of the tree.

Next n-1 lines contain two integers u and v (1 ≤ u,v ≤ n, u ≠ v) each, which means there is an edge between vertex u and v. All edges are bidirectional and distinct.

Next line contains an integer q (1 ≤ q ≤ 10^5), the number of queries Gildong wants to ask.

Next q lines contain five integers x, y, a, b, and k each (1 ≤ x,y,a,b ≤ n, x ≠ y, 1 ≤ k ≤ 10^9) – the integers explained in the description. It is guaranteed that the edge between x and y does not exist in the original tree.

Output

For each query, print "YES" if there exists a path that contains exactly k edges from vertex a to b after adding an edge between vertices x and y. Otherwise, print "NO".

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

Example

Input

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

Output

YES
YES
NO
YES
NO

Note

The image below describes the tree (circles and solid lines) and the added edges for each query (dotted lines).

<image>

Possible paths for the queries with "YES" answers are:

  * 1-st query: 1 – 3 – 2
  * 2-nd query: 1 – 2 – 3
  * 4-th query: 3 – 4 – 2 – 3 – 4 – 2 – 3 – 4 – 2 – 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct A {
  int nod, nvl;
};
queue<int> q;
vector<int> v[100005], rmq[18];
A Repr_Euler[200005];
int nr;
int nivel[100005], prima_aparitie[100005];
void nivelare();
void dfs(int nod);
int distanta(int nod1, int nod2);
int main() {
  int n, i, j, q, x, y, a, b, k, D1, D2, D3;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  nivelare();
  dfs(1);
  n = 2 * n - 1;
  x = log2(n);
  for (i = 1; i <= n; i++) rmq[0].push_back(Repr_Euler[i].nvl);
  for (i = 1; i <= x; i++)
    for (j = 0; j < n - (1 << i) + 1; j++)
      rmq[i].push_back(min(rmq[i - 1][j], rmq[i - 1][j + (1 << (i - 1))]));
  cin >> q;
  while (q--) {
    cin >> x >> y >> a >> b >> k;
    D1 = distanta(a, b);
    D2 = 1 + distanta(a, x) + distanta(y, b);
    D3 = 1 + distanta(a, y) + distanta(x, b);
    if (D1 <= k && D1 % 2 == k % 2)
      cout << "YES" << '\n';
    else if (D2 <= k && D2 % 2 == k % 2)
      cout << "YES" << '\n';
    else if (D3 <= k && D3 % 2 == k % 2)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}
void nivelare() {
  int x, i;
  nivel[1] = 1;
  q.push(1);
  while (q.empty() == 0) {
    x = q.front();
    q.pop();
    for (i = 0; i < v[x].size(); i++)
      if (nivel[v[x][i]] == 0) {
        nivel[v[x][i]] = nivel[x] + 1;
        q.push(v[x][i]);
      }
  }
}
void dfs(int nod) {
  int i;
  for (i = 0; i < v[nod].size(); i++)
    if (nivel[nod] == nivel[v[nod][i]] - 1) {
      Repr_Euler[++nr].nod = nod;
      Repr_Euler[nr].nvl = nivel[nod];
      if (prima_aparitie[nod] == 0) prima_aparitie[nod] = nr;
      dfs(v[nod][i]);
    }
  Repr_Euler[++nr].nod = nod;
  Repr_Euler[nr].nvl = nivel[nod];
  if (prima_aparitie[nod] == 0) prima_aparitie[nod] = nr;
}
int distanta(int nod1, int nod2) {
  int st, dr, x, val, a, b;
  st = prima_aparitie[nod1] - 1;
  dr = prima_aparitie[nod2] - 1;
  if (st > dr) swap(st, dr);
  x = log2(dr - st + 1);
  a = rmq[x][st];
  b = rmq[x][dr - (1 << x) + 1];
  val = min(rmq[x][st], rmq[x][dr - (1 << x) + 1]);
  return nivel[nod1] + nivel[nod2] - 2 * val;
}

```


### Prompt

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

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is ai meters high.

Vladimir has just planted n bamboos in a row, each of which has height 0 meters right now, but they grow 1 meter each day. In order to make the partition nice Vladimir can cut each bamboo once at any height (no greater that the height of the bamboo), and then the bamboo will stop growing.

Vladimir wants to check the bamboos each d days (i.e. d days after he planted, then after 2d days and so on), and cut the bamboos that reached the required height. Vladimir wants the total length of bamboo parts he will cut off to be no greater than k meters.

What is the maximum value d he can choose so that he can achieve what he wants without cutting off more than k meters of bamboo?

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1011) — the number of bamboos and the maximum total length of cut parts, in meters.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the required heights of bamboos, in meters.

Output

Print a single integer — the maximum value of d such that Vladimir can reach his goal.

Examples

Input

3 4
1 3 5

Output

3

Input

3 40
10 30 50

Output

32

Note

In the first example Vladimir can check bamboos each 3 days. Then he will cut the first and the second bamboos after 3 days, and the third bamboo after 6 days. The total length of cut parts is 2 + 0 + 1 = 3 meters.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[109];
  set<int> s;
  long long k;
  scanf("%d", &n);
  scanf("%lld", &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    k += a[i];
    for (int j = 1; j * j <= a[i]; j++) {
      s.insert(j);
      s.insert(ceil(a[i] * 1.0 / j));
    }
  }
  long long ans = 1;
  for (auto it : s) {
    long long sum = 0;
    for (int i = 0; i < n; i++) sum += ceil(a[i] * 1.0 / it);
    if (it <= k / sum) ans = max(ans, k / sum);
  }
  printf("%lld\n", ans);
}

```


### Prompt

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

There are n people in a row. The height of the i-th person is a_i. You can choose any subset of these people and try to arrange them into a balanced circle.

A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than 1. For example, let heights of chosen people be [a_{i_1}, a_{i_2}, ..., a_{i_k}], where k is the number of people you choose. Then the condition |a_{i_j} - a_{i_{j + 1}}| ≤ 1 should be satisfied for all j from 1 to k-1 and the condition |a_{i_1} - a_{i_k}| ≤ 1 should be also satisfied. |x| means the absolute value of x. It is obvious that the circle consisting of one person is balanced.

Your task is to choose the maximum number of people and construct a balanced circle consisting of all chosen people. It is obvious that the circle consisting of one person is balanced so the answer always exists.

Input

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

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5), where a_i is the height of the i-th person.

Output

In the first line of the output print k — the number of people in the maximum balanced circle.

In the second line print k integers res_1, res_2, ..., res_k, where res_j is the height of the j-th person in the maximum balanced circle. The condition |res_{j} - res_{j + 1}| ≤ 1 should be satisfied for all j from 1 to k-1 and the condition |res_{1} - res_{k}| ≤ 1 should be also satisfied.

Examples

Input

7
4 3 5 1 2 2 1

Output

5
2 1 1 2 3

Input

5
3 7 5 1 5

Output

2
5 5

Input

3
5 1 4

Output

2
4 5

Input

7
2 2 3 2 1 2 2

Output

7
1 2 2 2 2 3 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 2e5;
int n, a[MAXN], f[MAXN], m, ans = 1 + 1e9, cnt, b[MAXN], l = 1, r = 1, lp = 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ++f[a[i]];
  }
  sort(a + 1, a + n + 1);
  cnt = 0;
  for (int i = 1; i <= n; ++i) {
    ans = min(ans, f[a[i]]);
    if (a[i] != a[i - 1]) b[++m] = a[i];
  }
  int j = 1;
  l = 1;
  r = 1;
  lp = 1;
  cnt = 0;
  while (j <= m + 1) {
    if (b[j] - b[j - 1] == 1) {
      cnt += f[b[j]];
      if (f[b[j]] == 1 && j != lp) {
        if (ans <= cnt) {
          ans = cnt;
          r = j;
          l = lp;
        }
        if (b[j] + 1 == b[j + 1]) {
          lp = j;
          cnt = f[b[j]];
          ++j;
        } else {
          lp = j + 1;
          cnt = f[b[j + 1]];
          j += 2;
        }
      } else
        ++j;
    } else {
      if (ans <= cnt) {
        ans = cnt;
        l = lp;
        r = j - 1;
      }
      cnt = f[b[j]];
      lp = j;
      ++j;
    }
  }
  cout << ans << '\n';
  for (int i = l; i <= r; ++i) {
    cout << b[i] << ' ';
    --f[b[i]];
  }
  for (int i = r; i >= l; --i) {
    while (f[b[i]]--) cout << b[i] << ' ';
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given an array a of length n.

You are also given a set of distinct positions p_1, p_2, ..., p_m, where 1 ≤ p_i < n. The position p_i means that you can swap elements a[p_i] and a[p_i + 1]. You can apply this operation any number of times for each of the given positions.

Your task is to determine if it is possible to sort the initial array in non-decreasing order (a_1 ≤ a_2 ≤ ... ≤ a_n) using only allowed swaps.

For example, if a = [3, 2, 1] and p = [1, 2], then we can first swap elements a[2] and a[3] (because position 2 is contained in the given set p). We get the array a = [3, 1, 2]. Then we swap a[1] and a[2] (position 1 is also contained in p). We get the array a = [1, 3, 2]. Finally, we swap a[2] and a[3] again and get the array a = [1, 2, 3], sorted in non-decreasing order.

You can see that if a = [4, 1, 2, 3] and p = [3, 2] then you cannot sort the array.

You have to answer t independent test cases.

Input

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

Then t test cases follow. The first line of each test case contains two integers n and m (1 ≤ m < n ≤ 100) — the number of elements in a and the number of elements in p. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100). The third line of the test case contains m integers p_1, p_2, ..., p_m (1 ≤ p_i < n, all p_i are distinct) — the set of positions described in the problem statement.

Output

For each test case, print the answer — "YES" (without quotes) if you can sort the initial array in non-decreasing order (a_1 ≤ a_2 ≤ ... ≤ a_n) using only allowed swaps. Otherwise, print "NO".

Example

Input

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

Output

YES
NO
YES
YES
NO
YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 205, M = 1000000007, BIG = 0x3f3f3f3f;
int ct = 0;
int m, n;
int a[N], p[N];
bool Read() {
  cin >> n;
  if (cin.eof()) return 0;
  cin >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> p[i];
  return 1;
}
void Process() {
  for (int i = 0; i < 10005; i++)
    for (int j = 1; j <= m; j++)
      if (a[p[j]] > a[p[j] + 1]) swap(a[p[j]], a[p[j] + 1]);
  for (int i = 1; i < n; i++)
    if (a[i] > a[i + 1]) {
      cout << "NO\n";
      return;
    }
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T-- && Read()) Process();
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.

The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns.

How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?

Constraints

* 1 \leq H, W \leq N \leq 100
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
H
W

Output

Print the answer.

Examples

Input

3
2
3

Output

2

Input

100
1
1

Output

10000

Input

5
4
2

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c;
	scanf("%d %d %d ",&a,&b,&c);
	printf("%d\n",(a-b+1)*(a-c+1));
}

```


### Prompt

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

A and B are preparing themselves for programming contests.

B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.

Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.

However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.

Can you help B find out exactly what two errors he corrected?

Input

The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.

The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.

The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.

Output

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.

Examples

Input

5
1 5 8 123 7
123 7 5 1
5 1 7

Output

8
123

Input

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

Output

1
3

Note

In the first test sample B first corrects the error number 8, then the error number 123.

In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100000] = {};
int main() {
  long long b = 0, c = 0, d = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b += a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    c += a[i];
  }
  int x = b - c;
  for (int i = 0; i < n - 2; i++) {
    cin >> a[i];
    d += a[i];
  }
  int y = c - d;
  cout << x << '\n' << y;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

The only thing Mrs. Smith remembered was that any permutation of n can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.

The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).

A subsequence a_{i_1}, a_{i_2}, …, a_{i_k} where 1≤ i_1 < i_2 < … < i_k≤ n is called increasing if a_{i_1} < a_{i_2} < a_{i_3} < … < a_{i_k}. If a_{i_1} > a_{i_2} > a_{i_3} > … > a_{i_k}, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

For example, if there is a permutation [6, 4, 1, 7, 2, 3, 5], LIS of this permutation will be [1, 2, 3, 5], so the length of LIS is equal to 4. LDS can be [6, 4, 1], [6, 4, 2], or [6, 4, 3], so the length of LDS is 3.

Note, the lengths of LIS and LDS can be different.

So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.

Input

The only line contains one integer n (1 ≤ n ≤ 10^5) — the length of permutation that you need to build.

Output

Print a permutation that gives a minimum sum of lengths of LIS and LDS.

If there are multiple answers, print any.

Examples

Input

4

Output

3 4 1 2

Input

2

Output

2 1

Note

In the first sample, you can build a permutation [3, 4, 1, 2]. LIS is [3, 4] (or [1, 2]), so the length of LIS is equal to 2. LDS can be ony of [3, 1], [4, 2], [3, 2], or [4, 1]. The length of LDS is also equal to 2. The sum is equal to 4. Note that [3, 4, 1, 2] is not the only permutation that is valid.

In the second sample, you can build a permutation [2, 1]. LIS is [1] (or [2]), so the length of LIS is equal to 1. LDS is [2, 1], so the length of LDS is equal to 2. The sum is equal to 3. Note that permutation [1, 2] is also valid.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  long n;
  scanf("%ld", &n);
  long t(0);
  while (t * t < n) {
    ++t;
  }
  while (n) {
    long x = ((n - 1) / t) * t;
    for (long p = x + 1; p <= n; p++) {
      printf("%ld ", p);
    }
    n = x;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.

Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.

Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.

Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.

Constraints

* 1 ≤ N ≤ 10^5
* 2 ≤ C ≤ 10^{14}
* 1 ≤ x_1 < x_2 < ... < x_N < C
* 1 ≤ v_i ≤ 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N C
x_1 v_1
x_2 v_2
:
x_N v_N

Output

If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c.

Examples

Input

3 20
2 80
9 120
16 1

Output

191

Input

3 20
2 80
9 1
16 120

Output

192

Input

1 100000000000000
50000000000000 1

Output

0

Input

15 10000000000
400000000 1000000000
800000000 1000000000
1900000000 1000000000
2400000000 1000000000
2900000000 1000000000
3300000000 1000000000
3700000000 1000000000
3800000000 1000000000
4000000000 1000000000
4100000000 1000000000
5200000000 1000000000
6600000000 1000000000
8000000000 1000000000
9300000000 1000000000
9700000000 1000000000

Output

6500000000

### Response

```cpp
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
#define N 100000 + 5

int n, V[N];
LL c, ans, Max_1[N], _Max_1[N], Max_2[N], _Max_2[N], X[N], Sum_1[N], Sum_2[N];

int main()
{
	scanf("%d%lld", &n, &c);
	for (int i = 1; i <= n; i ++)
		scanf("%lld%d", X + i, V + i);
	for (int i = 1; i <= n; i ++)
	{
		Sum_1[i] = Sum_1[i - 1] + V[i] - (X[i] - X[i - 1]);
		Max_1[i] = max(Max_1[i - 1], Sum_1[i]);
		_Max_1[i] = max(_Max_1[i - 1], Sum_1[i] - X[i]);
	}
	X[n + 1] = c;
	for (int i = n; i; i --)
	{
		Sum_2[i] = Sum_2[i + 1] + V[i] - (X[i + 1] - X[i]);
		Max_2[i] = max(Max_2[i + 1], Sum_2[i]);
		_Max_2[i] = max(_Max_2[i + 1], Sum_2[i] - (c - X[i]));
	}
	for (int i = 0; i <= n; i ++)
		ans = max(ans, max(Max_1[i] + _Max_2[i + 1], _Max_1[i] + Max_2[i + 1]));//, printf("%lld %lld, %lld %lld\n", Max_1[i], _Max_1[i], Max_2[n - i + 1], _Max_2[n - i + 1]);
	printf("%lld\n", ans);
	return 0;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it?

The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is a circular area Ci described by a center (xi, yi) and a radius ri. No two ranges' borders have more than one common point, that is for every pair (i, j) (1 ≤ i < j ≤ n) either ranges Ci and Cj are disjoint, or one of them is a subset of the other. Note that it's possible that two ranges' borders share a single common point, but no two dancers have exactly the same ranges.

Tsukihi, being one of them, defines the spaciousness to be the area covered by an odd number of movement ranges of dancers who are moving. An example is shown below, with shaded regions representing the spaciousness if everyone moves at the same time.

<image>

But no one keeps moving for the whole night after all, so the whole night's time is divided into two halves — before midnight and after midnight. Every dancer moves around in one half, while sitting down with friends in the other. The spaciousness of two halves are calculated separately and their sum should, of course, be as large as possible. The following figure shows an optimal solution to the example above.

<image>

By different plans of who dances in the first half and who does in the other, different sums of spaciousness over two halves are achieved. You are to find the largest achievable value of this sum.

Input

The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers.

The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) with radius ri.

Output

Output one decimal number — the largest achievable sum of spaciousness over two halves of the night.

The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.

Examples

Input

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

Output

138.23007676

Input

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

Output

289.02652413

Note

The first sample corresponds to the illustrations in the legend.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
double pi = acos(-1.0);
struct circle {
  int r, x, y, cover;
} cir[1001];
int cmp(circle a, circle b) { return a.r > b.r; }
long long dist_sq(circle a, circle b) {
  return (long long)(a.x - b.x) * (a.x - b.x) +
         (long long)(a.y - b.y) * (a.y - b.y);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &cir[i].x, &cir[i].y, &cir[i].r);
  }
  sort(cir + 1, cir + 1 + n, cmp);
  cir[1].cover = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = i - 1; j >= 1; j--) {
      if (dist_sq(cir[i], cir[j]) < (long long)cir[j].r * cir[j].r) {
        cir[i].cover = cir[j].cover + 1;
        break;
      }
    }
  }
  long long answer = 0;
  for (int i = 1; i <= n; i++) {
    if (cir[i].cover == 0) answer += (long long)cir[i].r * cir[i].r;
    cir[i].cover--;
  }
  for (int i = 1; i <= n; i++) {
    if (cir[i].cover >= 0) {
      if (cir[i].cover & 1)
        answer -= (long long)cir[i].r * cir[i].r;
      else
        answer += (long long)cir[i].r * cir[i].r;
    }
  }
  printf("%.8lf", (double)answer * pi);
  return 0;
}

```


### Prompt

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

Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.

There are k boxes numbered from 1 to k. The i-th box contains n_i integer numbers. The integers can be negative. All of the integers are distinct.

Ujan is lazy, so he will do the following reordering of the numbers exactly once. He will pick a single integer from each of the boxes, k integers in total. Then he will insert the chosen numbers — one integer in each of the boxes, so that the number of integers in each box is the same as in the beginning. Note that he may also insert an integer he picked from a box back into the same box.

Ujan will be happy if the sum of the integers in each box is the same. Can he achieve this and make the boxes perfectly balanced, like all things should be?

Input

The first line contains a single integer k (1 ≤ k ≤ 15), the number of boxes.

The i-th of the next k lines first contains a single integer n_i (1 ≤ n_i ≤ 5 000), the number of integers in box i. Then the same line contains n_i integers a_{i,1}, …, a_{i,n_i} (|a_{i,j}| ≤ 10^9), the integers in the i-th box.

It is guaranteed that all a_{i,j} are distinct.

Output

If Ujan cannot achieve his goal, output "No" in a single line. Otherwise in the first line output "Yes", and then output k lines. The i-th of these lines should contain two integers c_i and p_i. This means that Ujan should pick the integer c_i from the i-th box and place it in the p_i-th box afterwards.

If there are multiple solutions, output any of those.

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

Examples

Input

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

Output

Yes
7 2
2 3
5 1
10 4

Input

2
2 3 -2
2 -1 5

Output

No

Input

2
2 -10 10
2 0 -20

Output

Yes
-10 2
-20 1

Note

In the first sample, Ujan can put the number 7 in the 2nd box, the number 2 in the 3rd box, the number 5 in the 1st box and keep the number 10 in the same 4th box. Then the boxes will contain numbers \{1,5,4\}, \{3, 7\}, \{8,2\} and \{10\}. The sum in each box then is equal to 10.

In the second sample, it is not possible to pick and redistribute the numbers in the required way.

In the third sample, one can swap the numbers -20 and -10, making the sum in each box equal to -10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int k, cnt, tot;
int a[20][N], b[20], tmp[N * 20];
long long sum[20], SS;
map<long long, int> mp;
int id[N * 20], E[1 << 16];
vector<int> G[N * 20], Q[1 << 16];
int vis[N * 20], look[1 << 16], dp[1 << 16];
int pre[1 << 16], l[20], r[20];
void dfs(int x, int statu) {
  if (vis[x]) {
    int now = 0;
    for (int i = tot; i; i--) {
      now |= b[id[E[i]] - 1];
      if (x == E[i]) break;
    }
    if (!look[now]) {
      look[now] = 1;
      for (int i = tot; i; i--) {
        Q[now].push_back(E[i]);
        if (E[i] == x) break;
      }
    }
    return;
  }
  if (statu & b[id[x] - 1]) return;
  statu |= b[id[x] - 1];
  vis[x] = 1;
  E[++tot] = x;
  for (int i = 0; i < G[x].size(); i++) {
    dfs(G[x][i], statu);
  }
  vis[x] = 0;
  --tot;
}
int main() {
  b[0] = 1;
  for (int i = 1; i <= 16; i++) b[i] = b[i - 1] * 2;
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &a[i][0]);
    for (int j = 1; j <= a[i][0]; j++) {
      scanf("%d", &a[i][j]);
      sum[i] += a[i][j];
      mp[a[i][j]] = ++cnt;
      id[cnt] = i;
      tmp[cnt] = a[i][j];
    }
    SS += sum[i];
  }
  if (SS % k) {
    puts("No");
    return 0;
  }
  SS /= k;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= a[i][0]; j++) {
      if (mp[SS - (sum[i] - a[i][j])]) {
        G[mp[a[i][j]]].push_back(mp[SS - (sum[i] - a[i][j])]);
      }
    }
  }
  for (int i = 1; i <= cnt; i++) dfs(i, 0);
  dp[0] = 1;
  for (int i = 0; i < b[k]; i++) {
    if (dp[i]) {
      int M = i ^ (b[k] - 1);
      for (int j = M; j; j = (j - 1) & M) {
        if (look[j]) {
          dp[i | j] = 1;
          pre[i | j] = i;
        }
      }
    }
  }
  if (!dp[b[k] - 1]) {
    puts("No");
    return 0;
  }
  int x = b[k] - 1;
  while (x) {
    int T = x - pre[x];
    for (int i = 0; i < Q[T].size(); i++) {
      l[id[mp[SS - sum[id[Q[T][i]]] + tmp[Q[T][i]]]]] =
          SS - sum[id[Q[T][i]]] + tmp[Q[T][i]];
      r[id[mp[SS - sum[id[Q[T][i]]] + tmp[Q[T][i]]]]] = id[Q[T][i]];
    }
    x = pre[x];
  }
  puts("Yes");
  for (int i = 1; i <= k; i++) {
    printf("%d %d\n", l[i], r[i]);
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.

Input

First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».

Output

Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.

Examples

Input

2 2
AG
CT

Output

AG
CT

Input

3 5
AGCAG
AGCAG
AGCAG

Output

TGCAT
CATGC
TGCAT

Note

In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice.

### Response

```cpp
#include <bits/stdc++.h>
const int ms = 3e5 + 19;
using namespace std;
string per = "ACGT";
int n, m, ans = ms;
string c[ms], cer[ms];
bool w[ms];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    cer[i] = c[i];
  }
  do {
    int cur = 0;
    for (int i = 0; i < n; i++) {
      int c1 = 0, c2 = 0;
      for (int j = 0; j < m; j++) {
        c1 += per[(i & 1) * 2 + (j & 1)] != c[i][j];
        c2 += per[(i & 1) * 2 + !(j & 1)] != c[i][j];
      }
      w[i] = c1 < c2;
      cur += min(c1, c2);
    }
    if (cur < ans) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cer[i][j] =
              w[i] ? per[(i & 1) * 2 + (j & 1)] : per[(i & 1) * 2 + !(j & 1)];
        }
      }
      ans = cur;
    }
    cur = 0;
    for (int i = 0; i < m; i++) {
      int c1 = 0, c2 = 0;
      for (int j = 0; j < n; j++) {
        c1 += per[(i & 1) * 2 + (j & 1)] != c[j][i];
        c2 += per[(i & 1) * 2 + !(j & 1)] != c[j][i];
      }
      w[i] = c1 < c2;
      cur += min(c1, c2);
    }
    if (cur < ans) {
      for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++)
          cer[j][i] =
              w[i] ? per[(i & 1) * 2 + (j & 1)] : per[(i & 1) * 2 + !(j & 1)];
      ans = cur;
    }
  } while (next_permutation(per.begin(), per.end()));
  for (int i = 0; i < n; i++) cout << cer[i] << "\n";
}

```


### Prompt

Develop a solution in cpp to the problem described below:

The Smart Beaver from ABBYY has a lot of hobbies. One of them is constructing efficient hash tables. One of the most serious problems in hash tables is resolving collisions. The Beaver is interested in this problem very much and he decided to explore it in detail.

We assume that the hash table consists of h cells numbered from 0 to h - 1. Objects are added to and removed from it. Every object has its own unique identifier. In addition, every object has a corresponding hash value — an integer between 0 and h - 1, inclusive. When an object is added to the table, if the cell corresponding to the hash value of the object is free, then this object goes there. If the cell is already occupied by another object, there is a collision. When an object is deleted from the table, the cell which it occupied becomes empty.

The Smart Beaver has recently learned about the method of linear probing to resolve collisions. It is as follows. Let's say that the hash value for the added object equals t and cell t of the table is already occupied. Then we try to add this object to cell (t + m) mod h. If it is also occupied, then we try cell (t + 2·m) mod h, then cell (t + 3·m) mod h, and so on. Note that in some cases it's possible that the new object can not be added to the table. It is guaranteed that the input for this problem doesn't contain such situations.

The operation a mod b means that we take the remainder of the division of number a by number b.

This technique immediately seemed very inoptimal to the Beaver, and he decided to assess its inefficiency. So, you are given a sequence of operations, each of which is either an addition of an object to the table or a deletion of an object from the table. When adding a new object, a sequence of calls to the table is performed. Calls to occupied cells are called dummy. In other words, if the result of the algorithm described above is the object being added to cell (t + i·m) mod h (i ≥ 0), then exactly i dummy calls have been performed.

Your task is to calculate the total number of dummy calls to the table for the given sequence of additions and deletions. When an object is deleted from the table, assume that no dummy calls are performed. The table is empty before performing the operations, that is, initially it doesn't contain any objects.

Input

The first line of input contains three integers h, m and n (1 ≤ m < h), separated by spaces, where h is the size of the hash table, m is the number that is used to resolve collisions, n is the number of operations.

The following n lines contains the descriptions of the operations. Their execution order corresponds to the order in which they appear in the input file. Each operation is described by a single line. The operations are described as follows:

  * "+ id hash"

This is the format of the operation that adds an object to the table. The first character is "+" (ASCII 43), followed by a single space, then the object identifier id (0 ≤ id ≤ 109), then another space, and the hash value of the given object hash (0 ≤ hash < h). The object identifier and the hash value of this object are integers.

  * "- id"

This is the format of the operation that deletes an object from the table. The first character is "-" (ASCII 45), followed by a single space, then the object identifier id (0 ≤ id ≤ 109). The object identifier is an integer.

It is guaranteed that for all addition operations the value of id is unique. It is also guaranteed that the initial data is correct, that is, it's always possible to add an object to the hash table and there won't be any deletions of nonexisting objects.

The input limitations for getting 20 points are:

  * 1 ≤ h ≤ 5000
  * 1 ≤ n ≤ 5000

The input limitations for getting 50 points are:

  * 1 ≤ h ≤ 5·104
  * 1 ≤ n ≤ 5·104

The input limitations for getting 100 points are:

  * 1 ≤ h ≤ 2·105
  * 1 ≤ n ≤ 2·105

Output

Print a single number — the total number of dummy calls to the hash table.

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

Examples

Input

10 2 7
+ 11 0
+ 22 2
+ 33 6
+ 44 0
+ 55 0
- 22
+ 66 0

Output

7

Input

5 1 6
+ 123 0
+ 234 1
+ 345 2
- 234
+ 456 0
+ 567 0

Output

4

### Response

```cpp
#include <bits/stdc++.h>
int IntMaxVal = (int)1e20;
int IntMinVal = (int)-1e20;
long long LongMaxVal = (long long)1e20;
long long LongMinVal = (long long)-1e20;
using namespace std;
template <typename T>
struct argument_type;
template <typename T, typename U>
struct argument_type<T(U)> {};
template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& s) {
  is >> s.first >> s.second;
  return is;
}
class minTree {
  int gp2(int n) {
    int x = 2;
    while (x < n) x *= 2;
    return x;
  }
  vector<int> data;
  int n;

 public:
  void init(int n) {
    n = this->n = gp2(n);
    data.resize(2 * n);
    for (int i = 0; i < n; ++i) data[i + n] = i;
    for (int i = n - 1; i >= 1; --i)
      data[i] = min(data[2 * i], data[2 * i + 1]);
  }
  void set(int i, int x) {
    i += n;
    data[i] = x;
    i /= 2;
    while (i) {
      data[i] = min(data[2 * i], data[2 * i + 1]);
      i /= 2;
    }
  }
  int getMin(int l, int r, int i, int fl, int fr) {
    if (l == fl && r + 1 == fr) return data[i];
    int m = (fl + fr) / 2;
    if (l < m && r >= m)
      return min(getMin(l, m - 1, 2 * i, fl, m),
                 getMin(m, r, 2 * i + 1, m, fr));
    else if (l < m)
      return getMin(l, r, 2 * i, fl, m);
    else
      return getMin(l, r, 2 * i + 1, m, fr);
  }
  int getMin(int l, int r) { return getMin(l, r, 1, 0, n); }
};
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h;
  cin >> h;
  ;
  int m;
  cin >> m;
  ;
  int n;
  cin >> n;
  ;
  int cur = m;
  int cycleLength = 1;
  while (cur) {
    cycleLength++;
    cur = (cur + m) % h;
  }
  int cycles = h / cycleLength;
  vector<minTree> trees(cycles);
  for (auto& tr : trees) tr.init(cycleLength);
  vector<int> treeIndex(h, -1);
  vector<int> indexInTree(h);
  int nextTree = 0;
  for (int i = 0; i < h; ++i)
    if (treeIndex[i] == -1) {
      treeIndex[i] = nextTree++;
      indexInTree[i] = 0;
      cur = i;
      while (true) {
        int then = (cur + m) % h;
        if (then == i) break;
        indexInTree[then] = indexInTree[cur] + 1;
        treeIndex[then] = treeIndex[i];
        cur = then;
      }
    }
  map<int, int> position;
  long long res = 0;
  while (n-- > 0) {
    char c;
    cin >> c;
    ;
    int id;
    cin >> id;
    ;
    if (c == '-') {
      int pos = position[id];
      trees[treeIndex[pos]].set(indexInTree[pos], indexInTree[pos]);
    } else {
      int pos;
      cin >> pos;
      ;
      int iTree = treeIndex[pos];
      int lookupPos = indexInTree[pos];
      int actualPos = trees[iTree].getMin(lookupPos, cycleLength - 1);
      if (actualPos == IntMaxVal)
        actualPos = trees[iTree].getMin(0, lookupPos - 1);
      int dist;
      if (actualPos >= lookupPos)
        dist = actualPos - lookupPos;
      else
        dist = cycleLength - lookupPos + actualPos;
      res += dist;
      trees[iTree].set(actualPos, IntMaxVal);
      long long longPos = pos + 1LL * dist * m;
      longPos %= h;
      position[id] = (int)longPos;
    }
  }
  cout << res;
}

```


### Prompt

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

Iahub is playing an uncommon game. Initially, he has n boxes, numbered 1, 2, 3, ..., n. Each box has some number of candies in it, described by a sequence a1, a2, ..., an. The number ak represents the number of candies in box k.

The goal of the game is to move all candies into exactly two boxes. The rest of n - 2 boxes must contain zero candies. Iahub is allowed to do several (possible zero) moves. At each move he chooses two different boxes i and j, such that ai ≤ aj. Then, Iahub moves from box j to box i exactly ai candies. Obviously, when two boxes have equal number of candies, box number j becomes empty.

Your task is to give him a set of moves such as Iahub to archive the goal of the game. If Iahub can't win the game for the given configuration of boxes, output -1. Please note that in case there exist a solution, you don't need to print the solution using minimal number of moves.

Input

The first line of the input contains integer n (3 ≤ n ≤ 1000). The next line contains n non-negative integers: a1, a2, ..., an — sequence elements. It is guaranteed that sum of all numbers in sequence a is up to 106.

Output

In case there exists no solution, output -1. Otherwise, in the first line output integer c (0 ≤ c ≤ 106), representing number of moves in your solution. Each of the next c lines should contain two integers i and j (1 ≤ i, j ≤ n, i ≠ j): integers i, j in the kth line mean that at the k-th move you will move candies from the j-th box to the i-th one.

Examples

Input

3
3 6 9

Output

2
2 3
1 3

Input

3
0 1 0

Output

-1

Input

4
0 1 1 0

Output

0

Note

For the first sample, after the first move the boxes will contain 3, 12 and 3 candies. After the second move, the boxes will contain 6, 12 and 0 candies. Now all candies are in exactly 2 boxes.

For the second sample, you can observe that the given configuration is not valid, as all candies are in a single box and they should be in two boxes. Also, any move won't change the configuration, so there exists no solution.

For the third sample, all candies are already in 2 boxes. Hence, no move is needed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
pair<int, int> v;
vector<pair<int, int> > ans;
int val[N], b[3], n;
int cmp(int x, int y) { return val[x] < val[y]; }
inline void doit(int x, int y) {
  ans.push_back(make_pair(x, y));
  val[y] -= val[x];
  val[x] <<= 1;
}
inline void solve(int a[3]) {
  sort(a, a + 3, cmp);
  if (!val[a[0]]) {
    v = make_pair(a[1], a[2]);
    return;
  }
  int t = val[a[1]] / val[a[0]];
  for (; t; t >>= 1)
    if (t & 1)
      doit(a[0], a[1]);
    else
      doit(a[0], a[2]);
  solve(a);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i <= n; i++)
    if (val[i]) {
      if (!v.first)
        v.first = i;
      else if (!v.second)
        v.second = i;
      else
        b[0] = v.first, b[1] = v.second, b[2] = i, solve(b);
    }
  if (!v.second) {
    puts("-1");
    return 0;
  }
  printf("%d\n", (int)ans.size());
  for (pair<int, int> i : ans) printf("%d %d\n", i.first, i.second);
}

```


### Prompt

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

One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1, z1). The six faces of the box contain some numbers a1, a2, ..., a6, exactly one number right in the center of each face.

<image>

The numbers are located on the box like that:

  * number a1 is written on the face that lies on the ZOX plane;
  * a2 is written on the face, parallel to the plane from the previous point;
  * a3 is written on the face that lies on the XOY plane;
  * a4 is written on the face, parallel to the plane from the previous point;
  * a5 is written on the face that lies on the YOZ plane;
  * a6 is written on the face, parallel to the plane from the previous point.

At the moment Vasya is looking at the box from point (x, y, z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the ai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some ai = 6, then he can't mistake this number for 9 and so on).

Input

The fist input line contains three space-separated integers x, y and z (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integers x1, y1, z1 (1 ≤ x1, y1, z1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers a1, a2, ..., a6 (1 ≤ ai ≤ 106) — the numbers that are written on the box faces.

It is guaranteed that point (x, y, z) is located strictly outside the box.

Output

Print a single integer — the sum of all numbers on the box faces that Vasya sees.

Examples

Input

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

Output

12

Input

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

Output

4

Note

The first sample corresponds to perspective, depicted on the picture. Vasya sees numbers a2 (on the top face that is the darkest), a6 (on the right face that is the lightest) and a4 (on the left visible face).

In the second sample Vasya can only see number a4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, z;
  scanf("%d%d%d", &x, &y, &z);
  int x1, y1, z1;
  scanf("%d%d%d", &x1, &y1, &z1);
  int a[6];
  for (int i = 0; i < 6; i++) scanf("%d", &a[i]);
  int s = 0;
  if (x < 0) s += a[4];
  if (x > x1) s += a[5];
  if (y < 0) s += a[0];
  if (y > y1) s += a[1];
  if (z < 0) s += a[2];
  if (z > z1) s += a[3];
  printf("%d\n", s);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 106) — the number of segments and the value of k.

The next n lines contain two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109) each — the endpoints of the i-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.

Output

First line contains integer m — the smallest number of segments.

Next m lines contain two integers aj, bj (aj ≤ bj) — the ends of j-th segment in the answer. The segments should be listed in the order from left to right.

Examples

Input

3 2
0 5
-3 2
3 8

Output

2
0 2
3 5

Input

3 2
0 5
-3 3
3 8

Output

1
0 5

### Response

```cpp
#include <bits/stdc++.h>
struct punct {
  int x, tip;
  inline bool operator<(const punct &b) const {
    if (x == b.x) return tip < b.tip;
    return x < b.x;
  }
};
std::vector<punct> intervale, rasp;
int main() {
  int n, k;
  scanf("%d %d ", &n, &k);
  for (int i = 1; i <= n; i++) {
    int st, dr;
    scanf("%d %d ", &st, &dr);
    punct a;
    a.tip = -1;
    a.x = st;
    intervale.push_back(a);
    a.tip = 1;
    a.x = dr;
    intervale.push_back(a);
  }
  std::sort(intervale.begin(), intervale.end());
  int X = 0;
  for (int i = 0; i < intervale.size(); i++) {
    int op;
    if (X == k - 1 && intervale[i].tip == -1) {
      op = intervale[i].x;
    }
    if (X == k && intervale[i].tip == 1) {
      punct a;
      a.tip = intervale[i].x;
      a.x = op;
      rasp.push_back(a);
    }
    X -= intervale[i].tip;
  }
  printf("%d\n", rasp.size());
  for (int i = 0; i < rasp.size(); i++) {
    printf("%d %d\n", rasp[i].x, rasp[i].tip);
  }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Shichikuji is the new resident deity of the South Black Snail Temple. Her first job is as follows:

There are n new cities located in Prefecture X. Cities are numbered from 1 to n. City i is located x_i km North of the shrine and y_i km East of the shrine. It is possible that (x_i, y_i) = (x_j, y_j) even when i ≠ j.

Shichikuji must provide electricity to each city either by building a power station in that city, or by making a connection between that city and another one that already has electricity. So the City has electricity if it has a power station in it or it is connected to a City which has electricity by a direct connection or via a chain of connections.

  * Building a power station in City i will cost c_i yen;
  * Making a connection between City i and City j will cost k_i + k_j yen per km of wire used for the connection. However, wires can only go the cardinal directions (North, South, East, West). Wires can cross each other. Each wire must have both of its endpoints in some cities. If City i and City j are connected by a wire, the wire will go through any shortest path from City i to City j. Thus, the length of the wire if City i and City j are connected is |x_i - x_j| + |y_i - y_j| km.

Shichikuji wants to do this job spending as little money as possible, since according to her, there isn't really anything else in the world other than money. However, she died when she was only in fifth grade so she is not smart enough for this. And thus, the new resident deity asks for your help.

And so, you have to provide Shichikuji with the following information: minimum amount of yen needed to provide electricity to all cities, the cities in which power stations will be built, and the connections to be made.

If there are multiple ways to choose the cities and the connections to obtain the construction of minimum price, then print any of them.

Input

First line of input contains a single integer n (1 ≤ n ≤ 2000) — the number of cities.

Then, n lines follow. The i-th line contains two space-separated integers x_i (1 ≤ x_i ≤ 10^6) and y_i (1 ≤ y_i ≤ 10^6) — the coordinates of the i-th city.

The next line contains n space-separated integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^9) — the cost of building a power station in the i-th city.

The last line contains n space-separated integers k_1, k_2, ..., k_n (1 ≤ k_i ≤ 10^9).

Output

In the first line print a single integer, denoting the minimum amount of yen needed.

Then, print an integer v — the number of power stations to be built.

Next, print v space-separated integers, denoting the indices of cities in which a power station will be built. Each number should be from 1 to n and all numbers should be pairwise distinct. You can print the numbers in arbitrary order.

After that, print an integer e — the number of connections to be made.

Finally, print e pairs of integers a and b (1 ≤ a, b ≤ n, a ≠ b), denoting that a connection between City a and City b will be made. Each unordered pair of cities should be included at most once (for each (a, b) there should be no more (a, b) or (b, a) pairs). You can print the pairs in arbitrary order.

If there are multiple ways to choose the cities and the connections to obtain the construction of minimum price, then print any of them.

Examples

Input

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

Output

8
3
1 2 3
0

Input

3
2 1
1 2
3 3
23 2 23
3 2 3

Output

27
1
2
2
1 2
2 3

Note

For the answers given in the samples, refer to the following diagrams (cities with power stations are colored green, other cities are colored blue, and wires are colored red):

<image>

For the first example, the cost of building power stations in all cities is 3 + 2 + 3 = 8. It can be shown that no configuration costs less than 8 yen.

For the second example, the cost of building a power station in City 2 is 2. The cost of connecting City 1 and City 2 is 2 ⋅ (3 + 2) = 10. The cost of connecting City 2 and City 3 is 3 ⋅ (2 + 3) = 15. Thus the total cost is 2 + 10 + 15 = 27. It can be shown that no configuration costs less than 27 yen.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int64_t n;
  cin >> n;
  struct point {
    int64_t x, y;
  };
  vector<point> a(n + 1);
  for (int64_t i = 1; i < n + 1; i++) {
    cin >> a[i].x >> a[i].y;
  }
  vector<int64_t> c(n + 1), k(n + 1);
  for (int64_t i = 1; i < n + 1; i++) {
    cin >> c[i];
  }
  for (int64_t i = 1; i < n + 1; i++) {
    cin >> k[i];
  }
  vector<vector<int64_t>> d(n + 1, vector<int64_t>(n + 1, INT64_MAX));
  for (int64_t i = 1; i < n + 1; i++) {
    d[0][i] = c[i];
    d[i][0] = c[i];
  }
  for (int64_t i = 1; i < n + 1; i++) {
    for (int64_t j = 1; j < n + 1; j++) {
      d[i][j] = d[j][i] =
          (k[i] + k[j]) * (abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y));
    }
  }
  int64_t ans = 0;
  vector<int64_t> used(n + 1, 0);
  vector<int64_t> min_c(n + 1, INT64_MAX), p(n + 1, -1);
  vector<pair<int64_t, int64_t>> mst;
  min_c[0] = 0;
  for (int64_t i = 0; i < n + 1; i++) {
    int64_t v = -1;
    for (int64_t j = 0; j < n + 1; j++) {
      if (!used[j] && (v == -1 || min_c[j] < min_c[v])) {
        v = j;
      }
    }
    used[v] = true;
    ans += min_c[v];
    mst.emplace_back(v, p[v]);
    for (int64_t j = 0; j < n + 1; j++) {
      if (d[v][j] < min_c[j]) {
        min_c[j] = d[v][j];
        p[j] = v;
      }
    }
  }
  cout << ans << "\n";
  vector<int64_t> ans1;
  vector<pair<int64_t, int64_t>> ans2;
  for (auto it : mst) {
    if (it.second == -1) {
      continue;
    }
    if (it.second == 0) {
      ans1.push_back(it.first);
    } else {
      ans2.emplace_back(it.first, it.second);
    }
  }
  cout << ans1.size() << "\n";
  for (auto it : ans1) {
    cout << it << " ";
  }
  cout << "\n";
  cout << ans2.size() << "\n";
  for (auto it : ans2) {
    cout << it.first << " " << it.second << "\n";
  }
}

```


### Prompt

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

A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n.

Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values n, d and h:

  * The tree had exactly n vertices.
  * The tree had diameter d. In other words, d was the biggest distance between two vertices.
  * Limak also remembers that he once rooted the tree in vertex 1 and after that its height was h. In other words, h was the biggest distance between vertex 1 and some other vertex.

The distance between two vertices of the tree is the number of edges on the simple path between them.

Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".

Input

The first line contains three integers n, d and h (2 ≤ n ≤ 100 000, 1 ≤ h ≤ d ≤ n - 1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.

Output

If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).

Otherwise, describe any tree matching Limak's description. Print n - 1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.

Examples

Input

5 3 2

Output

1 2
1 3
3 4
3 5

Input

8 5 2

Output

-1

Input

8 4 2

Output

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

Note

Below you can see trees printed to the output in the first sample and the third sample.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, d, h;
  cin >> n >> d >> h;
  if (d < h || d > h * 2 || d + 1 > n || d == 1 && n > 2) {
    cout << -1 << endl;
    return 0;
  }
  vector<vector<int> > adj(n);
  for (int i = 0; i < h; i++) adj[i].push_back(i + 1);
  if (d > h) {
    adj[0].push_back(h + 1);
    for (int i = h + 1; i < d; i++) adj[i].push_back(i + 1);
  }
  if (n > d + 1) {
    for (int i = d + 1; i < n; i++)
      if (h == 1)
        adj[0].push_back(i);
      else
        adj[1].push_back(i);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < adj[i].size(); j++)
      cout << i + 1 << " " << adj[i][j] + 1 << endl;
}

```


### Prompt

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

You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n]. Each segment has one of two colors: the i-th segment's color is t_i.

Let's call a pair of segments i and j bad if the following two conditions are met:

  * t_i ≠ t_j;
  * the segments [l_i, r_i] and [l_j, r_j] intersect, embed or touch, i. e. there exists an integer x such that x ∈ [l_i, r_i] and x ∈ [l_j, r_j].

Calculate the maximum number of segments that can be selected from the given ones, so that there is no bad pair among the selected ones.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — number of segments.

The next n lines contains three integers l_i, r_i, t_i (1 ≤ l_i ≤ r_i ≤ 10^9; t_i ∈ \{1, 2\}) — description of the i-th segment.

Output

Print the maximum number of segments that can be selected, so that there is no bad pair among the selected segments.

Examples

Input

3
1 3 1
4 6 2
2 5 1

Output

2

Input

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

Output

4

Input

7
19 20 1
13 15 2
6 11 2
4 10 1
14 17 1
13 13 2
5 9 1

Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 7;
struct SegmentTree {
  int tr[4 * MAXN];
  int lazy[4 * MAXN];
  void propagate(int u, int l, int r) {
    if (lazy[u]) {
      tr[u] += lazy[u];
      if (l != r) {
        lazy[u * 2] += lazy[u];
        lazy[u * 2 + 1] += lazy[u];
      }
      lazy[u] = 0;
    }
  }
  void build(int u, int l, int r) {
    tr[u] = 0;
    lazy[u] = 0;
    if (l == r) {
      return;
    }
    int mid = (l + r) / 2;
    build(u * 2, l, mid);
    build(u * 2 + 1, mid + 1, r);
  }
  void update(int u, int l, int r, int x, int y, int v) {
    propagate(u, l, r);
    if (r < x || y < l) return;
    if (x <= l && r <= y) {
      lazy[u] += v;
      propagate(u, l, r);
      return;
    }
    int mid = (l + r) / 2;
    update(u * 2, l, mid, x, y, v);
    update(u * 2 + 1, mid + 1, r, x, y, v);
    tr[u] = max(tr[u * 2], tr[u * 2 + 1]);
  }
  int query(int u, int l, int r, int x, int y) {
    propagate(u, l, r);
    if (x <= l && r <= y) return tr[u];
    int mid = (l + r) / 2;
    if (y <= mid) return query(u * 2, l, mid, x, y);
    if (mid < x) return query(u * 2 + 1, mid + 1, r, x, y);
    return max(query(u * 2, l, mid, x, y), query(u * 2 + 1, mid + 1, r, x, y));
  }
};
SegmentTree black, white;
int _l[MAXN], _r[MAXN], _t[MAXN];
vector<int> oc[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    cin >> _l[i] >> _r[i] >> _t[i];
    v.push_back(_l[i]);
    v.push_back(_r[i]);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 1; i <= n; i++) {
    _l[i] = lower_bound(v.begin(), v.end(), _l[i]) - v.begin();
    _r[i] = lower_bound(v.begin(), v.end(), _r[i]) - v.begin();
    oc[_l[i]].push_back(i);
  }
  int m = v.size();
  black.build(1, 0, m);
  white.build(1, 0, m);
  for (int x = m - 1; x >= 0; x--) {
    for (int i : oc[x]) {
      if (_t[i] == 1) {
        white.update(1, 0, m, _r[i] + 1, m, 1);
      } else {
        black.update(1, 0, m, _r[i] + 1, m, 1);
      }
    }
    black.update(1, 0, m, x, x, white.query(1, 0, m, x + 1, m));
    white.update(1, 0, m, x, x, black.query(1, 0, m, x + 1, m));
  }
  cout << max(black.tr[1], white.tr[1]) << "\n";
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that:

  * Each pencil belongs to exactly one box;
  * Each non-empty box has at least k pencils in it;
  * If pencils i and j belong to the same box, then |ai - aj| ≤ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils i and j such that |ai - aj| ≤ d and they belong to different boxes.

Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO".

Input

The first line contains three integer numbers n, k and d (1 ≤ k ≤ n ≤ 5·105, 0 ≤ d ≤ 109) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively.

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — saturation of color of each pencil.

Output

Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO".

Examples

Input

6 3 10
7 2 7 7 4 2

Output

YES

Input

6 2 3
4 5 3 13 4 10

Output

YES

Input

3 2 5
10 16 22

Output

NO

Note

In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.

In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and put the remaining ones into another box.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 500 * 1001;
int n, k, d, a[N];
set<int> done;
set<pair<int, int>> remain;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k >> d;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) remain.insert(make_pair(a[i], i));
  done.insert(0);
  while (done.size()) {
    int dex = *done.begin() + 1;
    done.erase(done.begin());
    int low = a[dex] + d;
    while (remain.upper_bound(make_pair(low, n)) != remain.begin()) {
      pair<int, int> p = *(--remain.upper_bound(make_pair(low, n)));
      if (p.second - dex + 1 < k) break;
      remain.erase(--remain.upper_bound(make_pair(low, n)));
      done.insert(p.second);
      if (p.second == n) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.

Input

jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.

Output

ekjfkj q iydwbu dkcruh.

Examples

Input

1

Output

13

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
bool notp[N];
void sieve() {
  notp[0] = notp[1] = 1;
  for (int i = 2; i < N; ++i) {
    if (notp[i]) continue;
    for (int j = i * 2; j < N; j += i) notp[j] = 1;
  }
}
int rev(int v) {
  int ans = 0;
  while (v) {
    ans *= 10;
    ans += (v % 10);
    v /= 10;
  }
  return ans;
}
int main() {
  sieve();
  int n;
  scanf("%d", &n);
  int c = 0;
  for (int i = 1; i < N; ++i) {
    if (!notp[i] && (!notp[rev(i)] && i != rev(i))) {
      ++c;
    }
    if (c == n) {
      printf("%d", i);
      return 0;
    }
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

Given an integer a as input, print the value a + a^2 + a^3.

Constraints

* 1 \leq a \leq 10
* a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

Print the value a + a^2 + a^3 as an integer.

Examples

Input

2

Output

14

Input

10

Output

1110

### Response

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

int main(){
  int a;
  std::cin >> a;
  std::cout << a+a*a+a*a*a << std::endl;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

problem

You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation.

For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo.

Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture.

<image> | <image>
--- | ---
Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky

input

The input consists of multiple datasets. Each dataset is given in the following format.

The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks.

The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less.

When m is 0, it indicates the end of input. The number of datasets does not exceed 5.

output

The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction.

Examples

Input

5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0

Output

2 -3
-384281 179674

Input

None

Output

None

### Response

```cpp
#include <stdio.h>
#include <algorithm>

using namespace std;

typedef struct {
	int x, y;
} POINT;

bool operator< (const POINT& a, const POINT& b)
{
	if (a.x == b.x){
		return (a.y < b.y);
	}
	return (a.x < b.x);
}

int main(void)
{
	POINT pat[200];
	POINT all[1000];
	int allcnt, patcnt;
	int i, j;

	while (1){
		scanf("%d", &patcnt);

		if (patcnt == 0){
			break;
		}

		for (int i = 0; i < patcnt; i++){
			scanf("%d%d", &pat[i].x, &pat[i].y);
		}

		scanf("%d", &allcnt);
		for (int i = 0; i < allcnt; i++){
			scanf("%d%d", &all[i].x, &all[i].y);
		}

		sort(pat, pat + patcnt);
		sort(all, all + allcnt);

		for (i = 0; i + patcnt - 1 < allcnt; i++){
			int k;
			k = 0;
			for (j = 0; j < patcnt; j++){
				for (int l = 0; l < allcnt; l++){
					if (pat[j].x - pat[0].x == all[l].x - all[i].x && pat[j].y - pat[0].y == all[l].y - all[i].y){
						k++;
						break;
					}
				}
			}
			if (k == patcnt){
				break;
			}
		}

		printf("%d %d\n", all[i].x - pat[0].x, all[i].y - pat[0].y);

	}

	return (0);
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.

Max is a young biologist. For n days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer k that if the shark in some day traveled the distance strictly less than k, then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to k; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least k.

The shark never returned to the same location after it has moved from it. Thus, in the sequence of n days we can find consecutive nonempty segments when the shark traveled the distance less than k in each of the days: each such segment corresponds to one location. Max wants to choose such k that the lengths of all such segments are equal.

Find such integer k, that the number of locations is as large as possible. If there are several such k, print the smallest one.

Input

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

The second line contains n distinct positive integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the distance traveled in each of the day.

Output

Print a single integer k, such that

  1. the shark was in each location the same number of days,
  2. the number of locations is maximum possible satisfying the first condition,
  3. k is smallest possible satisfying the first and second conditions.

Examples

Input

8
1 2 7 3 4 8 5 6

Output

7

Input

6
25 1 2 3 14 36

Output

2

Note

In the first example the shark travels inside a location on days 1 and 2 (first location), then on 4-th and 5-th days (second location), then on 7-th and 8-th days (third location). There are three locations in total.

In the second example the shark only moves inside a location on the 2-nd day, so there is only one location.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int md = 1e9 + 7;
const long long int N = 100005;
long long int dsu[N], sz[N];
pair<long long int, long long int> a[N];
map<long long int, long long int> m;
long long int root(long long int u) {
  while (u != dsu[u]) u = dsu[u];
  return u;
}
bool uni(long long int u, long long int v) {
  u = root(u), v = root(v);
  if (u == v) return 0;
  m[sz[u]]--;
  if (m[sz[u]] == 0) m.erase(sz[u]);
  m[sz[v]]--;
  if (m[sz[v]] == 0) m.erase(sz[v]);
  m[sz[u] + sz[v]]++;
  if (sz[u] > sz[v]) {
    dsu[v] = u;
    sz[u] += sz[v];
  } else {
    dsu[u] = v;
    sz[v] += sz[u];
  }
  return 1;
}
bool active[N];
signed main() {
  ios::sync_with_stdio(0);
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
    dsu[i] = i;
    sz[i] = 1;
  }
  sort(a + 1, a + n + 1);
  long long int maxi = 0;
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int v = a[i].first;
    while (a[i].first == v) {
      active[a[i].second] = 1;
      m[1]++;
      if (a[i].second > 1 && active[a[i].second - 1])
        uni(a[i].second - 1, a[i].second);
      if (a[i].second < n && active[a[i].second + 1])
        uni(a[i].second, a[i].second + 1);
      i++;
    }
    i--;
    auto it = m.begin();
    if (m.size() == 1 && maxi < it->second) {
      ans = a[i].first;
      maxi = it->second;
    }
  }
  cout << ans + 1;
  return 0;
}

```


### Prompt

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

Urpal lives in a big city. He has planned to meet his lover tonight.

The city has n junctions numbered from 1 to n. The junctions are connected by m directed streets, all the roads have equal length. Urpal lives in junction a and the date is planned in a restaurant in junction b. He wants to use public transportation to get to junction b. There are k bus transportation companies. At the beginning of every second, a bus from the i-th company chooses a random shortest path between junction si and junction ti and passes through it. There might be no path from si to ti. In that case no bus will leave from si to ti. If a bus passes through a junction where Urpal stands, he can get on the bus. He can also get off the bus at any junction along the path.

Now Urpal wants to know if it's possible to go to the date using public transportation in a finite amount of time (the time of travel is the sum of length of the traveled roads) and what is the minimum number of buses he should take in the worst case.

At any moment Urpal knows only his own position and the place where the date will be. When he gets on the bus he knows only the index of the company of this bus. Of course Urpal knows the city map and the the pairs (si, ti) for each company.

Note that Urpal doesn't know buses velocity.

Input

The first line of the input contains four integers n, m, a, b (2 ≤ n ≤ 100; 0 ≤ m ≤ n·(n - 1); 1 ≤ a, b ≤ n; a ≠ b).

The next m lines contain two integers each ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) describing a directed road from junction ui to junction vi. All roads in the input will be distinct.

The next line contains an integer k (0 ≤ k ≤ 100). There will be k lines after this, each containing two integers si and ti (1 ≤ si, ti ≤ n; si ≠ ti) saying there is a bus route starting at si and ending at ti. Please note that there might be no path from si to ti, this case is described in the problem statement.

Output

In the only line of output print the minimum number of buses Urpal should get on on his way in the worst case. If it's not possible to reach the destination in the worst case print -1.

Examples

Input

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

Output

2

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105, MOD = 998244353;
inline void ADD(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
int N, M, K, S, T, G[MAXN][MAXN], s[MAXN], t[MAXN], f[MAXN], dis[MAXN][MAXN],
    D[MAXN][MAXN], cnt[MAXN][MAXN];
queue<int> Q;
int main() {
  scanf("%d%d%d%d", &N, &M, &S, &T);
  int u, v;
  while (M--) scanf("%d%d", &u, &v), G[u][v] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) D[i][j] = -1;
    D[i][i] = 0, cnt[i][i] = 1, Q.push(i);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int j = 1; j <= N; ++j)
        if (G[u][j]) {
          if (D[i][j] == -1)
            D[i][j] = D[i][u] + 1, Q.push(j), cnt[i][j] = cnt[i][u];
          else if (D[i][j] == D[i][u] + 1)
            ADD(cnt[i][j], cnt[i][u]);
        }
    }
  }
  scanf("%d", &K);
  for (int i = 1; i <= K; ++i) scanf("%d%d", &s[i], &t[i]);
  f[T] = 1;
  for (int turn = 2; turn <= N + 1; ++turn) {
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= N; ++j) dis[i][j] = -1;
      dis[i][i] = 0, Q.push(i);
      while (!Q.empty()) {
        int u = Q.front();
        Q.pop();
        for (int j = 1; j <= N; ++j)
          if (G[u][j] && !f[j]) {
            if (dis[i][j] == -1) dis[i][j] = dis[i][u] + 1, Q.push(j);
          }
      }
    }
    int chk = 0;
    for (int i = 1; i <= N; ++i)
      if (!f[i]) {
        for (int j = 1; j <= K; ++j) {
          if (D[s[j]][i] + D[i][t[j]] != D[s[j]][t[j]]) continue;
          if (1ll * cnt[s[j]][i] * cnt[i][t[j]] % MOD != cnt[s[j]][t[j]])
            continue;
          if (dis[i][t[j]] != D[i][t[j]]) {
            f[i] = turn, ++chk;
            break;
          }
        }
      }
    if (f[S]) break;
    if (!cnt) break;
  }
  printf("%d\n", f[S] - 1);
  return 0;
}

```


### Prompt

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

problem

You are playing with J using the Midakuji. The Amida lottery consists of n vertical bars and m horizontal bars. The vertical bars are numbered from 1 to n in order from the left, and the vertical bar i The positive integer si is written at the bottom of.

<image>

Figure 3-1 Example of Amidakuji (n = 4, m = 5, s1 = 20, s2 = 80, s3 = 100, s4 = 50)

The integer written at the bottom of the vertical bar i, which is reached by following the path from the top of the vertical bar i, is the score when the vertical bar i is selected. For example, in Fig. 3-1 the vertical bar 1 is selected. And the score is 80 points, and if the vertical bar 2 is selected, the score is 100 points.

<image>

Figure 3-2 Example of how to follow the road

Mr. J decides to choose a series of k books from vertical bar 1 to vertical bar k. The total score when selecting those k vertical bars is J's score. However, you are in the Amidakuji You can select one horizontal bar and delete that horizontal bar from the Amidakuji. (You do not have to delete it.) If you delete one horizontal bar, the vertical bar in the deleted Amidakuji will be displayed vertically. J's score is the total of the points when selecting k consecutive vertical bars from bar 1 to vertical bar k.

Given the shape of the Amida lottery and the number of vertical bars k that J chooses as input, create a program that finds the minimum value of J's score.

input

The input consists of multiple datasets. Each dataset is given in the following format.

On the first line, four integers n, m, h, k are written separated by blanks. N (2 ≤ n ≤ 1000) is the number of vertical bars, and m (1 ≤ m ≤ 100000) is the horizontal bar. H (2 ≤ h ≤ 1000) represents the length of the vertical bar, and k (1 ≤ k ≤ n) represents the number of vertical bars you choose.

The following n lines contain the score written at the bottom of the vertical bar. The first line (1 ≤ i ≤ n) contains the positive integer si. Also, s1 + s2 + ... + sn ≤ 2000000000 = 2 × 109.

The following m lines indicate the position of the horizontal bar. The horizontal bars are numbered from 1 to m. The first line (1 ≤ i ≤ m) is the horizontal bar i. The two integers ai, bi (1 ≤ ai ≤ n --1, 1 ≤ bi ≤ h --1) representing the position are separated by blanks, and the horizontal bar i connects the vertical bar ai and the vertical bar ai + 1. , Indicates that the distance from the top edge of the horizontal bar i is bi. However, no two horizontal bars share an endpoint.

Of the scoring data, 20% of the points will have the lowest score for Mr. J if the horizontal bar is not deleted. Also, 30% of the points will satisfy n ≤ 20, m ≤ 30, h ≤ 10. 60% of the points are m ≤ 1000.

The end of the input is indicated by a line containing four zeros. The number of datasets does not exceed 10.

output

For each dataset, output the minimum score of Mr. J on one line.

Examples

Input

4 5 7 2
20
80
100
50
1 1
2 6
2 3
1 5
3 1
2 2 5 1
10
20
1 1
1 3
0 0 0 0

Output

100
10

Input

None

Output

None

### Response

```cpp
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
struct stick{
	int h;
	int l;
};

int main() {
	while (1) {
		int N, M, H, K; cin >> N >> M >> H >> K;
		if (!N)break;
		vector<int>scores(N);
		for (int i = 0; i < N; ++i) {
			cin >> scores[i];
		}
		vector<pair<int, int>>ss;
		for (int i = 0; i < M; ++i) {
			int a, b; cin >> a >> b;
			a--;
			ss.push_back(make_pair(b, a));
		}
		sort(ss.begin(), ss.end(),greater<pair<int,int>>());
		vector<int>nums(N);
		iota(nums.begin(), nums.end(), 0);
		vector<pair<int, int>>ps;
		for (auto s : ss) {
			ps.emplace_back(nums[s.second], nums[s.second + 1]);
			swap(nums[s.second], nums[s.second + 1]);
		}
		int ans = 2e9;
		{
			int nans = 0;
			for (int k = 0; k < K; ++k) {

				nans += scores[nums[k]];
			}
			ans = min(ans, nans);
		}
		for (int i = 0; i < M; ++i) {
			swap(scores[ps[i].first], scores[ps[i].second]);
			int nans = 0;
			for (int k = 0; k < K; ++k) {

				nans += scores[nums[k]];
			}
			ans = min(ans, nans);
			swap(scores[ps[i].first], scores[ps[i].second]);

		}
		cout << ans << endl;
	}

	return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Vova is playing a computer game. There are in total n turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is k.

During each turn Vova can choose what to do:

  * If the current charge of his laptop battery is strictly greater than a, Vova can just play, and then the charge of his laptop battery will decrease by a;
  * if the current charge of his laptop battery is strictly greater than b (b<a), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by b;
  * if the current charge of his laptop battery is less than or equal to a and b at the same time then Vova cannot do anything and loses the game.

Regardless of Vova's turns the charge of the laptop battery is always decreases.

Vova wants to complete the game (Vova can complete the game if after each of n turns the charge of the laptop battery is strictly greater than 0). Vova has to play exactly n turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.

Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 10^5) — the number of queries. Each query is presented by a single line.

The only line of the query contains four integers k, n, a and b (1 ≤ k, n ≤ 10^9, 1 ≤ b < a ≤ 10^9) — the initial charge of Vova's laptop battery, the number of turns in the game and values a and b, correspondingly.

Output

For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise.

Example

Input

6
15 5 3 2
15 5 4 3
15 5 2 1
15 5 5 1
16 7 5 2
20 5 7 3

Output

4
-1
5
2
0
1

Note

In the first example query Vova can just play 4 turns and spend 12 units of charge and then one turn play and charge and spend 2 more units. So the remaining charge of the battery will be 1.

In the second example query Vova cannot complete the game because even if he will play and charge the battery during each turn then the charge of the laptop battery will be 0 after the last turn.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9, MX = 1000007;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int x, int y) {
  x /= gcd(x, y);
  return x * y;
}
bool prime[MX], isprime[MX];
vector<int> v;
int cs = 0;
int fx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int fy[] = {0, 0, 1, -1, 1, -1, 1, -1};
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool InRng(int i, int j) { return ((i >= 1 && i < 9) && (j >= 1 && j < 9)); }
struct A {
  int u, v, id;
  A(int a, int b, int c) { u = a, v = b, id = c; }
};
bool operator<(A a, A b) { return a.v > b.v; }
void bs(long long k, long long n, long long a, long long b) {
  long long l = 0, r = n + 1, m, ans = 0;
  while (l < r) {
    m = (l + r) / 2;
    if (((m * a) + (n - m) * b) < k) {
      l = m + 1;
      ans = max(ans, m);
    } else
      r = m;
  }
  if (((ans * a) + (n - ans) * b) < k)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
void solve() {
  long long k, n, a, b, q;
  cin >> q;
  while (q--) {
    cin >> k >> n >> a >> b;
    bs(k, n, a, b);
  }
}
int main() {
  solve();
  return 0;
}

```


### Prompt

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

Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.

Constraints

* 1 ≤ length of the side ≤ 1,000
* N ≤ 1,000

Input

Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.

Output

For each data set, print "YES" or "NO".

Example

Input

3
4 3 5
4 3 6
8 8 8

Output

YES
NO
NO

### Response

```cpp
#include <cstdio>

int i,a,b,c;
int main()
{
	scanf("%d",&i);
		while(i!=0)
		{
			scanf("%d %d %d",&a,&b,&c);

			if(a*a+b*b==c*c||b*b+c*c==a*a||c*c+a*a==b*b)
			{
				printf("YES\n");
			}
			else printf("NO\n");
			i--;
		}

	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.

Assume that the cost of building a road connecting the i-th city and the j-th city is |i-j| \times D + A_{i} + A_{j}. For Takahashi, find the minimum possible total cost to achieve the objective.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 1 \leq D \leq 10^9
* 1 \leq A_{i} \leq 10^9
* A_{i} and D are integers.

Input

Input is given from Standard Input in the following format:

N D
A_1 A_2 ... A_N

Output

Print the minimum possible total cost.

Examples

Input

3 1
1 100 1

Output

106

Input

3 1000
1 100 1

Output

2202

Input

6 14
25 171 7 1 17 162

Output

497

Input

12 5
43 94 27 3 69 99 56 25 8 15 46 8

Output

658

### Response

```cpp
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll qmin(ll a, ll b){
	return (a < b) ? a : b;
}

ll n, d;
ll a[200200];
vector< pair< ll, pair<ll, ll> > > edge;

void solve(int l, int r){
	if(l >= r) return ;
	int mid = (l+r) >> 1;
	solve(l, mid);
	solve(mid+1, r);
	int mnpos1 = l;
	for(int i = l; i <= mid; i++){
		if(a[i] + (mid - i) * d < a[mnpos1] + (mid - mnpos1) * d) mnpos1 = i;
	}
	ll mnpos2 = mid+1;
	for(int i = mid+1; i <= r; i++){
		if(a[i] + (i - mid) * d < a[mnpos2] + (mnpos2 - mid) * d) mnpos2 = i;
	}
	for(int i = l; i <= mid; i++) edge.push_back(make_pair(a[mnpos2] + a[i] + (mnpos2 - i) * d, make_pair(i, mnpos2)));
	for(int i = mid+1; i <= r; i++) edge.push_back(make_pair(a[i] + a[mnpos1] + (i - mnpos1) * d, make_pair(i, mnpos1)));
}

int par[200200];
int get_par(int now){
	return par[now] = ((par[now] == now) ? now : get_par(par[now]));
}
void unite(int a, int b){
	par[get_par(a)] = get_par(b);
}
ll ans = 0;

int main(){
	scanf("%lld%lld", &n, &d);
	rep(i, n) par[i] = i;
	rep(i, n) scanf("%lld", &a[i]);
	solve(0, n-1);
	sort(edge.begin(), edge.end());
	rep(i, edge.size()){
		if(get_par(edge[i].second.first) != get_par(edge[i].second.second)){
			ans += edge[i].first;
			unite(edge[i].second.first, edge[i].second.second);
		}
	}
	cout << ans << endl;
	return 0;
}
```