### Prompt

Please create a solution in cpp to the following problem:

Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.

There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.

There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.

Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.

Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.

Input

The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.

Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.

The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.

Output

Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.

Examples

Input

3 1 8 10
10 8
5 7
11 9
3

Output

10

Input

2 2 10 18
10 4
20 6
5 3

Output

20

Note

In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int n, k, s, t;
int gas[MAXN];
struct Node {
  int c, v;
  friend bool operator<(const Node &p, const Node &q) { return p.c < q.c; }
} P[MAXN];
int pre[MAXN];
int check(int o) {
  int tt = 0;
  for (int i = 1; i <= k; i++) {
    int x = gas[i] - gas[i - 1];
    if (o < x) return 2147483647;
    tt += max(x, 2 * x - (o - x));
  }
  return tt;
}
int main() {
  scanf("%d%d%d%d", &n, &k, &s, &t);
  for (int i = 1; i <= n; i++) scanf("%d%d", &P[i].c, &P[i].v);
  for (int i = 1; i <= k; i++) scanf("%d", &gas[i]);
  sort(gas + 1, gas + k + 1);
  gas[++k] = s;
  int l = 1, r = n;
  sort(P + 1, P + n + 1);
  for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], P[i].v);
  while (l < r) {
    int mid = (l + r) >> 1;
    int o = pre[mid];
    int tt = check(o);
    if (tt <= t)
      r = mid;
    else
      l = mid + 1;
  }
  if (check(pre[l]) > t)
    puts("-1");
  else
    printf("%d\n", P[l].c);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given matrix a of size n × m, its elements are integers. We will assume that the rows of the matrix are numbered from top to bottom from 1 to n, the columns are numbered from left to right from 1 to m. We will denote the element on the intersecting of the i-th row and the j-th column as aij.

We'll call submatrix i1, j1, i2, j2 (1 ≤ i1 ≤ i2 ≤ n; 1 ≤ j1 ≤ j2 ≤ m) such elements aij of the given matrix that i1 ≤ i ≤ i2 AND j1 ≤ j ≤ j2. We'll call the area of the submatrix number (i2 - i1 + 1)·(j2 - j1 + 1). We'll call a submatrix inhomogeneous, if all its elements are distinct.

Find the largest (in area) inhomogenous submatrix of the given matrix.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 400) — the number of rows and columns of the matrix, correspondingly.

Each of the next n lines contains m integers aij (1 ≤ aij ≤ 160000) — the elements of the matrix.

Output

Print a single integer — the area of the optimal inhomogenous submatrix.

Examples

Input

3 3
1 3 1
4 5 6
2 6 1

Output

6

Input

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

Output

4

Input

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

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[405][405];
short int up[405][405][405];
int f[405][405];
int ret;
bool bo[160010];
void init() {
  int i, j, k, l, r;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  ret = 0;
  for (l = 1; l <= m; l++) {
    for (r = l + 1; r <= m; r++) {
      int now = n;
      for (i = n; i >= 1; i--) {
        now = min(now, i);
        while (now && a[now][l] != a[now][r] && !bo[a[now][l]] &&
               !bo[a[now][r]]) {
          bo[a[now][l]] = bo[a[now][r]] = 1;
          now--;
        }
        up[i][l][r] = i - now;
        bo[a[i][l]] = bo[a[i][r]] = 0;
      }
    }
    int now = n;
    for (i = n; i >= 1; i--) {
      now = min(now, i);
      while (now && !bo[a[now][l]]) {
        bo[a[now][l]] = 1;
        now--;
      }
      ret = max(i - now, ret);
      bo[a[i][l]] = 0;
    }
  }
}
void solve() {
  int i, j, k, l, r, len;
  for (i = 1; i <= n; i++) {
    memset(f, 0, sizeof(f));
    for (l = 1; l <= m - 1; l++) {
      f[l][l + 1] = up[i][l][l + 1];
      ret = max(ret, (int)f[l][l + 1] * 2);
    }
    for (len = 3; len <= m; len++) {
      for (l = 1; l <= m - len + 1; l++) {
        r = l + len - 1;
        f[l][r] = min(min(f[l + 1][r], f[l][r - 1]), (int)up[i][l][r]);
        ret = max(ret, (int)f[l][r] * (r - l + 1));
      }
    }
  }
  printf("%d\n", ret);
}
int main() {
  init();
  solve();
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.

A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.

More formally, if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x2 - x1 is divisible by 2.

Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.

Help him implement counting of these units before painting.

<image>

Input

The only line of input contains four integers x1, y1, x2, y2 ( - 109 ≤ x1 ≤ x2 ≤ 109, - 109 ≤ y1 ≤ y2 ≤ 109) — the coordinates of the centers of two cells.

Output

Output one integer — the number of cells to be filled.

Examples

Input

1 1 5 5

Output

13

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x1, y1, x2, y2;
  long long area;
  cin >> x1 >> y1 >> x2 >> y2;
  if ((y2 - y1) % 2 == 0) {
    area = ((y2 - y1) / 2 + 1) * ((x2 - x1) / 2 + 1) +
           ((y2 - y1) / 2) * ((x2 - x1) / 2);
  } else
    area = ((y2 - y1 + 1) / 2) * (x2 - x1 + 1);
  cout << area;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1.

There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points.

Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively.

The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i.

It is guaranteed that no segments coincide.

Output

Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks).

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

Examples

Input

12 6
1 3
3 7
5 7
7 11
9 11
11 3

Output

Yes

Input

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

Output

Yes

Input

10 3
1 2
3 2
7 2

Output

No

Input

10 2
1 6
2 7

Output

Yes

Note

The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 2e5 + 5;
struct HASH {
  size_t operator()(const pair<int, int>& x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};
pair<int, int> edge[MAXN];
unordered_set<pair<int, int>, HASH> st;
void impossible() {
  cout << "No\n";
  exit(0);
}
void possible() {
  cout << "Yes\n";
  exit(0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    edge[i] = {min(u, v), max(u, v)};
    st.insert(edge[i]);
  }
  for (int k = 1; k < n; k++) {
    if (n % k) continue;
    bool flag = true;
    for (int i = 1; i <= m; i++) {
      int u = edge[i].first, v = edge[i].second;
      if (!st.count({(u + k) % n, (v + k) % n}) &&
          !st.count({(v + k) % n, (u + k) % n})) {
        flag = false;
        break;
      }
    }
    if (flag) possible();
  }
  impossible();
}

```


### Prompt

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

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

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

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

Input

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

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

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

Output

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

Examples

Input

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

Output

4

Input

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

Output

4

Note

In the first example:

<image>

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

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gi() {
  T f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int INF = 0x3f3f3f3f, N = 300003, M = N << 1;
int n, m;
int tot, head[N], ver[M], nxt[M];
queue<int> q;
int in[N];
struct Edge {
  int u, v;
} a[N];
int cnt, f[N];
inline void add(int u, int v) {
  ver[++tot] = v, nxt[tot] = head[u], head[u] = tot, ++in[v];
}
inline void toposort() {
  while (!q.empty()) q.pop();
  for (int i = 1; i <= n; i += 1)
    if (!in[i]) q.push(i);
  cnt = n;
  while (!q.empty()) {
    int u = q.front(), sz = q.size();
    q.pop();
    --cnt;
    if (sz == 1) f[u] += cnt;
    if (sz == 2) {
      int v = q.front();
      bool ok = true;
      for (int i = head[v]; i; i = nxt[i]) {
        int p = ver[i];
        if (in[p] == 1) {
          ok = false;
          break;
        }
      }
      if (ok)
        f[u] += cnt - 1;
      else
        f[u] = -INF;
    }
    for (int i = head[u]; i; i = nxt[i]) {
      int v = ver[i];
      if (!(--in[v])) q.push(v);
    }
  }
}
int main() {
  n = gi<int>(), m = gi<int>();
  for (int i = 1; i <= m; i += 1) {
    a[i].u = gi<int>(), a[i].v = gi<int>();
    add(a[i].u, a[i].v);
  }
  toposort();
  tot = 0;
  memset(head, 0, sizeof head);
  memset(in, 0, sizeof in);
  for (int i = 1; i <= m; i += 1) add(a[i].v, a[i].u);
  toposort();
  int ans = 0;
  for (int i = 1; i <= n; i += 1)
    if (f[i] >= n - 2) ++ans;
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

Petya has n positive integers a1, a2, ..., an.

His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.

Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.

Input

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the number of Petya's numbers.

Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.

Output

Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.

Examples

Input

3
ab
de
aj

Output

47

Input

5
abcdef
ghij
bdef
accbd
g

Output

136542

Input

3
aa
jj
aa

Output

44

Note

In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.

In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3].

In the second example the numbers after the restoration can look like: [11, 22, 11].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 62) - 1;
const long long MOD = 1e9 + 7;
const int MAX = 1e9;
const long long int N = 102;
using namespace std;
int bPow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1ll) {
      res = 1ll * res * a % MOD;
    }
    b >>= 1;
    a = 1ll * a * a % MOD;
  }
  return res;
}
int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<int> mpf(N, 0);
void sieve() {
  for (int i = 2; i < N; ++i) {
    if (!mpf[i])
      for (int j = 2 * i; j < N; j += i) {
        mpf[j] = i;
      }
  }
}
void solve() {
  int n;
  cin >> n;
  map<char, int> values;
  set<char> startChars;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    startChars.insert(s[0]);
    reverse(s.begin(), s.end());
    int it = 1;
    for (auto j : s) {
      values[j] += it;
      it *= 10;
    }
  }
  vector<pair<int, char>> a;
  for (auto val : values) {
    a.emplace_back(val.second, val.first);
  }
  sort(a.rbegin(), a.rend());
  bool start = false;
  int it = 1, ans = 0;
  for (auto i : a) {
    if (startChars.find(i.second) == startChars.end() and !start) {
      start = true;
    } else {
      ans += it * i.first;
      it++;
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

At first, there was a legend related to the name of the problem, but now it's just a formal statement.

You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible.

The function f_k(x) can be described in the following way:

  * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x);
  * sort list d in non-descending order;
  * take d_{k + 1} as a result.

If there are multiple optimal answers you can print any of them.

Input

The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent.

The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order.

It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5.

Output

Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them.

Example

Input

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

Output

3
500000000
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    int i;
    for (i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    int dist = INT_MAX;
    for (i = k + 1; i <= n; i++) {
      int mid = (a[i] + a[i - k]) / 2;
      int temp = max(a[i] - mid, mid - a[i - k]);
      if (temp < dist) {
        ans = mid;
        dist = temp;
      }
    }
    cout << ans << endl;
  }
}

```


### Prompt

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

Takahashi has an N \times N grid. The square at the i-th row and the j-th column of the grid is denoted by (i,j). Particularly, the top-left square of the grid is (1,1), and the bottom-right square is (N,N).

An integer, 0 or 1, is written on M of the squares in the Takahashi's grid. Three integers a_i,b_i and c_i describe the i-th of those squares with integers written on them: the integer c_i is written on the square (a_i,b_i).

Takahashi decides to write an integer, 0 or 1, on each of the remaining squares so that the condition below is satisfied. Find the number of such ways to write integers, modulo 998244353.

* For all 1\leq i < j\leq N, there are even number of 1s in the square region whose top-left square is (i,i) and whose bottom-right square is (j,j).

Constraints

* 2 \leq N \leq 10^5
* 0 \leq M \leq min(5 \times 10^4,N^2)
* 1 \leq a_i,b_i \leq N(1\leq i\leq M)
* 0 \leq c_i \leq 1(1\leq i\leq M)
* If i \neq j, then (a_i,b_i) \neq (a_j,b_j).
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1 c_1
:
a_M b_M c_M

Output

Print the number of possible ways to write integers, modulo 998244353.

Examples

Input

3 3
1 1 1
3 1 0
2 3 1

Output

8

Input

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

Output

32

Input

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

Output

0

Input

4 8
1 1 1
1 2 0
3 2 1
1 4 0
2 1 1
1 3 0
3 4 1
4 4 1

Output

4

Input

100000 0

Output

342016343

### Response

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 1e5 + 3;
const LL mod = 998244353;
map<pair<int,int>,int> S;
int p1[MC],p2[MC],p0[MC];

int main(){
	LL N,M; cin >> N >> M;
	fill(p0,p0+MC,-1);
	fill(p1,p1+MC,-1);
	fill(p2,p2+MC,-1);
	LL z = N*(N+1)/2;
	repp(i,0,M){
		LL a,b,c; cin >> a >> b >> c;
		if(a == b) p0[a] = c;
		if(a > b) swap(a,b);
		auto it = S.find(MP(a,b));
		if(it != S.end()){
			if(b-a >= 3){
				if((*it).second != c) return cout << 0 << endl, 0;
			} else if(b-a == 2){
				p2[a] = ((*it).second != c);
			} else if(b-a == 1){
				p1[a] = ((*it).second != c);
			}
		} else {
			S[MP(a,b)] = c;
			--z;
		}
	}
	repp(i,1,N+1){
		if(p2[i] == 0){
			if(p0[i+1] == 1) return cout << 0 << endl, 0;
			if(p0[i+1] == -1) --z;
			p0[i+1] = 0;
		} else if(p2[i] == 1){
			if(p0[i+1] == 0) return cout << 0 << endl, 0;
			if(p0[i+1] == -1) --z;
			p0[i+1] = 1;
		}
		if(p1[i] == 0){
			if(p0[i] != -1 && p0[i+1] != -1 && p0[i] != p0[i+1]) return cout << 0 << endl, 0;
			if(p0[i] == -1 || p0[i+1] == -1) --z;
			if(p0[i] != -1) p0[i+1] = p0[i];
			else p0[i] = p0[i+1];
		} else if(p1[i] == 1){
			if(p0[i] != -1 && p0[i+1] != -1 && p0[i] == p0[i+1]) return cout << 0 << endl, 0;
			if(p0[i] == -1 || p0[i+1] == -1) --z;
			if(p0[i] != -1) p0[i+1] = 1-p0[i];
			else if(p0[i+1] != -1) p0[i] = 1-p0[i+1];
		}
	}
	LL ans = 1;
	for(LL k = 2 ; z > 0 ; k = k*k%mod){
		if(z&1) (ans *= k) %= mod;
		z /= 2;
	}
	cout << ans << endl;
	return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is not.

A permutation triple of permutations of length n (a, b, c) is called a Lucky Permutation Triple if and only if <image>. The sign ai denotes the i-th element of permutation a. The modular equality described above denotes that the remainders after dividing ai + bi by n and dividing ci by n are equal.

Now, he has an integer n and wants to find a Lucky Permutation Triple. Could you please help him?

Input

The first line contains a single integer n (1 ≤ n ≤ 105).

Output

If no Lucky Permutation Triple of length n exists print -1.

Otherwise, you need to print three lines. Each line contains n space-seperated integers. The first line must contain permutation a, the second line — permutation b, the third — permutation c.

If there are multiple solutions, print any of them.

Examples

Input

5

Output

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

Input

2

Output

-1

Note

In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds:

  * <image>;
  * <image>;
  * <image>;
  * <image>;
  * <image>.

In Sample 2, you can easily notice that no lucky permutation triple exists.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    puts("-1");
    return 0;
  }
  vector<int> v, vv;
  for (int i = 0; i < n; i++) {
    v.push_back(i);
    printf("%d ", i);
  }
  puts("");
  for (int i = 1; i < n; i++) {
    printf("%d ", i);
    vv.push_back(i);
  }
  vv.push_back(0);
  puts("0");
  for (int i = 0; i < n; i++) printf("%d ", (v[i] + vv[i]) % n);
  puts("");
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.

In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles.

Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the upper right cell of a rectangle.

Output

In a single line print the sum of all values in the cells of the table.

Examples

Input

2
1 1 2 3
2 2 3 3

Output

10

Input

2
1 1 3 3
1 1 3 3

Output

18

Note

Note to the first sample test:

Values of the table in the first three rows and columns will be as follows:

121

121

110

So, the sum of values will be equal to 10.

Note to the second sample test:

Values of the table in the first three rows and columns will be as follows:

222

222

222

So, the sum of values will be equal to 18.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
vector<long long int> b;
int m[1000][1000];
int main() {
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      m[i][j] = 0;
    }
  }
  int n, x, y, x2, y2, c = 0;
  cin >> n;
  while (n--) {
    cin >> x >> y >> x2 >> y2;
    x--;
    y--;
    for (int i = x; i < x2; i++) {
      for (int j = y; j < y2; j++) {
        m[i][j]++;
        c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

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

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

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

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

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

Input

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

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

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

Output

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

Examples

Input

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

Output

3

Input

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

Output

1

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 50;
int n, k;
int a[N], dp[N], vis[N];
vector<int> G[N];
int getval(int comp, int im0) {
  if (im0 != -1)
    return 1 + comp + im0;
  else
    return -(1 + comp);
}
void dfs(int v, int mn) {
  int comp = 0, imcomp = -1;
  vis[v] = 1;
  for (int nxt : G[v]) {
    if (vis[nxt]) continue;
    if (a[nxt] >= mn) dfs(nxt, mn);
    if (dp[nxt] < 0)
      comp += -dp[nxt];
    else
      imcomp = max(imcomp, dp[nxt]);
  }
  dp[v] = getval(comp, imcomp);
}
void reroot(int v, int p, int mn, int up_val, int& res) {
  int comp = 0, im[2] = {-1, -1};
  vector<int> vs;
  if (p != -1) vs.push_back(up_val);
  for (int nxt : G[v])
    if (nxt != p) vs.push_back(dp[nxt]);
  for (int val : vs) {
    if (val < 0)
      comp += -val;
    else
      for (int j = 0; j < (2); ++j)
        if (val > im[j]) swap(val, im[j]);
  }
  res = max(res, 1 + comp + max(0, im[0]));
  for (int nxt : G[v]) {
    if (nxt == p || a[nxt] < mn) continue;
    if (dp[nxt] < 0)
      reroot(nxt, v, mn, getval(comp + dp[nxt], im[0]), res);
    else {
      reroot(nxt, v, mn, getval(comp, (dp[nxt] == im[0] ? im[1] : im[0])), res);
    }
  }
}
int solve(int mn) {
  fill(vis, vis + n, 0);
  fill(dp, dp + n, 0);
  int res = 0;
  for (int i = 0; i < (n); ++i) {
    if (vis[i] || a[i] < mn) continue;
    dfs(i, mn);
    reroot(i, -1, mn, -1, res);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int l = 0, r = (int)1e6 + 1, mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (solve(mid) >= k)
      l = mid;
    else
      r = mid;
  }
  cout << l << '\n';
}

```


### Prompt

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

We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.

The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.

Input

The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.

Output

Print the minimum number of steps modulo 109 + 7.

Examples

Input

ab

Output

1

Input

aab

Output

3

Note

The first example: "ab"  →  "bba".

The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
int main() {
  string s;
  cin >> s;
  long long cntb = 0;
  long long ans = 0;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == 'b') {
      cntb++;
      cntb %= (long long)(1000 * 1000 * 1000 + 7);
    } else {
      ans += cntb;
      ans %= (long long)(1000 * 1000 * 1000 + 7);
      cntb *= 2;
      cntb %= (long long)(1000 * 1000 * 1000 + 7);
    }
  }
  ans %= (long long)(1000 * 1000 * 1000 + 7);
  cout << ans;
}

```


### Prompt

Generate a cpp solution to the following problem:

Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.

Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.

Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.

Input

A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.

Output

In a single line print the number of times Manao has to push a button in the worst-case scenario.

Examples

Input

2

Output

3

Input

3

Output

7

Note

Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int pushes = 0;
  int buttons;
  cin >> buttons;
  for (int i = 1; i <= buttons; i++) {
    pushes += 1 + (i * (buttons - i));
  }
  cout << pushes << endl;
  return 0;
}

```


### Prompt

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

Welcome! Everything is fine.

You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity.

You have a list of k pairs of people who have arrived in a new inhabited neighborhood. You need to assign each of the 2k people into one of the 2k houses. Each person will be the resident of exactly one house, and each house will have exactly one resident.

Of course, in the neighborhood, it is possible to visit friends. There are 2k - 1 roads, each of which connects two houses. It takes some time to traverse a road. We will specify the amount of time it takes in the input. The neighborhood is designed in such a way that from anyone's house, there is exactly one sequence of distinct roads you can take to any other house. In other words, the graph with the houses as vertices and the roads as edges is a tree.

The truth is, these k pairs of people are actually soulmates. We index them from 1 to k. We denote by f(i) the amount of time it takes for the i-th pair of soulmates to go to each other's houses.

As we have said before, you will need to assign each of the 2k people into one of the 2k houses. You have two missions, one from the entities in The Good Place and one from the entities of The Bad Place. Here they are:

  * The first mission, from The Good Place, is to assign the people into the houses such that the sum of f(i) over all pairs i is minimized. Let's define this minimized sum as G. This makes sure that soulmates can easily and efficiently visit each other;
  * The second mission, from The Bad Place, is to assign the people into the houses such that the sum of f(i) over all pairs i is maximized. Let's define this maximized sum as B. This makes sure that soulmates will have a difficult time to visit each other.

What are the values of G and B?

Input

The first line of input contains a single integer t (1 ≤ t ≤ 500) denoting the number of test cases. The next lines contain descriptions of the test cases.

The first line of each test case contains a single integer k denoting the number of pairs of people (1 ≤ k ≤ 10^5). The next 2k - 1 lines describe the roads; the i-th of them contains three space-separated integers a_i, b_i, t_i which means that the i-th road connects the a_i-th and b_i-th houses with a road that takes t_i units of time to traverse (1 ≤ a_i, b_i ≤ 2k, a_i ≠ b_i, 1 ≤ t_i ≤ 10^6). It is guaranteed that the given roads define a tree structure.

It is guaranteed that the sum of the k in a single file is at most 3 ⋅ 10^5.

Output

For each test case, output a single line containing two space-separated integers G and B.

Example

Input

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

Output

15 33
6 6

Note

For the sample test case, we have a minimum sum equal to G = 15. One way this can be achieved is with the following assignment:

  * The first pair of people get assigned to houses 5 and 6, giving us f(1) = 5;
  * The second pair of people get assigned to houses 1 and 4, giving us f(2) = 6;
  * The third pair of people get assigned to houses 3 and 2, giving us f(3) = 4.

Note that the sum of the f(i) is 5 + 6 + 4 = 15.

We also have a maximum sum equal to B = 33. One way this can be achieved is with the following assignment:

  * The first pair of people get assigned to houses 1 and 4, giving us f(1) = 6;
  * The second pair of people get assigned to houses 6 and 2, giving us f(2) = 14;
  * The third pair of people get assigned to houses 3 and 5, giving us f(3) = 13.

Note that the sum of the f(i) is 6 + 14 + 13 = 33.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 500;
const int INF = 1e9;
int fst[N], nxt[N], mm;
struct Edge {
  int v, w;
} e[N];
void ade(int u, int v, int w) {
  e[++mm] = (Edge){v, w}, nxt[mm] = fst[u], fst[u] = mm;
}
long long f[N], sum, dep[N];
int n, root, rsize;
int siz[N];
void dfs(int u, int fa) {
  siz[u] = 1;
  f[u] = 0;
  int mx = 0;
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
    mx = max(mx, siz[v]);
    f[u] += f[v];
    if (siz[v] & 1) f[u] += e[i].w;
  }
  mx = max(mx, n - siz[u]);
  if (mx < rsize) rsize = mx, root = u;
}
void dfs2(int u, int fa) {
  sum += dep[u];
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = e[i].v;
    if (v == fa) continue;
    dep[v] = dep[u] + e[i].w;
    dfs2(v, u);
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    n *= 2;
    for (int i = 1; i <= n; i++) fst[i] = 0;
    mm = 0;
    for (int i = 1, u, v, w; i < n; i++)
      scanf("%d%d%d", &u, &v, &w), ade(u, v, w), ade(v, u, w);
    root = 0, rsize = INF;
    dfs(1, 0);
    dep[root] = 0;
    sum = 0;
    dfs2(root, 0);
    printf("%lld ", f[1]);
    printf("%lld\n", sum);
  }
}

```


### Prompt

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

There are n segments [l_i, r_i] for 1 ≤ i ≤ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.

To optimize testing process you will be given multitest.

Input

The first line contains one integer T (1 ≤ T ≤ 50000) — the number of queries. Each query contains description of the set of segments. Queries are independent.

First line of each query contains single integer n (2 ≤ n ≤ 10^5) — number of segments. It is guaranteed that ∑{n} over all queries does not exceed 10^5.

The next n lines contains two integers l_i, r_i per line (1 ≤ l_i ≤ r_i ≤ 2 ⋅ 10^5) — the i-th segment.

Output

For each query print n integers t_1, t_2, ..., t_n (t_i ∈ \{1, 2\}) — for each segment (in the same order as in the input) t_i equals 1 if the i-th segment will belongs to the first group and 2 otherwise.

If there are multiple answers, you can print any of them. If there is no answer, print -1.

Example

Input

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

Output

2 1
-1
1 1 2

Note

In the first query the first and the second segments should be in different groups, but exact numbers don't matter.

In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is -1.

In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 6 possible is correct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 2, oo = 1e9, M = 1e6;
long long const OO = 1e18;
double const eps = 1e-6, PI = acos(-1);
int mod = oo + 7;
int n, an[N];
pair<pair<int, int>, int> seg[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> seg[i].first.first >> seg[i].first.second;
      seg[i].second = i;
      an[i] = 0;
    }
    sort(seg, seg + n);
    int r = seg[0].first.second;
    int i = 1;
    for (; i < n; i++)
      if (seg[i].first.first > r)
        break;
      else
        r = max(r, seg[i].first.second);
    if (i == n) {
      cout << -1 << '\n';
      continue;
    }
    for (int j = 0; j < i; j++) an[seg[j].second] = 1;
    for (int j = i; j < n; j++) an[seg[j].second] = 2;
    bool y = 0;
    for (int i = 0; i < n - 1; i++)
      if (an[i] != an[i + 1]) y = 1;
    if (y)
      for (int i = 0; i < n; i++) cout << an[i] << ' ';
    else
      cout << -1;
    cout << '\n';
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

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

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

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

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

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

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

Constraints

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

Input

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

Output

Print the fewest steps in a line.

Example

Input

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

Output

8

### Response

```cpp
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = { 'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle{int f[N2], space, MD;};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
  int sum = 0;
  for(int i = 0 ; i < N2 ; i++){
    if(pz.f[i] == N2) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

bool isSolved(){
  for(int i = 0 ; i < N2 ; i++) if(state.f[i] != i + 1) return false;
  return true;
}

bool dfs(int depth, int prev){
  if(state.MD == 0) return true;
  if(depth + state.MD > limit) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for(int r = 0 ; r < 4 ; r++){
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
    if(max(prev, r)-min(prev, r) == 2) continue;
    tmp = state;
    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
    swap(state.f[tx * N + ty], state.f[sx * N + sy]);
    state.space = tx * N + ty;
    if(dfs(depth + 1, r)) {path[depth] = r; return true;}
    state = tmp;
  }

  return false;
}

string iterative_deepening(Puzzle in){
  in.MD = getAllMD(in);

  for(limit = in.MD ; limit <= LIMIT ; limit++){
    state = in;
    if(dfs(0, -100)){
      string ans = "";
      for(int i = 0 ; i < limit ; i++) ans += dir[path[i]];
      return ans;
    }
  }

  return "ubsolvable";
}

int main(){
  for(int i = 0 ; i < N2 ; i++)
    for(int j = 0 ; j < N2 ; j++)
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for(int i = 0 ; i < N2 ; i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;

  return 0;
}
```


### Prompt

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

This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson!

Since Alex doesn't want to get expelled, he wants to know the number of working days left until the end of the term, so he can attend physical education lessons during these days. But in BSU calculating the number of working days is a complicated matter:

There are n days left before the end of the term (numbered from 1 to n), and initially all of them are working days. Then the university staff sequentially publishes q orders, one after another. Each order is characterised by three numbers l, r and k:

  * If k = 1, then all days from l to r (inclusive) become non-working days. If some of these days are made working days by some previous order, then these days still become non-working days;
  * If k = 2, then all days from l to r (inclusive) become working days. If some of these days are made non-working days by some previous order, then these days still become working days.

Help Alex to determine the number of working days left after each order!

Input

The first line contains one integer n, and the second line — one integer q (1 ≤ n ≤ 109, 1 ≤ q ≤ 3·105) — the number of days left before the end of the term, and the number of orders, respectively.

Then q lines follow, i-th line containing three integers li, ri and ki representing i-th order (1 ≤ li ≤ ri ≤ n, 1 ≤ ki ≤ 2).

Output

Print q integers. i-th of them must be equal to the number of working days left until the end of the term after the first i orders are published.

Example

Input

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

Output

2
0
2
3
1
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& fout, const vector<T>& vec) {
  for (const auto& el : vec) {
    fout << el << ' ';
  }
  return fout;
}
template <class T>
istream& operator>>(istream& fin, vector<T>& vec) {
  for (size_t i = 0; i < vec.size(); ++i) {
    cin >> vec[i];
  }
  return fin;
}
vector<int> res;
vector<int> an;
vector<int> bn;
bool dfs(int k = 0, int skip_check = 0, int mask = 0) { return 0; }
set<pair<int, int>> removed;
int n, q;
int lft;
void add(int l, int r, int k) {
  vector<pair<int, int>> to_remove;
  vector<pair<int, int>> to_add;
  if (k == 1) to_add.push_back({r, l});
  auto pos = removed.upper_bound({r, l});
  while (true) {
    if (pos == removed.end()) {
      if (pos == removed.begin()) break;
      std::advance(pos, -1);
      continue;
    }
    if (pos->second >= r) {
      if (pos == removed.begin()) break;
      std::advance(pos, -1);
      continue;
    }
    if (pos->first <= l) break;
    to_remove.push_back(*pos);
    if (pos->second < l) {
      to_add.push_back({l, pos->second});
    }
    if (pos->first > r) {
      to_add.push_back({pos->first, r});
    }
    if (pos == removed.begin()) break;
    std::advance(pos, -1);
  }
  for (auto el : to_remove) {
    lft += el.first - el.second;
    removed.erase(el);
  }
  for (auto el : to_add) {
    lft -= el.first - el.second;
    removed.insert(el);
  }
}
int Solve() {
  cin >> n >> q;
  lft = n;
  while (q--) {
    int l, r, k;
    cin >> l >> r >> k;
    switch (k) {
      case 1:
        add(l, r + 1, k);
        break;
      case 2:
        add(l, r + 1, k);
        break;
    }
    std::cout << lft << '\n';
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Solve();
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are n registered users and the i-th of them has contribution ti.

Limak is a little polar bear and he's new into competitive programming. He doesn't even have an account in Codeforces but he is able to upvote existing blogs and comments. We assume that every registered user has infinitely many blogs and comments.

  * Limak can spend b minutes to read one blog and upvote it. Author's contribution will be increased by 5.
  * Limak can spend c minutes to read one comment and upvote it. Author's contribution will be increased by 1.

Note that it's possible that Limak reads blogs faster than comments.

Limak likes ties. He thinks it would be awesome to see a tie between at least k registered users. To make it happen he is going to spend some time on reading and upvoting. After that, there should exist an integer value x that at least k registered users have contribution exactly x.

How much time does Limak need to achieve his goal?

Input

The first line contains four integers n, k, b and c (2 ≤ k ≤ n ≤ 200 000, 1 ≤ b, c ≤ 1000) — the number of registered users, the required minimum number of users with the same contribution, time needed to read and upvote a blog, and time needed to read and upvote a comment, respectively.

The second line contains n integers t1, t2, ..., tn (|ti| ≤ 109) where ti denotes contribution of the i-th registered user.

Output

Print the minimum number of minutes Limak will spend to get a tie between at least k registered users.

Examples

Input

4 3 100 30
12 2 6 1

Output

220

Input

4 3 30 100
12 2 6 1

Output

190

Input

6 2 987 789
-8 42 -4 -65 -8 -8

Output

0

Note

In the first sample, there are 4 registered users and Limak wants a tie between at least 3 of them. Limak should behave as follows.

  * He spends 100 minutes to read one blog of the 4-th user and increase his contribution from 1 to 6.
  * Then he spends 4·30 = 120 minutes to read four comments of the 2-nd user and increase his contribution from 2 to 6 (four times it was increaded by 1).

In the given scenario, Limak spends 100 + 4·30 = 220 minutes and after that each of users 2, 3, 4 has contribution 6.

In the second sample, Limak needs 30 minutes to read a blog and 100 minutes to read a comment. This time he can get 3 users with contribution equal to 12 by spending 100 + 3·30 = 190 minutes:

  * Spend 2·30 = 60 minutes to read two blogs of the 1-st user to increase his contribution from 2 to 12.
  * Spend 30 + 100 minutes to read one blog and one comment of the 3-rd user. His contribution will change from 6 to 6 + 5 + 1 = 12.

### Response

```cpp
#include <bits/stdc++.h>
const int MAXN = 2e5;
const int SHIFT = 1e9;
using namespace std;
int arr[MAXN];
vector<int> conds[5];
vector<int> lvls[5];
int ptrs[5][2];
long long b, c;
long long countCost(int lvl, int elem) {
  return ((lvl - elem) / 5) * b + ((lvl - elem) % 5) * c;
}
int main() {
  int n, k;
  cin >> n >> k >> b >> c;
  b = min(b, 5 * c);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    arr[i] += SHIFT;
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; ++i) {
    conds[arr[i] % 5].push_back(arr[i]);
    for (int j = 0; j < 5; ++j) lvls[(arr[i] + j) % 5].push_back(arr[i] + j);
  }
  long long ans = 2e18;
  for (int t = 0; t < 5; ++t) {
    fill(ptrs[0], ptrs[0] + 10, 0);
    int cnt = 0;
    long long cost = 0;
    int prev = 0;
    for (int lvl : lvls[t]) {
      cost += cnt * countCost(lvl, prev);
      prev = lvl;
      for (int r = 0; r < 5; ++r)
        while (ptrs[r][1] < (int)conds[r].size() &&
               conds[r][ptrs[r][1]] <= lvl) {
          cost += countCost(lvl, conds[r][ptrs[r][1]]);
          ptrs[r][1]++;
          cnt++;
        }
      while (cnt > k) {
        long long worst = -1;
        for (int r = 0; r < 5; ++r)
          if (ptrs[r][0] < ptrs[r][1])
            worst = max(worst, countCost(lvl, conds[r][ptrs[r][0]]));
        for (int r = 0; r < 5; ++r)
          if (ptrs[r][0] < ptrs[r][1] &&
              worst == countCost(lvl, conds[r][ptrs[r][0]])) {
            cost -= worst;
            ptrs[r][0]++;
            cnt--;
            break;
          }
      }
      if (cnt == k) ans = min(ans, cost);
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

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

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

Constraints

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

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Examples

Input

6
abcabc

Output

Yes

Input

6
abcadc

Output

No

Input

1
z

Output

No

### Response

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

int main() {

  int n;
  std::cin >> n;

  if (n & 1)
    return puts("No"), 0;

  std::string str;
  std::cin >> str;

  puts(str.substr(0, n/2) == str.substr(n/2, n/2) ? "Yes" : "No");
  return 0;
}

```


### Prompt

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

M-kun is a competitor in AtCoder, whose highest rating is X.
In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:

* From 400 through 599: 8-kyu
* From 600 through 799: 7-kyu
* From 800 through 999: 6-kyu
* From 1000 through 1199: 5-kyu
* From 1200 through 1399: 4-kyu
* From 1400 through 1599: 3-kyu
* From 1600 through 1799: 2-kyu
* From 1800 through 1999: 1-kyu

What kyu does M-kun have?

Constraints

* 400 \leq X \leq 1999
* X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the kyu M-kun has, as an integer. For example, if he has 8-kyu, print `8`.

Examples

Input

725

Output

7

Input

1600

Output

2

### Response

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

using namespace std;
int x;
int main(){
    cin >> x;
    cout << 8 - (x - 400) / 200;
}

```


### Prompt

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

Andrew plays a game called "Civilization". Dima helps him.

The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a road between any contiguous cities vi and vi + 1 (1 ≤ i < k). The length of the described path equals to (k - 1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.

During the game events of two types take place:

  1. Andrew asks Dima about the length of the longest path in the region where city x lies.
  2. Andrew asks Dima to merge the region where city x lies with the region where city y lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them.

Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.

Input

The first line contains three integers n, m, q (1 ≤ n ≤ 3·105; 0 ≤ m < n; 1 ≤ q ≤ 3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly.

Each of the following m lines contains two integers, ai and bi (ai ≠ bi; 1 ≤ ai, bi ≤ n). These numbers represent the road between cities ai and bi. There can be at most one road between two cities.

Each of the following q lines contains one of the two events in the following format:

  * 1 xi. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city xi (1 ≤ xi ≤ n).
  * 2 xi yi. It is the request Andrew gives to Dima to merge the region that contains city xi and the region that contains city yi (1 ≤ xi, yi ≤ n). Note, that xi can be equal to yi.

Output

For each event of the first type print the answer on a separate line.

Examples

Input

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

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
int par[300001], res[300001];
int fnd(int x) {
  if (par[x] == x) return x;
  return par[x] = fnd(par[x]);
}
void uni(int x, int y) {
  int a = fnd(x);
  int b = fnd(y);
  if (a == b) return;
  int c = res[a];
  c = (c + 1) / 2;
  int d = res[b];
  d = (d + 1) / 2;
  int e = max(res[a], res[b]);
  res[a] = c + d + 1;
  res[a] = max(res[a], e);
  par[b] = a;
}
int vis[300001];
vector<int> vc[300001];
int dfs(int c, int p) {
  vis[c] = 1;
  if (p == 0)
    par[c] = c;
  else
    par[c] = p;
  int ret = 0;
  int m2 = 0;
  for (int i = (0); i < (vc[c].size()); ++i) {
    if (vc[c][i] != p) {
      int t = dfs(vc[c][i], c) + 1;
      if (t > ret) {
        m2 = ret;
        ret = t;
      } else if (t > m2)
        m2 = t;
      else if (t == ret)
        m2 = t;
      res[c] = max(res[c], res[vc[c][i]]);
    }
  }
  res[c] = max(res[c], ret + m2);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, c, d = 0, e, f = 0, g = 0, h = 0, x, y, z;
  cin >> a >> b >> c;
  for (int i = (0); i < (b); ++i) {
    cin >> d >> e;
    vc[d].push_back(e);
    vc[e].push_back(d);
  }
  for (int i = 1; i <= a; i++) {
    if (vis[i] == 0) {
      dfs(i, 0);
    }
  }
  for (int i = (0); i < (c); ++i) {
    cin >> d >> e;
    if (d == 1) {
      f = fnd(e);
      cout << res[f] << endl;
    } else {
      cin >> f;
      uni(e, f);
    }
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below:

    //input: integers x, k, p
    a = x;
    for(step = 1; step <= k; step = step + 1){
        rnd = [random integer from 1 to 100];
        if(rnd <= p)
            a = a * 2;
        else
            a = a + 1;
    }

    s = 0;

    while(remainder after dividing a by 2 equals 0){
        a = a / 2;
        s = s + 1;
    }

Now Valera wonders: given the values x, k and p, what is the expected value of the resulting number s?

Input

The first line of the input contains three integers x, k, p (1 ≤ x ≤ 109; 1 ≤ k ≤ 200; 0 ≤ p ≤ 100).

Output

Print the required expected value. Your answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Examples

Input

1 1 50

Output

1.0000000000000

Input

5 3 0

Output

3.0000000000000

Input

5 3 25

Output

1.9218750000000

Note

If the concept of expected value is new to you, you can read about it by the link:

http://en.wikipedia.org/wiki/Expected_value

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(0)
using namespace std;
inline int read(void) {
  int n = 0;
  bool b = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') b = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') n = (n << 3) + (n << 1) + c - 48, c = getchar();
  return b ? n : -n;
}
int x, k, ans;
double p, f[210][210];
int main() {
  x = read();
  k = read();
  p = read();
  p /= 100.0;
  for (int i = 0; i <= k; ++i) {
    for (int j = x + i; !(j & 1); j >>= 1) {
      ++f[0][i];
    }
  }
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j <= k; ++j) {
      if (j) f[i + 1][j - 1] += (1 - p) * f[i][j];
      if ((j << 1) <= k) f[i + 1][j << 1] += p * (f[i][j] + 1);
    }
  }
  printf("%.15lf", f[k][0]);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Lena is a programmer. She got a task to solve at work.

There is an empty set of pairs of integers and n queries to process. Each query is one of three types:

  1. Add a pair (a, b) to the set.
  2. Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
  3. For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set.

Help Lena to process the queries.

Input

The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries.

Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query.

A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type.

An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed.

An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.

Output

For the queries of the third type print on a separate line the desired maximal value of x·q + y.

If there are no pairs in the set print "EMPTY SET".

Example

Input

7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1

Output

EMPTY SET
5
99
5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e6 + 2;
const int M = 1e5;
const int mod = 0;
const int inf = 1e9;
const long long INF = 3e18 + 1;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
void files() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
struct node {
  node *l, *r;
  pair<long long, long long> val;
  node(pair<long long, long long> val = {0, -INF}) : val(val) {
    l = nullptr;
    r = nullptr;
  }
} *r = new node();
struct li_chao {
  stack<pair<node *, pair<long long, long long>>> s;
  void save() { s.push({nullptr, {-INF, -INF}}); }
  void rollback() {
    while (s.top().first != nullptr) {
      s.top().first->val = s.top().second;
      s.pop();
    }
    s.pop();
  }
  node *upd(pair<long long, long long> val, node *v = r, long long tl = -inf,
            long long tr = inf) {
    if (v == nullptr) v = new node();
    if (tl == tr) return v;
    long long tm = tl + tr >> 1;
    if (v->val.first * tm + v->val.second <= val.first * tm + val.second) {
      s.push({v, v->val});
      swap(val, v->val);
    }
    if (v->val.first * tl + v->val.second <= val.first * tl + val.second)
      v->l = upd(val, v->l, tl, tm);
    else
      v->r = upd(val, v->r, tm + 1, tr);
    return v;
  }
  long long get(long long x, node *v = r, long long tl = -inf,
                long long tr = inf) {
    if (v == nullptr) return -INF;
    long long tm = tl + tr >> 1;
    if (tl == tr) return v->val.first * x + v->val.second;
    if (x <= tm)
      return max(v->val.first * x + v->val.second, get(x, v->l, tl, tm));
    else
      return max(v->val.first * x + v->val.second, get(x, v->r, tm + 1, tr));
  }
} LI;
int n, del[N];
pair<long long, long long> was[N];
long long ans[N];
struct tree {
  vector<pair<long long, long long>> t[N];
  pair<long long, long long> q[N];
  set<pair<long long, long long>> vals;
  void upd(int l, int r, pair<long long, long long> val, int v = 1, int tl = 1,
           int tr = n) {
    if (l <= tl && tr <= r) {
      t[v].push_back(val);
      return;
    }
    if (r < tl || tr < l) return;
    int tm = tl + tr >> 1;
    upd(l, r, val, v * 2, tl, tm);
    upd(l, r, val, v * 2 + 1, tm + 1, tr);
  }
  void dfs(int v = 1, int tl = 1, int tr = n) {
    LI.save();
    for (auto it : t[v]) {
      r = LI.upd(it);
    }
    if (tl == tr) {
      ans[tl] = LI.get(q[tl].first);
      LI.rollback();
      return;
    }
    int tm = tl + tr >> 1;
    dfs(v * 2, tl, tm);
    dfs(v * 2 + 1, tm + 1, tr);
    LI.rollback();
  }
} t;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    ans[i] = -INF;
    long long tp, a, b;
    cin >> tp >> a;
    if (tp == 1) {
      cin >> b;
      was[i] = {a, b};
      del[i] = -1;
    }
    if (tp == 2) {
      t.upd(a, i - 1, was[a]);
      del[a] = 1;
    }
    if (tp == 3) {
      t.q[i] = {a, 1};
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (del[i] == -1) {
      t.upd(i, n, was[i]);
    }
  }
  t.dfs();
  for (int i = 1; i <= n; ++i) {
    if (t.q[i].second == 1) {
      if (ans[i] == -INF)
        cout << "EMPTY SET\n";
      else
        cout << ans[i] << '\n';
    }
  }
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Ali is Hamed's little brother and tomorrow is his birthday. Hamed wants his brother to earn his gift so he gave him a hard programming problem and told him if he can successfully solve it, he'll get him a brand new laptop. Ali is not yet a very talented programmer like Hamed and although he usually doesn't cheat but this time is an exception. It's about a brand new laptop. So he decided to secretly seek help from you. Please solve this problem for Ali.

An n-vertex weighted rooted tree is given. Vertex number 1 is a root of the tree. We define d(u, v) as the sum of edges weights on the shortest path between vertices u and v. Specifically we define d(u, u) = 0. Also let's define S(v) for each vertex v as a set containing all vertices u such that d(1, u) = d(1, v) + d(v, u). Function f(u, v) is then defined using the following formula:

<image>

The goal is to calculate f(u, v) for each of the q given pair of vertices. As the answer can be rather large it's enough to print it modulo 109 + 7.

Input

In the first line of input an integer n (1 ≤ n ≤ 105), number of vertices of the tree is given.

In each of the next n - 1 lines three space-separated integers ai, bi, ci (1 ≤ ai, bi ≤ n, 1 ≤ ci ≤ 109) are given indicating an edge between ai and bi with weight equal to ci.

In the next line an integer q (1 ≤ q ≤ 105), number of vertex pairs, is given.

In each of the next q lines two space-separated integers ui, vi (1 ≤ ui, vi ≤ n) are given meaning that you must calculate f(ui, vi).

It is guaranteed that the given edges form a tree.

Output

Output q lines. In the i-th line print the value of f(ui, vi) modulo 109 + 7.

Examples

Input

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

Output

10
1000000005
1000000002
23
1000000002

Input

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

Output

999968753
49796
999961271
999991235
999958569
45130

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int mo = 1e9 + 7;
struct Val {
  int x2, x1, x0;
  friend Val operator+(const Val &a, const Val &b) {
    return Val{(a.x2 + b.x2) % mo, (a.x1 + b.x1) % mo, (a.x0 + b.x0) % mo};
  }
  friend Val operator-(const Val &a, const Val &b) {
    return Val{(a.x2 - b.x2) % mo, (a.x1 - b.x1) % mo, (a.x0 - b.x0) % mo};
  }
  friend Val operator*(const Val &a, const int d) {
    Val c;
    c.x2 = (a.x2 + 2ll * d * a.x1 + (long long)d * d % mo * a.x0) % mo;
    c.x1 = (a.x1 + 1ll * d * a.x0) % mo;
    c.x0 = a.x0;
    return c;
  }
} f[120000], g[120000], sum[120000];
int w[120000], ff[21][120000], dep[120000], Q, n;
vector<pair<int, int> > E[120000];
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; i >= 0; --i)
    if (dep[x] - dep[y] >= 1 << i) x = ff[i][x];
  if (x == y) return x;
  for (int i = 20; i >= 0; --i)
    if (ff[i][x] != ff[i][y]) x = ff[i][x], y = ff[i][y];
  return ff[0][x];
}
void dfs(int x, int fa) {
  ff[0][x] = fa;
  for (int i = 1; i <= 20; ++i) ff[i][x] = ff[i - 1][ff[i - 1][x]];
  f[x].x2 = f[x].x1 = 0;
  f[x].x0 = 1;
  for (auto e : E[x])
    if (e.first != fa) {
      dep[e.first] = dep[x] + 1;
      w[e.first] = (w[x] + e.second) % mo;
      dfs(e.first, x);
      f[x] = f[x] + f[e.first] * e.second;
    }
}
void dp(int x, int fa) {
  Val tmp = {0, 0, 1};
  for (auto e : E[x])
    if (e.first != fa) tmp = tmp + f[e.first] * e.second;
  for (auto e : E[x])
    if (e.first != fa) {
      int y = e.first;
      sum[y] = (sum[x] + (tmp - f[y] * e.second)) * e.second;
      g[y] = (tmp + g[x] - f[y] * e.second) * e.second;
      dp(y, x);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    int x, y, k;
    scanf("%d%d%d", &x, &y, &k);
    E[x].push_back(make_pair(y, k));
    E[y].push_back(make_pair(x, k));
  }
  dfs(1, 0);
  dp(1, 0);
  scanf("%d", &Q);
  for (int _ = 1; _ <= Q; ++_) {
    int u, v;
    scanf("%d%d", &u, &v);
    int lca = LCA(u, v), dist = ((long long)w[u] + w[v] - 2 * w[lca]) % mo, ans;
    if (lca == v)
      ans = (2ll * (f[u].x2 + (sum[u] - sum[v] * dist).x2) - (f[u] + g[u]).x2) %
            mo;
    else
      ans = (2ll * (f[v] * dist).x2 - (f[u] + g[u]).x2) % mo;
    printf("%d\n", (ans + mo) % mo);
  }
}

```


### Prompt

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

Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.

By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.

Polycarp has M minutes of time. What is the maximum number of points he can earn?

Input

The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).

The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.

Output

Print the maximum amount of points Polycarp can earn in M minutes.

Examples

Input

3 4 11
1 2 3 4

Output

6

Input

5 5 10
1 2 4 8 16

Output

7

Note

In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.

In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int t[100], k;
int get(int m, int n) {
  int res = 0;
  vector<int> a;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      a.push_back(t[j]);
    }
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < (int(a.size())); i++) {
    if (m >= a[i]) {
      m -= a[i];
      res++;
    }
  }
  return res;
}
int main() {
  int n, m, sum = 0;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &t[i]);
    sum += t[i];
  }
  sort(t + 1, t + k + 1);
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (m < sum * i) {
      break;
    }
    ans = max(ans, (k + 1) * i + get(m - sum * i, n - i));
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.

On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (called vertices), some of which are connected using n - 1 line segments (edges) so that each pair of vertices is connected by a path (a sequence of one or more edges).

To decipher the prophecy, Heidi needs to perform a number of steps. The first is counting the number of lifelines in the tree – these are paths of length 2, i.e., consisting of two edges. Help her!

Input

The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n). It is guaranteed that the input represents a tree.

Output

Print one integer – the number of lifelines in the tree.

Examples

Input

4
1 2
1 3
1 4

Output

3

Input

5
1 2
2 3
3 4
3 5

Output

4

Note

In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> point[10010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) point[i].clear();
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    point[a].push_back(b);
    point[b].push_back(a);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int t = point[i].size();
    ans += t * (t - 1) / 2;
  }
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands:

  * 'W' — move one cell up;
  * 'S' — move one cell down;
  * 'A' — move one cell left;
  * 'D' — move one cell right.

Let Grid(s) be the grid of minimum possible area such that there is a position in the grid where you can place the robot in such a way that it will not fall from the grid while running the sequence of commands s. For example, if s = DSAWWAW then Grid(s) is the 4 × 3 grid:

  1. you can place the robot in the cell (3, 2);
  2. the robot performs the command 'D' and moves to (3, 3);
  3. the robot performs the command 'S' and moves to (4, 3);
  4. the robot performs the command 'A' and moves to (4, 2);
  5. the robot performs the command 'W' and moves to (3, 2);
  6. the robot performs the command 'W' and moves to (2, 2);
  7. the robot performs the command 'A' and moves to (2, 1);
  8. the robot performs the command 'W' and moves to (1, 1).

<image>

You have 4 extra letters: one 'W', one 'A', one 'S', one 'D'. You'd like to insert at most one of these letters in any position of sequence s to minimize the area of Grid(s).

What is the minimum area of Grid(s) you can achieve?

Input

The first line contains one integer T (1 ≤ T ≤ 1000) — the number of queries.

Next T lines contain queries: one per line. This line contains single string s (1 ≤ |s| ≤ 2 ⋅ 10^5, s_i ∈ \{W, A, S, D\}) — the sequence of commands.

It's guaranteed that the total length of s over all queries doesn't exceed 2 ⋅ 10^5.

Output

Print T integers: one per query. For each query print the minimum area of Grid(s) you can achieve.

Example

Input

3
DSAWWAW
D
WA

Output

8
2
4

Note

In the first query you have to get string DSAWW\underline{D}AW.

In second and third queries you can not decrease the area of Grid(s).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  vector<long long> x(n + 1, 0), y(n + 1, 0);
  for (int i = 0; i < n; i++) {
    x[i + 1] = x[i];
    y[i + 1] = y[i];
    if (s[i] == 'W')
      x[i + 1]++;
    else if (s[i] == 'A')
      y[i + 1]--;
    else if (s[i] == 'S')
      x[i + 1]--;
    else
      y[i + 1]++;
  }
  vector<long long> xlh(n + 1), xll(n + 1), ylh(n + 1), yll(n + 1);
  for (int i = 1; i <= n; i++) {
    xlh[i] = max(xlh[i - 1], x[i]);
    xll[i] = min(xll[i - 1], x[i]);
    ylh[i] = max(ylh[i - 1], y[i]);
    yll[i] = min(yll[i - 1], y[i]);
  }
  vector<long long> xrh(n + 1), xrl(n + 1), yrh(n + 1), yrl(n + 1);
  xrh[n] = xrl[n] = x[n];
  yrh[n] = yrl[n] = y[n];
  for (int i = n - 1; i >= 0; i--) {
    xrh[i] = max(xrh[i + 1], x[i]);
    xrl[i] = min(xrl[i + 1], x[i]);
    yrh[i] = max(yrh[i + 1], y[i]);
    yrl[i] = min(yrl[i + 1], y[i]);
  }
  long long ans = (xlh[n] - xll[n] + 1) * (ylh[n] - yll[n] + 1);
  for (int i = 0; i < n; i++) {
    ans = min(ans, (max({xlh[i], xrh[i] + 1, x[i] + 1}) -
                    min({xll[i], xrl[i] + 1, x[i] + 1}) + 1) *
                       (max(ylh[i], yrh[i]) - min(yll[i], yrl[i]) + 1));
    ans = min(ans, (max({xlh[i], xrh[i] - 1, x[i] - 1}) -
                    min({xll[i], xrl[i] - 1, x[i] - 1}) + 1) *
                       (max(ylh[i], yrh[i]) - min(yll[i], yrl[i]) + 1));
    ans = min(ans, (max(xlh[i], xrh[i]) - min(xll[i], xrl[i]) + 1) *
                       (max({ylh[i], yrh[i] - 1, y[i] - 1}) -
                        min({yll[i], yrl[i] - 1, y[i] - 1}) + 1));
    ans = min(ans, (max(xlh[i], xrh[i]) - min(xll[i], xrl[i]) + 1) *
                       (max({ylh[i], yrh[i] + 1, y[i] + 1}) -
                        min({yll[i], yrl[i] + 1, y[i] + 1}) + 1));
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
}

```


### Prompt

Create a solution in CPP for the following problem:

Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:

Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the set, or v is in the set, or both are in the set. Mahmoud has found the following algorithm:

  * Root the tree at node 1.
  * Count the number of nodes at an even depth. Let it be evenCnt.
  * Count the number of nodes at an odd depth. Let it be oddCnt.
  * The answer is the minimum between evenCnt and oddCnt.

The depth of a node in a tree is the number of edges in the shortest path between this node and the root. The depth of the root is 0.

Ehab told Mahmoud that this algorithm is wrong, but he didn't believe because he had tested his algorithm against many trees and it worked, so Ehab asked you to find 2 trees consisting of n nodes. The algorithm should find an incorrect answer for the first tree and a correct answer for the second one.

Input

The only line contains an integer n (2 ≤ n ≤ 105), the number of nodes in the desired trees.

Output

The output should consist of 2 independent sections, each containing a tree. The algorithm should find an incorrect answer for the tree in the first section and a correct answer for the tree in the second. If a tree doesn't exist for some section, output "-1" (without quotes) for that section only.

If the answer for a section exists, it should contain n - 1 lines, each containing 2 space-separated integers u and v (1 ≤ u, v ≤ n), which means that there's an undirected edge between node u and node v. If the given graph isn't a tree or it doesn't follow the format, you'll receive wrong answer verdict.

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

Examples

Input

2

Output

-1
1 2

Input

8

Output

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

Note

In the first sample, there is only 1 tree with 2 nodes (node 1 connected to node 2). The algorithm will produce a correct answer in it so we printed  - 1 in the first section, but notice that we printed this tree in the second section.

In the second sample:

In the first tree, the algorithm will find an answer with 4 nodes, while there exists an answer with 3 nodes like this: <image> In the second tree, the algorithm will find an answer with 3 nodes which is correct: <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n < 6)
    cout << -1 << endl;
  else {
    cout << "1 2" << endl;
    cout << "2 3" << endl;
    cout << "2 4" << endl;
    cout << "4 5" << endl;
    cout << "4 6" << endl;
    for (int i = 7; i <= n; i++) cout << "4 " << i << "\n";
  }
  for (int i = 0; i < n - 1; i++) cout << i + 1 << " " << i + 2 << "\n";
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that user A sent user B a message at time t1, and user B sent user A a message at time t2. If 0 < t2 - t1 ≤ d, then user B's message was an answer to user A's one. Users A and B are considered to be friends if A answered at least one B's message or B answered at least one A's message.

You are given the log of messages in chronological order and a number d. Find all pairs of users who will be considered to be friends.

Input

The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at most 20 characters long, consisting of lowercase letters ('a' ... 'z'), and ti is an integer (0 ≤ ti ≤ 10000). It is guaranteed that the lines are given in non-decreasing order of ti's and that no user sent a message to himself. The elements in the lines are separated by single spaces.

Output

In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.

Examples

Input

4 1
vasya petya 1
petya vasya 2
anya ivan 2
ivan anya 4

Output

1
petya vasya

Input

1 1000
a b 0

Output

0

Note

In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct ektamessage {
  string sender, receiver;
  int time;
};
int main() {
  int i, j, n, d;
  vector<ektamessage> v;
  vector<pair<string, string> > ans;
  map<pair<string, string>, vector<int> > pathaise;
  map<pair<string, string>, int> nisi;
  ektamessage x;
  cin >> n >> d;
  for (i = 0; i < n; i++) {
    cin >> x.sender >> x.receiver >> x.time;
    v.push_back(x);
    pathaise[make_pair(x.sender, x.receiver)].push_back(x.time);
  }
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (v[i].sender == v[j].receiver && v[i].receiver == v[j].sender &&
          v[i].time != v[j].time && abs(v[i].time - v[j].time) <= d &&
          !nisi[make_pair(v[i].sender, v[j].sender)] &&
          !nisi[make_pair(v[i].sender, v[j].sender)]) {
        ans.push_back(make_pair(v[i].sender, v[j].sender));
        nisi[make_pair(v[i].sender, v[j].sender)] = 1;
        nisi[make_pair(v[j].sender, v[i].sender)] = 1;
      }
    }
  }
  int len = ans.size();
  cout << len << "\n";
  for (i = 0; i < len; i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
  return 0;
}

```


### Prompt

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

Input

The only line of input contains three integers a1, a2, a3 (1 ≤ a1, a2, a3 ≤ 20), separated by spaces.

Output

Output a single integer.

Examples

Input

2 3 2

Output

5

Input

13 14 1

Output

14

Input

14 5 9

Output

464

Input

17 18 3

Output

53

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
long double eps = 1e-9;
long long pp = 1000000007;
long long mo(long long a, long long pp) {
  if (a >= 0 && a < pp) return a;
  a %= pp;
  if (a < 0) a += pp;
  return a;
}
long long powmod(long long a, long long b, long long pp) {
  long long ans = 1;
  for (; b; b >>= 1, a = mo(a * a, pp))
    if (b & 1) ans = mo(ans * a, pp);
  return ans;
}
long long read() {
  long long ans = 0;
  char last = ' ', ch = getchar();
  while (ch < '0' || ch > '9') last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
  if (last == '-') ans = -ans;
  return ans;
}
int main() {
  int x, y, tep, n;
  cin >> x >> y >> n;
  for (int i = 2; i <= n; i++) {
    tep = x + y;
    x = y;
    y = tep;
  }
  cout << y << endl;
  return 0;
}

```


### Prompt

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

Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.

You are given two matrices A and B of size n × m, each of which consists of 0 and 1 only. You can apply the following operation to the matrix A arbitrary number of times: take any submatrix of the matrix A that has at least two rows and two columns, and invert the values in its corners (i.e. all corners of the submatrix that contain 0, will be replaced by 1, and all corners of the submatrix that contain 1, will be replaced by 0). You have to answer whether you can obtain the matrix B from the matrix A.

<image> An example of the operation. The chosen submatrix is shown in blue and yellow, its corners are shown in yellow.

Ramesses don't want to perform these operations by himself, so he asks you to answer this question.

A submatrix of matrix M is a matrix which consist of all elements which come from one of the rows with indices x_1, x_1+1, …, x_2 of matrix M and one of the columns with indices y_1, y_1+1, …, y_2 of matrix M, where x_1, x_2, y_1, y_2 are the edge rows and columns of the submatrix. In other words, a submatrix is a set of elements of source matrix which form a solid rectangle (i.e. without holes) with sides parallel to the sides of the original matrix. The corners of the submatrix are cells (x_1, y_1), (x_1, y_2), (x_2, y_1), (x_2, y_2), where the cell (i,j) denotes the cell on the intersection of the i-th row and the j-th column.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 500) — the number of rows and the number of columns in matrices A and B.

Each of the next n lines contain m integers: the j-th integer in the i-th line is the j-th element of the i-th row of the matrix A (0 ≤ A_{ij} ≤ 1).

Each of the next n lines contain m integers: the j-th integer in the i-th line is the j-th element of the i-th row of the matrix B (0 ≤ B_{ij} ≤ 1).

Output

Print "Yes" (without quotes) if it is possible to transform the matrix A to the matrix B using the operations described above, and "No" (without quotes), if it is not possible. You can print each letter in any case (upper or lower).

Examples

Input

3 3
0 1 0
0 1 0
1 0 0
1 0 0
1 0 0
1 0 0

Output

Yes

Input

6 7
0 0 1 1 0 0 1
0 1 0 0 1 0 1
0 0 0 1 0 0 1
1 0 1 0 1 0 0
0 1 0 0 1 0 1
0 1 0 1 0 0 1
1 1 0 1 0 1 1
0 1 1 0 1 0 0
1 1 0 1 0 0 1
1 0 1 0 0 1 0
0 1 1 0 1 0 0
0 1 1 1 1 0 1

Output

Yes

Input

3 4
0 1 0 1
1 0 1 0
0 1 0 1
1 1 1 1
1 1 1 1
1 1 1 1

Output

No

Note

The examples are explained below.

<image> Example 1. <image> Example 2. <image> Example 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[510][510], b[510][510];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> b[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == b[i][j]) continue;
      a[i][j] ^= 1;
      a[i][1] ^= 1;
      a[1][j] ^= 1;
      a[1][1] ^= 1;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] != b[i][j]) {
        cout << "No";
        return 0;
      }
  cout << "Yes";
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs.

The stairs consists of n steps. The steps are numbered from bottom to top, it means that the lowest step has number 1, and the highest step has number n. Above each of them there is a pointer with the direction (up or down) Olga should move from this step. As soon as Olga goes to the next step, the direction of the pointer (above the step she leaves) changes. It means that the direction "up" changes to "down", the direction "down" — to the direction "up".

Olga always moves to the next step in the direction which is shown on the pointer above the step.

If Olga moves beyond the stairs, she will fall and wake up. Moving beyond the stairs is a moving down from the first step or moving up from the last one (it means the n-th) step.

In one second Olga moves one step up or down according to the direction of the pointer which is located above the step on which Olga had been at the beginning of the second.

For each step find the duration of the dream if Olga was at this step at the beginning of the dream.

Olga's fall also takes one second, so if she was on the first step and went down, she would wake up in the next second.

Input

The first line contains single integer n (1 ≤ n ≤ 106) — the number of steps on the stairs.

The second line contains a string s with the length n — it denotes the initial direction of pointers on the stairs. The i-th character of string s denotes the direction of the pointer above i-th step, and is either 'U' (it means that this pointer is directed up), or 'D' (it means this pointed is directed down).

The pointers are given in order from bottom to top.

Output

Print n numbers, the i-th of which is equal either to the duration of Olga's dream or to  - 1 if Olga never goes beyond the stairs, if in the beginning of sleep she was on the i-th step.

Examples

Input

3
UUD

Output

5 6 3

Input

10
UUDUDUUDDU

Output

5 12 23 34 36 27 18 11 6 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c[1000010];
  long long n = 0, i, up = 0, down = 0, l = 0, r = 0, x = 0, y = 0;
  cin >> n;
  cin >> c + 1;
  for (i = 1; i <= n; i++) {
    x += 2 * up;
    y -= 2 * down;
    if (c[i - 1] == 'U') up++, x++;
    if (c[i - 1] == 'D') down--, y++;
    while (down - 1 < up && r < n)
      if (c[++r] == 'D') {
        down++;
        y += 2 * (r - i) + 1;
      }
    while (down < up && r == n)
      if (c[++l] == 'U') {
        up--;
        x -= 2 * (i - l) - 1;
      }
    if (down - 1 == up)
      cout << x + y + i - 1 << " ";
    else
      cout << x + y + n - i + 1 << " ";
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.

You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

Input

The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012).

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

Output

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

Examples

Input

3
4 5 6

Output

YES
NO
NO

Note

The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool prime[1000010];
void sieve() {
  prime[0] = prime[1] = 1;
  for (int i = 2; i * i < 1000010; ++i)
    if (!prime[i])
      for (int j = i * i; j <= 1000010; j += i) prime[j] = 1;
}
int main() {
  sieve();
  int n;
  long long int x, sq;
  scanf("%d", &n);
  while (n--) {
    scanf("%I64d", &x);
    sq = sqrt(x);
    puts(!prime[sq] && sq * sq == x ? "YES" : "NO");
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.

The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge.

When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7).

Input

The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.

It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation.

Output

Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7).

Examples

Input

5
-1 -1 4 3 -1

Output

2

Note

For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long pow(long long num, long long power) {
  if (power == 0) return 1;
  if (power == 1) return num;
  long long t = pow(num, power / 2);
  return power % 2 ? t * t * num : t * t;
}
int check(int);
int binarysearch(int len) {
  int lo = 1, hi = len, mid, flag;
  while (lo <= hi) {
    mid = hi + lo >> 1;
    (flag = check(mid)) ? lo = mid + 1 : hi = mid - 1;
  }
  return mid - 1 + flag;
}
const int N = 1000 * 100 + 5;
const int MOD = 1000 * 1000 * 1000 + 7;
int debug = 1;
int check(int a) { return a; }
inline int inp() {
  int n = 0, s = 1, c = getchar();
  if (c == '-') s = -1;
  while (c < 48) c = getchar();
  while (c > 47) n = (n << 3) + (n << 1) + c - '0', c = getchar();
  return n * s;
}
int a[N];
int vis1[N], vis2[N];
long long dp[2005][2005], fact[2005];
int solve(int a, int b) {
  if (a == 0) return fact[b];
  if (b < 0) return 0;
  if (a < 0) return 0;
  if (dp[a][b] != -1) return dp[a][b];
  long long &res = dp[a][b];
  res = 0;
  if (b) res = (res + (long long)b * solve(a - 1, b) % MOD) % MOD;
  res = (res + (long long)(a - 1) * solve(a - 2, b + 1) % MOD) % MOD;
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  int i, j, n, t;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i + 1];
  for (i = 1; i < n + 1; i++)
    if (a[i] != -1) {
      vis1[a[i]] = 1;
    } else {
      vis2[i] = 1;
    }
  fact[0] = 1;
  for (i = 1; i < 2005; i++) fact[i] = fact[i - 1] * (long long)i % MOD;
  for (i = 0; i < 2005; i++)
    for (j = 0; j < 2005; j++) dp[i][j] = -1;
  int c, d;
  c = d = 0;
  for (i = 1; i < n + 1; i++) {
    if (vis1[i] && vis2[i])
      d++;
    else if (vis2[i])
      c++;
  }
  cout << solve(c, d);
  cin >> i;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

Constraints

* 1 \leq N \leq 10^5

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of positive integers less than or equal to N that have an odd number of digits.

Examples

Input

11

Output

9

Input

136

Output

46

Input

100000

Output

90909

### Response

```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,k,pre,sum=0;
	cin>>N;
	for(int i=1;i<=N;i++){
		k=0;pre=i;
		while(pre>0){k++;pre/=10;}
		sum+=k%2;
	}
	cout<<sum;
}
```