### Prompt

Develop a solution in cpp to the problem described below:

This problem is different with hard version only by constraints on total answers length

It is an interactive problem

Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask two types of queries:

  * ? l r – ask to list all substrings of s[l..r]. Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled.
  * ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses.

The player can ask no more than 3 queries of the first type.

To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed (n+1)^2.

Venya asked you to write a program, which will guess the string by interacting with the orderlies' program and acting by the game's rules.

Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer.

Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive.

Input

First line contains number n (1 ≤ n ≤ 100) — the length of the picked string.

Interaction

You start the interaction by reading the number n.

To ask a query about a substring from l to r inclusively (1 ≤ l ≤ r ≤ n), you should output

? l r

on a separate line. After this, all substrings of s[l..r] will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled.

In the case, if you ask an incorrect query, ask more than 3 queries of the first type or there will be more than (n+1)^2 substrings returned in total, you will receive verdict Wrong answer.

To guess the string s, you should output

! s

on a separate line.

After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don't terminate with exit code 0, you can receive any unsuccessful verdict.

Hack format

To hack a solution, use the following format:

The first line should contain one integer n (1 ≤ n ≤ 100) — the length of the string, and the following line should contain the string s.

Example

Input

4

a
aa
a

cb
b
c

c

Output

? 1 2

? 3 4

? 4 4

! aabc

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
const int M = 1100000;
const long long mod = 1e9 + 7;
int n;
string s[N], t[N];
char ans[N];
int num1, num2;
struct node {
  string s;
  int len;
  friend bool operator<(node a, node b) { return a.len < b.len; }
} a[N];
int nn;
int nu[110];
int nu2[110];
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  printf("? 1 %d\n", n);
  fflush(stdout);
  num1 = n * (n + 1) / 2;
  for (int i = 1; i <= num1; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  if (n == 1) {
    printf("! %c\n", s[1][0]);
    fflush(stdout);
    return 0;
  }
  num2 = n * (n - 1) / 2;
  printf("? 1 %d\n", n - 1);
  fflush(stdout);
  for (int i = 1; i <= num2; i++) {
    cin >> t[i];
    sort(t[i].begin(), t[i].end());
  }
  sort(s + 1, s + 1 + num1);
  sort(t + 1, t + 1 + num2);
  int head = 1;
  for (int i = 1; i <= num1; i++) {
    if (s[i] == t[head])
      head++;
    else {
      nn++;
      a[nn].s = s[i], a[nn].len = s[i].size();
    }
  }
  sort(a + 1, a + 1 + nn);
  for (int i = 1; i <= nn; i++) {
    memset(nu2, 0, sizeof(nu2));
    for (int j = 0; j < a[i].len; j++) nu2[a[i].s[j] - 'a']++;
    for (int j = 0; j < 26; j++)
      if (nu2[j] > nu[j]) {
        nu[j] = nu2[j];
        ans[nn - i] = j + 'a';
        break;
      }
  }
  printf("! %s\n", ans);
  fflush(stdout);
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.

The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 1. Specifically, the recipe of Doughnut i (2 ≤ i ≤ N) is a direct modification of the recipe of Doughnut p_i (1 ≤ p_i < i).

Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:

* Let c_i be the number of Doughnut i (1 ≤ i ≤ N) that she makes. For each integer i such that 2 ≤ i ≤ N, c_{p_i} ≤ c_i ≤ c_{p_i} + D must hold. Here, D is a predetermined value.

At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.

Constraints

* 2 ≤ N ≤ 50
* 1 ≤ X ≤ 10^9
* 0 ≤ D ≤ 10^9
* 1 ≤ m_i ≤ 10^9 (1 ≤ i ≤ N)
* 1 ≤ p_i < i (2 ≤ i ≤ N)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X D
m_1
m_2 p_2
:
m_N p_N

Output

Print the maximum number of doughnuts that can be made under the condition.

Examples

Input

3 100 1
15
10 1
20 1

Output

7

Input

3 100 10
15
10 1
20 1

Output

10

Input

5 1000000000 1000000
123
159 1
111 1
135 3
147 3

Output

7496296

### Response

```cpp
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int N=55;
int n,m,d,sz[N],id[N],sum,q[N*N*N],ans;
long long val[N],f[N*N*N],g[N*N*N];
vector<int>E[N];
void dfs(int u){
	sz[u]=1;id[u]=u;
	for(int v:E[u])dfs(v),sz[u]+=sz[v],val[u]+=val[v];
	sum+=sz[u];
}
bool cmp(int x,int y){
	return val[x]*sz[y]<val[y]*sz[x]||val[x]*sz[y]==val[y]*sz[x]&&sz[x]>sz[y];
}
int greedy(int x){
//	printf("greedy x=%d ",x);
	int res=0;
	for(int i=1;i<=n;++i){
		int y=min(x/val[id[i]],(long long)d);
		if(id[i]==1)y=x/val[id[i]];
		res+=y*sz[id[i]];x-=y*val[id[i]];
	}
//	printf("res=%d\n",res);
	return res;
}
int main(){
	scanf("%d%d%d%lld",&n,&m,&d,&val[1]);
	for(int i=2,x;i<=n;++i){
		scanf("%lld%d",&val[i],&x);
		E[x].push_back(i);
	}
	dfs(1);sort(id+1,id+n+1,cmp);
	sum*=min(n,d);
	memset(f,63,sizeof(f));f[0]=0;
	for(int i=1;i<=n;++i){
		for(int j=0;j<sz[i];++j)
			for(int k=j,hd=1,tl=0;k<=sum;k+=sz[i]){
				while(hd<=tl&&q[hd]<k-sz[i]*min(n,d))++hd;
				while(hd<=tl&&f[q[tl]]-val[i]*(q[tl]/sz[i])>f[k]-val[i]*(k/sz[i]))--tl;
				q[++tl]=k;g[k]=f[q[hd]]+val[i]*((k-q[hd])/sz[i]);
//				printf("k=%d g[k]=%lld\n",k,g[k]);
//				for(int x=hd;x<=tl;++x)
//					printf("%d ",q[x]);puts("");
			}
		for(int j=0;j<=sum;++j)f[j]=g[j];
	}
//	for(int i=0;i<=sum;++i)printf("%lld ",f[i]);puts("");
	d-=min(n,d);
//	printf("d=%d\n",d);
	for(int i=0;i<=sum;++i)if(f[i]<=m)ans=max(ans,i+greedy(m-f[i]));
	printf("%d\n",ans);return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.

Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6.

What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?

Input

The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.

Output

Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].

Examples

Input

6 3 2 4

Output

5

Input

6 3 1 3

Output

1

Input

5 2 1 5

Output

0

Note

In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.

In the second test she only needs to close all the tabs to the right of the current position of the cursor.

In the third test Luba doesn't need to do anything.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, p, l, r;
  cin >> n >> p >> l >> r;
  int sec = 0;
  int a = 0;
  int b = 0;
  if (l == 1) {
    if (r == n) {
      cout << 0;
      exit(0);
    }
    sec = abs(r - p);
    sec++;
  } else if (r == n) {
    sec = abs(p - l);
    sec++;
  } else {
    sec = r - l;
    sec += 2;
    sec += min(abs(p - l), abs(r - p));
  }
  cout << sec;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Example

Input

4 3
1000 1
2000 2
3000 3

Output

2 3 4 4

### Response

```cpp
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main(void) {
	int n, m;
	cin>>n>>m;
	vector<P> arm(m);
	REP(i, m) {
		cin>>arm[i].first>>arm[i].second;
		--arm[i].second;
	}
	sort(ALL(arm));
	vector<P> rng(n);
	REP(i, n) {
		rng[i].first = i;
		rng[i].second = i;
	}
	REP(i, m) {
		rng[arm[i].second].second = max(rng[arm[i].second].second, rng[arm[i].second + 1].second);
		rng[arm[i].second + 1].first = min(rng[arm[i].second + 1].first, rng[arm[i].second].first);
	}
	REP(i, n) {
		cout<<rng[i].second - rng[i].first + 1;
		if(i != n - 1) cout<<' ';
		else cout<<endl;
	}
}
```


### Prompt

Generate a cpp solution to the following problem:

In the last mission, MDCS has successfully shipped N AI robots to Mars. Before they start exploring, system initialization is required so they are arranged in a line. Every robot can be described with three numbers: position (x_i), radius of sight (r_i) and IQ (q_i).

Since they are intelligent robots, some of them will talk if they see each other. Radius of sight is inclusive, so robot can see other all robots in range [x_i - r_i, x_i + r_i]. But they don't walk to talk with anybody, but only with robots who have similar IQ. By similar IQ we mean that their absolute difference isn't more than K.

Help us and calculate how many pairs of robots are going to talk with each other, so we can timely update their software and avoid any potential quarrel.

Input

The first line contains two integers, numbers N (1 ≤ N ≤ 10^5)  and K (0 ≤ K ≤ 20).

Next N lines contain three numbers each x_i, r_i, q_i (0 ≤ x_i,r_i,q_i ≤ 10^9) — position, radius of sight and IQ of every robot respectively.

Output

Output contains only one number — solution to the problem.

Example

Input

3 2
3 6 1
7 3 10
10 5 8

Output

1

Note

The first robot can see the second, but not vice versa. The first robot can't even see the third. The second and the third robot can see each other and their IQs don't differ more than 2 so only one conversation will happen.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool comp(array<int, 3> a, array<int, 3> b) { return a[1] > b[1]; }
const int SZ = (1 << 30);
template <class T>
struct node {
  vector<array<int, 2>> c;
  vector<int> val;
  int cur;
  node() {
    c.push_back({-1, -1});
    cur = 1;
    val.push_back(0);
  }
  void upd(int nd, int ind, T v, int L = 0, int R = SZ - 1) {
    if (L == ind && R == ind) {
      val[nd] += v;
      return;
    }
    int M = (L + R) / 2;
    if (ind <= M) {
      if (c[nd][0] == -1) {
        c[nd][0] = cur++;
        c.push_back({-1, -1});
        val.push_back(0);
      }
      upd(c[nd][0], ind, v, L, M);
    } else {
      if (c[nd][1] == -1) {
        c[nd][1] = cur++;
        c.push_back({-1, -1});
        val.push_back(0);
      }
      upd(c[nd][1], ind, v, M + 1, R);
    }
    val[nd] = 0;
    for (int i = 0; i < 2; ++i)
      if (c[nd][i] != -1) val[nd] += val[c[nd][i]];
  }
  T query(int nd, int lo, int hi, int L = 0, int R = SZ - 1) {
    if (hi < L || R < lo) return 0;
    if (lo <= L && R <= hi) return val[nd];
    int M = (L + R) / 2;
    T res = 0;
    if (c[nd][0] != -1) res += query(c[nd][0], lo, hi, L, M);
    if (c[nd][1] != -1) res += query(c[nd][1], lo, hi, M + 1, R);
    return res;
  }
};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<array<int, 3>> a(n);
  for (int i = 0; i < n; ++i) {
    int x, r, q;
    cin >> x >> r >> q;
    a[i] = {x, r, q};
  }
  sort((a).begin(), (a).end(), comp);
  map<int, int> exist;
  map<int, node<int>> segs;
  long long ans = 0;
  for (auto [x, r, q] : a) {
    for (int i = q - k; i <= q + k; ++i) {
      if (!exist[i]) continue;
      ans += segs[i].query(0, max(x - r, 0), x + r);
    }
    if (!exist[q]) {
      segs[q] = node<int>();
    }
    segs[q].upd(0, x, 1);
    exist[q] = 1;
  }
  cout << ans << "\n";
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Slime has a sequence of positive integers a_1, a_2, …, a_n.

In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}.

In this problem, for the integer multiset s, the median of s is equal to the ⌊ (|s|+1)/(2)⌋-th smallest number in it. For example, the median of \{1,4,4,6,5\} is 4, and the median of \{1,7,5,8\} is 5.

Slime wants Orac to make a_1 = a_2 = … = a_n = k using these operations.

Orac thinks that it is impossible, and he does not want to waste his time, so he decided to ask you if it is possible to satisfy the Slime's requirement, he may ask you these questions several times.

Input

The first line of the input is a single integer t: the number of queries.

The first line of each query contains two integers n\ (1≤ n≤ 100 000) and k\ (1≤ k≤ 10^9), the second line contains n positive integers a_1,a_2,...,a_n\ (1≤ a_i≤ 10^9)

The total sum of n is at most 100 000.

Output

The output should contain t lines. The i-th line should be equal to 'yes' if it is possible to make all integers k in some number of operations or 'no', otherwise. You can print each letter in lowercase or uppercase.

Example

Input

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

Output

no
yes
yes
no
yes

Note

In the first query, Orac can't turn all elements into 3.

In the second query, a_1=6 is already satisfied.

In the third query, Orac can select the complete array and turn all elements into 2.

In the fourth query, Orac can't turn all elements into 3.

In the fifth query, Orac can select [1,6] at first and then select [2,10].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  bool nw = 0;
  while (t--) {
    if (nw) cout << '\n';
    nw = 1;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int& x : a) cin >> x;
    string ac;
    if (n == 1 && a[0] == k) {
      cout << "yes";
      continue;
    }
    bool flg = 0;
    for (int i = 0; i < n; i++) {
      flg |= (a[i] == k);
      ac += (char)('0' + (a[i] >= k));
    }
    if (flg ^ 1) {
      cout << "no";
      continue;
    }
    flg = 0;
    for (int i = 0; i < n; i++) {
      if (i + 1 < n) {
        if (ac[i] == ac[i + 1] && ac[i] == '1') flg = 1;
      }
      if (i + 2 < n) {
        int hw = 0;
        hw = (ac[i] - '0') + (ac[i + 2] - '0') + (ac[i + 1] - '0');
        flg |= (hw > 1);
      }
    }
    if (flg)
      cout << "yes";
    else
      cout << "no";
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has n mandatory quests. To perform each of them, you need to take exactly two companions.

The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions that change the attitude of the companions, whom he took to perform this task, in positive or negative direction.

Tell us what companions the hero needs to choose to make their attitude equal after completing all the quests. If this can be done in several ways, choose the one in which the value of resulting attitude is greatest possible.

Input

The first line contains positive integer n (1 ≤ n ≤ 25) — the number of important tasks.

Next n lines contain the descriptions of the tasks — the i-th line contains three integers li, mi, wi — the values by which the attitude of Lynn, Meliana and Worrigan respectively will change towards the hero if the hero takes them on the i-th task. All the numbers in the input are integers and do not exceed 107 in absolute value.

Output

If there is no solution, print in the first line "Impossible".

Otherwise, print n lines, two characters is each line — in the i-th line print the first letters of the companions' names that hero should take to complete the i-th task ('L' for Lynn, 'M' for Meliana, 'W' for Worrigan). Print the letters in any order, if there are multiple solutions, print any of them.

Examples

Input

3
1 0 0
0 1 0
0 0 1

Output

LM
MW
MW

Input

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

Output

LM
MW
LM
LW
MW
LM
LW

Input

2
1 0 0
1 1 0

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct State {
  long long x, y, a;
  int trace;
  bool operator<(const State &state) const {
    if (x == state.x) return y < state.y;
    return x < state.x;
  }
};
int n, m, a[50], b[50], c[50];
set<State> states;
long long maxA;
int trace1, trace2;
void gen(int i, int hi, long long sa, long long sb, long long sc, int trace) {
  if (i >= hi) {
    State t;
    t.x = sa - sb;
    t.y = sb - sc;
    t.a = sa;
    t.trace = trace;
    set<State>::iterator it = states.find(t);
    if (it != states.end()) {
      if (it->a < t.a) {
        states.erase(it);
        states.insert(t);
      }
    } else {
      states.insert(t);
    }
    return;
  }
  gen(i + 1, hi, sa, sb + b[i], sc + c[i], trace * 3);
  gen(i + 1, hi, sa + a[i], sb, sc + c[i], trace * 3 + 1);
  gen(i + 1, hi, sa + a[i], sb + b[i], sc, trace * 3 + 2);
}
void rec(int i, int hi, long long sa, long long sb, long long sc, int trace) {
  if (i >= hi) {
    State t;
    t.x = sb - sa;
    t.y = sc - sb;
    set<State>::iterator it = states.find(t);
    if (it != states.end() && it->a + sa > maxA) {
      maxA = it->a + sa;
      trace1 = it->trace;
      trace2 = trace;
    }
    return;
  }
  rec(i + 1, hi, sa, sb + b[i], sc + c[i], trace * 3);
  rec(i + 1, hi, sa + a[i], sb, sc + c[i], trace * 3 + 1);
  rec(i + 1, hi, sa + a[i], sb + b[i], sc, trace * 3 + 2);
}
void printTrace(int trace) {
  vector<int> ds;
  while (trace > 1) {
    ds.push_back(trace % 3);
    trace /= 3;
  }
  for (int i = (ds.size()) - 1; i >= 0; i--) {
    if (ds[i] == 0)
      puts("MW");
    else if (ds[i] == 1)
      puts("LW");
    else
      puts("LM");
  }
}
bool solve() {
  m = min(n / 2, 11);
  maxA = -10001112221000000LL;
  gen(0, m, 0, 0, 0, 1);
  rec(m, n, 0, 0, 0, 1);
  if (maxA == -10001112221000000LL) return false;
  printTrace(trace1);
  printTrace(trace2);
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 0, _n = (n); i < _n; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);
  if (!solve()) puts("Impossible");
  return 0;
}

```


### Prompt

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

E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.

E869120 and square1001 were just about to eat A and B of those pieces, respectively,
when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".

Can both of them obey the instruction in the note and take desired numbers of pieces of cake?

Constraints

* A and B are integers between 1 and 16 (inclusive).
* A+B is at most 16.

Input

Input is given from Standard Input in the following format:

A B

Output

If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.

Examples

Input

5 4

Output

Yay!

Input

8 8

Output

Yay!

Input

11 4

Output

:(

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y;
cin>>x>>y;
if(x>=16||y>=16||x>=9||y>=9)
cout<<":(";
else
cout<<"Yay!";

}

```


### Prompt

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

To become the king of Codeforces, Kuroni has to solve the following problem.

He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≤ i<j≤ n} |a_i - a_j|. As result can be very big, output it modulo m.

If you are not familiar with short notation, ∏_{1≤ i<j≤ n} |a_i - a_j| is equal to |a_1 - a_2|⋅|a_1 - a_3|⋅ ... ⋅|a_1 - a_n|⋅|a_2 - a_3|⋅|a_2 - a_4|⋅ ... ⋅|a_2 - a_n| ⋅ ... ⋅ |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≤ i < j ≤ n.

Input

The first line contains two integers n, m (2≤ n ≤ 2⋅ 10^5, 1≤ m ≤ 1000) — number of numbers and modulo.

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

Output

Output the single number — ∏_{1≤ i<j≤ n} |a_i - a_j| mod m.

Examples

Input

2 10
8 5

Output

3

Input

3 12
1 4 5

Output

0

Input

3 7
1 4 9

Output

1

Note

In the first sample, |8 - 5| = 3 ≡ 3 mod 10.

In the second sample, |1 - 4|⋅|1 - 5|⋅|4 - 5| = 3⋅ 4 ⋅ 1 = 12 ≡ 0 mod 12.

In the third sample, |1 - 4|⋅|1 - 9|⋅|4 - 9| = 3 ⋅ 8 ⋅ 5 = 120 ≡ 1 mod 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[210000];
long long te[1100];
long long f[1100] = {0};
int main() {
  long long n, i, j;
  long long m;
  scanf("%lld%lld", &n, &m);
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  if (n > m)
    printf("0\n");
  else {
    long long ans = 1;
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++) {
        ans = ans * abs(a[i] - a[j]) % m;
      }
    }
    printf("%lld\n", ans);
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given a table consisting of n rows and m columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa.

What is the minimum number of cells with value 1 you can get after applying some number of operations?

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 20, 1 ≤ m ≤ 100 000) — the number of rows and the number of columns, respectively.

Then n lines follows with the descriptions of the rows. Each line has length m and contains only digits '0' and '1'.

Output

Output a single integer — the minimum possible number of ones you can get after applying some sequence of operations.

Example

Input

3 4
0110
1010
0111

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res % mod;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const std::vector<std::pair<int, int>> moves{{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
inline int bitCount(long long x) { return __builtin_popcountll(x); }
inline long long highestOneBit(long long x) {
  return 1LL << (63 - __builtin_clzll(x | 1LL));
}
inline int binaryDigits(long long x) { return 64 - __builtin_clzll(x | 1LL); }
template <typename A>
string to_string(A* ptr) {
  stringstream ss;
  ss << "0x" << std::setw(16) << std::setfill('0') << std::hex
     << (uint64_t)(uintptr_t)ptr;
  return ss.str();
}
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
namespace fwht {
template <typename T>
void hadamard(vector<T>& a) {
  int n = a.size();
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        T x = a[i + j];
        T y = a[i + j + k];
        a[i + j] = x + y;
        a[i + j + k] = x - y;
      }
    }
  }
}
template <typename T>
vector<T> multiply(vector<T> a, vector<T> b) {
  int eq = (a == b);
  int n = 1;
  while (n < (int)max(a.size(), b.size())) {
    n <<= 1;
  }
  a.resize(n);
  b.resize(n);
  hadamard(a);
  if (eq)
    b = a;
  else
    hadamard(b);
  for (int i = 0; i < n; i++) {
    a[i] *= b[i];
  }
  hadamard(a);
  T q = static_cast<T>(n);
  for (int i = 0; i < n; i++) {
    a[i] /= q;
  }
  return a;
}
}  // namespace fwht
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<long long> cost(1 << n, 0);
  for (int mask = 0; mask < 1 << n; mask++) {
    int count = bitCount(mask);
    cost[mask] = min(count, n - count);
  }
  vector<long long> freq(1 << n, 0);
  for (int col = 0; col < m; col++) {
    int mask = 0;
    for (int i = 0; i < n; i++) mask |= (s[i][col] - '0') << i;
    freq[mask]++;
  }
  auto ans = fwht::multiply(freq, cost);
  cout << *min_element(ans.begin(), ans.end()) << '\n';
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Let's consider the following game. We have a rectangular field n × m in size. Some squares of the field contain chips.

Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right.

The player may choose a chip and make a move with it.

The move is the following sequence of actions. The chosen chip is marked as the current one. After that the player checks whether there are more chips in the same row (or in the same column) with the current one that are pointed by the arrow on the current chip. If there is at least one chip then the closest of them is marked as the new current chip and the former current chip is removed from the field. After that the check is repeated. This process can be repeated several times. If a new chip is not found, then the current chip is removed from the field and the player's move ends.

By the end of a move the player receives several points equal to the number of the deleted chips.

By the given initial chip arrangement determine the maximum number of points that a player can receive during one move. Also determine the number of such moves.

Input

The first line contains two integers n and m (1 ≤ n, m, n × m ≤ 5000). Then follow n lines containing m characters each — that is the game field description. "." means that this square is empty. "L", "R", "U", "D" mean that this square contains a chip and an arrow on it says left, right, up or down correspondingly.

It is guaranteed that a field has at least one chip.

Output

Print two numbers — the maximal number of points a player can get after a move and the number of moves that allow receiving this maximum number of points.

Examples

Input

4 4
DRLD
U.UL
.UUR
RDDL

Output

10 1

Input

3 5
.D...
RRRLL
.U...

Output

6 2

Note

In the first sample the maximum number of points is earned by the chip in the position (3, 3). You can see its progress at the following picture:

<image>

All other chips earn fewer points.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N, M, best, curr, cnt;
char A[5005][5005], B[5005][5005];
int P[4][4 * 5005], up, dp, lp, rp;
int pos(int x, int y) {
  if (x < 1 || x > N || y < 1 || y > M) return 0;
  return (x - 1) * M + y;
}
int X(int p) {
  p--;
  return (p / M) + 1;
}
int Y(int p) {
  int ret = (p % M);
  if (ret == 0) ret = M;
  return ret;
}
void init() {
  for (int I = 1; I <= N; I++)
    for (int K = 1; K <= M; K++) B[I][K] = A[I][K];
  for (int I = 1; I <= N; I++)
    for (int K = 1; K <= M; K++) {
      int p = pos(I, K);
      P[0][p] = pos(I - 1, K);
      P[1][p] = pos(I + 1, K);
      P[2][p] = pos(I, K - 1);
      P[3][p] = pos(I, K + 1);
    }
}
int setof(int p, int id) {
  if (p == 0 || (B[X(p)][Y(p)] != '.')) return p;
  return P[id][p] = setof(P[id][p], id);
}
int DFS(int x, int y) {
  int p = pos(x, y), np = -1;
  char tmp = B[x][y];
  B[x][y] = '.';
  if (tmp == 'U')
    np = setof(p, 0);
  else if (tmp == 'D')
    np = setof(p, 1);
  else if (tmp == 'L')
    np = setof(p, 2);
  else if (tmp == 'R')
    np = setof(p, 3);
  else
    assert(false);
  assert(np != -1);
  if (np == 0) return 1;
  return 1 + DFS(X(np), Y(np));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (int I = 1; I <= N; I++) cin >> A[I] + 1;
  for (int I = 1; I <= N; I++)
    for (int K = 1; K <= M; K++) {
      int p = pos(I, K);
    }
  for (int I = 1; I <= N; I++)
    for (int K = 1; K <= M; K++)
      if (A[I][K] != '.') {
        init();
        curr = DFS(I, K);
        if (curr > best) {
          best = curr;
          cnt = 1;
        } else if (curr == best) {
          cnt++;
        }
      }
  cout << best << " " << cnt << endl;
}

```


### Prompt

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

Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.

<image>

We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.

Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~

Input

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

n
a1
a2
::
an

The first line gives the number of visitors n (1 ≤ n ≤ 1000000), and the following n lines give the age of the i-th visitor ai (0 ≤ ai ≤ 120).

Output

The number of people is output in the following format for each data set.

Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60

Example

Input

8
71
34
65
11
41
39
6
5
4
67
81
78
65
0

Output

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

### Response

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int n;
	while (cin >> n, n) {
		int cnt[7] = {};
		REP(i, n) {
			int a;
			scanf("%d", &a);

			a /= 10;
			if (a >= 6) cnt[6]++;
			else cnt[a]++;
		}

		REP(i, 7) cout << cnt[i] << endl;
	}
	return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in N colors. Those colors are conveniently numbered 1 through N. Snuke currently has no slime. His objective is to have slimes of all the colors together.

Snuke can perform the following two actions:

* Select a color i (1≤i≤N), such that he does not currently have a slime in color i, and catch a slime in color i. This action takes him a_i seconds.

* Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color i (1≤i≤N-1) will become color i+1, and the color of a slime in color N will become color 1. This action takes him x seconds.

Find the minimum time that Snuke needs to have slimes in all N colors.

Constraints

* 2≤N≤2,000
* a_i are integers.
* 1≤a_i≤10^9
* x is an integer.
* 1≤x≤10^9

Input

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

N x
a_1 a_2 ... a_N

Output

Find the minimum time that Snuke needs to have slimes in all N colors.

Examples

Input

2 10
1 100

Output

12

Input

3 10
100 1 100

Output

23

Input

4 10
1 2 3 4

Output

10

### Response

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

int a[2010], b[2010][2010];
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);

    long n, x; cin>>n>>x;
    for(int i=0; i<n; ++i) cin>>a[i];

    for(int i=0; i<n; ++i) {
        b[i][0]=a[i];
        for(int k=1; k<n; ++k)
            b[i][k]=min(b[i][k-1], a[(i-k+n)%n]);
    }

    long res=1L<<62;
    for(int k=0; k<n; ++k) {
        long t=0;
        for(int i=0; i<n; ++i)
            t+=b[i][k];
        res=min(res, t+k*x);
    }
    cout<<res<<endl;
}

```


### Prompt

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

You are given a regular polygon with n vertices labeled from 1 to n in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.

Calculate the minimum weight among all triangulations of the polygon.

Input

The first line contains single integer n (3 ≤ n ≤ 500) — the number of vertices in the regular polygon.

Output

Print one integer — the minimum weight among all triangulations of the given polygon.

Examples

Input

3

Output

6

Input

4

Output

18

Note

According to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) P into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is P.

In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is 1 ⋅ 2 ⋅ 3 = 6.

In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal 1-3 so answer is 1 ⋅ 2 ⋅ 3 + 1 ⋅ 3 ⋅ 4 = 6 + 12 = 18.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[502];
int main() {
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 6;
  for (int i = 4; i <= 500; i++) {
    dp[i] = dp[i - 1] + (i * (i - 1));
  }
  int n;
  cin >> n;
  cout << dp[n] << endl;
}

```


### Prompt

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

Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".

To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or Hearts — H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).

At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.

In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.

Input

The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.

Each string is two characters long. The first character denotes the rank and belongs to the set \{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}. The second character denotes the suit and belongs to the set \{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}.

All the cards in the input are different.

Output

If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO".

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

Examples

Input

AS
2H 4C TH JH AD

Output

YES

Input

2H
3D 4C AC KD AS

Output

NO

Input

4D
AS AC AD AH 5H

Output

YES

Note

In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.

In the second example, you cannot play any card.

In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  char c[3], d[16];
  cin >> c;
  char ch = getchar();
  cin.get(d, 15);
  if (c[0] == d[0] || c[0] == d[3] || c[0] == d[6] || c[0] == d[9] ||
      c[0] == d[12])
    cout << "Yes";
  else if (c[1] == d[1] || c[1] == d[4] || c[1] == d[7] || c[1] == d[10] ||
           c[1] == d[13])
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

```


### Prompt

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

In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:

* Rating 1-399 : gray
* Rating 400-799 : brown
* Rating 800-1199 : green
* Rating 1200-1599 : cyan
* Rating 1600-1999 : blue
* Rating 2000-2399 : yellow
* Rating 2400-2799 : orange
* Rating 2800-3199 : red

Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.
Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.
Find the minimum and maximum possible numbers of different colors of the users.

Constraints

* 1 ≤ N ≤ 100
* 1 ≤ a_i ≤ 4800
* a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.

Examples

Input

4
2100 2500 2700 2700

Output

2 2

Input

5
1100 1900 2800 3200 3200

Output

3 5

Input

20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990

Output

1 1

### Response

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

int main(void){
    int n,col[9]={};
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a>3200) a=3200;
        col[a/400] ++;
    }

    int ans=0;
    for(int i=0;i<8;i++){
        ans += (col[i]>0);
    }
    cout<<(ans>0?ans:1)<<" "<<(ans+col[8])<<endl;

}
```


### Prompt

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

Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.

The boys decided to have fun and came up with a plan. Namely, in some day in the morning Misha will ride the underground from station s to station f by the shortest path, and will draw with aerosol an ugly text "Misha was here" on every station he will pass through (including s and f). After that on the same day at evening Grisha will ride from station t to station f by the shortest path and will count stations with Misha's text. After that at night the underground workers will wash the texts out, because the underground should be clean.

The boys have already chosen three stations a, b and c for each of several following days, one of them should be station s on that day, another should be station f, and the remaining should be station t. They became interested how they should choose these stations s, f, t so that the number Grisha will count is as large as possible. They asked you for help.

Input

The first line contains two integers n and q (2 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of stations and the number of days.

The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n). The integer pi means that there is a route between stations pi and i. It is guaranteed that it's possible to reach every station from any other.

The next q lines contains three integers a, b and c each (1 ≤ a, b, c ≤ n) — the ids of stations chosen by boys for some day. Note that some of these ids could be same.

Output

Print q lines. In the i-th of these lines print the maximum possible number Grisha can get counting when the stations s, t and f are chosen optimally from the three stations on the i-th day.

Examples

Input

3 2
1 1
1 2 3
2 3 3

Output

2
3

Input

4 1
1 2 3
1 2 3

Output

2

Note

In the first example on the first day if s = 1, f = 2, t = 3, Misha would go on the route 1 <image> 2, and Grisha would go on the route 3 <image> 1 <image> 2. He would see the text at the stations 1 and 2. On the second day, if s = 3, f = 2, t = 3, both boys would go on the route 3 <image> 1 <image> 2. Grisha would see the text at 3 stations.

In the second examle if s = 1, f = 3, t = 2, Misha would go on the route 1 <image> 2 <image> 3, and Grisha would go on the route 2 <image> 3 and would see the text at both stations.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
struct LCA {
  int p[maxn][20], n, q, cnt[maxn], deep[maxn];
  vector<int> G[maxn];
  int dfs(int u, int _p) {
    p[u][0] = _p;
    cnt[u] = 1;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (v == _p) continue;
      deep[v] = deep[u] + 1;
      cnt[u] += dfs(v, u);
    }
    return cnt[u];
  }
  int dis(int x, int y) { return deep[x] + deep[y] - 2 * deep[Lca(x, y)]; }
  void Lca_init() {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < maxn; i++) G[i].clear();
    for (int i = 2; i <= n; i++) {
      int v;
      scanf("%d", &v);
      G[v].push_back(i), G[i].push_back(v);
    }
    deep[1] = 0;
    dfs(1, -1);
    for (int j = 1; j < 20; j++)
      for (int i = 1; i <= n; i++) {
        if (p[i][j - 1] == -1)
          p[i][j] = -1;
        else
          p[i][j] = p[p[i][j - 1]][j - 1];
      }
    for (int i = 1; i <= q; i++) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      int ab = dis(a, b), bc = dis(b, c), ac = dis(a, c);
      int sum = ab + bc + ac;
      sum /= 2;
      int ans = 0;
      ans = 1 + max(ans, max(sum - ab, max(sum - bc, sum - ac)));
      printf("%d\n", ans);
    }
  }
  int Lca_up(int u, int len) {
    for (int i = 0; i < 20; i++)
      if (u != -1 && len & (1 << i)) u = p[u][i];
    return u;
  }
  int Lca(int u, int v) {
    if (deep[u] < deep[v]) swap(u, v);
    u = Lca_up(u, deep[u] - deep[v]);
    if (u == v) return u;
    for (int i = 19; i >= 0; i--) {
      if (p[u][i] == p[v][i]) continue;
      u = p[u][i];
      v = p[v][i];
    }
    return p[u][0];
  }
} solver;
int main() {
  solver.Lca_init();
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k.

There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different.

Now the children wonder, how to divide the orange so as to meet these conditions:

  * each child gets exactly n orange segments;
  * the i-th child gets the segment with number ai for sure;
  * no segment goes to two children simultaneously.

Help the children, divide the orange and fulfill the requirements, described above.

Input

The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get.

It is guaranteed that all numbers ai are distinct.

Output

Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.

You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them.

Examples

Input

2 2
4 1

Output

2 4
1 3

Input

3 1
2

Output

3 2 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10000], b[10000], i, j, k, l, n, m;
int main() {
  cin >> n >> k;
  for (i = 1; i <= k; i++) {
    cin >> b[i];
    a[b[i]] = 1;
  }
  for (i = 1; i <= k; i++) {
    cout << b[i] << " ";
    l = 1;
    for (j = 1; j <= n * k; j++)
      if (a[j] == 0) {
        cout << j << " ";
        a[j] = 1;
        l++;
        if (l == n) break;
      }
    cout << endl;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.

Input

The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.

The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.

Output

Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.

Examples

Input

4
90 90 90 90

Output

0

Input

3
100 100 160

Output

40

Input

1
360

Output

360

Input

4
170 30 150 10

Output

0

Note

In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.

In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.

In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.

Picture explaning fourth sample:

<image>

Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  int res = 360;
  for (int i = 0; i < n; ++i) {
    int cur = 0;
    for (int j = 0; j < n; ++j) {
      cur += v[(i + j) % n];
      res = min(res, abs(cur - (360 - cur)));
    }
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

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

Let us define a magic grid to be a square matrix of integers of size n × n, satisfying the following conditions.

  * All integers from 0 to (n^2 - 1) inclusive appear in the matrix exactly once.
  * [Bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all elements in a row or a column must be the same for each row and column.

You are given an integer n which is a multiple of 4. Construct a magic grid of size n × n.

Input

The only line of input contains an integer n (4 ≤ n ≤ 1000). It is guaranteed that n is a multiple of 4.

Output

Print a magic grid, i.e. n lines, the i-th of which contains n space-separated integers, representing the i-th row of the grid.

If there are multiple answers, print any. We can show that an answer always exists.

Examples

Input

4

Output

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

Input

8

Output

19 55 11 39 32 36 4 52
51 7 35 31 12 48 28 20
43 23 59 15 0 8 16 44
3 47 27 63 24 40 60 56
34 38 6 54 17 53 9 37
14 50 30 22 49 5 33 29
2 10 18 46 41 21 57 13
26 42 62 58 1 45 25 61

Note

In the first example, XOR of each row and each column is 13.

In the second example, XOR of each row and each column is 60.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 10E16;
const long long mask = (1 << 9) - 1;
const long long base = 100000000000;
const long double eps = 0.0000001;
struct pp {
  long long fi, sc;
  bool const operator<(const pp& b) {
    if (fi == b.fi) return sc < b.sc;
    return fi < b.fi;
  }
  bool const operator>(const pp& b) {
    if (fi == b.fi) return sc > b.sc;
    return fi > b.fi;
  }
  bool const operator==(const pp& b) {
    if (fi == b.fi && sc == b.sc) return 1;
    return 0;
  }
};
bool const operator<(const pp& a, const pp& b) {
  if (a.fi == b.fi) return a.sc < b.sc;
  return a.fi < b.fi;
}
long long n, A[2007][2007];
set<long long> S;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long r = 0;
  for (long long i = 1; i <= n; i += 4) {
    for (long long j = 1; j <= n; j += 4) {
      for (long long ii = i; ii < i + 4; ii++) {
        for (long long jj = j; jj < j + 4; jj++) {
          A[ii][jj] = r;
          r++;
        }
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      cout << A[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.

Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1, 2, ..., m. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.

The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties.

Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109 + 7).

Input

A single line contains a single positive integer m (7 ≤ m ≤ 109) — the number of possible numbers in the ballot.

Output

In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

7

Output

0

Input

8

Output

1440

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
int m;
long long sum = 0;
int cnt[20];
long long dp[15][2][15];
void DP() {
  int digit[15];
  memset(digit, 0, sizeof(digit));
  int mm = m;
  int index = 1;
  while (mm > 0) {
    digit[index++] = mm % 10;
    mm /= 10;
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  for (int i = 1; i <= 10; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i][0][j] = 8 * dp[i - 1][0][j];
      if (j > 0) dp[i][0][j] += dp[i - 1][0][j - 1] * 2;
      for (int k = 0; k < digit[i]; k++) {
        if (k == 4 || k == 7)
          dp[i][1][j] += dp[i - 1][0][j - 1];
        else
          dp[i][1][j] += dp[i - 1][0][j];
      }
      if (digit[i] == 4 || digit[i] == 7)
        dp[i][1][j] += dp[i - 1][1][j - 1];
      else
        dp[i][1][j] += dp[i - 1][1][j];
    }
  }
  for (int i = 0; i <= 10; i++) {
    cnt[i] = dp[10][1][i];
  }
  cnt[0]--;
}
void Search(int depth, int left, long long ways) {
  ways %= M;
  if (depth == 0) {
    sum += ways;
    sum %= M;
    return;
  }
  for (int i = 0; i <= left; i++) {
    if (cnt[i] > 0) {
      Search(depth - 1, left - i, ways * cnt[i]--);
      cnt[i]++;
    }
  }
}
int main() {
  scanf("%d", &m);
  m++;
  DP();
  for (int i = 10; i > 0; i--) {
    if (cnt[i] == 0) continue;
    Search(6, i - 1, cnt[i]);
  }
  cout << sum << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1 ≤ i < n condition, that api·api + 1 is not perfect square, holds. Leha wants to find number of right permutations modulo 109 + 7.

Input

First line of input data contains single integer n (1 ≤ n ≤ 300) — length of the array.

Next line contains n integers a1, a2, ... , an (1 ≤ ai ≤ 109) — found array.

Output

Output single integer — number of right permutations modulo 109 + 7.

Examples

Input

3
1 2 4

Output

2

Input

7
5 2 4 2 4 1 1

Output

144

Note

For first example:

[1, 2, 4] — right permutation, because 2 and 8 are not perfect squares.

[1, 4, 2] — wrong permutation, because 4 is square of 2.

[2, 1, 4] — wrong permutation, because 4 is square of 2.

[2, 4, 1] — wrong permutation, because 4 is square of 2.

[4, 1, 2] — wrong permutation, because 4 is square of 2.

[4, 2, 1] — right permutation, because 8 and 2 are not perfect squares.

### Response

```cpp
#include <bits/stdc++.h>
const int INF = 1e9 + 1;
const double PI = acos(-1.0);
const double EPS = 1e-9;
using namespace std;
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  typename map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
template <class T>
void deb_array(T *arr, int length) {
  for (int i = 0; i < length; i++) {
    cout << arr[i] << ' ';
  }
  cout << '\n';
}
const int maxn = 305;
const long long mod = 1e9 + 7;
int n;
long long a[maxn], fac[maxn];
long long comb[maxn][maxn], dp[maxn][maxn];
vector<int> group;
map<int, int> mp;
void calc() {
  for (int i = 0; i < maxn; i++) {
    for (int j = 0; j <= i; j++) {
      if (i == j || j == 0)
        comb[i][j] = 1;
      else
        comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
    }
  }
  fac[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int b = a[i], num;
    for (int j = 2; j * j <= b; j++) {
      num = 0;
      while (b % j == 0) {
        num++;
        b /= j;
      }
      if (num & 1) {
        b *= j;
      }
    }
    mp[b]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    group.push_back(it->second);
  }
  calc();
  dp[0][group[0] - 1] = fac[group[0]];
  int sum = group[0] + 1;
  for (int x = 1; x < group.size(); x++) {
    for (int y = 0; y <= sum; y++) {
      for (int ij = 1; ij <= group[x]; ij++) {
        for (int j = 0; j <= min(ij, y); j++) {
          long long cur = dp[x - 1][y];
          if (cur == 0) continue;
          cur *= fac[group[x]];
          cur %= mod;
          cur *= comb[y][j];
          cur %= mod;
          cur *= comb[sum - y][ij - j];
          cur %= mod;
          cur *= comb[group[x] - 1][ij - 1];
          dp[x][y - j + group[x] - ij] += cur;
          dp[x][y - j + group[x] - ij] %= mod;
        }
      }
    }
    sum += group[x];
  }
  cout << dp[group.size() - 1][0] << '\n';
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Rainbow built h cells in a row that are numbered from 1 to h from left to right. There are n cells with treasure. We call each of these n cells "Treasure Cell". The i-th "Treasure Cell" is the ai-th cell and the value of treasure in it is ci dollars.

Then, Freda went in the first cell. For now, she can go just k cells forward, or return to the first cell. That means Freda was able to reach the 1st, (k + 1)-th, (2·k + 1)-th, (3·k + 1)-th cells and so on.

Then Rainbow gave Freda m operations. Each operation is one of the following three types:

  1. Add another method x: she can also go just x cells forward at any moment. For example, initially she has only one method k. If at some moment she has methods a1, a2, ..., ar then she can reach all the cells with number in form <image>, where vi — some non-negative integer.
  2. Reduce the value of the treasure in the x-th "Treasure Cell" by y dollars. In other words, to apply assignment cx = cx - y.
  3. Ask the value of the most valuable treasure among the cells Freda can reach. If Freda cannot reach any cell with the treasure then consider the value of the most valuable treasure equal to 0, and do nothing. Otherwise take the most valuable treasure away. If several "Treasure Cells" have the most valuable treasure, take the "Treasure Cell" with the minimum number (not necessarily with the minimum number of cell). After that the total number of cells with a treasure is decreased by one.

As a programmer, you are asked by Freda to write a program to answer each query.

Input

The first line of the input contains four integers: h (1 ≤ h ≤ 1018), n, m (1 ≤ n, m ≤ 105) and k (1 ≤ k ≤ 104).

Each of the next n lines contains two integers: ai (1 ≤ ai ≤ h), ci (1 ≤ ci ≤ 109). That means the i-th "Treasure Cell" is the ai-th cell and cost of the treasure in that cell is ci dollars. All the ai are distinct.

Each of the next m lines is in one of the three following formats:

  * "1 x" — an operation of type 1, 1 ≤ x ≤ h;
  * "2 x y" — an operation of type 2, 1 ≤ x ≤ n, 0 ≤ y < cx;
  * "3" — an operation of type 3.

There are at most 20 operations of type 1. It's guaranteed that at any moment treasure in each cell has positive value. It's guaranteed that all operations is correct (no operation can decrease the value of the taken tresure).

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

Output

For each operation of type 3, output an integer indicates the value (in dollars) of the most valuable treasure among the "Treasure Cells" Freda can reach. If there is no such treasure, output 0.

Examples

Input

10 3 5 2
5 50
7 60
8 100
2 2 5
3
1 3
3
3

Output

55
100
50

Note

In the sample, there are 10 cells and 3 "Treasure Cells". The first "Treasure Cell" is cell 5, having 50 dollars tresure in it. The second "Treasure Cell" is cell 7, having 60 dollars tresure in it. The third "Treasure Cell" is cell 8, having 100 dollars tresure in it.

At first, Freda can only reach cell 1, 3, 5, 7 and 9. In the first operation, we reduce the value in the second "Treasure Cell" from 60 to 55. Then the most valuable treasure among the "Treasure Cells" she can reach is max(50, 55) = 55. After the third operation, she can also go 3 cells forward each step, being able to reach cell 1, 3, 4, 5, 6, 7, 8, 9, 10. So the most valuable tresure is 100.

Noticed that she took the 55 dollars and 100 dollars treasure away, so the last answer is 50.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
static inline int Rint() {
  struct X {
    int dig[256];
    X() {
      for (int i = '0'; i <= '9'; ++i) dig[i] = 1;
      dig['-'] = 1;
    }
  };
  static X fuck;
  int s = 1, v = 0, c;
  for (; !fuck.dig[c = getchar()];)
    ;
  if (c == '-')
    s = 0;
  else if (fuck.dig[c])
    v = c ^ 48;
  for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))
    ;
  return s ? v : -v;
}
template <typename T>
static inline void cmax(T& a, const T& b) {
  if (b > a) a = b;
}
template <typename T>
static inline void cmin(T& a, const T& b) {
  if (b < a) a = b;
}
const int maxn = 100005;
long long h;
int n, m, k;
long long pos[maxn];
int treasure[maxn];
int flag[maxn];
long long D[10005];
long long allk[32];
int top;
struct Pt {
  long long t, p, id;
  int operator<(const Pt& o) const {
    if (t != o.t) return t < o.t;
    return id > o.id;
  }
};
void fix(priority_queue<Pt>& pq) {
  set<pair<long long, int> > st;
  for (int i = 0; i < k; ++i)
    if (D[i] != -1) st.insert({D[i], i});
  while (!st.empty()) {
    auto where = st.begin();
    auto curr = *where;
    st.erase(where);
    if (D[curr.second] != curr.first) continue;
    for (int i = 0; i < top; ++i) {
      {
        const long long val = curr.first + allk[i];
        if (val > h) continue;
        int next = val % k;
        if (next == curr.second) {
          continue;
        }
        if (D[next] == -1) {
          D[next] = val;
          st.insert({D[next], next});
        } else if (D[next] > val) {
          D[next] = val;
          st.insert({D[next], next});
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if (flag[i] == 0) {
      const int bucket = pos[i] % k;
      if (D[bucket] != -1) {
        if (pos[i] >= D[bucket]) {
          pq.push({treasure[i], pos[i], i});
          flag[i] = 1;
        }
      }
    }
}
int main() {
  scanf("%I64d", &h);
  n = Rint(), m = Rint(), k = Rint();
  for (int i = 1; i <= n; ++i) scanf("%I64d %d", pos + i, treasure + i);
  memset(D, -1, sizeof D);
  D[1 % k] = 1;
  priority_queue<Pt> pq;
  for (int i = 1; i <= n; ++i) {
    const int bucket = pos[i] % k;
    if (D[bucket] != -1) {
      if (pos[i] >= D[bucket]) {
        pq.push({treasure[i], pos[i], i});
        flag[i] = 1;
      }
    }
  }
  for (int id = 0; id < m; ++id) {
    const int cmd = Rint();
    if (cmd == 3) {
      while (!pq.empty()) {
        auto curr = pq.top();
        if (treasure[curr.id] != curr.t) {
          pq.pop();
        } else {
          break;
        }
      }
      long long ans = 0;
      if (!pq.empty()) {
        ans = pq.top().t;
        treasure[pq.top().id] = -1;
        flag[pq.top().id] = 2;
        pq.pop();
      }
      printf("%I64d\n", ans);
    } else if (cmd == 2) {
      const int x = Rint();
      const int c = Rint();
      treasure[x] -= c;
      if (c != 0 && flag[x]) {
        if (flag[x] == 1) {
          pq.push({treasure[x], pos[x], x});
        }
      }
    } else {
      long long x;
      scanf("%I64d", &x);
      int ok = 1;
      if (ok) {
        allk[top++] = x;
        fix(pq);
      }
    }
  }
  return 0;
}

```


### Prompt

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

In this task you need to process a set of stock exchange orders and use them to create order book.

An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell qi stocks at price pi for one stock. A value qi is also known as a volume of an order.

All orders with the same price p and direction d are merged into one aggregated order with price p and direction d. The volume of such order is a sum of volumes of the initial orders.

An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order.

An order book of depth s contains s best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than s aggregated orders for some direction then all of them will be in the final order book.

You are given n stock exhange orders. Your task is to print order book of depth s for these orders.

Input

The input starts with two positive integers n and s (1 ≤ n ≤ 1000, 1 ≤ s ≤ 50), the number of orders and the book depth.

Next n lines contains a letter di (either 'B' or 'S'), an integer pi (0 ≤ pi ≤ 105) and an integer qi (1 ≤ qi ≤ 104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order.

Output

Print no more than 2s lines with aggregated orders from order book of depth s. The output format for orders should be the same as in input.

Examples

Input

6 2
B 10 3
S 50 2
S 40 1
S 50 6
B 20 4
B 25 10

Output

S 50 8
S 40 1
B 25 10
B 20 4

Note

Denote (x, y) an order with price x and volume y. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.

You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, s, p, q;
  char d;
  vector<tuple<char, long long, long long>> b;
  cin >> n >> s;
  while (n--) {
    cin >> d >> p >> q;
    b.push_back(make_tuple(d, p, q));
  }
  sort(b.begin(), b.end(),
       [](const tuple<char, long long, long long> &left,
          const tuple<char, long long, long long> &right) {
         return get<0>(left) > get<0>(right);
       });
  vector<tuple<char, long long, long long>>::iterator i = b.begin(), j;
  i = find_if(b.begin(), b.end(),
              [](const tuple<char, long long, long long> &e) {
                return get<0>(e) == 'B';
              });
  sort(b.begin(), i,
       [](const tuple<char, long long, long long> &left,
          const tuple<char, long long, long long> &right) {
         return get<1>(left) < get<1>(right);
       });
  sort(i, b.end(),
       [](const tuple<char, long long, long long> &left,
          const tuple<char, long long, long long> &right) {
         return get<1>(left) > get<1>(right);
       });
  for (j = b.begin() + 1; j < i; j++)
    if (get<1>(*j) == get<1>(*(j - 1))) {
      get<2>(*j) += get<2>(*(j - 1));
      b.erase(j - 1);
      i--;
      j--;
    }
  for (j = i + 1; j < b.end(); j++)
    if (get<1>(*j) == get<1>(*(j - 1))) {
      get<2>(*j) += get<2>(*(j - 1));
      b.erase(j - 1);
      j--;
    }
  for (j = b.begin(), n = 0; j != i && n < s; j++, n++)
    ;
  for (j = j - 1; j >= b.begin(); j--)
    cout << get<0>(*j) << " " << get<1>(*j) << " " << get<2>(*j) << "\n";
  for (j = i, n = 0; j != b.end() && n < s; j++, n++)
    cout << get<0>(*j) << " " << get<1>(*j) << " " << get<2>(*j) << "\n";
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters.

Since you spend a lot of time typing it, you want to buy a new keyboard.

A keyboard is a permutation of the first m Latin letters. For example, if m = 3, then there are six possible keyboards: abc, acb, bac, bca, cab and cba.

Since you type your password with one finger, you need to spend time moving your finger from one password character to the next. The time to move from character s_i to character s_{i+1} is equal to the distance between these characters on keyboard. The total time you have to spend typing the password with a keyboard is called the slowness of this keyboard.

More formaly, the slowness of keyboard is equal to ∑_{i=2}^{n} |pos_{s_{i-1}} - pos_{s_i} |, where pos_x is position of letter x in keyboard.

For example, if s is aacabc and the keyboard is bac, then the total time of typing this password is |pos_a - pos_a| + |pos_a - pos_c| + |pos_c - pos_a| + |pos_a - pos_b| + |pos_b - pos_c| = |2 - 2| + |2 - 3| + |3 - 2| + |2 - 1| + |1 - 3| = 0 + 1 + 1 + 1 + 2 = 5.

Before buying a new keyboard you want to know the minimum possible slowness that the keyboard can have.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 20).

The second line contains the string s consisting of n characters. Each character is one of the first m Latin letters (lowercase).

Output

Print one integer – the minimum slowness a keyboard can have.

Examples

Input

6 3
aacabc

Output

5

Input

6 4
aaaaaa

Output

0

Input

15 4
abacabadabacaba

Output

16

Note

The first test case is considered in the statement.

In the second test case the slowness of any keyboard is 0.

In the third test case one of the most suitable keyboards is bacd.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 5;
const long long N = 20;
const long long INF = 1e18;
long long n, m, dp[1 << N], times[N + 1][N + 1];
char str[MAXN];
long long cost(long long s) {
  long long ret = 0;
  for (long long i = 1; i <= m; i++) {
    if (s & (1 << (i - 1))) {
      for (long long j = 1; j <= m; j++) {
        if (!(s & (1 << (j - 1)))) {
          ret += times[i][j];
        }
      }
    }
  }
  return ret;
}
void solve() {
  for (long long i = 2; i <= n; i++) {
    long long u = str[i] - 'a' + 1;
    long long v = str[i - 1] - 'a' + 1;
    if (u == v) continue;
    times[u][v]++;
    times[v][u]++;
  }
  for (long long s = 1; s < (1 << m); s++) {
    dp[s] = INF;
  }
  dp[0] = 0;
  for (long long s = 0; s < (1 << m); s++) {
    long long c = cost(s);
    for (long long i = 1; i <= m; i++) {
      if (!(s & (1 << (i - 1)))) {
        dp[s | (1 << (i - 1))] = min(dp[s | (1 << (i - 1))], dp[s] + c);
      }
    }
  }
  printf("%lld\n", dp[(1 << m) - 1]);
}
int main() {
  scanf("%lld %lld", &n, &m);
  scanf("%s", str + 1);
  solve();
}

```


### Prompt

Create a solution in Cpp for the following problem:

Nezzar has a binary string s of length n that he wants to share with his best friend, Nanako. Nanako will spend q days inspecting the binary string. At the same time, Nezzar wants to change the string s into string f during these q days, because it looks better.

It is known that Nanako loves consistency so much. On the i-th day, Nanako will inspect a segment of string s from position l_i to position r_i inclusive. If the segment contains both characters '0' and '1', Nanako becomes unhappy and throws away the string.

After this inspection, at the i-th night, Nezzar can secretly change strictly less than half of the characters in the segment from l_i to r_i inclusive, otherwise the change will be too obvious.

Now Nezzar wonders, if it is possible to avoid Nanako being unhappy and at the same time have the string become equal to the string f at the end of these q days and nights.

Input

The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — the number of test cases.

The first line of each test case contains two integers n,q (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ q ≤ 2 ⋅ 10^5).

The second line of each test case contains a binary string s of length n.

The third line of each test case contains a binary string f of length n.

Then q lines follow, i-th of them contains two integers l_i,r_i (1 ≤ l_i ≤ r_i ≤ n) — bounds of the segment, that Nanako will inspect on the i-th day.

It is guaranteed that the sum of n for all test cases doesn't exceed 2 ⋅ 10^5, and the sum of q for all test cases doesn't exceed 2 ⋅ 10^5.

Output

For each test case, print "YES" on the single line if it is possible to avoid Nanako being unhappy and have the string f at the end of q days and nights. Otherwise, print "NO".

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

Example

Input

4
5 2
00000
00111
1 5
1 3
2 1
00
01
1 2
10 6
1111111111
0110001110
1 10
5 9
7 10
1 7
3 5
6 10
5 2
10000
11000
2 5
1 3

Output

YES
NO
YES
NO

Note

In the first test case, \underline{00000} → \underline{000}11 → 00111 is one of the possible sequences of string changes.

In the second test case, it can be shown that it is impossible to have the string f at the end.

### Response

```cpp
#include <bits/stdc++.h>
#define endl '\n'

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

string t;

struct node
{
	int sum, lazy;

	node() {sum = 0; lazy = -1;}
	node(int val)
	{
		sum = val;
		lazy = -1;
	}
};

node temp, broken;

node merge(node l, node r)
{
	temp.sum = l.sum + r.sum;
	temp.lazy = -1;
	return temp;
}

struct segment_tree
{
	node tr[4 * MAXN];

	void push(int l, int r, int idx)
	{
		if(tr[idx].lazy != -1)
		{
			tr[idx].sum = (r - l + 1) * tr[idx].lazy;

			if(l != r)
			{
				tr[2 * idx + 1].lazy = tr[idx].lazy;
				tr[2 * idx + 2].lazy = tr[idx].lazy;
			}

			tr[idx].lazy = -1;
		}
	}

	void init(int l, int r, int idx)
	{
		if(l == r)
		{
			tr[idx] = node(t[l] - '0');
			return;
		}

		int mid = (l + r) >> 1;
		init(l, mid, 2 * idx + 1);
		init(mid + 1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
	}

	void update(int qL, int qR, int val, int l, int r, int idx)
	{
		push(l, r, idx);

		if(qL > r || l > qR)
			return;

		if(qL <= l && r <= qR)
		{
			tr[idx].lazy = val;
			push(l, r, idx);
			return;
		}

		int mid = (l + r) >> 1;
		update(qL, qR, val, l, mid, 2 * idx + 1);
		update(qL, qR, val, mid + 1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
	}

	node query(int qL, int qR, int l, int r, int idx)
	{
		push(l, r, idx);

		if(l > qR || r < qL)
			return broken;

		if(qL <= l && r <= qR)
			return tr[idx];

		int mid = (l + r) >> 1;
		return merge(query(qL, qR, l, mid, 2 * idx + 1), query(qL, qR, mid + 1, r, 2 * idx + 2));
	}
} tr;

int n, q;
string s;
pair<int, int> que[MAXN];

void read() {
	cin >> n >> q;
	cin >> s >> t;
	for(int i = 0; i < q; i++) {
		cin >> que[i].first >> que[i].second;
		que[i].first--;
		que[i].second--;
	}
}

void solve() {
	tr.init(0, n - 1, 0);

	for(int i = q - 1; i >= 0; i--) {
		int l = que[i].first, r = que[i].second, cnt = r - l + 1;

		auto nd = tr.query(l, r, 0, n - 1, 0);
		int cnt1 = nd.sum;
		int cnt0 = cnt - cnt1;

		if(cnt1 <= (cnt - 1) / 2) {
			tr.update(l, r, 0, 0, n - 1, 0);
		} else if(cnt0 <= (cnt - 1) / 2) {
			tr.update(l, r, 1, 0, n - 1, 0);
		} else {
			cout << "NO" << endl;
			return;
		}
	}

	for(int i = 0; i < n; i++) {
		if(s[i] - '0' != tr.query(i, i, 0, n - 1, 0).sum) {
			cout << "NO" << endl;
			return;
		}
	}

	cout << "YES" << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int T;
	cin >> T;
	while(T--) {
		read();
		solve();
	}

	return 0;
}

```


### Prompt

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

As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).

A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si — how many students who play basketball belong to this department.

Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.

Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.

Input

The first line contains three integers n, m and h (1 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ h ≤ m) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.

The second line contains a single-space-separated list of m integers si (1 ≤ si ≤ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.

Output

Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.

Examples

Input

3 2 1
2 1

Output

1

Input

3 2 1
1 1

Output

-1

Input

3 2 1
2 2

Output

0.666667

Note

In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.

In the second example, there are not enough players.

In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, h;
  cin >> n >> m >> h;
  h--;
  int sum = 0;
  int Q = 0;
  for (int i = (0); i < (m); ++i) {
    int t;
    cin >> t;
    if (i == h) Q = t;
    sum += t;
  }
  if (sum < n) {
    cout << "-1\n";
    return 0;
  }
  sum--;
  Q--;
  n--;
  double ans = 1.0;
  int it1 = sum - Q - n + 1;
  int up1 = sum - n;
  int it2 = sum - Q + 1;
  int up2 = sum;
  double eps = 1e-15;
  bool bx = true;
  while ((it1 <= up1 || it2 <= up2) && bx) {
    bx = false;
    if (ans < eps) {
      while (it1 <= up1 && ans < 1e9) {
        ans *= it1;
        it1++;
        bx = true;
      }
    }
    while (it2 <= up2 && ans > 1e-9) {
      ans = 1.0 * ans / it2;
      it2++;
      bx = true;
    }
  }
  while (it1 <= up1) {
    ans *= 1.0 * it1;
    it1++;
  }
  while (it2 <= up2) {
    ans = 1.0 * ans / it2;
    it2++;
  }
  printf("%.8f\n", 1.0 - ans);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.

Note, that during capitalization all the letters except the first one remains unchanged.

Input

A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.

Output

Output the given word after capitalization.

Examples

Input

ApPLe

Output

ApPLe

Input

konjac

Output

Konjac

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  char word[1001];
  scanf("%s", &word);
  if (word[0] >= 'a' && word[0] <= 'z') {
    word[0] = word[0] - 32;
  }
  printf("%s\n", word);
  return 0;
}

```


### Prompt

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

Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.

Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.

Peter decided to tie his car to point P and now he is wondering what is the area of the region that will be cleared from snow. Help him.

Input

The first line of the input contains three integers — the number of vertices of the polygon n (<image>), and coordinates of point P.

Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.

All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value.

Output

Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

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

Examples

Input

3 0 0
0 1
-1 2
1 2

Output

12.566370614359172464

Input

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

Output

21.991148575128551812

Note

In the first sample snow will be removed from that area:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long t = 1;
long double dis(pair<long long, long long> x, pair<long long, long long> y) {
  return (x.first - y.first) * (x.first - y.first) +
         (x.second - y.second) * (x.second - y.second);
}
bool check(pair<long long, long long> x, pair<long long, long long> y,
           pair<long long, long long> z) {
  if (x.first == y.first) {
    if ((x.second - z.second) * (y.second - z.second) <= 0)
      return true;
    else
      return false;
  }
  if (x.second == y.second) {
    if ((x.first - z.first) * (y.first - z.first) <= 0)
      return true;
    else
      return false;
  }
  long double m = (x.second - y.second) / (x.first - y.first + 0.0);
  long double m1 = -1 / (m);
  if ((m1 * (x.first - z.first) - x.second + z.second) *
          (m1 * (y.first - z.first) - y.second + z.second) <=
      0)
    return true;
  else
    return false;
}
long double shorestdis(pair<long long, long long> x,
                       pair<long long, long long> y,
                       pair<long long, long long> z) {
  if (check(x, y, z) == false) {
    return min(dis(x, z), dis(y, z));
  }
  if (x.first == y.first) {
    return (z.first - x.first) * (z.first - x.first);
  } else {
    long double m = (x.second - y.second) / (x.first - y.first + 0.0);
    long double d1 = m * z.first - z.second - m * x.first + x.second;
    d1 = d1 * d1;
    long double d2 = m * m + 1;
    return d1 / (d2 + 0.0);
  }
}
void solve() {
  long long n, x, y;
  pair<long long, long long> z;
  vector<pair<long long, long long> > vv;
  cin >> n >> z.first >> z.second;
  for (long long i = 1; i < n + 1; i += 1) {
    cin >> x >> y;
    vv.push_back(make_pair(x, y));
  }
  long double r = 1e18, R = 0;
  for (long long i = 0; i < n; i += 1) {
    pair<long long, long long> x, y;
    x = vv[i];
    y = vv[(i + 1) % n];
    r = min(r, shorestdis(x, y, z));
    R = max(R, dis(x, z));
  }
  cout << setprecision(20) << 3.14159265358979323846 * (R - r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (t--) solve();
  return 0;
}

```


### Prompt

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

DO YOU EXPECT ME TO FIND THIS OUT?

WHAT BASE AND/XOR LANGUAGE INCLUDES string?

DON'T BYTE OF MORE THAN YOU CAN CHEW

YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR

SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD

THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!

I HAVE NO ARRAY AND I MUST SCREAM

ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE

Input

The first line of input data contains a single integer n (1 ≤ n ≤ 10).

The second line of input data contains n space-separated integers ai (1 ≤ ai ≤ 11).

Output

Output a single integer.

Example

Input

4
2 5 3 1

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, MAX = -1, i;
  scanf("%d", &n);
  int a;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    MAX = max(a, MAX);
  }
  printf("%d\n", a ^ MAX);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.

Input

A single line with a positive integer k (1 ≤ k ≤ 10 000).

Output

A single number, denoting the k-th smallest perfect integer.

Examples

Input

1

Output

19

Input

2

Output

28

Note

The first perfect integer is 19 and the second one is 28.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, i = 18, j, temp, sum = 0;
  cin >> n;
  while (n) {
    i++;
    temp = i;
    sum = 0;
    while (temp) {
      sum += temp % 10;
      temp /= 10;
    }
    if (sum == 10) n--;
  }
  cout << i;
}

```


### Prompt

Generate a cpp solution to the following problem:

There is a sequence of length 2N: A_1, A_2, ..., A_{2N}. Each A_i is either -1 or an integer between 1 and 2N (inclusive). Any integer other than -1 appears at most once in {A_i}.

For each i such that A_i = -1, Snuke replaces A_i with an integer between 1 and 2N (inclusive), so that {A_i} will be a permutation of 1, 2, ..., 2N. Then, he finds a sequence of length N, B_1, B_2, ..., B_N, as B_i = min(A_{2i-1}, A_{2i}).

Find the number of different sequences that B_1, B_2, ..., B_N can be, modulo 10^9 + 7.

Constraints

* 1 \leq N \leq 300
* A_i = -1 or 1 \leq A_i \leq 2N.
* If A_i \neq -1, A_j \neq -1, then A_i \neq A_j. (i \neq j)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_{2N}

Output

Print the number of different sequences that B_1, B_2, ..., B_N can be, modulo 10^9 + 7.

Examples

Input

3
1 -1 -1 3 6 -1

Output

5

Input

4
7 1 8 3 5 2 6 4

Output

1

Input

10
7 -1 -1 -1 -1 -1 -1 6 14 12 13 -1 15 -1 -1 -1 -1 20 -1 -1

Output

9540576

Input

20
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 -1 -1 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 34 -1 -1 -1 -1 31 -1 -1 -1 -1 -1 -1 -1 -1

Output

374984201

### Response

```cpp
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=605;
const int mod=1e9+7;
int n,k;
int a[maxn],dp[2][maxn][maxn];
bool del[maxn],done[maxn];
void Add(int &a,int b){a+=b;if(a>=mod)a-=mod;}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	REP(i,n){
		scanf("%d%d",&a[2*i-1],&a[2*i]);
		if(a[2*i-1]<0&&a[2*i]<0)k++;
		else if(a[2*i-1]>0&&a[2*i]>0)del[a[2*i-1]]=del[a[2*i]]=true;
		else if(a[2*i-1]>0)done[a[2*i-1]]=true;
		else done[a[2*i]]=true;
	}
	int z=0;
	dp[z][0][0]=1;
	REP(i,2*n){
		if(del[i])continue;
		rep(j,2*n+1)rep(k,n+1)dp[z^1][j][k]=0;
		rep(j,2*n+1)rep(k,n+1){
			int cur=dp[z][j][k];
			if(!cur)continue;
			if(!done[i]){
				if(k)Add(dp[z^1][j][k-1],cur);
				Add(dp[z^1][j][k+1],cur);
				Add(dp[z^1][j+1][k],cur);
			}
			else{
				if(j)Add(dp[z^1][j-1][k],1LL*cur*j%mod);
				Add(dp[z^1][j][k+1],cur);
			}
		}
		z^=1;
	}
	int ans=dp[z][0][0];
	REP(i,k)ans=1LL*ans*i%mod;
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/

```


### Prompt

Please formulate a cpp solution to the following problem:

Carving the cake 2 (Cake 2)

JOI-kun and IOI-chan are twin brothers and sisters. JOI has been enthusiastic about making sweets lately, and JOI tried to bake a cake and eat it today, but when it was baked, IOI who smelled it came, so we decided to divide the cake. became.

The cake is round. We made radial cuts from a point, cut the cake into N pieces, and numbered the pieces counterclockwise from 1 to N. That is, for 1 ≤ i ≤ N, the i-th piece is adjacent to the i − 1st and i + 1st pieces (though the 0th is considered to be the Nth and the N + 1st is considered to be the 1st). The size of the i-th piece was Ai, but I was so bad at cutting that all Ai had different values.

<image>
Figure 1: Cake example (N = 5, A1 = 2, A2 = 8, A3 = 1, A4 = 10, A5 = 9)

I decided to divide these N pieces by JOI-kun and IOI-chan. I decided to divide it as follows:

1. First, JOI chooses and takes one of N.
2. After that, starting with IOI-chan, IOI-chan and JOI-kun alternately take the remaining pieces one by one. However, if you can only take a piece that has already been taken at least one of the pieces on both sides, and there are multiple pieces that can be taken, IOI will choose the largest one and JOI will take it. You can choose what you like.

JOI wants to maximize the total size of the pieces he will finally take.

Task

Given the number N of cake pieces and the size information of N pieces, create a program to find the maximum value of the total size of pieces that JOI can take.

input

Read the following input from standard input.

* The integer N is written on the first line, which means that the cake is cut into N pieces.
* The integer Ai is written on the i-th line (1 ≤ i ≤ N) of the following N lines, which indicates that the size of the i-th piece is Ai.

output

Output an integer representing the maximum value of the total size of pieces that JOI can take to the standard output on one line.

Limits

All input data satisfy the following conditions.

* 1 ≤ N ≤ 20000.
* 1 ≤ Ai ≤ 1 000 000 000.
* Ai are all different.

Input / output example

Input example 1

Five
2
8
1
Ten
9

Output example 1

18

JOI is best to take the pieces as follows.

1. JOI takes the second piece. The size of this piece is 8.
2. IOI takes the first piece. The size of this piece is 2.
3. JOI takes the 5th piece. The size of this piece is 9.
4. IOI takes the 4th piece. The size of this piece is 10.
5. JOI takes the third piece. The size of this piece is 1.

Finally, the total size of the pieces taken by JOI is 8 + 9 + 1 = 18.

Input example 2

8
1
Ten
Four
Five
6
2
9
3

Output example 2

26

Input example 3

15
182243672
10074562
977552215
122668426
685444213
3784162
463324752
560071245
134465220
21447865
654556327
183481051
20041805
405079805
564327789

Output example 3

3600242976

The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.

Example

Input

5
2
8
1
10
9

Output

18

### Response

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

ll memo[2020][2020];
int n;
vector<ll> a;

ll rec(int l, int len){
  if(memo[l][len]>=0)return memo[l][len];
  if(len <= 1)return 0;

  int L = l, R = (l+len-1)%n;
  if(a[L]<a[R])R = (R+n-1)%n;
  else L = (L+1)%n;

  return memo[l][len] = max(a[L]+rec((L+1)%n,len-2) , a[R]+rec(L,len-2));
}

int main(){
  cin >> n;
  a.resize(n);
  for(int i=0;i<n;i++)cin >> a[i];

  memset(memo,-1,sizeof(memo));
  ll res = 0;
  for(int i=0;i<n;i++){
    res = max( res, rec((i+1)%n,n-1) + a[i] );
  }
  cout << res << endl;
}
```