### Prompt

Generate a CPP solution to the following problem:

Nikola owns a large warehouse which is illuminated by N light bulbs, numbered 1 to N. At the exit of the warehouse, there are S light switches, numbered 1 to S. Each switch swaps the on/off state for some light bulbs, so if a light bulb is off, flipping the switch turns it on, and if the light bulb is on, flipping the switch turns it off.

At the end of the day, Nikola wants to turn all the lights off. To achieve this, he will flip some of the light switches at the exit of the warehouse, but since Nikola is lazy, he wants to flip the _minimum_ number of switches required to turn all the lights off. Since Nikola was not able to calculate the minimum number of switches, he asked you to help him. During a period of D days, Nikola noted which light bulbs were off and which were on at the end of each day. He wants you to tell him the minimum number of switches he needed to flip to turn all the lights off for each of the D days or tell him that it's impossible.

Input

First line contains three integers, N, S and D (1 ≤ N ≤ 10^3, 1 ≤ S ≤ 30, 1 ≤ D ≤ 10^3) – representing number of light bulbs, the number of light switches, and the number of days respectively.

The next S lines contain the description of each light switch as follows: The first number in the line, C_i (1 ≤ C_i ≤ N), represents the number of light bulbs for which the on/off state is swapped by light switch i, the next C_i numbers (sorted in increasing order) represent the indices of those light bulbs.

The next D lines contain the description of light bulbs for each day as follows: The first number in the line, T_i (1 ≤ T_i ≤ N), represents the number of light bulbs which are on at the end of day i, the next T_i numbers (sorted in increasing order) represent the indices of those light bulbs.

Output

Print D lines, one for each day. In the i^{th} line, print the minimum number of switches that need to be flipped on day i, or -1 if it's impossible to turn all the lights off.

Example

Input

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

Output

2
2
3
-1

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
int n, s, d;
const int mod = 1145141;
struct Bitset {
  unsigned long long a[16];
  inline Bitset() { memset(a, 0, sizeof(a)); }
  inline void reset() { memset(a, 0, sizeof(a)); }
  inline void set(int i) { a[i >> 6] |= (1ull << (i & 63)); }
  inline Bitset &operator^=(const Bitset &oth) {
    for (int i = 0; i < 16; i++) a[i] ^= oth.a[i];
    return *this;
  }
  inline Bitset operator^(const Bitset &oth) const {
    Bitset ret;
    for (int i = 0; i < 16; i++) ret.a[i] = a[i] ^ oth.a[i];
    return ret;
  }
  inline int getval() const {
    unsigned long long ret = 0;
    for (int i = 0; i < 16; i++) {
      ret = (ret + a[i] % mod * (i + 1) * (i + 1) % mod) % mod;
    }
    return ret;
  }
  inline bool operator==(const Bitset &oth) const {
    for (int i = 0; i < 16; i++)
      if (a[i] != oth.a[i]) return false;
    return true;
  }
};
namespace Hash_Table {
int head[1145141] = {0}, cnt, nxt[(1 << 20) + 1] = {0}, val[(1 << 20) + 1];
Bitset bs[(1 << 20) + 1];
void insert(Bitset NOW, int VAL) {
  int valu = NOW.getval();
  for (int now = head[valu]; now; now = nxt[now]) {
    if (bs[now] == NOW) {
      val[now] = min(val[now], VAL);
      return;
    }
  }
  ++cnt;
  val[cnt] = VAL;
  bs[cnt] = NOW;
  nxt[cnt] = head[valu];
  head[valu] = cnt;
}
int query(Bitset NOW) {
  int valu = NOW.getval();
  for (int now = head[valu]; now; now = nxt[now]) {
    if (bs[now] == NOW) {
      return val[now];
    }
  }
  return INF;
}
}  // namespace Hash_Table
Bitset swi[31];
int bit_count[1 << 20];
Bitset full;
Bitset second_part[1 << 20];
int second_val[1 << 20];
int main() {
  cin >> n >> s >> d;
  for (int i = 1; i <= n; ++i) full.set(i);
  for (int i = 0; i < 1 << 20; ++i) {
    if (i) bit_count[i] = bit_count[i & (i - 1)] + 1;
  }
  for (int i = 0; i < s; ++i) {
    int c;
    scanf("%d", &c);
    while (c--) {
      int a;
      scanf("%d", &a);
      swi[i].set(a);
    }
  }
  int two = min(10, s / 2), one = s - two;
  for (int i = 0; i < 1 << one; ++i) {
    Bitset now;
    for (int j = 0; j < s; ++j) {
      if ((i >> j) & 1) {
        now ^= swi[j];
      }
    }
    Hash_Table::insert(now, bit_count[i]);
  }
  for (int i = 0; i < 1 << two; ++i) {
    Bitset now;
    for (int j = 0; j < s; ++j) {
      if ((i >> j) & 1) {
        now ^= swi[j + one];
      }
    }
    second_part[i] = now;
    second_val[i] = bit_count[i];
  }
  for (int i = 1; i <= d; ++i) {
    Bitset query;
    int c;
    scanf("%d", &c);
    while (c--) {
      int a;
      scanf("%d", &a);
      query.set(a);
    }
    int rest = INF;
    for (int mask = 0; mask < 1 << two; ++mask) {
      rest = min(rest, second_val[mask] +
                           Hash_Table::query(query ^ second_part[mask]));
    }
    if (rest >= INF) rest = -1;
    printf("%d\n", rest);
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

In a far away kingdom lives a very greedy king. To defend his land, he built n guard towers. Apart from the towers the kingdom has two armies, each headed by a tyrannical and narcissistic general. The generals can't stand each other, specifically, they will never let soldiers of two armies be present in one tower.

During defence operations to manage a guard tower a general has to send part of his army to that tower. Each general asks some fee from the king for managing towers. As they live in a really far away kingdom, each general evaluates his fee in the following weird manner: he finds two remotest (the most distant) towers, where the soldiers of his army are situated and asks for the fee equal to the distance. Each tower is represented by a point on the plane with coordinates (x, y), and the distance between two points with coordinates (x1, y1) and (x2, y2) is determined in this kingdom as |x1 - x2| + |y1 - y2|.

The greedy king was not exactly satisfied with such a requirement from the generals, that's why he only agreed to pay one fee for two generals, equal to the maximum of two demanded fees. However, the king is still green with greed, and among all the ways to arrange towers between armies, he wants to find the cheapest one. Each tower should be occupied by soldiers of exactly one army.

He hired you for that. You should find the minimum amount of money that will be enough to pay the fees. And as the king is also very scrupulous, you should also count the number of arrangements that will cost the same amount of money. As their number can be quite large, it is enough for the king to know it as a remainder from dividing by 109 + 7.

Two arrangements are distinct if the sets of towers occupied by soldiers of the first general are distinct.

Input

The first line contains an integer n (2 ≤ n ≤ 5000), n is the number of guard towers. Then follow n lines, each of which contains two integers x, y — the coordinates of the i-th tower (0 ≤ x, y ≤ 5000). No two towers are present at one point.

Pretest 6 is one of the maximal tests for this problem.

Output

Print on the first line the smallest possible amount of money that will be enough to pay fees to the generals.

Print on the second line the number of arrangements that can be carried out using the smallest possible fee. This number should be calculated modulo 1000000007 (109 + 7).

Examples

Input

2
0 0
1 1

Output

0
2

Input

4
0 0
0 1
1 0
1 1

Output

1
4

Input

3
0 0
1000 1000
5000 5000

Output

2000
2

Note

In the first example there are only two towers, the distance between which is equal to 2. If we give both towers to one general, then we well have to pay 2 units of money. If each general receives a tower to manage, to fee will be equal to 0. That is the smallest possible fee. As you can easily see, we can obtain it in two ways.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, cnt, a[5001], b[5001], vis[5001];
int dfs(int x, int mid, int type) {
  vis[x] = type;
  for (int i = 1; i <= n; i++)
    if (i != x && abs(a[i] - a[x]) + abs(b[i] - b[x]) > mid) {
      if (vis[i] == -1)
        if (!dfs(i, mid, type ^ 1)) return false;
      if (vis[x] == vis[i]) return false;
    }
  return true;
}
int chk(int x) {
  memset(vis, -1, sizeof(vis));
  for (int i = 1; i <= n; i++)
    if (vis[i] == -1)
      if (!dfs(i, x, 0)) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
  int l = 0, r = 10000;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (chk(mid))
      r = mid;
    else
      l = mid + 1;
  }
  memset(vis, -1, sizeof(vis));
  for (int i = 1; i <= n; i++)
    if (vis[i] == -1) dfs(i, r, 0), cnt++;
  int ans = 1;
  for (int i = 1; i <= cnt; i++) ans = (ans << 1) % 1000000007;
  printf("%d\n%d\n", r, ans);
  return 0;
}

```


### Prompt

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

The only difference between easy and hard versions is the constraints.

Polycarp has to write a coursework. The coursework consists of m pages.

Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).

Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.

Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.

If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.

Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 10^4) — the number of cups of coffee and the number of pages in the coursework.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100), where a_i is the caffeine dosage of coffee in the i-th cup.

Output

If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.

Examples

Input

5 8
2 3 1 1 2

Output

4

Input

7 10
1 3 4 2 1 4 2

Output

2

Input

5 15
5 5 5 5 5

Output

1

Input

5 16
5 5 5 5 5

Output

2

Input

5 26
5 5 5 5 5

Output

-1

Note

In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.

In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.

In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.

In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.

In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6;
long long int n, m;
vector<long long int> v(N);
bool check(long long int days) {
  long long int pages = 0, k = 0;
  for (long long int i = 0, j = 0; j < n; i++, j++) {
    pages += max(0ll, v[j] - k);
    if (i + 1 == days) i = -1, k++;
  }
  return pages >= m;
}
int32_t main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  long long int sum = 0;
  for (long long int i = 0; i < n; ++i) {
    scanf("%lld", &v[i]);
    sum += v[i];
  }
  if (sum < m) {
    printf("-1");
    return 0;
  }
  sort(v.begin(), v.end(), greater<long long int>());
  long long int ans = n;
  long long int low = 1;
  long long int high = n;
  while (low <= high) {
    long long int mid = (low + high) / 2;
    if (check(mid)) {
      ans = min(ans, mid);
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  printf("%lld", ans);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given two arrays a and b of positive integers, with length n and m respectively.

Let c be an n × m matrix, where c_{i,j} = a_i ⋅ b_j.

You need to find a subrectangle of the matrix c such that the sum of its elements is at most x, and its area (the total number of elements) is the largest possible.

Formally, you need to find the largest number s such that it is possible to choose integers x_1, x_2, y_1, y_2 subject to 1 ≤ x_1 ≤ x_2 ≤ n, 1 ≤ y_1 ≤ y_2 ≤ m, (x_2 - x_1 + 1) × (y_2 - y_1 + 1) = s, and $$$∑_{i=x_1}^{x_2}{∑_{j=y_1}^{y_2}{c_{i,j}}} ≤ x.$$$

Input

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

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 2000).

The third line contains m integers b_1, b_2, …, b_m (1 ≤ b_i ≤ 2000).

The fourth line contains a single integer x (1 ≤ x ≤ 2 ⋅ 10^{9}).

Output

If it is possible to choose four integers x_1, x_2, y_1, y_2 such that 1 ≤ x_1 ≤ x_2 ≤ n, 1 ≤ y_1 ≤ y_2 ≤ m, and ∑_{i=x_1}^{x_2}{∑_{j=y_1}^{y_2}{c_{i,j}}} ≤ x, output the largest value of (x_2 - x_1 + 1) × (y_2 - y_1 + 1) among all such quadruplets, otherwise output 0.

Examples

Input

3 3
1 2 3
1 2 3
9

Output

4

Input

5 1
5 4 2 4 5
2
5

Output

1

Note

Matrix from the first sample and the chosen subrectangle (of blue color):

<image>

Matrix from the second sample and the chosen subrectangle (of blue color):

<image>

### Response

```cpp
#include <bits/stdc++.h>
long long int a[2100], b[2100], n, i, j, m, k, d[10000000], f[10000000], x, y,
    z = 0;
int main() {
  while (scanf("%lld %lld", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
    }
    for (i = 1; i <= m; i++) {
      scanf("%lld", &b[i]);
    }
    scanf("%lld", &k);
    for (i = 1; i <= n; i++) {
      a[i] = a[i] + a[i - 1];
    }
    for (i = 1; i <= m; i++) {
      b[i] = b[i] + b[i - 1];
    }
    for (i = 1; i <= n; i++) {
      d[i] = 300000000;
      for (j = 1; j <= n; j++) {
        if (i + j - 1 > n) {
          break;
        }
        x = a[i + j - 1] - a[j - 1];
        if (x < d[i]) {
          d[i] = x;
        }
      }
    }
    for (i = 1; i <= m; i++) {
      f[i] = 300000000;
      for (j = 1; j <= m; j++) {
        if (i + j - 1 > m) {
          break;
        }
        y = b[i + j - 1] - b[j - 1];
        if (y < f[i]) {
          f[i] = y;
        }
      }
    }
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        if (d[i] * f[j] <= k) {
          if (i * j * 1 > z) {
            z = i * j * 1;
          }
          if (i * j * 1 <= z) {
            continue;
          }
        }
      }
    }
    printf("%lld", z);
  }
  return 0;
}

```


### Prompt

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

Being bored of exploring the Moon over and over again Wall-B decided to explore something he is made of — binary numbers. He took a binary number and decided to count how many times different substrings of length two appeared. He stored those values in c_{00}, c_{01}, c_{10} and c_{11}, representing how many times substrings 00, 01, 10 and 11 appear in the number respectively. For example:

10111100 → c_{00} = 1, \ c_{01} = 1,\ c_{10} = 2,\ c_{11} = 3

10000 → c_{00} = 3,\ c_{01} = 0,\ c_{10} = 1,\ c_{11} = 0

10101001 → c_{00} = 1,\ c_{01} = 3,\ c_{10} = 3,\ c_{11} = 0

1 → c_{00} = 0,\ c_{01} = 0,\ c_{10} = 0,\ c_{11} = 0

Wall-B noticed that there can be multiple binary numbers satisfying the same c_{00}, c_{01}, c_{10} and c_{11} constraints. Because of that he wanted to count how many binary numbers satisfy the constraints c_{xy} given the interval [A, B]. Unfortunately, his processing power wasn't strong enough to handle large intervals he was curious about. Can you help him? Since this number can be large print it modulo 10^9 + 7.

Input

First two lines contain two positive binary numbers A and B (1 ≤ A ≤ B < 2^{100 000}), representing the start and the end of the interval respectively. Binary numbers A and B have no leading zeroes.

Next four lines contain decimal numbers c_{00}, c_{01}, c_{10} and c_{11} (0 ≤ c_{00}, c_{01}, c_{10}, c_{11} ≤ 100 000) representing the count of two-digit substrings 00, 01, 10 and 11 respectively.

Output

Output one integer number representing how many binary numbers in the interval [A, B] satisfy the constraints mod 10^9 + 7.

Examples

Input

10
1001
0
0
1
1

Output

1

Input

10
10001
1
2
3
4

Output

0

Note

Example 1: The binary numbers in the interval [10,1001] are 10,11,100,101,110,111,1000,1001. Only number 110 satisfies the constraints: c_{00} = 0, c_{01} = 0, c_{10} = 1, c_{11} = 1.

Example 2: No number in the interval satisfies the constraints

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int p = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    p = p * 10 + ch - '0';
    ch = getchar();
  }
  return p * f;
}
const int maxn = 100005;
const int mod = 1000000007;
long long qpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long fac[maxn], invfac[maxn];
inline long long C(long long n, long long m) {
  if (n == -1 && m == -1)
    return 1;
  else if (n < 0 || m < 0)
    return 0;
  if (n < m) return 0;
  return fac[n] * invfac[n - m] % mod * invfac[m] % mod;
}
void init(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
  invfac[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--) invfac[i] = invfac[i + 1] * (i + 1) % mod;
}
long long solve(int n, int a, int b, int c, int d) {
  if (n <= 1) return (a == 0 && b == 0 && c == 0 && d == 0);
  int seg1, seg0, num1, num0;
  if (b == c) {
    seg1 = b + 1;
    seg0 = b;
  } else if (c == b + 1) {
    seg1 = seg0 = c;
  } else {
    return 0;
  }
  num0 = a + seg0;
  num1 = d + seg1;
  if (num0 + num1 > n) {
    return 0;
  }
  long long ans = C(num0 - 1, seg0 - 1) * C(num1 - 1, seg1 - 1) % mod;
  return (ans + mod) % mod;
}
void jian(char *A) {
  int len = strlen(A);
  for (int i = len - 1; i >= 0; i--) {
    if (A[i] == '1') {
      A[i] = '0';
      for (int j = i + 1; j < len; j++) A[j] = '1';
      if (i == 0) {
        for (int j = 0; j < len - 1; j++) A[j] = A[j + 1];
        A[len - 1] = '\0';
      }
      break;
    }
  }
  if (A[0] == '\0') A[0] = '0', A[1] = '\0';
}
long long solve0(int n, int a, int b, int c, int d) {
  if (a < 0 || b < 0 || c < 0 || d < 0) return 0;
  if (n <= 1) return (a == 0 && b == 0 && c == 0 && d == 0);
  int seg1, seg0, num1, num0;
  long long res = 0;
  c--;
  if (b == c) {
    seg1 = b, seg0 = b + 1;
    num0 = a + seg0, num1 = d + seg1;
    if (num0 + num1 == n)
      res = (res + C(num0 - 1, seg0 - 1) * C(num1 - 1, seg1 - 1) % mod) % mod;
  } else if (c == b - 1) {
    seg0 = seg1 = b;
    num0 = a + seg0, num1 = d + seg1;
    if (num0 + num1 == n)
      res = (res + C(num0 - 1, seg0 - 1) * C(num1 - 1, seg1 - 1) % mod) % mod;
  }
  c++;
  d--;
  if (b == c) {
    seg1 = b + 1, seg0 = b;
    num0 = a + seg0, num1 = d + seg1;
    if (num0 + num1 == n)
      res = (res + C(num0 - 1, seg0 - 1) * C(num1 - 1, seg1 - 1) % mod) % mod;
  } else if (b == c - 1) {
    seg0 = seg1 = c;
    num0 = a + seg0, num1 = d + seg1;
    if (num0 + num1 == n)
      res = (res + C(num0 - 1, seg0 - 1) * C(num1 - 1, seg1 - 1) % mod) % mod;
  }
  d++;
  return res;
}
long long calc(char *A, int a, int b, int c, int d) {
  if (A[0] == '0') return (a == 0 && b == 0 && c == 0 && d == 0);
  int len = strlen(A);
  long long ans = solve(len, a, b, c, d);
  for (int i = 1; i < len; i++) {
    if (A[i] == '0') {
      if (A[i - 1] == '0')
        b--;
      else if (A[i - 1] == '1')
        d--;
      ans -= solve0(len - i - 1, a, b, c, d);
      ans %= mod;
      if (A[i - 1] == '0')
        b++;
      else if (A[i - 1] == '1')
        d++;
    }
    if (A[i - 1] == '0' && A[i] == '0')
      a--;
    else if (A[i - 1] == '0' && A[i] == '1')
      b--;
    else if (A[i - 1] == '1' && A[i] == '0')
      c--;
    else if (A[i - 1] == '1' && A[i] == '1')
      d--;
  }
  return ans;
}
inline bool ok(char *A, int na, int nb, int nc, int nd) {
  int len = strlen(A);
  int a = 0, b = 0, c = 0, d = 0;
  for (int i = 0; i < len - 1; i++) {
    if (A[i] == '0' && A[i + 1] == '0')
      a++;
    else if (A[i] == '0' && A[i + 1] == '1')
      b++;
    else if (A[i] == '1' && A[i + 1] == '0')
      c++;
    else if (A[i] == '1' && A[i + 1] == '1')
      d++;
  }
  return (a == na && b == nb && c == nc && d == nd);
}
char A[maxn], B[maxn];
int main() {
  init(maxn - 5);
  scanf("%s%s", A, B);
  int a = read(), b = read(), c = read(), d = read();
  long long ans =
      ((calc(B, a, b, c, d) - calc(A, a, b, c, d)) % mod + mod) % mod;
  if (ok(A, a, b, c, d)) ans++;
  printf("%lld", (ans + mod) % mod);
}

```


### Prompt

Generate a cpp solution to the following problem:

When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.

Mole, who lives in this garden, now can watch the roses without going up to the surface. Typical mole is blind, but this mole was granted as special vision by the Old Lady. He can watch any underground objects on any distance, even through the obstacles and other objects. However, the quality of the picture depends on the Manhattan distance to object being observed.

Mole wants to find an optimal point to watch roses, that is such point with integer coordinates that the maximum Manhattan distance to the rose is minimum possible.

As usual, he asks you to help.

Manhattan distance between points (x1, y1, z1) and (x2, y2, z2) is defined as |x1 - x2| + |y1 - y2| + |z1 - z2|.

Input

The first line of the input contains an integer t t (1 ≤ t ≤ 100 000) — the number of test cases. Then follow exactly t blocks, each containing the description of exactly one test.

The first line of each block contains an integer ni (1 ≤ ni ≤ 100 000) — the number of roses in the test. Then follow ni lines, containing three integers each — the coordinates of the corresponding rose. Note that two or more roses may share the same position.

It's guaranteed that the sum of all ni doesn't exceed 100 000 and all coordinates are not greater than 1018 by their absolute value.

Output

For each of t test cases print three integers — the coordinates of the optimal point to watch roses. If there are many optimal answers, print any of them.

The coordinates of the optimal point may coincide with the coordinates of any rose.

Examples

Input

1
5
0 0 4
0 0 -4
0 4 0
4 0 0
1 1 1

Output

0 0 0

Input

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

Output

3 5 9
3 5 9

Note

In the first sample, the maximum Manhattan distance from the point to the rose is equal to 4.

In the second sample, the maximum possible distance is 0. Note that the positions of the roses may coincide with each other and with the position of the optimal point.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;
template <typename T>
inline void read(T &x) {
  char ch, t = 0;
  x = 0;
  while (!isdigit(ch = (iS == iT
                            ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)))
    t |= ch == '-';
  while (isdigit(ch))
    x = x * 10 + (ch ^ 48),
    ch = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                      (iS == iT ? EOF : *iS++))
                   : *iS++);
  x = t ? -x : x;
}
inline char read_alpha() {
  char c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                        (iS == iT ? EOF : *iS++))
                     : *iS++);
  while (!isalpha(c) && c != EOF)
    c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                     (iS == iT ? EOF : *iS++))
                  : *iS++);
  return c;
}
inline int read_int() {
  int x;
  return read(x), x;
}
inline long long read_ll() {
  long long x;
  return read(x), x;
}
template <typename T>
inline void chkmin(T &a, T b) {
  a = a < b ? a : b;
}
template <typename T>
inline void chkmax(T &a, T b) {
  a = a > b ? a : b;
}
const int MAXN = 100010;
long long x[MAXN];
long long y[MAXN];
long long z[MAXN];
long long l[5], r[5];
inline int check(long long val, int n, int tp = 0) {
  for (int i = 1; i < 5; i++) l[i] = -3e18, r[i] = 3e18;
  for (int i = 1; i <= n; i++) {
    chkmax(l[1], x[i] + y[i] + z[i] - val);
    chkmin(r[1], x[i] + y[i] + z[i] + val);
    chkmax(l[2], -x[i] + y[i] + z[i] - val);
    chkmin(r[2], -x[i] + y[i] + z[i] + val);
    chkmax(l[3], x[i] - y[i] + z[i] - val);
    chkmin(r[3], x[i] - y[i] + z[i] + val);
    chkmax(l[4], x[i] + y[i] - z[i] - val);
    chkmin(r[4], x[i] + y[i] - z[i] + val);
  }
  for (int i = 1; i < 5; i++)
    if (l[i] > r[i]) return 0;
  for (int rt = 0; rt < 2; rt++) {
    long long tl[5], tr[5];
    tl[1] = (l[1] - 3 * rt + 1) >> 1, tr[1] = (r[1] - 3 * rt) >> 1;
    for (int i = 2; i < 5; i++)
      tl[i] = (l[i] - rt + 1) >> 1, tr[i] = (r[i] - rt) >> 1;
    int flag = 1;
    for (int i = 1; i < 5; i++)
      if (tl[i] > tr[i]) flag = 0;
    if (!flag) continue;
    long long sl = tl[2] + tl[3] + tl[4];
    long long sr = tr[2] + tr[3] + tr[4];
    if (tl[1] <= sr && sl <= tr[1]) {
      if (tp) {
        long long a = tl[2], b = tl[3], c = tl[4], lim = tl[1];
        if (a + b + c < lim) a += min(tr[2] - tl[2], lim - a - b - c);
        if (a + b + c < lim) b += min(tr[3] - tl[3], lim - a - b - c);
        if (a + b + c < lim) c += min(tr[4] - tl[4], lim - a - b - c);
        printf("%lld %lld %lld\n", b + c + rt, a + c + rt, a + b + rt);
      }
      return 1;
    }
  }
  return 0;
}
int main() {
  int Cases = read_int();
  while (Cases--) {
    int n = read_int();
    for (int i = 1; i <= n; i++)
      x[i] = read_ll(), y[i] = read_ll(), z[i] = read_ll();
    long long l = 0, r = 3e18, res;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (check(mid, n))
        res = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    check(res, n, 1);
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

There is a rectangular grid of size n × m. Each cell has a number written on it; the number on the cell (i, j) is a_{i, j}. Your task is to calculate the number of paths from the upper-left cell (1, 1) to the bottom-right cell (n, m) meeting the following constraints:

  * You can move to the right or to the bottom only. Formally, from the cell (i, j) you may move to the cell (i, j + 1) or to the cell (i + 1, j). The target cell can't be outside of the grid.
  * The xor of all the numbers on the path from the cell (1, 1) to the cell (n, m) must be equal to k (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).

Find the number of such paths in the given grid.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 20, 0 ≤ k ≤ 10^{18}) — the height and the width of the grid, and the number k.

The next n lines contain m integers each, the j-th element in the i-th line is a_{i, j} (0 ≤ a_{i, j} ≤ 10^{18}).

Output

Print one integer — the number of paths from (1, 1) to (n, m) with xor sum equal to k.

Examples

Input

3 3 11
2 1 5
7 10 0
12 6 4

Output

3

Input

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

Output

5

Input

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

Output

0

Note

All the paths from the first example:

  * (1, 1) → (2, 1) → (3, 1) → (3, 2) → (3, 3);
  * (1, 1) → (2, 1) → (2, 2) → (2, 3) → (3, 3);
  * (1, 1) → (1, 2) → (2, 2) → (3, 2) → (3, 3).

All the paths from the second example:

  * (1, 1) → (2, 1) → (3, 1) → (3, 2) → (3, 3) → (3, 4);
  * (1, 1) → (2, 1) → (2, 2) → (3, 2) → (3, 3) → (3, 4);
  * (1, 1) → (2, 1) → (2, 2) → (2, 3) → (2, 4) → (3, 4);
  * (1, 1) → (1, 2) → (2, 2) → (2, 3) → (3, 3) → (3, 4);
  * (1, 1) → (1, 2) → (1, 3) → (2, 3) → (3, 3) → (3, 4).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 24;
long long a[MAXN][MAXN];
long long n, m, k, ans;
map<long long, long long> mp[MAXN][MAXN], mp2[MAXN][MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cerr << "HELLO WORLD :)\n";
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> a[i][j];
  mp[1][1][a[1][1]]++;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      if (i + j <= n) {
        for (auto u : mp[i - 1][j]) mp[i][j][u.first ^ a[i][j]] += u.second;
        for (auto u : mp[i][j - 1]) mp[i][j][u.first ^ a[i][j]] += u.second;
      }
  mp2[n][m][a[n][m]]++;
  for (long long i = n; i; i--)
    for (long long j = m; j; j--)
      if (i + j >= n) {
        for (auto u : mp2[i + 1][j]) mp2[i][j][u.first ^ a[i][j]] += u.second;
        for (auto u : mp2[i][j + 1]) mp2[i][j][u.first ^ a[i][j]] += u.second;
      }
  if (n == 1 || m == 1) {
    long long v = 0;
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= m; j++) v ^= a[i][j];
    return cout << (v == k) << '\n', false;
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      if (i + j == n) {
        for (auto u : mp[i][j])
          ans += mp2[i][j][k ^ u.first ^ a[i][j]] * u.second;
      }
  return cout << ans << '\n', false;
}

```


### Prompt

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

Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.

Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows:

* Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).
* Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.

However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:

* Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q).

What is the maximum possible happiness after M handshakes?

Constraints

* 1 \leq N \leq 10^5
* 1 \leq M \leq N^2
* 1 \leq A_i \leq 10^5
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the maximum possible happiness after M handshakes.

Examples

Input

5 3
10 14 19 34 33

Output

202

Input

9 14
1 3 5 110 24 21 34 5 3

Output

1837

Input

9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076

Output

8128170

### Response

```cpp
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int n;
ll m;
vector<ll> a;

bool judge( int x ){
	ll sum = 0;
	for( auto k : a ){
		sum += (ll)(a.end() - lower_bound( a.begin(), a.end(), x-k ));
	}
	return sum >= m;
}

int main(){
	cin >> n >> m;
	a.resize(n);
	for( auto &k : a ) cin >> k;
	sort( a.begin(), a.end() );
	int ok = -1;
	int ng = 2*a.back()+1;
	while( abs(ok-ng) > 1 ){
		int mid = (ok+ng)/2;
		( judge(mid) ? ok : ng ) = mid;
	}
	vector<ll> sum(n+1, 0);
	for( int i = 0; i < n; ++i ) sum[i+1] = sum[i] + a[i];
	ll cnt = 0;
	ll ans = 0;
	for( auto x : a ){
		int t = lower_bound( a.begin(), a.end(), ok-x ) - a.begin();
		ans += sum[n]-sum[t]+((n-t)*x);
		cnt += n-t;
	}
	ans -= ok*(cnt-m);
	cout << ans << endl;
}
```


### Prompt

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

You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.

You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.

Calculate the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Then the description of t testcases follow.

The first line of each test case contains three integers n, x and m (1 ≤ n ≤ 10^9; 1 ≤ m ≤ 100; 1 ≤ x ≤ n).

Each of next m lines contains the descriptions of the operations; the i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n).

Output

For each test case print one integer — the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Example

Input

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

Output

6
2
3

Note

In the first test case, it is possible to achieve a_k = 1 for every k. To do so, you may use the following operations:

  1. swap a_k and a_4;
  2. swap a_2 and a_2;
  3. swap a_5 and a_5.

In the second test case, only k = 1 and k = 2 are possible answers. To achieve a_1 = 1, you have to swap a_1 and a_1 during the second operation. To achieve a_2 = 1, you have to swap a_1 and a_2 during the second operation.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, x, k = 0;
    cin >> n >> x >> m;
    int s1, s2;
    s1 = x, s2 = x;
    while (m--) {
      int l, r;
      cin >> l >> r;
      if (l <= s1 && r >= s1) s1 = l;
      if (l <= s2 && r >= s2) s2 = r;
    }
    cout << s2 - s1 + 1 << "\n";
  }
  return 0;
}

```


### Prompt

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

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

<image>

The numbers are located on the box like that:

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

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

Input

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

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

Output

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

Examples

Input

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

Output

12

Input

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

Output

4

Note

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

In the second sample Vasya can only see number a4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y, z;
  long long x1, y1, z1;
  vector<long long> a(6);
  long long sum = 0;
  cin >> x >> y >> z;
  cin >> x1 >> y1 >> z1;
  for (int i = 0; i < 6; ++i) {
    long long b;
    cin >> b;
    a[i] = b;
  }
  if (x < 0) {
    sum += a[4];
  } else if (x > x1) {
    sum += a[5];
  }
  if (y < 0) {
    sum += a[0];
  } else if (y > y1) {
    sum += a[1];
  }
  if (z < 0) {
    sum += a[2];
  } else if (z > z1) {
    sum += a[3];
  }
  cout << sum;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Polycarp loves ciphers. He has invented his own cipher called repeating.

Repeating cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{m} (1 ≤ m ≤ 10), Polycarp uses the following algorithm:

  * he writes down s_1 ones,
  * he writes down s_2 twice,
  * he writes down s_3 three times,
  * ...
  * he writes down s_m m times.

For example, if s="bab" the process is: "b" → "baa" → "baabbb". So the encrypted s="bab" is "baabbb".

Given string t — the result of encryption of some string s. Your task is to decrypt it, i. e. find the string s.

Input

The first line contains integer n (1 ≤ n ≤ 55) — the length of the encrypted string. The second line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is exactly n.

It is guaranteed that the answer to the test exists.

Output

Print such string s that after encryption it equals t.

Examples

Input

6
baabbb

Output

bab

Input

10
ooopppssss

Output

oops

Input

1
z

Output

z

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string t;
  char a[100];
  cin >> t;
  a[0] = t[0];
  int i, j, k;
  for (i = 1, j = 0, k = 2; j < n; ++i, ++k) {
    j = j + k;
    a[i] = t[j];
  }
  a[i - 1] = '\0';
  cout << a;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You've got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.

A picture is a barcode if the following conditions are fulfilled:

  * All pixels in each column are of the same color.
  * The width of each monochrome vertical line is at least x and at most y pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than x or greater than y.

Input

The first line contains four space-separated integers n, m, x and y (1 ≤ n, m, x, y ≤ 1000; x ≤ y).

Then follow n lines, describing the original image. Each of these lines contains exactly m characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#".

Output

In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists.

Examples

Input

6 5 1 2
##.#.
.###.
###..
#...#
.##.#
###..

Output

11

Input

2 5 1 1
#####
.....

Output

5

Note

In the first test sample the picture after changing some colors can looks as follows:

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

In the second test sample the picture after changing some colors can looks as follows:

    .#.#.
    .#.#.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int32_t INFint = 1e9;
const long long INFll = 1e18;
const long long INF = 9e18;
const long double PI = acos(-1);
long long powersOfTwo[31] = {
    1,         2,         4,         8,        16,       32,       64,
    128,       256,       512,       1024,     2048,     4096,     8192,
    16384,     32768,     65536,     131072,   262144,   524288,   1048576,
    2097152,   4194304,   8388608,   16777216, 33554432, 67108864, 134217728,
    268435456, 536870912, 1073741824};
long long power(long long x, long long y) {
  long long r = 1;
  while (y > 0) {
    if (y & 1) r = r * x;
    y = y >> 1;
    x = x * x;
  }
  return r;
}
long long powerMod(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long n, m, x, y;
long long cnt[1010][1010];
long long dp[1010][1010][2];
long long solve(long long color, long long pos, long long width) {
  if (pos == m) {
    if (width == 1) return 0;
    if ((width - 1 >= x && width - 1 <= y)) return 0;
    return 1e12;
  }
  long long ans = dp[pos][width][color];
  if (ans != -1) return dp[x][pos][width] = ans;
  if (width < x) {
    ans = cnt[color ^ 1][pos] + solve(color, pos + 1, width + 1);
  } else if (width < y) {
    ans = min(cnt[color ^ 1][pos] + solve(color, pos + 1, width + 1),
              cnt[color ^ 1][pos] + solve(color ^ 1, pos + 1, 1));
  } else
    ans = cnt[color ^ 1][pos] + solve(color ^ 1, pos + 1, 1);
  return dp[pos][width][color] = ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long tt = 1;
  while (tt--) {
    cin >> n >> m >> x >> y;
    char arr[n][m];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        cin >> arr[i][j];
      }
    }
    for (long long j = 0; j < m; j++) {
      for (long long i = 0; i < n; i++) {
        if (arr[i][j] == '.') cnt[0][j]++;
        if (arr[i][j] == '#') cnt[1][j]++;
      }
    }
    memset(dp, -1, sizeof(dp));
    cout << min(solve(0, 0, 1), solve(1, 0, 1));
  }
  cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC
       << "ms\n";
  ;
}

```


### Prompt

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

Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.

As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi ≤ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).

In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?

Input

The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.

The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.

All numbers on the lines are separated by single spaces.

Output

Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.

Examples

Input

5 2 3
6 2 3 100 1

Output

3

Input

7 3 4
1 1 9 1 1 1 1

Output

0

Note

In the first sample the possible values of x are 3, 4 or 5.

In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, temp;
  int h[2005];
  while (cin >> n >> a >> b) {
    for (int i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (int i = 0; i < n - 1; i++)
      for (int j = 0; j < n - i - 1; j++) {
        if (h[j] < h[j + 1]) {
          temp = h[j];
          h[j] = h[j + 1];
          h[j + 1] = temp;
        }
      }
    if (h[a - 1] > h[a])
      cout << h[a - 1] - h[a] << endl;
    else
      cout << "0" << endl;
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.

Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance.

<image> Illustration for n = 6, a = 2, b = - 5.

Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.

Input

The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n, - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.

Output

Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.

Examples

Input

6 2 -5

Output

3

Input

5 1 3

Output

4

Input

3 2 7

Output

3

Note

The first example is illustrated by the picture in the statements.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (b < 0) {
    b = b % n;
    b += n;
  }
  if ((a + b) % n == 0)
    cout << n;
  else
    cout << (a + b) % n;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given two positive integers a and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test cases.

Input

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

The only line of the test case contains two integers a and b (1 ≤ a, b ≤ 10^9).

Output

For each test case print the answer — the minimum number of moves you need to do in order to make a divisible by b.

Example

Input

5
10 4
13 9
100 13
123 456
92 46

Output

2
5
4
333
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c;
    cin >> a >> b;
    if (a % b == 0) {
      std::cout << 0 << std::endl;
      continue;
    }
    if (a < b) {
      cout << b - a << endl;
      continue;
    }
    c = a / b;
    cout << (b * (c + 1)) - a << endl;
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

Tomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.

While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and draw everything he has to during all of the practical classes. Polycarp writes lectures using a pen (he can't use a pencil to write lectures!); he can write down c lectures using one pen, and after that it runs out of ink. During practical classes Polycarp draws blueprints with a pencil (he can't use a pen to draw blueprints!); one pencil is enough to draw all blueprints during d practical classes, after which it is unusable.

Polycarp's pencilcase can hold no more than k writing implements, so if Polycarp wants to take x pens and y pencils, they will fit in the pencilcase if and only if x + y ≤ k.

Now Polycarp wants to know how many pens and pencils should he take. Help him to determine it, or tell that his pencilcase doesn't have enough room for all the implements he needs tomorrow!

Note that you don't have to minimize the number of writing implements (though their total number must not exceed k).

Input

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

Each test case is described by one line containing five integers a, b, c, d and k, separated by spaces (1 ≤ a, b, c, d, k ≤ 100) — the number of lectures Polycarp has to attend, the number of practical classes Polycarp has to attend, the number of lectures which can be written down using one pen, the number of practical classes for which one pencil is enough, and the number of writing implements that can fit into Polycarp's pencilcase, respectively.

In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.

Output

For each test case, print the answer as follows:

If the pencilcase can't hold enough writing implements to use them during all lectures and practical classes, print one integer -1. Otherwise, print two non-negative integers x and y — the number of pens and pencils Polycarp should put in his pencilcase. If there are multiple answers, print any of them. Note that you don't have to minimize the number of writing implements (though their total number must not exceed k).

Example

Input

3
7 5 4 5 8
7 5 4 5 2
20 53 45 26 4

Output

7 1
-1
1 3

Note

There are many different answers for the first test case; x = 7, y = 1 is only one of them. For example, x = 3, y = 1 is also correct.

x = 1, y = 3 is the only correct answer for the third test case.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b, c, d, k;
  cin >> a >> b >> c >> d >> k;
  int pens;
  if (a % c == 0)
    pens = a / c;
  else
    pens = a / c + 1;
  int pencils;
  if (b % d == 0)
    pencils = b / d;
  else
    pencils = b / d + 1;
  if (pens + pencils > k)
    cout << -1 << endl;
  else
    cout << pens << ' ' << pencils << endl;
}
int main(void) {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}

```


### Prompt

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

Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).

q events are about to happen (in chronological order). They are of three types:

  1. Application x generates a notification (this new notification is unread).
  2. Thor reads all notifications generated so far by application x (he may re-read some notifications).
  3. Thor reads the first t notifications generated by phone applications (notifications generated in first t events of the first type). It's guaranteed that there were at least t events of the first type before this event. Please note that he doesn't read first t unread notifications, he just reads the very first t notifications generated on his phone and he may re-read some of them in this operation.

Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.

Input

The first line of input contains two integers n and q (1 ≤ n, q ≤ 300 000) — the number of applications and the number of events to happen.

The next q lines contain the events. The i-th of these lines starts with an integer typei — type of the i-th event. If typei = 1 or typei = 2 then it is followed by an integer xi. Otherwise it is followed by an integer ti (1 ≤ typei ≤ 3, 1 ≤ xi ≤ n, 1 ≤ ti ≤ q).

Output

Print the number of unread notifications after each event.

Examples

Input

3 4
1 3
1 1
1 2
2 3

Output

1
2
3
2

Input

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

Output

1
2
3
0
1
2

Note

In the first sample:

  1. Application 3 generates a notification (there is 1 unread notification).
  2. Application 1 generates a notification (there are 2 unread notifications).
  3. Application 2 generates a notification (there are 3 unread notifications).
  4. Thor reads the notification generated by application 3, there are 2 unread notifications left.

In the second sample test:

  1. Application 2 generates a notification (there is 1 unread notification).
  2. Application 4 generates a notification (there are 2 unread notifications).
  3. Application 2 generates a notification (there are 3 unread notifications).
  4. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.
  5. Application 3 generates a notification (there is 1 unread notification).
  6. Application 3 generates a notification (there are 2 unread notifications).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int cnt = 0, n, ques, mark = 0, ans = 0;
queue<int> q[N];
bool vis[N];
int main() {
  scanf("%d%d", &n, &ques);
  memset(vis, false, sizeof(vis));
  while (ques--) {
    int op, x;
    scanf("%d%d", &op, &x);
    if (op == 1) {
      q[x].push(++cnt);
      ans++;
    } else if (op == 2) {
      while (!q[x].empty()) {
        int u = q[x].front();
        q[x].pop();
        if (u > mark) {
          ans--;
          vis[u] = true;
        }
      }
    } else {
      for (int i = mark + 1; i <= x; i++) {
        if (!vis[i]) ans--;
      }
      mark = max(mark, x);
    }
    printf("%d\n", ans);
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character.

Let's introduce several definitions:

  * A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string sisi + 1...sj.
  * The prefix of string s of length l (1 ≤ l ≤ |s|) is string s[1..l].
  * The suffix of string s of length l (1 ≤ l ≤ |s|) is string s[|s| - l + 1..|s|].

Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.

Input

The single line contains a sequence of characters s1s2...s|s| (1 ≤ |s| ≤ 105) — string s. The string only consists of uppercase English letters.

Output

In the first line, print integer k (0 ≤ k ≤ |s|) — the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.

Examples

Input

ABACABA

Output

3
1 4
3 2
7 1

Input

AAA

Output

3
1 3
2 2
3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int p[n];
  for (int i = 0; i < n; i++) p[i] = -1;
  for (int i = 1; i < n; i++) {
    int x = p[i - 1];
    while (1) {
      if (s[x + 1] == s[i]) {
        p[i] = x + 1;
        break;
      } else if (x == -1) {
        p[i] = -1;
        break;
      }
      x = p[x];
    }
  }
  int cnt[n];
  for (int i = 0; i < n; i++) cnt[i] = 1;
  for (int i = n - 1; i >= 0; i--)
    if (p[i] != -1) cnt[p[i]] += cnt[i];
  int last = n - 1;
  vector<int> ans;
  while (last != -1) {
    ans.push_back(last);
    last = p[last];
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] + 1 << " " << cnt[ans[i]] << endl;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.

There are two armies on the playing field each of which consists of n men (n is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.

The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.

You are asked to calculate the maximum total number of soldiers that may be killed during the game.

Input

The input data consist of a single integer n (2 ≤ n ≤ 108, n is even). Please note that before the game starts there are 2n soldiers on the fields.

Output

Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.

Examples

Input

2

Output

3

Input

4

Output

6

Note

The first sample test:

1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.

2) Arcady's soldier 2 shoots at Valera's soldier 1.

3) Valera's soldier 1 shoots at Arcady's soldier 2.

There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, h;
void input() { cin >> n; }
void work() {
  h = n / 4 + n / 4;
  if (n % 4 != 0) h++;
}
void output() { cout << n * 2 - h; }
int main() {
  input();
  work();
  output();
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

Input

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integers hi (1 ≤ hi ≤ 109), where hi equals the number of floors in the i-th house.

Output

Print n integers a1, a2, ..., an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero.

All houses are numbered from left to right, starting from one.

Examples

Input

5
1 2 3 1 2

Output

3 2 0 2 0

Input

4
3 2 1 4

Output

2 3 4 0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long Nmax = 1000000000;
int n;
vector<long long> a;
vector<long long> tree;
void add(int x, int i, int l, int r, int pos) {
  if (i < l || i > r) return;
  if (l == r) {
    tree[pos] = x;
    return;
  }
  int mid = (l + r) / 2;
  add(x, i, l, mid, pos * 2);
  add(x, i, mid + 1, r, pos * 2 + 1);
  tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
}
long long get_max(int u, int v, int l, int r, int pos) {
  if (v < l || r < u) return -999999999999999999;
  if (u <= l && r <= v) return tree[pos];
  int mid = (l + r) / 2;
  return max(get_max(u, v, l, mid, pos * 2),
             get_max(u, v, mid + 1, r, pos * 2 + 1));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  tree.assign(4 * n + 1, 0);
  a.assign(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    add(a[i], i, 1, n, 1);
  }
  for (int i = 1; i < n; ++i) {
    long long v = get_max(i + 1, n, 1, n, 1);
    if (a[i] > v)
      cout << 0 << ' ';
    else
      cout << v + 1 - a[i] << ' ';
  }
  cout << 0 << ' ';
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead.

<image>

Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≤ i ≤ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled.

Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all).

After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper.

Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him.

Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7.

Input

The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≤ n ≤ 106 and 0 ≤ m ≤ n - |p| + 1).

The second line contains string p (1 ≤ |p| ≤ n).

The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≤ y1 < y2 < ... < ym ≤ n - |p| + 1).

Output

In a single line print the answer modulo 1000 000 007.

Examples

Input

6 2
ioi
1 3

Output

26

Input

5 2
ioi
1 2

Output

0

Note

In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy.

Here |x| denotes the length of string x.

Please note that it's possible that there is no such string (answer is 0).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
char res[1000010];
vector<int> z_function(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
int main() {
  int N, M;
  cin >> N >> M;
  string s;
  cin >> s;
  vector<int> z = z_function(s + "#" + s);
  for (int i = 0; i < M; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= N; i++) res[i] = '*';
  int cur = 0;
  for (int i = 0; i < M; i++) {
    if (!i || a[i - 1] + (int)s.length() <= a[i]) {
      for (int j = 0; j < (int)s.length(); j++) res[a[i] + j] = s[j];
    } else {
      int len = (int)s.length() - (a[i] - a[i - 1]);
      if (z[(int)s.length() + (int)s.length() - len + 1] == len) {
        for (int j = len; j < (int)s.length(); j++) res[a[i] + j] = s[j];
      } else {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  long long cnt = 1, mod = 1e9 + 7;
  for (int i = 1; i <= N; i++) {
    if (res[i] == '*') cnt = (cnt * 26) % mod;
  }
  cout << cnt << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Input

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

Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordinates are between  - 1000 and 1000, inclusive.

Output

Output a single real number θ — the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.

Examples

Input

8
-2.14 2.06
-1.14 2.04
-2.16 1.46
-2.14 0.70
-1.42 0.40
-0.94 -0.48
-1.42 -1.28
-2.16 -1.62

Output

5.410

Input

5
2.26 1.44
2.28 0.64
2.30 -0.30
1.58 0.66
3.24 0.66

Output

5.620

Input

8
6.98 2.06
6.40 1.12
5.98 0.24
5.54 -0.60
7.16 0.30
7.82 1.24
8.34 0.24
8.74 -0.76

Output

5.480

Input

5
10.44 2.06
10.90 0.80
11.48 -0.48
12.06 0.76
12.54 2.06

Output

6.040

Input

8
16.94 2.42
15.72 2.38
14.82 1.58
14.88 0.50
15.76 -0.16
16.86 -0.20
17.00 0.88
16.40 0.92

Output

6.040

Input

7
20.62 3.00
21.06 2.28
21.56 1.36
21.66 0.56
21.64 -0.52
22.14 2.32
22.62 3.04

Output

6.720

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  double x, y, avg = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    avg += y;
  }
  avg /= n;
  avg += 5;
  cout << setprecision(3) << fixed << avg << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of length n.

Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue together the remaining parts (any of them can be empty). For example, if he erases substring 111 from string 111110 he will get the string 110. Vasya gets a_x points for erasing substring of length x.

Vasya wants to maximize his total points, so help him with this!

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the length of string s.

The second line contains string s, consisting only of digits 0 and 1.

The third line contains n integers a_1, a_2, ... a_n (1 ≤ a_i ≤ 10^9), where a_i is the number of points for erasing the substring of length i.

Output

Print one integer — the maximum total points Vasya can get.

Examples

Input

7
1101001
3 4 9 100 1 2 3

Output

109

Input

5
10101
3 10 15 15 15

Output

23

Note

In the first example the optimal sequence of erasings is: 1101001 → 111001 → 11101 → 1111 → ∅.

In the second example the optimal sequence of erasings is: 10101 → 1001 → 11 → ∅.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
long long a[maxn];
long long dp[2][maxn][maxn][maxn];
long long ans[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  string s;
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      a[i] = max(a[i], a[i - j] + a[j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= n; k++) {
      dp[0][i][i][k] = -1e18;
      dp[1][i][i][k] = -1e18;
      dp[0][i + 1][i][k] = -1e18;
      dp[1][i + 1][i][k] = -1e18;
    }
    if (s[i - 1] == '0') {
      dp[0][i][i][1] = 0;
    } else {
      dp[1][i][i][1] = 0;
    }
    dp[0][i][i][0] = a[1];
    dp[1][i][i][0] = a[1];
    ans[i][i] = a[1];
  }
  for (int d = 1; d < n; d++) {
    for (int le = 1; le <= n; le++) {
      int ri = le + d;
      if (ri > n) continue;
      for (int k = 1; k <= n; k++) {
        for (int dig = 0; dig < 2; dig++) {
          dp[dig][le][ri][k] = -1e18;
          for (int i = le; i <= ri; i++) {
            if (s[i - 1] - '0' == dig) {
              dp[dig][le][ri][k] =
                  max(dp[dig][le][ri][k],
                      ans[le][i - 1] + dp[dig][i + 1][ri][k - 1]);
            }
          }
        }
      }
      ans[le][ri] = -1e18;
      for (int k = 1; k <= n; k++) {
        ans[le][ri] =
            max(ans[le][ri], max(dp[0][le][ri][k], dp[1][le][ri][k]) + a[k]);
      }
      dp[0][le][ri][0] = ans[le][ri];
      dp[1][le][ri][0] = ans[le][ri];
    }
  }
  cout << ans[1][n] << "\n";
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are at the top left cell (1, 1) of an n × m labyrinth. Your goal is to get to the bottom right cell (n, m). You can only move right or down, one cell per step. Moving right from a cell (x, y) takes you to the cell (x, y + 1), while moving down takes you to the cell (x + 1, y).

Some cells of the labyrinth contain rocks. When you move to a cell with rock, the rock is pushed to the next cell in the direction you're moving. If the next cell contains a rock, it gets pushed further, and so on.

The labyrinth is surrounded by impenetrable walls, thus any move that would put you or any rock outside of the labyrinth is illegal.

Count the number of different legal paths you can take from the start to the goal modulo 10^9 + 7. Two paths are considered different if there is at least one cell that is visited in one path, but not visited in the other.

Input

The first line contains two integers n, m — dimensions of the labyrinth (1 ≤ n, m ≤ 2000).

Next n lines describe the labyrinth. Each of these lines contains m characters. The j-th character of the i-th of these lines is equal to "R" if the cell (i, j) contains a rock, or "." if the cell (i, j) is empty.

It is guaranteed that the starting cell (1, 1) is empty.

Output

Print a single integer — the number of different legal paths from (1, 1) to (n, m) modulo 10^9 + 7.

Examples

Input

1 1
.

Output

1

Input

2 3
...
..R

Output

0

Input

4 4
...R
.RR.
.RR.
R...

Output

4

Note

In the first sample case we can't (and don't have to) move, hence the only path consists of a single cell (1, 1).

In the second sample case the goal is blocked and is unreachable.

Illustrations for the third sample case can be found here: <https://assets.codeforces.com/rounds/1225/index.html>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int sum(int a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}
const int N = 2010;
int dp[N][N][2], pref0[N][N], pref1[N][N], calc1[N][N], calc0[N][N];
char c[N][N];
int get_sum1(int a, int l, int r) {
  if (l > r) {
    return 0;
  }
  int res = pref1[a][r] - pref1[a][l - 1];
  if (res < 0) {
    res += MOD;
  }
  return res;
}
int get_sum0(int a, int l, int r) {
  if (l > r) {
    return 0;
  }
  int res = pref0[a][r] - pref0[a][l - 1];
  if (res < 0) {
    res += MOD;
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 1 << '\n';
    exit(0);
  }
  int cnt0 = 0, cnt1 = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == 'R') {
        if (i == 1) {
          cnt1++;
        }
        if (j == 1) {
          cnt0++;
        }
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    int cnt = 0;
    for (int i = n; i >= 1; i--) {
      if (c[i][j] == 'R') {
        cnt++;
        calc1[j][cnt] = i;
      }
    }
    for (int i = cnt + 1; i <= n; i++) {
      calc1[j][i] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = m; j >= 1; j--) {
      if (c[i][j] == 'R') {
        cnt++;
        calc0[i][cnt] = j;
      }
    }
    for (int j = cnt + 1; j <= m; j++) {
      calc0[i][j] = 1;
    }
  }
  for (int j = 2; j <= m; j++) {
    if (cnt1 <= m - j) {
      dp[1][j][1] = 1;
      pref1[j][1] = 1;
    }
  }
  for (int i = 2; i <= n; i++) {
    if (cnt0 <= n - i) {
      dp[i][1][0] = 1;
      pref0[i][1] = 1;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 2; j <= m; j++) {
      int up = calc1[j][n - i + 1], lef = calc0[i][m - j + 1];
      dp[i][j][0] = get_sum1(j, up, i - 1);
      dp[i][j][1] = get_sum0(i, lef, j - 1);
      pref1[j][i] = sum(pref1[j][i - 1], dp[i][j][1]);
      pref0[i][j] = sum(pref0[i][j - 1], dp[i][j][0]);
    }
  }
  cout << sum(dp[n][m][0], dp[n][m][1]) << '\n';
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?

The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.

Input

The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).

Output

Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.

Examples

Input

1

Output

0

Input

3

Output

1

Input

99

Output

49

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long unsigned int n, now, m;
  cin >> n;
  if (n % 2) {
    cout << n / 2;
  } else {
    m = log2(n);
    cout << (int)(n - pow(2, m)) / 2;
  }
}

```


### Prompt

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

Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.

Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.

Find the maximum possible sum of utilities of purchased integers.

Constraints

* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N K
A_1 B_1
:
A_N B_N

Outputs

Print the maximum possible sum of utilities of purchased integers.

Examples

Input

3 5
3 3
4 4
2 5

Output

8

Input

3 6
3 3
4 4
2 5

Output

9

Input

7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9

Output

32

### Response

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

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    auto calc = [&](int mask) {
        long long sum = 0;
        for (int j = 0; j < n; j++) if ((a[j] | mask) == mask) sum += b[j];
        return sum;
    };
    long long ans = calc(k);
    for (int i = 0; i < 31; i++) if (k >> i & 1) {
        int mask = (k ^ (1 << i)) | ((1 << i) - 1);
        ans = max(ans, calc(mask));
    }
    cout << ans << endl;
    return 0;
}

```


### Prompt

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

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

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

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

Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?

Constraints

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

Input

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

s

Output

Print the string displayed in the editor in the end.

Examples

Input

01B0

Output

00

Input

0BB1

Output

1

### Response

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


### Prompt

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

Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times.

Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the n-th exercise.

Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.

Input

The first line contains integer n (1 ≤ n ≤ 20). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 25) — the number of times Greg repeats the exercises.

Output

Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.

It is guaranteed that the input is such that the answer to the problem is unambiguous.

Examples

Input

2
2 8

Output

biceps

Input

3
5 1 10

Output

back

Input

7
3 3 2 7 9 6 8

Output

chest

Note

In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.

In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.

In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int sum1 = 0, sum2 = 0, sum3 = 0, n, b, c;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  if (n == 1) {
    cout << "chest";
    return 0;
  } else if (n == 2) {
    b = max(arr[1], arr[2]);
    if (b == arr[1]) {
      cout << "chest";
    } else {
      cout << "biceps";
    }
    return 0;
  } else if (n > 2) {
    for (int i = 1; i <= (n + 2) / 3; i++) {
      sum1 += arr[3 * i - 2];
    }
    for (int i = 1; i <= (n + 1) / 3; i++) {
      sum2 += arr[3 * i - 1];
    }
    for (int i = 1; i <= (n) / 3; i++) {
      sum3 += arr[3 * i];
    }
  }
  c = max(max(sum1, sum2), sum3);
  if (c == sum1) {
    cout << "chest";
  } else if (c == sum2) {
    cout << "biceps";
  } else {
    cout << "back";
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Snuke has two boards, each divided into a grid with N rows and N columns. For both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j).

There is a lowercase English letter written in each square on the first board. The letter written in Square (i,j) is S_{i,j}. On the second board, nothing is written yet.

Snuke will write letters on the second board, as follows:

* First, choose two integers A and B ( 0 \leq A, B < N ).
* Write one letter in each square on the second board. Specifically, write the letter written in Square ( i+A, j+B ) on the first board into Square (i,j) on the second board. Here, the k-th row is also represented as the (N+k)-th row, and the k-th column is also represented as the (N+k)-th column.

After this operation, the second board is called a good board when, for every i and j ( 1 \leq i, j \leq N ), the letter in Square (i,j) and the letter in Square (j,i) are equal.

Find the number of the ways to choose integers A and B ( 0 \leq A, B < N ) such that the second board is a good board.

Constraints

* 1 \leq N \leq 300
* S_{i,j} ( 1 \leq i, j \leq N ) is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

N
S_{1,1}S_{1,2}..S_{1,N}
S_{2,1}S_{2,2}..S_{2,N}
:
S_{N,1}S_{N,2}..S_{N,N}

Output

Print the number of the ways to choose integers A and B ( 0 \leq A, B < N ) such that the second board is a good board.

Examples

Input

2
ab
ca

Output

2

Input

4
aaaa
aaaa
aaaa
aaaa

Output

16

Input

5
abcde
fghij
klmno
pqrst
uvwxy

Output

0

### Response

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

const int MAXN = 305;

int N;
char mat[MAXN][MAXN];

bool check(int diff) {
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			if (mat[i][j] != mat[(j + diff) % N][(i - diff + N) % N])
				return false;
	return true;
}

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%s", mat[i]);

	int sol = 0;
	for (int i = 0; i < N; i++)
		sol += check(i);

	printf("%d\n", N * sol);

	return 0;
}
```


### Prompt

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

There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules:

  * Red-green tower is consisting of some number of levels;

  * Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level — of n - 1 blocks, the third one — of n - 2 blocks, and so on — the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one;

  * Each level of the red-green tower should contain blocks of the same color.

<image>

Let h be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks.

Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.

You are to write a program that will find the number of different red-green towers of height h modulo 109 + 7.

Input

The only line of input contains two integers r and g, separated by a single space — the number of available red and green blocks respectively (0 ≤ r, g ≤ 2·105, r + g ≥ 1).

Output

Output the only integer — the number of different possible red-green towers of height h modulo 109 + 7.

Examples

Input

4 6

Output

2

Input

9 7

Output

6

Input

1 1

Output

2

Note

The image in the problem statement shows all possible red-green towers for the first sample.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <unsigned long long mod>
class modint {
 public:
  unsigned long long v;
  modint(const long long x = 0) : v(x % mod) {}
  modint operator+(const modint rhs) { return modint(*this) += rhs; }
  modint operator-(const modint rhs) { return modint(*this) -= rhs; }
  modint operator*(const modint rhs) { return modint(*this) *= rhs; }
  modint operator/(const modint rhs) { return modint(*this) /= rhs; }
  modint operator-() { return modint(mod - this->v); }
  modint& operator+=(const modint rhs) {
    v += rhs.v;
    if (v >= mod) v -= mod;
    return *this;
  }
  modint& operator-=(const modint rhs) {
    if (v < rhs.v) v += mod;
    v -= rhs.v;
    return *this;
  }
  modint& operator*=(const modint rhs) {
    v = v * rhs.v % mod;
    return *this;
  }
  modint inverse(modint a) {
    unsigned long long exp = mod - 2;
    modint ret(1ULL);
    while (exp) {
      if (exp % 2) {
        ret *= a;
      }
      a *= a;
      exp >>= 1;
    }
    return ret;
  }
  modint& operator/=(modint rhs) {
    (*this) *= inverse(rhs);
    return *this;
  }
  friend ostream& operator<<(ostream& os, modint& u) {
    os << u.v;
    return (os);
  }
  friend istream& operator>>(istream& is, modint& u) {
    is >> u.v;
    return (is);
  }
};
const int MOD = 1000000007;
using mint = modint<MOD>;
class Solution {
 public:
  void solve() {
    int r, g;
    cin >> r >> g;
    int h = 0;
    while ((h + 1) * (h + 2) <= (r + g) * 2) h++;
    int rem = (r + g) - (h * (h + 1)) / 2;
    vector<mint> dp(r + 1);
    dp[0] = 1;
    for (int i = 0; i < h; i++) {
      for (int j = r - 1 - i; j >= 0; j--) {
        dp[j + i + 1] += dp[j];
      }
    }
    mint ans = 0;
    for (int i = r; i >= max(r - rem, 0); i--) {
      ans += dp[i];
    }
    cout << ans << "\n";
  };
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Solution solution;
  solution.solve();
  return 0;
}

```


### Prompt

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

You are a car race organizer and would like to arrange some races in Linear Kingdom.

Linear Kingdom has n consecutive roads spanning from left to right. The roads are numbered from 1 to n from left to right, thus the roads follow in the order of their numbers' increasing. There will be several races that may be held on these roads. Each race will use a consecutive subset of these roads. Also, each race will pay some amount of money to you if this race is held. No races overlap in time, so some roads can be used in several races.

Unfortunately, some of the roads are in a bad condition and they need repair. Each road has repair costs associated with it, you are required to pay this cost to repair the road. A race can only take place if all the roads used in the race are renovated. Your task is to repair such roads (possibly all or none) that will maximize your profit. Your profit is defined as the total money you get from the races that are held minus the total money you spent to repair the roads. Note that you may decide not to repair any road and gain zero profit.

Print the maximum profit you can gain.

Input

The first line contains two single-space separated integers, n and m (1 ≤ n, m ≤ 2·105), denoting the number of roads and the number of races, respectively.

Then n lines follow, each line will contain a single non-negative integer not exceeding 109 denoting the cost to repair a road. The costs are given in order from road 1 to road n.

Finally, m lines follow. Each line is single-space-separated triplets of integers. Each triplet will be given as lb, ub, and p (1 ≤ lb ≤ ub ≤ n, 1 ≤ p ≤ 109), which means that the race these three integers describe will use all the roads from lb to ub, inclusive, and if it's held you get p.

Output

Print a single integer denoting the maximum possible profit you can gain.

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is recommended to use cin, cout stream (also you may use %I64d specificator).

Examples

Input

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

Output

4

Input

2 1
0
3
1 2 5

Output

2

Input

3 1
10
10
10
1 3 10

Output

0

Note

In the first sample the optimal solution is to repair roads 1, 2, 3, and 7. Three races will take place which nets you 15. The road repair costs 11, hence your profit is 4.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
const long long MAXN = 2e5 + 10;
const long long MAXM = MAXN << 2;
struct Road {
  long long l, u, p;
} e[MAXN];
long long n, m, root, a[MAXN], f[MAXN], sum[MAXN];
std::vector<std::pair<long long, long long> > node[MAXN];
namespace Segtree {
long long cnt, lazy[MAXM], max_num[MAXM], ls[MAXM], rs[MAXM], l[MAXM], r[MAXM];
inline void build(long long &cur, long long L, long long R) {
  cur = ++cnt;
  l[cur] = L, r[cur] = R;
  if (L == R) {
    max_num[L] = a[L];
    return;
  }
  long long mid = (L + R) >> 1;
  build(ls[cur], L, mid), build(rs[cur], mid + 1, R);
}
inline void push_down(long long cur) {
  if (!lazy[cur]) return;
  lazy[ls[cur]] += lazy[cur], lazy[rs[cur]] += lazy[cur];
  max_num[ls[cur]] += lazy[cur], max_num[rs[cur]] += lazy[cur];
  lazy[cur] = 0;
}
inline void Modification(long long L, long long R, long long cur,
                         long long add) {
  if (L <= l[cur] and r[cur] <= R) {
    lazy[cur] += add, max_num[cur] += add;
    return;
  }
  push_down(cur);
  long long mid = (l[cur] + r[cur]) >> 1;
  if (L <= mid) Modification(L, R, ls[cur], add);
  if (R > mid) Modification(L, R, rs[cur], add);
  max_num[cur] = std::max(max_num[ls[cur]], max_num[rs[cur]]);
}
inline long long query(long long L, long long R, long long cur) {
  if (L <= l[cur] and r[cur] <= R) return max_num[cur];
  push_down(cur);
  long long mid = (l[cur] + r[cur]) >> 1, res = 0;
  if (L <= mid) res = std::max(res, query(L, R, ls[cur]));
  if (R > mid) res = std::max(res, query(L, R, rs[cur]));
  return res;
}
}  // namespace Segtree
inline long long read() {
  long long X = 0, flag = 0;
  char ch = 0;
  while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return flag ? -X : X;
}
inline bool cmp(Road x, Road y) { return x.u < y.u; }
inline void write(long long X) {
  if (X < 0) putchar('-'), X = -X;
  if (X > 9) write(X / 10);
  putchar(X % 10 + '0');
}
signed main() {
  n = read(), m = read(), Segtree::build(root, 0, n);
  for (register long long i = 1; i <= n; i++)
    a[i] = read(), sum[i] = sum[i - 1] + a[i];
  for (register long long i = 1; i <= m; i++) {
    e[i].l = read(), e[i].u = read(), e[i].p = read();
    node[e[i].u].push_back(std::make_pair(e[i].l, e[i].p));
  }
  std::sort(e + 1, e + n + 1, cmp);
  for (register long long i = 1; i <= n; i++) {
    Segtree::Modification(i, i, 1, Segtree::query(0, i - 1, 1));
    for (register long long j = 0; j < node[i].size(); j++)
      Segtree::Modification(0, node[i][j].first - 1, 1, node[i][j].second);
    Segtree::Modification(0, i - 1, 1, -a[i]);
  }
  write(Segtree::max_num[1]);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

There's a famous museum in the city where Kleofáš lives. In the museum, n exhibits (numbered 1 through n) had been displayed for a long time; the i-th of those exhibits has value vi and mass wi.

Then, the museum was bought by a large financial group and started to vary the exhibits. At about the same time, Kleofáš... gained interest in the museum, so to say.

You should process q events of three types:

  * type 1 — the museum displays an exhibit with value v and mass w; the exhibit displayed in the i-th event of this type is numbered n + i (see sample explanation for more details)
  * type 2 — the museum removes the exhibit with number x and stores it safely in its vault
  * type 3 — Kleofáš visits the museum and wonders (for no important reason at all, of course): if there was a robbery and exhibits with total mass at most m were stolen, what would their maximum possible total value be?

For each event of type 3, let s(m) be the maximum possible total value of stolen exhibits with total mass  ≤ m.

Formally, let D be the set of numbers of all exhibits that are currently displayed (so initially D = {1, ..., n}). Let P(D) be the set of all subsets of D and let

<image>

Then, s(m) is defined as

<image>

Compute s(m) for each <image>. Note that the output follows a special format.

Input

The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 1000) — the initial number of exhibits in the museum and the maximum interesting mass of stolen exhibits.

Then, n lines follow. The i-th of them contains two space-separated positive integers vi and wi (1 ≤ vi ≤ 1 000 000, 1 ≤ wi ≤ 1000) — the value and mass of the i-th exhibit.

The next line contains a single integer q (1 ≤ q ≤ 30 000) — the number of events.

Each of the next q lines contains the description of one event in the following format:

  * 1 v w — an event of type 1, a new exhibit with value v and mass w has been added (1 ≤ v ≤ 1 000 000, 1 ≤ w ≤ 1000)
  * 2 x — an event of type 2, the exhibit with number x has been removed; it's guaranteed that the removed exhibit had been displayed at that time
  * 3 — an event of type 3, Kleofáš visits the museum and asks his question

There will be at most 10 000 events of type 1 and at least one event of type 3.

Output

As the number of values s(m) can get large, output the answers to events of type 3 in a special format.

For each event of type 3, consider the values s(m) computed for the question that Kleofáš asked in this event; print one line containing a single number

<image>

where p = 107 + 19 and q = 109 + 7.

Print the answers to events of type 3 in the order in which they appear in the input.

Examples

Input

3 10
30 4
60 6
5 1
9
3
1 42 5
1 20 3
3
2 2
2 4
3
1 40 6
3

Output

556674384
168191145
947033915
181541912

Input

3 1000
100 42
100 47
400 15
4
2 2
2 1
2 3
3

Output

0

Note

In the first sample, the numbers of displayed exhibits and values s(1), ..., s(10) for individual events of type 3 are, in order:

<image> <image> <image> <image>

The values of individual exhibits are v1 = 30, v2 = 60, v3 = 5, v4 = 42, v5 = 20, v6 = 40 and their masses are w1 = 4, w2 = 6, w3 = 1, w4 = 5, w5 = 3, w6 = 6.

In the second sample, the only question is asked after removing all exhibits, so s(m) = 0 for any m.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 30030, M = 5005000, L = 1010, oo = 1000000000, P = 10000019,
          Q = 1000000007;
int i, j, k, n, m, nm, Tn, q, En, ch, last, o, x, An;
int f[22][L], h[N << 2], ans[N], p[N];
struct cc {
  int l, r, v, w;
} A[N];
struct edge {
  int s, n;
} E[M];
void R(int &x) {
  x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
int max(const int &x, const int &y) {
  if (x > y) return x;
  return y;
}
void E_add(int x, int y) {
  E[++En].s = y;
  E[En].n = h[x];
  h[x] = En;
}
void T_add(int L, int R, int l, int r, int x, int k) {
  if (L == l && R == r) {
    E_add(k, x);
    return;
  }
  int mid = (L + R) >> 1;
  if (r <= mid)
    T_add(L, mid, l, r, x, k << 1);
  else {
    if (l > mid)
      T_add(mid + 1, R, l, r, x, k << 1 | 1);
    else
      T_add(L, mid, l, mid, x, k << 1),
          T_add(mid + 1, R, mid + 1, r, x, k << 1 | 1);
  }
}
void T_bl(int L, int R, int dp, int k) {
  for (int i = 0; i <= m; i++) f[dp][i] = f[dp - 1][i];
  for (int kk = h[k]; kk; kk = E[kk].n) {
    int v = A[E[kk].s].v, w = A[E[kk].s].w;
    for (int i = m; i >= w; i--) f[dp][i] = max(f[dp][i], f[dp][i - w] + v);
  }
  if (L == R) {
    int &res = ans[L];
    int pp = 1;
    for (int i = 1; i <= m; i++) {
      res = ((long long)f[dp][i] * pp + res) % Q;
      pp = (long long)pp * P % Q;
    }
    return;
  }
  int mid = (L + R) >> 1;
  T_bl(L, mid, dp + 1, k << 1);
  T_bl(mid + 1, R, dp + 1, k << 1 | 1);
}
int main() {
  R(n);
  R(m);
  for (i = 1; i <= n; i++) {
    A[i].l = 1;
    A[i].r = oo;
    R(A[i].v);
    R(A[i].w);
  }
  R(q);
  An = n;
  for (i = 1; i <= q; i++) {
    last = o;
    R(o);
    if (o == 3) {
      if (last == 3)
        p[++nm] = Tn;
      else
        p[++nm] = ++Tn;
      continue;
    }
    if (o == 1) {
      An++;
      A[An].l = Tn + 1;
      A[An].r = oo;
      R(A[An].v);
      R(A[An].w);
      continue;
    }
    if (o == 2) {
      R(x);
      A[x].r = Tn;
      continue;
    }
  }
  for (i = 1; i <= An; i++) {
    if (A[i].r == oo) A[i].r = Tn;
    if (1 <= A[i].l && A[i].l <= A[i].r && A[i].r <= Tn)
      T_add(1, Tn, A[i].l, A[i].r, i, 1);
  }
  T_bl(1, Tn, 1, 1);
  for (i = 1; i <= nm; i++) printf("%d\n", ans[p[i]]);
}

```