### Prompt

Construct a cpp code solution to the problem outlined:

Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here, it is abbreviated as JOI.

JOI is conducting research to confine many microorganisms in one petri dish alive. There are N microorganisms to be investigated, and they are numbered 1, 2, ..., N. When each microorganism is trapped in a petri dish, it instantly releases a harmful substance called foo (fatally odd object) into the petri dish. The amount of foo released by each microorganism is known. The foo released by all the microorganisms trapped in the petri dish is evenly ingested by each microorganism in the petri dish. The foo tolerance of each microorganism is known, and if foo is ingested in excess of this amount, the microorganism will die.

The foo release amount of the microorganism i is ai milligrams, and the foo tolerance is bi milligrams. That is, when the microorganisms i1, i2, ..., ik are trapped in the petri dish, each microorganism in the petri dish ingests (ai1 + ai2 + ... + aik) / k milligrams of foo, and the microorganisms in the petri dish ingest. i will die if this intake is greater than bi.

On behalf of JOI, you must keep as many microorganisms alive in the petri dish as possible. However, no microbes in the petri dish should die from ingestion of foo, as carcasses of microorganisms adversely affect the environment in the petri dish.

It is still a mystery how JOI profits from making "just a strange invention", and no one in JOI knows except the president.

input

Read the following input from standard input.

* The integer N is written on the first line, which indicates that there are N microorganisms to be investigated.
* The following N lines contain information on each microorganism. On the first line of i + (1 ≤ i ≤ N), the positive integers ai and bi are written separated by blanks, and the foo emission amount of the microorganism i is ai milligrams and the foo tolerance is bi milligrams. Represent.

output

Output the maximum number of microorganisms that can be confined in one petri dish to the standard output in one line.

Example

Input

6
12 8
5 9
2 4
10 12
6 7
13 9

Output

3

### Response

```cpp
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;
typedef pair<int,int> P;
typedef long long ll;
int n;
P f[300001];
int k[300001];

bool C(int num){
	multiset<int> S;
	ll sum=0;
	for(int i=n-1;i>=0;i--){
		sum+=f[i].second;
		S.insert(f[i].second);
		if(S.size()<num)continue;
		if(S.size()>num){
			sum-=*S.rbegin();
			S.erase(--S.end());
		}
		if((ll)num*f[i].first>=sum)return true;
	}
	return false;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&f[i].second,&f[i].first);
	}
	sort(f,f+n);
	int lb=0,ub=n+1;
	while(ub-lb>1){
		int mid=(lb+ub)/2;
		if(C(mid))lb=mid;
		else ub=mid;
	}
	printf("%d\n",lb);
	return 0;
}
```


### Prompt

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

Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix s.

Input

The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.

Output

If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal address of one of the visited pages starting from s.

The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.

Examples

Input

next
2
nextpermutation
nextelement

Output

nextelement

Input

find
4
find
findfirstof
findit
fand

Output

find

Input

find
4
fondfind
fondfirstof
fondit
fand

Output

find

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 100;
vector<string> arr;
int main() {
  string s, w;
  int x;
  cin >> s >> x;
  for (int i = 0; i < x; ++i) {
    cin >> w;
    if (s.size() <= w.size() && w.substr(0, s.size()) == s) arr.push_back(w);
  }
  sort(arr.begin(), arr.end());
  if (arr.size())
    cout << arr[0] << endl;
  else
    cout << s << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can jump out of the window. He knows values of all ladies and wants to find out how many probable self-murderers will be on the ball. Lets denote beauty of the i-th lady by Bi, her intellect by Ii and her richness by Ri. Then i-th lady is a probable self-murderer if there is some j-th lady that Bi < Bj, Ii < Ij, Ri < Rj. Find the number of probable self-murderers.

Input

The first line contains one integer N (1 ≤ N ≤ 500000). The second line contains N integer numbers Bi, separated by single spaces. The third and the fourth lines contain sequences Ii and Ri in the same format. It is guaranteed that 0 ≤ Bi, Ii, Ri ≤ 109.

Output

Output the answer to the problem.

Examples

Input

3
1 4 2
4 3 2
2 5 3

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
const int maxn = 5e5 + 1, inf = 1e9 + 1;
int fen[3 * maxn], n, x[maxn], y[maxn], z[maxn], ans;
vector<int> w;
vector<pair<int, int> > query[maxn];
int ID(int x) { return upper_bound(w.begin(), w.end(), x) - w.begin(); }
void mini(int x, int y) {
  for (; x < maxn; x = x + (x & (-x))) {
    fen[x] = max(fen[x], y);
  }
  return;
}
int get(int x) {
  int res = 0;
  for (; x > 0; x = x - (x & (-x))) {
    res = max(res, fen[x]);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t1;
    cin >> t1;
    x[i] = t1;
    w.push_back(t1);
  }
  for (int i = 1; i <= n; i++) {
    int t1;
    cin >> t1;
    y[i] = t1;
    w.push_back(t1);
  }
  for (int i = 1; i <= n; i++) {
    int t1;
    cin >> t1;
    z[i] = t1;
    w.push_back(t1);
  }
  sort(w.begin(), w.end());
  w.resize(unique(w.begin(), w.end()) - w.begin());
  for (int i = 1; i <= n; i++) {
    x[i] = ID(x[i]);
    y[i] = ID(y[i]);
    z[i] = ID(z[i]);
    query[x[i]].push_back({y[i], z[i]});
  }
  for (int i = maxn - 1; i >= 1; i--) {
    for (auto tmp : query[i]) {
      int t = get(maxn - 1 - tmp.first);
      if (t > tmp.second) {
        ans++;
      }
    }
    for (auto tmp : query[i]) {
      mini(maxn - tmp.first, tmp.second);
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.

There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).

Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.

Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!

Input

The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.

Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).

The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.

The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).

Output

If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.

Examples

Input

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

Output

26

Input

1 1 1 1
1
1
1
1
1
1 1
0
0

Output

-1

Note

The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.

In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <complex>
#include <functional>

using namespace std;

typedef long long ll;

typedef struct node {
    int num;
    int val;
    int mini;
    node(int nn = 0, int v = 0, int m = 0) : num(nn), val(v), mini(m) { }
} node;

typedef struct edge {
    int x, y;
    edge(int xx = 0, int yy = 0) : x(xx), y(yy) { }
} edge;

inline bool cmp1(node a, node b) {
    if(a.val == b.val) return a.num < b.num;
    return a.val < b.val;
}

inline bool cmp2(edge a, edge b) {
    if(a.y == b.y) return a.x < b.x;
    return a.y < b.y;
}

int n[4];
node v[4][150000 + 10];
int match[4][150000 + 10];
int m[4];
vector<int> e[4][150000];
int ans = 0x3f3f3f3f;

int main()
{
    for(int i = 0;i < 4; i++)  {
        scanf("%d", &n[i]);
    }
    int vv;
    for(int i = 0;i < 4; i++) {
        for(int j = 0;j < n[i]; j++) {
            scanf("%d", &vv);
            v[i][j] = node(j, vv, 0);
        }
    }
    for(int i = 1;i < 4; i++) {
        scanf("%d", &m[i]);
        sort(v[i - 1], v[i - 1] + n[i - 1], cmp1);
        for(int j = 0;j < n[i - 1]; j++) {
            match[i - 1][v[i - 1][j].num] = j;
        }
        for(int j = 0;j < m[i]; j++) {
            int x, y;
            scanf("%d%d", &x, &y);
            x--; //输入下标从1开始，我下标从0开始
            y--;
            e[i][y].push_back(match[i - 1][x]);
        }
        for(int j = 0;j < n[i]; j++) {
            sort(e[i][j].begin(), e[i][j].end());
            if(e[i][j].size() == 0) continue;
            int tot = e[i][j].size();
            int cur = 0;
            while(v[i][j].mini == e[i][j][cur]) {
                cur++;
                v[i][j].mini++;
                if(cur >= tot) break;
            }
        }
        for(int j = 0;j < n[i]; j++) {
            int front = v[i][j].mini;
            if(front >= n[i - 1]) v[i][j].val = 0x3f3f3f3f;
            v[i][j].val += v[i - 1][front].val;
            if(i == 3) ans = min(ans, v[i][j].val);
        }
    }
    if(ans >= 0x3f3f3f3f) printf("-1\n");
    else printf("%d\n", ans);
    return 0;
}
/*
4 3 2 1
4 3 2 1
7 6 5
9 8
10
2
1 2
1 1
2
3 1
3 2
1
1 1
*/
```


### Prompt

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

You have matrix a of size n × n. Let's number the rows of the matrix from 1 to n from top to bottom, let's number the columns from 1 to n from left to right. Let's use aij to represent the element on the intersection of the i-th row and the j-th column.

Matrix a meets the following two conditions:

  * for any numbers i, j (1 ≤ i, j ≤ n) the following inequality holds: aij ≥ 0;
  * <image>.

Matrix b is strictly positive, if for any numbers i, j (1 ≤ i, j ≤ n) the inequality bij > 0 holds. You task is to determine if there is such integer k ≥ 1, that matrix ak is strictly positive.

Input

The first line contains integer n (2 ≤ n ≤ 2000) — the number of rows and columns in matrix a.

The next n lines contain the description of the rows of matrix a. The i-th line contains n non-negative integers ai1, ai2, ..., ain (0 ≤ aij ≤ 50). It is guaranteed that <image>.

Output

If there is a positive integer k ≥ 1, such that matrix ak is strictly positive, print "YES" (without the quotes). Otherwise, print "NO" (without the quotes).

Examples

Input

2
1 0
0 1

Output

NO

Input

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

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, gr;
vector<char> used;
vector<int> order, component;
void dfs1(int v) {
  used[v] = true;
  for (size_t i = 0; i < g[v].size(); ++i)
    if (!used[g[v][i]]) dfs1(g[v][i]);
  order.push_back(v);
}
void dfs2(int v) {
  used[v] = true;
  component.push_back(v);
  for (size_t i = 0; i < gr[v].size(); ++i)
    if (!used[gr[v][i]]) dfs2(gr[v][i]);
}
int main() {
  int n;
  scanf("%d", &n);
  g.resize(n + 5);
  gr.resize(n + 5);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; ++j) {
      int k;
      scanf("%d", &k);
      if (k > 0 && i != j) {
        g[i].push_back(j);
        gr[j].push_back(i);
      }
    }
  }
  used.assign(n, false);
  for (int i = 0; i < n; ++i)
    if (!used[i]) dfs1(i);
  used.assign(n, false);
  int cc = 0;
  for (int i = 0; i < n; ++i) {
    int v = order[n - 1 - i];
    if (!used[v]) {
      dfs2(v);
      ++cc;
      component.clear();
    }
  }
  if (cc == 1) {
    printf("YES\n");
  } else
    printf("NO\n");
  return 0;
}

```


### Prompt

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

Lunar New Year is approaching, and you bought a matrix with lots of "crosses".

This matrix M of size n × n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≤ i, j ≤ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) =  'X'.

The following figure illustrates a cross appearing at position (2, 2) in a 3 × 3 matrix.

    X.X
    .X.
    X.X

Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns.

Input

The first line contains only one positive integer n (1 ≤ n ≤ 500), denoting the size of the matrix M.

The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≤ i, j ≤ n.

Output

Output a single line containing only one integer number k — the number of crosses in the given matrix M.

Examples

Input

5
.....
.XXX.
.XXX.
.XXX.
.....

Output

1

Input

2
XX
XX

Output

0

Input

6
......
X.X.X.
.X.X.X
X.X.X.
.X.X.X
......

Output

4

Note

In the first sample, a cross appears at (3, 3), so the answer is 1.

In the second sample, no crosses appear since n < 3, so the answer is 0.

In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char a[n + 1][n + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  if (n < 3) {
    cout << "0";
    return 0;
  }
  int c = 0;
  int x, y;
  for (int i = 2; i <= n - 1; i++) {
    for (int j = 2; j <= n - 1; j++) {
      if (a[i][j] == 'X' && a[i + 1][j + 1] == 'X' && a[i + 1][j - 1] == 'X' &&
          a[i - 1][j + 1] == 'X' && a[i - 1][j - 1] == 'X' &&
          (x != i || y != j)) {
        x = i;
        y = j;
        c++;
      }
    }
  }
  cout << c;
  return 0;
}

```


### Prompt

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

Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes.

The exam consists of n problems that can be solved in T minutes. Thus, the exam begins at time 0 and ends at time T. Petya can leave the exam at any integer time from 0 to T, inclusive.

All problems are divided into two types:

  * easy problems — Petya takes exactly a minutes to solve any easy problem;
  * hard problems — Petya takes exactly b minutes (b > a) to solve any hard problem.

Thus, if Petya starts solving an easy problem at time x, then it will be solved at time x+a. Similarly, if at a time x Petya starts to solve a hard problem, then it will be solved at time x+b.

For every problem, Petya knows if it is easy or hard. Also, for each problem is determined time t_i (0 ≤ t_i ≤ T) at which it will become mandatory (required). If Petya leaves the exam at time s and there is such a problem i that t_i ≤ s and he didn't solve it, then he will receive 0 points for the whole exam. Otherwise (i.e if he has solved all such problems for which t_i ≤ s) he will receive a number of points equal to the number of solved problems. Note that leaving at time s Petya can have both "mandatory" and "non-mandatory" problems solved.

For example, if n=2, T=5, a=2, b=3, the first problem is hard and t_1=3 and the second problem is easy and t_2=2. Then:

  * if he leaves at time s=0, then he will receive 0 points since he will not have time to solve any problems;
  * if he leaves at time s=1, he will receive 0 points since he will not have time to solve any problems;
  * if he leaves at time s=2, then he can get a 1 point by solving the problem with the number 2 (it must be solved in the range from 0 to 2);
  * if he leaves at time s=3, then he will receive 0 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
  * if he leaves at time s=4, then he will receive 0 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
  * if he leaves at time s=5, then he can get 2 points by solving all problems.

Thus, the answer to this test is 2.

Help Petya to determine the maximal number of points that he can receive, before leaving the exam.

Input

The first line contains the integer m (1 ≤ m ≤ 10^4) — the number of test cases in the test.

The next lines contain a description of m test cases.

The first line of each test case contains four integers n, T, a, b (2 ≤ n ≤ 2⋅10^5, 1 ≤ T ≤ 10^9, 1 ≤ a < b ≤ 10^9) — the number of problems, minutes given for the exam and the time to solve an easy and hard problem, respectively.

The second line of each test case contains n numbers 0 or 1, separated by single space: the i-th number means the type of the i-th problem. A value of 0 means that the problem is easy, and a value of 1 that the problem is hard.

The third line of each test case contains n integers t_i (0 ≤ t_i ≤ T), where the i-th number means the time at which the i-th problem will become mandatory.

It is guaranteed that the sum of n for all test cases does not exceed 2⋅10^5.

Output

Print the answers to m test cases. For each set, print a single integer — maximal number of points that he can receive, before leaving the exam.

Example

Input

10
3 5 1 3
0 0 1
2 1 4
2 5 2 3
1 0
3 2
1 20 2 4
0
16
6 20 2 5
1 1 0 1 0 0
0 8 2 9 11 6
4 16 3 6
1 0 1 1
8 3 5 6
6 20 3 6
0 1 0 0 1 0
20 11 3 20 16 17
7 17 1 6
1 1 0 1 0 0 0
1 7 0 11 10 15 10
6 17 2 6
0 0 1 0 0 1
7 6 3 7 10 12
5 17 2 5
1 1 1 1 0
17 11 10 6 4
1 1 1 2
0
1

Output

3
2
1
0
1
4
0
1
2
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
void print(T1 a[], T2 n) {
  for (T2 i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
template <class T1, class T2>
void print(vector<T1> a, T2 n) {
  for (T2 i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
long long int modexpo(long long int a, long long int b, long long int m) {
  if (b == 0) {
    return 1;
  } else if (a == 1) {
    return 1;
  }
  if (b % 2 == 0) {
    long long int t = modexpo(a, b / 2, m);
    t = (t * t) % m;
    return t;
  } else {
    long long int t = modexpo(a, b / 2, m);
    t = (t * t) % m;
    t = (t * a) % m;
    return t;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int cntTest;
  cin >> cntTest;
  for (int test = 0; test < cntTest; test++) {
    long long int n, t, a, b;
    cin >> n >> t >> a >> b;
    vector<pair<long long int, long long int>> v;
    vector<int> hard(n);
    int cntA = 0, cntB = 0;
    for (int i = 0; i < n; i++) {
      cin >> hard[i];
      if (hard[i]) {
        cntB++;
      } else {
        cntA++;
      }
    }
    for (int i = 0; i < n; i++) {
      long long int time;
      cin >> time;
      v.push_back({time, hard[i]});
    }
    v.push_back({t + 1, 0});
    sort(v.begin(), v.end());
    long long int cnt1 = 0, cnt2 = 0;
    long long int ans = 0;
    for (int i = 0; i <= n; i++) {
      long long int need = cnt1 * a + cnt2 * b;
      long long int has = v[i].first - 1 - need;
      if (has >= 0) {
        long long int canA = min((cntA - cnt1), has / a);
        has -= canA * a;
        long long int canB = min((cntB - cnt2), has / b);
        ans = max(ans, cnt1 + cnt2 + canA + canB);
      }
      if (v[i].second) {
        cnt2++;
      } else {
        cnt1++;
      }
    }
    cout << ans << "\n";
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Constraints

* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 a_3 ... a_N

Output

Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

Examples

Input

2
3 1

Output

2

Input

3
2 7 4

Output

5

Input

4
20 18 2 18

Output

18

### Response

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

int main(){
  int n,a[100],sa=0,i,j;
  cin>>n;
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n,greater<int>());
  for(j=0;j<n;j++){
    if(j%2!=0)sa-=a[j];
    else sa+=a[j];
  }
  cout<<sa<<endl;
  return 0;

}

```


### Prompt

Develop a solution in CPP to the problem described below:

Instructors of Some Informatics School make students go to bed.

The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to n. Initially, in i-th room there are ai students. All students are currently somewhere in the house, therefore a1 + a2 + ... + an = nb. Also 2 instructors live in this house.

The process of curfew enforcement is the following. One instructor starts near room 1 and moves toward room n, while the second instructor starts near room n and moves toward room 1. After processing current room, each instructor moves on to the next one. Both instructors enter rooms and move simultaneously, if n is odd, then only the first instructor processes the middle room. When all rooms are processed, the process ends.

When an instructor processes a room, she counts the number of students in the room, then turns off the light, and locks the room. Also, if the number of students inside the processed room is not equal to b, the instructor writes down the number of this room into her notebook (and turns off the light, and locks the room). Instructors are in a hurry (to prepare the study plan for the next day), so they don't care about who is in the room, but only about the number of students.

While instructors are inside the rooms, students can run between rooms that are not locked and not being processed. A student can run by at most d rooms, that is she can move to a room with number that differs my at most d. Also, after (or instead of) running each student can hide under a bed in a room she is in. In this case the instructor will not count her during the processing. In each room any number of students can hide simultaneously.

Formally, here is what's happening:

  * A curfew is announced, at this point in room i there are ai students.
  * Each student can run to another room but not further than d rooms away from her initial room, or stay in place. After that each student can optionally hide under a bed.
  * Instructors enter room 1 and room n, they count students there and lock the room (after it no one can enter or leave this room).
  * Each student from rooms with numbers from 2 to n - 1 can run to another room but not further than d rooms away from her current room, or stay in place. Each student can optionally hide under a bed.
  * Instructors move from room 1 to room 2 and from room n to room n - 1.
  * This process continues until all rooms are processed.

Let x1 denote the number of rooms in which the first instructor counted the number of non-hidden students different from b, and x2 be the same number for the second instructor. Students know that the principal will only listen to one complaint, therefore they want to minimize the maximum of numbers xi. Help them find this value if they use the optimal strategy.

Input

The first line contains three integers n, d and b (2 ≤ n ≤ 100 000, 1 ≤ d ≤ n - 1, 1 ≤ b ≤ 10 000), number of rooms in the house, running distance of a student, official number of students in a room.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109), i-th of which stands for the number of students in the i-th room before curfew announcement.

It is guaranteed that a1 + a2 + ... + an = nb.

Output

Output one integer, the minimal possible value of the maximum of xi.

Examples

Input

5 1 1
1 0 0 0 4

Output

1

Input

6 1 2
3 8 0 1 0 0

Output

2

Note

In the first sample the first three rooms are processed by the first instructor, and the last two are processed by the second instructor. One of the optimal strategies is the following: firstly three students run from room 5 to room 4, on the next stage two of them run to room 3, and one of those two hides under a bed. This way, the first instructor writes down room 2, and the second writes down nothing.

In the second sample one of the optimal strategies is the following: firstly all students in room 1 hide, all students from room 2 run to room 3. On the next stage one student runs from room 3 to room 4, and 5 students hide. This way, the first instructor writes down rooms 1 and 2, the second instructor writes down rooms 5 and 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, d, b;
int a[200007], cnt[200007], aa[200007];
bool calc(int dis, int pos) {
  int t = (dis + d - 1) / d, tot = min(pos, n - pos + 1);
  return (t <= tot);
}
bool check(int x) {
  for (int i = 1; i <= n; i++) a[i] = aa[i];
  for (int i = x + 1; i <= n; i++) cnt[i] = b;
  int pos = x + 1;
  for (int i = 1; i <= n; i++) {
    while (a[i] > 0) {
      if (calc(abs(pos - i), pos)) {
        int del = min(a[i], cnt[pos]);
        a[i] -= del;
        cnt[pos] -= del;
        if (cnt[pos] == 0) ++pos;
        if (pos + x - 1 >= n) return true;
      } else
        break;
    }
  }
  return false;
}
int main() {
  scanf("%d%d%d", &n, &d, &b);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) aa[i] = a[i];
  int lx = 0, rx = (n + 1) / 2;
  while (rx - lx > 1) {
    int mid = (lx + rx) / 2;
    if (check(mid))
      rx = mid;
    else
      lx = mid;
  }
  if (check(lx))
    printf("%d\n", lx);
  else
    printf("%d\n", rx);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Consider a sequence of n numbers using integers from 0 to 9 k1, k2, ..., kn. Read the positive integers n and s,

k1 + 2 x k2 + 3 x k3 + ... + n x kn = s

Create a program that outputs how many rows of n numbers such as. However, the same number does not appear more than once in one "n sequence of numbers".

Input

The input consists of multiple datasets. For each dataset, n (1 ≤ n ≤ 10) and s (0 ≤ s ≤ 10,000) are given on one line, separated by blanks.

The number of datasets does not exceed 100.

Output

For each dataset, print the number of combinations in which the sum of n integers is s on one line.

Example

Input

3 10
3 1

Output

8
0

### Response

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

bool flags[10];
int solved[1024][331];

int trans(){
  int a=0;
  for(int i=0;i<10;i++)
    a+= ( int(flags[i])<<i );
  return a;
}

int solve(int index,int sum,int max){
  int a=trans();
  if(sum < 0 || sum>330 || index > max){ return 0; }
  if(index == max && sum == 0){
    return solved[a][0]=1;
  }

  if(solved[a][sum]!=-1) return solved[a][sum];
  int count=0;
  for(int i=0;i<10;i++){
    if(!flags[i]){
      flags[i]=true;
      int s=solve(index+1,sum-index*i,max);
      count+=s;
      flags[i]=false;
    }
  }
  return solved[a][sum]=count;
}

int main(){
  int n,s;
  while(cin>>n>>s){
    for(int i=0;i<1024;i++)
      for(int j=0;j<331;j++)
	solved[i][j]=-1;
    cout<<solve(1,s,n+1)<<endl;
  }
  return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.

Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:

<image>

After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.

Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.

Input

The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.

Output

Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.

Examples

Input

zeus

Output

18

Input

map

Output

35

Input

ares

Output

34

Note

<image>

To print the string from the first sample it would be optimal to perform the following sequence of rotations:

  1. from 'a' to 'z' (1 rotation counterclockwise),
  2. from 'z' to 'e' (5 clockwise rotations),
  3. from 'e' to 'u' (10 rotations counterclockwise),
  4. from 'u' to 's' (2 counterclockwise rotations).

In total, 1 + 5 + 10 + 2 = 18 rotations are required.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    string s;
    cin >> s;
    int moves = 0;
    int start = 0;
    for (int i = 0; i < s.length(); i++) {
      int value = s[i] - 97;
      int m = abs(start - value);
      if (m > 13) {
        moves += 26 - m;
      } else {
        moves += m;
      }
      start = value;
    }
    cout << moves;
    return 0;
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.

Input

The first line contains two integers w, m (2 ≤ w ≤ 109, 1 ≤ m ≤ 109) — the number defining the masses of the weights and the mass of the item.

Output

Print word 'YES' if the item can be weighted and 'NO' if it cannot.

Examples

Input

3 7

Output

YES

Input

100 99

Output

YES

Input

100 50

Output

NO

Note

Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.

Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.

Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int w, m;
bool solve(int a) {
  if (a == 0 || a == 1) return true;
  if ((a + 1) % w == 0 && solve((a + 1) / w)) return true;
  if ((a) % w == 0 && solve((a) / w)) return true;
  if ((a - 1) % w == 0 && solve((a - 1) / w)) return true;
  return false;
}
int main() {
  cin >> w >> m;
  if (solve(m))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

```


### Prompt

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

You are given n strings s_1, s_2, …, s_n consisting of lowercase Latin letters.

In one operation you can remove a character from a string s_i and insert it to an arbitrary position in a string s_j (j may be equal to i). You may perform this operation any number of times. Is it possible to make all n strings equal?

Input

The first line contains t (1 ≤ t ≤ 10): the number of test cases.

The first line of each test case contains a single integer n (1 ≤ n ≤ 1000): the number of strings.

n lines follow, the i-th line contains s_i (1 ≤ \lvert s_i \rvert ≤ 1000).

The sum of lengths of all strings in all test cases does not exceed 1000.

Output

If it is possible to make the strings equal, print "YES" (without quotes).

Otherwise, print "NO" (without quotes).

You can output each character in either lowercase or uppercase.

Example

Input

4
2
caa
cbb
3
cba
cba
cbb
4
ccab
cbac
bca
acbcc
4
acb
caf
c
cbafc

Output

YES
NO
YES
NO

Note

In the first test case, you can do the following:

  * Remove the third character of the first string and insert it after the second character of the second string, making the two strings "ca" and "cbab" respectively.
  * Remove the second character of the second string and insert it after the second character of the first string, making both strings equal to "cab".

In the second test case, it is impossible to make all n strings equal.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e10 + 6;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
const int MX = 1e6 + 5;
const int LG = 25;
template <typename t>
void fff(const char* x, t&& val1) {
  cout << x << " : " << val1 << "\n";
}
template <typename t1, typename... t2>
void fff(const char* x, t1&& val1, t2&&... val2) {
  const char* xd = strchr(x + 1, ',');
  cout.write(x, xd - x) << " : " << val1 << " | ";
  fff(xd + 1, val2...);
}
long long a[MX];
long long b[MX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n;
    cin >> n;
    map<char, long long> mapa;
    for (int i = 0; i < n; i++) {
      string a;
      cin >> a;
      for (int i = 0; i < a.size(); i++) {
        mapa[a[i]]++;
      }
    }
    long long flag = 0;
    for (auto xd : mapa) {
      if (xd.second % n != 0) flag = 1;
    }
    if (flag == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

```


### Prompt

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

Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute

$$$ (a_1 + a_2) ⊕ (a_1 + a_3) ⊕ … ⊕ (a_1 + a_n) \\\ ⊕ (a_2 + a_3) ⊕ … ⊕ (a_2 + a_n) \\\ … \\\ ⊕ (a_{n-1} + a_n) \\\ $$$

Here x ⊕ y is a bitwise XOR operation (i.e. x ^ y in many modern programming languages). You can read about it in Wikipedia: <https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation>.

Input

The first line contains a single integer n (2 ≤ n ≤ 400 000) — the number of integers in the array.

The second line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7).

Output

Print a single integer — xor of all pairwise sums of integers in the given array.

Examples

Input

2
1 2

Output

3

Input

3
1 2 3

Output

2

Note

In the first sample case there is only one sum 1 + 2 = 3.

In the second sample case there are three sums: 1 + 2 = 3, 1 + 3 = 4, 2 + 3 = 5. In binary they are represented as 011_2 ⊕ 100_2 ⊕ 101_2 = 010_2, thus the answer is 2.

⊕ is the bitwise xor operation. To define x ⊕ y, consider binary representations of integers x and y. We put the i-th bit of the result to be 1 when exactly one of the i-th bits of x and y is 1. Otherwise, the i-th bit of the result is put to be 0. For example, 0101_2   ⊕   0011_2 = 0110_2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int a[N], b[N];
int ans, n;
int calc(int L, int R) {
  if (L > R) return 0;
  long long res = 0;
  for (int i = n, l = 1, r = 1; i >= 1; i--) {
    for (; l <= n && b[i] + b[l] < L; l++)
      ;
    for (; r <= n && b[i] + b[r] <= R; r++)
      ;
    res += r - l - (l <= i && i < r);
  }
  return res >> 1 & 1;
}
int sol(int x) {
  for (int i = 1; i <= n; i++) b[i] = a[i] & (1 << x + 1) - 1;
  sort(b + 1, b + n + 1);
  return (calc(1 << x, (1 << x + 1) - 1) ^ calc(3 << x, (1 << x + 2) - 2)) << x;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < 30; i++) ans |= sol(i);
  printf("%d\n", ans);
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.

In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge has a weight capacity. A delivery consists of a bear carrying weights with their bear hands on a simple path from node 1 to node n. The total weight that travels across a particular edge must not exceed the weight capacity of that edge.

Niwel has exactly x bears. In the interest of fairness, no bear can rest, and the weight that each bear carries must be exactly the same. However, each bear may take different paths if they like.

Niwel would like to determine, what is the maximum amount of weight he can deliver (it's the sum of weights carried by bears). Find the maximum weight.

Input

The first line contains three integers n, m and x (2 ≤ n ≤ 50, 1 ≤ m ≤ 500, 1 ≤ x ≤ 100 000) — the number of nodes, the number of directed edges and the number of bears, respectively.

Each of the following m lines contains three integers ai, bi and ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 1 000 000). This represents a directed edge from node ai to bi with weight capacity ci. There are no self loops and no multiple edges from one city to the other city. More formally, for each i and j that i ≠ j it's guaranteed that ai ≠ aj or bi ≠ bj. It is also guaranteed that there is at least one path from node 1 to node n.

Output

Print one real value on a single line — the maximum amount of weight Niwel can deliver if he uses exactly x bears. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

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

Examples

Input

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

Output

1.5000000000

Input

5 11 23
1 2 3
2 3 4
3 4 5
4 5 6
1 3 4
2 4 5
3 5 6
1 4 2
2 5 3
1 5 2
3 2 30

Output

10.2222222222

Note

In the first sample, Niwel has three bears. Two bears can choose the path <image>, while one bear can choose the path <image>. Even though the bear that goes on the path <image> can carry one unit of weight, in the interest of fairness, he is restricted to carry 0.5 units of weight. Thus, the total weight is 1.5 units overall. Note that even though Niwel can deliver more weight with just 2 bears, he must use exactly 3 bears on this day.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ans;
int m, n, maxflow;
const int length = 1000;
const int mymax = -1;
int path[2000];
int id[2000];
int thetop = 0;
int a[505][3];
class mincostMaxFlow {
 private:
  int flow[length * 2];
  int capacity[length * 2];
  int value[length * 2];
  int head[length];
  int next[length];
  bool isvisited[length * 2];
  int queue[length * 5];
  int dist[length];
  int cost[length];
  int pos;
  int e[length];
  int prev[length];
  int source;
  int target;
  int prev_vec[length];
  double smallest;

 public:
  void init(int s, int e) {
    source = s;
    target = e;
    pos = 0;
    clear();
  }
  void clear() {
    memset(head, -1, sizeof(head));
    memset(flow, 0, sizeof(flow));
    memset(capacity, 0, sizeof(capacity));
    pos = 0;
  }
  void reset(double d) {
    for (int i = 0; i < pos; i++) {
      flow[i] = 0.0;
    }
    smallest = d;
  }
  void add(int s, int t, int cap, int v) {
    e[pos] = t;
    cost[pos] = v;
    capacity[pos] = (double)cap;
    next[pos] = head[s];
    head[s] = pos++;
    e[pos] = s;
    cost[pos] = -v;
    next[pos] = head[t];
    head[t] = pos++;
  }
  bool find() {
    memset(isvisited, false, sizeof(isvisited));
    int start = 0;
    int end = 1;
    queue[start] = source;
    int l = 0;
    while (start < end) {
      int t = queue[start++];
      for (int i = head[t]; i != -1; i = next[i]) {
        if (capacity[i] - flow[i] > 0 && !isvisited[e[i]]) {
          prev[e[i]] = i;
          queue[end++] = e[i];
          isvisited[e[i]] = true;
          if (e[i] == target) return true;
        }
      }
    }
    return false;
  }
  int getmaxflow_mincost() {
    int i = 0;
    int j = 1;
    ans = 0;
    i = 0;
    ;
    int l = 0;
    while (find()) {
      int max = INT_MAX;
      int t = target;
      while (t != source) {
        int i = prev[t];
        if (max > capacity[i] - flow[i]) {
          max = capacity[i] - flow[i];
        }
        t = e[i ^ 1];
      }
      ans += max;
      t = target;
      while (t != source) {
        int i = prev[t];
        flow[i] += max;
        flow[i ^ 1] = -flow[i];
        prev_vec[t] = e[i ^ 1];
        t = e[i ^ 1];
      }
      j++;
    }
    return ans;
  }
  void getcost() {
    int s, t;
    for (int i = 0; i < pos; i++) {
      if (flow[i] > 0) {
        t = e[i] / 2;
        s = e[i ^ 1] / 2;
        path[t] = s;
      }
    }
    int cnt = 1;
    for (int i = 0; i < n; i++) {
      if (path[i] >= n) {
        id[i] = cnt++;
      } else {
        id[i] = id[path[i]];
      }
    }
  }
};
mincostMaxFlow solution;
void process() {
  int i, j, t;
  int ret = 0;
}
void input() {
  int i, j, t, k, u, v;
  int s;
  scanf("%d %d %d", &n, &m, &thetop);
  t = 0;
  solution.init(1, n);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
    if (a[i][2] > t) t = a[i][2];
  }
  double l = 0;
  double h = (double)t;
  double mid;
  double diff = 0.00000000001;
  int c = 0;
  while (l + diff < h) {
    mid = (l + h) / 2;
    solution.clear();
    for (i = 0; i < m; i++) {
      k = (int)((double)a[i][2] / mid);
      if (k > 0)
        solution.add(a[i][0], a[i][1], k, 0);
      else if (k == -2147483648)
        solution.add(a[i][0], a[i][1], INT_MAX, 0);
    }
    v = solution.getmaxflow_mincost();
    if (v >= thetop) {
      l = mid;
    } else {
      h = mid;
    }
    c++;
    if (c >= 100) break;
  }
  printf("%lf\n", l * thetop);
}
int main() {
  input();
  process();
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Based on the information of the time when study started and the time when study ended, check whether the total time studied in one day is t or more, and if not, create a program to find the shortage time. Time is one unit per hour, and minutes and seconds are not considered. The time is expressed in 24-hour notation in 1-hour units.

Enter the target time of study per day and the information of the time actually studied (number of studies n, start time s and end time f of each study), and check whether the total study time has reached the target. If it has reached, write "OK", and if it has not reached, write a program that outputs the insufficient time. However, the study time spent on each will not overlap.

Example: Target time | Study time | Judgment
--- | --- | ---
10 hours | 6:00 to 11:00 = 5 hours
12:00 to 15:00 = 3 hours
18:00 to 22:00 = 4 hours | OK
14 hours | 6:00 to 11:00 = 5 hours
13:00 to 20:00 = 7 hours
| 2 hours shortage

Input example

Ten
3
6 11
12 15
18 22
14
2
6 11
13 20
0

Output example

OK
2

input

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

t
n
s1 f1
s2 f2
::
sn fn

The first line gives the target time of the day t (0 ≤ t ≤ 22), and the second line gives the number of studies n (1 ≤ n ≤ 10). The following n lines are given the start time si and end time f (6 ≤ si, fi ≤ 22) of the i-th study.

The number of datasets does not exceed 100.

output

Outputs OK or missing time on one line for each dataset.

Example

Input

10
3
6 11
12 15
18 22
14
2
6 11
13 20
0

Output

OK
2

### Response

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

int main() {
  int t, n, s, f;
  while (cin >> t, t) {
    cin >> n;
    int sum = 0;
    while (n--) {
      cin >> s >> f;
      sum += f - s;
    }
    if (sum >= t) cout << "OK\n";
    else cout << t - sum << "\n";
  }
}

```


### Prompt

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

A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows:

<image>

You start with n cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?

Input

Each test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.

Each test case contains a single integer n (1≤ n≤ 10^9) — the number of cards.

It is guaranteed that the sum of n over all test cases does not exceed 10^9.

Output

For each test case output a single integer — the number of pyramids you will have constructed in the end.

Example

Input

5
3
14
15
24
1

Output

1
2
1
3
0

Note

In the first test, you construct a pyramid of height 1 with 2 cards. There is 1 card remaining, which is not enough to build a pyramid.

In the second test, you build two pyramids, each of height 2, with no cards remaining.

In the third test, you build one pyramid of height 3, with no cards remaining.

In the fourth test, you build one pyramid of height 3 with 9 cards remaining. Then you build a pyramid of height 2 with 2 cards remaining. Then you build a final pyramid of height 1 with no cards remaining.

In the fifth test, one card is not enough to build any pyramids.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  ;
  while (t--) {
    long long n;
    cin >> n;
    ;
    long long sum = 0;
    while (n > 1) {
      long long h = floor((sqrt(1 + 24 * n) - 1) / 6);
      n = n - h * (3 * h + 1) / 2;
      sum++;
    }
    cout << sum << endl;
    ;
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

Little Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform its commands. There are 5 possible commands: to stay idle or to move from current cell to some of the four side-neighboring cells (that is, one command for each of the four possible directions). Petya gives the commands so that no spider leaves the field. It is allowed for spiders to pass through each other when they crawl towards each other in opposite directions. All spiders crawl simultaneously and several spiders may end up in one cell. Petya wants to know the maximum possible number of spider-free cells after one second.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 40, n·m ≤ 40) — the board sizes.

Output

In the first line print the maximum number of cells without spiders.

Examples

Input

1 1

Output

0

Input

2 3

Output

4

Note

In the first sample the only possible answer is:

s

In the second sample one of the possible solutions is:

    rdl
    rul

s denotes command "stay idle", l, r, d, u denote commands "crawl left", "crawl right", "crawl down", "crawl up", correspondingly.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, l, c, h[45][45];
void d(int x, int y) {
  if (y == m) x++, y = 0;
  if (c == l) return;
  if (x == n) {
    if (h[n - 1][m - 1])
      l = c;
    else
      l = c + 1;
    return;
  }
  c++;
  if (x) h[x - 1][y]++;
  if (y) h[x][y - 1]++;
  if (x + 1 < n) h[x + 1][y]++;
  if (y + 1 < m) h[x][y + 1]++;
  h[x][y]++;
  d(x, y + 1);
  c--;
  if (x) h[x - 1][y]--;
  if (y) h[x][y - 1]--;
  if (x + 1 < n) h[x + 1][y]--;
  if (y + 1 < m) h[x][y + 1]--;
  h[x][y]--;
  if (x && h[x - 1][y] == 0) return;
  if (x + 1 == n && y && h[x][y - 1] == 0) return;
  d(x, y + 1);
}
int main() {
  scanf("%d%d", &n, &m);
  memset(h, 0, sizeof(h));
  l = 15;
  d(0, 0);
  printf("%d\n", n * m - l);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the importance of fast and highly reliable automatic baggage inspection systems is increasing. Since it is actually difficult for an inspector to inspect all the baggage, we would like to establish a mechanism for the inspector to inspect only the baggage judged to be suspicious by the automatic inspection.

At the request of the aviation industry, the International Cabin Protection Company investigated recent passenger baggage in order to develop a new automated inspection system. As a result of the investigation, it was found that the baggage of recent passengers has the following tendency.

* Baggage is shaped like a rectangular parallelepiped with only one side short.
* Items that ordinary passengers pack in their baggage and bring into the aircraft include laptop computers, music players, handheld game consoles, and playing cards, all of which are rectangular.
* Individual items are packed so that their rectangular sides are parallel to the sides of the baggage.
* On the other hand, weapons such as those used for terrorism have a shape very different from a rectangle.

Based on the above survey results, we devised the following model for baggage inspection. Each piece of baggage is considered to be a rectangular parallelepiped container that is transparent to X-rays. It contains multiple items that are opaque to X-rays. Here, consider a coordinate system with the three sides of the rectangular parallelepiped as the x-axis, y-axis, and z-axis, irradiate X-rays in the direction parallel to the x-axis, and take an image projected on the y-z plane. The captured image is divided into grids of appropriate size, and the material of the item reflected in each grid area is estimated by image analysis. Since this company has a very high level of analysis technology and can analyze even the detailed differences in materials, it can be considered that the materials of the products are different from each other. When multiple items overlap in the x-axis direction, the material of the item that is in the foreground for each lattice region, that is, the item with the smallest x-coordinate is obtained. We also assume that the x-coordinates of two or more items are never equal.

Your job can be asserted that it contains non-rectangular (possibly a weapon) item when given the results of the image analysis, or that the baggage contains anything other than a rectangular item. It is to create a program that determines whether it is presumed that it is not included.

Input

The first line of input contains a single positive integer, which represents the number of datasets. Each dataset is given in the following format.

> H W
> Analysis result 1
> Analysis result 2
> ...
> Analysis result H
>

H is the vertical size of the image, and W is an integer representing the horizontal size (1 <= h, w <= 50). Each line of the analysis result is composed of W characters, and the i-th character represents the analysis result in the grid region i-th from the left of the line. For the lattice region where the substance is detected, the material is represented by uppercase letters (A to Z). At this time, the same characters are used if they are made of the same material, and different characters are used if they are made of different materials. The lattice region where no substance was detected is represented by a dot (.).

For all datasets, it is guaranteed that there are no more than seven material types.

Output

For each data set, output "SUSPICIOUS" if it contains items other than rectangles, and "SAFE" if not, on one line.

Sample Input

6
1 1
..
3 3
...
.W.
...
10 10
..........
.DDDDCC ..
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
..........
.DDDDDD ...
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE ....
EEEEEEE ...
.EEEEEEE ..
..EEEEEEE.
... EEEEEEE
.... EEEEE.
..... EEE ..
...... E ...
16 50
.................................................................
......... AAAAAAAAAAAAAAAAA ............................
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ....
.... PPP .............. AAAAA.AAAAAAAAAAAAAAAA .......
.... PPP ................ A .... AAA.AAAAAAAAAA ........
.... PPP ........... IIIIIAAIIAIII.AAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIAAAAAAAAAAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIIIIIIII ... AAAAAAAAAAA ......
.... PPP .................. AAAAAAAAAAA .....
MMMMPPPMMMMMMMMMMMMMMM ............. AAAAAAAAAAA ....
MMMMPPPMMMMMMMMMMMMMMM .............. AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............................

Output for the Sample Input

SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS

Example

Input

6
1 1
.
3 3
...
.W.
...
10 10
..........
.DDDDCCC..
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
..........
.DDDDDD...
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE....
EEEEEEE...
.EEEEEEE..
..EEEEEEE.
...EEEEEEE
....EEEEE.
.....EEE..
......E...
16 50
..................................................
.........AAAAAAAAAAAAAAAA.........................
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA....
....PPP..............AAAAA.AAAAAAAAAAAAAAAA.......
....PPP................A....AAA.AAAAAAAAAA........
....PPP...........IIIIIAAIIAIII.AAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIAAAAAAAAAAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIIIIIIII...AAAAAAAAAA......
....PPP............................AAAAAAAAAA.....
MMMMPPPMMMMMMMMMMMMMMM.............AAAAAAAAAAA....
MMMMPPPMMMMMMMMMMMMMMM..............AAAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM............................

Output

SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS

### Response

```cpp
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define rep(i, j, k) for (auto i = j; i < k; i++)
#define rrep(i, j, k) for (auto i = j; i > k; i--)
using namespace std;

void solve() {
  int h, w; cin >> h >> w;
  char a[51][51], b[51][51];
  set<char> set1;
  rep(i, 0, h) rep(j, 0, w) {
    cin >> a[i][j];
    if (a[i][j] == '.') continue;
    set1.insert(a[i][j]);
  }
  if (set1.size() < 1) {
    cout << "SAFE" << endl;
    return;
  }
  assert(set1.size() < 8);
  vector<char> v;
  for (auto ite : set1) v.push_back(ite);
  sort(v.begin(), v.end());
  do {
    rep(i, 0, h) rep(j, 0, w) b[i][j] = a[i][j];
    bool ok = true;
    rep(nowi, 0, (int)v.size()) {
      int left = INT_MAX, right = INT_MIN;
      rep(j, 0, w) rep(i, 0, h) {
        if (b[i][j] == v[nowi]) {
          left = min(left, j);
          right = max(right, j);
        }
      }
      int up = INT_MAX, down = INT_MIN;
      rep(i, 0, h) rep(j, 0, w) {
        if (b[i][j] == v[nowi]) {
          up = min(up, i);
          down = max(down, i);
        }
      }
      [&]{
        rep(i, up, down + 1) rep(j, left, right + 1) {
          if (b[i][j] != v[nowi] && b[i][j] != '*') {
            ok = false;
            return;
          }
        }
      }();
      if (ok) {
        rep(i, up, down + 1) rep(j, left, right + 1) {
          if (b[i][j] == v[nowi]) b[i][j] = '*';
        }
      } else {
        break;
      }
    }
    if (ok) {
      cout << "SAFE" << endl;
      return;
    }
  } while (next_permutation(v.begin(), v.end()));
  cout << "SUSPICIOUS" << endl;
}

int main() {
  int n; cin >> n;
  rep(i, 0, n) solve();
}

//////////////////////////////////////////////////////////////////////////
//NOTE
//////////////////////////////////////////////////////////////////////////
// 一つのカバンに入っている物の数は7種類以下とわかっているので、
// どんな順でx座標が大きくなっていくのかを、全通り試していければ良い.

```


### Prompt

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

You are given a bipartite graph: the first part of this graph contains n_1 vertices, the second part contains n_2 vertices, and there are m edges. The graph can contain multiple edges.

Initially, each edge is colorless. For each edge, you may either leave it uncolored (it is free), paint it red (it costs r coins) or paint it blue (it costs b coins). No edge can be painted red and blue simultaneously.

There are three types of vertices in this graph — colorless, red and blue. Colored vertices impose additional constraints on edges' colours:

  * for each red vertex, the number of red edges indicent to it should be strictly greater than the number of blue edges incident to it;
  * for each blue vertex, the number of blue edges indicent to it should be strictly greater than the number of red edges incident to it.

Colorless vertices impose no additional constraints.

Your goal is to paint some (possibly none) edges so that all constraints are met, and among all ways to do so, you should choose the one with minimum total cost.

Input

The first line contains five integers n_1, n_2, m, r and b (1 ≤ n_1, n_2, m, r, b ≤ 200) — the number of vertices in the first part, the number of vertices in the second part, the number of edges, the amount of coins you have to pay to paint an edge red, and the amount of coins you have to pay to paint an edge blue, respectively.

The second line contains one string consisting of n_1 characters. Each character is either U, R or B. If the i-th character is U, then the i-th vertex of the first part is uncolored; R corresponds to a red vertex, and B corresponds to a blue vertex.

The third line contains one string consisting of n_2 characters. Each character is either U, R or B. This string represents the colors of vertices of the second part in the same way.

Then m lines follow, the i-th line contains two integers u_i and v_i (1 ≤ u_i ≤ n_1, 1 ≤ v_i ≤ n_2) denoting an edge connecting the vertex u_i from the first part and the vertex v_i from the second part.

The graph may contain multiple edges.

Output

If there is no coloring that meets all the constraints, print one integer -1.

Otherwise, print an integer c denoting the total cost of coloring, and a string consisting of m characters. The i-th character should be U if the i-th edge should be left uncolored, R if the i-th edge should be painted red, or B if the i-th edge should be painted blue. If there are multiple colorings with minimum possible cost, print any of them.

Examples

Input

3 2 6 10 15
RRB
UB
3 2
2 2
1 2
1 1
2 1
1 1

Output

35
BUURRU

Input

3 1 3 4 5
RRR
B
2 1
1 1
3 1

Output

-1

Input

3 1 3 4 5
URU
B
2 1
1 1
3 1

Output

14
RBB

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N, M, K, s, t, r, b, tot, R[501], B[501], fst[501],
    cnt = 1, to[100001], flow[100001], len[100001], nxt[100001], mflow[501],
    pre[501];
long long dis[501], ans;
bool in[501];
int get() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
void add(int u, int v, int f, int l) {
  to[++cnt] = v, flow[cnt] = f, len[cnt] = l, nxt[cnt] = fst[u], fst[u] = cnt;
  to[++cnt] = u, flow[cnt] = 0, len[cnt] = -l, nxt[cnt] = fst[v], fst[v] = cnt;
}
bool spfa() {
  memset(dis, 0x3f, sizeof(dis));
  memset(in, 0, sizeof(in));
  queue<int> q;
  q.push(s);
  dis[s] = 0;
  in[s] = 1;
  mflow[s] = 0x3fffffff;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    in[u] = 0;
    for (int i = fst[u]; i; i = nxt[i])
      if (flow[i] && dis[to[i]] > dis[u] + len[i]) {
        dis[to[i]] = dis[u] + len[i];
        mflow[to[i]] = min(mflow[u], flow[i]);
        pre[to[i]] = i;
        if (!in[to[i]]) q.push(to[i]), in[to[i]] = 1;
      }
  }
  return dis[t] != 0x3f3f3f3f3f3f3f3f;
}
void upd() {
  int x = t;
  while (x != s) {
    x = pre[x];
    flow[x] -= mflow[t], flow[x ^ 1] += mflow[t], x = to[x ^ 1];
  }
  ans += dis[t] * mflow[t];
}
int main() {
  N = get(), M = get(), K = get(), r = get(), b = get(), s = 0, t = N + M + 1;
  for (int i = 1; i <= N; i++) {
    char c;
    cin >> c;
    c == 'R' || c == 'B' ? tot++,
        c == 'R'         ? add(s, i, 1, -0x3fffffff),
        add(s, i, 0x3fffffff, 0)
                 : (add(i, t, 1, -0x3fffffff), add(i, t, 0x3fffffff, 0))
                 : (add(s, i, 0x3fffffff, 0), add(i, t, 0x3fffffff, 0));
  }
  for (int i = 1; i <= M; i++) {
    char c;
    cin >> c;
    c == 'R' || c == 'B' ? tot++,
        c == 'R'         ? add(i + N, t, 1, -0x3fffffff),
        add(i + N, t, 0x3fffffff, 0)
                 : (add(s, i + N, 1, -0x3fffffff), add(s, i + N, 0x3fffffff, 0))
                 : (add(s, i + N, 0x3fffffff, 0), add(i + N, t, 0x3fffffff, 0));
  }
  for (int i = 1; i <= K; i++) {
    int u, v;
    cin >> u >> v;
    add(u, v + N, 1, r);
    R[i] = cnt - 1;
    add(v + N, u, 1, b);
    B[i] = cnt - 1;
  }
  while (spfa()) {
    if (dis[t] <= 0)
      upd();
    else if (ans + tot * 0x3fffffff < 0x3fffffff)
      break;
  }
  ans += 1ll * tot * 0x3fffffff;
  if (ans > 0x3fffffff) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  for (int i = 1; i <= K; i++)
    cout << (!flow[R[i]] ? 'R' : !flow[B[i]] ? 'B' : 'U');
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.

Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.

Constraints

* 1≦a,b,c≦100

Input

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

a b c

Output

Print the number of different kinds of colors of the paint cans.

Examples

Input

3 1 4

Output

3

Input

3 3 33

Output

2

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int x;
map<int,int> a;
int main(){
  cin>>x;a[x]++;
  cin>>x;a[x]++;
  cin>>x;a[x]++;
  cout<<a.size()<<endl;
}

```


### Prompt

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

You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:

* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).

Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.

Constraints

* 1 \leq N \leq 2000
* 1 \leq K \leq N
* 1 \leq Q \leq N-K+1
* 1 \leq A_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K Q
A_1 A_2 ... A_N

Output

Print the smallest possible value of X-Y.

Examples

Input

5 3 2
4 3 1 5 2

Output

1

Input

10 1 6
1 1 2 3 5 8 13 21 34 55

Output

7

Input

11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784

Output

451211184

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n,K,Q,a[2005],w[2005],s[2005],temp[2005];
int main(){
	scanf("%d%d%d",&n,&K,&Q);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),w[i]=a[i];
	sort(w+1,w+n+1);
	int ans=2e9;
	for(int i=1;i<=n;i++){
		int top=0;
		for(int p=1,j;p<=n;){
			if(a[p]<w[i]){
				p++;continue;
			}
			for(j=p;a[j]>=w[i]&&j<=n;j++) temp[j-p+1]=a[j];
			sort(temp+1,temp+j-p+1);
			for(int k=1;k<=j-p-K+1;k++) s[++top]=temp[k];
			p=j;
		}
		sort(s+1,s+top+1);
		if(top>=Q) ans=min(ans,s[Q]-s[1]);
	}
	printf("%d",ans);
	return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:

  * on Mondays, Thursdays and Sundays he eats fish food;
  * on Tuesdays and Saturdays he eats rabbit stew;
  * on other days of week he eats chicken stake.

Polycarp plans to go on a trip and already packed his backpack. His backpack contains:

  * a daily rations of fish food;
  * b daily rations of rabbit stew;
  * c daily rations of chicken stakes.

Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Input

The first line of the input contains three positive integers a, b and c (1 ≤ a, b, c ≤ 7⋅10^8) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.

Output

Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Examples

Input

2 1 1

Output

4

Input

3 2 2

Output

7

Input

1 100 1

Output

3

Input

30 20 10

Output

39

Note

In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday — rabbit stew and during Wednesday — chicken stake. So, after four days of the trip all food will be eaten.

In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack.

In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long N, K, M, a, b, i, j, c, d, A, B, C;
string S;
void solve() {
  cin >> a >> b >> c;
  A = a / 3;
  B = b / 2;
  C = c / 2;
  d = min(A, min(B, C));
  A = a - 3 * d;
  B = b - 2 * d;
  C = c - 2 * d;
  d *= 7;
  int Aa[8], Bb[4];
  Aa[1] = 1;
  Aa[4] = 1;
  Aa[7] = 1;
  Aa[2] = 2;
  Aa[6] = 2;
  Aa[5] = 3;
  Aa[3] = 3;
  Bb[1] = A;
  Bb[2] = B;
  Bb[3] = C;
  int q = 0;
  for (int i = 1; i < 8; i++) {
    j = i;
    int count = 7, p = 0;
    int Cc[8];
    for (int i = 1; i < 8; i++) Cc[i] = Bb[i];
    while (count--) {
      if (Cc[Aa[j]] > 0) {
        p++;
        Cc[Aa[j]]--;
      } else
        break;
      j++;
      if (j == 8) j = 1;
    }
    q = max(q, p);
  }
  cout << q + d << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Urpal lives in a big city. He has planned to meet his lover tonight.

The city has n junctions numbered from 1 to n. The junctions are connected by m directed streets, all the roads have equal length. Urpal lives in junction a and the date is planned in a restaurant in junction b. He wants to use public transportation to get to junction b. There are k bus transportation companies. At the beginning of every second, a bus from the i-th company chooses a random shortest path between junction si and junction ti and passes through it. There might be no path from si to ti. In that case no bus will leave from si to ti. If a bus passes through a junction where Urpal stands, he can get on the bus. He can also get off the bus at any junction along the path.

Now Urpal wants to know if it's possible to go to the date using public transportation in a finite amount of time (the time of travel is the sum of length of the traveled roads) and what is the minimum number of buses he should take in the worst case.

At any moment Urpal knows only his own position and the place where the date will be. When he gets on the bus he knows only the index of the company of this bus. Of course Urpal knows the city map and the the pairs (si, ti) for each company.

Note that Urpal doesn't know buses velocity.

Input

The first line of the input contains four integers n, m, a, b (2 ≤ n ≤ 100; 0 ≤ m ≤ n·(n - 1); 1 ≤ a, b ≤ n; a ≠ b).

The next m lines contain two integers each ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) describing a directed road from junction ui to junction vi. All roads in the input will be distinct.

The next line contains an integer k (0 ≤ k ≤ 100). There will be k lines after this, each containing two integers si and ti (1 ≤ si, ti ≤ n; si ≠ ti) saying there is a bus route starting at si and ending at ti. Please note that there might be no path from si to ti, this case is described in the problem statement.

Output

In the only line of output print the minimum number of buses Urpal should get on on his way in the worst case. If it's not possible to reach the destination in the worst case print -1.

Examples

Input

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

Output

2

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, k, vs[200], a, b, d[2000][2000], aa[2000], bb[2000], ans = -1;
int que[2000000], dist[20000], vis[20000], f[2000], tot = 0, dp[2000];
int bo[2000][2000], head[200000], line = 0, p[2000][2000];
int dfs(int x, int s, int k) {
  if (vis[x] == tot) return dp[x];
  int cmp = -1;
  vis[x] = tot;
  for (int i = 1; i <= n; ++i) {
    int y = i;
    if (d[x][y] == 1 && d[x][bb[k]] == d[y][bb[k]] + 1) {
      cmp = max(cmp, dfs(y, s, k));
    }
  }
  if (cmp == -1) cmp = 1e9;
  cmp = min(cmp, f[x]);
  return dp[x] = cmp;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (i != j) d[i][j] = 1e9;
  int x, y;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    d[x][y] = 1;
  }
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  scanf("%d", &k);
  for (int i = 1; i <= n; ++i) f[i] = 1e9, dp[i] = 1e9;
  memset(vs, 0, sizeof(vs));
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &x, &y);
    aa[i] = x, bb[i] = y;
    if (d[x][y] == 1e9) continue;
    for (int l = 1; l <= n; ++l)
      if (d[x][l] + d[l][y] == d[x][y]) ++vs[d[x][l]];
    for (int j = 1; j <= n; ++j)
      if (d[x][j] + d[j][y] == d[x][y]) {
        if (vs[d[x][j]] == 1) bo[i][j] = 1;
        vs[d[x][j]] = 0;
      }
  }
  int t = 1;
  f[b] = 0;
  while (t) {
    t = 0;
    for (int i = 1; i <= k; ++i)
      for (int j = 1; j <= n; ++j)
        if (bo[i][j]) {
          tot++;
          int cnt = dfs(j, i, i) + 1;
          if (cnt < f[j]) f[j] = cnt, t = 1;
        }
  }
  if (f[a] == 1e9)
    printf("-1");
  else
    printf("%d\n", f[a]);
}

```


### Prompt

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

Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.

Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109 + 9).

Input

The single line contains three space-separated integers n, m and k (2 ≤ k ≤ n ≤ 109; 0 ≤ m ≤ n).

Output

Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 9).

Examples

Input

5 3 2

Output

3

Input

5 4 2

Output

6

Note

Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.

Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.

Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though 2000000020 mod 1000000009 is a smaller number.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const unsigned long long P = 239017, MaxN = 2100000, INF = 100000000;
const long long mod = 1000000009;
long long step(int t) {
  if (t == 0) return 1;
  if (t % 2 == 0) {
    long long a = step(t / 2);
    return (a * a) % mod;
  }
  return (2 * step(t - 1)) % mod;
}
int n, m, k;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int t = m - n % k - (n / k) * (k - 1);
  if (t <= 0) {
    printf("%d", m);
    return 0;
  }
  long long ans =
      (((long long)k * (step(t + 1) - 2)) % mod + m - t * k + mod) % mod;
  printf("%I64d", ans);
  return 0;
}

```


### Prompt

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

Fibonacci numbers are the sequence of integers: f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, ..., fn = fn - 2 + fn - 1. So every next number is the sum of the previous two.

Bajtek has developed a nice way to compute Fibonacci numbers on a blackboard. First, he writes a 0. Then, below it, he writes a 1. Then he performs the following two operations:

  * operation "T": replace the top number with the sum of both numbers;
  * operation "B": replace the bottom number with the sum of both numbers.

If he performs n operations, starting with "T" and then choosing operations alternately (so that the sequence of operations looks like "TBTBTBTB..."), the last number written will be equal to fn + 1.

Unfortunately, Bajtek sometimes makes mistakes and repeats an operation two or more times in a row. For example, if Bajtek wanted to compute f7, then he would want to do n = 6 operations: "TBTBTB". If he instead performs the sequence of operations "TTTBBT", then he will have made 3 mistakes, and he will incorrectly compute that the seventh Fibonacci number is 10. The number of mistakes in the sequence of operations is the number of neighbouring equal operations («TT» or «BB»).

You are given the number n of operations that Bajtek has made in an attempt to compute fn + 1 and the number r that is the result of his computations (that is last written number). Find the minimum possible number of mistakes that Bajtek must have made and any possible sequence of n operations resulting in r with that number of mistakes.

Assume that Bajtek always correctly starts with operation "T".

Input

The first line contains the integers n and r (1 ≤ n, r ≤ 106).

Output

The first line of the output should contain one number — the minimum possible number of mistakes made by Bajtek. The second line should contain n characters, starting with "T", describing one possible sequence of operations with that number of mistakes. Each character must be either "T" or "B".

If the required sequence doesn't exist, output "IMPOSSIBLE" (without quotes).

Examples

Input

6 10

Output

2
TBBTTB

Input

4 5

Output

0
TBTB

Input

2 1

Output

IMPOSSIBLE

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mx = 1000005;
const int inf = 0x3f3f3f3f;
int t, n, r, ans;
char a[mx], c[mx];
void solve(int t, int b) {
  int j = 1;
  while (t != b && t >= 0 && b >= 0) {
    if (t > b) {
      c[j++] = 'T';
      t -= b;
    } else {
      c[j++] = 'B';
      b -= t;
    }
  }
  if (j != n || t != 1) return;
  c[n] = 'T';
  int sum = 0;
  for (int i = 0; i < n; i++)
    if (c[i] == c[i + 1]) sum++;
  if (sum < ans) {
    ans = sum;
    for (int i = 0; i < n; i++) {
      a[i] = c[n - i];
    }
    a[n] = '\n';
  }
}
int main() {
  while (scanf("%d%d", &n, &r) != EOF) {
    ans = inf;
    for (int i = 1; i <= r; i++) {
      solve(i, r);
      solve(r, i);
    }
    if (ans == inf)
      printf("IMPOSSIBLE\n");
    else {
      printf("%d\n", ans);
      for (int i = 0; i < n; i++) printf("%c", a[i]);
      puts("");
    }
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lowercase English letter.

<image>

Max and Lucas are playing the game. Max goes first, then Lucas, then Max again and so on. Each player has a marble, initially located at some vertex. Each player in his/her turn should move his/her marble along some edge (a player can move the marble from vertex v to vertex u if there's an outgoing edge from v to u). If the player moves his/her marble from vertex v to vertex u, the "character" of that round is the character written on the edge from v to u. There's one additional rule; the ASCII code of character of round i should be greater than or equal to the ASCII code of character of round i - 1 (for i > 1). The rounds are numbered for both players together, i. e. Max goes in odd numbers, Lucas goes in even numbers. The player that can't make a move loses the game. The marbles may be at the same vertex at the same time.

Since the game could take a while and Lucas and Max have to focus on finding Dart, they don't have time to play. So they asked you, if they both play optimally, who wins the game?

You have to determine the winner of the game for all initial positions of the marbles.

Input

The first line of input contains two integers n and m (2 ≤ n ≤ 100, <image>).

The next m lines contain the edges. Each line contains two integers v, u and a lowercase English letter c, meaning there's an edge from v to u written c on it (1 ≤ v, u ≤ n, v ≠ u). There's at most one edge between any pair of vertices. It is guaranteed that the graph is acyclic.

Output

Print n lines, a string of length n in each one. The j-th character in i-th line should be 'A' if Max will win the game in case her marble is initially at vertex i and Lucas's marble is initially at vertex j, and 'B' otherwise.

Examples

Input

4 4
1 2 b
1 3 a
2 4 c
3 4 b

Output

BAAA
ABAA
BBBA
BBBB

Input

5 8
5 3 h
1 2 c
3 1 c
3 2 r
5 1 r
4 3 z
5 4 r
5 2 h

Output

BABBB
BBBBB
AABBB
AAABA
AAAAB

Note

Here's the graph in the first sample test case:

<image>

Here's the graph in the second sample test case:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e2 + 5;
const int inf = 0x3f3f3f3f;
struct node {
  int v, next, w;
} e[maxn * maxn / 2];
int head[maxn], tot, dp[maxn][maxn][30];
int dfs(int u, int v, int val) {
  if (dp[u][v][val] != -1) return dp[u][v][val];
  dp[u][v][val] = 0;
  for (int i = head[u]; i + 1; i = e[i].next) {
    if (e[i].w >= val && !dfs(v, e[i].v, e[i].w)) dp[u][v][val] = 1;
  }
  return dp[u][v][val];
}
void add(int u, int v, int w) {
  e[tot].v = v;
  e[tot].w = w;
  e[tot].next = head[u];
  head[u] = tot++;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  memset(dp, -1, sizeof(dp));
  while (m--) {
    int u, v;
    char s[2];
    scanf("%d%d%s", &u, &v, s);
    add(u, v, s[0] - 'a');
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0))
        printf("A");
      else
        printf("B");
    }
    puts("");
  }
}

```


### Prompt

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

Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.

Note that the order of the points inside the group of three chosen points doesn't matter.

Input

The first line contains two integers: n and d (1 ≤ n ≤ 105; 1 ≤ d ≤ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 — the x-coordinates of the points that Petya has got.

It is guaranteed that the coordinates of the points in the input strictly increase.

Output

Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed d.

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

Examples

Input

4 3
1 2 3 4

Output

4

Input

4 2
-3 -2 -1 0

Output

2

Input

5 19
1 10 20 30 50

Output

1

Note

In the first sample any group of three points meets our conditions.

In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.

In the third sample only one group does: {1, 10, 20}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  int arr[100012];
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long lower = 0;
  int higher = 0;
  long long kount = 0;
  arr[n] = 1e9 + 7;
  for (long long i = 0; i < n; i++) {
    while (arr[higher] - arr[i] <= d && higher < n) higher++;
    kount = kount + (higher - i - 1) * (higher - i - 2) / 2;
  }
  cout << kount << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.

Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Constraints

* 2 ≤ H, W ≤ 10^5

Input

Input is given from Standard Input in the following format:

H W

Output

Print the minimum possible value of S_{max} - S_{min}.

Examples

Input

3 5

Output

0

Input

4 5

Output

2

Input

5 5

Output

4

Input

100000 2

Output

1

Input

100000 100000

Output

50000

### Response

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

using namespace std;

int main(void){
	long long int h, w;

	cin >> h >> w;

	long long int m = 1e9;

	for (int i = 1; i < h; i++){
		m = min(m, max(w/2*i, max((w-w/2)*i, w*(h-i))) - min(w/2*i, min((w-w/2)*i, w*(h-i))));
	}

	for (int i = 1; i < w; i++){
		m = min(m, max(h/2*i, max((h-h/2)*i, h*(w-i))) - min(h/2*i, min((h-h/2)*i, h*(w-i))));
	}

	if (h % 3 == 0 || w % 3 == 0)
		m = 0;

	m = min(m, min(h, w));

	cout << m << endl;

}
```


### Prompt

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

You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

For instance, if we are given an array [10, 20, 30, 40], we can permute it so that it becomes [20, 40, 10, 30]. Then on the first and the second positions the integers became larger (20>10, 40>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 2. Read the note for the first example, there is one more demonstrative test case.

Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

Input

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

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

Output

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

Examples

Input

7
10 1 1 1 5 5 3

Output

4

Input

5
1 1 1 1 1

Output

0

Note

In the first sample, one of the best permutations is [1, 5, 5, 3, 10, 1, 1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, ans = 0;
  cin >> n;
  long long int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  int i = 0, j = 1;
  while (j != n) {
    if (arr[i] < arr[j])
      i++, j++, ans++;
    else
      j++;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.

<image>

The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.

In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.

Input

The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.

Output

Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.

Examples

Input

9

Output

+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+

Input

20

Output

+------------------------+
|O.O.O.O.O.O.O.#.#.#.#.|D|)
|O.O.O.O.O.O.#.#.#.#.#.|.|
|O.......................|
|O.O.O.O.O.O.#.#.#.#.#.|.|)
+------------------------+

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
void printLine() {
  cout << '+';
  for (int i = 0; i < (int)(24); ++i) cout << '-';
  cout << "+\n";
}
void pLine(int cnt, bool d = false) {
  printf("|");
  for (int i = 0; i < (int)(cnt); ++i) printf("O.");
  for (int i = 0; i < (int)(11 - cnt); ++i) printf("#.");
  printf("|");
  if (d)
    printf("D");
  else
    printf(".");
  printf("|");
}
void pLine2() {
  printf("|");
  if (n < 3)
    printf("#");
  else
    printf("O");
  for (int i = 0; i < (int)(23); ++i) printf(".");
  printf("|");
}
int main() {
  scanf("%d", &n);
  printLine();
  int m = n - 4;
  if (n == 0)
    pLine(0, true);
  else if (n <= 4)
    pLine(1, true);
  else
    pLine(1 + (m + 2) / 3, true);
  printf(")\n");
  if (n <= 1)
    pLine(0);
  else if (n <= 4)
    pLine(1);
  else
    pLine(1 + (m + 1) / 3);
  printf("\n");
  pLine2();
  printf("\n");
  if (n <= 3)
    pLine(0);
  else if (n == 4)
    pLine(1);
  else
    pLine(1 + m / 3);
  printf(")\n");
  printLine();
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

During a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.

As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum k, that the promotional code could be uniquely identified if it was typed with no more than k errors. At that, k = 0 means that the promotional codes must be entered exactly.

A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.

Input

The first line of the output contains number n (1 ≤ n ≤ 1000) — the number of promocodes.

Each of the next n lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".

Output

Print the maximum k (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most k mistakes.

Examples

Input

2
000000
999999

Output

2

Input

6
211111
212111
222111
111111
112111
121111

Output

0

Note

In the first sample k < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string s[1055];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  int res = 6;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int cnt = 0;
      for (int k = 0; k < 6; k++) cnt += s[i][k] != s[j][k];
      res = min(res, (cnt - 1) / 2);
    }
  }
  cout << res << '\n';
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, if Jack uses the sequence 'right, left, break', when the sergeant yells: 'Left! Right! Left! Right! Left! Right!', Jack first makes a step with the right foot, then one with the left foot, then he is confused and stops for a moment, then again - this time according to the order - starts with the right foot, then uses the left foot, then - to the sergeant's irritation - he stops to catch his breath, to incorrectly start with the right foot again... Marching this way, Jack will make the step that he is supposed to in the given moment in only one third of cases.

When the officers convinced him he should do something about it, Jack decided to modify the basic sequence of steps that he repeats. However, in order not to get too tired, he has decided that the only thing he'll do is adding any number of breaks in any positions of the original sequence (a break corresponds to stopping for the duration of one step). Of course, Jack can't make a step on the same foot twice in a row, if there is no pause between these steps. It is, however, not impossible that the sequence of steps he used so far is incorrect (it would explain a lot, actually).

Help Private Jack! Given the sequence of steps he keeps repeating, calculate the maximal percentage of time that he can spend marching correctly after adding some breaks to his scheme.

Input

The first line of input contains a sequence consisting only of characters 'L', 'R' and 'X', where 'L' corresponds to a step with the left foot, 'R' — with the right foot, and 'X' — to a break. The length of the sequence will not exceed 106.

Output

Output the maximum percentage of time that Jack can spend marching correctly, rounded down to exactly six digits after the decimal point.

Examples

Input

X

Output

0.000000

Input

LXRR

Output

50.000000

Note

In the second example, if we add two breaks to receive LXXRXR, Jack will march: LXXRXRLXXRXRL... instead of LRLRLRLRLRLRL... and will make the correct step in half the cases. If we didn't add any breaks, the sequence would be incorrect — Jack can't step on his right foot twice in a row.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mod = (int)1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;
string s, t;
long double check(string s) {
  int g = 0, t = 0, f = 0, c = 0;
  for (unsigned int i = 0; i < s.length(); i++) {
    if (s[i] == 'X')
      t++;
    else if (s[i] == (t & 1 ? 'R' : 'L'))
      g++, t++, f = 0;
    else
      g++, t += 2, c += f, f = !f;
  }
  if (t & 1) t++, c += f;
  if (g * 2 > t) g -= c, t -= c * 2;
  return double(g) / t;
}
int main() {
  {
    srand(time(0));
    const string file = "";
    if (!file.empty()) {
      freopen((file + ".in").c_str(), "r", stdin);
      freopen((file + ".out").c_str(), "w", stdout);
    }
  }
  getline(cin, s);
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (i && s[i] == s[i - 1] && s[i] != 'X') t += 'X';
    t += s[i];
  }
  long double ans;
  if (s[0] == s[n - 1] && s[0] != 'X') {
    ans = max(check('X' + t), check(t + 'X'));
  } else {
    ans = check(t);
  }
  printf("%.6lf\n", double(floor(ans * 1e8) / 1e6));
  return (0);
}

```