### Prompt

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

You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.

You have to answer t independent test cases.

Input

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

The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).

Output

For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.

Example

Input

6
3 1
4 2
10 3
10 2
16 4
16 5

Output

YES
YES
NO
YES
YES
NO

Note

In the first test case, you can represent 3 as 3.

In the second test case, the only way to represent 4 is 1+3.

In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.

In the fourth test case, you can represent 10 as 3+7, for example.

In the fifth test case, you can represent 16 as 1+3+5+7.

In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (float(n - k) / 2 != (n - k) / 2)
      cout << "NO" << endl;
    else {
      long long num = (n - k) / 2;
      if (num == 1 && k <= 2)
        cout << "YES" << endl;
      else if (num >= k * (k - 1) / 2)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}

```


### Prompt

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

In this problem you will have to deal with a very special network.

The network consists of two parts: part A and part B. Each part consists of n vertices; i-th vertex of part A is denoted as Ai, and i-th vertex of part B is denoted as Bi.

For each index i (1 ≤ i < n) there is a directed edge from vertex Ai to vertex Ai + 1, and from Bi to Bi + 1, respectively. Capacities of these edges are given in the input. Also there might be several directed edges going from part A to part B (but never from B to A).

You have to calculate the [maximum flow value](https://en.wikipedia.org/wiki/Maximum_flow_problem) from A1 to Bn in this network. Capacities of edges connecting Ai to Ai + 1 might sometimes change, and you also have to maintain the maximum flow value after these changes. Apart from that, the network is fixed (there are no changes in part B, no changes of edges going from A to B, and no edge insertions or deletions).

Take a look at the example and the notes to understand the structure of the network better.

Input

The first line contains three integer numbers n, m and q (2 ≤ n, m ≤ 2·105, 0 ≤ q ≤ 2·105) — the number of vertices in each part, the number of edges going from A to B and the number of changes, respectively.

Then n - 1 lines follow, i-th line contains two integers xi and yi denoting that the edge from Ai to Ai + 1 has capacity xi and the edge from Bi to Bi + 1 has capacity yi (1 ≤ xi, yi ≤ 109).

Then m lines follow, describing the edges from A to B. Each line contains three integers x, y and z denoting an edge from Ax to By with capacity z (1 ≤ x, y ≤ n, 1 ≤ z ≤ 109). There might be multiple edges from Ax to By.

And then q lines follow, describing a sequence of changes to the network. i-th line contains two integers vi and wi, denoting that the capacity of the edge from Avi to Avi + 1 is set to wi (1 ≤ vi < n, 1 ≤ wi ≤ 109).

Output

Firstly, print the maximum flow value in the original network. Then print q integers, i-th of them must be equal to the maximum flow value after i-th change.

Example

Input

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

Output

9
14
14

Note

This is the original network in the example:

<image>

### Response

```cpp
#include <bits/stdc++.h>
struct segt {
  long long mn, ad;
} tr[1111111];
long long min(long long x, long long y) { return (x < y) ? x : y; }
void pushu(int p) { tr[p].mn = min(tr[p << 1].mn, tr[p << 1 | 1].mn); }
void push(int p, long long d) { tr[p].ad += d, tr[p].mn += d; }
void pushd(int p) {
  if (tr[p].ad)
    push(p << 1, tr[p].ad), push(p << 1 | 1, tr[p].ad), tr[p].ad = 0;
}
int n, m, q;
void modify(int l, int r, long long d, int p = 1, int pl = 1, int pr = n) {
  if (l > pr || pl > r) return;
  if (pl >= l && pr <= r) return push(p, d);
  int mid = (pl + pr) >> 1;
  pushd(p), modify(l, r, d, p << 1, pl, mid),
      modify(l, r, d, p << 1 | 1, mid + 1, pr), pushu(p);
}
long long cst[1111111], va[1111111], vb[1111111];
std::multiset<long long> S;
int t[1111111], l[1111111];
std::vector<int> v[1111111];
int main() {
  scanf("%d%d%d", &n, &m, &q);
  register int i;
  for (i = 1; i < n; i++)
    scanf("%lld%lld", va + i, vb + i), modify(i + 1, i + 1, vb[i]);
  int x, y;
  for (i = 1; i <= m; i++) scanf("%d%d%d", &x, t + i, l + i), v[x].push_back(i);
  for (i = 1; i <= n; i++) {
    for (auto r : v[i]) modify(1, t[r], l[r]);
    cst[i] = tr[1].mn;
  }
  for (i = 1; i <= n; i++) S.insert(cst[i] + va[i]);
  printf("%lld\n", *S.begin());
  for (i = 1; i <= q; i++)
    scanf("%d%d", &x, &y), S.erase(S.find(cst[x] + va[x])),
        va[x] = y, S.insert(cst[x] + y), printf("%lld\n", *S.begin());
}

```


### Prompt

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

Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an).

Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws each box vertically down on the first wi stairs of the staircase, that is, the box covers stairs with numbers 1, 2, ..., wi. Each thrown box flies vertically down until at least one of the two following events happen:

  * the bottom of the box touches the top of a stair;
  * the bottom of the box touches the top of a box, thrown earlier.

We only consider touching of the horizontal sides of stairs and boxes, at that touching with the corners isn't taken into consideration. Specifically, that implies that a box with width wi cannot touch the stair number wi + 1.

You are given the description of the staircase and the sequence in which Dima threw the boxes at it. For each box, determine how high the bottom of the box after landing will be. Consider a box to fall after the previous one lands.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of n integers, a1, a2, ..., an (1 ≤ ai ≤ 109; ai ≤ ai + 1).

The next line contains integer m (1 ≤ m ≤ 105) — the number of boxes. Each of the following m lines contains a pair of integers wi, hi (1 ≤ wi ≤ n; 1 ≤ hi ≤ 109) — the size of the i-th thrown box.

The numbers in the lines are separated by spaces.

Output

Print m integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.

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

Examples

Input

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

Output

1
3
4
6

Input

3
1 2 3
2
1 1
3 1

Output

1
3

Input

1
1
5
1 2
1 10
1 10
1 10
1 10

Output

1
3
13
23
33

Note

The first sample are shown on the picture.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, m;
int a[MAXN];
int w[MAXN], h[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &w[i], &h[i]);
  }
  long long lasth = 0;
  for (int i = 1; i <= m; i++) {
    long long int x = lasth + 1;
    if (a[w[i]] > x) x = a[w[i]];
    printf("%I64d\n", x);
    lasth = x + h[i] - 1;
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Simon has a prime number x and an array of non-negative integers a1, a2, ..., an.

Simon loves fractions very much. Today he wrote out number <image> on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: <image>, where number t equals xa1 + a2 + ... + an. Now Simon wants to reduce the resulting fraction.

Help him, find the greatest common divisor of numbers s and t. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109 + 7).

Input

The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number.

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

Output

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

Examples

Input

2 2
2 2

Output

8

Input

3 3
1 2 3

Output

27

Input

2 2
29 29

Output

73741817

Input

4 5
0 0 0 0

Output

1

Note

In the first sample <image>. Thus, the answer to the problem is 8.

In the second sample, <image>. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.

In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.

In the fourth sample <image>. Thus, the answer to the problem is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[100666];
map<long long, int> fr;
long long i, x, st, numar;
long long n;
long long lgpow(long long val, long long P) {
  if (P == 1) return val;
  if (P == 0) return 1;
  long long V = lgpow(val, P / 2);
  V *= V;
  V %= 1000000007;
  if (P % 2) V *= val;
  V %= 1000000007;
  return V;
}
int main() {
  cin >> n >> x;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    st += a[i];
  }
  long long vmin = ((long long)1 << (long long)60);
  for (i = 1; i <= n; ++i) {
    long long V = st - a[i];
    fr[V]++;
    vmin = min(vmin, V);
  }
  for (i = vmin; i <= st; ++i) {
    if (fr.find(i) != fr.end()) numar += fr[i];
    if (numar % x) {
      cout << lgpow(x, i);
      return 0;
    }
    long long h = numar / x;
    fr[i + 1] += h;
  }
  cout << lgpow(x, st);
  return 0;
}

```


### Prompt

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

Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and reverse specified elements by a list of the following operation:

* reverse($b, e$): reverse the order of $a_b, a_{b+1}, ..., a_{e-1}$

Constraints

* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$

Input

The input is given in the following format.

$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1$
$b_2 \; e_2$
:
$b_{q} \; b_{q}$

In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by two integers $b_i \; e_i$ in the following $q$ lines.

Output

Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.

Example

Input

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

Output

1 6 5 8 7 2 3 4

### Response

```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int n,q;
int a[1000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	cin>>q;
	for(int i=0;i<q;i++)
	{
		int b,e;cin>>b>>e;
		reverse(a+b,a+e);
	}
	for(int i=0;i<n;i++)cout<<(i?" ":"")<<a[i];
	cout<<endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i.

Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime:

* Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes.

Find the minimum possible total cost incurred.

Constraints

* All values in input are integers.
* 2 \leq N \leq 400
* 1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print the minimum possible total cost incurred.

Examples

Input

4
10 20 30 40

Output

190

Input

5
10 10 10 10 10

Output

120

Input

3
1000000000 1000000000 1000000000

Output

5000000000

Input

6
7 6 8 6 1 1

Output

68

### Response

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

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

int a[410];
long long pre[410];
long long dp[410][410];

int main(void) {
	int N;
	cin >> N;
	memset(dp, 127, sizeof dp);
	REP(i,N) {
		cin >> a[i];
		pre[i] = pre[i-1] + a[i];
		dp[i][i] = 0;
	}
	for (int i = N-2; i >= 0; i--)
		for (int j = i+1; j < N; j++)
			for (int k = i; k < j; k++)
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + pre[j] - pre[i-1]);
	cout << dp[0][N-1] << endl;
	return 0;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.

According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:

* All even numbers written on the document are divisible by 3 or 5.

If the immigrant should be allowed entry according to the regulation, output `APPROVED`; otherwise, print `DENIED`.

Constraints

* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

If the immigrant should be allowed entry according to the regulation, print `APPROVED`; otherwise, print `DENIED`.

Examples

Input

5
6 7 9 10 31

Output

APPROVED

Input

3
28 27 24

Output

DENIED

### Response

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

int n, a;
int main() {
	cin >> n;
	while(n--) {
		cin >> a;
		if(a%2==0 && a%3 && a%5) return puts("DENIED")*0;
	}
	return puts("APPROVED")*0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya calls a mask of a positive integer n the number that is obtained after successive writing of all lucky digits of number n from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number.

Petya has two numbers — an arbitrary integer a and a lucky number b. Help him find the minimum number c (c > a) such that the mask of number c equals b.

Input

The only line contains two integers a and b (1 ≤ a, b ≤ 105). It is guaranteed that number b is lucky.

Output

In the only line print a single number — the number c that is sought by Petya.

Examples

Input

1 7

Output

7

Input

100 47

Output

147

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c, k;
string s;
int main() {
  cin >> a >> b;
  string mask;
  k = b;
  while (k > 0) {
    if (k % 10 == 4 || k % 10 == 7) {
      mask += (char)('0' + k % 10);
    }
    k /= 10;
  }
  while (mask != s) {
    a++;
    s = "";
    k = a;
    while (k > 0) {
      if (k % 10 == 4 || k % 10 == 7) {
        s += (char)('0' + k % 10);
      }
      k /= 10;
    }
  }
  cout << a;
}

```


### Prompt

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

One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees.

One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've brought with you have space for no more than k huge prizes.

Besides the fact that you want to take all the prizes home, you also want to perform well. You will consider your performance good if you win at least l tours.

In fact, years of organizing contests proved to the organizers that transporting huge prizes is an issue for the participants. Alas, no one has ever invented a spell that would shrink the prizes... So, here's the solution: for some tours the winner gets a bag instead of a huge prize. Each bag is characterized by number ai — the number of huge prizes that will fit into it.

You already know the subject of all tours, so you can estimate the probability pi of winning the i-th tour. You cannot skip the tour under any circumstances.

Find the probability that you will perform well on the contest and will be able to take all won prizes home (that is, that you will be able to fit all the huge prizes that you won into the bags that you either won or brought from home).

Input

The first line contains three integers n, l, k (1 ≤ n ≤ 200, 0 ≤ l, k ≤ 200) — the number of tours, the minimum number of tours to win, and the number of prizes that you can fit in the bags brought from home, correspondingly.

The second line contains n space-separated integers, pi (0 ≤ pi ≤ 100) — the probability to win the i-th tour, in percents.

The third line contains n space-separated integers, ai (1 ≤ ai ≤ 200) — the capacity of the bag that will be awarded to you for winning the i-th tour, or else -1, if the prize for the i-th tour is a huge prize and not a bag.

Output

Print a single real number — the answer to the problem. The answer will be accepted if the absolute or relative error does not exceed 10 - 6.

Examples

Input

3 1 0
10 20 30
-1 -1 2

Output

0.300000000000

Input

1 1 1
100
123

Output

1.000000000000

Note

In the first sample we need either win no tour or win the third one. If we win nothing we wouldn't perform well. So, we must to win the third tour. Other conditions will be satisfied in this case. Probability of wining the third tour is 0.3.

In the second sample we win the only tour with probability 1.0, and go back home with bag for it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double dp[210][210][410];
int p[210];
int a[210];
int main() {
  int n, l, k;
  while (scanf("%d%d%d", &n, &l, &k) != EOF) {
    int i, j, z;
    for (i = 1; i <= n; i++) {
      scanf("%d", &p[i]);
    }
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0][200 + k] = 1;
    for (i = 1; i <= n; i++) {
      for (j = 0; j <= i; j++) {
        for (z = 0; z <= 400; z++) {
          dp[i][j][z] += dp[i - 1][j][z] * (100.0 - p[i]) / 100.0;
          if (a[i] == -1) {
            if (z > 0) dp[i][j + 1][z - 1] += dp[i - 1][j][z] * p[i] / 100.0;
          } else {
            dp[i][j + 1][(z + a[i]) >= 400 ? 400 : (z + a[i])] +=
                dp[i - 1][j][z] * p[i] / 100.0;
          }
        }
      }
    }
    double ans = 0;
    for (j = l; j <= n; j++) {
      for (k = 200; k <= 400; k++) ans += dp[n][j][k];
    }
    printf("%.12lf\n", ans);
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Pashmak has fallen in love with an attractive girl called Parmida since one year ago...

Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.

Input

The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.

Output

If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.

Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000).

Examples

Input

0 0 0 1

Output

1 0 1 1

Input

0 0 1 1

Output

0 1 1 0

Input

0 0 1 2

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool ch(int x1, int y1, int x2, int y2, int& x3, int& y3, int& x4, int& y4,
        int l) {
  if (x2 == x1 && y2 == y1 + l) {
    x3 = x1 + l, y3 = y1, x4 = x3, y4 = y2;
    return 9;
  } else if (x2 == x1 + l && y2 == y1) {
    x3 = x1, y3 = y1 + l, x4 = x2, y4 = y3;
    return 9;
  } else if (x2 == x1 + l && y2 == y1 + l) {
    x3 = x1, y3 = y2, x4 = x2, y4 = y1;
    return 9;
  } else if (x2 == x1 + l && y2 == y1 - l) {
    x3 = x1, y3 = y2, x4 = x2, y4 = y1;
    return 9;
  }
  return 0;
}
int main() {
  int x1, y1, x2, y2, x3, y3, x4, y4, l;
  cin >> x1 >> y1 >> x2 >> y2;
  l = max(abs(x2 - x1), (abs(y2 - y1)));
  if (ch(x1, y1, x2, y2, x3, y3, x4, y4, l)) {
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  } else if (ch(x2, y2, x1, y1, x3, y3, x4, y4, l)) {
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  } else
    cout << "-1" << endl;
  return 0;
}

```


### Prompt

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

Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 ⋅ n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from left to right.

<image>

Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n students (there are no additional constraints), and a team can consist of any number of students.

Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10^5) — the number of students in each row.

The second line of the input contains n integers h_{1, 1}, h_{1, 2}, …, h_{1, n} (1 ≤ h_{1, i} ≤ 10^9), where h_{1, i} is the height of the i-th student in the first row.

The third line of the input contains n integers h_{2, 1}, h_{2, 2}, …, h_{2, n} (1 ≤ h_{2, i} ≤ 10^9), where h_{2, i} is the height of the i-th student in the second row.

Output

Print a single integer — the maximum possible total height of players in a team Demid can choose.

Examples

Input

5
9 3 5 7 3
5 8 1 4 5

Output

29

Input

3
1 2 9
10 1 1

Output

19

Input

1
7
4

Output

7

Note

In the first example Demid can choose the following team as follows:

<image>

In the second example Demid can choose the following team as follows:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
long long h[N][2], dp[N][2];
long long solve(int i, int Row) {
  if (i == n) return 0;
  long long& r = dp[i][Row];
  if (r != -1) return r;
  return r = max(solve(i + 1, !Row) + h[i][Row], solve(i + 1, Row));
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> h[i][0];
  for (int i = 0; i < n; i++) cin >> h[i][1];
  memset(dp, -1, sizeof dp);
  cout << max(solve(0, 1), solve(0, 0)) << endl;
}

```


### Prompt

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

Some time ago Lesha found an entertaining string s consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.

Lesha chooses an arbitrary (possibly zero) number of pairs on positions (i, i + 1) in such a way that the following conditions are satisfied:

  * for each pair (i, i + 1) the inequality 0 ≤ i < |s| - 1 holds;
  * for each pair (i, i + 1) the equality s_i = s_{i + 1} holds;
  * there is no index that is contained in more than one pair.

After that Lesha removes all characters on indexes contained in these pairs and the algorithm is over.

Lesha is interested in the lexicographically smallest strings he can obtain by applying the algorithm to the suffixes of the given string.

Input

The only line contains the string s (1 ≤ |s| ≤ 10^5) — the initial string consisting of lowercase English letters only.

Output

In |s| lines print the lengths of the answers and the answers themselves, starting with the answer for the longest suffix. The output can be large, so, when some answer is longer than 10 characters, instead print the first 5 characters, then "...", then the last 2 characters of the answer.

Examples

Input

abcdd

Output

3 abc
2 bc
1 c
0
1 d

Input

abbcdddeaaffdfouurtytwoo

Output

18 abbcd...tw
17 bbcdd...tw
16 bcddd...tw
15 cddde...tw
14 dddea...tw
13 ddeaa...tw
12 deaad...tw
11 eaadf...tw
10 aadfortytw
9 adfortytw
8 dfortytw
9 fdfortytw
8 dfortytw
7 fortytw
6 ortytw
5 rtytw
6 urtytw
5 rtytw
4 tytw
3 ytw
2 tw
1 w
0
1 o

Note

Consider the first example.

  * The longest suffix is the whole string "abcdd". Choosing one pair (4, 5), Lesha obtains "abc".
  * The next longest suffix is "bcdd". Choosing one pair (3, 4), we obtain "bc".
  * The next longest suffix is "cdd". Choosing one pair (2, 3), we obtain "c".
  * The next longest suffix is "dd". Choosing one pair (1, 2), we obtain "" (an empty string).
  * The last suffix is the string "d". No pair can be chosen, so the answer is "d".

In the second example, for the longest suffix "abbcdddeaaffdfouurtytwoo" choose three pairs (11, 12), (16, 17), (23, 24) and we obtain "abbcdddeaadfortytw"

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[100086];
int n;
bool del[100086];
string S;
pair<int, string> ans[100086];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int x = 0, y = 0, z = 0;
  for (int i = n; i; i--) {
    if (i < n && !del[i + 1] && s[i] == s[i + 1] && s[i] > y) {
      S.pop_back();
      del[i] = true;
      if (S.length() == 0 || S.back() == y) x = y, y = z, z = 0;
    } else {
      if (S.empty() || S.back() != s[i]) {
        z = y, y = x, x = s[i];
      }
      S += s[i];
    }
    ans[i].first = S.length();
    if (S.length() <= 10)
      ans[i].second = S, reverse(ans[i].second.begin(), ans[i].second.end());
    else {
      for (int j = 1; j <= 5; j++) ans[i].second += S[S.length() - j];
      ans[i].second += "...";
      ans[i].second += S[1], ans[i].second += S[0];
    }
  }
  for (int i = 1; i <= n; i++)
    printf("%d %s\n", ans[i].first, ans[i].second.c_str());
}

```


### Prompt

Please formulate a CPP solution to the following problem:

It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.

The flea can count the amount of cells that she can reach from the starting position (x, y). Let's denote this amount by dx, y. Your task is to find the number of such starting positions (x, y), which have the maximum possible value of dx, y.

Input

The first line contains three integers n, m, s (1 ≤ n, m, s ≤ 106) — length of the board, width of the board and length of the flea's jump.

Output

Output the only integer — the number of the required starting positions of the flea.

Examples

Input

2 3 1000000

Output

6

Input

3 3 2

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long value(int a, int b) {
  long long ans = 1;
  int k1, k2;
  if (a % b == 0 || a <= b)
    ans = (long long)a;
  else {
    k1 = (a - 1) / b;
    k2 = a - k1 * b;
    ans = (long long)(k1 + 1) * k2;
  }
  return ans;
}
int main() {
  int n, m, s;
  long long ans = 1;
  scanf("%d%d%d", &n, &m, &s);
  ans = value(n, s) * value(m, s);
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given n points on a plane. All points are different.

Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC.

The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are considered the same.

Input

The first line contains a single integer n (3 ≤ n ≤ 3000) — the number of points.

Next n lines contain the points. The i-th line contains coordinates of the i-th point: two space-separated integers xi, yi ( - 1000 ≤ xi, yi ≤ 1000).

It is guaranteed that all given points are different.

Output

Print the single number — the answer to the problem.

Examples

Input

3
1 1
2 2
3 3

Output

1

Input

3
0 0
-1 0
0 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int p[2005][2005];
int xp[3005], yp[3005];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> xp[i] >> yp[i];
    xp[i] += 1000;
    yp[i] += 1000;
    p[xp[i]][yp[i]] = 1;
  }
  int res = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      if ((abs(xp[i] - xp[j]) & 1) || (abs(yp[i] - yp[j]) & 1)) continue;
      if (p[(xp[i] + xp[j]) / 2][(yp[i] + yp[j]) / 2]) res++;
    }
  cout << res << '\n';
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria.

Initially, on day 1, there is one bacterium with mass 1.

Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass m splits, it becomes two bacteria of mass m/2 each. For example, a bacterium of mass 3 can split into two bacteria of mass 1.5.

Also, every night, the mass of every bacteria will increase by one.

Phoenix is wondering if it is possible for the total mass of all the bacteria to be exactly n. If it is possible, he is interested in the way to obtain that mass using the minimum possible number of nights. Help him become the best scientist!

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.

The first line of each test case contains an integer n (2 ≤ n ≤ 10^9) — the sum of bacteria masses that Phoenix is interested in.

Output

For each test case, if there is no way for the bacteria to exactly achieve total mass n, print -1. Otherwise, print two lines.

The first line should contain an integer d — the minimum number of nights needed.

The next line should contain d integers, with the i-th integer representing the number of bacteria that should split on the i-th day.

If there are multiple solutions, print any.

Example

Input

3
9
11
2

Output

3
1 0 2
3
1 1 2
1
0

Note

In the first test case, the following process results in bacteria with total mass 9:

  * Day 1: The bacterium with mass 1 splits. There are now two bacteria with mass 0.5 each.
  * Night 1: All bacteria's mass increases by one. There are now two bacteria with mass 1.5.
  * Day 2: None split.
  * Night 2: There are now two bacteria with mass 2.5.
  * Day 3: Both bacteria split. There are now four bacteria with mass 1.25.
  * Night 3: There are now four bacteria with mass 2.25.

The total mass is 2.25+2.25+2.25+2.25=9. It can be proved that 3 is the minimum number of nights needed. There are also other ways to obtain total mass 9 in 3 nights.

In the second test case, the following process results in bacteria with total mass 11:

  * Day 1: The bacterium with mass 1 splits. There are now two bacteria with mass 0.5.
  * Night 1: There are now two bacteria with mass 1.5.
  * Day 2: One bacterium splits. There are now three bacteria with masses 0.75, 0.75, and 1.5.
  * Night 2: There are now three bacteria with masses 1.75, 1.75, and 2.5.
  * Day 3: The bacteria with mass 1.75 and the bacteria with mass 2.5 split. There are now five bacteria with masses 0.875, 0.875, 1.25, 1.25, and 1.75.
  * Night 3: There are now five bacteria with masses 1.875, 1.875, 2.25, 2.25, and 2.75.

The total mass is 1.875+1.875+2.25+2.25+2.75=11. It can be proved that 3 is the minimum number of nights needed. There are also other ways to obtain total mass 11 in 3 nights.

In the third test case, the bacterium does not split on day 1, and then grows to mass 2 during night 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7, N = 205001;
long long mm(long long x, long long y) {
  x %= M, y %= M;
  return (x * y) % M;
}
long long po(long long x, long long y) {
  if (!y) return 1;
  long long a = po(x, y / 2) % M;
  if (y % 2) return mm(a, mm(a, x));
  return mm(a, a);
}
void solve() {
  long long n;
  cin >> n;
  long long p = 1, s = 0, c = 0;
  vector<long long> v;
  while (s <= n) {
    if (s + p > n) {
      if (n - s > 0) v.push_back(n - s);
      break;
    }
    s = s + p;
    v.push_back(p);
    p *= 2;
  }
  sort(v.begin(), v.end());
  cout << v.size() - 1 << "\n";
  for (long long i = 1; i < v.size(); i++) cout << v[i] - v[i - 1] << " ";
  cout << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Professor Phunsuk Wangdu has performed some experiments on rays. The setup for n rays is as follows.

There is a rectangular box having exactly n holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from each hole. The holes are in a straight line.

<image>

Professor Wangdu is showing his experiment to his students. He shows that there are cases, when all the rays are intersected by every other ray. A curious student asked the professor: "Sir, there are some groups of rays such that all rays in that group intersect every other ray in that group. Can we determine the number of rays in the largest of such groups?".

Professor Wangdu now is in trouble and knowing your intellect he asks you to help him.

Input

The first line contains n (1 ≤ n ≤ 106), the number of rays. The second line contains n distinct integers. The i-th integer xi (1 ≤ xi ≤ n) shows that the xi-th ray enters from the i-th hole. Similarly, third line contains n distinct integers. The i-th integer yi (1 ≤ yi ≤ n) shows that the yi-th ray exits from the i-th hole. All rays are numbered from 1 to n.

Output

Output contains the only integer which is the number of rays in the largest group of rays all of which intersect each other.

Examples

Input

5
1 4 5 2 3
3 4 2 1 5

Output

3

Input

3
3 1 2
2 3 1

Output

2

Note

For the first test case, the figure is shown above. The output of the first test case is 3, since the rays number 1, 4 and 3 are the ones which are intersected by each other one i.e. 1 is intersected by 4 and 3, 3 is intersected by 4 and 1, and 4 is intersected by 1 and 3. Hence every ray in this group is intersected by each other one. There does not exist any group containing more than 3 rays satisfying the above-mentioned constraint.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[1000010], p[1000010], tree[4000000];
void update(int v, int l, int r, int pos, int value) {
  if (l == r && l == pos)
    tree[v] = value;
  else {
    int mid = (l + r) / 2;
    if (pos <= mid)
      update(2 * v, l, mid, pos, value);
    else
      update(2 * v + 1, mid + 1, r, pos, value);
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
  };
};
int search(int v, int l, int r, int L, int R) {
  if (L > R) return 0;
  if (l == L && r == R) return tree[v];
  int mid = (l + r) / 2;
  if (R <= mid) return search(2 * v, l, mid, L, R);
  if (L > mid) return search(2 * v + 1, mid + 1, r, L, R);
  return max(search(2 * v, l, mid, L, mid),
             search(2 * v + 1, mid + 1, r, mid + 1, R));
};
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int v;
    scanf("%d", &v);
    a[v] = i;
  };
  for (int i = 1; i <= n; i++) {
    int v;
    scanf("%d", &v);
    p[i] = a[v];
  };
  for (int i = 1; i <= n; i++)
    update(1, 1, n, p[i], search(1, 1, n, p[i] + 1, n) + 1);
  printf("%d\n", tree[1]);
  return 0;
}

```


### Prompt

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

Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.

An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of vertexes. A leaf is a distinct from root vertex, which is connected with exactly one other vertex.

The ant wants to visit every vertex in the tree and return to the root, passing every edge twice. In addition, he wants to visit the leaves in a specific order. You are to find some possible route of the ant.

Input

The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The last line contains k integers, where k is amount of leaves in the tree. These numbers describe the order in which the leaves should be visited. It is guaranteed that each leaf appears in this order exactly once.

Output

If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.

Examples

Input

3
1 2
2 3
3

Output

1 2 3 2 1

Input

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

Output

1 2 4 5 4 6 4 2 1 3 1

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
const int max_n = 400;
vector<int> ad_list[max_n], leaves[max_n];
vector<int> order;
int mark[max_n], ind = 0;
queue<int> ans;
void init(int v) {
  mark[v] = 1;
  if (ad_list[v].size() == 1 && v != 1) {
    leaves[v].push_back(v);
    return;
  }
  for (int i = 0; i < ad_list[v].size(); i++) {
    if (mark[ad_list[v][i]]) continue;
    init(ad_list[v][i]);
    for (int j = 0; j < leaves[ad_list[v][i]].size(); j++)
      leaves[v].push_back(leaves[ad_list[v][i]][j]);
  }
}
void solve(int v) {
  mark[v] = 2;
  ans.push(v);
  if (ad_list[v].size() == 1 && v != 1) {
    ind++;
    return;
  }
  for (int i = 0; i < ad_list[v].size(); i++) {
    int temp = ad_list[v][i];
    if (mark[temp] == 2) continue;
    for (int j = 0; j < leaves[temp].size(); j++)
      if (leaves[temp][j] == order[ind] || ind >= order.size()) {
        solve(temp);
        ans.push(v);
        i = -1;
        break;
      }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  {
    cin >> n;
    int a, b;
    int t = n - 1;
    while (t--) {
      cin >> a >> b;
      ad_list[a].push_back(b);
      ad_list[b].push_back(a);
    }
    t = 2;
    for (int i = 1; i <= n; i++)
      if (ad_list[i].size() > 2) t += ad_list[i].size() - 2;
    if (ad_list[1].size() == 1) t--;
    while (t--) {
      cin >> a;
      order.push_back(a);
    }
  }
  init(1);
  solve(1);
  if (ans.size() != 2 * n - 1) {
    cout << -1 << endl;
    return 0;
  }
  while (!ans.empty()) {
    cout << ans.front() << " ";
    ans.pop();
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

You are given a long decimal number a consisting of n digits from 1 to 9. You also have a function f that maps every digit from 1 to 9 to some (possibly the same) digit from 1 to 9.

You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in a, and replace each digit x from this segment with f(x). For example, if a = 1337, f(1) = 1, f(3) = 5, f(7) = 3, and you choose the segment consisting of three rightmost digits, you get 1553 as the result.

What is the maximum possible number you can obtain applying this operation no more than once?

Input

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

The second line contains a string of n characters, denoting the number a. Each character is a decimal digit from 1 to 9.

The third line contains exactly 9 integers f(1), f(2), ..., f(9) (1 ≤ f(i) ≤ 9).

Output

Print the maximum number you can get after applying the operation described in the statement no more than once.

Examples

Input

4
1337
1 2 5 4 6 6 3 1 9

Output

1557

Input

5
11111
9 8 7 6 5 4 3 2 1

Output

99999

Input

2
33
1 1 1 1 1 1 1 1 1

Output

33

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s1;
  cin >> s1;
  vector<int> s(n);
  for (int i = 0; i < n; ++i) {
    s[i] = s1[i] - '0';
  }
  vector<int> res(9);
  for (int i = 0; i < 9; ++i) {
    cin >> res[i];
  }
  int i = 0;
  while (i < n) {
    if (res[s[i] - 1] <= s[i]) {
      ++i;
    } else {
      int j = i;
      while (j < n && res[s[j] - 1] >= s[j]) {
        s[j] = res[s[j] - 1];
        ++j;
      }
      break;
    }
  }
  for (auto k : s) {
    cout << k;
  }
  cout << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Kuro is living in a country called Uberland, consisting of n towns, numbered from 1 to n, and n - 1 bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns a and b. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns (u, v) (u ≠ v) and walk from u using the shortest path to v (note that (u, v) is considered to be different from (v, u)).

Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index x) and Beetopia (denoted with the index y). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns (u, v) if on the path from u to v, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.

Kuro wants to know how many pair of city (u, v) he can take as his route. Since he’s not really bright, he asked you to help him with this problem.

Input

The first line contains three integers n, x and y (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ x, y ≤ n, x ≠ y) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.

n - 1 lines follow, each line contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), describes a road connecting two towns a and b.

It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.

Output

A single integer resembles the number of pair of towns (u, v) that Kuro can use as his walking route.

Examples

Input

3 1 3
1 2
2 3

Output

5

Input

3 1 3
1 2
1 3

Output

4

Note

On the first example, Kuro can choose these pairs:

  * (1, 2): his route would be 1 → 2,
  * (2, 3): his route would be 2 → 3,
  * (3, 2): his route would be 3 → 2,
  * (2, 1): his route would be 2 → 1,
  * (3, 1): his route would be 3 → 2 → 1.

Kuro can't choose pair (1, 3) since his walking route would be 1 → 2 → 3, in which Kuro visits town 1 (Flowrisa) and then visits town 3 (Beetopia), which is not allowed (note that pair (3, 1) is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).

On the second example, Kuro can choose the following pairs:

  * (1, 2): his route would be 1 → 2,
  * (2, 1): his route would be 2 → 1,
  * (3, 2): his route would be 3 → 1 → 2,
  * (3, 1): his route would be 3 → 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct cont {
  long long int ch, fl;
};
long long int f, b;
long long int dfs(vector<long long int> g[], long long int s, long long int p,
                  long long int x, long long int y) {
  long long int ch = 1;
  for (int i = 0; i < g[s].size(); i++) {
    if (g[s][i] != p) {
      long long int c = dfs(g, g[s][i], s, x, y);
      if (b != -1 && s == x) return c;
      ch += c;
    }
  }
  if (s == y) b = ch;
  return ch;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  while (test--) {
    long long int n, x, y;
    cin >> n >> x >> y;
    b = -1;
    vector<long long int> g[n + 1];
    for (int i = 1; i <= n - 1; i++) {
      long long int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    long long int ch = dfs(g, x, -1, x, y);
    f = n - ch;
    long long int ans = n * (n - 1) - f * b;
    cout << ans;
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to it. However, if you put a large bookshelf in the room, it will be quite small, so you have to devise to make the width of the bookshelf as small as possible. When I measured the height from the floor to the ceiling, I found that an m-level bookshelf could be placed. So, how can we divide the n volumes of novels to minimize the width of the bookshelf in m columns? Taro is particular about it, and the novels to be stored in each column must be arranged in the order of the volume numbers. ..

Enter the number of bookshelves, the number of volumes of the novel, and the thickness of each book as input, and create a program to find the width of the bookshelf that has the smallest width that can accommodate all volumes in order from one volume. However, the size of the bookshelf frame is not included in the width.

<image>

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
w1
w2
::
wn

The first line gives m (1 ≤ m ≤ 20) the number of bookshelves that can be placed in the room and n (1 ≤ n ≤ 100) the number of volumes in the novel. The next n lines are given the integer wi (1 ≤ wi ≤ 1000000), which represents the thickness of the book in Volume i.

However, the width of the bookshelf shall not exceed 1500000.

The number of datasets does not exceed 50.

Output

Outputs the minimum bookshelf width for each dataset on one line.

Example

Input

3 9
500
300
800
200
100
600
900
700
400
4 3
1000
1000
1000
0 0

Output

1800
1000

### Response

```cpp
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<int>V;
int main(){
    int m,n;
    while(cin>>m>>n,m||n){
        V.clear();
        V.resize(n);
        int Max=0;
        for(int i=0;i<n;i++){
            cin>>V[i];
            Max=max(Max,V[i]);
        }
        int l=Max,r=100000000;
        while(r-l>=1){
            int mid=(l+r)/2;
            int cnt=1,leftW=mid;
            for(int i=0;i<n;i++){
                if(leftW>=V[i])leftW-=V[i];
                else{
                    cnt++;
                    leftW=mid-V[i];
                }
            }
            if(m<cnt)l=mid+1;
            else r=mid;
        }
        cout<<r<<endl;
    }
    return 0;
}
```


### Prompt

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

You have two strings A = A_1 A_2 ... A_n and B = B_1 B_2 ... B_n of the same length consisting of 0 and 1.

You can transform A using the following operations in any order and as many times as you want:

* Shift A by one character to the left (i.e., if A = A_1 A_2 ... A_n, replace A with A_2 A_3 ... A_n A_1).
* Shift A by one character to the right (i.e., if A = A_1 A_2 ... A_n, replace A with A_n A_1 A_2 ... A_{n-1}).
* Choose any i such that B_i = 1. Flip A_i (i.e., set A_i = 1 - A_i).

You goal is to make strings A and B equal.

Print the smallest number of operations required to achieve this, or -1 if the goal is unreachable.

Constraints

* 1 \leq |A| = |B| \leq 2,000
* A and B consist of 0 and 1.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print the smallest number of operations required to make strings A and B equal, or -1 if the goal is unreachable.

Examples

Input

1010
1100

Output

3

Input

1
0

Output

-1

Input

11010
10001

Output

4

Input

0100100
1111111

Output

5

### Response

```cpp
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;

const int MN = 2e5+5;
const int MOD = 1e9+7;
const int INF = 1e9;

int N;
priority_queue<pii> PQ;

int cal(int x, int y)
{
	if(x>y) swap(x,y);
	return min(y-x,x+N-y);
}

int solve(int x)
{
	int l = 0, res = INF;
	for(int r=N-1; r>=0; r--){
		while(PQ.size()&&r<PQ.top().va){
			l = max(l,PQ.top().vb);
			PQ.pop();
		}
		//cout << l << ' ' << r << '\n';
		res = min(res,2*l+r+cal(r,x));
		res = min(res,l+2*r+cal(N-l,x));
	}
	while(PQ.size()) PQ.pop();
	//cout << res << '\n';
	return res;
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    string A,B;
    cin >> A >> B;
    N = A.size();
    int a=0, b=0;
    for(int i=0; i<N; i++){
    	a += A[i]=='1';
    	b += B[i]=='1';
    }
    if(!b){
    	if(!a) cout << 0;
    	else cout << -1;
    	exit(0);
    }
    int r[N],l[N];
    for(int i=0; i<N; i++){
    	for(int j=i; j<i+N; j++){
    		if(B[j%N]=='1'){
    			r[i] = j-i;
    			break;
    		}
    	}
    	for(int j=i; j>i-N; j--){
    		if(B[(j+N)%N]=='1'){
    			l[i] = i-j;
    			break;
    		}
    	}
    }
    int ans = INF;
    for(int i=0; i<N; i++){
    	int cnt = 0;
    	for(int j=0; j<N; j++){
    		if(A[j]==B[(i+j)%N]) continue;
    		//cout << r[j] << ' ' << l[j] << '\n';
    		PQ.emplace(r[j],l[j]);
    		cnt++;
    	}
    	ans = min(ans,solve(i)+cnt);
    }
    cout << ans;
}
```


### Prompt

Please create a solution in CPP to the following problem:

Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.

Input

The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.

Output

Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".

Examples

Input

rock
rock
rock

Output

?

Input

paper
rock
rock

Output

F

Input

scissors
rock
rock

Output

?

Input

scissors
paper
rock

Output

?

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s1, s2, s3;
void enter() {
  cin >> s1;
  cin >> s2;
  cin >> s3;
}
bool win(string s, string t) {
  if (s == t) return (false);
  if (s == "scissors" && t == "rock") return (false);
  if (s == "paper" && t == "scissors") return (false);
  if (s == "rock" && t == "paper") return (false);
  return (true);
}
void solve() {
  if (win(s1, s2) && win(s1, s3))
    printf("F\n");
  else if (win(s2, s1) && win(s2, s3))
    printf("M\n");
  else if (win(s3, s1) && win(s3, s2))
    printf("S\n");
  else
    printf("?\n");
}
int main() {
  enter();
  solve();
  return 0;
}

```


### Prompt

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

You are given two strings s and t consisting of lowercase Latin letters. Also you have a string z which is initially empty. You want string z to be equal to string t. You can perform the following operation to achieve this: append any subsequence of s at the end of string z. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. For example, if z = ac, s = abcde, you may turn z into following strings in one operation:

  1. z = acace (if we choose subsequence ace);
  2. z = acbcd (if we choose subsequence bcd);
  3. z = acbce (if we choose subsequence bce).

Note that after this operation string s doesn't change.

Calculate the minimum number of such operations to turn string z into string t.

Input

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

The first line of each testcase contains one string s (1 ≤ |s| ≤ 10^5) consisting of lowercase Latin letters.

The second line of each testcase contains one string t (1 ≤ |t| ≤ 10^5) consisting of lowercase Latin letters.

It is guaranteed that the total length of all strings s and t in the input does not exceed 2 ⋅ 10^5.

Output

For each testcase, print one integer — the minimum number of operations to turn string z into string t. If it's impossible print -1.

Example

Input

3
aabce
ace
abacaba
aax
ty
yyt

Output

1
-1
3

### Response

```cpp
#include <bits/stdc++.h>
const int N = 1e5 + 100;
const int M = 1e6 + 100;
const long long oo = 2e18;
long long n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;
using namespace std;
string s, ts, zs;
set<int> second[250];
int toIndex(int pr, char x, int ind) {
  if (ind + 1 == ts.size()) return ind;
  if (second[ts[ind + 1]].upper_bound(pr) != second[ts[ind + 1]].end()) {
    return toIndex(*(second[ts[ind + 1]].upper_bound(pr)), ts[ind + 1],
                   ind + 1);
  }
  return ind;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> s >> ts;
    zs = "";
    for (char a = 'a'; a <= 'z'; a++) {
      second[a].clear();
    }
    for (int i = 0; i < s.size(); i++) {
      second[s[i]].insert(i);
    }
    int ans = 0;
    for (int i = 0; i < ts.size(); i++) {
      if (second[ts[i]].upper_bound(-1) == second[ts[i]].end()) {
        ans = -1;
        break;
      }
      i = toIndex(*(second[ts[i]].upper_bound(-1)), ts[i], i);
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

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

There is a dice with one letter of the alphabet (a ~ z, A ~ Z) drawn on each side.

<image>

Consider combining eight such dice to make a 2 x 2 x 2 cube.

<image>

There are conditions on how to combine the dice, and the facing faces of each dice must have the same alphabet, one in lowercase and the other in uppercase. For example, a surface marked a can be touched by a face marked A. However, the orientation of the characters when touching them does not matter.

<image>

According to this rule, input the information of 8 dice and create a program to judge whether or not you can make a cube. If you can make a cube, output YES (half-width uppercase letters), and if you cannot make it, output NO (half-width uppercase letters).

The letters on each side of the dice will be represented as c1 to c6 as shown in the following figure. Also, assume that the same letter is never drawn multiple times on a single dice (uppercase and lowercase letters of the same alphabet are not the case).

<image>

Input

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

s1
s2
::
s8

The i-line gives the information si of the i-th dice. si is a string of length 6 and the jth character corresponds to each side cj of the dice.

The number of datasets does not exceed 50.

Output

The judgment result (half-width uppercase letters) is output to one line for each data set.

Example

Input

zabZNq
BCxmAi
ZcbBCj
aizXCm
QgmABC
JHzMop
ImoXGz
MZTOhp
zabZnQ
BCxmAi
ZcbBCj
aizXCm
QgmABC
JHzMop
ImoXGz
MZTOhp
abcdef
ABDCFE
FBDCAE
abcdef
BEACDF
bfcaed
fabcde
DEABCF
UnivOf
AizuaH
zTXZYW
piglIt
GRULNP
higGtH
uAzIXZ
FizmKZ
UnivOf
AizuaH
piglIt
higGtH
GRULNP
uAzIXZ
FizmKZ
ZTXzYW
0

Output

YES
NO
YES
YES
NO

### Response

```cpp
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <limits>
using namespace std;
typedef long long ll;

enum Face {
	C1, C2, C3, C4, C5, C6, FACE_SIZE
};

struct Dice {
	char face[FACE_SIZE];

	Dice(){}
	Dice(string init){
		for(int i=0;i<FACE_SIZE;i++)face[i] = init[i];
	}

	void roll_y(){
		roll(C2, C3, C5, C4);
	}

	void roll_x(){
		roll(C2, C6, C5, C1);
	}

	void roll_z(){
		roll(C1, C3, C6, C4);
	}

	void roll(Face a, Face b, Face c, Face d){
		char tmp = face[d];
		face[d] = face[c];
		face[c] = face[b];
		face[b] = face[a];
		face[a] = tmp;
	}

	inline char at(int a) const {
		return face[a];
	}
};

int dx[] =  {0, 0,  1, -1, 0, 0};
int dy[] =  {1, -1, 0,  0, 0, 0};
int dz[] =  {0, 0,  0,  0, 1, -1};

Face from[] = {C6, C1, C3, C4, C5, C2};
Face to[] =   {C1, C6, C4, C3, C2, C5};

Dice dices[8];
Dice rolls[8][64];
int id[2][2][2];

bool allow[2][2][2][64];

bool used[2][2][2];
int cube[2][2][2];

inline bool valid(char a, char b){
	if(tolower(a) != tolower(b))return false;
	if(a == b)return false;
	return true;
}

bool dfs(int n){
	if(n >= 8)return true;

	int m = n;
	int x = m % 2; m /= 2;
	int y = m % 2; m /= 2;
	int z = m;

	for(int i=0;i<64;i++)if(allow[z][y][x][i]){
		Dice dice = rolls[id[z][y][x]][i];
		bool ok = true;

		for(int k=0;k<6;k++){
			int nz = z + dz[k];
			int ny = y + dy[k];
			int nx = x + dx[k];

			if(nz < 0 || nz >= 2 || ny < 0 || ny >= 2 || nx < 0 || nx >= 2)continue;
			if(!used[nz][ny][nx])continue;

			Dice to_dice = rolls[id[nz][ny][nx]][cube[nz][ny][nx]];
			if(!valid(dice.at(from[k]), to_dice.at(to[k]))){
				ok = false;
				break;
			}
		}

		if(!ok)continue;

		used[z][y][x] = true;
		cube[z][y][x] = i;

		if(dfs(n + 1))return true;

		used[z][y][x] = false;
	}

	return false;
}

inline bool valid(){
	memset(allow, false, sizeof(allow));
	for(int z=0;z<2;z++)for(int y=0;y<2;y++)for(int x=0;x<2;x++){
		int num = 0;
		int cnt = 0;

		for(int kz=0;kz<4;kz++)
		for(int ky=0;ky<4;ky++)
		for(int kx=0;kx<4;kx++){
			Dice dice = rolls[id[z][y][x]][num];
			bool ok = true;

			for(int k=0;k<6;k++){
				int nz = z + dz[k];
			    int ny = y + dy[k];
				int nx = x + dx[k];
				if(nz < 0 || nz >= 2 || ny < 0 || ny >= 2 || nx < 0 || nx >= 2)continue;

				Dice to_dice = dices[id[nz][ny][nx]];

				char from_face = dice.at(from[k]);
				bool check = false;

				for(int face=0;face<FACE_SIZE;face++){
					if(valid(from_face, to_dice.at(face))){
						check = true;
						break;
					}
				}

				if(!check){
					ok = false;
					break;
				}
			}

			if(ok){
				allow[z][y][x][num] = true;
				++cnt;
			}

			++num;
		}
		if(cnt == 0)return false;
	}

	memset(used, false, sizeof(used));
	return dfs(0);
}

inline string solve(const vector<Dice> &dice_vec){
	for(int i=0;i<dice_vec.size();i++){
		Dice dice = dice_vec[i];

		dices[i] = dice;

		int num = 0;
		for(int kz=0;kz<4;kz++, dice.roll_z())
		for(int ky=0;ky<4;ky++, dice.roll_y())
		for(int kx=0;kx<4;kx++, dice.roll_x()){
			rolls[i][num] = dice;
			++num;
		}
	}

	vector<int> perm(dice_vec.size());
	for(int i=0;i<perm.size();i++)perm[i] = i;

	do {
		for(int z=0;z<2;z++)for(int y=0;y<2;y++)for(int x=0;x<2;x++){
			int num = (z * 2 + y) * 2 + x;
			id[z][y][x] = perm[num];
		}
		if(valid())return "YES";
	} while(next_permutation(perm.begin(), perm.end()));

	return "NO";
}

int main(){
	string init;
	while(cin >> init){
		if(init == "0")break;

		vector<Dice> dices;
		dices.push_back(Dice(init));

		for(int t=0;t<7;t++){
			cin >> init;
			dices.push_back(Dice(init));
		}

		cout << solve(dices) << endl;
	}

	return 0;
}
```


### Prompt

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

problem

AOR Ika likes rooted trees with a fractal (self-similar) structure. Consider using the weighted rooted tree $ T $ consisting of $ N $ vertices to represent the rooted tree $ T'$ with the following fractal structure.

* $ T'$ is the addition of a tree rooted at $ x $ and having a tree structure similar to $ T $ (same cost) for each vertex $ x $ of $ T $.
* The root of $ T'$ is the same as that of $ T $.

The tree represented in this way is, for example, as shown in the figure below.

<image>

AOR Ika is trying to do a depth-first search for $ T'$, but finds that it takes a lot of time to trace all the vertices. Therefore, we decided to skip some node visits by performing a depth-first search with a policy of transitioning with a probability of $ p $ and not transitioning with a probability of $ 1-p $ at the time of transition during a depth-first search. Given $ T $ and the probability $ p $, find the expected value of the sum of the costs of all edges to follow when performing a depth-first search for $ T'$. The information of $ T $ is given by the number of vertices $ N $ and the information of the edges of $ N-1 $, and the vertex $ 1 $ is the root. Each vertex is labeled $ 1,2, \ dots, N $, and the $ i \ (1 \ le i \ le N-1) $ th edge costs the vertices $ x_i $ and $ y_i $ $ c_i $ It is tied with. The non-deterministic algorithm of the depth-first search that transitions to a child with a probability of $ p $, which is dealt with in this problem, is expressed as follows. The sum of the costs of the edges that the output $ \ mathrm {answer} $ follows.

1. Prepare an empty stack $ S $.
2. Set $ \ mathrm {answer} = 0 $
3. Push the root vertex of $ T'$ to $ S $.
4. Extract the first element of $ S $ and make it $ x $.
5. For each child $ c $ of $ x $, do the following with probability $ p $ and do nothing with probability $ 1-p $.
* Add vertex $ c $ to $ S $. Then add the weight of the edge connecting $ x $ to $ c $ to $ \ mathrm {answer} $.
6. If S is not empty, transition to 3.
7. Output $ \ mathrm {answer} $.

output

Print the answer in one line. If the relative or absolute error is less than $ 10 ^ {-6} $, then AC. Also, output a line break at the end.

Example

Input

0.75
4
1 2 1
2 3 3
3 4 10

Output

24.8569335938

### Response

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

struct edge {
	int from;
	int to;
	int cost;
	edge() {
		from = 0;
		to = 0;
		cost = 0;
	}
	edge(int from_, int to_, int cost_):from(from_), to(to_), cost(cost_) {

	}
};
ld p;
ld dfs1(const int now, const int from, const vector<vector<edge>>&edges,vector<ld>&come_pers,ld aper) {
	ld ans = 0;
	come_pers[now] = aper;
	for (auto e : edges[now]) {
		if (e.to == from)continue;
		else {
			ans += p*(e.cost + dfs1(e.to, now, edges,come_pers,aper*p));
		}
	}
	return ans;
}

int main() {cin >> p;
	int N; cin >> N;
	vector<vector<edge>>edges(N);
	for (int i = 0; i < N - 1; ++i) {
		int x, y, c; cin >> x >> y >> c;
		x--; y--;
		edges[x].push_back(edge(x, y, c));
		edges[y].push_back(edge(y, x, c));
	}
	vector<ld>come_pers(N);
	ld sum=dfs1(0, -1, edges, come_pers, 1);
	ld ans = accumulate(come_pers.begin(), come_pers.end(), 1.l)*sum;
	cout << setprecision(10) << fixed << ans << endl;
	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?

The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE

Input

The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.

Only the drinks from the list given above should be considered alcohol.

Output

Print a single number which is the number of people Vasya should check to guarantee the law enforcement.

Examples

Input

5
18
VODKA
COKE
19
17

Output

2

Note

In the sample test the second and fifth clients should be checked.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-11;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
string d[] = {"ABSINTH", "BEER",    "BRANDY", "CHAMPAGNE", "GIN", "RUM",
              "SAKE",    "TEQUILA", "VODKA",  "WHISKEY",   "WINE"};
int main() {
  string s;
  int n, res = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    if (find(d, d + 11, s) != d + 11 || (isdigit(s[0]) && atoi(s.c_str()) < 18))
      res++;
  }
  cout << res;
  return 0;
}

```


### Prompt

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

Your friend gave you a dequeue D as a birthday present.

D is a horizontal cylinder that contains a row of N jewels.

The values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.

In the beginning, you have no jewel in your hands.

You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):

* Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.

* Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.

* Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.

* Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.

Find the maximum possible sum of the values of jewels in your hands after the operations.

Constraints

* All values in input are integers.
* 1 \leq N \leq 50
* 1 \leq K \leq 100
* -10^7 \leq V_i \leq 10^7

Input

Input is given from Standard Input in the following format:

N K
V_1 V_2 ... V_N

Output

Print the maximum possible sum of the values of jewels in your hands after the operations.

Examples

Input

6 4
-10 8 2 1 2 6

Output

14

Input

6 4
-6 -100 50 -2 -5 -3

Output

44

Input

6 3
-6 -100 50 -2 -5 -3

Output

0

### Response

```cpp
#include<stdio.h>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k,i,a,b,c,f[1000],sum_max=-999999999,sum;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&f[i]);
	}
	for(a=0;a<=k;a++)
	{
		for(b=0;b<=k;b++)
		{
				for(c=0;c<=k;c++)
				{
					priority_queue<int>q;
					if(a+b+c<=k&&a+b>=c&&a+b<=n)
					{
						for(i=0;i<a;i++)
						{
					       q.push(f[i]);
						}
						for(i=0;i<b;i++)
						{
					       q.push(f[n-i-1]);
						}
						int sum=0;
						for(i=0;i<a+b-c;i++)
						{
							sum=sum+q.top();
							q.pop();
						}
						sum_max=max(sum_max,sum);
					}
				}

		}
	}
	printf("%d",sum_max);
	return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given an array which is initially empty. You need to perform n operations of the given format:

  * "a l r k": append a to the end of the array. After that count the number of integer pairs x, y such that l ≤ x ≤ y ≤ r and \operatorname{mex}(a_{x}, a_{x+1}, …, a_{y}) = k.

The elements of the array are numerated from 1 in the order they are added to the array.

To make this problem more tricky we don't say your real parameters of the queries. Instead your are given a', l', r', k'. To get a, l, r, k on the i-th operation you need to perform the following:

  * a := (a' + lans) mod(n + 1),
  * l := (l' + lans) mod{i} + 1,
  * r := (r' + lans) mod{i} + 1,
  * if l > r swap l and r,
  * k := (k' + lans) mod(n + 1),

where lans is the answer to the previous operation, initially lans is equal to zero. i is the id of the operation, operations are numbered from 1.

The \operatorname{mex}(S), where S is a multiset of non-negative integers, is the smallest non-negative integer which does not appear in the set. For example, \operatorname{mex}(\{2, 2, 3\}) = 0 and \operatorname{mex} (\{0, 1, 4, 1, 6\}) = 2.

Input

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

The next n lines contain the description of queries.

Each of them n lines contains four non-negative integers a', l', r', k' (0, ≤ a', l', r', k' ≤ 10^9), describing one operation.

Output

For each query print a single integer — the answer to this query.

Examples

Input

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

Output

1
1
2
6
3

Input

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

Output

0
0
3
0
0

Note

For the first example the decoded values of a, l, r, k are the following:

a_1=0,l_1=1,r_1=1,k_1=1

a_2=1,l_2=1,r_2=2,k_2=0

a_3=0,l_3=1,r_3=3,k_3=1

a_4=1,l_4=1,r_4=4,k_4=2

a_5=2,l_5=1,r_5=5,k_5=3

For the second example the decoded values of a, l, r, k are the following:

a_1=2,l_1=1,r_1=1,k_1=2

a_2=2,l_2=1,r_2=2,k_2=1

a_3=0,l_3=1,r_3=3,k_3=0

a_4=0,l_4=2,r_4=2,k_4=3

a_5=0,l_5=3,r_5=4,k_5=0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
struct data {
  int x1, x2, y1, y2;
  long long sum;
  data(int x1 = 0, int x2 = 0, int y1 = 0, int y2 = 0, long long sum = 0)
      : x1(x1), x2(x2), y1(y1), y2(y2), sum(sum) {}
};
int a[N], le[N], ri[N], tag[N], lst[N];
vector<data> vec[N];
void del(int x, int y) {
  if (y > tag[x])
    vec[x].emplace_back(tag[x], y - 1, le[x], ri[x],
                        (vec[x].empty() ? 0ll : vec[x].back().sum) +
                            (long long)(ri[x] - le[x] + 1) * (y - tag[x]));
  tag[x] = 0;
}
void mdf(int x, int l, int r, int y) {
  if (tag[x])
    del(x, y);
  else
    le[x] = l;
  ri[x] = r;
  tag[x] = y;
}
long long query(int K, int l, int r) {
  long long ret = 0;
  if (!vec[K].empty()) {
    int L = 0, R = vec[K].size(), tL, tR;
    while (L < R) {
      int mid = (L + R) / 2;
      if (vec[K][mid].x2 >= l && vec[K][mid].y2 >= l)
        R = mid;
      else
        L = mid + 1;
    }
    tL = L;
    L = -1;
    R = vec[K].size() - 1;
    while (L < R) {
      int mid = (L + R + 1) / 2;
      if (vec[K][mid].x1 <= r && vec[K][mid].y1 <= r)
        L = mid;
      else
        R = mid - 1;
    }
    tR = L;
    if (tL <= tR) {
      assert(vec[K][tL].x2 >= l && vec[K][tL].y2 >= l && vec[K][tR].x1 <= r &&
             vec[K][tR].y1 <= r);
      ret += vec[K][tR].sum - (tL ? vec[K][tL - 1].sum : 0);
      if (l > vec[K][tL].x1)
        ret -= (long long)(vec[K][tL].y2 - vec[K][tL].y1 + 1) *
               (l - vec[K][tL].x1);
      if (r < vec[K][tR].x2)
        ret -= (long long)(vec[K][tR].y2 - vec[K][tR].y1 + 1) *
               (vec[K][tR].x2 - r);
      if (vec[K][tL].y1 < l) {
        L = tL;
        R = vec[K].size() - 1;
        while (L < R) {
          int mid = (L + R + 1) / 2;
          if (vec[K][mid].y1 < l)
            L = mid;
          else
            R = mid - 1;
        }
        ret -= (long long)(l - vec[K][tL].y1) *
               (min(vec[K][L].x2, r) - max(vec[K][tL].x1, l) + 1);
      }
    }
  }
  if (tag[K]) {
    int l1 = max(l, tag[K]), r1 = r, l2 = max(l, le[K]), r2 = min(r, ri[K]);
    if (l1 <= r1 && l2 <= r2) ret += (long long)(r1 - l1 + 1) * (r2 - l2 + 1);
  }
  return ret;
}
int n;
long long last_ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int l, r, K;
    cin >> a[i] >> l >> r >> K;
    a[i] = (a[i] + last_ans) % (n + 1);
    l = (l + last_ans) % i + 1;
    r = (r + last_ans) % i + 1;
    if (l > r) swap(l, r);
    K = (K + last_ans) % (n + 1);
    if (tag[a[i]]) {
      for (int j = a[i] + 1, r = ri[a[i]];; ++j)
        if (lst[j] < le[a[i]]) {
          mdf(j, le[a[i]], r, i);
          break;
        } else if (lst[j] < r) {
          mdf(j, lst[j] + 1, r, i);
          r = lst[j];
        }
      del(a[i], i);
    }
    mdf(!a[i], i, i, i);
    lst[a[i]] = i;
    cout << (last_ans = query(K, l, r)) << '\n';
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100.

Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively.

The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≤ 10 000) — the y-coordinates of the spaceships in the first group.

The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≤ 10 000) — the y-coordinates of the spaceships in the second group.

The y coordinates are not guaranteed to be unique, even within a group.

Output

Print a single integer – the largest number of enemy spaceships that can be destroyed.

Examples

Input

3 9
1 2 3
1 2 3 7 8 9 11 12 13

Output

9

Input

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

Output

10

Note

In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed.

In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[67], b[67], n, m;
map<int, long long> l, r;
vector<int> g;
inline int shu(long long a, int p) {
  int v = 0, len = p ? m : n;
  for (int i = 0; i < len; i++) {
    if (a >> i & 1) v++;
  }
  return v;
}
long long l1[100007], r1[100007];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int k = 0; k < m; k++) {
      int val = a[i] + b[k];
      g.push_back(val);
      l[val] |= (1LL << i);
      r[val] |= (1LL << k);
    }
  for (int i = 0; i < g.size(); i++) l1[i] = l[g[i]], r1[i] = r[g[i]];
  for (int i = 0; i < g.size(); i++) {
    for (int k = i; k < g.size(); k++) {
      ans = max(ans, shu(l1[i] | l1[k], 0) + shu(r1[i] | r1[k], 1));
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.

Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.

Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.

Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.

The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.

The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Output

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

Examples

Input

5
2 7 3 4 9
3
1 25 11

Output

1
5
3

Note

For the sample input:

  * The worms with labels from [1, 2] are in the first pile.
  * The worms with labels from [3, 9] are in the second pile.
  * The worms with labels from [10, 12] are in the third pile.
  * The worms with labels from [13, 16] are in the fourth pile.
  * The worms with labels from [17, 25] are in the fifth pile.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10000001], n, i, m, k = 0, x, j;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    for (j = k + 1; j <= k + x; j++) a[j] = i;
    k = k + x;
  }
  cin >> m;
  while (m-- > 0) {
    cin >> x;
    cout << a[x] << endl;
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.

This problem is similar to a standard problem but it has a different format and constraints.

In the standard problem you are given an array of integers, and you have to find one or more consecutive elements in this array where their sum is the maximum possible sum.

But in this problem you are given n small arrays, and you will create one big array from the concatenation of one or more instances of the small arrays (each small array could occur more than once). The big array will be given as an array of indexes (1-based) of the small arrays, and the concatenation should be done in the same order as in this array. Then you should apply the standard problem mentioned above on the resulting big array.

For example let's suppose that the small arrays are {1, 6, -2}, {3, 3} and {-5, 1}. And the indexes in the big array are {2, 3, 1, 3}. So the actual values in the big array after formatting it as concatenation of the small arrays will be {3, 3, -5, 1, 1, 6, -2, -5, 1}. In this example the maximum sum is 9.

Can you help Mostafa solve this problem?

Input

The first line contains two integers n and m, n is the number of the small arrays (1 ≤ n ≤ 50), and m is the number of indexes in the big array (1 ≤ m ≤ 250000). Then follow n lines, the i-th line starts with one integer l which is the size of the i-th array (1 ≤ l ≤ 5000), followed by l integers each one will be greater than or equal -1000 and less than or equal 1000. The last line contains m integers which are the indexes in the big array, and you should concatenate the small arrays in the same order, and each index will be greater than or equal to 1 and less than or equal to n.

The small arrays are numbered from 1 to n in the same order as given in the input. Some of the given small arrays may not be used in big array.

Note, that the array is very big. So if you try to build it straightforwardly, you will probably get time or/and memory limit exceeded.

Output

Print one line containing the maximum sum in the big array after formatting it as described above. You must choose at least one element for the sum, i. e. it cannot be empty.

Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).

Examples

Input

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

Output

9

Input

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

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int getmax(int* a, int n) {
  int cnt = 0;
  int s = 0;
  int res = *max_element(a, a + n);
  for (int i = 0; i < n; ++i) {
    s += a[i];
    if (s < 0) {
      s = 0;
      cnt = 0;
    } else
      cnt++;
    if (cnt > 0) res = max(res, s);
  }
  return res;
}
int len[1 << 6];
int a[1 << 6][1 << 13];
int p[1 << 6][1 << 13];
int s[1 << 6][1 << 13];
int ms[1 << 6];
int mp[1 << 6];
int mm[1 << 6];
int b[1 << 18];
long long go(int L, int R) {
  if (R - L == 1) return mm[b[L]];
  int M = (L + R) / 2;
  long long res = max(go(L, M), go(M, R));
  long long maxR = -(1LL << 60);
  long long maxL = -(1LL << 60);
  long long now = 0;
  for (int i = M; i < R; ++i) {
    maxR = max(maxR, now + mp[b[i]]);
    now += p[b[i]][len[b[i]]];
    maxR = max(maxR, now);
  }
  now = 0;
  for (int i = M - 1; i >= L; --i) {
    maxL = max(maxL, now + ms[b[i]]);
    now += p[b[i]][len[b[i]]];
    maxL = max(maxL, now);
  }
  res = max(res, maxR);
  res = max(res, maxL);
  res = max(res, maxL + maxR);
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &len[i]);
    for (int j = 0; j < len[i]; ++j) scanf("%d", &a[i][j]);
    ms[i] = -(int)1e9;
    mp[i] = -(int)1e9;
    s[i][0] = p[i][0] = 0;
    for (int j = 0; j < len[i]; ++j) {
      s[i][j + 1] = s[i][j] + a[i][len[i] - j - 1];
      p[i][j + 1] = p[i][j] + a[i][j];
      ms[i] = max(ms[i], s[i][j + 1]);
      mp[i] = max(mp[i], p[i][j + 1]);
    }
    mm[i] = getmax(a[i], len[i]);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d", &b[i]);
    b[i]--;
  }
  printf("%I64d\n", go(0, m));
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Kleofáš is participating in an n-thlon - a tournament consisting of n different competitions in n different disciplines (numbered 1 through n). There are m participants in the n-thlon and each of them participates in all competitions.

In each of these n competitions, the participants are given ranks from 1 to m in such a way that no two participants are given the same rank - in other words, the ranks in each competition form a permutation of numbers from 1 to m. The score of a participant in a competition is equal to his/her rank in it.

The overall score of each participant is computed as the sum of that participant's scores in all competitions.

The overall rank of each participant is equal to 1 + k, where k is the number of participants with strictly smaller overall score.

The n-thlon is over now, but the results haven't been published yet. Kleofáš still remembers his ranks in each particular competition; however, he doesn't remember anything about how well the other participants did. Therefore, Kleofáš would like to know his expected overall rank.

All competitors are equally good at each discipline, so all rankings (permutations of ranks of everyone except Kleofáš) in each competition are equiprobable.

Input

The first line of the input contains two space-separated integers n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 1000) — the number of competitions and the number of participants respectively.

Then, n lines follow. The i-th of them contains one integer xi (1 ≤ xi ≤ m) — the rank of Kleofáš in the i-th competition.

Output

Output a single real number – the expected overall rank of Kleofáš. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.

Examples

Input

4 10
2
1
2
1

Output

1.0000000000000000

Input

5 5
1
2
3
4
5

Output

2.7500000000000000

Input

3 6
2
4
2

Output

1.6799999999999999

Note

In the first sample, Kleofáš has overall score 6. Nobody else can have overall score less than 6 (but it's possible for one other person to have overall score 6 as well), so his overall rank must be 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int S, N, M, a[110];
double d[100100], s[100100], rez;
int main() {
  scanf("%d%d", &N, &M);
  if (M == 1) {
    printf("%.12lf", 1.0);
    return 0;
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &a[i]);
    S += a[i];
  }
  for (int i = 1; i <= S; ++i) {
    if (i != a[1] && i <= M) {
      d[i] = 1;
    }
    s[i] = s[i - 1] + d[i];
  }
  for (int i = 2; i <= N; ++i) {
    for (int j = 1; j <= S; ++j) {
      d[j] = s[j - 1] - s[max(0, j - a[i])] + s[max(0, j - a[i] - 1)] -
             s[max(0, j - M - 1)];
    }
    for (int j = 1; j <= S; ++j) {
      d[j] /= (M - 1);
      s[j] = s[j - 1] + d[j];
    }
  }
  for (int i = 1; i < S; ++i) {
    rez += d[i];
  }
  printf("%.12lf", rez + 1);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters.

The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.

Input

The first line of the input data contains two integer numbers separated by a space n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≤ hi ≤ 106) is the height of the i-th book in millimeters.

Output

In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b — the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters.

In each of the following b lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.

Examples

Input

3 3
14 12 10

Output

2 2
1 2
2 3

Input

2 0
10 10

Output

2 1
1 2

Input

4 5
8 19 10 13

Output

2 1
3 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
template <class T>
T abs(T a) {
  return a >= 0 ? a : -a;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T mod(T a, T b) {
  return (a % b + b) % b;
}
template <class T>
T addmod(T a, T b, T c) {
  return (T)mod((long long)a + b, (long long)c);
}
template <class T>
T mulmod(T a, T b, T c) {
  return (T)mod((long long)a * b, (long long)c);
}
template <class T>
T powmod(T a, T b, T c) {
  return (T)mod(
      b ? mulmod(mod(sqr((long long)powmod(a, b >> 1, c)), (long long)c),
                 (b & 1LL) ? a : 1LL, (long long)c)
        : 1LL,
      (long long)c);
}
template <class T>
void maxe(T &a, T b) {
  a = max(a, b);
}
template <class T>
void mine(T &a, T b) {
  a = min(a, b);
}
template <class T>
void mode(T &a, T b) {
  a = mod(a, b);
}
template <class T>
void addmode(T &a, T b, T c) {
  a = addmod(a, b, c);
}
template <class T>
void mulmode(T &a, T b, T c) {
  a = mulmod(a, b, c);
}
template <class T>
void powmode(T &a, T b, T c) {
  a = powmod(a, b, c);
}
int iszero(double a) { return abs(a) <= eps; }
template <class T>
void geti(T &a) {
  a = 0;
  long long b = 1;
  char c = getchar();
  if (c == '-')
    b = -1;
  else
    a = c - 48;
  while ((c = getchar()) != ' ' && c != '\n') a = a * 10 + c - 48;
  a *= b;
}
void fileio_in_out() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
void fileio_txt() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int arr[100005], n, k, cmx, cmn, s[100005];
struct segTree {
  int mx, mn;
} tree[1 << 18];
void insert(int cs, int in, int s, int e) {
  if (s == e) {
    tree[cs].mx = tree[cs].mn = arr[in];
    return;
  }
  int mid = (s + e) / 2;
  if (in <= mid)
    insert(2 * cs, in, s, mid);
  else
    insert(2 * cs + 1, in, mid + 1, e);
  tree[cs].mx = max(tree[2 * cs].mx, tree[2 * cs + 1].mx);
  tree[cs].mn = min(tree[2 * cs].mn, tree[2 * cs + 1].mn);
}
bool stop;
int ans;
bool ok(int mx, int mn) {
  int tmx = max(cmx, mx);
  int tmn = min(cmn, mn);
  if (tmx - tmn <= k) {
    cmx = tmx;
    cmn = tmn;
    return true;
  }
  return false;
}
void cal(int cs, int s1, int e1, int s, int e) {
  if (stop) return;
  int mid = (s + e) / 2;
  if (s1 == s && e1 == e) {
    if (ok(tree[cs].mx, tree[cs].mn))
      ans += (e - s + 1);
    else if (s == e) {
      stop = true;
    } else if (!stop) {
      if (ok(tree[2 * cs].mx, tree[2 * cs].mn)) {
        ans += (mid - s + 1);
        cal(2 * cs + 1, mid + 1, e, mid + 1, e);
      } else {
        cal(2 * cs, s, mid, s, mid);
        stop = true;
      }
    }
    return;
  }
  if (s1 <= mid) cal(2 * cs, s1, min(mid, e1), s, mid);
  if (e1 > mid) cal(2 * cs + 1, max(s1, mid + 1), e1, mid + 1, e);
}
int main() {
  cin >> n >> k;
  for (int i = 1; i < (n + 1); ++i) {
    cin >> arr[i];
    insert(1, i, 1, n);
  }
  int MX = 0, in = 0;
  for (int i = 1; i < (n + 1); ++i) {
    ans = 0;
    stop = false;
    cmx = cmn = arr[i];
    cal(1, i + 1, n, 1, n);
    if (ans + 1 > MX) {
      MX = ans + 1;
      in = 0;
      s[in++] = i;
    } else if (ans + 1 == MX)
      s[in++] = i;
  }
  cout << MX << " " << in << endl;
  for (int i = 0; i < (in); ++i) cout << s[i] << " " << s[i] + MX - 1 << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties:

  * Have positive area.
  * With vertices at integer points.
  * All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0, 0), (w, 0), (w, h), (0, h). In other words, for all vertices (xi, yi) of the rhombus the following conditions should fulfill: 0 ≤ xi ≤ w and 0 ≤ yi ≤ h.
  * Its diagonals are parallel to the axis.

Count the number of such rhombi.

Let us remind you that a rhombus is a quadrilateral whose four sides all have the same length.

Input

The first line contains two integers w and h (1 ≤ w, h ≤ 4000) — the rectangle's sizes.

Output

Print a single number — the number of sought rhombi.

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.

Examples

Input

2 2

Output

1

Input

1 2

Output

0

Note

In the first example there exists only one such rhombus. Its vertices are located at points (1, 0), (2, 1), (1, 2), (0, 1).

### Response

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

```


### Prompt

Develop a solution in CPP to the problem described below:

Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.

Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:

  * Each piece should contain at least l numbers.
  * The difference between the maximal and the minimal number on the piece should be at most s.

Please help Alexandra to find the minimal number of pieces meeting the condition above.

Input

The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105).

The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).

Output

Output the minimal number of strip pieces.

If there are no ways to split the strip, output -1.

Examples

Input

7 2 2
1 3 1 2 4 1 2

Output

3

Input

7 2 2
1 100 1 100 1 100 1

Output

-1

Note

For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2].

For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int arr[N];
int n, s, l;
int last[N];
void buildLast() {
  multiset<int> ms;
  int curr = n - 1;
  for (int i = n - 1; i >= 0; --i) {
    ms.insert(arr[i]);
    while (*ms.rbegin() - *ms.begin() > s) {
      ms.erase(ms.find(arr[curr]));
      --curr;
    }
    last[i] = curr;
  }
}
int best[N];
const int OO = 1e8;
int solve() {
  multiset<int> ms;
  for (int i = n - l + 1; i < n; ++i) {
    best[i] = OO;
  }
  best[n] = 0;
  int curr = n;
  for (int i = n - l; i >= 0; --i) {
    ms.insert(best[i + l]);
    while (curr > last[i] + 1 && curr >= i + l) {
      ms.erase(ms.find(best[curr]));
      --curr;
    }
    if (ms.empty() || *ms.begin() == OO) {
      best[i] = OO;
    } else {
      best[i] = *ms.begin() + 1;
    }
  }
  if (best[0] == OO) return -1;
  return best[0];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> s >> l;
  if (l > n) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  buildLast();
  cout << solve();
}

```