### Prompt

Construct a CPP code solution to the problem outlined:

Snuke has N strings. The i-th string is s_i.

Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.

Constraints

* 1 \leq N \leq 10^{4}
* 2 \leq |s_i| \leq 10
* s_i consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
s_1
\vdots
s_N

Output

Print the answer.

Examples

Input

3
ABCA
XBAZ
BAD

Output

2

Input

9
BEWPVCRWH
ZZNQYIJX
BAVREA
PA
HJMYITEOX
BCJHMRMNK
BP
QVFABZ
PRGKSPUNA

Output

4

Input

7
RABYBBE
JOZ
BMHQUVA
BPA
ISU
MCMABAOBHZ
SZMEHMA

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char a[1000];
int main()
{
	long long n,a1=0,a2=0,a3=0,a4=0;
	cin>>n;
	while(n--)
	{
		memset(a,'\0',sizeof(a));
		cin>>a;
			if(a[0]=='B')
			{
				a1++;
			}
			if(a[strlen(a)-1]=='A')
			{
				a2++;
			}
			if(a[strlen(a)-1]=='A'&&a[0]=='B')
			{
				a4++;
			}
		for(int i=0;i<strlen(a)-1;i++)
		{
			if(a[i]=='A'&&a[i+1]=='B')
			{
				a3++;
			}
		}
	}
	long long aa=min(a1,a2);
	if(a1==a4&&a2==a4&&a4!=0)
	{
		cout<<aa+a3-1<<endl;
	}
	else
	cout<<aa+a3<<endl;
}
```


### Prompt

Generate a CPP solution to the following problem:

There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty.

In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.

You can repeat the following operation any number of times:

* Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.

You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.

Determine whether this is possible.

Constraints

* 4 \leq N \leq 200\ 000
* S is a string of length N consisting of `.` and `#`.
* 1 \leq A, B, C, D \leq N
* Square A, B, C and D do not contain a rock.
* A, B, C and D are all different.
* A < B
* A < C
* B < D

Input

Input is given from Standard Input in the following format:

N A B C D
S

Output

Print `Yes` if the objective is achievable, and `No` if it is not.

Examples

Input

7 1 3 6 7
.#..#..

Output

Yes

Input

7 1 3 7 6
.#..#..

Output

No

Input

15 1 3 15 13
...#.#...#.#...

Output

Yes

### Response

```cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    long long int n, a, b, c, d, k, i, j, ng=0, ok=0;
    scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d);
    char s[n+1];
    a--;
    b--;
    c--;
    d--;
    scanf("%s", s);
    if(c<d) ok=1;
    for(i=a; i<=c||i<=d; i++){
        if(i>0){
            if(s[i-1]=='#'&&s[i]=='#') ng=1;
        }
        if(c>d && i>=b+1 && i<=d+1){
            if(s[i-2]=='.'&&s[i-1]=='.'&&s[i]=='.') ok=1;
        }
    }
//    printf("%lld %lld", ok, ng);
    if(ok==1&&ng==0) printf("Yes");
    else printf("No");

}
```


### Prompt

Please create a solution in cpp to the following problem:

There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.

The following steps happen until there is exactly one active startup. The following sequence of steps takes exactly 1 day.

  1. Two distinct active startups A, B, are chosen uniformly at random.
  2. A fair coin is flipped, and with equal probability, A acquires B or B acquires A (i.e. if A acquires B, then that means B's state changes from active to acquired, and its starts following A).
  3. When a startup changes from active to acquired, all of its previously acquired startups become active.

For example, the following scenario can happen: Let's say A, B are active startups. C, D, E are acquired startups under A, and F, G are acquired startups under B:

<image>

Active startups are shown in red.

If A acquires B, then the state will be A, F, G are active startups. C, D, E, B are acquired startups under A. F and G have no acquired startups:

<image>

If instead, B acquires A, then the state will be B, C, D, E are active startups. F, G, A are acquired startups under B. C, D, E have no acquired startups:

<image>

You are given the initial state of the startups. For each startup, you are told if it is either acquired or active. If it is acquired, you are also given the index of the active startup that it is following.

You're now wondering, what is the expected number of days needed for this process to finish with exactly one active startup at the end.

It can be shown the expected number of days can be written as a rational number P/Q, where P and Q are co-prime integers, and Q not= 0 \pmod{10^9+7}. Return the value of P ⋅ Q^{-1} modulo 10^9+7.

Input

The first line contains a single integer n (2 ≤ n ≤ 500), the number of startups.

The next line will contain n space-separated integers a_1, a_2, …, a_n (a_i = -1 or 1 ≤ a_i ≤ n). If a_i = -1, then that means startup i is active. Otherwise, if 1 ≤ a_i ≤ n, then startup i is acquired, and it is currently following startup a_i. It is guaranteed if a_i not= -1, then a_{a_i} =-1 (that is, all startups that are being followed are active).

Output

Print a single integer, the expected number of days needed for the process to end with exactly one active startup, modulo 10^9+7.

Examples

Input

3
-1 -1 -1

Output

3

Input

2
2 -1

Output

0

Input

40
3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3

Output

755808950

Note

In the first sample, there are three active startups labeled 1, 2 and 3, and zero acquired startups. Here's an example of how one scenario can happen

  1. Startup 1 acquires startup 2 (This state can be represented by the array [-1, 1, -1])
  2. Startup 3 acquires startup 1 (This state can be represented by the array [3, -1, -1])
  3. Startup 2 acquires startup 3 (This state can be represented by the array [-1, -1, 2]).
  4. Startup 2 acquires startup 1 (This state can be represented by the array [2, -1, 2]).

At this point, there is only one active startup, and this sequence of steps took 4 days. It can be shown the expected number of days is 3.

For the second sample, there is only one active startup, so we need zero days.

For the last sample, remember to take the answer modulo 10^9+7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long solve(vector<int> freq) {
  long long ans = 0;
  for (int i = 0; i < freq.size(); i++) {
    if (freq[i] > 0) {
      long long num = 1;
      for (int j = 0; j < freq[i] - 1; j++) {
        num = (num + num) % MOD;
      }
      num--;
      ans = (ans + num) % MOD;
    }
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<int> freq(n, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    a--;
    if (a < 0) a = i;
    freq[a]++;
  }
  long long ans = solve({n}) - solve(freq);
  if (ans < 0) ans += MOD;
  cout << ans << endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given a string s consisting of exactly n characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.

Your task is to replace minimum number of characters in this string with other characters to obtain a balanced ternary string (balanced ternary string is a ternary string such that the number of characters '0' in this string is equal to the number of characters '1', and the number of characters '1' (and '0' obviously) is equal to the number of characters '2').

Among all possible balanced ternary strings you have to obtain the lexicographically (alphabetically) smallest.

Note that you can neither remove characters from the string nor add characters to the string. Also note that you can replace the given characters only with characters '0', '1' and '2'.

It is guaranteed that the answer exists.

Input

The first line of the input contains one integer n (3 ≤ n ≤ 3 ⋅ 10^5, n is divisible by 3) — the number of characters in s.

The second line contains the string s consisting of exactly n characters '0', '1' and '2'.

Output

Print one string — the lexicographically (alphabetically) smallest balanced ternary string which can be obtained from the given one with minimum number of replacements.

Because n is divisible by 3 it is obvious that the answer exists. And it is obvious that there is only one possible answer.

Examples

Input

3
121

Output

021

Input

6
000000

Output

001122

Input

6
211200

Output

211200

Input

6
120110

Output

120120

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
int main() {
  int n1;
  cin >> n1;
  char a[n1 + 1];
  cin >> a;
  int n[3] = {0, 0, 0};
  for (int i = 0; i < n1; i++) {
    if (a[i] == '1')
      n[1]++;
    else if (a[i] == '2')
      n[2]++;
    else if (a[i] == '0')
      n[0]++;
  }
  int ide = (n1 / 3);
  int dum0, dum1, dum2;
  dum1 = (n[1] - ide);
  dum2 = (n[2] - ide);
  dum0 = (n[0] - ide);
  if (dum0 > 0) {
    for (int j = n1 - 1; j > 0; j--) {
      if (a[j] == '0' && dum0 > 0) {
        if (dum2 < 0) {
          a[j] = '2';
          dum2++;
          dum0--;
        } else if (dum1 < 0) {
          a[j] = '1';
          dum1++;
          dum0--;
        }
      }
    }
  }
  if (dum2 > 0) {
    for (int j = 0; j < n1; j++) {
      if (a[j] == '2' && dum2 > 0) {
        if (dum0 < 0) {
          a[j] = '0';
          dum2--;
          dum0++;
        } else if (dum1 < 0) {
          a[j] = '1';
          dum1++;
          dum2--;
        }
      }
    }
  }
  if (dum1 > 0) {
    for (int j = n1 - 1; j > 0; j--) {
      if (a[j] == '1' && dum1 > 0) {
        if (dum2 < 0) {
          a[j] = '2';
          dum2++;
          dum1--;
        }
      }
    }
    for (int j = 0; j < n1; j++) {
      if (a[j] == '1' && dum1 > 0) {
        if (dum0 < 0) {
          a[j] = '0';
          dum1--;
          dum0++;
        }
      }
    }
  }
  cout << a;
  return 0;
}

```


### Prompt

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

The game of Berland poker is played with a deck of n cards, m of which are jokers. k players play this game (n is divisible by k).

At the beginning of the game, each player takes n/k cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he gets the number of points equal to x - y, where x is the number of jokers in the winner's hand, and y is the maximum number of jokers among all other players. If there are two or more players with maximum number of jokers, all of them are winners and they get 0 points.

Here are some examples:

  * n = 8, m = 3, k = 2. If one player gets 3 jokers and 1 plain card, and another player gets 0 jokers and 4 plain cards, then the first player is the winner and gets 3 - 0 = 3 points;
  * n = 4, m = 2, k = 4. Two players get plain cards, and the other two players get jokers, so both of them are winners and get 0 points;
  * n = 9, m = 6, k = 3. If the first player gets 3 jokers, the second player gets 1 joker and 2 plain cards, and the third player gets 2 jokers and 1 plain card, then the first player is the winner, and he gets 3 - 2 = 1 point;
  * n = 42, m = 0, k = 7. Since there are no jokers, everyone gets 0 jokers, everyone is a winner, and everyone gets 0 points.

Given n, m and k, calculate the maximum number of points a player can get for winning the game.

Input

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

Then the test cases follow. Each test case contains three integers n, m and k (2 ≤ n ≤ 50, 0 ≤ m ≤ n, 2 ≤ k ≤ n, k is a divisors of n).

Output

For each test case, print one integer — the maximum number of points a player can get for winning the game.

Example

Input

4
8 3 2
4 2 4
9 6 3
42 0 7

Output

3
0
1
0

Note

Test cases of the example are described in the statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t, n, m, k;
  cin >> t;
  while (t--) {
    cin >> n >> m >> k;
    int take;
    take = n / k;
    if (m <= take) {
      cout << m << endl;
    } else {
      int rem, ans;
      rem = m - take;
      double tmp = ceil((double)rem / (double)(k - 1));
      ans = tmp;
      cout << take - ans << endl;
    }
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given two integers a and b. You may perform any number of operations on them (possibly zero).

During each operation you should choose any positive integer x and set a := a - x, b := b - 2x or a := a - 2x, b := b - x. Note that you may choose different values of x in different operations.

Is it possible to make a and b equal to 0 simultaneously?

Your program should answer t independent test cases.

Input

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

Then the test cases follow, each test case is represented by one line containing two integers a and b for this test case (0 ≤ a, b ≤ 10^9).

Output

For each test case print the answer to it — YES if it is possible to make a and b equal to 0 simultaneously, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example

Input

3
6 9
1 1
1 2

Output

YES
NO
YES

Note

In the first test case of the example two operations can be used to make both a and b equal to zero:

  1. choose x = 4 and set a := a - x, b := b - 2x. Then a = 6 - 4 = 2, b = 9 - 8 = 1;
  2. choose x = 1 and set a := a - 2x, b := b - x. Then a = 2 - 2 = 0, b = 1 - 1 = 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long maxm = -1e18;
long long minm = 1e18;
long long mod = 1e9 + 7;
const long double Pi = 3.141592653;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    if ((a + b) % 3 == 0) {
      if (min(a, b) == 0 && max(a, b) == 0) {
        cout << "YES" << endl;
      } else if (min(a, b) == 0 && max(a, b) > 0) {
        cout << "NO" << endl;
      } else if (min(a, b) > 0 && max(a, b) <= 2 * min(a, b)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

```


### Prompt

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

The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.

Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:

Suppose we want to analyze the segment of n consecutive days. We have measured the temperatures during these n days; the temperature during i-th day equals a_i.

We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day x to day y, we calculate it as \frac{∑ _{i = x}^{y} a_i}{y - x + 1} (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than k consecutive days. For example, if analyzing the measures [3, 4, 1, 2] and k = 3, we are interested in segments [3, 4, 1], [4, 1, 2] and [3, 4, 1, 2] (we want to find the maximum value of average temperature over these segments).

You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task?

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 5000) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 5000) — the temperature measures during given n days.

Output

Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than k consecutive days.

Your answer will be considered correct if the following condition holds: |res - res_0| < 10^{-6}, where res is your answer, and res_0 is the answer given by the jury's solution.

Example

Input

4 3
3 4 1 2

Output

2.666666666666667

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[5005];
  a[0] = 0;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) a[i] = a[i] + a[i - 1];
  double ans = 0;
  int sum;
  for (int j = k; j <= n; ++j)
    for (int i = j; i <= n; ++i) ans = max(ans, (double)(a[i] - a[i - j]) / j);
  printf("%.15lf", ans);
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).

You want to construct the array a of length n such that:

  * The first n/2 elements of a are even (divisible by 2);
  * the second n/2 elements of a are odd (not divisible by 2);
  * all elements of a are distinct and positive;
  * the sum of the first half equals to the sum of the second half (∑_{i=1}^{n/2} a_i = ∑_{i=n/2 + 1}^{n} a_i).

If there are multiple answers, you can print any. It is not guaranteed that the answer exists.

You have to answer t independent test cases.

Input

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

The only line of the test case contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. It is guaranteed that that n is even (i.e. divisible by 2).

It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) satisfying conditions from the problem statement on the second line.

Example

Input

5
2
4
6
8
10

Output

NO
YES
2 4 1 5
NO
YES
2 4 6 8 1 3 5 11
NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  for (long long j = 0; j < t; ++j) {
    long long n;
    cin >> n;
    if (n % 4 != 0)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      vector<long long> a(n);
      for (long long i = 0; i < n / 2; ++i) {
        a[i] = i * 2 + 1;
        if (i == n / 2 - 1) a[i] += n / 2;
      }
      for (long long i = n / 2; i < n; ++i) {
        a[i] = (i - n / 2) * 2 + 2;
      }
      for (long long i = n - 1; i >= 0; --i) cout << a[i] << ' ';
      cout << endl;
    }
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the beauty of the tower as follows:

* The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.

Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.

Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.

Constraints

* 1 ≤ N ≤ 3×10^5
* 1 ≤ A,B ≤ 3×10^5
* 0 ≤ K ≤ 18×10^{10}
* All values in the input are integers.

Input

Input is given from Standard Input in the following format:

N A B K

Output

Print the number of the ways to paint tiles, modulo 998244353.

Examples

Input

4 1 2 5

Output

40

Input

2 5 6 0

Output

1

Input

90081 33447 90629 6391049189

Output

577742975

### Response

```cpp
#include<bits/stdc++.h>
#define int long long
#define mod 998244353
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int f1(int a, int p) {
	if (p == 1)return a;
	if (p % 2)return f1(a, p - 1) * a % mod;
	else return f1(a * a % mod, p / 2) % mod;
}
int c[345678], n, a, b, k, ans = 0;
signed main() {
	cin >> n >> a >> b >> k;
	c[0] = 1;
	for1(i, n) {
		c[i] = c[i - 1] * (n - i + 1) % mod;
		c[i] = c[i] * f1(i, mod - 2) % mod;
	}
	for0(i, n + 1) {
		if (a * i > k)break;
		if ((k - a * i) % b == 0 && (k - a * i) / b <= n) {
			ans += c[i] * c[(k - a * i) / b]; ans %= mod;
		}
	}
	cout << ans << endl;
}
```


### Prompt

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

An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).

The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the 2-nd one, the 2-nd one — to the 1-st and the 3-rd ones, the 3-rd one — only to the 2-nd one. The transitions are possible only between the adjacent sections.

The spacecraft team consists of n aliens. Each of them is given a rank — an integer from 1 to n. The ranks of all astronauts are distinct. The rules established on the Saucer, state that an alien may move from section a to section b only if it is senior in rank to all aliens who are in the segments a and b (besides, the segments a and b are of course required to be adjacent). Any alien requires exactly 1 minute to make a move. Besides, safety regulations require that no more than one alien moved at the same minute along the ship.

Alien A is senior in rank to alien B, if the number indicating rank A, is more than the corresponding number for B.

At the moment the whole saucer team is in the 3-rd segment. They all need to move to the 1-st segment. One member of the crew, the alien with the identification number CFR-140, decided to calculate the minimum time (in minutes) they will need to perform this task.

Help CFR-140, figure out the minimum time (in minutes) that all the astronauts will need to move from the 3-rd segment to the 1-st one. Since this number can be rather large, count it modulo m.

Input

The first line contains two space-separated integers: n and m (1 ≤ n, m ≤ 109) — the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly.

Output

Print a single number — the answer to the problem modulo m.

Examples

Input

1 10

Output

2

Input

3 8

Output

2

Note

In the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes.

To briefly describe the movements in the second sample we will use value <image>, which would correspond to an alien with rank i moving from the segment in which it is at the moment, to the segment number j. Using these values, we will describe the movements between the segments in the second sample: <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>; In total: the aliens need 26 moves. The remainder after dividing 26 by 8 equals 2, so the answer to this test is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long b, long long p, long long m) {
  if (p == 0) return 1;
  long long ret;
  if ((p % 2) == 0) {
    ret = bigmod(b, p / 2, m) % m;
    ret = (ret * ret) % m;
  } else {
    ret = bigmod(b, p - 1, m) % m;
    ret = (ret * (b % m)) % m;
  }
  return ret;
}
int main() {
  long long n, m;
  while (cin >> n >> m) {
    long long ans = bigmod(3, n, m);
    ans = (ans - 1 + m) % m;
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Yuki made a sugoroku so that everyone can play at the children's association event. In this sugoroku, squares are lined up in a ring, and each square has an integer of 1 or more written on it.

The player chooses a square as a starting point and places his piece. Advance the pieces clockwise by the number written on the square. Advance the pieces clockwise again by the number written on the stopped square. Repeat this, and when the piece stops on the square selected as the starting point, it is "Agari".

In reality, depending on how you choose the squares, it may never be "finished". Yuki is trying to count the number of squares that can reach the "Agari" in this sugoroku.

Create a program that inputs sugoroku information and reports the number of squares that can reach "Agari".

Input

The input is given in the following format.

N
a1 a2 ... aN

The number N (1 ≤ N ≤ 100000) of all the cells contained in the sugoroku is given in the first line. On the second line, the number ai (1 ≤ ai ≤ 109) written in each cell is given in turn clockwise.

Output

The number of squares that can reach "Agari" is output in one line.

Examples

Input

3
1 1 1

Output

3

Input

3
1 1 2

Output

2

Input

8
2 3 7 3 3 3 4 4

Output

6

### Response

```cpp
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[100000];
vector<int> G[100000], R[100000];
vector<int> vs;
bool used[100000];
int ord[100000];
int size[100000];

void dfs(int x) {
  if (used[x]) return;
  used[x] = true;
  for (int t : G[x]) dfs(t);
  vs.pb(x);
}
void rdfs(int x, int k) {
  if (used[x]) return;
  used[x] = true;
  ord[x] = k;
  for (int t : R[x]) rdfs(t, k);
}

int scc() {
  rep(i, N) used[i] = false;
  rep(i, N) dfs(i);
  rep(i, N) used[i] = false;
  int k = 0;
  for (int i=vs.size()-1; i>=0; i--) {
    if (!used[vs[i]]) rdfs(vs[i], k++);
  }
  return k;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) {
    int a;
    cin >> a;
    A[i] = (i+a) % N;
  }
  int c = 0;
  rep(i, N) if (A[i] == i) c++;
  rep(i, N) {
    G[i].pb(A[i]);
    R[A[i]].pb(i);
  }
  scc();
  rep(i, N) size[ord[i]]++;
  rep(i, N) {
    if (size[ord[i]] >= 2) c++;
  }
  cout << c << "\n";
  return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put n dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. The i-th domino has the coordinate xi and the height hi. Now Vasya wants to learn for every domino, how many dominoes will fall if he pushes it to the right. Help him do that.

Consider that a domino falls if it is touched strictly above the base. In other words, the fall of the domino with the initial coordinate x and height h leads to the fall of all dominoes on the segment [x + 1, x + h - 1].

<image>

Input

The first line contains integer n (1 ≤ n ≤ 105) which is the number of dominoes. Then follow n lines containing two integers xi and hi ( - 108 ≤ xi ≤ 108, 2 ≤ hi ≤ 108) each, which are the coordinate and height of every domino. No two dominoes stand on one point.

Output

Print n space-separated numbers zi — the number of dominoes that will fall if Vasya pushes the i-th domino to the right (including the domino itself).

Examples

Input

4
16 5
20 5
10 10
18 2

Output

3 1 4 1

Input

4
0 10
1 5
9 10
15 10

Output

4 1 2 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int64_t MOD = 1000000007;
const int INF = 0x3F3F3F3F;
const long long LINF = 4611686018427387903;
int64_t gcd(int64_t a, int64_t b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
template <typename _Size>
inline _Size __lg(_Size __n) {
  _Size __k;
  for (__k = 0; __n != 0; __n >>= 1) ++__k;
  return __k - 1;
}
const int N = 100025;
struct node {
  int x, h, id;
};
bool cmp(node a, node b) { return a.x < b.x; }
vector<node> arr;
int dp[N];
int lc[N * 40], rc[N * 40];
int cnt;
struct segtree {
  int lazy[N * 40];
  int seg[N * 40];
  void push(int p) {
    if (lazy[p]) {
      seg[lc[p]] += lazy[p];
      lazy[lc[p]] += lazy[p];
      seg[rc[p]] += lazy[p];
      lazy[rc[p]] += lazy[p];
      lazy[p] = 0;
    }
  }
  void pull(int p) { seg[p] = max(seg[lc[p]], seg[rc[p]]); }
  void modify(int rt, int l, int r, int ql, int qr, int x) {
    if (ql <= l && qr >= r) {
      seg[rt] += x;
      lazy[rt] += x;
      return;
    }
    if (!lc[rt]) lc[rt] = ++cnt;
    if (!rc[rt]) rc[rt] = ++cnt;
    push(rt);
    int mid = l + r >> 1;
    if (ql <= mid) modify(lc[rt], l, mid, ql, qr, x);
    if (qr > mid) modify(rc[rt], mid + 1, r, ql, qr, x);
    pull(rt);
  }
  int query(int rt, int l, int r, int ql, int qr) {
    if (ql <= l && qr >= r) return seg[rt];
    if (!lc[rt]) lc[rt] = ++cnt;
    if (!rc[rt]) rc[rt] = ++cnt;
    push(rt);
    int tmp = -INF;
    int mid = l + r >> 1;
    if (ql <= mid) tmp = max(tmp, query(lc[rt], l, mid, ql, qr));
    if (qr > mid) tmp = max(tmp, query(rc[rt], mid + 1, r, ql, qr));
    return tmp;
  }
} sgt;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cnt = 1;
  arr.resize(n + 1);
  arr[0].x = -INF;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i].x;
    cin >> arr[i].h;
    arr[i].id = i;
  }
  sort(arr.begin(), arr.end(), cmp);
  for (int i = n; i; i--) {
    sgt.modify(1, -(int)1e8, (int)1e8, arr[i].x, (int)1e8, 1);
    dp[arr[i].id] = sgt.query(1, -(int)1e8, int(1e8), arr[i].x,
                              min((int)1e8, arr[i].x + arr[i].h - 1));
    sgt.modify(1, -(int)1e8, (int)1e8, arr[i].x, arr[i].x, dp[arr[i].id] - 1);
  }
  for (int i = 1; i <= n; i++) cout << dp[i] << " ";
  return 0;
}

```


### Prompt

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

There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle.

Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.

At the moment 0, from the point (0, 0) the laser ray is released in the direction of point (1, 1). The ray travels with a speed of <image> meters per second. Thus, the ray will reach the point (1, 1) in exactly one second after the start.

When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.

For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print  - 1 for such sensors.

Input

The first line of the input contains three integers n, m and k (2 ≤ n, m ≤ 100 000, 1 ≤ k ≤ 100 000) — lengths of the room's walls and the number of sensors.

Each of the following k lines contains two integers xi and yi (1 ≤ xi ≤ n - 1, 1 ≤ yi ≤ m - 1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point.

Output

Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or  - 1 if this will never happen.

Examples

Input

3 3 4
1 1
1 2
2 1
2 2

Output

1
-1
-1
2

Input

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

Output

1
-1
-1
2
5
-1

Input

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

Output

13
2
9
5
-1

Note

In the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds.

<image>

In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (3, 1), (2, 2), (1, 3), (0, 4). The ray will stop at the point (0, 4) after 12 seconds. It will reflect at the points (3, 3), (2, 4), (0, 2), (2, 0) and (3, 1).

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<pair<long long, long long> > pts(k);
  for (int i = 0; i < k; ++i) {
    cin >> pts[i].first >> pts[i].second;
  }
  const int UP = 1;
  const int DOWN = -1;
  pair<long long, long long> cur = {0, 0};
  int xdir = UP;
  int ydir = UP;
  map<pair<long long, long long>, long long> bumps;
  map<long long, pair<long long, long long> > bumpstimes;
  long long tim = 0;
  bumps.insert({cur, tim});
  bumpstimes.insert({tim, cur});
  while (true) {
    long long dt = LLONG_MAX;
    if (xdir == UP)
      dt = min(dt, n - cur.first);
    else
      dt = min(dt, cur.first);
    if (ydir == UP)
      dt = min(dt, m - cur.second);
    else
      dt = min(dt, cur.second);
    cur.first += xdir * dt;
    cur.second += ydir * dt;
    if (cur.first == 0 || cur.first == n) {
      xdir *= -1;
    }
    if (cur.second == 0 || cur.second == m) {
      ydir *= -1;
    }
    tim += dt;
    bumps.insert({cur, tim});
    bumpstimes.insert({tim, cur});
    if ((cur.first == 0 || cur.first == n) &&
        (cur.second == 0 || cur.second == m)) {
      break;
    }
  }
  for (int i = 0; i < k; ++i) {
    long long min_t = LLONG_MAX;
    for (int xdir : {UP, DOWN}) {
      for (int ydir : {UP, DOWN}) {
        cur = pts[i];
        long long dt = LLONG_MAX;
        if (xdir == UP)
          dt = min(dt, n - cur.first);
        else
          dt = min(dt, cur.first);
        if (ydir == UP)
          dt = min(dt, m - cur.second);
        else
          dt = min(dt, cur.second);
        cur.first += xdir * dt;
        cur.second += ydir * dt;
        if (bumps.find(cur) != bumps.end()) {
          pair<long long, long long> cur2 = pts[i];
          long long dt2 = LLONG_MAX;
          int xdir2 = xdir * -1;
          int ydir2 = ydir * -1;
          if (xdir2 == UP)
            dt2 = min(dt2, n - cur2.first);
          else
            dt2 = min(dt2, cur2.first);
          if (ydir2 == UP)
            dt2 = min(dt2, m - cur2.second);
          else
            dt2 = min(dt2, cur2.second);
          cur2.first += xdir2 * dt2;
          cur2.second += ydir2 * dt2;
          auto it = bumps.find(cur);
          auto it2 = bumps.find(cur2);
          if (it->second < it2->second) {
            min_t = min(min_t, it->second + dt);
          } else {
            min_t = min(min_t, it2->second + dt2);
          }
        }
      }
    }
    if (min_t == LLONG_MAX)
      cout << "-1" << endl;
    else
      cout << min_t << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Dreamoon likes coloring cells very much.

There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.

You are given an integer m and m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n)

Dreamoon will perform m operations.

In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.

Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints.

Input

The first line contains two integers n,m (1 ≤ m ≤ n ≤ 100 000).

The second line contains m integers l_1, l_2, …, l_m (1 ≤ l_i ≤ n).

Output

If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes).

Otherwise, print m integers p_1, p_2, …, p_m (1 ≤ p_i ≤ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored.

If there are several possible solutions, you can print any.

Examples

Input

5 3
3 2 2

Output

2 4 1

Input

10 1
1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int read() {
  int p = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    p = (p << 1) + (p << 3) + (c ^ 48), c = getchar();
  }
  return p * f;
}
int l[maxn], p[maxn];
int main() {
  int n = read(), m = read();
  long long sum = 0;
  for (register int i = 1; i <= m; i++) {
    l[i] = read();
    sum += l[i];
  }
  if (sum < n) {
    cout << "-1";
    return 0;
  }
  for (register int i = 1; i <= m; i++) {
    if (i + l[i] - 1 > n) {
      cout << "-1";
      return 0;
    }
    p[i] = i;
  }
  int now = m, res = n;
  while (res) {
    if (res - l[now] + 1 <= now - 1) break;
    p[now] = res - l[now] + 1;
    res = p[now] - 1;
    now--;
  }
  for (register int i = 1; i <= m; i++) cout << p[i] << " ";
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given two sequences a and b, both of length 2N. The i-th elements in a and b are a_i and b_i, respectively. Using these sequences, Snuke is doing the job of calculating the beauty of pairs of balanced sequences of parentheses (defined below) of length 2N. The beauty of a pair (s,t) is calculated as follows:

* Let X=0.
* For each i between 1 and 2N (inclusive), increment X by a_i if s_i = t_i, and increment X by b_i otherwise.
* The beauty of (s,t) is the final value of X.

You will be given Q queries. Process them in order. In the i-th query, update the value of a_{p_i} to x_i, and the value of b_{p_i} to y_i. Then, find the maximum possible beauty of a pair of balanced sequences of parentheses.

In this problem, only the sequences below are defined to be balanced sequences of parentheses.

* An empty string
* The concatenation of `(`, s, `)` in this order, where s is a balanced sequence of parentheses
* The concatenation of s, t in this order, where s and t are balanced sequences of parentheses

Constraints

* 1 \leq N,Q \leq 10^{5}
* -10^{9} \leq a_i,b_i,x_i,y_i \leq 10^{9}
* 1 \leq p_i \leq 2N
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N Q
a_1 a_2 ... a_{2N}
b_1 b_2 ... b_{2N}
p_1 x_1 y_1
:
p_Q x_Q y_Q

Output

Print Q lines. The i-th line should contain the response to the i-th query.

Examples

Input

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

Output

15
15

Input

7 7
34 -20 -27 42 44 29 9 11 20 44 27 19 -31 -29
46 -50 -11 20 28 46 12 13 33 -22 -48 -27 35 -17
7 27 34
12 -2 22
4 -50 -12
3 -32 15
8 -7 23
3 -30 11
4 -2 23

Output

311
312
260
286
296
292
327

### Response

```cpp
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	using F=function<T(T,T)>;
	const F calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		const F calcfn_=[](T a,T b){return a<b?a:b;},
		const F updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T lret=defvalue,rret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))lret=calcfn(lret,dat[L]);
			if(!(R&1))rret=calcfn(dat[--R],rret);
		}
		return calcfn(lret,rret);
	}
};
int N,Q;
int A[2<<17],B[2<<17];
int main()
{
	cin>>N>>Q;
	N*=2;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	int bc=0;
	long sum=0;
	vector<int>init(N);
	for(int i=0;i<N;i++)
	{
		if(i==0||i==N-1||A[i]>=B[i])
		{
			sum+=A[i];
			init[i]=A[i]-B[i];
		}
		else
		{
			sum+=B[i];
			init[i]=B[i]-A[i];
			bc++;
		}
	}
	segtree<int>P(N);
	P.copy(init);
	for(;Q--;)
	{
		int p,x,y;cin>>p>>x>>y;p--;
		if(p==0||p==N-1||A[p]>=B[p])
		{
			sum-=A[p];
		}
		else
		{
			sum-=B[p];
			bc--;
		}
		A[p]=x;B[p]=y;
		if(p==0||p==N-1||A[p]>=B[p])
		{
			sum+=A[p];
			P.update(p,A[p]-B[p]);
		}
		else
		{
			sum+=B[p];
			P.update(p,B[p]-A[p]);
			bc++;
		}
		long now=sum;
		if(bc%2)now-=P.query(1,N-1);
		cout<<now<<endl;
	}
}

```


### Prompt

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

VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications.

The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within t_i seconds.

What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm.

Input

The first line of input consists of single integer n — the number of news categories (1 ≤ n ≤ 200 000).

The second line of input consists of n integers a_i — the number of publications of i-th category selected by the batch algorithm (1 ≤ a_i ≤ 10^9).

The third line of input consists of n integers t_i — time it takes for targeted algorithm to find one new publication of category i (1 ≤ t_i ≤ 10^5).

Output

Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.

Examples

Input

5
3 7 9 7 8
5 2 5 7 5

Output

6

Input

5
1 2 3 4 5
1 1 1 1 1

Output

0

Note

In the first example, it is possible to find three publications of the second type, which will take 6 seconds.

In the second example, all news categories contain a different number of publications.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long Z = (long long)3e3 + 228;
const long long N = (long long)2e5 + 228;
const long long INF = (long long)1e9 + 228;
const long long MOD = (long long)998244353;
const long long LLINF = (long long)1e18 + 228;
const long double eps = (long double)1e-6;
long long a[N], b[N], t[N];
map<long long, long long> cnt;
map<long long, multiset<long long> > mp;
set<long long> news;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    news.insert(a[i]);
    cnt[a[i]]++;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> t[i];
    mp[a[i]].insert(t[i]);
  }
  news.insert(LLINF);
  long long ans = 0, cur = -INF;
  while (true) {
    long long it = *news.upper_bound(cur);
    if (it == LLINF) break;
    long long sum = 0;
    multiset<long long> q;
    for (auto& z : mp[it]) {
      if (cnt[it] == 1) break;
      cnt[it]--;
      q.insert(z);
      sum += z;
    }
    long long seen = 0;
    for (long long i = it + 1; q.size() != 0; i++) {
      seen++;
      ans += sum;
      if (mp.find(i) != mp.end()) {
        for (auto& z : mp[i]) {
          q.insert(z);
          sum += z;
        }
      }
      sum -= *--q.end();
      q.erase(--q.end());
    }
    cur = it + seen;
  }
  cout << ans;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

You are given a string S consisting of lowercase English letters. Determine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.

Constraints

* 1 \leq |S| \leq 2 × 10^5
* S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If we cannot turn S into a palindrome, print `-1`. Otherwise, print the minimum required number of operations.

Examples

Input

eel

Output

1

Input

ataatmma

Output

4

Input

snuke

Output

-1

### Response

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

const int mx = 200005;
int memo[26][mx], sz, c[26], pr[mx], bit[mx*2];
long long ans;
bool safe = true;
string s;

int main(){
  cin >> s; sz = s.size();
  for(int i = 0; i < sz; i++){
    int t = s[i]-'a';
    memo[t][c[t]++] = i;
  }
  for(int i = 0; i < 26; i++){
    if(c[i]&1){
      if(safe) safe = false;
      else return puts("-1")*0;
    }
    for(int j = 0; j < c[i]; j++) pr[memo[i][j]] = memo[i][c[i]-1-j];
  }
  for(int i = 0; i < sz; i++){
    for(int j = pr[i]+1; j > 0; j -= j&-j) ans += bit[j];
    for(int j = pr[i]+1; j < mx*2; j += j&-j) bit[j]++;
  }
  printf("%lld\n", ans/2);
}
```


### Prompt

Please create a solution in CPP to the following problem:

Nikita likes tasks on order statistics, for example, he can easily find the k-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number x is the k-th number in increasing order on this segment. In other words, you should find the number of segments of a given array such that there are exactly k numbers of this segment which are less than x.

Nikita wants to get answer for this question for each k from 0 to n, where n is the size of the array.

Input

The first line contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5, -10^9 ≤ x ≤ 10^9).

The second line contains n integers a_1, a_2, …, a_n (-10^9 ≤ a_i ≤ 10^9) — the given array.

Output

Print n+1 integers, where the i-th number is the answer for Nikita's question for k=i-1.

Examples

Input

5 3
1 2 3 4 5

Output

6 5 4 0 0 0

Input

2 6
-5 9

Output

1 2 0

Input

6 99
-1 -1 -1 -1 -1 -1

Output

0 6 5 4 3 2 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using cd = complex<double>;
using vcd = vector<cd>;
const int maxN = 530000;
const double PI = acos(-1);
int rev[maxN];
cd roots[maxN];
void fft(vcd& a) {
  int n = a.size();
  for (int i = 0; i < n; ++i)
    if (i < rev[i]) swap(a[i], a[rev[i]]);
  vcd cur(n);
  for (int len = 1, step = n / 2; len < n; len <<= 1, step >>= 1) {
    for (int st = 0; st < n; st += len + len)
      for (int i = 0, root = 0; i < len; ++i, root += step) {
        cd u = a[st + i], v = roots[root] * a[st + len + i];
        cur[st + i] = u + v;
        cur[st + i + len] = u - v;
      }
    a.swap(cur);
  }
}
void inv(vcd& a) {
  fft(a);
  reverse(a.begin() + 1, a.end());
  for (cd& x : a) x /= a.size();
}
void conv(vcd& a, vcd& b) {
  int n = 1, h = 0;
  while (n < a.size() + b.size()) n *= 2, ++h;
  while (a.size() < n) a.push_back(0);
  while (b.size() < n) b.push_back(0);
  rev[0] = 0;
  --h;
  for (int i = 1, high = -1; i < n; ++i) {
    high += !(i & (i - 1));
    rev[i] = rev[i ^ (1 << high)] | (1 << (h - high));
  }
  double sector = 2. * PI / n, alpha = 0;
  for (int i = 0; i < n; ++i) {
    roots[i] = cd(cos(alpha), sin(alpha));
    alpha += sector;
  }
  fft(a);
  fft(b);
  for (int i = 0; i < n; ++i) a[i] *= b[i];
  inv(a);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  int stn = n;
  vector<int> t(n);
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
    t[i] = (t[i] >= x);
  }
  t.insert(t.begin(), 0);
  vector<int> r;
  for (int i = 0; i < t.size(); ++i) {
    int j = i;
    while (j + 1 < t.size() && t[j + 1] == 1) ++j;
    r.push_back(j - i + 1);
    i = j;
  }
  llong zer = 0;
  for (int i = 0; i < r.size(); ++i) zer += (r[i] * (r[i] - 1LL)) / 2LL;
  vcd a(r.begin(), r.end());
  vcd b(r.rbegin(), r.rend());
  n = r.size();
  conv(a, b);
  cout << zer << ' ';
  for (int i = 1; i <= stn; ++i)
    if (n - 1 + i < a.size())
      cout << llong(a[n - 1 + i].real() + 0.5) << ' ';
    else
      cout << "0 ";
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.

Innokentiy decides that new password should satisfy the following conditions:

  * the length of the password must be equal to n,
  * the password should consist only of lowercase Latin letters,
  * the number of distinct symbols in the password must be equal to k,
  * any two consecutive symbols in the password must be distinct.

Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.

Input

The first line contains two positive integers n and k (2 ≤ n ≤ 100, 2 ≤ k ≤ min(n, 26)) — the length of the password and the number of distinct symbols in it.

Pay attention that a desired new password always exists.

Output

Print any password which satisfies all conditions given by Innokentiy.

Examples

Input

4 3

Output

java

Input

6 6

Output

python

Input

5 2

Output

phphp

Note

In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.

In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.

In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.

Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n, k;
  std::cin >> n;
  char *pass = new char[n];
  std::cin >> k;
  int t = 97;
  for (int i = 0; i < n; ++i) {
    if ((i >= k) && (i + t - k > 96)) {
      t -= k;
    }
    pass[i] = static_cast<char>(i + t);
  }
  for (int i = 0; i < n; ++i) {
    std::cout << pass[i];
  }
  std::cout << '\n';
  delete[] pass;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

My name is James diGriz, I'm the most clever robber and treasure hunter in the whole galaxy. There are books written about my adventures and songs about my operations, though you were able to catch me up in a pretty awkward moment.

I was able to hide from cameras, outsmart all the guards and pass numerous traps, but when I finally reached the treasure box and opened it, I have accidentally started the clockwork bomb! Luckily, I have met such kind of bombs before and I know that the clockwork mechanism can be stopped by connecting contacts with wires on the control panel of the bomb in a certain manner.

I see n contacts connected by n - 1 wires. Contacts are numbered with integers from 1 to n. Bomb has a security mechanism that ensures the following condition: if there exist k ≥ 2 contacts c1, c2, ..., ck forming a circuit, i. e. there exist k distinct wires between contacts c1 and c2, c2 and c3, ..., ck and c1, then the bomb immediately explodes and my story ends here. In particular, if two contacts are connected by more than one wire they form a circuit of length 2. It is also prohibited to connect a contact with itself.

On the other hand, if I disconnect more than one wire (i. e. at some moment there will be no more than n - 2 wires in the scheme) then the other security check fails and the bomb also explodes. So, the only thing I can do is to unplug some wire and plug it into a new place ensuring the fact that no circuits appear.

I know how I should put the wires in order to stop the clockwork. But my time is running out! Help me get out of this alive: find the sequence of operations each of which consists of unplugging some wire and putting it into another place so that the bomb is defused.

Input

The first line of the input contains n (2 ≤ n ≤ 500 000), the number of contacts.

Each of the following n - 1 lines contains two of integers xi and yi (1 ≤ xi, yi ≤ n, xi ≠ yi) denoting the contacts currently connected by the i-th wire.

The remaining n - 1 lines contain the description of the sought scheme in the same format.

It is guaranteed that the starting and the ending schemes are correct (i. e. do not contain cicuits nor wires connecting contact with itself).

Output

The first line should contain k (k ≥ 0) — the minimum number of moves of unplugging and plugging back some wire required to defuse the bomb.

In each of the following k lines output four integers ai, bi, ci, di meaning that on the i-th step it is neccesary to unplug the wire connecting the contacts ai and bi and plug it to the contacts ci and di. Of course the wire connecting contacts ai and bi should be present in the scheme.

If there is no correct sequence transforming the existing scheme into the sought one, output -1.

Examples

Input

3
1 2
2 3
1 3
3 2

Output

1
1 2 1 3

Input

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

Output

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

Note

Picture with the clarification for the sample tests:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int max_n = 555555;
int n, ans, p[max_n], parent[max_n];
vector<int> g[max_n], all;
vector<pair<int, int> > a[max_n];
set<pair<int, int> > q, q2;
void dfs(int v, int pp) {
  p[v] = pp;
  all.push_back(v);
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i] != pp) {
      dfs(g[v][i], v);
    }
  }
}
int find_set(int v) {
  if (v == parent[v]) {
    return v;
  }
  return parent[v] = find_set(parent[v]);
}
void union_set(int v1, int v2) {
  v1 = find_set(v1);
  v2 = find_set(v2);
  if (a[v1].size() < a[v2].size()) {
    swap(v1, v2);
  }
  copy(a[v2].begin(), a[v2].end(), back_inserter(a[v1]));
  parent[v2] = v1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 2; ++i) {
    for (int j = 1; j < n; ++j) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u > v) {
        swap(u, v);
      }
      if (i == 0) {
        q.insert(make_pair(u, v));
        g[u].push_back(v);
        g[v].push_back(u);
      } else {
        q2.insert(make_pair(u, v));
        if (!q.count(make_pair(u, v))) {
          ++ans;
          a[u].push_back(make_pair(u, v));
          a[v].push_back(make_pair(u, v));
        }
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i) {
    parent[i] = i;
  }
  dfs(1, -1);
  q.clear();
  for (int i = all.size() - 1; i > 0; --i) {
    int v1 = all[i];
    int v2 = p[v1];
    if (v1 > v2) {
      swap(v1, v2);
    }
    if (q2.count(make_pair(v1, v2))) {
      union_set(v1, v2);
    } else {
      int v = find_set(all[i]);
      pair<int, int> p;
      while (true) {
        p = a[v].back();
        a[v].pop_back();
        if (p.first > p.second) {
          swap(p.first, p.second);
        }
        if (!q.count(p)) {
          break;
        }
      }
      q.insert(p);
      printf("%d %d %d %d\n", v1, v2, p.first, p.second);
      union_set(p.first, p.second);
    }
  }
  return 0;
}

```


### Prompt

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

Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates <image> that is defined as the maximal number of non-overlapping substrings equal to p that can be found in s'. He wants to make this number as big as possible.

More formally, let's define <image> as maximum value of <image> over all s' that can be obtained by removing exactly x characters from s. Dreamoon wants to know <image> for all x from 0 to |s| where |s| denotes the length of string s.

Input

The first line of the input contains the string s (1 ≤ |s| ≤ 2 000).

The second line of the input contains the string p (1 ≤ |p| ≤ 500).

Both strings will only consist of lower case English letters.

Output

Print |s| + 1 space-separated integers in a single line representing the <image> for all x from 0 to |s|.

Examples

Input

aaaaa
aa

Output

2 2 1 1 0 0

Input

axbaxxb
ab

Output

0 1 1 2 1 1 0 0

Note

For the first sample, the corresponding optimal values of s' after removal 0 through |s| = 5 characters from s are {"aaaaa", "aaaa", "aaa", "aa", "a", ""}.

For the second sample, possible corresponding optimal values of s' are {"axbaxxb", "abaxxb", "axbab", "abab", "aba", "ab", "a", ""}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char str[2010], pattern[2010];
int dp[2010][2010];
int main(void) {
  scanf("%s", str);
  scanf("%s", pattern);
  int len1 = (int)strlen(str);
  int len2 = (int)strlen(pattern);
  for (int i = 1; i <= len1; ++i) {
    int k = len2, j = i;
    while (k > 0 && j > 0) {
      if (pattern[k - 1] == str[j - 1]) k--;
      j--;
    }
    if (k == 0) {
      int del = i - j - len2;
      for (int f = del; f <= i - len2; ++f)
        dp[i][f] = max(dp[i][f], dp[j][f - del] + 1);
    }
    for (int f = 0; f < i; ++f) dp[i][f] = max(dp[i][f], dp[i - 1][f]);
  }
  for (int i = 0; i <= len1; ++i) printf("%d ", dp[len1][i]);
  return 0;
}

```


### Prompt

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

There are n points on a plane. The i-th point has coordinates (x_i, y_i). You have two horizontal platforms, both of length k. Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same y-coordinate) and have integer borders. If the left border of the platform is (x, y) then the right border is (x + k, y) and all points between borders (including borders) belong to the platform.

Note that platforms can share common points (overlap) and it is not necessary to place both platforms on the same y-coordinate.

When you place both platforms on a plane, all points start falling down decreasing their y-coordinate. If a point collides with some platform at some moment, the point stops and is saved. Points which never collide with any platform are lost.

Your task is to find the maximum number of points you can save if you place both platforms optimally.

You have to answer t independent test cases.

For better understanding, please read the Note section below to see a picture for the first test case.

Input

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

The first line of the test case contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 10^9) — the number of points and the length of each platform, respectively. The second line of the test case contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is x-coordinate of the i-th point. The third line of the input contains n integers y_1, y_2, ..., y_n (1 ≤ y_i ≤ 10^9), where y_i is y-coordinate of the i-th point. All points are distinct (there is no pair 1 ≤ i < j ≤ n such that x_i = x_j and y_i = y_j).

It is guaranteed that the sum of n does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer: the maximum number of points you can save if you place both platforms optimally.

Example

Input

4
7 1
1 5 2 3 1 5 4
1 3 6 7 2 5 4
1 1
1000000000
1000000000
5 10
10 7 5 15 8
20 199 192 219 1904
10 10
15 19 8 17 20 10 9 2 10 19
12 13 6 17 1 14 7 9 19 3

Output

6
1
5
10

Note

The picture corresponding to the first test case of the example:

<image>

Blue dots represent the points, red segments represent the platforms. One of the possible ways is to place the first platform between points (1, -1) and (2, -1) and the second one between points (4, 3) and (5, 3). Vectors represent how the points will fall down. As you can see, the only point we can't save is the point (3, 7) so it falls down infinitely and will be lost. It can be proven that we can't achieve better answer here. Also note that the point (5, 3) doesn't fall at all because it is already on the platform.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int t, n, k;
int x[200005];
int y[200005];
int count1[200005];
int max1[200005];
int main() {
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n >> k;
    for (int j = 1; j <= n; j++) {
      cin >> x[j];
    }
    for (int j = 1; j <= n; j++) {
      cin >> y[i];
    }
    sort(x + 1, x + n + 1);
    for (int j = 1; j <= n; j++) {
      count1[j] = upper_bound(x + 1, x + n + 1, x[j] + k) - (x + j);
    }
    for (int j = 1; j <= n; j++) {
      max1[j] = max(max1[j - 1], count1[j]);
    }
    int max2 = 0;
    for (int j = 1; j <= n; j++) {
      int temp = upper_bound(x + 1, x + n + 1, x[j] - k - 1) - (x + 1);
      max2 = max(max2, max1[temp] + count1[j]);
    }
    cout << max2 << endl;
  }
}

```


### Prompt

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

Today Pari and Arya are playing a game called Remainders.

Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x?

Note, that <image> means the remainder of x after dividing it by y.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000).

Output

Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise.

Examples

Input

4 5
2 3 5 12

Output

Yes

Input

2 7
2 3

Output

No

Note

In the first sample, Arya can understand <image> because 5 is one of the ancient numbers.

In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long int n, k;
  scanf("%lld %lld\n", &n, &k);
  long long int value = 1;
  long long int curr;
  for (long long int i = 0; i < n; i++) {
    scanf("%lld", &curr);
    value = gcd(k, value * curr / gcd(value, curr));
  }
  if (value == k) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:

  1. The product of all numbers in the first set is less than zero ( < 0).
  2. The product of all numbers in the second set is greater than zero ( > 0).
  3. The product of all numbers in the third set is equal to zero.
  4. Each number from the initial array must occur in exactly one set.

Help Vitaly. Divide the given array.

Input

The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements.

Output

In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set.

In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set.

In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set.

The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.

Examples

Input

3
-1 2 0

Output

1 -1
1 2
1 0

Input

4
-1 -2 -3 0

Output

1 -1
2 -3 -2
1 0

### Response

```cpp
#include <bits/stdc++.h>
int n, i, z = 0, x = 0, c = 0, a, s[10001], t[10001], r[10001];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (a > 0) {
      z++;
      s[z] = a;
    } else if (a == 0) {
      x++;
      t[x] = a;
    } else {
      c++;
      r[c] = a;
    }
  }
  if (c % 2 == 0) {
    x++;
    t[x] = r[c];
    c--;
  }
  if (z == 0) {
    z = 2;
    s[1] = r[c];
    s[2] = r[c - 1];
    c = c - 2;
  }
  printf("%d ", c);
  for (i = 1; i <= c; i++) printf("%d ", r[i]);
  printf("\n");
  printf("%d ", z);
  for (i = 1; i <= z; i++) printf("%d ", s[i]);
  printf("\n");
  printf("%d ", x);
  for (i = 1; i <= x; i++) printf("%d ", t[i]);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room — five windows, and a seven-room — seven windows.

Monocarp went around the building and counted n windows. Now he is wondering, how many apartments of each type the building may have.

Unfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has n windows. If there are multiple answers, you can print any of them.

Here are some examples:

  * if Monocarp has counted 30 windows, there could have been 2 three-room apartments, 2 five-room apartments and 2 seven-room apartments, since 2 ⋅ 3 + 2 ⋅ 5 + 2 ⋅ 7 = 30;
  * if Monocarp has counted 67 windows, there could have been 7 three-room apartments, 5 five-room apartments and 3 seven-room apartments, since 7 ⋅ 3 + 5 ⋅ 5 + 3 ⋅ 7 = 67;
  * if Monocarp has counted 4 windows, he should have mistaken since no building with the aforementioned layout can have 4 windows.

Input

Th first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.

The only line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of windows in the building.

Output

For each test case, if a building with the new layout and the given number of windows just can't exist, print -1.

Otherwise, print three non-negative integers — the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.

Example

Input

4
30
67
4
14

Output

2 2 2
7 5 3
-1
0 0 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void count(int n) {
  for (int a = 0; a * 3 <= n; a++) {
    for (int b = 0; a * 3 + b * 5 <= n; b++) {
      for (int c = 0; a * 3 + b * 5 + c * 7 <= n; c++) {
        if (a * 3 + b * 5 + c * 7 == n) {
          cout << a << ' ' << b << ' ' << c << endl;
          return;
        }
      }
    }
  }
  cout << -1 << endl;
}
int main() {
  int t, n;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    count(n);
  }
}

```


### Prompt

Generate a CPP solution to the following problem:

A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:

x2 + 2bx + c = 0 where b, c are natural numbers.

Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.

Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 ≤ b ≤ n, 1 ≤ c ≤ m. Help Petya find that number.

Input

The single line contains two integers n and m. (1 ≤ n, m ≤ 5000000).

Output

Print a single number which is the number of real roots of the described set of equations.

Examples

Input

3 3

Output

12

Input

1 2

Output

1

Note

In the second test from the statement the following equations are analysed:

b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1

b = 1, c = 2: x2 + 2x + 2 = 0; No roots

Overall there's one root

In the second test the following equations are analysed:

b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1

b = 1, c = 2: x2 + 2x + 2 = 0; No roots

b = 1, c = 3: x2 + 2x + 3 = 0; No roots

b = 2, c = 1: x2 + 4x + 1 = 0; The roots are <image>

b = 2, c = 2: x2 + 4x + 2 = 0; The roots are <image>

b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 = - 3, x2 = - 1

b = 3, c = 1: x2 + 6x + 1 = 0; The roots are <image>

b = 3, c = 2: x2 + 6x + 2 = 0; The roots are <image>

b = 3, c = 3: x2 + 6x + 3 = 0; The roots are <image> Overall there are 13 roots and as the root  - 1 is repeated twice, that means there are 12 different roots.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int mark[5000000 * 4], n, m;
long long num(long long x) {
  long long g = (int)sqrt(x * 1.0);
  while (((g) * (g)) <= x) g++;
  while (((g) * (g)) > x) g--;
  return g;
}
int main() {
  scanf("%d%d", &n, &m);
  long long ans = 0;
  for (int b = 1; b <= n; b++) {
    long long max_c = min((long long)m, (((long long)b) * ((long long)b)));
    ans += max_c * 2;
    long long x = (((long long)b) * ((long long)b)) - max_c,
              y = (((long long)b) * ((long long)b)) - 1;
    long long l = num(x), r = num(y);
    if (((l) * (l)) < x) l++;
    ans -= (r - l + 1) * 2;
    mark[-b - r + n * 3]++;
    mark[-b - l + 1 + n * 3]--;
    mark[-b + l + n * 3]++;
    mark[-b + r + 1 + n * 3]--;
  }
  for (int i = 0, k = 0; i < n * 4; i++) {
    k += mark[i];
    if (k) ans++;
  }
  printf("%I64d\n", ans);
}

```


### Prompt

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

Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place:

  * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars.
  * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.

Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally.

Input

The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000).

Output

Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.

Examples

Input

7
win 10
win 5
win 3
sell 5
sell 3
win 10
sell 10

Output

1056

Input

3
win 5
sell 6
sell 4

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef int bignum_t[10000 + 1];
int read(bignum_t a, istream& is = cin) {
  char buf[10000 * 4 + 1], ch;
  int i, j;
  memset((void*)a, 0, sizeof(bignum_t));
  if (!(is >> buf)) return 0;
  for (a[0] = strlen(buf), i = a[0] / 2 - 1; i >= 0; i--)
    ch = buf[i], buf[i] = buf[a[0] - 1 - i], buf[a[0] - 1 - i] = ch;
  for (a[0] = (a[0] + 4 - 1) / 4, j = strlen(buf); j < a[0] * 4; buf[j++] = '0')
    ;
  for (i = 1; i <= a[0]; i++)
    for (a[i] = 0, j = 0; j < 4; j++)
      a[i] = a[i] * 10 + buf[i * 4 - 1 - j] - '0';
  for (; !a[a[0]] && a[0] > 1; a[0]--)
    ;
  return 1;
}
void write(const bignum_t a, ostream& os = cout) {
  int i, j;
  for (os << a[i = a[0]], i--; i; i--)
    for (j = 10000 / 10; j; j /= 10) os << a[i] / j % 10;
}
int comp(const bignum_t a, const bignum_t b) {
  int i;
  if (a[0] != b[0]) return a[0] - b[0];
  for (i = a[0]; i; i--)
    if (a[i] != b[i]) return a[i] - b[i];
  return 0;
}
int comp(const bignum_t a, const int b) {
  int c[12] = {1};
  for (c[1] = b; c[c[0]] >= 10000;
       c[c[0] + 1] = c[c[0]] / 10000, c[c[0]] %= 10000, c[0]++)
    ;
  return comp(a, c);
}
int comp(const bignum_t a, const int c, const int d, const bignum_t b) {
  int i, t = 0, O = -10000 * 2;
  if (b[0] - a[0] < d && c) return 1;
  for (i = b[0]; i > d; i--) {
    t = t * 10000 + a[i - d] * c - b[i];
    if (t > 0) return 1;
    if (t < O) return 0;
  }
  for (i = d; i; i--) {
    t = t * 10000 - b[i];
    if (t > 0) return 1;
    if (t < O) return 0;
  }
  return t > 0;
}
void add(bignum_t a, const bignum_t b) {
  int i;
  for (i = 1; i <= b[0]; i++)
    if ((a[i] += b[i]) >= 10000) a[i] -= 10000, a[i + 1]++;
  if (b[0] >= a[0])
    a[0] = b[0];
  else
    for (; a[i] >= 10000 && i < a[0]; a[i] -= 10000, i++, a[i]++)
      ;
  a[0] += (a[a[0] + 1] > 0);
}
void add(bignum_t a, const int b) {
  int i = 1;
  for (a[1] += b; a[i] >= 10000 && i < a[0];
       a[i + 1] += a[i] / 10000, a[i] %= 10000, i++)
    ;
  for (; a[a[0]] >= 10000;
       a[a[0] + 1] = a[a[0]] / 10000, a[a[0]] %= 10000, a[0]++)
    ;
}
void sub(bignum_t a, const bignum_t b) {
  int i;
  for (i = 1; i <= b[0]; i++)
    if ((a[i] -= b[i]) < 0) a[i + 1]--, a[i] += 10000;
  for (; a[i] < 0; a[i] += 10000, i++, a[i]--)
    ;
  for (; !a[a[0]] && a[0] > 1; a[0]--)
    ;
}
void sub(bignum_t a, const int b) {
  int i = 1;
  for (a[1] -= b; a[i] < 0; a[i + 1] += (a[i] - 10000 + 1) / 10000,
                            a[i] -= (a[i] - 10000 + 1) / 10000 * 10000, i++)
    ;
  for (; !a[a[0]] && a[0] > 1; a[0]--)
    ;
}
void sub(bignum_t a, const bignum_t b, const int c, const int d) {
  int i, O = b[0] + d;
  for (i = 1 + d; i <= O; i++)
    if ((a[i] -= b[i - d] * c) < 0)
      a[i + 1] += (a[i] - 10000 + 1) / 10000,
          a[i] -= (a[i] - 10000 + 1) / 10000 * 10000;
  for (; a[i] < 0; a[i + 1] += (a[i] - 10000 + 1) / 10000,
                   a[i] -= (a[i] - 10000 + 1) / 10000 * 10000, i++)
    ;
  for (; !a[a[0]] && a[0] > 1; a[0]--)
    ;
}
void mul(bignum_t c, const bignum_t a, const bignum_t b) {
  int i, j;
  memset((void*)c, 0, sizeof(bignum_t));
  for (c[0] = a[0] + b[0] - 1, i = 1; i <= a[0]; i++)
    for (j = 1; j <= b[0]; j++)
      if ((c[i + j - 1] += a[i] * b[j]) >= 10000)
        c[i + j] += c[i + j - 1] / 10000, c[i + j - 1] %= 10000;
  for (c[0] += (c[c[0] + 1] > 0); !c[c[0]] && c[0] > 1; c[0]--)
    ;
}
void mul(bignum_t a, const int b) {
  int i;
  for (a[1] *= b, i = 2; i <= a[0]; i++) {
    a[i] *= b;
    if (a[i - 1] >= 10000) a[i] += a[i - 1] / 10000, a[i - 1] %= 10000;
  }
  for (; a[a[0]] >= 10000;
       a[a[0] + 1] = a[a[0]] / 10000, a[a[0]] %= 10000, a[0]++)
    ;
  for (; !a[a[0]] && a[0] > 1; a[0]--)
    ;
}
void mul(bignum_t b, const bignum_t a, const int c, const int d) {
  int i;
  memset((void*)b, 0, sizeof(bignum_t));
  for (b[0] = a[0] + d, i = d + 1; i <= b[0]; i++)
    if ((b[i] += a[i - d] * c) >= 10000)
      b[i + 1] += b[i] / 10000, b[i] %= 10000;
  for (; b[b[0] + 1]; b[0]++, b[b[0] + 1] = b[b[0]] / 10000, b[b[0]] %= 10000)
    ;
  for (; !b[b[0]] && b[0] > 1; b[0]--)
    ;
}
void div(bignum_t c, bignum_t a, const bignum_t b) {
  int h, l, m, i;
  memset((void*)c, 0, sizeof(bignum_t));
  c[0] = (b[0] < a[0] + 1) ? (a[0] - b[0] + 2) : 1;
  for (i = c[0]; i; sub(a, b, c[i] = m, i - 1), i--)
    for (h = 10000 - 1, l = 0, m = (h + l + 1) >> 1; h > l;
         m = (h + l + 1) >> 1)
      if (comp(b, m, i - 1, a))
        h = m - 1;
      else
        l = m;
  for (; !c[c[0]] && c[0] > 1; c[0]--)
    ;
  c[0] = c[0] > 1 ? c[0] : 1;
}
void div(bignum_t a, const int b, int& c) {
  int i;
  for (c = 0, i = a[0]; i; c = c * 10000 + a[i], a[i] = c / b, c %= b, i--)
    ;
  for (; !a[a[0]] && a[0] > 1; a[0]--)
    ;
}
void sqrt(bignum_t b, bignum_t a) {
  int h, l, m, i;
  memset((void*)b, 0, sizeof(bignum_t));
  for (i = b[0] = (a[0] + 1) >> 1; i; sub(a, b, m, i - 1), b[i] += m, i--)
    for (h = 10000 - 1, l = 0, b[i] = m = (h + l + 1) >> 1; h > l;
         b[i] = m = (h + l + 1) >> 1)
      if (comp(b, m, i - 1, a))
        h = m - 1;
      else
        l = m;
  for (; !b[b[0]] && b[0] > 1; b[0]--)
    ;
  for (i = 1; i <= b[0]; b[i++] >>= 1)
    ;
}
int length(const bignum_t a) {
  int t, ret;
  for (ret = (a[0] - 1) * 4, t = a[a[0]]; t; t /= 10, ret++)
    ;
  return ret > 0 ? ret : 1;
}
int digit(const bignum_t a, const int b) {
  int i, ret;
  for (ret = a[(b - 1) / 4 + 1], i = (b - 1) % 4; i; ret /= 10, i--)
    ;
  return ret % 10;
}
int zeronum(const bignum_t a) {
  int ret, t;
  for (ret = 0; !a[ret + 1]; ret++)
    ;
  for (t = a[ret + 1], ret *= 4; !(t % 10); t /= 10, ret++)
    ;
  return ret;
}
void comp(int* a, const int l, const int h, const int d) {
  int i, j, t;
  for (i = l; i <= h; i++)
    for (t = i, j = 2; t > 1; j++)
      while (!(t % j)) a[j] += d, t /= j;
}
void convert(int* a, const int h, bignum_t b) {
  int i, j, t = 1;
  memset(b, 0, sizeof(bignum_t));
  for (b[0] = b[1] = 1, i = 2; i <= h; i++)
    if (a[i])
      for (j = a[i]; j; t *= i, j--)
        if (t * i > 10000) mul(b, t), t = 1;
  mul(b, t);
}
void combination(bignum_t a, int m, int n) {
  int* t = new int[m + 1];
  memset((void*)t, 0, sizeof(int) * (m + 1));
  comp(t, n + 1, m, 1);
  comp(t, 2, m - n, -1);
  convert(t, m, a);
  delete[] t;
}
void permutation(bignum_t a, int m, int n) {
  int i, t = 1;
  memset(a, 0, sizeof(bignum_t));
  a[0] = a[1] = 1;
  for (i = m - n + 1; i <= m; t *= i++)
    if (t * i > 10000) mul(a, t), t = 1;
  mul(a, t);
}
int read(bignum_t a, int& sgn, istream& is = cin) {
  char str[10000 * 4 + 2], ch, *buf;
  int i, j;
  memset((void*)a, 0, sizeof(bignum_t));
  if (!(is >> str)) return 0;
  buf = str, sgn = 1;
  if (*buf == '-') sgn = -1, buf++;
  for (a[0] = strlen(buf), i = a[0] / 2 - 1; i >= 0; i--)
    ch = buf[i], buf[i] = buf[a[0] - 1 - i], buf[a[0] - 1 - i] = ch;
  for (a[0] = (a[0] + 4 - 1) / 4, j = strlen(buf); j < a[0] * 4; buf[j++] = '0')
    ;
  for (i = 1; i <= a[0]; i++)
    for (a[i] = 0, j = 0; j < 4; j++)
      a[i] = a[i] * 10 + buf[i * 4 - 1 - j] - '0';
  for (; !a[a[0]] && a[0] > 1; a[0]--)
    ;
  if (a[0] == 1 && !a[1]) sgn = 0;
  return 1;
}
struct bignum {
  bignum_t num;
  int sgn;

 public:
  inline bignum() {
    memset(num, 0, sizeof(bignum_t));
    num[0] = 1;
    sgn = 0;
  }
  inline int operator!() { return num[0] == 1 && !num[1]; }
  inline bignum& operator=(const bignum& a) {
    memcpy(num, a.num, sizeof(bignum_t));
    sgn = a.sgn;
    return *this;
  }
  inline bignum& operator=(const int a) {
    memset(num, 0, sizeof(bignum_t));
    num[0] = 1;
    sgn = ((a) > 0 ? 1 : ((a) < 0 ? -1 : 0));
    add(num, sgn * a);
    return *this;
  };
  inline bignum& operator+=(const bignum& a) {
    if (sgn == a.sgn)
      add(num, a.num);
    else if (sgn && a.sgn) {
      int ret = comp(num, a.num);
      if (ret > 0)
        sub(num, a.num);
      else if (ret < 0) {
        bignum_t t;
        memcpy(t, num, sizeof(bignum_t));
        memcpy(num, a.num, sizeof(bignum_t));
        sub(num, t);
        sgn = a.sgn;
      } else
        memset(num, 0, sizeof(bignum_t)), num[0] = 1, sgn = 0;
    } else if (!sgn)
      memcpy(num, a.num, sizeof(bignum_t)), sgn = a.sgn;
    return *this;
  }
  inline bignum& operator+=(const int a) {
    if (sgn * a > 0)
      add(num, ((a) > 0 ? (a) : -(a)));
    else if (sgn && a) {
      int ret = comp(num, ((a) > 0 ? (a) : -(a)));
      if (ret > 0)
        sub(num, ((a) > 0 ? (a) : -(a)));
      else if (ret < 0) {
        bignum_t t;
        memcpy(t, num, sizeof(bignum_t));
        memset(num, 0, sizeof(bignum_t));
        num[0] = 1;
        add(num, ((a) > 0 ? (a) : -(a)));
        sgn = -sgn;
        sub(num, t);
      } else
        memset(num, 0, sizeof(bignum_t)), num[0] = 1, sgn = 0;
    } else if (!sgn)
      sgn = ((a) > 0 ? 1 : ((a) < 0 ? -1 : 0)),
      add(num, ((a) > 0 ? (a) : -(a)));
    return *this;
  }
  inline bignum operator+(const bignum& a) {
    bignum ret;
    memcpy(ret.num, num, sizeof(bignum_t));
    ret.sgn = sgn;
    ret += a;
    return ret;
  }
  inline bignum operator+(const int a) {
    bignum ret;
    memcpy(ret.num, num, sizeof(bignum_t));
    ret.sgn = sgn;
    ret += a;
    return ret;
  }
  inline bignum& operator-=(const bignum& a) {
    if (sgn * a.sgn < 0)
      add(num, a.num);
    else if (sgn && a.sgn) {
      int ret = comp(num, a.num);
      if (ret > 0)
        sub(num, a.num);
      else if (ret < 0) {
        bignum_t t;
        memcpy(t, num, sizeof(bignum_t));
        memcpy(num, a.num, sizeof(bignum_t));
        sub(num, t);
        sgn = -sgn;
      } else
        memset(num, 0, sizeof(bignum_t)), num[0] = 1, sgn = 0;
    } else if (!sgn)
      add(num, a.num), sgn = -a.sgn;
    return *this;
  }
  inline bignum& operator-=(const int a) {
    if (sgn * a < 0)
      add(num, ((a) > 0 ? (a) : -(a)));
    else if (sgn && a) {
      int ret = comp(num, ((a) > 0 ? (a) : -(a)));
      if (ret > 0)
        sub(num, ((a) > 0 ? (a) : -(a)));
      else if (ret < 0) {
        bignum_t t;
        memcpy(t, num, sizeof(bignum_t));
        memset(num, 0, sizeof(bignum_t));
        num[0] = 1;
        add(num, ((a) > 0 ? (a) : -(a)));
        sub(num, t);
        sgn = -sgn;
      } else
        memset(num, 0, sizeof(bignum_t)), num[0] = 1, sgn = 0;
    } else if (!sgn)
      sgn = -((a) > 0 ? 1 : ((a) < 0 ? -1 : 0)),
      add(num, ((a) > 0 ? (a) : -(a)));
    return *this;
  }
  inline bignum operator-(const bignum& a) {
    bignum ret;
    memcpy(ret.num, num, sizeof(bignum_t));
    ret.sgn = sgn;
    ret -= a;
    return ret;
  }
  inline bignum operator-(const int a) {
    bignum ret;
    memcpy(ret.num, num, sizeof(bignum_t));
    ret.sgn = sgn;
    ret -= a;
    return ret;
  }
  inline bignum& operator*=(const bignum& a) {
    bignum_t t;
    mul(t, num, a.num);
    memcpy(num, t, sizeof(bignum_t));
    sgn *= a.sgn;
    return *this;
  }
  inline bignum& operator*=(const int a) {
    mul(num, ((a) > 0 ? (a) : -(a)));
    sgn *= ((a) > 0 ? 1 : ((a) < 0 ? -1 : 0));
    return *this;
  }
  inline bignum operator*(const bignum& a) {
    bignum ret;
    mul(ret.num, num, a.num);
    ret.sgn = sgn * a.sgn;
    return ret;
  }
  inline bignum operator*(const int a) {
    bignum ret;
    memcpy(ret.num, num, sizeof(bignum_t));
    mul(ret.num, ((a) > 0 ? (a) : -(a)));
    ret.sgn = sgn * ((a) > 0 ? 1 : ((a) < 0 ? -1 : 0));
    return ret;
  }
  inline bignum& operator/=(const bignum& a) {
    bignum_t t;
    div(t, num, a.num);
    memcpy(num, t, sizeof(bignum_t));
    sgn = (num[0] == 1 && !num[1]) ? 0 : sgn * a.sgn;
    return *this;
  }
  inline bignum& operator/=(const int a) {
    int t;
    div(num, ((a) > 0 ? (a) : -(a)), t);
    sgn =
        (num[0] == 1 && !num[1]) ? 0 : sgn * ((a) > 0 ? 1 : ((a) < 0 ? -1 : 0));
    return *this;
  }
  inline bignum operator/(const bignum& a) {
    bignum ret;
    bignum_t t;
    memcpy(t, num, sizeof(bignum_t));
    div(ret.num, t, a.num);
    ret.sgn = (ret.num[0] == 1 && !ret.num[1]) ? 0 : sgn * a.sgn;
    return ret;
  }
  inline bignum operator/(const int a) {
    bignum ret;
    int t;
    memcpy(ret.num, num, sizeof(bignum_t));
    div(ret.num, ((a) > 0 ? (a) : -(a)), t);
    ret.sgn = (ret.num[0] == 1 && !ret.num[1])
                  ? 0
                  : sgn * ((a) > 0 ? 1 : ((a) < 0 ? -1 : 0));
    return ret;
  }
  inline bignum& operator%=(const bignum& a) {
    bignum_t t;
    div(t, num, a.num);
    if (num[0] == 1 && !num[1]) sgn = 0;
    return *this;
  }
  inline int operator%=(const int a) {
    int t;
    div(num, ((a) > 0 ? (a) : -(a)), t);
    memset(num, 0, sizeof(bignum_t));
    num[0] = 1;
    add(num, t);
    return t;
  }
  inline bignum operator%(const bignum& a) {
    bignum ret;
    bignum_t t;
    memcpy(ret.num, num, sizeof(bignum_t));
    div(t, ret.num, a.num);
    ret.sgn = (ret.num[0] == 1 && !ret.num[1]) ? 0 : sgn;
    return ret;
  }
  inline int operator%(const int a) {
    bignum ret;
    int t;
    memcpy(ret.num, num, sizeof(bignum_t));
    div(ret.num, ((a) > 0 ? (a) : -(a)), t);
    memset(ret.num, 0, sizeof(bignum_t));
    ret.num[0] = 1;
    add(ret.num, t);
    return t;
  }
  inline bignum& operator++() {
    *this += 1;
    return *this;
  }
  inline bignum& operator--() {
    *this -= 1;
    return *this;
  };
  inline int operator>(const bignum& a) {
    return sgn > 0
               ? (a.sgn > 0 ? comp(num, a.num) > 0 : 1)
               : (sgn < 0 ? (a.sgn < 0 ? comp(num, a.num) < 0 : 0) : a.sgn < 0);
  }
  inline int operator>(const int a) {
    return sgn > 0 ? (a > 0 ? comp(num, a) > 0 : 1)
                   : (sgn < 0 ? (a < 0 ? comp(num, -a) < 0 : 0) : a < 0);
  }
  inline int operator>=(const bignum& a) {
    return sgn > 0 ? (a.sgn > 0 ? comp(num, a.num) >= 0 : 1)
                   : (sgn < 0 ? (a.sgn < 0 ? comp(num, a.num) <= 0 : 0)
                              : a.sgn <= 0);
  }
  inline int operator>=(const int a) {
    return sgn > 0 ? (a > 0 ? comp(num, a) >= 0 : 1)
                   : (sgn < 0 ? (a < 0 ? comp(num, -a) <= 0 : 0) : a <= 0);
  }
  inline int operator<(const bignum& a) {
    return sgn < 0
               ? (a.sgn < 0 ? comp(num, a.num) > 0 : 1)
               : (sgn > 0 ? (a.sgn > 0 ? comp(num, a.num) < 0 : 0) : a.sgn > 0);
  }
  inline int operator<(const int a) {
    return sgn < 0 ? (a < 0 ? comp(num, -a) > 0 : 1)
                   : (sgn > 0 ? (a > 0 ? comp(num, a) < 0 : 0) : a > 0);
  }
  inline int operator<=(const bignum& a) {
    return sgn < 0 ? (a.sgn < 0 ? comp(num, a.num) >= 0 : 1)
                   : (sgn > 0 ? (a.sgn > 0 ? comp(num, a.num) <= 0 : 0)
                              : a.sgn >= 0);
  }
  inline int operator<=(const int a) {
    return sgn < 0 ? (a < 0 ? comp(num, -a) >= 0 : 1)
                   : (sgn > 0 ? (a > 0 ? comp(num, a) <= 0 : 0) : a >= 0);
  }
  inline int operator==(const bignum& a) {
    return (sgn == a.sgn) ? !comp(num, a.num) : 0;
  }
  inline int operator==(const int a) {
    return (sgn * a >= 0) ? !comp(num, ((a) > 0 ? (a) : -(a))) : 0;
  }
  inline int operator!=(const bignum& a) {
    return (sgn == a.sgn) ? comp(num, a.num) : 1;
  }
  inline int operator!=(const int a) {
    return (sgn * a >= 0) ? comp(num, ((a) > 0 ? (a) : -(a))) : 1;
  }
  inline int operator[](const int a) { return digit(num, a); }
  friend inline istream& operator>>(istream& is, bignum& a) {
    read(a.num, a.sgn, is);
    return is;
  }
  friend inline ostream& operator<<(ostream& os, const bignum& a) {
    if (a.sgn < 0) os << '-';
    write(a.num, os);
    return os;
  }
  friend inline bignum sqrt(const bignum& a) {
    bignum ret;
    bignum_t t;
    memcpy(t, a.num, sizeof(bignum_t));
    sqrt(ret.num, t);
    ret.sgn = ret.num[0] != 1 || ret.num[1];
    return ret;
  }
  friend inline bignum sqrt(const bignum& a, bignum& b) {
    bignum ret;
    memcpy(b.num, a.num, sizeof(bignum_t));
    sqrt(ret.num, b.num);
    ret.sgn = ret.num[0] != 1 || ret.num[1];
    b.sgn = b.num[0] != 1 || ret.num[1];
    return ret;
  }
  inline int length() { return ::length(num); }
  inline int zeronum() { return ::zeronum(num); }
  inline bignum C(const int m, const int n) {
    combination(num, m, n);
    sgn = 1;
    return *this;
  }
  inline bignum P(const int m, const int n) {
    permutation(num, m, n);
    sgn = 1;
    return *this;
  }
};
int a[5002], b[5002], ans[5002], n;
int sum[5002 << 2], setv[5002 << 2];
void Up(int rt, int ls, int rs) { sum[rt] = sum[ls] + sum[rs]; }
void Down(int rt, int ls, int rs, int m) {
  if (~setv[rt]) {
    sum[ls] = m - (m >> 1), sum[rs] = m >> 1;
    setv[ls] = setv[rs] = 1;
    setv[rt] = -1;
  }
}
void build(int l, int r, int rt) {
  sum[rt] = 0;
  setv[rt] = -1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
}
void update(int L, int R, int l, int r, int rt) {
  if (L == l && R == r) {
    setv[rt] = 1;
    sum[rt] = r - l + 1;
    return;
  }
  int mid = (l + r) >> 1;
  Down(rt, rt << 1, rt << 1 | 1, r - l + 1);
  if (L > mid)
    update(L, R, mid + 1, r, rt << 1 | 1);
  else if (R <= mid)
    update(L, R, l, mid, rt << 1);
  else {
    update(L, mid, l, mid, rt << 1);
    update(mid + 1, R, mid + 1, r, rt << 1 | 1);
  }
  Up(rt, rt << 1, rt << 1 | 1);
}
int query(int L, int R, int l, int r, int rt) {
  if (L == l && R == r) return sum[rt];
  int mid = (l + r) >> 1;
  Down(rt, rt << 1, rt << 1 | 1, r - l + 1);
  if (L > mid)
    return query(L, R, mid + 1, r, rt << 1 | 1);
  else if (R <= mid)
    return query(L, R, l, mid, rt << 1);
  else
    return query(L, mid, l, mid, rt << 1) +
           query(mid + 1, R, mid + 1, r, rt << 1 | 1);
}
void solve() {
  char s[10];
  int u;
  memset(a, -1, sizeof(a));
  memset(b, -1, sizeof(b));
  memset(ans, 0, sizeof(ans));
  build(1, n, 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%d", s, &u);
    if (*s == 'w') {
      if (~b[u])
        continue;
      else
        a[u] = i;
    } else
      b[u] = i;
  }
  for (int i = 2000; i >= 0; --i) {
    if (~a[i] && ~b[i] && a[i] < b[i]) {
      if (0 == query(a[i], b[i], 1, n, 1)) {
        update(a[i], b[i], 1, n, 1);
        ans[i] = true;
      }
    }
  }
  bignum x;
  for (int i = 2000; i >= 0; --i) {
    x = x * 2;
    if (ans[i]) x = x + 1;
  }
  cout << x << endl;
}
int main() {
  while (1 == scanf("%d", &n)) {
    solve();
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

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

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

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

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

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

Input

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

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

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

Output

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

Examples

Input

3 1 8 10
10 8
5 7
11 9
3

Output

10

Input

2 2 10 18
10 4
20 6
5 3

Output

20

Note

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k, s, t;
int g[200005], c[200005], v[200005], l[200005];
int suml[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> k >> s >> t;
  for (int i = 1; i <= n; i++) {
    cin >> c[i] >> v[i];
  }
  for (int i = 1; i <= k; i++) {
    cin >> g[i];
  }
  k++;
  sort(g + 1, g + k);
  g[k] = s;
  for (int i = 1; i <= k; i++) {
    l[i] = g[i] - g[i - 1];
  }
  sort(l + 1, l + k + 1);
  for (int i = 1; i <= k; i++) {
    suml[i] = suml[i - 1] + l[i];
  }
  int mc = 1999999999;
  for (int i = 1; i <= n; i++) {
    int c = ::c[i];
    int v = ::v[i];
    if (v < l[k]) {
      continue;
    }
    int split = upper_bound(l + 1, l + k + 1, v / 2) - l;
    int t_fast = suml[split - 1];
    long long t_eco =
        3ll * (suml[k] - suml[split - 1]) - v * 1ll * (k - split + 1);
    if (t_fast + t_eco <= t) {
      mc = min(mc, c);
    }
  }
  if (mc == 1999999999) {
    mc = -1;
  }
  cout << mc;
}

```


### Prompt

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

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

<image>

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

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

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

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

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

Input

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

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

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

Output

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

Examples

Input

6 2
ioi
1 3

Output

26

Input

5 2
ioi
1 2

Output

0

Note

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

Here |x| denotes the length of string x.

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
char str[2000100];
int pos[2000100], cnt[2000100];
int p[2000100], q[2000100];
int main() {
  int n, k;
  cin >> n >> k;
  scanf("%s", str + 1);
  int len = strlen(str + 1);
  for (int i = 1; i <= len; i++)
    p[i] = (p[i - 1] * 29LL + str[i] - 'a' + 1) % 1000000007;
  long long pp = 1;
  for (int i = len; i; i--) {
    int l = len - i + 1;
    q[l] = (q[l - 1] + pp * (str[i] - 'a' + 1)) % 1000000007;
    pp = pp * 29 % 1000000007;
  }
  for (int i = 0; i < k; i++) gn(pos[i]), cnt[pos[i]]++, cnt[pos[i] + len]--;
  for (int i = 0; i < k - 1; i++) {
    int l = pos[i] + len - pos[i + 1];
    if (l <= 0) continue;
    if (p[l] != q[l]) {
      puts("0");
      return 0;
    }
  }
  int nn = 0;
  for (int i = 1; i <= n; i++) {
    cnt[i] += cnt[i - 1];
    if (cnt[i] == 0) nn++;
  }
  printf("%d\n", power(26, nn, 1000000007));
  return 0;
}

```