### Prompt

Please formulate a CPP solution to the following problem:

Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d.

Johnny's truck has a gas tank that holds exactly n liters, and his tank is initially full. As he drives, the truck consumes exactly one liter per unit distance traveled. Moreover, there are m gas stations located at various points along the way to the district center. The i-th station is located at the point xi on the number line and sells an unlimited amount of fuel at a price of pi dollars per liter. Find the minimum cost Johnny must pay for fuel to successfully complete the delivery.

Input

The first line of input contains three space separated integers d, n, and m (1 ≤ n ≤ d ≤ 109, 1 ≤ m ≤ 200 000) — the total distance to the district center, the volume of the gas tank, and the number of gas stations, respectively.

Each of the next m lines contains two integers xi, pi (1 ≤ xi ≤ d - 1, 1 ≤ pi ≤ 106) — the position and cost of gas at the i-th gas station. It is guaranteed that the positions of the gas stations are distinct.

Output

Print a single integer — the minimum cost to complete the delivery. If there is no way to complete the delivery, print -1.

Examples

Input

10 4 4
3 5
5 8
6 3
8 4

Output

22

Input

16 5 2
8 2
5 1

Output

-1

Note

In the first sample, Johnny's truck holds 4 liters. He can drive 3 units to the first gas station, buy 2 liters of gas there (bringing the tank to 3 liters total), drive 3 more units to the third gas station, buy 4 liters there to fill up his tank, and then drive straight to the district center. His total cost is 2·5 + 4·3 = 22 dollars.

In the second sample, there is no way for Johnny to make it to the district center, as his tank cannot hold enough gas to take him from the latest gas station to the district center.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int n;
int m;
vector<pair<int, long long int> > v;
long long int d;
deque<pair<long long int, long long int> > q;
int main() {
  scanf("%I64d%I64d%d", &d, &n, &m);
  for (int i = 0; i < m; i++) {
    long long int x;
    long long int p;
    scanf("%I64d%I64d", &x, &p);
    v.push_back(make_pair(x, p));
  }
  sort(v.begin(), v.end());
  v.push_back(make_pair(d, 114514LL));
  long long int has = n;
  long long int pre = 0;
  long long int add = 0;
  long long int ans = 0;
  for (int i = 0; i < m + 1; i++) {
    long long int moved = v[i].first - pre;
    if (has < moved) {
      long long int need = moved - has;
      while (q.size() && need > 0LL) {
        long long int can = q.front().second - add;
        if (can < 0LL) {
          return 1;
        }
        if (can == 0LL) {
          q.pop_front();
          continue;
        }
        long long int minu = min(can, need);
        need -= minu;
        add += minu;
        ans += minu * q.front().first;
        has += minu;
      }
      if (need) {
        puts("-1");
        return 0;
      }
    }
    pre = v[i].first;
    has -= moved;
    while (q.size() && q.back().first > v[i].second) {
      q.pop_back();
    }
    q.push_back(make_pair(v[i].second, n - has + add));
  }
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

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

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

Constraints

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

Input

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

Output

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

Example

Input

3
4 3 5
4 3 6
8 8 8

Output

YES
NO
NO

### Response

```cpp
#include<iostream>
using namespace std;
int main() {
	int N,a,b,c;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a >> b >> c;
		if (a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given a sequence a_1, a_2, …, a_n of non-negative integers.

You need to find the largest number m of triples (i_1, j_1, k_1), (i_2, j_2, k_2), ..., (i_m, j_m, k_m) such that:

  * 1 ≤ i_p < j_p < k_p ≤ n for each p in 1, 2, …, m;
  * a_{i_p} = a_{k_p} = 0, a_{j_p} ≠ 0;
  * all a_{j_1}, a_{j_2}, …, a_{j_m} are different;
  * all i_1, j_1, k_1, i_2, j_2, k_2, …, i_m, j_m, k_m are different.

Input

The first line of input contains one integer t (1 ≤ t ≤ 500 000): the number of test cases.

The first line of each test case contains one integer n (1 ≤ n ≤ 500 000).

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

The total sum of n is at most 500 000.

Output

For each test case, print one integer m: the largest number of proper triples that you can find.

Example

Input

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

Output

0
0
1
2
1
1
1
2

Note

In the first two test cases, there are not enough elements even for a single triple, so the answer is 0.

In the third test case we can select one triple (1, 2, 3).

In the fourth test case we can select two triples (1, 3, 5) and (2, 4, 6).

In the fifth test case we can select one triple (1, 2, 3). We can't select two triples (1, 2, 3) and (4, 5, 6), because a_2 = a_5.

### Response

```cpp
#include <bits/stdc++.h>
const int kN = 500000 + 5;
struct SegmentTree {
  int val[kN << 1];
  int delta[kN << 1];
  int get_id(int l, int r) { return l + r | l != r; }
  void build(int l, int r) {
    int u = get_id(l, r);
    val[u] = delta[u] = 0;
    if (l == r) return;
    int mid = l + r >> 1;
    build(l, mid);
    build(mid + 1, r);
  }
  void up(int l, int r) {
    if (l == r) return;
    int mid = l + r >> 1;
    int u = get_id(l, r);
    val[u] = std::min(val[get_id(l, mid)], val[get_id(mid + 1, r)]);
    val[u] += delta[u];
  }
  int query(int l, int r, int L, int R) {
    if (L <= l && r <= R) {
      return val[get_id(l, r)];
    }
    int mid = l + r >> 1;
    int ret = 0;
    if (L <= mid && mid < R) {
      ret = std::min(query(l, mid, L, R), query(mid + 1, r, L, R));
    } else if (L <= mid) {
      ret = query(l, mid, L, R);
    } else {
      ret = query(mid + 1, r, L, R);
    }
    return ret + delta[get_id(l, r)];
  }
  void update(int l, int r, int L, int R, int dt) {
    if (L <= l && r <= R) {
      int u = get_id(l, r);
      val[u] += dt;
      delta[u] += dt;
      return;
    }
    int mid = l + r >> 1;
    if (L <= mid) update(l, mid, L, R, dt);
    if (mid < R) update(mid + 1, r, L, R, dt);
    up(l, r);
  }
} sgt;
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    int n;
    scanf("%d", &n);
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
    }
    sgt.build(0, n - 1);
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      sgt.update(0, n - 1, i, i, cnt);
      cnt += a[i] == 0;
    }
    int result = cnt / 2;
    std::vector<int> last(n + 1, -1);
    for (int i = 0; i < n; ++i) {
      cnt -= a[i] == 0;
      if (a[i] > 0) {
        sgt.update(0, n - 1, last[a[i]] + 1, i, 1);
        last[a[i]] = i;
      }
      result = std::min(result, sgt.query(0, n - 1, 0, i) + cnt);
    }
    printf("%d\n", result);
  }
}

```


### Prompt

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

Mashmokh works in a factory. At the end of each day he must turn off all of the lights.

The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.

Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.

Please, help Mashmokh, print these indices.

Input

The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).

It is guaranteed that all lights will be turned off after pushing all buttons.

Output

Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.

Examples

Input

5 4
4 3 1 2

Output

1 1 3 4 4

Input

5 5
5 4 3 2 1

Output

1 2 3 4 5

Note

In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ans[110];
int main() {
  int n, m;
  memset(ans, -1, sizeof(ans));
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) {
    int v;
    scanf("%d", &v);
    for (int j = (v); j < (n + 1); ++j)
      if (ans[j] == -1)
        ans[j] = v;
      else
        break;
  }
  for (int i = (1); i < (n + 1); ++i) {
    if (i != 1) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.

Kirk has a binary string s (a string which consists of zeroes and ones) of length n and he is asking you to find a binary string t of the same length which satisfies the following conditions:

  * For any l and r (1 ≤ l ≤ r ≤ n) the length of the longest non-decreasing subsequence of the substring s_{l}s_{l+1} … s_{r} is equal to the length of the longest non-decreasing subsequence of the substring t_{l}t_{l+1} … t_{r};
  * The number of zeroes in t is the maximum possible.

A non-decreasing subsequence of a string p is a sequence of indices i_1, i_2, …, i_k such that i_1 < i_2 < … < i_k and p_{i_1} ≤ p_{i_2} ≤ … ≤ p_{i_k}. The length of the subsequence is k.

If there are multiple substrings which satisfy the conditions, output any.

Input

The first line contains a binary string of length not more than 2\: 000.

Output

Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.

Examples

Input

110

Output

010

Input

010

Output

010

Input

0001111

Output

0000000

Input

0111001100111011101000

Output

0011001100001011101000

Note

In the first example:

  * For the substrings of the length 1 the length of the longest non-decreasing subsequnce is 1;
  * For l = 1, r = 2 the longest non-decreasing subsequnce of the substring s_{1}s_{2} is 11 and the longest non-decreasing subsequnce of the substring t_{1}t_{2} is 01;
  * For l = 1, r = 3 the longest non-decreasing subsequnce of the substring s_{1}s_{3} is 11 and the longest non-decreasing subsequnce of the substring t_{1}t_{3} is 00;
  * For l = 2, r = 3 the longest non-decreasing subsequnce of the substring s_{2}s_{3} is 1 and the longest non-decreasing subsequnce of the substring t_{2}t_{3} is 1;

The second example is similar to the first one.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void stand8th() {
  string s;
  cin >> s;
  long long n = (long long)(s.size());
  string temp = s;
  long long c = 0;
  for (long long i = n - 1; i >= 0; --i) {
    if (temp[i] == '0') {
      c++;
    } else if (c == 0) {
      temp[i] = '0';
    } else {
      c--;
    }
  }
  cout << temp << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tin = 1;
  while (tin--) {
    stand8th();
  }
  return 0;
}

```


### Prompt

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

Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.

For a given number n, find the number of ordinary numbers among the numbers from 1 to n.

Input

The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.

Each test case is characterized by one integer n (1 ≤ n ≤ 10^9).

Output

For each test case output the number of ordinary numbers among numbers from 1 to n.

Example

Input

6
1
2
3
4
5
100

Output

1
2
3
4
5
18

### Response

```cpp
#include <iostream>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <unordered_set>
#include <queue>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mk make_pair
#define mod 1000000007

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

void solve() {

    ll n; cin >> n;
    vector<int> arr;

    ll temp = n;
    while(temp > 0) {
        arr.push_back(temp%10);
        temp /= 10;
    }

    reverse(arr.begin(), arr.end());
    int ans = 0;
    ll curr = 1;

    while(curr*10 <= n) {
        ans += 9;
        curr *= 10;
    }

    for(int i = 1;i<=9;i++) {
        ll num = 0;
        for(int j = 0;j<arr.size();j++) {
            num = num*10 + i;
        }
        if(num > n) {
            break;
        }
        ans ++;
    }

    cout << ans << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t ;
    cin >> t;
    while(t--) {
        solve();
    }

    return 0;
}
```


### Prompt

Please create a solution in cpp to the following problem:

Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.

The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.

Input

The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ m2).

Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.

The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").

It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.

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

Output

Print a single integer — the sought number modulo 1000000007 (109 + 7).

Examples

Input

3 3 2
ab
ba

Output

17

Input

3 3 0

Output

27

Input

2 1 1
aa

Output

0

Note

In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.

In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > canBe(53, vector<bool>(53, true));
char temp[3];
long long n;
int m, k;
namespace matrix {
long long mat[53][53], tmp[53][53], res[53][53];
long long MOD;
int n;
void init(int _n, long long _MOD) {
  n = _n;
  MOD = _MOD;
  memset(mat, 0, sizeof(mat));
  memset(tmp, 0, sizeof(tmp));
  memset(res, 0, sizeof(res));
}
void mul(long long r[][53], long long a[][53], long long b[][53]) {
  int i, j, t;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      long long val = 0;
      for (t = 0; t < n; t++) {
        val = (val + 1LL * a[i][t] * b[t][j]) % MOD;
      }
      tmp[i][j] = val % MOD;
    }
  memcpy(r, tmp, n * 53 * sizeof(tmp[0][0]));
}
void mPow(long long r[][53], long long a[][53], long long p) {
  int i;
  if (p < 0) return;
  memset(r, 0, sizeof(r));
  for (i = 0; i < n; i++) r[i][i] = 1;
  while (p > 0) {
    if (p & 1) mul(r, r, a);
    mul(a, a, a);
    p >>= 1;
  }
}
void pow(long long p) {
  mPow(res, mat, p);
  memcpy(mat, res, n * 53 * sizeof(tmp[0][0]));
}
}  // namespace matrix
using matrix::mat;
void add(long long& lhs, long long rhs) { lhs = (lhs + rhs) % 1000000007; }
void transform() {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++)
      if (canBe[i][j]) {
        mat[i][j]++;
      }
  }
}
int main(int argc, char const* argv[]) {
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    scanf("%s", &temp);
    int a =
        (temp[0] >= 'a' && temp[0] <= 'z' ? temp[0] - 'a' : temp[0] - 'A' + 26);
    int b =
        (temp[1] >= 'a' && temp[1] <= 'z' ? temp[1] - 'a' : temp[1] - 'A' + 26);
    canBe[a][b] = false;
  }
  matrix::init(m, 1000000007);
  transform();
  matrix::pow(n - 1);
  long long ans = 0LL;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      add(ans, mat[i][j]);
    }
  cout << ans;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Jaroslav owns a small courier service. He has recently got and introduced a new system of processing parcels. Each parcel is a box, the box has its weight and strength. The system works as follows. It originally has an empty platform where you can put boxes by the following rules:

  * If the platform is empty, then the box is put directly on the platform, otherwise it is put on the topmost box on the platform.
  * The total weight of all boxes on the platform cannot exceed the strength of platform S at any time.
  * The strength of any box of the platform at any time must be no less than the total weight of the boxes that stand above.

You can take only the topmost box from the platform.

The system receives n parcels, the i-th parcel arrives exactly at time ini, its weight and strength are equal to wi and si, respectively. Each parcel has a value of vi bourles. However, to obtain this value, the system needs to give the parcel exactly at time outi, otherwise Jaroslav will get 0 bourles for it. Thus, Jaroslav can skip any parcel and not put on the platform, formally deliver it at time ini and not get anything for it.

Any operation in the problem is performed instantly. This means that it is possible to make several operations of receiving and delivering parcels at the same time and in any order.

Please note that the parcel that is delivered at time outi, immediately gets outside of the system, and the following activities taking place at the same time are made without taking it into consideration.

Since the system is very complex, and there are a lot of received parcels, Jaroslav asks you to say what maximum amount of money he can get using his system.

Input

The first line of the input contains two space-separated integers n and S (1 ≤ n ≤ 500, 0 ≤ S ≤ 1000). Then n lines follow, the i-th line contains five space-separated integers: ini, outi, wi, si and vi (0 ≤ ini < outi < 2n, 0 ≤ wi, si ≤ 1000, 1 ≤ vi ≤ 106). It is guaranteed that for any i and j (i ≠ j) either ini ≠ inj, or outi ≠ outj.

Output

Print a single number — the maximum sum in bourles that Jaroslav can get.

Examples

Input

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

Output

3

Input

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

Output

5

Note

Note to the second sample (T is the moment in time):

  * T = 0: The first parcel arrives, we put in on the first platform.
  * T = 1: The second and third parcels arrive, we put the third one on the current top (i.e. first) parcel on the platform, then we put the secod one on the third one. Now the first parcel holds weight w2 + w3 = 2 and the third parcel holds w2 = 1.
  * T = 2: We deliver the second parcel and get v2 = 1 bourle. Now the first parcel holds weight w3 = 1, the third one holds 0.
  * T = 3: The fourth parcel comes. First we give the third parcel and get v3 = 1 bourle. Now the first parcel holds weight 0. We put the fourth parcel on it — the first one holds w4 = 2.
  * T = 4: The fifth parcel comes. We cannot put it on the top parcel of the platform as in that case the first parcel will carry weight w4 + w5 = 3, that exceed its strength s1 = 2, that's unacceptable. We skip the fifth parcel and get nothing for it.
  * T = 5: Nothing happens.
  * T = 6: We deliver the fourth, then the first parcel and get v1 + v4 = 3 bourles for them.

Note that you could have skipped the fourth parcel and got the fifth one instead, but in this case the final sum would be 4 bourles.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, s, f[505][1005], g[1005];
vector<pair<int, int> > p[1005];
struct parcel {
  int in, out, w, s, v;
} a[505];
int solve(int now, int s) {
  if (s < 0) return 0;
  if (f[now][s] != -1) return f[now][s];
  for (int i = 1; i <= n; i++)
    if ((i != now) && (a[i].in >= a[now].in) && (a[i].out <= a[now].out))
      solve(i, min(a[i].s, s - a[i].w));
  for (int i = a[now].in; i <= a[now].out; i++) {
    g[i] = 0;
    p[i].clear();
  }
  for (int i = 1; i <= n; i++)
    if ((i != now) && (a[i].in >= a[now].in) && (a[i].out <= a[now].out))
      p[a[i].out].push_back(
          make_pair(a[i].in, solve(i, min(a[i].s, s - a[i].w))));
  for (int i = a[now].in + 1; i <= a[now].out; i++) {
    g[i] = g[i - 1];
    for (int j = 0; j < p[i].size(); j++)
      g[i] = max(g[i], g[p[i][j].first] + p[i][j].second);
  }
  return f[now][s] = g[a[now].out] + a[now].v;
}
int main() {
  scanf("%d%d", &n, &s);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d%d", &a[i].in, &a[i].out, &a[i].w, &a[i].s, &a[i].v);
    a[i].in++;
    a[i].out++;
  }
  a[++n] = (parcel){0, 2 * n + 1, 0, s, 0};
  memset(f, -1, sizeof(f));
  printf("%d\n", solve(n, s));
  return 0;
}

```


### Prompt

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

Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water.

There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop.

The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly.

Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles.

You also have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries.

The next q lines contain queries. The i-th query is given as three space-separated integers n_i, a_i and b_i (1 ≤ n_i ≤ 10^{12}, 1 ≤ a_i, b_i ≤ 1000) — how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively.

Output

Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly n_i liters of water in the nearby shop if the bottle of the first type costs a_i burles and the bottle of the second type costs b_i burles.

Example

Input

4
10 1 3
7 3 2
1 1000 1
1000000000000 42 88

Output

10
9
1000
42000000000000

### Response

```cpp
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
long long inp() {
  long long i{};
  std::cin >> i;
  return i;
}
long long min(long long a, long long b) { return (a >= b) ? b : a; }
int main() {
  long long t{inp()};
  while (t--) {
    long long n{inp()}, a{inp()}, b{inp()}, ans{a * n};
    if (b - 2 * a < 0) ans += (b - 2 * a) * (n / 2);
    std::cout << ans << '\n';
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.

In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white.

Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

Constraints

* 1 ≦ |S| ≦ 10^5
* Each character in S is `B` or `W`.

Input

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

S

Output

Print the minimum number of new stones that Jiro needs to place for his purpose.

Examples

Input

BBBWW

Output

1

Input

WWWWWW

Output

0

Input

WBWBWBWBWB

Output

9

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
string st;
int x,l;
int main()
{
	cin>>st;
	l=st.size();
	for(int i=1;i<l;i++)x+=(st[i]!=st[i-1]);
	cout<<x;
	return 0;
}
```


### Prompt

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

In the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are n residents and n cats in the Catowice, and each resident has exactly one cat living in his house. The residents and cats are numbered with integers from 1 to n, where the i-th cat is living in the house of i-th resident.

Each Catowice resident is in friendship with several cats, including the one living in his house. In order to conduct a contest, at least one jury member is needed and at least one cat contestant is needed. Of course, every jury member should know none of the contestants. For the contest to be successful, it's also needed that the number of jury members plus the number of contestants is equal to n.

Please help Catowice residents to select the jury and the contestants for the upcoming competition, or determine that it's impossible to do.

Input

The first line contains an integer t (1 ≤ t ≤ 100 000), the number of test cases. Then description of t test cases follow, where each description is as follows:

The first line contains integers n and m (1 ≤ n ≤ m ≤ 10^6), the number of Catowice residents and the number of friendship pairs between residents and cats.

Each of the next m lines contains integers a_i and b_i (1 ≤ a_i, b_i ≤ n), denoting that a_i-th resident is acquaintances with b_i-th cat. It's guaranteed that each pair of some resident and some cat is listed at most once.

It's guaranteed, that for every i there exists a pair between i-th resident and i-th cat.

Different test cases are separated with an empty line.

It's guaranteed, that the sum of n over all test cases is at most 10^6 and that the sum of m over all test cases is at most 10^6.

Output

For every test case print:

  * "No", if it's impossible to select the jury and contestants.
  * Otherwise print "Yes".

In the second line print two integers j and p (1 ≤ j, 1 ≤ p, j + p = n) — the number of jury members and the number of contest participants.

In the third line print j distinct integers from 1 to n, the indices of the residents forming a jury.

In the fourth line print p distinct integers from 1 to n, the indices of the cats, which will participate in the contest.

In case there are several correct answers, print any of them.

Example

Input

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

Output

Yes
2 1
1 3
2
Yes
1 2
2
1 3
No
No

Note

In the first test case, we can select the first and the third resident as a jury. Both of them are not acquaintances with a second cat, so we can select it as a contestant.

In the second test case, we can select the second resident as a jury. He is not an acquaintances with a first and a third cat, so they can be selected as contestants.

In the third test case, the only resident is acquaintances with the only cat, so they can't be in the contest together. So it's not possible to make a contest with at least one jury and at least one cat.

In the fourth test case, each resident is acquaintances with every cat, so it's again not possible to make a contest with at least one jury and at least one cat.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 1000010;
const int M = 2000010;
const int maxn = 60;
using namespace std;
int n, m;
int vis[N];
struct Graph {
  int edge[N], lst[N], nxt[N], t;
  void ADD(int x, int y) {
    edge[++t] = y;
    nxt[t] = lst[x];
    lst[x] = t;
  }
  void MEM() {
    for (int i = 1; i <= n; i++) lst[i] = 0;
    t = 0;
  }
  int SEARCH(int x) {
    vis[x] = 1;
    int res = 0;
    for (int r = lst[x]; r; r = nxt[r]) {
      if (!vis[edge[r]]) res += SEARCH(edge[r]);
    }
    return res + 1;
  }
  int CHK(int pd) {
    for (int i = 1; i <= n; i++) vis[i] = 0;
    int now = SEARCH(1);
    if (now == n) return 0;
    printf("Yes\n");
    if (pd == 0) {
      printf("%d %d\n", now, n - now);
      for (int i = 1; i <= n; i++)
        if (vis[i]) printf("%d ", i);
      puts("");
      for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
    } else {
      printf("%d %d\n", n - now, now);
      for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
      puts("");
      for (int i = 1; i <= n; i++)
        if (vis[i]) printf("%d ", i);
    }
    puts("");
    return 1;
  }
} gr[2];
void SOLVE() {
  int u, v;
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= 1; i++) gr[i].MEM();
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    if (u == v) continue;
    gr[0].ADD(u, v);
    gr[1].ADD(v, u);
  }
  for (int i = 0; i <= 1; i++) {
    if (gr[i].CHK(i)) return;
  }
  printf("No\n");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) SOLVE();
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Arkadiy has lots square photos with size a × a. He wants to put some of them on a rectangular wall with size h × w.

The photos which Arkadiy will put on the wall must form a rectangular grid and the distances between neighboring vertically and horizontally photos and also the distances between outside rows and columns of photos to the nearest bound of the wall must be equal to x, where x is some non-negative real number. Look on the picture below for better understanding of the statement.

<image>

Arkadiy haven't chosen yet how many photos he would put on the wall, however, he want to put at least one photo. Your task is to determine the minimum value of x which can be obtained after putting photos, or report that there is no way to put positive number of photos and satisfy all the constraints. Suppose that Arkadiy has enough photos to make any valid arrangement according to the constraints.

Note that Arkadiy wants to put at least one photo on the wall. The photos should not overlap, should completely lie inside the wall bounds and should have sides parallel to the wall sides.

Input

The first line contains three integers a, h and w (1 ≤ a, h, w ≤ 109) — the size of photos and the height and the width of the wall.

Output

Print one non-negative real number — the minimum value of x which can be obtained after putting the photos on the wall. The absolute or the relative error of the answer must not exceed 10 - 6.

Print -1 if there is no way to put positive number of photos and satisfy the constraints.

Examples

Input

2 18 13

Output

0.5

Input

4 4 4

Output

0

Input

3 4 3

Output

-1

Note

In the first example Arkadiy can put 7 rows of photos with 5 photos in each row, so the minimum value of x equals to 0.5.

In the second example Arkadiy can put only 1 photo which will take the whole wall, so the minimum value of x equals to 0.

In the third example there is no way to put positive number of photos and satisfy the constraints described in the statement, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long read() {
  char cc = getchar();
  long long cn = 0;
  while (cc > '9' || cc < '0') cc = getchar();
  while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar();
  return cn;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long h, a, w;
signed main() {
  a = read(), h = read(), w = read();
  long long g = gcd(h + a, w + a);
  long long y = g / a;
  if (y == 0 || h < a || w < a)
    puts("-1");
  else
    printf("%lf\n", (1.0 * g / y) - a);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:

  * Everyone must gift as many coins as others.
  * All coins given to Ivan must be different.
  * Not less than L coins from gifts altogether, must be new in Ivan's collection.

But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.

Input

The only line of input contains 4 integers N, M, K, L (1 ≤ K ≤ N ≤ 10^{18}; 1 ≤ M,    L ≤ 10^{18}) — quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.

Output

Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).

Examples

Input

20 15 2 3

Output

1

Input

10 11 2 4

Output

-1

Note

In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.

In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int64_t N, M, K, L, x;
int main() {
  cin >> N >> M >> K >> L;
  x = K + L + M - 1;
  x /= M;
  cout << (x * M <= N && x > 0 ? x : -1);
}

```


### Prompt

Create a solution in cpp for the following problem:

I won't feel lonely, nor will I be sorrowful... not before everything is buried.

A string of n beads is left as the message of leaving. The beads are numbered from 1 to n from left to right, each having a shape numbered by integers between 1 and n inclusive. Some beads may have the same shapes.

The memory of a shape x in a certain subsegment of beads, is defined to be the difference between the last position and the first position that shape x appears in the segment. The memory of a subsegment is the sum of memories over all shapes that occur in it.

From time to time, shapes of beads change as well as the memories. Sometimes, the past secreted in subsegments are being recalled, and you are to find the memory for each of them.

Input

The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 100 000) — the number of beads in the string, and the total number of changes and queries, respectively.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — the initial shapes of beads 1, 2, ..., n, respectively.

The following m lines each describes either a change in the beads or a query of subsegment. A line has one of the following formats:

  * 1 p x (1 ≤ p ≤ n, 1 ≤ x ≤ n), meaning that the shape of the p-th bead is changed into x;
  * 2 l r (1 ≤ l ≤ r ≤ n), denoting a query of memory of the subsegment from l to r, inclusive.

Output

For each query, print one line with an integer — the memory of the recalled subsegment.

Examples

Input

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

Output

5
0
7
1

Input

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

Output

0
0

Note

The initial string of beads has shapes (1, 2, 3, 1, 3, 2, 1).

Consider the changes and queries in their order:

  1. 2 3 7: the memory of the subsegment [3, 7] is (7 - 4) + (6 - 6) + (5 - 3) = 5;
  2. 2 1 3: the memory of the subsegment [1, 3] is (1 - 1) + (2 - 2) + (3 - 3) = 0;
  3. 1 7 2: the shape of the 7-th bead changes into 2. Beads now have shapes (1, 2, 3, 1, 3, 2, 2) respectively;
  4. 1 3 2: the shape of the 3-rd bead changes into 2. Beads now have shapes (1, 2, 2, 1, 3, 2, 2) respectively;
  5. 2 1 6: the memory of the subsegment [1, 6] is (4 - 1) + (6 - 2) + (5 - 5) = 7;
  6. 2 5 7: the memory of the subsegment [5, 7] is (7 - 6) + (5 - 5) = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <int Sx, int Sy>
struct FenwickTree2D {
  unordered_map<int, int> arr[Sx + 1];
  int szx, szy;
  FenwickTree2D() : szx(Sx), szy(Sy) {}
  void add(int i, int j, int val) {
    for (int ii = i; ii <= szx; ii += (ii & -ii)) {
      for (int jj = j; jj <= szy; jj += (jj & -jj)) {
        arr[ii][jj] += val;
      }
    }
  }
  long long query(int i, int j) {
    long long sum = 0;
    int ii = i;
    for (int ii = i; ii; ii -= (ii & -ii)) {
      for (int jj = j; jj; jj -= (jj & -jj)) {
        if (arr[ii].count(jj)) sum += arr[ii][jj];
      }
    }
    return sum;
  }
  long long query(int i1, int j1, int i2, int j2) {
    return query(i2, j2) - query(i1 - 1, j2) - query(i2, j1 - 1) +
           query(i1 - 1, j1 - 1);
  }
};
const int N = 100000 + 10;
int n, m;
int A[N];
int pre[N];
set<int> shape_pos[N];
FenwickTree2D<N, N> ft;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  ft.szx = n;
  ft.szy = n;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
  }
  for (int i = 1; i <= n; ++i) {
    shape_pos[A[i]].insert(i);
    if (pre[A[i]]) {
      ft.add(pre[A[i]], i, i - pre[A[i]]);
    }
    pre[A[i]] = i;
  }
  int t, a, b;
  for (int i = 0; i != m; ++i) {
    cin >> t >> a >> b;
    if (t == 1) {
      auto it = shape_pos[A[a]].find(a);
      auto itn = next(it, 1);
      auto itp = prev(it, 1);
      if (itn != shape_pos[A[a]].end()) ft.add(*it, *itn, -(*itn - *it));
      if (it != shape_pos[A[a]].begin()) ft.add(*itp, *it, -(*it - *itp));
      if (itn != shape_pos[A[a]].end() && it != shape_pos[A[a]].begin())
        ft.add(*itp, *itn, *itn - *itp);
      shape_pos[A[a]].erase(it);
      A[a] = b;
      shape_pos[A[a]].insert(a);
      it = shape_pos[A[a]].find(a);
      itn = next(it, 1);
      itp = prev(it, 1);
      if (itn != shape_pos[A[a]].end()) ft.add(*it, *itn, *itn - *it);
      if (it != shape_pos[A[a]].begin()) ft.add(*itp, *it, *it - *itp);
      if (itn != shape_pos[A[a]].end() && it != shape_pos[A[a]].begin())
        ft.add(*itp, *itn, -(*itn - *itp));
    } else {
      cout << ft.query(a, a, b, b) << '\n';
    }
  }
  return 0;
}

```


### Prompt

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

Honestly, a rabbit does not matter.

There is a rabbit playing a stage system action game. In this game, every stage has a difficulty level. The rabbit, which always needs challenges, basically wants to play more difficult stages than he has ever played. However, he sometimes needs rest too. So, to compromise, he admitted to play T or less levels easier stages than the preceding one.

How many ways are there to play all the stages at once, while honoring the convention above? Maybe the answer will be a large number. So, let me know the answer modulo 1,000,000,007.

Input

The first line of input contains two integers N and T (1 ≤ N ≤ 100,000, 1 ≤ T ≤ 10,000). N is the number of stages, and T is the compromise level.

The following N lines describe the difficulty levels of each stage. The i-th line contains one integer Di (1 ≤ Di ≤ 100,000), which is the difficulty level of the i-th stage.

Output

Calculate how many ways to play all the stages at once there are. Print the answer modulo 1,000,000,007 in a line.

Examples

Input

3 1
1
2
3

Output

4

Input

5 3
9
2
6
8
8

Output

24

Input

5 7
9
9
9
1
5

Output

48

### Response

```cpp
#include<iostream>
#include<algorithm>

using namespace std;
#define MOD 1000000007
int n, t;
int d[108000];
int dp[108000];
int main(){
	cin >> n >> t;
	for(int i = 0;i < n;i++)cin >> d[i];
	sort(d, d + n);
	dp[0] = 1;
	for(int i = 1;i < n;i++){
		dp[i] = dp[i-1] * (i - (lower_bound(d, d + i, d[i]-t) - d) + 1) % MOD;
	}
	cout << dp[n-1] << endl;
}
```


### Prompt

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

Arpa is researching the Mexican wave.

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

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

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

Input

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

Output

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

Examples

Input

10 5 3

Output

3

Input

10 5 7

Output

5

Input

10 5 12

Output

3

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void print(long long a) { cout << a << '\t' << '\n'; }
void print(long long a, long long b) { cout << a << '\t' << b << '\t' << '\n'; }
void print(long long a, long long b, long long c) {
  cout << a << '\t' << b << '\t' << c << '\n';
}
void print(long long a, long long b, long long c, long long d) {
  cout << a << '\t' << b << '\t' << c << '\t' << d << '\n';
}
void print(long long a, long long b, long long c, long long d, long long e) {
  cout << a << '\t' << b << '\t' << c << '\t' << d << '\t' << e << '\n';
}
void MAIN() {
  long long n, k, t;
  cin >> n >> k >> t;
  if (t <= k)
    cout << t;
  else if (k <= t and t <= n)
    cout << k;
  else
    cout << n + k - t;
}
int32_t main() { MAIN(); }

```


### Prompt

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

Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.

The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>.

The pseudo code of the unexpected code is as follows:

    input n
    for i from 1 to n
        input the i-th point's coordinates into p[i]
    sort array p[] by increasing of x coordinate first and increasing of y coordinate second
    d=INF        //here INF is a number big enough
    tot=0
    for i from 1 to n
        for j from (i+1) to n
            ++tot
            if (p[j].x-p[i].x>=d) then break    //notice that "break" is only to be
                                                //out of the loop "for j"
            d=min(d,distance(p[i],p[j]))
    output d

Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.

You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?

Input

A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109).

Output

If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point.

The conditions below must be held:

  * All the points must be distinct.
  * |xi|, |yi| ≤ 109.
  * After running the given code, the value of tot should be larger than k.

Examples

Input

4 3

Output

0 0
0 1
1 0
1 1

Input

2 100

Output

no solution

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void RD(int &x) { scanf("%d\n", &x); }
void RD(long long &x) { scanf("%I64d", &x); }
void RD(unsigned int &x) { scanf("%u", &x); }
void RD(double &x) { scanf("%lf", &x); }
void RD(int &x, int &y) { scanf("%d%d", &x, &y); }
void RD(long long &x, long long &y) { scanf("%I64d%I64d", &x, &y); }
void RD(unsigned int &x, unsigned int &y) { scanf("%u%u", &x, &y); }
void RD(double &x, double &y) { scanf("%lf%lf", &x, &y); }
void RD(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void RD(long long &x, long long &y, long long &z) {
  scanf("%I64d%I64d%I64d", &x, &y, &z);
}
void RD(unsigned int &x, unsigned int &y, unsigned int &z) {
  scanf("%u%u%u", &x, &y, &z);
}
void RD(double &x, double &y, double &z) { scanf("%lf%lf%lf", &x, &y, &z); }
void RD(char &x) { x = getchar(); }
void RD(char *s) { scanf("%s", s); }
void RD(string &s) { cin >> s; }
void PR(int x) { printf("%d\n", x); }
void PR(long long x) { printf("%I64d\n", x); }
void PR(unsigned int x) { printf("%u\n", x); }
void PR(double x) { printf("%.10lf\n", x); }
void PR(char x) { printf("%c\n", x); }
void PR(char *x) { printf("%s\n", x); }
void PR(string x) { cout << x << endl; }
const double inf = 1e50;
const int INF = 1000000000;
const int N = 205;
int n, m;
int main() {
  RD(n, m);
  if (m >= n * (n - 1) / 2)
    puts("no solution");
  else {
    int i;
    for (i = 1; i <= n; i++) printf("0 %d\n", i);
  }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already N stores in the street, numbered 1 through N.

You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.

Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

* 1≤N≤100
* 0≤F_{i,j,k}≤1
* For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.
* -10^7≤P_{i,j}≤10^7
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

Output

Print the maximum possible profit of Joisino's shop.

Examples

Input

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

Output

8

Input

2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

Output

-2

Input

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

Output

23

### Response

```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int n,p[100][11],f[100][10];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<10;j++)cin>>f[i][j];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=10;j++)cin>>p[i][j];
	}
	int ans;
	for(int i=1;i<1<<10;i++)
	{
		int now=0;
		for(int j=0;j<n;j++)
		{
			int cnt=0;
			for(int k=0;k<10;k++)f[j][k]&&(i&(1<<k))&&cnt++;
			now+=p[j][cnt];
		}
		if(i==1)ans=now;
		else ans=max(ans,now);
	}
	cout<<ans<<endl;
}

```


### Prompt

Create a solution in cpp for the following problem:

Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.

<image>

Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.

Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.

Input

The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value.

a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.

Output

Print the only real number x (the desired distance value) in the only line in its decimal notation.

Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.

Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).

Examples

Input

8.549e2

Output

854.9

Input

8.549e3

Output

8549

Input

0.33e0

Output

0.33

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int pos = s.find('.'), pos1 = s.find('e'), cnt = 0, len = s.size();
  if (s[pos - 1] == '0') {
    if (s[pos + 1] == '0' && s[pos + 2] == 'e') {
      cout << 0 << endl;
      return 0;
    }
    printf("0.");
    for (int i = pos + 1; i < pos1; i++) {
      printf("%c", s[i]);
    }
    printf("\n");
  } else {
    int num = 0, step = 0;
    for (int i = len - 1;; i--) {
      if (s[i] == 'e') break;
      num += (s[i] - '0') * pow(10, step);
      step++;
    }
    if (num == 0 && s[pos + 1] == '0' && pos1 - 2 == pos) {
      cout << s[0] << endl;
      return 0;
    }
    int cha = pos1 - pos - 1;
    if (cha > num) {
      for (int i = 0; i < pos; i++) {
        printf("%c", s[i]);
      }
      char op;
      int f = pos;
      for (int i = pos + 1; i < pos + 1 + num; i++) {
        printf("%c", s[i]);
        op = s[i - 1];
        s[i - 1] = s[i];
        s[i] = op;
        f++;
      }
      printf(".");
      for (int i = f; i < pos1; i++) {
        if (s[i] != '.') printf("%c", s[i]);
      }
      printf("\n");
    } else if (cha == num) {
      for (int i = 0; i < pos1; i++) {
        if (s[i] != '.') printf("%c", s[i]);
      }
      printf("\n");
    } else if (cha < num) {
      for (int i = 0; i < pos1; i++) {
        if (s[i] != '.') printf("%c", s[i]);
      }
      for (int i = 0; i < num - cha; i++) {
        printf("0");
      }
      printf("\n");
    }
  }
  return 0;
}

```


### Prompt

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

There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.

In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points).

Input

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

The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≤ x_i ≤ 10^9) — the coordinates of points.

Output

In the first line print m — the maximum possible number of points in a subset that satisfies the conditions described above.

In the second line print m integers — the coordinates of points in the subset you have chosen.

If there are multiple answers, print any of them.

Examples

Input

6
3 5 4 7 10 12

Output

3
7 3 5

Input

5
-1 2 5 8 11

Output

1
8

Note

In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename T1, typename T2>
void mapped(map<T1, T2> m) {
  for (auto ite = m.begin(); ite != m.end(); ++ite) {
    cout << "'" << ite->first << "'"
         << " : " << ite->second << endl;
  }
}
template <typename T1, typename T2>
void mappedArr(map<T1, vector<T2>> m) {
  for (auto ity = m.begin(); ity != m.end(); ++ity) {
    cout << "'" << ity->first << "'"
         << " : "
         << "[";
    for (int i = 0; i < (int)ity->second.size(); ++i) {
      (i == (int)ity->second.size() - 1) ? cout << ity->second[i]
                                         : cout << ity->second[i] << ",";
    }
    cout << "]" << endl;
  }
}
string int_to_string(int x) {
  stringstream ss;
  ss << x;
  string ni = ss.str();
  return ni;
}
int char_to_int(char c) {
  int n = (int)c - 48;
  return n;
}
int string_to_int(string x) {
  int n;
  stringstream s(x);
  s >> n;
  return n;
}
template <typename T1, typename T2>
void ArrPair(vector<pair<T1, T2>> vp) {
  for (int i = 0; i < (int)vp.size(); ++i) {
    cout << "(" << vp[i].first << "," << vp[i].second << ")" << endl;
  }
}
const int MOD = 1e9 + 7;
const long long INF = 1e18L + 5;
unordered_map<int, int> um;
unordered_set<int> us;
set<int> s;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  vector<int> ans;
  ans.push_back(v[0]);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= 30; ++j) {
      long long z = pow(2, j);
      long long left = v[i] - z;
      long long right = v[i] + z;
      bool check_left = binary_search(v.begin(), v.end(), left);
      bool check_right = binary_search(v.begin(), v.end(), right);
      if (check_left && check_right) {
        cout << 3 << "\n";
        cout << v[i] << " " << left << " " << right;
        return 0;
      } else if (check_left) {
        vector<int> val(2);
        val[0] = v[i];
        val[1] = left;
        ans = val;
      } else if (check_right) {
        vector<int> val(2);
        val[0] = v[i];
        val[1] = right;
        ans = val;
      }
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < (int)ans.size(); ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Bob has a string s consisting of lowercase English letters. He defines s' to be the string after removing all "a" characters from s (keeping all other characters in the same order). He then generates a new string t by concatenating s and s'. In other words, t=s+s' (look at notes for an example).

You are given a string t. Your task is to find some s that Bob could have used to generate t. It can be shown that if an answer exists, it will be unique.

Input

The first line of input contains a string t (1 ≤ |t| ≤ 10^5) consisting of lowercase English letters.

Output

Print a string s that could have generated t. It can be shown if an answer exists, it is unique. If no string exists, print ":(" (without double quotes, there is no space between the characters).

Examples

Input

aaaaa

Output

aaaaa

Input

aacaababc

Output

:(

Input

ababacacbbcc

Output

ababacac

Input

baba

Output

:(

Note

In the first example, we have s =  "aaaaa", and s' =  "".

In the second example, no such s can work that will generate the given t.

In the third example, we have s =  "ababacac", and s' =  "bbcc", and t = s + s' =  "ababacacbbcc".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF64 = 1000000000000000000;
const long long BigPrime = 252097800623;
const long double LDINF = 1000000000000;
const long long Mmod = 998244353;
const long long INF = 1000000000;
const long long Mod = 1000000007;
const long double PI = acosl(-1.);
const long double Eps = 10e-10;
const long long Prime = 31;
const unsigned int N = 100005;
string t;
void input() { cin >> t; }
vector<pair<char, int>> pp;
void solve() {
  int lftma = -1;
  for (int i = 0; i < (int)(t).size(); i++)
    if (t[i] == 'a')
      lftma = i;
    else
      pp.push_back(make_pair(t[i], i));
  if (pp.size() % 2 != 0) {
    cout << ":(" << endl;
  } else {
    bool ok = true;
    for (int i = 0, j = pp.size() / 2; j < (int)(pp).size(); i++, j++)
      if (pp[i].first != pp[j].first) ok = false;
    if (pp.size() == 0) {
      cout << t << endl;
    } else if (ok && pp[(int)(pp).size() / 2].second > lftma) {
      cout << t.substr(0, pp[(int)(pp).size() / 2].second) << endl;
    } else {
      cout << ":(" << endl;
    }
  }
}
int main() {
  int testcases = 1;
  for (int _ = 0; _ < testcases; ++_) {
    input();
    solve();
  }
  return 0;
}

```


### Prompt

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

Convenience store Deven Eleven is planning to open its first store in Aizuwakamatsu City to expand its business. There are already many other convenience stores in Aizuwakamatsu, so the place to open a new store is likely to be the key to success. Under the premise that "customers use the convenience store closest to the area where they live," Seven Eleven has decided to open a store at "a point that many customers will use."

| <image>
--- | ---

Seven Eleven has divided the map of Aizuwakamatsu City using a congruent regular hexagon (hereinafter referred to as "block") in order to grasp the range covered by each existing convenience store. At this time, each block was divided so that there was at most one existing convenience store. On this map, the distance to the convenience store is calculated based on the number of blocks that go through from each block to the convenience store. We believe that each block is covered by the convenience store with the shortest distance. The problem is to look for "a block without an existing convenience store that covers as many blocks as possible" based on this map.

As a Deven-Eleven programmer, you have decided to develop a program that calculates the number of blocks that can be covered most widely from the block-divided map information and the information on the candidate sites for new stores.

The map divided into m x n is shown as shown in Fig. 1. There are m hexagonal blocks horizontally and n vertically, each represented by one coordinate (x, y). The left edge of the odd row is located at the bottom left of the left edge of the row above it, and the left edge of the even row is located at the bottom right of the left edge of the row above it. For example, the coordinates (1, 1) indicate the upper left block in Figure 1. Also, the coordinates (1, 2) are located at the lower right of the coordinates (1, 1), and the coordinates (1, 3) are located at the lower left of the coordinates (1, 2).

<image>

Figure 2 shows an example of the case where there are 6 existing convenience stores, which are divided into 6 x 6. Each convenience store is numbered in order from 1. At this time, if the blocks covered by each convenience store are painted separately for each number, it will be as shown in Fig. 3. Unpainted blocks such as coordinates (1, 4) and (2, 5) have two or more closest convenience stores, and neither is a block that can be judged. For example, in the case of a block with coordinates (1, 4), the distance to the convenience store number 4 and the convenience store number 5 are equal, and it is assumed that no convenience store covers this block. The number of blocks covered by the convenience store number 4 is 5.

<image>

Now suppose that Seven Eleven considers coordinates (1, 3) and coordinates (5, 3) as potential sites for a new store. If you set up a store at coordinates (1, 3), the number of blocks that can be covered is 3 (Fig. 4). On the other hand, if you set up a store at coordinates (5, 3), the number of blocks that can be covered is 4 (Fig. 5). Therefore, the number of blocks that can be covered most widely is 4.

<image>

Enter map information m x n, number of existing convenience stores s and their coordinates (x, y), number of candidate sites t and their coordinates (p, q), and the number of blocks that can be covered most widely among all candidate sites. Create a program that outputs.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:

m n
s
x1 y1
x2 y2
::
xs ys ys
t
p1 q1
p2 q2
::
pt qt

The integers m, n (2 ≤ m, n ≤ 100) are given to represent the size (horizontal, vertical) of the divided map on the first line.

The second line gives the number of existing convenience stores s (1 ≤ s ≤ 10). The following s line is given the coordinates xi, y1 of the ith existing convenience store.

The next line is given the number of potential new store sites t (1 ≤ t ≤ 10). The following t line is given the coordinates pi, qi of the i-th candidate site.

The number of datasets does not exceed 20.

Output

For each data set, the number of blocks that can cover the widest of all candidate sites is output on one line.

Example

Input

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

Output

4
4

### Response

```cpp
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef pair < int , int > Pi;
typedef pair < int , Pi > Pii;
#define fr first
#define sc second

int m, n, s;
int min_cost[100][100];
bool used[100][100];
int dy[] = {-1,0,1,-1,0,1};
int dx[][6] = {{ -1,-1,-1,0,1,0}, {0,-1,0,1,1,1}};

bool isover(int y, int x){
  return y < 0 || y >= n || x < 0 || x >= m;
}

void bfs(int y, int x){
  queue< Pii > que;
  que.push(Pii( 0, Pi( y, x)));
  min_cost[y][x] = 0;
  while(!que.empty()){
    Pii p = que.front();
    que.pop();
    for(int i = 0 ; i < 6 ; i++ ){
      int ny = p.sc.fr + dy[i], nx = p.sc.sc + dx[p.sc.fr % 2][i];
      if(isover( ny, nx) || min_cost[ny][nx] <= p.fr + 1) continue;
      que.push(Pii( p.fr + 1, Pi( ny, nx)));
      min_cost[ny][nx] = p.fr + 1;
    }
  }
}

int prebfs(int y, int x){
  if(!min_cost[y][x]) return 0;

  int ret = 1;
  fill_n( *used, 10000, false);
  queue< Pii > que;
  que.push(Pii( 0, Pi( y, x)));
  used[y][x] = true;

  while(!que.empty()){
    Pii p = que.front();
    que.pop();
    for(int i = 0 ; i < 6 ; i++ ){
      int ny = p.sc.fr + dy[i], nx = p.sc.sc + dx[p.sc.fr % 2][i];
      if(isover( ny, nx) || used[ny][nx] || min_cost[ny][nx] <= p.fr + 1) continue;
      que.push(Pii( p.fr + 1, Pi( ny, nx)));
      used[ny][nx] = true;
      ret++;
    }
  }
  return ret;
}

int main(){
  while(cin >> m, m){
    fill_n( *min_cost, 10000, 1 << 30);

    cin >> n >> s;

    for(int i = 0 ; i < s ; i++ ){
      int x, y;
      cin >> x >> y;
      bfs( y - 1, x - 1);
    }

    int t, ret = 0;
    cin >> t;
    while(t--){
      int p, q;
      cin >> p >> q;
      ret = max( ret,prebfs( q - 1, p - 1));
    }
    cout << ret << endl;
  }
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.

Find the maximum possible value of <image> after performing at most k operations optimally.

Input

The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

Output the maximum value of a bitwise OR of sequence elements after performing operations.

Examples

Input

3 1 2
1 1 1

Output

3

Input

4 2 3
1 2 4 8

Output

79

Note

For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.

For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(9);
  int T = 1;
  while (T-- > 0) {
    int n, k, x;
    cin >> n >> k >> x;
    vector<int> a;
    vector<int> dig(32);
    int total = 0;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      total |= x;
      a.push_back(x);
      for (int j = 0; j < 32; ++j) {
        int mask = 1 << j;
        if (mask & x) {
          dig[j]++;
        }
      }
    }
    vector<int> b;
    for (int i = 0; i < n; ++i) {
      int res = total;
      for (int j = 0; j < 32; ++j) {
        if (dig[j]) {
          int mask = 1 << j;
          if (a[i] & mask) {
            if (dig[j] == 1) {
              res -= mask;
            }
          }
        }
      }
      b.push_back(res);
    }
    long long p = 1;
    for (int j = 0; j < k; ++j) p *= x;
    long long maxres = 0;
    for (int i = 0; i < n; ++i) {
      long long res = b[i] | (a[i] * 1ll * p);
      maxres = max(maxres, res);
    }
    cout << maxres << "\n";
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti ≥ di, then i-th item cannot be saved.

Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b — in ta + tb seconds after fire started.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house.

Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of item i.

Output

In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.

Examples

Input

3
3 7 4
2 6 5
3 7 6

Output

11
2
2 3

Input

2
5 6 1
3 3 5

Output

1
1
1

Note

In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.

In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, dp[200][3000], maxx, sol[1000000], idx;
struct node {
  int t, d, p, idx;
};
struct node1 {
  int x, y, idx;
};
map<int, int> mapa;
node a[10000];
node1 prosli[200][3000];
set<int> s;
bool cmp(node a, node b) { return a.d < b.d; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d %d %d", &a[i].t, &a[i].d, &a[i].p), a[i].idx = i;
  sort(a + 1, a + n + 1, cmp);
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 2000; j++) {
      if (dp[i + 1][j + a[i + 1].t] < dp[i][j] + a[i + 1].p &&
          j + a[i + 1].t < a[i + 1].d) {
        prosli[i + 1][j + a[i + 1].t].idx = a[i + 1].idx;
        prosli[i + 1][j + a[i + 1].t].x = i;
        prosli[i + 1][j + a[i + 1].t].y = j;
        dp[i + 1][j + a[i + 1].t] = dp[i][j] + a[i + 1].p;
      }
      if (dp[i + 1][j] < dp[i][j]) {
        prosli[i + 1][j].idx = prosli[i][j].idx;
        prosli[i + 1][j].x = i;
        prosli[i + 1][j].y = j;
        dp[i + 1][j] = dp[i][j];
      }
      maxx = max(maxx, dp[i][j]);
    }
  }
  cout << maxx << endl;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 2000; j++) {
      if (dp[i][j] == maxx) {
        int x = i, y = j;
        int t = prosli[x][y].idx;
        while (t != 0) {
          if (!mapa[t]) sol[++idx] = t;
          mapa[t] = 1;
          int p = prosli[x][y].x;
          int p1 = prosli[x][y].y;
          x = p;
          y = p1;
          t = prosli[p][p1].idx;
        }
        cout << idx << endl;
        for (int i = idx; i >= 1; i--) printf("%d ", sol[i]);
        return 0;
      }
    }
  }
  return 0;
}

```


### Prompt

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

Vanya is doing his maths homework. He has an expression of form <image>, where x1, x2, ..., xn are digits from 1 to 9, and sign <image> represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.

Input

The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs  +  and  * .

The number of signs  *  doesn't exceed 15.

Output

In the first line print the maximum possible value of an expression.

Examples

Input

3+5*7+8*4

Output

303

Input

2+3*5

Output

25

Input

3*4*5

Output

60

Note

Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.

Note to the second sample test. (2 + 3) * 5 = 25.

Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void put(int x, int t, stack<long long> &s) {
  if (t == 0)
    s.push(x);
  else {
    long long y = s.top();
    s.pop();
    s.push(y * x);
  }
}
long long res(stack<long long> &s) {
  long long ans = 0;
  while (!s.empty()) {
    ans += s.top();
    s.pop();
  }
  return ans;
}
long long compute(int n, int st, int e, string &str) {
  stack<long long> s[2];
  int lt = 0, is = 0;
  for (int i = 1; i < n; i += 2) {
    int x = str[i] - '0';
    int t = (str[i - 1] == '+' ? 0 : 1);
    if (i == st) {
      is = 1;
      lt = t;
      t = 0;
    }
    put(x, t, s[is]);
    if (i == e) {
      long long y = res(s[1]);
      put(y, lt, s[0]);
      is = 0;
    }
  }
  long long ans = res(s[is]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  s = "+" + s;
  int n = s.length();
  long long ans = compute(n, 1, n - 1, s);
  for (int i = 1; i < n; i += 2)
    for (int j = i; j < n; j += 2) {
      if (i >= 3 && s[i - 1] == '+' && s[i - 3] == '+') continue;
      if (j + 3 < n && s[j + 1] == '+' && s[j + 3] == '+') continue;
      ans = max(ans, compute(n, i, j, s));
    }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Mr. A came to Aizu for sightseeing. You can overlook the Aizu Basin from the window of the hotel where you stayed. As I was looking at the scenery, I noticed a piece of the photo on the floor. Apparently I took the outside view from the window. "Which area did you take?" A asked, holding the photo so that the view outside the window and the picture were the same size, and began looking for a place where the picture and the view outside the window matched. ..

Now let's do what Mr. A is doing on his computer. Divide the view outside the window into squares of n x n squares (n is called the size of the view). Each cell has an integer greater than or equal to 0 that represents the information in the image of that cell. The position of the cell is represented by the coordinates (x, y). The coordinates of each square are as follows.

<image>

A piece of a photo is represented by a square of m x m squares (m is called the size of the piece of the photo). In this square, the image information is written in the square of the piece, and -1 is written in the square of the part not included in the piece. For example, in the figure below, the colored areas represent the shape of the actual photo scraps. There may be holes in the pieces, but they are always connected together. (If cells with a value greater than or equal to 0 touch only at the vertices, they are considered unconnected.) Also, cells with a value of -1 are not lined up in a vertical or horizontal column from end to end.

<image>

In the view through the window, look for an area that matches a piece of the photo rotated 0, 90, 180, or 270 degrees. For example, if the landscape looks like the one below, you can rotate the piece in the above figure 90 degrees counterclockwise to match the colored area.

<image>

Entering the information of the view from the window and the piece of the photo, the square closest to the top of the area that matches any of the pieces rotated by 0, 90, 180, or 270 degrees is the closest to the left end. Create a program that outputs the coordinates of the mass.

If there are multiple matching areas, output the coordinates of the cell closest to the leftmost of the cells in those areas. If there is no matching area, NA is output.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:

n m
w11 w12 ... w1n
w21 w22 ... w2n
::
wn1 wn2 ... wnn
p11 p12 ... p1m
p21 p22 ... p2m
::
pm1 pm2 ... pmm

The first line gives n, m (1 ≤ n ≤ 100, 1 ≤ m ≤ 50, m ≤ n).

The next n lines give information about the view from the window wij (0 ≤ wij ≤ 15), and the following m lines give information about the data of the photo scraps pij (-1 ≤ pij ≤ 15).

The number of datasets does not exceed 100.

Output

Outputs the coordinates or NA of the mass position on one line for each input dataset.

Example

Input

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

Output

4 2
NA

### Response

```cpp
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<vector<int>>rot(vector<vector<int>>v) {
	vector<vector<int>>rotated(v);
	for (int i = 0; i < v.size(); ++i) {
		for (int j = 0; j < v.size(); ++j) {
			rotated[i][j]=v[v.size()-j-1][i];
		}
	}
	return rotated;
}

pair<int,int> check(vector<vector<int>>&f, vector<vector<int>>&p, int l, int u) {
	pair<int,int>ans(10000,10000);;
	for (int x = l; x < l + p.size(); ++x) {
		for (int y = u; y < u + p.size(); ++y) {
			if (p[y - u][x - l] != -1) {
				ans=min(ans,make_pair(y,x));
				if (f[y][x] != p[y - u][x - l])return make_pair(10000, 10000);

			}
		}
	}
	return ans;
}
int main() {
	while (true) {
		int N,M;cin>>N>>M;
		if(!N)break;
		vector<vector<int>>field(N,vector<int>(N));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cin>>field[i][j];
			}
		}
		vector<vector<int>>picture(M,vector<int>(M));
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < M; ++j) {
				cin >> picture[i][j];
			}
		}
		pair<int,int>ans(10000,10000);
		for (int l = 0; l <= N - M; ++l) {
			for (int u = 0; u <= N - M; ++u) {
				for (int k = 0; k < 4; ++k) {
					picture=rot(picture);
					ans=min(ans,check(field,picture,l,u));
				}
			}
		}
		if (ans.first == 10000) {
			cout<<"NA"<<endl;
		}
		else {
			cout<<ans.second+1<<" "<<ans.first+1<<endl;
		}
	}
	return 0;
}

```


### Prompt

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

You are given an array s consisting of n integers.

You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.

Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such element in s, then you cannot cut out one more copy of t. The both arrays can contain duplicate elements.

For example, if s = [1, 2, 3, 2, 4, 3, 1] and k = 3 then one of the possible answers is t = [1, 2, 3]. This array t can be cut out 2 times.

  * To cut out the first copy of t you can use the elements [1, \underline{2}, 3, 2, 4, \underline{3}, \underline{1}] (use the highlighted elements). After cutting out the first copy of t the array s can look like [1, 3, 2, 4].
  * To cut out the second copy of t you can use the elements [\underline{1}, \underline{3}, \underline{2}, 4]. After cutting out the second copy of t the array s will be [4].

Your task is to find such array t that you can cut out the copy of t from s maximum number of times. If there are multiple answers, you may choose any of them.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of elements in s and the desired number of elements in t, respectively.

The second line of the input contains exactly n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2 ⋅ 10^5).

Output

Print k integers — the elements of array t such that you can cut out maximum possible number of copies of this array from s. If there are multiple answers, print any of them. The required array t can contain duplicate elements. All the elements of t (t_1, t_2, ..., t_k) should satisfy the following condition: 1 ≤ t_i ≤ 2 ⋅ 10^5.

Examples

Input

7 3
1 2 3 2 4 3 1

Output

1 2 3

Input

10 4
1 3 1 3 10 3 7 7 12 3

Output

7 3 1 3

Input

15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1

Output

1 1

Note

The first example is described in the problem statement.

In the second example the only answer is [7, 3, 1, 3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 2.

In the third example the array t can be cut out 5 times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200 * 1000 + 1;
int n, k;
vector<int> s, t;
vector<int> cnts(MAX);
bool can(int cnt) {
  t.clear();
  for (int i = 0; i < MAX; ++i) {
    int need = min(cnts[i] / cnt, k - int(t.size()));
    for (int j = 0; j < need; ++j) {
      t.push_back(i);
    }
  }
  return int(t.size()) == k;
}
int main() {
  cin >> n >> k;
  s = vector<int>(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (auto c : s) {
    ++cnts[c];
  }
  int l = 0, r = n;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (can(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  if (!can(r)) can(l);
  for (auto it : t) cout << it << " ";
  cout << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.

Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.

How many combinations of "on" and "off" states of the switches light all the bulbs?

Constraints

* 1 \leq N, M \leq 10
* 1 \leq k_i \leq N
* 1 \leq s_{ij} \leq N
* s_{ia} \neq s_{ib} (a \neq b)
* p_i is 0 or 1.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
k_1 s_{11} s_{12} ... s_{1k_1}
:
k_M s_{M1} s_{M2} ... s_{Mk_M}
p_1 p_2 ... p_M

Output

Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.

Examples

Input

2 2
2 1 2
1 2
0 1

Output

1

Input

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

Output

0

Input

5 2
3 1 2 5
2 2 3
1 0

Output

8

### Response

```cpp
#include <iostream>
#include <tuple>
#include <algorithm>

using namespace std;

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

int s[10];

int count(int n, int p) {
  if(n <= 0) return p == 0;
  else return count(n-1, p ^ s[n-1]) + count(n-1, p);
}

int main() {
  int n, m, p = 0;
  cin >> n >> m;
  rep(i,m) {
    int k;
    cin >> k;
    rep(j,k) {
      int b;
      cin >> b;
      s[b-1] += 1 << i;
    }
  }
  rep(i,m) {
    int b;
    cin >> b;
    p += b << i;
  }

  cout << count(n, p) << endl;
  return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

Ichiro likes baseball and has decided to write a program which simulates baseball.

The program reads events in an inning and prints score in that inning. There are only three events as follows:

Single hit

* put a runner on the first base.
* the runner in the first base advances to the second base and the runner in the second base advances to the third base.
* the runner in the third base advances to the home base (and go out of base) and a point is added to the score.

Home run

* all the runners on base advance to the home base.
* points are added to the score by an amount equal to the number of the runners plus one.

Out

* The number of outs is increased by 1.
* The runners and the score remain stationary.
* The inning ends with three-out.

Ichiro decided to represent these events using "HIT", "HOMERUN" and "OUT", respectively.

Write a program which reads events in an inning and prints score in that inning. You can assume that the number of events is less than or equal to 100.

Input

The input consists of several datasets. In the first line, the number of datasets n is given. Each dataset consists of a list of events (strings) in an inning.

Output

For each dataset, prints the score in the corresponding inning.

Example

Input

2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT

Output

7
0

### Response

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

int main(void){

	int n;
	cin >> n;

	int runner = 0;
	int result = 0;

	int i = 0;
	while(i < n * 3){

		string buff;
		cin >> buff;

		if (buff == "HIT"){
			runner++;
			if (runner > 3){
				result++;
				runner = 3;
			}
		}
		else if (buff == "OUT"){
			i++;
			if (i % 3 == 0){
				cout << result << endl;
				runner = 0;
				result = 0;
			}
		}
		else if (buff == "HOMERUN") {
			result += (runner + 1);
			runner = 0;
		}

	}

	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

In problems on strings one often has to find a string with some particular properties. The problem authors were reluctant to waste time on thinking of a name for some string so they called it good. A string is good if it doesn't have palindrome substrings longer than or equal to d.

You are given string s, consisting only of lowercase English letters. Find a good string t with length |s|, consisting of lowercase English letters, which is lexicographically larger than s. Of all such strings string t must be lexicographically minimum.

We will call a non-empty string s[a ... b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|) a substring of string s = s1s2... s|s|.

A non-empty string s = s1s2... sn is called a palindrome if for all i from 1 to n the following fulfills: si = sn - i + 1. In other words, palindrome read the same in both directions.

String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in such strings are compared like their ASCII codes.

Input

The first line contains integer d (1 ≤ d ≤ |s|).

The second line contains a non-empty string s, its length is no more than 4·105 characters. The string consists of lowercase English letters.

Output

Print the good string that lexicographically follows s, has the same length and consists of only lowercase English letters. If such string does not exist, print "Impossible" (without the quotes).

Examples

Input

3
aaaaaaa

Output

aabbcaa

Input

3
zzyzzzz

Output

Impossible

Input

4
abbabbbabbb

Output

abbbcaaabab

### Response

```cpp
#include <bits/stdc++.h>
char s[1000007], ans[1000007];
int n, j, m, f[1000007], g[1000007], p[1000007];
bool check(int y, int L) {
  int x = y - L;
  if (x < 0) return 1;
  return (g[y] - g[x] * p[L]) * p[x + 1] != f[y] - f[x];
}
void dfs(int t, bool beyond) {
  if (t > n) {
    puts(ans + 1);
    exit(0);
  }
  for (char i = beyond ? 'a' : s[t]; i <= 'z'; i++) {
    ans[t] = i, f[t] = f[t - 1] + i * p[t], g[t] = g[t - 1] * 1000007 + i;
    if (check(t, m) && check(t, m + 1)) dfs(t + 1, beyond || i > s[t]);
  }
}
int main() {
  scanf("%d%s", &m, s + 1), j = n = strlen(s + 1);
  while (j && s[j] == 'z') s[j--] = 'a';
  if (!j) return puts("Impossible"), 0;
  s[j]++, p[0] = 1;
  for (j = 1; j <= n; j++) p[j] = p[j - 1] * 1000007;
  dfs(1, 0);
  puts("Impossible");
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.

There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.

What is the minimum amount of money with which he can buy M cans of energy drinks?

It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

Constraints

* All values in input are integers.
* 1 \leq N, M \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^5
* B_1 + ... + B_N \geq M

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

Examples

Input

2 5
4 9
2 4

Output

12

Input

4 30
6 18
2 5
3 10
7 9

Output

130

Input

1 100000
1000000000 100000

Output

100000000000000

### Response

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

using ll = long long;
using namespace std;

int n, m;
ll ans;

int main(){
	vector< pair<int, int> > t;
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		int a, b; cin >> a >> b;
		t.push_back(make_pair(a, b));
	}
	sort(t.begin(), t.end());

	for(int i = 0; i < n; ++i){
		int honsu = min(m, t[i].second);
		if(honsu > 0){
			m -= honsu;
			ans += 1LL * honsu * t[i].first;
		}else break;
	}
	cout << ans << endl;
}
```


### Prompt

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

There is a railroad in Takahashi Kingdom. The railroad consists of N sections, numbered 1, 2, ..., N, and N+1 stations, numbered 0, 1, ..., N. Section i directly connects the stations i-1 and i. A train takes exactly A_i minutes to run through section i, regardless of direction. Each of the N sections is either single-tracked over the whole length, or double-tracked over the whole length. If B_i = 1, section i is single-tracked; if B_i = 2, section i is double-tracked. Two trains running in opposite directions can cross each other on a double-tracked section, but not on a single-tracked section. Trains can also cross each other at a station.

Snuke is creating the timetable for this railroad. In this timetable, the trains on the railroad run every K minutes, as shown in the following figure. Here, bold lines represent the positions of trains running on the railroad. (See Sample 1 for clarification.)

<image>

When creating such a timetable, find the minimum sum of the amount of time required for a train to depart station 0 and reach station N, and the amount of time required for a train to depart station N and reach station 0. It can be proved that, if there exists a timetable satisfying the conditions in this problem, this minimum sum is always an integer.

Formally, the times at which trains arrive and depart must satisfy the following:

* Each train either departs station 0 and is bound for station N, or departs station N and is bound for station 0.
* Each train takes exactly A_i minutes to run through section i. For example, if a train bound for station N departs station i-1 at time t, the train arrives at station i exactly at time t+A_i.
* Assume that a train bound for station N arrives at a station at time s, and departs the station at time t. Then, the next train bound for station N arrives at the station at time s+K, and departs the station at time t+K. Additionally, the previous train bound for station N arrives at the station at time s-K, and departs the station at time t-K. This must also be true for trains bound for station 0.
* Trains running in opposite directions must not be running on the same single-tracked section (except the stations at both ends) at the same time.

Constraints

* 1 \leq N \leq 100000
* 1 \leq K \leq 10^9
* 1 \leq A_i \leq 10^9
* A_i is an integer.
* B_i is either 1 or 2.

Input

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

N K
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print an integer representing the minimum sum of the amount of time required for a train to depart station 0 and reach station N, and the amount of time required for a train to depart station N and reach station 0. If it is impossible to create a timetable satisfying the conditions, print -1 instead.

Examples

Input

3 10
4 1
3 1
4 1

Output

26

Input

1 10
10 1

Output

-1

Input

6 4
1 1
1 1
1 1
1 1
1 1
1 1

Output

12

Input

20 987654321
129662684 2
162021979 1
458437539 1
319670097 2
202863355 1
112218745 1
348732033 1
323036578 1
382398703 1
55854389 1
283445191 1
151300613 1
693338042 2
191178308 2
386707193 1
204580036 1
335134457 1
122253639 1
824646518 2
902554792 2

Output

14829091348

### Response

```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=4e5+5;
typedef long long ll;
#define lch x<<1
#define rch x<<1|1
ll tree[N];
ll a[N],b[N];
ll cnt,n,k;
ll sum[N];
ll t[N];
ll L[N],R[N];
ll dp[N];
void Pushdown(ll x){
    if(tree[x]){
        tree[lch]=tree[rch]=tree[x];
        tree[x]=0;
    }
}
void Modify(ll x,ll l,ll r,ll pl,ll pr,ll d){
    if(l>r||pl>pr)
        return ;
    if(pl<=l&&r<=pr){
        tree[x]=d;
        return ;
    }
    Pushdown(x);
    ll mid=(l+r)>>1;
    if(pl<=mid)
        Modify(lch,l,mid,pl,pr,d);
    if(pr>mid)
        Modify(rch,mid+1,r,pl,pr,d);
}
ll Query(ll x,ll l,ll r,ll pos){
    if(l==r)
        return tree[x];
    Pushdown(x);
    ll mid=(l+r)>>1;
    if(pos<=mid)
        return Query(lch,l,mid,pos);
    else
        return Query(rch,mid+1,r,pos);
}
ll Ask(ll pos){
    ll c=Query(1,1,cnt,pos);
    if(!c)
        return 0;
    ll res=1ll*dp[c]+(t[L[c]]-t[pos]+k)%k;
    return res;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(ll i=1;i<=n;i++){
        scanf("%d%d",&a[i],&b[i]);
        sum[i]=sum[i-1]+a[i];
        if(b[i]==1&&2*a[i]>k){
            puts("-1");
            return 0;
        }
    }
    for(ll i=1;i<=n;i++){
        if(b[i]==1){
            L[i]=(-2*sum[i-1]%k+k)%k;
            R[i]=(-2*sum[i]%k+k)%k;
        }
        else{
            L[i]=0;
            R[i]=k-1;
        }
        t[i*2-1]=L[i];
        t[i*2]=R[i];
    }
    sort(t+1,t+2*n+1);
    cnt=unique(t+1,t+2*n+1)-t-1;
    for(ll i=1;i<=n;i++){
        L[i]=lower_bound(t+1,t+cnt+1,L[i])-t,R[i]=lower_bound(t+1,t+cnt+1,R[i])-t;
    }
    for(ll i=n;i>0;i--){
        dp[i]=Ask(L[i]);
        if(L[i]>R[i]){
            Modify(1,1,cnt,R[i]+1,L[i]-1,i);
        }
        else{
            Modify(1,1,cnt,1,L[i]-1,i);
            Modify(1,1,cnt,R[i]+1,cnt,i);
        }
    }
    ll ans=dp[1];
    for(ll i=1;i<=cnt;i++){
        ans=min(ans,Ask(i));
        //printf("%lld\n",Ask(i));
    }
    printf("%lld\n",ans+sum[n]*2);
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined <image>. You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.

Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.

Input

The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively.

Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A.

Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.

Output

Output a single integer — the minimum possible value of <image> after doing exactly k1 operations on array A and exactly k2 operations on array B.

Examples

Input

2 0 0
1 2
2 3

Output

2

Input

2 1 0
1 2
2 2

Output

0

Input

2 5 7
3 4
14 4

Output

1

Note

In the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2.

In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.

In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[10005], t;
long long cnt(int n, int k) {
  long long ans = 0, m;
  int tmp = n, p;
  while (tmp > 0) {
    if (a[tmp] != a[tmp - 1]) {
      p = n + 1 - tmp;
      if (k >= p * (a[tmp] - a[tmp - 1])) {
        k -= p * (a[tmp] - a[tmp - 1]);
      } else {
        m = a[tmp] - k / p;
        ans += (m - 1) * (m - 1) * (k % p);
        ans += m * m * (p - k % p);
        for (int i = 0; i < tmp; ++i) ans += a[i] * a[i];
        return ans;
      }
    }
    --tmp;
  }
  if (k % 2 == 0)
    return ans;
  else
    return ans + 1ll;
}
int main() {
  int n, k1, k2;
  scanf("%d%d%d", &n, &k1, &k2);
  k1 += k2;
  a[0] = 0;
  for (int i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
  for (int i = 1; i <= n; ++i)
    scanf("%I64d", &t), a[i] = a[i] > t ? a[i] - t : t - a[i];
  std::sort(a, a + n + 1);
  printf("%I64d\n", cnt(n, k1));
  return 0;
}

```