### Prompt

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

As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabetical order, each of them should put a hat on his head and, after some thought, the hat solemnly announces the name of the house the student should enter.

At that the Hat is believed to base its considerations on the student's personal qualities: it sends the brave and noble ones to Gryffindor, the smart and shrewd ones — to Ravenclaw, the persistent and honest ones — to Hufflepuff and the clever and cunning ones — to Slytherin. However, a first year student Hermione Granger got very concerned about the forthcoming sorting. She studied all the literature on the Sorting Hat and came to the conclusion that it is much simpler than that. If the relatives of the student have already studied at Hogwarts, the hat puts the student to the same house, where his family used to study. In controversial situations, when the relatives studied in different houses or when they were all Muggles like Hermione's parents, then the Hat sorts the student to the house, to which the least number of first years has been sent at that moment. If there are several such houses, the choice is given to the student himself. Then the student can choose any of the houses, to which the least number of first years has been sent so far.

Hermione has already asked the students that are on the list before her about their relatives. Now she and her new friends Harry Potter and Ron Weasley want to find out into what house the Hat will put Hermione.

Input

The first input line contains an integer n (1 ≤ n ≤ 10000). It is the number of students who are in the list before Hermione. The next line contains n symbols. If all the relatives of a student used to study in the same house, then the i-th character in the string coincides with the first letter of the name of this house. Otherwise, the i-th symbol is equal to "?".

Output

Print all the possible houses where Hermione can be sent. The names of the houses should be printed in the alphabetical order, one per line.

Examples

Input

11
G????SS???H

Output

Gryffindor
Ravenclaw

Input

2
H?

Output

Gryffindor
Ravenclaw
Slytherin

Note

Consider the second example. There are only two students before Hermione. The first student is sent to Hufflepuff. The second disciple is given the choice between the houses where the least number of students has been sent, i.e. Gryffindor, Slytherin and Ravenclaw. If he chooses Gryffindor, Hermione is forced to choose between Ravenclaw and Slytherin, if he chooses Ravenclaw, Hermione will choose between Gryffindor and Slytherin, if he chooses Slytherin, Hermione will choose between Gryffindor and Ravenclaw. In the end, the following situation is possible (it depends on the choice of the second student and Hermione). Hermione will end up 1) in Gryffindor, 2) in Ravenclaw, 3) in Slytherin. Note that, despite the fact that in neither case Hermione will be given a choice between all the three options, they are all possible and they should all be printed in the answer. Hermione will not, under any circumstances, end up in Hufflepuff.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
  int a[4];
  int t;
  bool operator<(const node &T) const { return t > T.t; }
} tmp;
string s[4] = {"Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"};
priority_queue<node> q;
map<pair<pair<int, int>, pair<int, int> >, int> mp;
pair<pair<int, int>, pair<int, int> > pp;
int main() {
  for (int i = 0; i < 4; i++) tmp.a[i] = 0;
  tmp.t = 0;
  q.push(tmp);
  int n;
  char str[11111];
  cin >> n >> str;
  mp[make_pair(make_pair(0, 0), make_pair(0, 0))] = 1;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'G') {
      while (!q.empty()) {
        tmp = q.top();
        if (tmp.t == i + 1) break;
        q.pop();
        tmp.a[0]++;
        pp = make_pair(make_pair(tmp.a[0], tmp.a[1]),
                       make_pair(tmp.a[2], tmp.a[3]));
        if (mp[pp] == 0) {
          tmp.t++;
          mp[pp] = 1;
          q.push(tmp);
        }
      }
    }
    if (str[i] == 'H') {
      while (!q.empty()) {
        tmp = q.top();
        if (tmp.t == i + 1) break;
        q.pop();
        tmp.a[1]++;
        pp = make_pair(make_pair(tmp.a[0], tmp.a[1]),
                       make_pair(tmp.a[2], tmp.a[3]));
        if (mp[pp] == 0) {
          tmp.t++;
          mp[pp] = 1;
          q.push(tmp);
        }
      }
    }
    if (str[i] == 'R') {
      while (!q.empty()) {
        tmp = q.top();
        if (tmp.t == i + 1) break;
        q.pop();
        tmp.a[2]++;
        pp = make_pair(make_pair(tmp.a[0], tmp.a[1]),
                       make_pair(tmp.a[2], tmp.a[3]));
        if (mp[pp] == 0) {
          tmp.t++;
          mp[pp] = 1;
          q.push(tmp);
        }
      }
    }
    if (str[i] == 'S') {
      while (!q.empty()) {
        tmp = q.top();
        if (tmp.t == i + 1) break;
        q.pop();
        tmp.a[3]++;
        pp = make_pair(make_pair(tmp.a[0], tmp.a[1]),
                       make_pair(tmp.a[2], tmp.a[3]));
        if (mp[pp] == 0) {
          tmp.t++;
          mp[pp] = 1;
          q.push(tmp);
        }
      }
    }
    if (str[i] == '?') {
      while (!q.empty()) {
        tmp = q.top();
        if (tmp.t == i + 1) break;
        q.pop();
        int mn = (1 << 30);
        for (int j = 0; j < 4; j++) mn = min(tmp.a[j], mn);
        for (int j = 0; j < 4; j++)
          if (tmp.a[j] == mn) {
            node tt = tmp;
            tt.a[j]++;
            pp = make_pair(make_pair(tt.a[0], tt.a[1]),
                           make_pair(tt.a[2], tt.a[3]));
            if (mp[pp] == 0) {
              tt.t++;
              mp[pp] = 1;
              q.push(tt);
            }
          }
      }
    }
  }
  int has[4] = {0};
  while (!q.empty()) {
    tmp = q.top();
    int mn = (1 << 30);
    for (int j = 0; j < 4; j++) mn = min(tmp.a[j], mn);
    for (int j = 0; j < 4; j++)
      if (tmp.a[j] == mn) has[j] = 1;
    q.pop();
  }
  for (int i = 0; i < 4; i++)
    if (has[i]) cout << s[i] << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

There is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N.

Takahashi is now in Room 1, and Room N has the exit. The i-th passage connects Room s_i and Room t_i (s_i < t_i) and can only be traversed in the direction from Room s_i to Room t_i. It is known that, for each room except Room N, there is at least one passage going from that room.

Takahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room 1 at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage.

Aoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room 1. However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room N.

Let E be the expected number of passages Takahashi takes before he reaches Room N. Find the value of E when Aoki makes a choice that minimizes E.

Constraints

* 2 \leq N \leq 600
* N-1 \leq M \leq \frac{N(N-1)}{2}
* s_i < t_i
* If i != j, (s_i, t_i) \neq (s_j, t_j). (Added 21:23 JST)
* For every v = 1, 2, ..., N-1, there exists i such that v = s_i.

Input

Input is given from Standard Input in the following format:

N M
s_1 t_1
:
s_M t_M

Output

Print the value of E when Aoki makes a choice that minimizes E. Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.

Examples

Input

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

Output

1.5000000000

Input

3 2
1 2
2 3

Output

2.0000000000

Input

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

Output

3.0133333333

### Response

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<vector<int>> G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u].emplace_back(v);
	}

	double dp0[600]={};
	for(int u=n-2;u>=0;u--){
		for(int v:G[u]){
			dp0[u]+=dp0[v];
		}
		dp0[u]=dp0[u]/G[u].size()+1;
	}

	double ans=1e77;
	double dp[600];
	rep(i,n){
		int j=-1;
		for(int k:G[i]){ if(j==-1 || dp0[j]<dp0[k]) j=k; }

		dp[n-1]=0;
		for(int u=n-2;u>=0;u--){
			dp[u]=0;
			int deg=0;
			for(int v:G[u]) if(u!=i || v!=j) {
				dp[u]+=dp[v];
				deg++;
			}
			dp[u]=dp[u]/deg+1;
		}
		ans=min(ans,dp[0]);
	}
	printf("%.15f\n",ans);

	return 0;
}

```


### Prompt

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

Twin adventurers Rin and Len are searching for treasure in the Mirror Cave. The cave has two pairs of rooms, the Hall of Mirrors, and an expensive treasure lies behind the door of the room.

For convenience, each of the two rooms is considered to have W × H cells arranged in a grid pattern. The outside of the room is surrounded by a wall. In addition, walls are installed in places inside the room, and it is not possible to enter the cells where the walls are located. To open the door to the treasure room, the two must move symmetrically to reach a particular cell at the same time. Moreover, if only one arrives first, the door will be locked and will not open.

Symmetrical movement means moving north and north, west and east, east and west, and south and south at the same time. However, it is recognized that the movement is symmetrical even in a situation where one has a wall at the end where it is trying to move and the other has no wall at the end. In this case, those with a wall will stay there, and those without a wall will move to the next cell.

As inputs, the initial position of the twins, the destination, and the placement of obstacles are given. Your job is to write a program to determine if the twins can open the door.

Input

The input consists of multiple datasets. Each dataset is given in the following format.

> W H
> RoomL1 RoomR1
> RoomL2 RoomR2
> ...
> RoomLH RoomRH

The first line gives two positive integers W, H (1 ≤ W, H ≤ 50) separated by a single space. After that, information on two rooms is given over H lines. RoomLi and RoomRi correspond to the i-th row of the left and right rooms, respectively. Both are strings of length W, with the jth character corresponding to the jth column of the room. Each character is one of the following:

* `.`: Freely moveable cell
* `#`: Cell with wall (cannot enter)
* `%`: Destination
* `R`: Initial position of Rin
* `L`: Initial position of Len

In each room, the first row corresponds to the north end of the room and the first row corresponds to the west end of the room. Also, each room always has exactly one destination, with exactly one initial position for Len in the left room and one for Rin in the right room.

The end of the input is indicated by a line containing two zeros separated by a blank.

Output

For each dataset, print Yes if the twins can open the door, and No if they can't.

Sample Input

5 5
% # ... ... #%
. #. #.. #. #.
. #. #.. #. #.
. #. #.. #. #.
... # L R # ...
3 2
.L. .R #
% .. .%.
4 1
L.%.% .. R
0 0

Output for the Sample Input

Yes
Yes
No

Example

Input

5 5
%#... ...#%
.#.#. .#.#.
.#.#. .#.#.
.#.#. .#.#.
...#L R#...
3 2
.L. .R#
%.. .%.
4 1
L.%. %..R
0 0

Output

Yes
Yes
No

### Response

```cpp
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int N = 52;
char l[N][N], r[N][N];
int dp[N][N][N][N];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int W, H; cin >> W >> H&&H;) {
		memset(l, 0, sizeof(l));
		memset(r, 0, sizeof(r));
		memset(dp, 0x3f, sizeof(dp));
		int sli, slj, sri, srj;
		int gli, glj, gri, grj;
		rep(i, 0, H) {
			rrep(j, 0, W) {
				cin >> l[i][j];
				if (l[i][j] == 'L') {
					sli = i, slj = j;
				}
				if (l[i][j] == '%') {
					gli = i, glj = j;
				}
			}
			rep(j, 0, W) {
				cin >> r[i][j];
				if (r[i][j] == 'R') {
					sri = i, srj = j;
				}
				if (r[i][j] == '%') {
					gri = i, grj = j;
				}
			}
		}
		using T = tuple<int, int, int, int, int>;
		queue<T> q;
		q.emplace(sli, slj, sri, srj, 0);
		auto inrange = [&](int i, int j) { return i >= 0 && i < H && j >= 0 && j < W; };
		while (q.size()) {
			int li, lj, ri, rj, c;
			tie(li, lj, ri, rj, c) = q.front(); q.pop();
			if (dp[li][lj][ri][rj] != INF)continue;
			if (li == gli && lj == glj && ri == gri && rj == grj) {
				cout << "Yes" << endl;
				dp[li][lj][ri][rj] = c;
				break;
			}
			else if (li == gli&&lj == glj) {
				continue;
			}
			else if (ri == gri&&rj == grj) {
				continue;
			}
			dp[li][lj][ri][rj] = c;
			static const int di[] = { 1,0,-1,0 };
			static const int dj[] = { 0,1,0,-1 };
			rep(k, 0, 4) {
				int nli = li + di[k],
					nlj = lj + dj[k],
					nri = ri + di[k],
					nrj = rj + dj[k];
				if (!inrange(nli, nlj) || l[nli][nlj] == '#')nli -= di[k], nlj -= dj[k];
				if (!inrange(nri, nrj) || r[nri][nrj] == '#')nri -= di[k], nrj -= dj[k];
				if (dp[nli][nlj][nri][nrj] != INF)continue;
				q.emplace(nli, nlj, nri, nrj, c + 1);
			}
		}
		//rep(li, 0, H)rep(lj, 0, W)rep(ri, 0, H)rep(rj, 0, W) {
		//	if (dp[li][lj][ri][rj] == INF)continue;
		//	dump(li, lj, ri, rj, dp[li][lj][ri][rj]);
		//}
		if (dp[gli][glj][gri][grj] == INF) {
			cout << "No" << endl;
		}
	}
	return 0;
}
```


### Prompt

Generate a cpp solution to the following problem:

One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.

If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.

To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.

Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.

We remind you that 1 byte contains 8 bits.

k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.

Input

The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.

The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.

Output

Print a single integer — the minimal possible number of changed elements.

Examples

Input

6 1
2 1 2 3 4 3

Output

2

Input

6 2
2 1 2 3 4 3

Output

0

Input

6 1
1 1 2 2 3 3

Output

2

Note

In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.

In the second example the disk is larger, so the initial file fits it and no changes are required.

In the third example we have to change both 1s or both 3s.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, raz, r = 0, ans = 0, dop = 0;
  cin >> n >> raz;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long k = 8 * raz / n;
  long long K = (k < 30 ? (1 << k) : n);
  for (long long l = 0; l < n; l++) {
    while (r < n) {
      if (l < r && a[r] == a[r - 1])
        r++;
      else {
        if (dop == K) break;
        dop++;
        r++;
      }
    }
    ans = max(ans, r - l);
    if (l < n - 1 && (l + 1 == r || a[l] != a[l + 1])) dop--;
  }
  cout << n - ans;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

In a far away galaxy there is war again. The treacherous Republic made k precision strikes of power ai on the Empire possessions. To cope with the republican threat, the Supreme Council decided to deal a decisive blow to the enemy forces.

To successfully complete the conflict, the confrontation balance after the blow should be a positive integer. The balance of confrontation is a number that looks like <image>, where p = n! (n is the power of the Imperial strike), <image>. After many years of war the Empire's resources are low. So to reduce the costs, n should be a minimum positive integer that is approved by the commanders.

Help the Empire, find the minimum positive integer n, where the described fraction is a positive integer.

Input

The first line contains integer k (1 ≤ k ≤ 106). The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 107).

Output

Print the minimum positive integer n, needed for the Empire to win.

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

Examples

Input

2
1000 1000

Output

2000

Input

1
2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 10000010;
long long l, r;
int n, a[1000010], maxr, vis[N];
int prime[N], cnt, mindiv[N];
bool ok[N];
long long tot[N];
inline void init() {
  for (int i = 2; i <= maxr; i++) {
    if (!ok[i]) {
      prime[++cnt] = i;
      mindiv[i] = cnt;
    }
    for (int j = 1; j <= cnt && i * prime[j] <= maxr; j++) {
      ok[i * prime[j]] = 1;
      mindiv[i * prime[j]] = j;
      if (i % prime[j] == 0) break;
    }
  }
  for (int i = 1; i <= maxr; i++) {
    int t = i;
    while (t > 1) {
      tot[mindiv[t]] += vis[i];
      t /= prime[mindiv[t]];
    }
  }
}
inline bool check(long long x) {
  for (int i = 1; i <= cnt; i++) {
    long long t = 0, p = prime[i];
    while (x / p) {
      t += x / p;
      p *= prime[i];
    }
    if (t < tot[i]) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), vis[a[i]]++, r += a[i], maxr = max(maxr, a[i]);
  for (int i = maxr; i >= 1; i--) vis[i] += vis[i + 1];
  init();
  l = 1;
  while (l <= r) {
    long long mid = l + r >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%I64d\n", l);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

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

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

Input

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

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

Output

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

Example

Input

6
1
2
3
4
5
100

Output

1
2
3
4
5
18

### Response

```cpp
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0 ; i<n ; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
const ll MX=1e6+2;
const ll MOD=1e9+7;

int main(){
    int t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll s=floor(log10(n))+1;
        vector<ll> A;
        rep(i,9){
            ll a=i+1,b=i+1;
            rep(j,s-1){
                b*=10;
                b+=a;
            }
            A.pb(b);
        }
        ll ans=0;
        for(auto el:A){
            if(el<=n)ans++;
        }
        ll an=9*(s-1)+ans;
        cout<<an<<endl;
    }
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

The Elements of Harmony are six supernatural artifacts representing subjective aspects of harmony. They are arguably the most powerful force in Equestria. The inside of Elements of Harmony can be seen as a complete graph with n vertices labeled from 0 to n - 1, where n is a power of two, equal to 2m.

<image>

The energy in Elements of Harmony is in constant movement. According to the ancient book, the energy of vertex u in time i (ei[u]) equals to:

<image>

Here b[] is the transformation coefficient — an array of m + 1 integers and f(u, v) is the number of ones in the binary representation of number (u xor v).

Given the transformation coefficient and the energy distribution at time 0 (e0[]). Help Twilight Sparkle predict the energy distribution at time t (et[]). The answer can be quite large, so output it modulo p.

Input

The first line contains three integers m, t and p (1 ≤ m ≤ 20; 0 ≤ t ≤ 1018; 2 ≤ p ≤ 109). The following line contains n (n = 2m) integers e0[i] (1 ≤ e0[i] ≤ 109; 0 ≤ i < n). The next line contains m + 1 integers b[i] (0 ≤ b[i] ≤ 109; 0 ≤ i ≤ m).

Output

Output n lines, the i-th line must contain a single integer et[i] modulo p.

Examples

Input

2 2 10000
4 1 2 3
0 1 0

Output

14
6
6
14

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, p;
long long mod;
long long a[1201000], b[1201000], c[1201000];
void fwt(long long* a) {
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      if (!(j >> i & 1)) {
        long long x = a[j], y = a[j | 1 << i];
        a[j] = (x + y) % mod;
        a[j | 1 << i] = (x - y + mod) % mod;
      }
}
long long mul(long long x, long long y) {
  long long tmp = x * y - (long long)((long double)x / mod * y + 0.5) * mod;
  return tmp < 0 ? tmp + mod : tmp;
}
long long power(long long x, long long y) {
  long long ret = 1;
  for (; y; y >>= 1, x = mul(x, x))
    if (y & 1) ret = mul(ret, x);
  return ret;
}
int main() {
  scanf("%lld%lld%lld", &m, &k, &p);
  n = 1 << m;
  mod = n * p;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]), a[i] %= mod;
  fwt(a);
  for (int i = 0; i <= m; i++) scanf("%lld", &b[i]), b[i] %= mod;
  for (int i = 0; i < n; i++) c[i] = b[__builtin_popcount(i)];
  fwt(c);
  for (int i = 0; i < n; i++) c[i] = mul(power(c[i] % mod, k), a[i]);
  fwt(c);
  for (int i = 0; i < n; i++) printf("%lld\n", c[i] / n);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Do you know "sed," a tool provided with Unix? Its most popular use is to substitute every occurrence of a string  contained in the input string (actually each input line) with another string β. More precisely, it proceeds as follows.

1. Within the input string, every non-overlapping (but possibly adjacent) occurrences of α are marked. If there is more than one possibility for non-overlapping matching, the leftmost one is chosen.
2. Each of the marked occurrences is substituted with β to obtain the output string; other parts of the input string remain intact.

For example, when α is "aa" and β is "bca", an input string "aaxaaa" will produce "bcaxbcaa", but not "aaxbcaa" nor "bcaxabca". Further application of the same substitution to the string "bcaxbcaa" will result in "bcaxbcbca", but this is another substitution, which is counted as the second one.

In this problem, a set of substitution pairs (αi, βi) (i = 1, 2, ... , n), an initial string γ, and a final string δ are given, and you must investigate how to produce δ from γ with a minimum number of substitutions. A single substitution (αi, βi) here means simultaneously substituting all the non-overlapping occurrences of αi, in the sense described above, with βi.

You may use a specific substitution (αi, βi ) multiple times, including zero times.

Input

The input consists of multiple datasets, each in the following format.

n
α1 β1
α2 β2
.
.
.
αn βn
γ δ

n is a positive integer indicating the number of pairs. αi and βi are separated by a single space. You may assume that 1 ≤ |αi| < |βi| ≤ 10 for any i (|s| means the length of the string s), αi ≠ αj for any i ≠ j, n ≤ 10 and 1 ≤ |γ| < |δ| ≤ 10. All the strings consist solely of lowercase letters. The end of the input is indicated by a line containing a single zero.

Output

For each dataset, output the minimum number of substitutions to obtain δ from γ. If δ cannot be produced from γ with the given set of substitutions, output -1.

Example

Input

2
a bb
b aa
a
bbbbbbbb
1
a aa
a
aaaaa
3
ab aab
abc aadc
ad dee
abc
deeeeeeeec
10
a abc
b bai
c acf
d bed
e abh
f fag
g abe
h bag
i aaj
j bbb
a
abacfaabe
0

Output

3
-1
7
4

### Response

```cpp
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;
set<string> ss;
vector<pair<string, string>> vs;
string s, t;

ll solve(string tt, int cnt) {
	//cout << tt << endl;
	if (tt == t)return cnt;
	if (tt.size() >= t.size() || ss.find(tt) != ss.end())return INF;
	//if (cnt > 3)return INF;
	ss.insert(tt);
	ll res = INF;
	rep(i, n) {
		//cout << "!" << i << " ";
		string nxt = "";
		rep(j, tt.size()) {
			ll num = tt.find(vs[i].first, j);
			if (num != string::npos) {
				nxt += tt.substr(j, num - j);
				j = num + vs[i].first.size() - 1;
				//cout << j << " ";
				nxt += vs[i].second;
			}
			else nxt += tt[j];
		}
		//cout << endl;
		res = min(res, solve(nxt, cnt + 1));
	}
	return res;
}

int main() {
	while (cin >> n&&n) {
		ss.clear();
		vs.clear();
		rep(i, n) {
			string ss, tt;
			cin >> ss >> tt;
			vs.push_back({ ss,tt });
		}
		cin >> s >> t;
		ll ans = solve(s, 0);
		if (ans == INF)cout << -1 << endl;
		else cout << ans << endl;
	}
}

```


### Prompt

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

The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.

A Bitlandish string is a string made only of characters "0" and "1".

BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.

The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.

So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.

You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.

Input

The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.

It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.

Output

Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.

Examples

Input

11
10

Output

YES

Input

1
01

Output

NO

Input

000
101

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, ss;
  cin >> s >> ss;
  if (s.length() != ss.length())
    cout << "NO" << endl;
  else {
    int flag1 = 0, flag2 = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') flag1 = 1;
      if (ss[i] == '1') flag2 = 1;
    }
    if (flag1 == flag2)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.

Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.

Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.

Input

The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).

Output

Print a single integer — the number of hours Vasily can light up the room for.

Examples

Input

4 2

Output

7

Input

6 3

Output

8

Note

Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int main() {
  int a, b, newa, newb;
  cin >> a >> b;
  bool flag = true;
  int ans = a;
  while (true) {
    newa = a;
    newa = a / b;
    if (newa == 0) break;
    newb = a % b;
    ans += newa;
    a = newa + newb;
  }
  cout << ans;
}

```


### Prompt

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

problem

In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.

* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.

The following is an example of a Bingo card when N = 5, M = 50, S = 685.

<image>

I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.

input

The input consists of multiple datasets. Each dataset is given in the following format.

The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.

When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.

output

For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.

Examples

Input

3 9 45
3 100 50
5 50 685
0 0 0

Output

1
7
74501

Input

None

Output

None

### Response

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

int n, m, s;
int dp[100][3010];

void solve(){
	n *= n;
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
	for(int i = 1; i <= m; i++){
		for(int j = n; j > 0; j--){
			for(int k = i; k <= s; k++){
				dp[j][k] = (dp[j][k]+dp[j-1][k-i])%100000;
			}
		}
	}
	printf("%d\n", dp[n][s]);
}

int main(){
	while(scanf("%d%d%d",&n,&m,&s),n||m||s) solve();
}
```


### Prompt

Please create a solution in cpp to the following problem:

Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is c meters.

For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).

Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.

Input

First line contains an integer n (1 ≤ n ≤ 100) — number of visits.

Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.

Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.

Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.

Output

Output one number — minimum distance in meters Winnie must go through to have a meal n times.

Examples

Input

3
2
3
1

Output

3

Input

1
2
3
5

Output

0

Note

In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.

In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n, r, S, Z, s1, s2, s3, s4, s5, s6, s7, s8, x, y, z, m, j, l, k,
      t;
  long long a[500005];
  long long b[300045];
  long long c[100001];
  long long d[100001];
  long long e[101][101];
  pair<long long, long long> aa[100001];
  double h, w, u, v, uu, vv;
  string q1;
  string q2;
  string q3;
  string q4;
  string s;
  string q;
  string sq[50005];
  string qs[3001];
  map<long long, long long> g;
  map<long long, long long>::iterator it;
  cin >> n >> s1 >> s2 >> s3;
  x = min(s1, min(s2, s3));
  if (n == 1) {
    cout << 0;
    exit(0);
  }
  if (x == s1 || x == s2) {
    cout << (n - 1) * x;
  } else {
    cout << min(s1, s2) + (n - 2) * x;
  }
}

```


### Prompt

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

The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.

<image>

One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.

What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)?

Input

The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump.

Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop.

Output

Print a single integer — the maximum number of candies Om Nom can eat.

Examples

Input

5 3
0 2 4
1 3 1
0 8 3
0 20 10
1 5 5

Output

4

Note

One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario:

  1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7.
  2. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12.
  3. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15.
  4. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> h1, h2, m1, m2;
  int t, h, m;
  for (int i = 0; i < n; i++) {
    cin >> t >> h >> m;
    if (t) {
      h1.push_back(h);
      m1.push_back(m);
    } else {
      h2.push_back(h);
      m2.push_back(m);
    }
  }
  int max = 0;
  int _x = x;
  for (int t = 1; t <= 2; t++) {
    vector<bool> e1(h1.size(), true), e2(h2.size(), true);
    int turn = t;
    x = _x;
    int count = 0;
    int p1 = 0;
    int p2 = 0;
    while (1) {
      if (turn == 1) {
        int m = 0;
        int idx = -1;
        for (int i = 0; i < h1.size(); i++) {
          if (e1[i] && h1[i] <= x) {
            if (m1[i] > m) {
              idx = i;
              m = m1[i];
            }
          }
        }
        if (idx != -1) {
          turn = 2;
          count++;
          x += m1[idx];
          e1[idx] = false;
        } else
          break;
      } else {
        int m = 0;
        int idx = -1;
        for (int i = 0; i < h2.size(); i++) {
          if (e2[i] && h2[i] <= x) {
            if (m2[i] > m) {
              idx = i;
              m = m2[i];
            }
          }
        }
        if (idx != -1) {
          turn = 1;
          count++;
          x += m2[idx];
          e2[idx] = false;
        } else
          break;
      }
    }
    if (count > max) max = count;
  }
  cout << max;
}

```


### Prompt

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

Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).

Now, he will perform the following operation exactly once:

* Choose K consecutive elements in P and sort them in ascending order.

Find the number of permutations that can be produced as P after the operation.

Constraints

* 2 \leq N \leq 200000
* 2 \leq K \leq N
* 0 \leq P_i \leq N-1
* P_0,P_1,\cdots,P_{N-1} are all different.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_0 P_1 \cdots P_{N-1}

Output

Print the number of permutations that can be produced as P after the operation.

Examples

Input

5 3
0 2 1 4 3

Output

2

Input

4 4
0 1 2 3

Output

1

Input

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

Output

6

### Response

```cpp
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  int n, k; cin >> n >> k;
  if (n==k) return puts("1") * 0e1;
  int p[n]; for(int i=0; i<n; i++) cin >> p[i];
  int an = 1;
  set<int> s;
  for(int i=0; i<k; i++) {
    s.insert(p[i]);
  }
  for(int i=0; i<n-k; i++) {
    s.insert(p[i+k]);
    auto b=s.begin(), e=s.end(); e--;
    //cout << *b << " " << *e << " " << p[i] << " " << p[i+k] << endl;
    if (!(*b == p[i] && *e == p[i+k])) an++;
    s.erase(p[i]);
  }

  bool nt = false; int bf=-1, ct=0;
  for(int i=0; i<n; i++) {
    if (bf<p[i]) ct++; else ct=1; bf=p[i];
    if (ct==k) {nt=1;an--;}
  }

  cout << an+nt << endl;
}

```


### Prompt

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

You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.

The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.

Input

The first line contains the only integer q (1 ≤ q ≤ 1013).

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

Output

In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.

Examples

Input

6

Output

2

Input

30

Output

1
6

Input

1

Output

1
0

Note

Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool prime(long long n) {
  if (n == 1) return true;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (long long i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
bool flag = false;
void check(long long n, bool p) {
  if (flag) return;
  vector<long long> v;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (!prime(i)) v.push_back(i);
      if (!prime(n / i)) v.push_back(n / i);
    }
  }
  if (v.size() == 0 && p) {
    flag = true;
    cout << 1 << endl << n << endl;
    return;
  }
  for (long long i = 0; i < v.size(); i++) check(v[i], !p);
}
int32_t main() {
  long long n;
  cin >> n;
  if (prime(n)) {
    cout << 1 << endl << 0 << endl;
    return 0;
  }
  check(n, 0);
  if (!flag) cout << 2 << endl;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes on the left scalepan, the fourth one goes on the right scalepan and so on. Xenia wants to put the total of m weights on the scalepans.

Simply putting weights on the scales is not interesting, so Xenia has set some rules. First, she does not put on the scales two consecutive weights of the same weight. That is, the weight that goes i-th should be different from the (i + 1)-th weight for any i (1 ≤ i < m). Second, every time Xenia puts a weight on some scalepan, she wants this scalepan to outweigh the other one. That is, the sum of the weights on the corresponding scalepan must be strictly greater than the sum on the other pan.

You are given all types of weights available for Xenia. You can assume that the girl has an infinite number of weights of each specified type. Your task is to help Xenia lay m weights on the scales or to say that it can't be done.

Input

The first line contains a string consisting of exactly ten zeroes and ones: the i-th (i ≥ 1) character in the line equals "1" if Xenia has i kilo weights, otherwise the character equals "0". The second line contains integer m (1 ≤ m ≤ 1000).

Output

In the first line print "YES", if there is a way to put m weights on the scales by all rules. Otherwise, print in the first line "NO". If you can put m weights on the scales, then print in the next line m integers — the weights' weights in the order you put them on the scales.

If there are multiple solutions, you can print any of them.

Examples

Input

0000000101
3

Output

YES
8 10 8

Input

1000000000
2

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << '\n';
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << '\n';
}
bool f[11] = {0};
long long m;
vector<long long> v;
bool dfs(long long x, long long y, long long k, vector<long long> r) {
  if (k == m) {
    cout << "YES" << '\n';
    dpv(r);
    return 1;
  }
  bool f1 = false;
  for (long long i = x + 1; i <= 10; i++) {
    if (f[i] && y != i) {
      r.push_back(i);
      f1 = dfs(i - x, i, k + 1, r);
      if (f1) {
        return true;
      }
      r.pop_back();
    }
  }
  return 0;
}
void oblivious() {
  string s;
  cin >> s;
  cin >> m;
  for (long long i = 1; i <= 10; i++) {
    f[i] = s[i - 1] - '0';
  }
  vector<long long> r;
  if (!dfs(0, 0, 0, r)) {
    cout << "NO" << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    oblivious();
  }
  return 0;
}

```


### Prompt

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

Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better names than his competitors, then he'll be at the top of the search results and will be a millionaire.

After doing some research, you find out that search engines only sort their results lexicographically. If your friend could rename his products to lexicographically smaller strings than his competitor's, then he'll be at the top of the rankings!

To make your strategy less obvious to his competitors, you decide to swap no more than two letters of the product names.

Please help Jeff to find improved names for his products that are lexicographically smaller than his competitor's!

Given the string s representing Jeff's product name and the string c representing his competitor's product name, find a way to swap at most one pair of characters in s (that is, find two distinct indices i and j and swap s_i and s_j) such that the resulting new name becomes strictly lexicographically smaller than c, or determine that it is impossible.

Note: String a is strictly lexicographically smaller than string b if and only if one of the following holds:

  * a is a proper prefix of b, that is, a is a prefix of b such that a ≠ b;
  * There exists an integer 1 ≤ i ≤ min{(|a|, |b|)} such that a_i < b_i and a_j = b_j for 1 ≤ j < i.

Input

The first line of input contains a single integer t (1 ≤ t ≤ 1500) denoting the number of test cases. The next lines contain descriptions of the test cases.

Each test case consists of a single line containing two space-separated strings s and c (2 ≤ |s| ≤ 5000, 1 ≤ |c| ≤ 5000). The strings s and c consists of uppercase English letters.

It is guaranteed that the sum of |s| in the input is at most 5000 and the sum of the |c| in the input is at most 5000.

Output

For each test case, output a single line containing a single string, which is either

  * the new name which is obtained after swapping no more than one pair of characters that is strictly lexicographically smaller than c. In case there are many possible such strings, you can output any of them;
  * three dashes (the string "---" without quotes) if it is impossible.

Example

Input

3
AZAMON APPLE
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA

Output

AMAZON
---
APPLE

Note

In the first test case, it is possible to swap the second and the fourth letters of the string and the resulting string "AMAZON" is lexicographically smaller than "APPLE".

It is impossible to improve the product's name in the second test case and satisfy all conditions.

In the third test case, it is possible not to swap a pair of characters. The name "APPLE" is lexicographically smaller than "BANANA". Note that there are other valid answers, e.g., "APPEL".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    long long i, j, x;
    long long m = s1.size();
    for (i = 0; i < m; i++) {
      x = i;
      for (j = m - 1; j > i; j--) {
        if (s1[j] < s1[x]) {
          x = j;
        }
      }
      if (x != i) {
        swap(s1[x], s1[i]);
        break;
      }
    }
    if (s1 < s2) {
      cout << s1 << endl;
    } else {
      cout << "---" << endl;
    }
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given three integers, A, B and C.
Among them, two are the same, but the remaining one is different from the rest.
For example, when A=5,B=7,C=5, A and C are the same, but B is different.
Find the one that is different from the rest among the given three integers.

Constraints

* -100 \leq A,B,C \leq 100
* A, B and C are integers.
* The input satisfies the condition in the statement.

Input

Input is given from Standard Input in the following format:

A B C

Output

Among A, B and C, print the integer that is different from the rest.

Examples

Input

5 7 5

Output

7

Input

1 1 7

Output

7

Input

-100 100 100

Output

-100

### Response

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

int main() {
	int a,b,c;cin>>a>>b>>c;
	int ans=a;
	if(a==b){
		ans=c;
	}else if(a==c){
		ans=b;
	}
	cout<<ans<<endl;
	return 0;
}

```


### Prompt

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

There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step.

You're given the initial arrangement of the psychos in the line. Calculate how many steps are needed to the moment of time such, that nobody kills his neighbor after that moment. Look notes to understand the statement more precise.

Input

The first line of input contains integer n denoting the number of psychos, (1 ≤ n ≤ 105). In the second line there will be a list of n space separated distinct integers each in range 1 to n, inclusive — ids of the psychos in the line from left to right.

Output

Print the number of steps, so that the line remains the same afterward.

Examples

Input

10
10 9 7 8 6 5 3 4 2 1

Output

2

Input

6
1 2 3 4 5 6

Output

0

Note

In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1]  →  [10 8 4] →  [10]. So, there are two steps.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
template <typename T>
T read() {
  char c = getchar();
  T sgn = 1;
  T t = 0;
  while (!isdigit(c)) {
    if (c == '-') sgn = -sgn;
    c = getchar();
  }
  while (isdigit(c)) {
    t *= 10;
    t += c - '0';
    c = getchar();
  }
  return t * sgn;
}
struct node {
  int id, val;
  node(int x, int y) : id(x), val(y) {}
};
const int N = 1e5 + 233;
int t[N], a[N];
stack<node> s;
int main() {
  int n = read<int>();
  for (int i = 0; i < n; ++i) a[i] = read<int>();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    node temp(0, 0);
    int sumn = 0;
    while (!s.empty()) {
      temp = s.top();
      if (temp.id < a[i]) {
        sumn = max(sumn, temp.val);
        s.pop();
      } else
        break;
    }
    if (s.empty())
      s.emplace(a[i], 0);
    else
      s.emplace(a[i], sumn + 1);
    ans = max(s.top().val, ans);
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

This problem is interactive.

We have hidden an array a of n pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.

This device can answer queries of the following form: in response to the positions of k different elements of the array, it will return the position and value of the m-th among them in the ascending order.

Unfortunately, the instruction for the device was lost during delivery. However, you remember k, but don't remember m. Your task is to find m using queries to this device.

You can ask not more than n queries.

Note that the array a and number m are fixed before the start of the interaction and don't depend on your queries. In other words, interactor is not adaptive.

Note that you don't have to minimize the number of queries, and you don't need to guess array a. You just have to guess m.

Input

The first line contains two integers n and k (1≤ k < n ≤ 500) — the length of the array and the number of the elements in the query.

It is guaranteed that number m satisfies 1≤ m ≤ k, elements a_1, a_2, ..., a_n of the array satisfy 0≤ a_i ≤ 10^9, and all of them are different.

Interaction

You begin the interaction by reading n and k.

To ask a question about elements on positions x_1, x_2, ..., x_k, in a separate line output

? x_1 x_2 x_3 ... x_k

Numbers in the query have to satisfy 1 ≤ x_i ≤ n, and all x_i have to be different. Don't forget to 'flush', to get the answer.

In response, you will receive two integers pos and a_{pos} — the position in the array a of the m-th in ascending order element among a_{x_1}, a_{x_2}, ..., a_{x_k}, and the element on this position.

In case your query is invalid or you asked more than n queries, the program will print -1 and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

When you determine m, output

! m

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, 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.

Hack format

For the hacks use the following format:

The first line has to contain three integers n, k, m (1 ≤ m ≤ k < n ≤ 500) — the length of the array, number of elements in the query, and which in the ascending order number the device returns.

In the next line output n integers a_1, a_2, ..., a_n (0≤ a_i ≤ 10^9) — the elements of the array. They have to be pairwise different.

Example

Input

4 3
4 9
4 9
4 9
1 2

Output

? 2 3 4
? 1 3 4
? 1 2 4
? 1 2 3
! 3

Note

In the example, n = 4, k = 3, m = 3, a = [2, 0, 1, 9].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k + 1; i++) {
    printf("? ");
    for (int j = 1; j <= k + 1; j++)
      if (j != i) printf("%d ", j);
    printf("\n");
    fflush(stdout);
    int ind, val;
    scanf("%d%d", &ind, &val);
    cnt[val]++;
  }
  int y = (*(--cnt.end())).second;
  printf("! %d", y);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).

Constraints

* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* 0 ≤ wi ≤ 10,000
* G has arborescence(s) with the root r

Input

|V| |E| r
s0 t0 w0
s1 t1 w1
:
s|E|-1 t|E|-1 w|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence.

si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.

Output

Print the sum of the weights the Minimum-Cost Arborescence.

Examples

Input

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

Output

6

Input

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

Output

11

### Response

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

using namespace std;

template< typename T, typename E = T >
struct SkewHeap {
  using G = function< T(T, E) >;
  using H = function< E(E, E) >;

  struct Node {
    T key;
    E lazy;
    Node *l, *r;
  };

  const bool rev;
  const G g;
  const H h;

  SkewHeap(bool rev = false) : g([](const T &a, const E &b) { return a + b; }),
                               h([](const E &a, const E &b) { return a + b; }), rev(rev) {}

  SkewHeap(const G &g, const H &h, bool rev = false) : g(g), h(h), rev(rev) {}

  Node *propagate(Node *t) {
    if(t->lazy != 0) {
      if(t->l) t->l->lazy = h(t->l->lazy, t->lazy);
      if(t->r) t->r->lazy = h(t->r->lazy, t->lazy);
      t->key = g(t->key, t->lazy);
      t->lazy = 0;
    }
    return t;
  }

  Node *merge(Node *x, Node *y) {
    if(!x || !y) return x ? x : y;
    propagate(x), propagate(y);
    if((x->key > y->key) ^ rev) swap(x, y);
    x->r = merge(y, x->r);
    swap(x->l, x->r);
    return x;
  }

  void push(Node *&root, const T &key) {
    root = merge(root, new Node({key, 0, nullptr, nullptr}));
  }

  T top(Node *root) {
    return propagate(root)->key;
  }

  void pop(Node *&root) {
    propagate(root);
    auto *temp = root;
    root = merge(root->l, root->r);
    delete temp;
  }

  bool empty(Node *root) const {
    return !root;
  }

  void add(Node *root, const E &lazy) {
    if(root) {
      root->lazy = h(root->lazy, lazy);
      propagate(root);
    }
  }

  Node *makeheap() {
    return nullptr;
  }
};

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
struct MinimumSpanningTreeArborescence {
  using Pi = pair< T, int >;
  using Heap = SkewHeap< Pi, int >;
  using Node = typename Heap::Node;
  const Edges< T > &es;
  const int V;
  T INF;

  MinimumSpanningTreeArborescence(const Edges< T > &es, int V) :
      INF(numeric_limits< T >::max()), es(es), V(V) {}

  T build(int start) {
    auto g = [](const Pi &a, const T &b) { return Pi(a.first + b, a.second); };
    auto h = [](const T &a, const T &b) { return a + b; };
    Heap heap(g, h);
    vector< Node * > heaps(V, heap.makeheap());
    for(auto &e : es) heap.push(heaps[e.to], {e.cost, e.src});
    UnionFind uf(V);
    vector< int > used(V, -1);
    used[start] = start;

    T ret = 0;
    for(int s = 0; s < V; s++) {
      stack< int > path;
      for(int u = s; used[u] < 0;) {
        path.push(u);
        used[u] = s;
        if(heap.empty(heaps[u])) return -1;
        auto p = heap.top(heaps[u]);
        ret += p.first;
        heap.add(heaps[u], -p.first);
        heap.pop(heaps[u]);
        int v = uf.find(p.second);
        if(used[v] == s) {
          int w;
          Node *nextheap = heap.makeheap();
          do {
            w = path.top();
            path.pop();
            nextheap = heap.merge(nextheap, heaps[w]);
          } while(uf.unite(v, w));
          heaps[uf.find(v)] = nextheap;
          used[uf.find(v)] = -1;
        }
        u = uf.find(v);
      }
    }
    return ret;
  }
};

int main() {
  int V, E, R;
  scanf("%d %d %d", &V, &E, &R);
  Edges< int > edges;
  for(int i = 0; i < E; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    edges.emplace_back(a, b, c);
  }
  printf("%d\n", MinimumSpanningTreeArborescence< int >(edges, V).build(R));
}

```


### Prompt

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

Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:

  * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb.
  * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine.
  * Masculine adjectives end with -lios, and feminine adjectives end with -liala.
  * Masculine nouns end with -etr, and feminime nouns end with -etra.
  * Masculine verbs end with -initis, and feminime verbs end with -inites.
  * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language.
  * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language.
  * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications.
  * A sentence is either exactly one valid language word or exactly one statement.

Statement is any sequence of the Petya's language, that satisfy both conditions:

  * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs.
  * All words in the statement should have the same gender.

After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.

Input

The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.

It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.

Output

If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).

Examples

Input

petr

Output

YES

Input

etis atis animatis etis atis amatis

Output

NO

Input

nataliala kataliala vetra feinites

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, pair<bool, int>> Data;
string msg = "";
void setData() {
  Data["lios"] = {1, 1};
  Data["liala"] = {0, 1};
  Data["etr"] = {1, 2};
  Data["etra"] = {0, 2};
  Data["initis"] = {1, 3};
  Data["inites"] = {0, 3};
}
pair<bool, int> find_out(string s) {
  string end = "";
  for (int i = (int)s.size() - 1; i >= 0 && (int)s.size() - i <= 6; --i) {
    end = s[i] + end;
    if ((int)s.size() - i == 3) {
      if (Data.find(end) != Data.end()) return Data[end];
    } else if ((int)s.size() - i == 4) {
      if (Data.find(end) != Data.end()) return Data[end];
    } else if ((int)s.size() - i == 5) {
      if (Data.find(end) != Data.end()) return Data[end];
    } else if ((int)s.size() - i == 6) {
      if (Data.find(end) != Data.end()) return Data[end];
    }
  }
  return {0, -1};
}
bool analize_grammar(vector<int> &g) {
  int i;
  int line = 1;
  bool ord = true;
  int aln = 0;
  for (i = 0; i < (int)g.size() - 1; ++i) {
    ord = ord & (g[i] <= g[i + 1]);
    aln += (g[i] == 2);
  }
  aln += (g[(int)g.size() - 1] == 2);
  return (aln == 1) && ord;
}
bool analize_gender(int &e, int &nw) { return ((e) ? e == nw : true); }
bool test_Word() { return find_out(msg) != pair<bool, int>(0, -1); }
bool test_Statement() {
  int e_gender = 0;
  int n_words = 0;
  vector<int> grammar;
  string s = "";
  for (int i = 0; i < (int)msg.size(); ++i) {
    if (msg[i] == ' ') {
      ++n_words;
      pair<bool, int> temp = find_out(s);
      if (temp == pair<bool, int>(0, -1)) return false;
      s = "";
      grammar.push_back(temp.second);
      e_gender += temp.first;
    } else {
      s.push_back(msg[i]);
    }
  }
  ++n_words;
  if (n_words == 1) return test_Word();
  pair<bool, int> temp = find_out(s);
  if (temp == pair<bool, int>(0, -1)) return false;
  s = "";
  grammar.push_back(temp.second);
  e_gender += temp.first;
  return analize_grammar(grammar) && analize_gender(e_gender, n_words);
}
int main() {
  setData();
  getline(cin, msg);
  if (test_Statement()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

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

Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.

Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.

Input

The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.

Output

Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.

Examples

Input

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

Output

11

Input

3
1 2 3
2
3 1 2
3 1 3

Output

-1

Note

In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
int a[N];
int vis[N];
int n;
struct edge {
  int from, to, w;
  bool operator<(const edge& e) const { return w > e.w; }
};
vector<edge> adj[N];
priority_queue<edge> q;
int MST() {
  int mstCost = 0;
  int edges = 0;
  while (!q.empty()) {
    edge e = q.top();
    q.pop();
    if (vis[e.to]) continue;
    vis[e.to] = 1;
    mstCost += e.w;
    ++edges;
    for (int j = 0; j < adj[e.to].size(); j++) {
      edge ne = adj[e.to][j];
      if (!vis[ne.to]) q.push(ne);
    }
  }
  if (edges != n - 1) return -1;
  return mstCost;
}
int main() {
  int m;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    --u, --v;
    adj[u].push_back(edge{u, v, w});
    q.push(edge{u, v, w});
  }
  printf("%d\n", MST());
}

```


### Prompt

Generate a CPP solution to the following problem:

Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.

We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ..., xr, where xi is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

<image>

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.

The second line contains n integers ai (0 ≤ ai ≤ 109).

The third line contains n integers bi (0 ≤ bi ≤ 109).

Output

Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

Examples

Input

5
1 2 4 3 2
2 3 3 12 1

Output

22

Input

10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6

Output

46

Note

Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation.

In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 and r = 5, l = 3 and r = 4, or l = 3 and r = 5.

In the second sample, the maximum value is obtained for l = 1 and r = 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1001], b[1001];
map<pair<int, int>, int> mapp;
int main(void) {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; ++i) {
    int xorr = 0;
    for (int j = i; j < n; ++j) {
      xorr |= a[j];
      mapp[make_pair(i, j)] = xorr;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int xorr = 0;
    for (int j = i; j < n; ++j) {
      xorr |= b[j];
      if (xorr + mapp[make_pair(i, j)] > ans) {
        ans = xorr + mapp[make_pair(i, j)];
      }
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given an undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition, each vertex has a label, `A` or `B`. The label of Vertex i is s_i. Edge i bidirectionally connects vertex a_i and b_i.

The phantom thief Nusook likes to choose some vertex as the startpoint and traverse an edge zero or more times. Today, he will make a string after traveling as above, by placing the labels of the visited vertices in the order visited, beginning from the startpoint.

For example, in a graph where Vertex 1 has the label `A` and Vertex 2 has the label `B`, if Nusook travels along the path 1 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 2, the resulting string is `ABABB`.

Determine if Nusook can make all strings consisting of `A` and `B`.

Constraints

* 2 \leq N \leq 2 \times 10^{5}
* 1 \leq M \leq 2 \times 10^{5}
* |s| = N
* s_i is `A` or `B`.
* 1 \leq a_i, b_i \leq N
* The given graph may NOT be simple or connected.

Input

Input is given from Standard Input in the following format:

N M
s
a_1 b_1
:
a_{M} b_{M}

Output

If Nusook can make all strings consisting of `A` and `B`, print `Yes`; otherwise, print `No`.

Examples

Input

2 3
AB
1 1
1 2
2 2

Output

Yes

Input

4 3
ABAB
1 2
2 3
3 1

Output

No

Input

13 23
ABAAAABBBBAAB
7 1
10 6
1 11
2 10
2 8
2 11
11 12
8 3
7 12
11 2
13 13
11 9
4 1
9 7
9 6
8 13
8 6
4 10
8 7
4 3
2 1
8 12
6 9

Output

Yes

Input

13 17
BBABBBAABABBA
7 1
7 9
11 12
3 9
11 9
2 1
11 5
12 11
10 8
1 11
1 8
7 7
9 10
8 8
8 12
6 2
13 11

Output

No

### Response

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

using namespace std;
const int N=2e5+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<1],nt[N<<1],hd[N],dg[N][2],tot=1;
void adde(int x,int y)
{
    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;
    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;
}
char cc[N];
int n,m,tt;
bool v[N];

int main()
{
    n=rd(),m=rd();
    scanf("%s",cc+1);
    for(int i=1;i<=m;++i)
    {
	int x=rd(),y=rd();
	adde(x,y);
	++dg[x][cc[y]-'A'],++dg[y][cc[x]-'A'];
    }
    queue<int> q;
    for(int i=1;i<=n;++i)
	if(!dg[i][0]||!dg[i][1]) v[i]=1,q.push(i);
    while(!q.empty())
    {
	int x=q.front();
	q.pop();
	++tt;
	for(int i=hd[x];i;i=nt[i])
	{
	    int y=to[i];
	    --dg[y][cc[x]-'A'];
	    if(!v[y]&&!dg[y][cc[x]-'A']) v[y]=1,q.push(y);
	}
    }
    puts(tt==n?"No":"Yes");
    return 0;
}

```


### Prompt

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

You are given a weighted tree (undirected connected graph with no cycles, loops or multiple edges) with n vertices. The edge \\{u_j, v_j\} has weight w_j. Also each vertex i has its own value a_i assigned to it.

Let's call a path starting in vertex u and ending in vertex v, where each edge can appear no more than twice (regardless of direction), a 2-path. Vertices can appear in the 2-path multiple times (even start and end vertices).

For some 2-path p profit Pr(p) = ∑_{v ∈ distinct vertices in  p}{a_v} - ∑_{e ∈ distinct edges in  p}{k_e ⋅ w_e}, where k_e is the number of times edge e appears in p. That is, vertices are counted once, but edges are counted the number of times they appear in p.

You are about to answer m queries. Each query is a pair of vertices (qu, qv). For each query find 2-path p from qu to qv with maximal profit Pr(p).

Input

The first line contains two integers n and q (2 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ q ≤ 4 ⋅ 10^5) — the number of vertices in the tree and the number of queries.

The second line contains n space-separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the values of the vertices.

Next n - 1 lines contain descriptions of edges: each line contains three space separated integers u_i, v_i and w_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i, 1 ≤ w_i ≤ 10^9) — there is edge \\{u_i, v_i\} with weight w_i in the tree.

Next q lines contain queries (one per line). Each query contains two integers qu_i and qv_i (1 ≤ qu_i, qv_i ≤ n) — endpoints of the 2-path you need to find.

Output

For each query print one integer per line — maximal profit Pr(p) of the some 2-path p with the corresponding endpoints.

Example

Input

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

Output

9
9
9
8
12
-14

Note

Explanation of queries:

  1. (1, 1) — one of the optimal 2-paths is the following: 1 → 2 → 4 → 5 → 4 → 2 → 3 → 2 → 1. Pr(p) = (a_1 + a_2 + a_3 + a_4 + a_5) - (2 ⋅ w(1,2) + 2 ⋅ w(2,3) + 2 ⋅ w(2,4) + 2 ⋅ w(4,5)) = 21 - 2 ⋅ 12 = 9.
  2. (4, 4): 4 → 2 → 1 → 2 → 3 → 2 → 4. Pr(p) = (a_1 + a_2 + a_3 + a_4) - 2 ⋅ (w(1,2) + w(2,3) + w(2,4)) = 19 - 2 ⋅ 10 = 9.
  3. (5, 6): 5 → 4 → 2 → 3 → 2 → 1 → 2 → 4 → 6.
  4. (6, 4): 6 → 4 → 2 → 1 → 2 → 3 → 2 → 4.
  5. (3, 4): 3 → 2 → 1 → 2 → 4.
  6. (3, 7): 3 → 2 → 1 → 2 → 4 → 5 → 4 → 2 → 3 → 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long N, Q;
map<long long, long long> adj[300000 + 1];
long long depth[300000 + 1];
long long dp[300000 + 1];
long long dp2[300000 + 1];
long long up[300000 + 1][20 + 1];
long long edgeSum[300000 + 1][20 + 1];
long long dpSum[300000 + 1][20 + 1];
long long f(long long u, long long v) {
  return max(dp2[v] - 2 * adj[u][v], 0LL);
}
void dfs1(long long node, long long par) {
  for (auto i : adj[node])
    if (i.first != par) {
      dfs1(i.first, node);
      dp2[node] += f(node, i.first);
    }
}
void dfs2(long long node, long long par) {
  dp[node] = dp2[node];
  for (auto i : adj[node]) {
    if (i.first == par) continue;
    dp2[node] -= f(node, i.first);
    dp2[i.first] += f(i.first, node);
    dfs2(i.first, node);
    dp2[i.first] -= f(i.first, node);
    dp2[node] += f(node, i.first);
  }
}
void dfs3(long long node, long long par) {
  depth[node] = depth[up[node][0] = par] + 1;
  dpSum[node][0] = dp2[node] - f(par, node);
  for (long long i = 1; i <= 20; i++) {
    dpSum[node][i] = dpSum[node][i - 1] + dpSum[up[node][i - 1]][i - 1];
    edgeSum[node][i] = edgeSum[node][i - 1] + edgeSum[up[node][i - 1]][i - 1];
    up[node][i] = up[up[node][i - 1]][i - 1];
  }
  for (auto i : adj[node])
    if (i.first != par) {
      edgeSum[i.first][0] = i.second;
      dfs3(i.first, node);
    }
}
pair<long long, long long> jmp(long long x, long long k) {
  long long ret = 0;
  for (long long i = 0; i <= 20; i++)
    if ((k >> i) & 1) {
      ret += dpSum[x][i];
      ret -= edgeSum[x][i];
      x = up[x][i];
    }
  return {x ? x : -1, ret};
}
long long query(long long a, long long b) {
  if (depth[a] < depth[b]) swap(a, b);
  long long ret = 0;
  pair<long long, long long> ans = jmp(a, depth[a] - depth[b]);
  a = ans.first, ret = ans.second;
  assert(a != -1);
  if (a == b) return ret + dp[a];
  for (long long i = 20; i >= 0; i--) {
    long long newA = up[a][i], newB = up[b][i];
    if (newA != newB) {
      ret += dpSum[a][i] + dpSum[b][i];
      ret -= edgeSum[a][i] + edgeSum[b][i];
      a = newA, b = newB;
    }
  }
  return ret + dpSum[a][0] + dpSum[b][0] - edgeSum[a][0] - edgeSum[b][0] +
         dp[up[a][0]];
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> Q;
  for (long long i = 1; i <= N; i++) cin >> dp2[i];
  for (long long i = 1; i < N; i++) {
    long long u, v, c;
    cin >> u >> v >> c;
    adj[u][v] = c;
    adj[v][u] = c;
  }
  dfs1(1, 0);
  dfs2(1, 0);
  dfs3(1, 0);
  for (long long i = 1; i <= Q; i++) {
    long long a, b;
    cin >> a >> b;
    cout << query(a, b) << "\n";
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.

Two pictures are considered to be different if the coordinates of corresponding rectangles are different.

Input

The first line of input contains four space-separated integers r, c, n, k (1 ≤ r, c, n ≤ 10, 1 ≤ k ≤ n) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.

The next n lines each contain two integers xi and yi (1 ≤ xi ≤ r, 1 ≤ yi ≤ c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.

Output

Print a single integer — the number of photographs Paul can take which include at least k violas.

Examples

Input

2 2 1 1
1 2

Output

4

Input

3 2 3 3
1 1
3 1
2 2

Output

1

Input

3 2 3 2
1 1
3 1
2 2

Output

4

Note

We will use '*' to denote violinists and '#' to denote violists.

In the first sample, the orchestra looks as follows

    *#
    **

Paul can take a photograph of just the viola, the 1 × 2 column containing the viola, the 2 × 1 row containing the viola, or the entire string section, for 4 pictures total.

In the second sample, the orchestra looks as follows

    #*
    *#
    #*

Paul must take a photograph of the entire section.

In the third sample, the orchestra looks the same as in the second sample.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int r, c, n, k, dp[105][105];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> r >> c >> n >> k;
  int x, y;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    dp[x][y]++;
  }
  for (int x1 = 1; x1 <= r; x1++)
    for (int fasdfasd = 1; fasdfasd <= c; fasdfasd++)
      for (int x2 = x1; x2 <= r; x2++)
        for (int y2 = fasdfasd; y2 <= c; y2++) {
          int cur = 0;
          for (int i = x1; i <= x2; i++)
            for (int j = fasdfasd; j <= y2; j++)
              if (dp[i][j]) cur++;
          if (cur >= k) ans++;
        }
  cout << ans << '\n';
  cout.flush();
  return 0;
}

```


### Prompt

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

Yeah, we failed to make up a New Year legend for this problem.

A permutation of length n is an array of n integers such that every integer from 1 to n appears in it exactly once.

An element y of permutation p is reachable from element x if x = y, or p_x = y, or p_{p_x} = y, and so on.

The decomposition of a permutation p is defined as follows: firstly, we have a permutation p, all elements of which are not marked, and an empty list l. Then we do the following: while there is at least one not marked element in p, we find the leftmost such element, list all elements that are reachable from it in the order they appear in p, mark all of these elements, then cyclically shift the list of those elements so that the maximum appears at the first position, and add this list as an element of l. After all elements are marked, l is the result of this decomposition.

For example, if we want to build a decomposition of p = [5, 4, 2, 3, 1, 7, 8, 6], we do the following:

  1. initially p = [5, 4, 2, 3, 1, 7, 8, 6] (bold elements are marked), l = [];
  2. the leftmost unmarked element is 5; 5 and 1 are reachable from it, so the list we want to shift is [5, 1]; there is no need to shift it, since maximum is already the first element;
  3. p = [5, 4, 2, 3, 1, 7, 8, 6], l = [[5, 1]];
  4. the leftmost unmarked element is 4, the list of reachable elements is [4, 2, 3]; the maximum is already the first element, so there's no need to shift it;
  5. p = [5, 4, 2, 3, 1, 7, 8, 6], l = [[5, 1], [4, 2, 3]];
  6. the leftmost unmarked element is 7, the list of reachable elements is [7, 8, 6]; we have to shift it, so it becomes [8, 6, 7];
  7. p = [5, 4, 2, 3, 1, 7, 8, 6], l = [[5, 1], [4, 2, 3], [8, 6, 7]];
  8. all elements are marked, so [[5, 1], [4, 2, 3], [8, 6, 7]] is the result.

The New Year transformation of a permutation is defined as follows: we build the decomposition of this permutation; then we sort all lists in decomposition in ascending order of the first elements (we don't swap the elements in these lists, only the lists themselves); then we concatenate the lists into one list which becomes a new permutation. For example, the New Year transformation of p = [5, 4, 2, 3, 1, 7, 8, 6] is built as follows:

  1. the decomposition is [[5, 1], [4, 2, 3], [8, 6, 7]];
  2. after sorting the decomposition, it becomes [[4, 2, 3], [5, 1], [8, 6, 7]];
  3. [4, 2, 3, 5, 1, 8, 6, 7] is the result of the transformation.

We call a permutation good if the result of its transformation is the same as the permutation itself. For example, [4, 3, 1, 2, 8, 5, 6, 7] is a good permutation; and [5, 4, 2, 3, 1, 7, 8, 6] is bad, since the result of transformation is [4, 2, 3, 5, 1, 8, 6, 7].

Your task is the following: given n and k, find the k-th (lexicographically) good permutation of length n.

Input

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

Then the test cases follow. Each test case is represented by one line containing two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 10^{18}).

Output

For each test case, print the answer to it as follows: if the number of good permutations of length n is less than k, print one integer -1; otherwise, print the k-th good permutation on n elements (in lexicographical order).

Example

Input

5
3 3
5 15
4 13
6 8
4 2

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mxN = 50;
const long long oo = 1ll << 60;
int n;
long long k, dp[mxN + 1], f[mxN + 1], g[mxN + 1];
bool b1[mxN];
long long add(long long a, long long b) {
  if (a + b <= oo) return a + b;
  return oo;
}
long long mult(long long a, long long b) {
  if (a <= oo / b) return a * b;
  return oo;
}
vector<int> rec2(int n, long long k) {
  vector<int> p(n);
  p[0] = n - 1;
  memset(b1, 0, n);
  b1[n - 1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (b1[j]) continue;
      p[i] = j;
      long long c;
      if (i < n - 1) {
        c = f[n - 2 - i];
        int b = j;
        while (b <= i) {
          if (b == i) break;
          b = p[b];
        }
        if (b == i) c = 0;
      } else
        c = 1;
      if (c <= k) {
        k -= c;
      } else {
        b1[j] = 1;
        break;
      }
    }
  }
  return p;
}
vector<int> rec1(int n, long long k) {
  if (!n) return vector<int>();
  for (int i = 1; i <= n; ++i) {
    if (mult(dp[n - i], g[i]) <= k) {
      k -= mult(dp[n - i], g[i]);
    } else {
      vector<int> w1 = rec2(i, k / dp[n - i]), w2 = rec1(n - i, k % dp[n - i]);
      for (int &wi : w2) wi += i;
      w1.insert(w1.end(), w2.begin(), w2.end());
      return w1;
    }
  }
}
void solve() {
  cin >> n >> k;
  if (dp[n] < k) {
    cout << "-1\n";
    return;
  }
  vector<int> v = rec1(n, k - 1);
  for (int i = 0; i < n; ++i) cout << v[i] + 1 << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  f[0] = 1;
  for (int i = 1; i <= mxN; ++i) f[i] = mult(f[i - 1], i);
  g[1] = 1;
  for (int i = 2; i <= mxN; ++i) g[i] = f[i - 2];
  dp[0] = 1;
  for (int i = 1; i <= mxN; ++i) {
    for (int j = 1; j <= i; ++j) dp[i] = add(dp[i], mult(dp[i - j], g[j]));
  }
  int t;
  cin >> t;
  while (t--) solve();
}

```


### Prompt

Create a solution in cpp for the following problem:

There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j).

In Cell (i, j), a_{ij} coins are placed.

You can perform the following operation any number of times:

Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.

Maximize the number of cells containing an even number of coins.

Constraints

* All values in input are integers.
* 1 \leq H, W \leq 500
* 0 \leq a_{ij} \leq 9

Input

Input is given from Standard Input in the following format:

H W
a_{11} a_{12} ... a_{1W}
a_{21} a_{22} ... a_{2W}
:
a_{H1} a_{H2} ... a_{HW}

Output

Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:

N
y_1 x_1 y_1' x_1'
y_2 x_2 y_2' x_2'
:
y_N x_N y_N' x_N'

That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations.

In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i').

Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer.

Examples

Input

2 3
1 2 3
0 1 1

Output

3
2 2 2 3
1 1 1 2
1 3 1 2

Input

3 2
1 0
2 1
1 0

Output

3
1 1 1 2
1 2 2 2
3 1 3 2

Input

1 5
9 9 9 9 9

Output

2
1 1 1 2
1 3 1 4

### Response

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<int> w(H*W),m(2*H*W);

  int i,j,k=0;
  for(i=0; i<H*W; i++){
    cin >> w.at(i);
  }

  for(i=0; i<H; i++){
    for(j=0; j<W-1; j++){
      if(w.at(i*W+j)%2 == 1){
        w.at(i*W+j)-=1;
        w.at(i*W+j+1)+=1;
        m.at(2*k)=i*W+j;
        m.at(2*k+1)=i*W+j+1;
        k++;
      }
    }
  }

  for(i=0; i<H-1; i++){
    if(w.at((i+1)*W-1)%2 == 1){
        w.at((i+1)*W-1)-=1;
        w.at((i+2)*W-1)+=1;
        m.at(2*k)=(i+1)*W-1;
        m.at(2*k+1)=(i+2)*W-1;
        k++;
    }
  }

  cout << k << endl;
  for(i=0; i<k; i++){
    cout << m.at(2*i)/W+1 << " " << m.at(2*i)%W+1 << " " << m.at(2*i+1)/W+1 << " " << m.at(2*i+1)%W+1 << endl;
  }
}
```


### Prompt

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

Karen has just arrived at school, and she has a math test today!

<image>

The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.

There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.

Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.

The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.

Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?

Since this number can be quite large, output only the non-negative remainder after dividing it by 109 + 7.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row.

The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.

Output

Output a single integer on a line by itself, the number on the final row after performing the process above.

Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.

Examples

Input

5
3 6 9 12 15

Output

36

Input

4
3 7 5 2

Output

1000000006

Note

In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.

Karen performs the operations as follows:

<image>

The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output.

In the second test case, the numbers written on the first row are 3, 7, 5 and 2.

Karen performs the operations as follows:

<image>

The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6, so this is the correct output.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void get(int &v) {
  char c;
  while ((c = getchar()) != EOF && isdigit(c) == 0)
    ;
  v = c - '0';
  while ((c = getchar()) != EOF && isdigit(c))
    v = (v << 3) + (v << 1) + c - '0';
  return;
}
int pow_mod(long long a, int x) {
  int ans = 1;
  while (x) {
    if (x & 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007;
    x >>= 1;
  }
  return ans;
}
int a[200000 + 80];
int main() {
  int n, i, ans = 0;
  long long f = 1, tmp;
  get(n);
  for (i = 1; i <= n; i++) get(a[i]);
  switch (n % 4) {
    case 0:
      for (i = 1; i <= (n >> 1); i++) {
        ans = (ans + (a[(i << 1) - 1] - a[(i << 1)]) * f) % 1000000007;
        f = f * ((n >> 1) - i) % 1000000007 * pow_mod(i, 1000000007 - 2) %
            1000000007;
      }
      break;
    case 1:
      for (i = 0; i <= (n >> 1); i++) {
        ans = (ans + a[(i << 1) + 1] * f) % 1000000007;
        f = f * ((n >> 1) - i) % 1000000007 * pow_mod(i + 1, 1000000007 - 2) %
            1000000007;
      }
      break;
    case 2:
      for (i = 1; i <= (n >> 1); i++) {
        ans = (ans + (a[(i << 1) - 1] + a[(i << 1)]) * f) % 1000000007;
        f = f * ((n >> 1) - i) % 1000000007 * pow_mod(i, 1000000007 - 2) %
            1000000007;
      }
      break;
    case 3:
      ans = a[1];
      for (i = 1; i <= (n >> 1); i++) {
        ans = (ans + ((a[i << 1] * f) << 1)) % 1000000007;
        tmp = f;
        f = f * ((n >> 1) - i) % 1000000007 * pow_mod(i, 1000000007 - 2) %
            1000000007;
        ans = (ans + (f - tmp) * a[(i << 1) + 1]) % 1000000007;
      }
      break;
  }
  printf("%d", (ans + 1000000007) % 1000000007);
  return 0;
}

```


### Prompt

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

Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.

In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.

Your problem is to print the minimum possible length of the sequence of moves after the replacements.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 100) — the length of the sequence. The second line contains the sequence consisting of n characters U and R.

Output

Print the minimum possible length of the sequence of moves after all replacements are done.

Examples

Input

5
RUURU

Output

3

Input

17
UUURRRRRUUURURUUU

Output

13

Note

In the first test the shortened sequence of moves may be DUD (its length is 3).

In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int MAXN = 1000100;
char s[110];
int main() {
  int n;
  cin >> n;
  char c;
  int r = 0, u = 0;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  int ans = n;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'U' && s[i + 1] == 'R' || s[i] == 'R' && s[i + 1] == 'U') {
      --ans;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.

There are n stages available. The rocket must contain exactly k of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.

For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — 26 tons.

Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.

Input

The first line of input contains two integers — n and k (1 ≤ k ≤ n ≤ 50) – the number of available stages and the number of stages to use in the rocket.

The second line contains string s, which consists of exactly n lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.

Output

Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.

Examples

Input

5 3
xyabd

Output

29

Input

7 4
problem

Output

34

Input

2 2
ab

Output

-1

Input

12 1
abaabbaaabbb

Output

1

Note

In the first example, the following rockets satisfy the condition:

  * "adx" (weight is 1+4+24=29);
  * "ady" (weight is 1+4+25=30);
  * "bdx" (weight is 2+4+24=30);
  * "bdy" (weight is 2+4+25=31).

Rocket "adx" has the minimal weight, so the answer is 29.

In the second example, target rocket is "belo". Its weight is 2+5+12+15=34.

In the third example, n=k=2, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int n, k;
  cin >> n >> k;
  set<char> st;
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) st.insert(s[i]);
  int res = 0;
  char lastc = 0;
  int i;
  for (i = 0; i < k && !st.empty(); ++i) {
    auto it = st.begin();
    char c = *it;
    st.erase(it);
    if (*it - lastc < 2)
      --i;
    else {
      res += int(c - 'a' + 1);
      lastc = c;
    }
  }
  if (i == k)
    cout << res << "\n";
  else
    cout << -1 << "\n";
  return 0;
}

```