### Prompt

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

Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".

Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows:

  1. initially, Inna chooses some cell of the table where letter "D" is written;
  2. then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name;
  3. Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D".

Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 103).

Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A".

Note that it is not guaranteed that the table contains at least one letter "D".

Output

If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer — the maximum number of times Inna can go through name DIMA.

Examples

Input

1 2
DI

Output

Poor Dima!

Input

2 2
MA
ID

Output

Poor Inna!

Input

5 5
DIMAD
DIMAI
DIMAM
DDMAA
AAMID

Output

4

Note

Notes to the samples:

In the first test sample, Inna cannot go through name DIMA a single time.

In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner.

In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
const int maxn = 1100;
int n, m, sz, ans, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}, dp[maxn][maxn],
                   used[maxn][maxn];
char a[maxn][maxn];
pair<int, int> b[maxn * maxn];
bool check(int x, int y, int u, int v) {
  if (a[x][y] == 'D' && a[u][v] == 'I') return true;
  if (a[x][y] == 'I' && a[u][v] == 'M') return true;
  if (a[x][y] == 'M' && a[u][v] == 'A') return true;
  if (a[x][y] == 'A' && a[u][v] == 'D') return true;
  return false;
}
void dfs(int x, int y) {
  used[x][y] = 1;
  dp[x][y] = 0;
  if (a[x][y] == 'A') dp[x][y] = 1;
  for (int i = 0; i < 4; ++i)
    if (x + dx[i] > 0 && x + dx[i] <= n && y + dy[i] > 0 && y + dy[i] <= m) {
      if (!check(x, y, x + dx[i], y + dy[i])) continue;
      if (used[x + dx[i]][y + dy[i]] == 1) {
        cout << "Poor Inna!";
        exit(0);
      }
      if (!used[x + dx[i]][y + dy[i]]) dfs(x + dx[i], y + dy[i]);
      dp[x][y] = max(dp[x][y], dp[x + dx[i]][y + dy[i]] + (a[x][y] == 'A'));
    }
  used[x][y] = 2;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'D') b[sz++] = make_pair(i, j);
    }
  for (int i = 0; i < sz; ++i) {
    if (!used[b[i].first][b[i].second]) dfs(b[i].first, b[i].second);
    ans = max(ans, dp[b[i].first][b[i].second]);
  }
  if (!ans)
    cout << "Poor Dima!";
  else
    cout << ans;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given an integer N.
For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.
For example, F(3,11) = 2 since 3 has one digit and 11 has two digits.
Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

Constraints

* 1 \leq N \leq 10^{10}
* N is an integer.

Input

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

N

Output

Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

Examples

Input

10000

Output

3

Input

1000003

Output

7

Input

9876543210

Output

6

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int ws(int n){
	int l=0;
	while(n) n/=10,l++;
	return l;
}
int f(long long n){
	for(int i=(int)sqrt(n);;i--)
		if(n%i==0)
			return n/i;
}
int main(){
	long long n;
	scanf("%lld",&n);
	printf("%d\n",ws(f(n)));
	return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.

There is a sequence a that consists of n integers a1, a2, ..., an. Let's denote f(l, r, x) the number of indices k such that: l ≤ k ≤ r and ak = x. His task is to calculate the number of pairs of indicies i, j (1 ≤ i < j ≤ n) such that f(1, i, ai) > f(j, n, aj).

Help Pashmak with the test.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 106). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the answer to the problem.

Examples

Input

7
1 2 1 1 2 2 1

Output

8

Input

3
1 1 1

Output

1

Input

5
1 2 3 4 5

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int l[N], v[N], r[N];
int seg[4 * N];
map<int, int> ls, rs;
void update(int n, int l, int r, int s, int e, int d) {
  if (r < s || l > e) return;
  if (l >= s && r <= e) {
    seg[n] += d;
    return;
  }
  int mid = (l + r) / 2;
  update(n * 2 + 1, l, mid, s, e, d);
  update(n * 2 + 2, mid + 1, r, s, e, d);
  seg[n] = seg[n * 2 + 1] + seg[n * 2 + 2];
}
int get(int n, int l, int r, int s, int e) {
  if (r < s || l > e) return 0;
  if (l >= s && r <= e) {
    return seg[n];
  }
  int mid = (l + r) / 2;
  return get(n * 2 + 1, l, mid, s, e) + get(n * 2 + 2, mid + 1, r, s, e);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> cmp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    cmp.push_back(v[i]);
  }
  sort(cmp.begin(), cmp.end());
  cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());
  for (int i = 0; i < n; i++) {
    v[i] = lower_bound(cmp.begin(), cmp.end(), v[i]) - cmp.begin();
  }
  for (int i = 0; i < n; i++) {
    ls[v[i]]++;
    l[i] = ls[v[i]];
  }
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += get(0, 0, N, 0, l[i] - 1);
    rs[v[i]]++;
    r[i] = rs[v[i]];
    update(0, 0, N, r[i], r[i], 1);
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.

Kevin is a meticulous cowbell collector and knows that the size of his i-th (1 ≤ i ≤ n) cowbell is an integer si. In fact, he keeps his cowbells sorted by size, so si - 1 ≤ si for any i > 1. Also an expert packer, Kevin can fit one or two cowbells into a box of size s if and only if the sum of their sizes does not exceed s. Given this information, help Kevin determine the smallest s for which it is possible to put all of his cowbells into k boxes of size s.

Input

The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 2·k ≤ 100 000), denoting the number of cowbells and the number of boxes, respectively.

The next line contains n space-separated integers s1, s2, ..., sn (1 ≤ s1 ≤ s2 ≤ ... ≤ sn ≤ 1 000 000), the sizes of Kevin's cowbells. It is guaranteed that the sizes si are given in non-decreasing order.

Output

Print a single integer, the smallest s for which it is possible for Kevin to put all of his cowbells into k boxes of size s.

Examples

Input

2 1
2 5

Output

7

Input

4 3
2 3 5 9

Output

9

Input

3 2
3 5 7

Output

8

Note

In the first sample, Kevin must pack his two cowbells into the same box.

In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.

In the third sample, the optimal solution is {3, 5} and {7}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long _max = a[n - 1];
  for (long long i = 0; i < n - k; i++)
    _max = max(_max, a[i] + a[2 * (n - k) - i - 1]);
  cout << _max;
  return 0;
}

```


### Prompt

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

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.

Let's call a sequence of non-negative integers v1, v2, ..., vn a plan, if v1 + v2 + ... + vn = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v1 lines of the given task, then the second programmer writes v2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let's call a plan good, if all the written lines of the task contain at most b bugs in total.

Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer mod.

Input

The first line contains four integers n, m, b, mod (1 ≤ n, m ≤ 500, 0 ≤ b ≤ 500; 1 ≤ mod ≤ 109 + 7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer.

The next line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of bugs per line for each programmer.

Output

Print a single integer — the answer to the problem modulo mod.

Examples

Input

3 3 3 100
1 1 1

Output

10

Input

3 6 5 1000000007
1 2 3

Output

0

Input

3 5 6 11
1 2 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, b, mod, ans = 0;
int dp[505][505];
int main() {
  cin >> n >> m >> b >> mod;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    for (int j = 1; j <= m; j++) {
      for (int k = x; k <= b; k++) (dp[j][k] += dp[j - 1][k - x]) %= mod;
    }
  }
  for (int i = 0; i <= b; i++) {
    (ans += dp[m][i]) %= mod;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.

You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.

A position is good if two conditions hold:

  * there is no actor in the cell the spotlight is placed to;
  * there is at least one actor in the direction the spotlight projects.

Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the plan.

The next n lines contain m integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.

Output

Print one integer — the number of good positions for placing the spotlight.

Examples

Input

2 4
0 1 0 0
1 0 1 0

Output

9

Input

4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0

Output

20

Note

In the first example the following positions are good:

  1. the (1, 1) cell and right direction;
  2. the (1, 1) cell and down direction;
  3. the (1, 3) cell and left direction;
  4. the (1, 3) cell and down direction;
  5. the (1, 4) cell and left direction;
  6. the (2, 2) cell and left direction;
  7. the (2, 2) cell and up direction;
  8. the (2, 2) and right direction;
  9. the (2, 4) cell and left direction.

Therefore, there are 9 good positions in this example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1010][1010], co[1010][1010], st[1010][1010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      st[i][j] = a[i][j];
      co[i][j] = a[i][j];
      if (i > 0) co[i][j] += co[i - 1][j];
      if (j > 0) st[i][j] += st[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == 0) {
        if (co[n - 1][j] - co[i][j] > 0) ans++;
        if (co[i][j] > 0) ans++;
        if (st[i][j] > 0) ans++;
        if (st[i][m - 1] - st[i][j] > 0) ans++;
      }
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Barney was hanging out with Nora for a while and now he thinks he may have feelings for her. Barney wants to send her a cheesy text message and wants to make her as happy as possible.

<image>

Initially, happiness level of Nora is 0. Nora loves some pickup lines like "I'm falling for you" and stuff. Totally, she knows n pickup lines, each consisting only of lowercase English letters, also some of them may be equal (in writing, but different in pronouncing or meaning though). Every time Nora sees i-th pickup line as a consecutive subsequence of Barney's text message her happiness level increases by ai. These substrings may overlap, for example, Nora will see the pickup line aa twice and the pickup line ab once in text message aaab.

Due to texting app limits, Barney's text may have up to l characters.

Barney asked you to help him make Nora as much happy as possible, it's gonna be legen...

Input

The first line of input contains two integers n and l (1 ≤ n ≤ 200, 1 ≤ l ≤ 1014) — the number of pickup lines and the maximum length of Barney's text.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100), meaning that Nora's happiness level increases by ai after every time seeing i-th pickup line.

The next n lines contain the pickup lines. i-th of them contains a single string si consisting of only English lowercase letter. Summary length of all pickup lines does not exceed 200.

All strings are not empty.

Output

Print the only integer — the maximum possible value of Nora's happiness level after reading Barney's text.

Examples

Input

3 6
3 2 1
heart
earth
art

Output

6

Input

3 6
3 2 8
heart
earth
art

Output

16

Note

An optimal answer for the first sample case is hearth containing each pickup line exactly once.

An optimal answer for the second sample case is artart.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 205;
long long n, m, tot, val[N], h[N], ch[N][26], fail[N], v, i, ans, cur, u, j, c,
    len;
char a[N];
struct w {
  long long c[N][N];
  w() {
    for (long long i = 0; i < N; i++)
      for (long long j = 0; j < N; j++) c[i][j] = -1e18;
  }
  w operator*(w x) {
    w res;
    for (long long k = 0; k <= tot; k++)
      for (long long i = 0; i <= tot; i++)
        for (long long j = 0; j <= tot; j++)
          res.c[i][j] = max(res.c[i][j], c[i][k] + x.c[k][j]);
    return res;
  }
} k;
w pow(w x, long long y) {
  w res;
  for (long long i = 0; i <= tot; ++i) res.c[i][i] = 0;
  while (y) {
    if (y & 1) res = res * x;
    x = x * x;
    y >>= 1;
  }
  return res;
}
int main() {
  scanf("%d%lld", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%d", &val[i]);
  for (i = 1; i <= n; ++i) {
    scanf("%s", a + 1);
    cur = 0;
    len = strlen(a + 1);
    for (long long j = 1; j <= len; j++) {
      c = a[j] - 'a';
      if (!ch[cur][c]) ch[cur][c] = ++tot;
      cur = ch[cur][c];
    }
    h[cur] += val[i];
  }
  deque<long long> q;
  for (i = 0; i < 26; ++i) {
    v = ch[0][i];
    if (v) q.push_back(v);
  }
  while (!q.empty()) {
    u = q.front();
    q.pop_front();
    h[u] += h[fail[u]];
    for (i = 0; i < 26; ++i) {
      v = ch[u][i];
      if (v)
        fail[v] = ch[fail[u]][i], q.push_back(v);
      else
        ch[u][i] = ch[fail[u]][i];
    }
  }
  for (i = 0; i <= tot; ++i)
    for (j = 0; j < 26; ++j) cur = ch[i][j], k.c[i][cur] = h[cur];
  k = pow(k, m);
  for (long long i = 0; i <= tot; ++i) ans = max(ans, k.c[0][i]);
  printf("%lld", ans);
}

```


### Prompt

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

Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.

Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.

The sweepstake has the following prizes (the prizes are sorted by increasing of their cost):

  * a mug (costs a points),
  * a towel (costs b points),
  * a bag (costs c points),
  * a bicycle (costs d points),
  * a car (costs e points).

Now Vasya wants to recollect what prizes he has received. You know sequence p1, p2, ..., pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Output

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed.

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

3
3 10 4
2 4 10 15 20

Output

1 1 1 0 0
1

Input

4
10 4 39 2
3 5 10 11 12

Output

3 0 1 0 3
0

Note

In the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.

### Response

```cpp
#include <bits/stdc++.h>
struct compare {
  bool operator()(const int& l, const int& r) { return l > r; }
};
using namespace std;
priority_queue<int, vector<int>, compare> pq;
long long ans[5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long arr[n], c[5];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < 5; i++) cin >> c[i];
  long long tot = 0;
  for (int i = 0; i < n; i++) {
    tot += arr[i];
    if (tot < c[0]) continue;
    int itr = 0;
    while (itr < 5 && c[itr] <= tot) itr++;
    itr--;
    for (; itr >= 0; itr--) {
      ans[itr] += tot / c[itr];
      tot -= (tot / c[itr]) * c[itr];
    }
  }
  for (int i = 0; i < 5; i++) cout << ans[i] << " ";
  cout << "\n";
  cout << tot << "\n";
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Naman has two binary strings s and t of length n (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert s into t using the following operation as few times as possible.

In one operation, he can choose any subsequence of s and rotate it clockwise once.

For example, if s = 1110100, he can choose a subsequence corresponding to indices (1-based) \{2, 6, 7 \} and rotate them clockwise. The resulting string would then be s = 1010110.

A string a is said to be a subsequence of string b if a can be obtained from b by deleting some characters without changing the ordering of the remaining characters.

To perform a clockwise rotation on a sequence c of size k is to perform an operation which sets c_1:=c_k, c_2:=c_1, c_3:=c_2, …, c_k:=c_{k-1} simultaneously.

Determine the minimum number of operations Naman has to perform to convert s into t or say that it is impossible.

Input

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

The second line contains the binary string s of length n.

The third line contains the binary string t of length n.

Output

If it is impossible to convert s to t after any number of operations, print -1.

Otherwise, print the minimum number of operations required.

Examples

Input

6
010000
000001

Output

1

Input

10
1111100000
0000011111

Output

5

Input

8
10101010
01010101

Output

1

Input

10
1111100000
1111100001

Output

-1

Note

In the first test, Naman can choose the subsequence corresponding to indices \{2, 6\} and rotate it once to convert s into t.

In the second test, he can rotate the subsequence corresponding to all indices 5 times. It can be proved, that it is the minimum required number of operations.

In the last test, it is impossible to convert s into t.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  long long int cnt = 0;
  long long int ans = 0;
  long long int mn = 0, mx = 0;
  for (long long int i = 0; i < (long long int)(n); i++) {
    if (s[i] == '0' && t[i] == '1')
      cnt++;
    else if (s[i] == '1' && t[i] == '0')
      cnt--;
    ans = max({ans, abs(cnt - mx), abs(cnt - mn)});
    mn = min(mn, cnt);
    mx = max(mx, cnt);
  }
  if (cnt != 0) {
    cout << -1 << '\n';
    return;
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < (long long int)(t); i++) {
    solve();
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You are given a tree (an undirected connected graph without cycles) and an integer s.

Vanya wants to put weights on all edges of the tree so that all weights are non-negative real numbers and their sum is s. At the same time, he wants to make the diameter of the tree as small as possible.

Let's define the diameter of a weighed tree as the maximum sum of the weights of the edges lying on the path between two some vertices of the tree. In other words, the diameter of a weighed tree is the length of the longest simple path in the tree, where length of a path is equal to the sum of weights over all edges in the path.

Find the minimum possible diameter that Vanya can get.

Input

The first line contains two integer numbers n and s (2 ≤ n ≤ 10^5, 1 ≤ s ≤ 10^9) — the number of vertices in the tree and the sum of edge weights.

Each of the following n−1 lines contains two space-separated integer numbers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) — the indexes of vertices connected by an edge. The edges are undirected.

It is guaranteed that the given edges form a tree.

Output

Print the minimum diameter of the tree that Vanya can get by placing some non-negative real weights on its edges with the sum equal to s.

Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if \frac {|a-b|} {max(1, b)} ≤ 10^{-6}.

Examples

Input

4 3
1 2
1 3
1 4

Output

2.000000000000000000

Input

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

Output

0.500000000000000000

Input

5 5
1 2
2 3
3 4
3 5

Output

3.333333333333333333

Note

In the first example it is necessary to put weights like this:

<image>

It is easy to see that the diameter of this tree is 2. It can be proved that it is the minimum possible diameter.

In the second example it is necessary to put weights like this:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100010];
int main() {
  int k = 0, n, s, x, y, i;
  long double ans;
  cin >> n >> s;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (i = 1; i <= n; i++) {
    if (v[i].size() == 1) k++;
  }
  ans = 1.0 * s / k * 2;
  cout << setprecision(21) << ans << endl;
}

```


### Prompt

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

While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used).

Suppose the cache may store no more than k objects. At the beginning of the workflow the cache is empty. When some object is queried we check if it is present in the cache and move it here if it's not. If there are more than k objects in the cache after this, the least recently used one should be removed. In other words, we remove the object that has the smallest time of the last query.

Consider there are n videos being stored on the server, all of the same size. Cache can store no more than k videos and caching algorithm described above is applied. We know that any time a user enters the server he pick the video i with probability pi. The choice of the video is independent to any events before.

The goal of this problem is to count for each of the videos the probability it will be present in the cache after 10100 queries.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 20) — the number of videos and the size of the cache respectively. Next line contains n real numbers pi (0 ≤ pi ≤ 1), each of them is given with no more than two digits after decimal point.

It's guaranteed that the sum of all pi is equal to 1.

Output

Print n real numbers, the i-th of them should be equal to the probability that the i-th video will be present in the cache after 10100 queries. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

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

Examples

Input

3 1
0.3 0.2 0.5

Output

0.3 0.2 0.5

Input

2 1
0.0 1.0

Output

0.0 1.0

Input

3 2
0.3 0.2 0.5

Output

0.675 0.4857142857142857 0.8392857142857143

Input

3 3
0.2 0.3 0.5

Output

1.0 1.0 1.0

### Response

```cpp
#include <bits/stdc++.h>
double p[22], d[(1 << 20) + 10];
double ans[22];
int hmany(int a) {
  int ret = 0;
  while (a) {
    if (a % 2) ret++;
    a >>= 1;
  }
  return ret;
}
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &p[i]);
    if (p[i] == 0) num++;
  }
  if (n - num < k) k = n - num;
  memset(d, 0, sizeof(d));
  d[0] = 1.0;
  for (int i = 0; i < (1 << n); i++) {
    int tmp = i;
    double tmpp = 0.0;
    int tmpk = 0;
    for (int j = 1; j <= n; j++) {
      if (i & (1 << (j - 1))) {
        tmpk++;
      } else
        tmpp += p[j];
    }
    if (tmpk >= k) continue;
    for (int j = 1; j <= n; j++) {
      if (((1 << (j - 1)) & i) == 0) {
        d[i | (1 << (j - 1))] += d[i] * (p[j] / tmpp);
      }
    }
  }
  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < (1 << n); i++) {
    if (hmany(i) != k) continue;
    for (int j = 1; j <= n; j++) {
      if ((1 << (j - 1)) & i) {
        ans[j] += d[i];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%.10lf\n", ans[i]);
  }
  return 0;
}

```


### Prompt

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

Many people are aware of DMCA – Digital Millennium Copyright Act. But another recently proposed DMCA – Digital Millennium Calculation Act – is much less known.

In this problem you need to find a root of a number according to this new DMCA law.

Input

The input contains a single integer a (1 ≤ a ≤ 1000000).

Output

Output the result – an integer number.

Examples

Input

1

Output

1

Input

81

Output

9

### Response

```cpp
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

#define ll long long int
#define ld long double

using namespace std;

void Void(){
    int64_t n;
    cin >> n;
    while(n >= 10){
        int64_t sum = 0;
        int64_t a = n;
        while(a != 0){
            sum += a % 10;
            a /= 10;
        }
        n = sum;
    }
    cout << n << endl;
}

int main(){
    int t = 1;
//    cin >> t;
    while(t--)Void();
    return 0;
}

```


### Prompt

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

Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.

The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components of the vectors. The unusual square of an n × n square matrix A is defined as the sum of n dot products. The i-th of them is the dot product of the i-th row vector and the i-th column vector in the matrix A.

Fortunately for Chris, he has to work only in GF(2)! This means that all operations (addition, multiplication) are calculated modulo 2. In fact, the matrix A is binary: each element of A is either 0 or 1. For example, consider the following matrix A:

<image>

The unusual square of A is equal to (1·1 + 1·0 + 1·1) + (0·1 + 1·1 + 1·0) + (1·1 + 0·1 + 0·0) = 0 + 1 + 1 = 0.

However, there is much more to the homework. Chris has to process q queries; each query can be one of the following:

  1. given a row index i, flip all the values in the i-th row in A;
  2. given a column index i, flip all the values in the i-th column in A;
  3. find the unusual square of A.

To flip a bit value w means to change it to 1 - w, i.e., 1 changes to 0 and 0 changes to 1.

Given the initial matrix A, output the answers for each query of the third type! Can you solve Chris's homework?

Input

The first line of input contains an integer n (1 ≤ n ≤ 1000), the number of rows and the number of columns in the matrix A. The next n lines describe the matrix: the i-th line contains n space-separated bits and describes the i-th row of A. The j-th number of the i-th line aij (0 ≤ aij ≤ 1) is the element on the intersection of the i-th row and the j-th column of A.

The next line of input contains an integer q (1 ≤ q ≤ 106), the number of queries. Each of the next q lines describes a single query, which can be one of the following:

  * 1 i — flip the values of the i-th row;
  * 2 i — flip the values of the i-th column;
  * 3 — output the unusual square of A.

Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

Output

Let the number of the 3rd type queries in the input be m. Output a single string s of length m, where the i-th symbol of s is the value of the unusual square of A for the i-th query of the 3rd type as it appears in the input.

Examples

Input

3
1 1 1
0 1 1
1 0 0
12
3
2 3
3
2 2
2 2
1 3
3
3
1 2
2 1
1 1
3

Output

01001

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(const T& c) {
  return c.size();
}
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const int maxn = 1000 + 10;
int n, u, q, com;
int res;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &u);
      if (i == j) res = (res + u) % 2;
    }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &com);
    if (com == 3)
      printf("%d", res);
    else {
      scanf("%d", &u);
      res = 1 - res;
    }
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}

```


### Prompt

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

A sequence of n integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let x and y be two adjacent numbers (x before y), then he can remove them and write x + 2y instead of them. He will perform these operations until one number is left. Sasha likes big numbers and will get the biggest possible number.

Nikita wants to get to the blackboard before Sasha and erase some of the numbers. He has q options, in the option i he erases all numbers to the left of the li-th number and all numbers to the right of ri-th number, i. e. all numbers between the li-th and the ri-th, inclusive, remain on the blackboard. For each of the options he wants to know how big Sasha's final number is going to be. This number can be very big, so output it modulo 109 + 7.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 105) — the number of integers on the blackboard and the number of Nikita's options.

The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence on the blackboard.

Each of the next q lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), describing Nikita's options.

Output

For each option output Sasha's result modulo 109 + 7.

Examples

Input

3 3
1 2 3
1 3
1 2
2 3

Output

17
5
8

Input

3 1
1 2 -3
1 3

Output

1000000006

Input

4 2
1 1 1 -1
1 4
3 4

Output

5
1000000006

Note

In the second sample Nikita doesn't erase anything. Sasha first erases the numbers 1 and 2 and writes 5. Then he erases 5 and -3 and gets -1. -1 modulo 109 + 7 is 109 + 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10, Max = 2e9, mod = 1e9 + 7;
vector<pair<int, int> > Q[N];
int a[N], pre[N], fa[N], Pw[N], Suf[N], Sum[N], ans[N];
inline int read() {
  int x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') flag = -1, ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch - '0'), ch = getchar();
  return x * flag;
}
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline void Merge(int x, int y) {
  fa[x] = fa[y], pre[y] = pre[x];
  long long Len = x - pre[x];
  if ((Len > 30 && a[y] > 0) || (a[x] + (1ll * a[y] << Len) > Max))
    a[y] = Max + 10;
  else
    a[y] = a[x] + (a[y] << Len);
}
inline int Query(int l, int r) {
  return (Suf[l] - 1ll * Suf[r + 1] * Pw[r - l + 1] % mod + mod) % mod;
}
int main() {
  int n = read(), q = read();
  Pw[0] = 1;
  for (int i = (1), iend = (n); i <= iend; i++)
    a[i] = read(), pre[i] = i - 1, fa[i] = i, Pw[i] = Pw[i - 1] * 2 % mod;
  for (int i = (n), iend = (1); i >= iend; i--)
    Suf[i] = (Suf[i + 1] * 2ll + a[i] + mod) % mod;
  for (int i = (1), iend = (q); i <= iend; i++) {
    int l = read(), r = read();
    Q[r].push_back(make_pair(l, i));
  }
  for (int i = (1), iend = (n); i <= iend; i++) {
    while (pre[i] && a[i] > 0) Merge(pre[i], i);
    Sum[i] = (Sum[pre[i]] + 2ll * Query(pre[i] + 1, i)) % mod;
    for (int j = (0), jend = (Q[i].size() - 1); j <= jend; j++) {
      int pos = find(Q[i][j].first);
      ans[Q[i][j].second] =
          ((Sum[i] - Sum[pos] + Query(Q[i][j].first, pos)) % mod + mod) % mod;
    }
  }
  for (int i = (1), iend = (q); i <= iend; i++) printf("%d\n", ans[i]);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.

The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.

Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).

Vova can put bricks horizontally on the neighboring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).

The next paragraph is specific to the version 1 of the problem.

Vova can also put bricks vertically. That means increasing height of any part of the wall by 2.

Vova is a perfectionist, so he considers the wall completed when:

  * all parts of the wall has the same height;
  * the wall has no empty spaces inside it.

Can Vova complete the wall using any amount of bricks (possibly zero)?

Input

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

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.

Output

Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).

Print "NO" otherwise.

Examples

Input

5
2 1 1 2 5

Output

YES

Input

3
4 5 3

Output

YES

Input

2
10 10

Output

YES

Input

3
1 2 3

Output

NO

Note

In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].

In the second example Vova can put a brick vertically on part 3 to make the wall [4, 5, 5], then horizontally on parts 2 and 3 to make it [4, 6, 6] and then vertically on part 1 to make it [6, 6, 6].

In the third example the wall is already complete.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAX = 2e5 + 5;
const long long MAX2 = 11;
const int MOD = 1000000000 + 7;
const long long INF = 20000;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const double pi = acos(-1);
const double EPS = 1e-9;
int n, x[MAX], mx;
stack<int> s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  if (n == 1) return cout << "YES", 0;
  x[0] = x[n + 1] = 2e9;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    mx = max(mx, x[i]);
    if (s.empty() || s.top() != x[i])
      s.push(x[i]);
    else
      s.pop();
  }
  for (int i = 1; i <= n; i++)
    if (x[i - 1] > x[i] && x[i + 1] > x[i]) return cout << "NO", 0;
  if (s.empty() || (s.size() < 2 && s.top() == mx))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

```


### Prompt

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

Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com).

It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots.

You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result.

Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at.

Input

The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols.

Output

Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages).

In the ASCII table the symbols go in this order: . @ ab...z

Examples

Input

vasyaatgmaildotcom

Output

vasya@gmail.com

Input

dotdotdotatdotdotat

Output

dot..@..at

Input

aatt

Output

a@t

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[110];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  bool et = false;
  for (int i = 0; i < n; i++) {
    bool printed = false;
    if (i != 0 && i + 2 != n - 1) {
      if (s[i] == 'd' && s[i + 1] == 'o' && s[i + 2] == 't') {
        printf(".");
        i += 2;
        printed = true;
      }
    }
    if (i != 0 && i + 1 != n - 1 && !et) {
      if (s[i] == 'a' && s[i + 1] == 't') {
        printf("@");
        i += 1;
        printed = true;
        et = true;
      }
    }
    if (!printed) printf("%c", s[i]);
  }
  printf("\n");
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

The official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1 ≤ i ≤ n) region has a stable temperature of ti degrees in summer.

This summer a group of m schoolchildren wants to get from the official capital to the cultural capital to visit museums and sights. The trip organizers transport the children between the cities in buses, but sometimes it is very hot. Specifically, if the bus is driving through the i-th region and has k schoolchildren, then the temperature inside the bus is ti + k degrees.

Of course, nobody likes it when the bus is hot. So, when the bus drives through the i-th region, if it has more than Ti degrees inside, each of the schoolchild in the bus demands compensation for the uncomfortable conditions. The compensation is as large as xi rubles and it is charged in each region where the temperature in the bus exceeds the limit.

To save money, the organizers of the trip may arbitrarily add or remove extra buses in the beginning of the trip, and between regions (of course, they need at least one bus to pass any region). The organizers can also arbitrarily sort the children into buses, however, each of buses in the i-th region will cost the organizers costi rubles. Please note that sorting children into buses takes no money.

Your task is to find the minimum number of rubles, which the organizers will have to spend to transport all schoolchildren.

Input

The first input line contains two integers n and m (1 ≤ n ≤ 105; 1 ≤ m ≤ 106) — the number of regions on the way and the number of schoolchildren in the group, correspondingly. Next n lines contain four integers each: the i-th line contains ti, Ti, xi and costi (1 ≤ ti, Ti, xi, costi ≤ 106). The numbers in the lines are separated by single spaces.

Output

Print the only integer — the minimum number of roubles the organizers will have to spend to transport all schoolchildren.

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

Examples

Input

2 10
30 35 1 100
20 35 10 10

Output

120

Input

3 100
10 30 1000 1
5 10 1000 3
10 40 1000 100000

Output

200065

Note

In the first sample the organizers will use only one bus to travel through the first region. However, the temperature in the bus will equal 30 + 10 = 40 degrees and each of 10 schoolchildren will ask for compensation. Only one bus will transport the group through the second region too, but the temperature inside won't exceed the limit. Overall, the organizers will spend 100 + 10 + 10 = 120 rubles.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  for (int i = (0); i < (n); ++i) {
    long long t, T, x, cost;
    cin >> t >> T >> x >> cost;
    if (t >= T) {
      ans += cost + m * x;
      continue;
    }
    long long aux1 = cost;
    if (m > (T - t)) aux1 += m * x;
    long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;
    aux2 *= cost;
    ans += min(aux1, aux2);
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Alice and Bob are playing a fun game of tree tag.

The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n-1 edges.

Initially, Alice is located at vertex a, and Bob at vertex b. They take turns alternately, and Alice makes the first move. In a move, Alice can jump to a vertex with distance at most da from the current vertex. And in a move, Bob can jump to a vertex with distance at most db from the current vertex. The distance between two vertices is defined as the number of edges on the unique simple path between them. In particular, either player is allowed to stay at the same vertex in a move. Note that when performing a move, a player only occupies the starting and ending vertices of their move, not the vertices between them.

If after at most 10^{100} moves, Alice and Bob occupy the same vertex, then Alice is declared the winner. Otherwise, Bob wins.

Determine the winner if both players play optimally.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). Description of the test cases follows.

The first line of each test case contains five integers n,a,b,da,db (2≤ n≤ 10^5, 1≤ a,b≤ n, a≠ b, 1≤ da,db≤ n-1) — the number of vertices, Alice's vertex, Bob's vertex, Alice's maximum jumping distance, and Bob's maximum jumping distance, respectively.

The following n-1 lines describe the edges of the tree. The i-th of these lines contains two integers u, v (1≤ u, v≤ n, u≠ v), denoting an edge between vertices u and v. It is guaranteed that these edges form a tree structure.

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

Output

For each test case, output a single line containing the winner of the game: "Alice" or "Bob".

Example

Input

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

Output

Alice
Bob
Alice
Alice

Note

In the first test case, Alice can win by moving to vertex 1. Then wherever Bob moves next, Alice will be able to move to the same vertex on the next move.

<image>

In the second test case, Bob has the following strategy to win. Wherever Alice moves, Bob will always move to whichever of the two vertices 1 or 6 is farthest from Alice.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m, k, t, mx, mi, x, y, u, v, dx, dy, idx, cnt, tot, sum, res, flag, st;
vector<int> e[maxn];
void dfs(int u, int pre, int dep, int op) {
  if (dep > mx) {
    mx = dep;
    idx = u;
  }
  if (u == y && op && dep <= dx) {
    flag = 1;
    return;
  }
  for (int v : e[u]) {
    if (v == pre) continue;
    dfs(v, u, dep + 1, op);
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    flag = 0;
    scanf("%d %d %d %d %d", &n, &x, &y, &dx, &dy);
    for (int i = 1; i <= n; i++) {
      e[i].clear();
    }
    for (int i = 1; i < n; i++) {
      scanf("%d %d", &u, &v);
      e[u].push_back(v);
      e[v].push_back(u);
    }
    mx = 0;
    dfs(x, 0, 0, 1);
    if (flag) {
      puts("Alice");
      continue;
    }
    mx = 0;
    dfs(idx, 0, 0, 0);
    puts(2 * dx >= mx || dy <= 2 * dx ? "Alice" : "Bob");
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Fedor runs for president of Byteland! In the debates, he will be asked how to solve Byteland's transport problem. It's a really hard problem because of Byteland's transport system is now a tree (connected graph without cycles). Fedor's team has found out in the ministry of transport of Byteland that there is money in the budget only for one additional road. In the debates, he is going to say that he will build this road as a way to maximize the number of distinct simple paths in the country. A simple path is a path which goes through every vertex no more than once. Two simple paths are named distinct if sets of their edges are distinct.

But Byteland's science is deteriorated, so Fedor's team hasn't succeeded to find any scientists to answer how many distinct simple paths they can achieve after adding exactly one edge on the transport system?

Help Fedor to solve it.

An edge can be added between vertices that are already connected, but it can't be a loop.

In this problem, we consider only simple paths of length at least two.

Input

The first line contains one integer n (2 ≤ n ≤ 500\ 000) — number of vertices in Byteland's transport system.

Each of the following n - 1 lines contains two integers v_i and u_i (1 ≤ v_i, u_i ≤ n). It's guaranteed that the graph is tree.

Output

Print exactly one integer — a maximal number of simple paths that can be achieved after adding one edge.

Examples

Input

2
1 2

Output

2

Input

4
1 2
1 3
1 4

Output

11

Input

6
1 2
1 3
3 4
3 5
4 6

Output

29

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500001;
struct Edge {
  int y, next;
} adj[MAXN * 2];
struct State {
  int size;
  long long f;
} state[MAXN];
int fch[MAXN], size[MAXN];
long long f[MAXN], ans;
int que[MAXN];
int n, m;
void add(int u, int v) {
  adj[++m] = (Edge){v, fch[u]};
  fch[u] = m;
}
long long square(int x) { return x * 1LL * x; }
long long check(State a, State b) {
  return a.f + b.f + square(n - a.size - b.size);
}
bool cross(State a, State b, State c) {
  double y0 = a.f + square(a.size);
  double x1 = b.size - a.size, y1 = b.f + square(b.size) - y0;
  double x2 = c.size - a.size, y2 = c.f + square(c.size) - y0;
  return x1 * y2 < x2 * y1;
}
bool cmp(State a, State b) { return a.size > b.size; }
void dfs(int t, int parent) {
  f[t] = 1LL << 60;
  size[t] = 1;
  for (int i = fch[t]; i != 0; i = adj[i].next) {
    int v = adj[i].y;
    if (v != parent) {
      dfs(v, t);
      size[t] += size[v];
    }
  }
  if (size[t] == 1) {
    f[t] = 1;
    return;
  }
  int m = 0;
  for (int i = fch[t]; i != 0; i = adj[i].next) {
    int v = adj[i].y;
    if (v != parent) {
      long long c = f[v] + square(size[t] - size[v]);
      if (c < f[t]) f[t] = c;
      if (parent == 0) {
        c = f[v] + square(n - size[v]);
        if (c < ans) ans = c;
      }
      state[m++] = (State){size[v], f[v]};
    }
  }
  if (m == 1) return;
  sort(state, state + m, cmp);
  int head = 0, tail = 0;
  que[0] = 0;
  for (int i = 1; i < m; i++) {
    while (head < tail && check(state[i], state[que[head]]) >=
                              check(state[i], state[que[head + 1]]))
      head++;
    long long c = check(state[i], state[que[head]]);
    if (c < ans) ans = c;
    que[++tail] = i;
    while (head + 1 < tail &&
           cross(state[que[tail - 2]], state[que[tail - 1]], state[que[tail]]))
      que[--tail] = i;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  ans = square(n);
  dfs(1, 0);
  cout << (square(n) - ans) / 2 + (n * 1LL * (n - 1) / 2) << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given n integers a1, a2, ..., an.

A sequence of integers x1, x2, ..., xk is called a "xor-sequence" if for every 1 ≤ i ≤ k - 1 the number of ones in the binary representation of the number xi <image> xi + 1's is a multiple of 3 and <image> for all 1 ≤ i ≤ k. The symbol <image> is used for the binary exclusive or operation.

How many "xor-sequences" of length k exist? Output the answer modulo 109 + 7.

Note if a = [1, 1] and k = 1 then the answer is 2, because you should consider the ones from a as different.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1018) — the number of given integers and the length of the "xor-sequences".

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

Output

Print the only integer c — the number of "xor-sequences" of length k modulo 109 + 7.

Examples

Input

5 2
15 1 2 4 8

Output

13

Input

5 1
15 1 2 4 8

Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int d;
vector<vector<long long>> multiply(vector<vector<long long>> A,
                                   vector<vector<long long>> B) {
  vector<vector<long long>> C(d, vector<long long>(d));
  for (int i = 0; i < d; i++)
    for (int j = 0; j < d; j++)
      for (int z = 0; z < d; z++)
        C[i][j] = (C[i][j] + (A[i][z] * B[z][j]) % MOD) % MOD;
  return C;
}
vector<vector<long long>> power(vector<vector<long long>> &A, long long p) {
  if (p == 1) return A;
  if (p & 1)
    return multiply(A, power(A, p - 1));
  else {
    vector<vector<long long>> X = power(A, p / 2);
    return multiply(X, X);
  }
}
int main() {
  ios::sync_with_stdio(0);
  long long i, j, n;
  long long k;
  cin >> n >> k;
  long long a[n];
  for (i = 0; i < n; ++i) cin >> a[i];
  d = n;
  vector<vector<long long>> b(n, vector<long long>(n)),
      c(n, vector<long long>(n));
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      b[i][j] = (__builtin_popcountll(a[i] ^ a[j]) % 3LL == 0);
    }
  }
  if (k == 1) {
    cout << n << "\n";
    return 0;
  }
  c = power(b, k - 1);
  long long ans = 0;
  for (i = 0; i < n; ++i)
    for (j = 0; j < n; ++j) ans = (ans + c[i][j]) % MOD;
  cout << ans << "\n";
  return 0;
}

```


### Prompt

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

IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.

A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.

Input

The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the prediction on the number of people who will buy the game.

Output

Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.

Examples

Input

3000

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long temp = 0, r, l, w, k = 0, m1, e, p, q, ans = 0, k1 = 0, k2 = 0, d = 0,
          a = 0, b = 0, s = 0, x, y, min1 = 1000000010, max1 = 0, m, c = 0,
          t = 0, i, n, c1 = 0, tot = 0, t1, k4 = 0, c2 = 0, j = 0, k3 = 0;
char ch, ch1, ch2;
string s1, s2, s3;
signed main() {
  cin >> n;
  k = n - n / 2 - n / 3 - n / 5 - n / 7 + n / (2 * 3) + n / (3 * 5) +
      n / (2 * 7) + n / (2 * 5) + n / (3 * 7) + n / (5 * 7) - n / (2 * 3 * 5) -
      n / (2 * 5 * 7) - n / (3 * 5 * 7) - n / (2 * 3 * 7) + n / (2 * 3 * 5 * 7);
  cout << k;
}

```


### Prompt

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

Vasya studies divisibility rules at school. Here are some of them:

  * Divisibility by 2. A number is divisible by 2 if and only if its last digit is divisible by 2 or in other words, is even.
  * Divisibility by 3. A number is divisible by 3 if and only if the sum of its digits is divisible by 3.
  * Divisibility by 4. A number is divisible by 4 if and only if its last two digits form a number that is divisible by 4.
  * Divisibility by 5. A number is divisible by 5 if and only if its last digit equals 5 or 0.
  * Divisibility by 6. A number is divisible by 6 if and only if it is divisible by 2 and 3 simultaneously (that is, if the last digit is even and the sum of all digits is divisible by 3).
  * Divisibility by 7. Vasya doesn't know such divisibility rule.
  * Divisibility by 8. A number is divisible by 8 if and only if its last three digits form a number that is divisible by 8.
  * Divisibility by 9. A number is divisible by 9 if and only if the sum of its digits is divisible by 9.
  * Divisibility by 10. A number is divisible by 10 if and only if its last digit is a zero.
  * Divisibility by 11. A number is divisible by 11 if and only if the sum of digits on its odd positions either equals to the sum of digits on the even positions, or they differ in a number that is divisible by 11.

Vasya got interested by the fact that some divisibility rules resemble each other. In fact, to check a number's divisibility by 2, 4, 5, 8 and 10 it is enough to check fulfiling some condition for one or several last digits. Vasya calls such rules the 2-type rules.

If checking divisibility means finding a sum of digits and checking whether the sum is divisible by the given number, then Vasya calls this rule the 3-type rule (because it works for numbers 3 and 9).

If we need to find the difference between the sum of digits on odd and even positions and check whether the difference is divisible by the given divisor, this rule is called the 11-type rule (it works for number 11).

In some cases we should divide the divisor into several factors and check whether rules of different types (2-type, 3-type or 11-type) work there. For example, for number 6 we check 2-type and 3-type rules, for number 66 we check all three types. Such mixed divisibility rules are called 6-type rules.

And finally, there are some numbers for which no rule works: neither 2-type, nor 3-type, nor 11-type, nor 6-type. The least such number is number 7, so we'll say that in such cases the mysterious 7-type rule works, the one that Vasya hasn't discovered yet.

Vasya's dream is finding divisibility rules for all possible numbers. He isn't going to stop on the decimal numbers only. As there are quite many numbers, ha can't do it all by himself. Vasya asked you to write a program that determines the divisibility rule type in the b-based notation for the given divisor d.

Input

The first input line contains two integers b and d (2 ≤ b, d ≤ 100) — the notation system base and the divisor. Both numbers are given in the decimal notation.

Output

On the first output line print the type of the rule in the b-based notation system, where the divisor is d: "2-type", "3-type", "11-type", "6-type" or "7-type". If there are several such types, print the one that goes earlier in the given sequence. If a number belongs to the 2-type, print on the second line the least number of the last b-based digits that we will need to use to check the divisibility.

Examples

Input

10 10

Output

2-type
1

Input

2 3

Output

11-type

Note

The divisibility rule for number 3 in binary notation looks as follows: "A number is divisible by 3 if and only if the sum of its digits that occupy the even places differs from the sum of digits that occupy the odd places, in a number that is divisible by 3". That's an 11-type rule. For example, 2110 = 101012. For it the sum of digits on odd positions equals 1 + 1 + 1 = 3, an on even positions — 0 + 0 = 0. The rule works and the number is divisible by 3.

In some notations a number can fit into the 3-type rule and the 11-type rule. In this case the correct answer is "3-type".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, s;
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int main() {
  scanf("%d%d", &n, &m);
  while (gcd(n, m) > 1) m /= gcd(n, m), s++;
  if (m == 1)
    printf("2-type\n%d\n", s);
  else {
    if ((n - 1) * (n + 1) / gcd(n - 1, n + 1) % m == 0) {
      if (!s && (n - 1) % m == 0)
        puts("3-type");
      else if (!s && (n + 1) % m == 0)
        puts("11-type");
      else
        puts("6-type");
    } else
      puts("7-type");
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis.

Petya decided to compress tables. He is given a table a consisting of n rows and m columns that is filled with positive integers. He wants to build the table a' consisting of positive integers such that the relative order of the elements in each row and each column remains the same. That is, if in some row i of the initial table ai, j < ai, k, then in the resulting table a'i, j < a'i, k, and if ai, j = ai, k then a'i, j = a'i, k. Similarly, if in some column j of the initial table ai, j < ap, j then in compressed table a'i, j < a'p, j and if ai, j = ap, j then a'i, j = a'p, j.

Because large values require more space to store them, the maximum value in a' should be as small as possible.

Petya is good in theory, however, he needs your help to implement the algorithm.

Input

The first line of the input contains two integers n and m (<image>, the number of rows and the number of columns of the table respectively.

Each of the following n rows contain m integers ai, j (1 ≤ ai, j ≤ 109) that are the values in the table.

Output

Output the compressed table in form of n lines each containing m integers.

If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them.

Examples

Input

2 2
1 2
3 4

Output

1 2
2 3

Input

4 3
20 10 30
50 40 30
50 60 70
90 80 70

Output

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

Note

In the first sample test, despite the fact a1, 2 ≠ a21, they are not located in the same row or column so they may become equal after the compression.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, nvt;
int **a, **id;
int dsu[1000010];
set<int> adj[1000010];
int din[1000010];
int DSU(int u) { return u == dsu[u] ? u : dsu[u] = DSU(dsu[u]); }
int merge(int u, int v) {
  int U = DSU(u);
  int V = DSU(v);
  dsu[U] = V;
  return V;
}
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
bool gone[1000010];
int value[1000010];
int main() {
  scanf("%d%d", &n, &m);
  a = new int *[n];
  id = new int *[n];
  nvt = 0;
  for (int i = 0; i < n; ++i) {
    a[i] = new int[m];
    id[i] = new int[m];
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      id[i][j] = ++nvt;
      dsu[nvt] = nvt;
    }
  }
  for (int i = 0; i < n; ++i) {
    map<int, int> assign;
    for (int j = 0; j < m; ++j) {
      if (assign.count(a[i][j]))
        assign[a[i][j]] = merge(id[i][j], assign[a[i][j]]);
      else
        assign[a[i][j]] = id[i][j];
    }
  }
  for (int j = 0; j < m; ++j) {
    map<int, int> assign;
    for (int i = 0; i < n; ++i) {
      if (assign.count(a[i][j]))
        assign[a[i][j]] = merge(id[i][j], assign[a[i][j]]);
      else
        assign[a[i][j]] = id[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    map<int, int> assign;
    for (int j = 0; j < m; ++j) assign[a[i][j]] = DSU(id[i][j]);
    for (int j = 0; j < m; ++j) {
      map<int, int>::iterator it = assign.upper_bound(a[i][j]);
      if (it != assign.end()) adj[assign[a[i][j]]].insert(it->second);
    }
  }
  for (int j = 0; j < m; ++j) {
    map<int, int> assign;
    for (int i = 0; i < n; ++i) assign[a[i][j]] = DSU(id[i][j]);
    for (int i = 0; i < n; ++i) {
      map<int, int>::iterator it = assign.upper_bound(a[i][j]);
      if (it != assign.end()) adj[assign[a[i][j]]].insert(it->second);
    }
  }
  for (int i = 1; i <= nvt; ++i) {
    if (DSU(i) != i) continue;
    for (set<int>::iterator it = adj[i].begin(); it != adj[i].end(); ++it)
      din[*it]++;
  }
  for (int i = 1; i <= nvt; ++i) {
    if (DSU(i) != i) continue;
    q.push(make_pair(din[i], i));
    value[i] = 1;
  }
  while (!q.empty()) {
    pair<int, int> cur = q.top();
    q.pop();
    if (gone[cur.second]) continue;
    gone[cur.second] = true;
    for (set<int>::iterator it = adj[cur.second].begin();
         it != adj[cur.second].end(); ++it) {
      value[*it] = max(value[*it], value[cur.second] + 1);
      din[*it]--;
      q.push(make_pair(din[*it], *it));
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) a[i][j] = value[DSU(id[i][j])];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) printf("%d ", a[i][j]);
    printf("\n");
  }
  return 0;
}

```


### Prompt

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

There are league games and tournament games in sports competitions. In soccer league games, points are given to each of the wins, losses, and draws, and the rankings are competed based on the points. The points are win (3 points), negative (0 points), and draw (1 point), respectively.

Enter the number of teams and the results of the league match, sort them in order of best results (in descending order of points), and create a program that outputs the team name and points. If the points are tied, output in the order of input.

Input

Given multiple datasets. Each dataset is given in the following format:

n
name1 w1 l1 d1
name2 w2 l2 d2
::
namen wn ln dn

The number of teams n (n ≤ 10) is given on the first line. The next n lines are given the name of team i (alphabet of up to 20 characters), the number of wins wi, the number of negatives li, and the number of draws di (0 ≤ wi, li, di ≤ 9), separated by spaces. ..

When the number of teams is 0, the input is completed. The number of datasets does not exceed 50.

Output

Print a sorted list of teams for each dataset. Print the name of the i-th team and the points on the i-line, separated by commas.

Insert one blank line between the datasets.

Example

Input

4
Japan 1 0 2
Egypt 1 2 0
Canada 0 2 1
Spain 2 0 1
3
India 0 2 0
Poland 1 0 1
Italy 1 0 1
0

Output

Spain,7
Japan,5
Egypt,3
Canada,1

Poland,4
Italy,4
India,0

### Response

```cpp
// 2011/02/02 Tazoe

#include <iostream>
#include <string>
using namespace std;

struct score{
	string nam;
	int win;
	int los;
	int drw;
	int ord;
	int pnt;
};

int main()
{
	bool flg = false;

	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		if(flg)
			cout << endl;
		else
			flg = true;

		struct score tem[10];
		for(int i=0; i<n; i++){
			cin >> tem[i].nam >> tem[i].win >> tem[i].los >> tem[i].drw;
			tem[i].ord = i;
		}

		for(int i=0; i<n; i++)
			tem[i].pnt = tem[i].win*3+tem[i].drw;

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(tem[i].pnt<tem[j].pnt||(tem[i].pnt==tem[j].pnt&&tem[i].ord>tem[j].ord)){
					struct score tmp = tem[i];
					tem[i] = tem[j];
					tem[j] = tmp;
				}

		for(int i=0; i<n; i++)
			cout << tem[i].nam << ',' << tem[i].pnt << endl;
	}

	return 0;
}
```


### Prompt

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

There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime".

In each move, a slime can move to east, west, south and north direction until it enters a cell occupied by another slime or hit the surrounding wall. If two slimes come together, they unite and become a new slime.

Your task is write a program which calculates the minimum number of moves that all the slimes unite and become a King Slime. Suppose slimes move one by one and they never move simultaneously.

Input

The first line contains three integers N (2 ≤ N ≤ 40,000), W and H (1 ≤ W, H ≤ 100,000), which denote the number of slimes, the width and the height of the grid respectively.

The following N lines describe the initial coordinates of the slimes. The i-th line contains two integers xi (1 ≤ xi ≤ W) and yi (1 ≤ yi ≤ H), which indicate the coordinates of the i-th slime . All the coordinates are 1-based.

You may assume that each cell is occupied by at most one slime initially.

Output

Output the minimum number of moves that all the slimes unite and become a King Slime.

Examples

Input

4 3 3
1 1
1 3
3 1
3 3

Output

3

Input

2 3 3
2 2
3 3

Output

2

Input

2 4 4
2 2
3 3

Output

3

Input

2 4 4
2 2
2 3

Output

1

### Response

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

using namespace std;

vector<int> Ws[100001], Hs[100001];
int par[40000];

int find(int x)
{
    return (par[x] >= 0 ? par[x] = find(par[x]) : x);
}

void merge(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (-par[x] < -par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
}

int main()
{
    int n, w, h;
    int cw = 0, ch = 0;

    scanf("%d %d %d", &n, &w, &h);

    for (int i = 0; i < n; i++){
        int a, b;
        scanf("%d %d", &a, &b);

        if (a == 1 || a == w) cw = 1;
        if (b == 1 || b == h) ch = 1;

        Ws[a].push_back(i);
        Hs[b].push_back(i);
    }

    memset(par, -1, sizeof(par));
    for (int i = 1; i <= w; i++){
        for (int j = 1; j < Ws[i].size(); j++){
            merge(Ws[i][j - 1], Ws[i][j]);
        }
    }
    for (int i = 1; i <= h; i++){
        for (int j = 1; j < Hs[i].size(); j++){
            merge(Hs[i][j - 1], Hs[i][j]);
        }
    }

    set<int> s;
    for (int i = 0; i < n; i++) s.insert(find(i));

    printf("%d\n", s.size() == 1 ? n - 1 : (n - 1 + s.size() - (cw | ch)));

    return (0);
}
```


### Prompt

Please formulate a cpp solution to the following problem:

«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.

You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.

Input

The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.

Output

Output the required default value for the next test index.

Examples

Input

3
1 7 2

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, najmniejsza = 1, poprzednia = 1;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 1; i <= n; i++) {
    if (a[0] > 1) break;
    if ((a[i] - 1) != poprzednia) {
      poprzednia++;
      break;
    } else
      poprzednia++;
  }
  cout << poprzednia;
}

```


### Prompt

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

There are n shovels in the nearby shop. The i-th shovel costs a_i bourles.

Misha has to buy exactly k shovels. Each shovel can be bought no more than once.

Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset.

There are also m special offers in the shop. The j-th of them is given as a pair (x_j, y_j), and it means that if Misha buys exactly x_j shovels during one purchase then y_j most cheapest of them are for free (i.e. he will not pay for y_j most cheapest shovels during the current purchase).

Misha can use any offer any (possibly, zero) number of times, but he cannot use more than one offer during one purchase (but he can buy shovels without using any offers).

Your task is to calculate the minimum cost of buying k shovels, if Misha buys them optimally.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 2 ⋅ 10^5, 1 ≤ k ≤ min(n, 2000)) — the number of shovels in the shop, the number of special offers and the number of shovels Misha has to buy, correspondingly.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5), where a_i is the cost of the i-th shovel.

The next m lines contain special offers. The j-th of them is given as a pair of integers (x_i, y_i) (1 ≤ y_i ≤ x_i ≤ n) and means that if Misha buys exactly x_i shovels during some purchase, then he can take y_i most cheapest of them for free.

Output

Print one integer — the minimum cost of buying k shovels if Misha buys them optimally.

Examples

Input

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

Output

7

Input

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

Output

17

Input

5 1 4
2 5 7 4 6
5 4

Output

17

Note

In the first example Misha can buy shovels on positions 1 and 4 (both with costs 2) during the first purchase and get one of them for free using the first or the third special offer. And then he can buy shovels on positions 3 and 6 (with costs 4 and 3) during the second purchase and get the second one for free using the first or the third special offer. Then he can buy the shovel on a position 7 with cost 1. So the total cost is 4 + 2 + 1 = 7.

In the second example Misha can buy shovels on positions 1, 2, 3, 4 and 8 (costs are 6, 8, 5, 1 and 2) and get three cheapest (with costs 5, 1 and 2) for free. And then he can buy shovels on positions 6, 7 and 9 (all with costs 1) without using any special offers. So the total cost is 6 + 8 + 1 + 1 + 1 = 17.

In the third example Misha can buy four cheapest shovels without using any special offers and get the total cost 17.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e6 + 7;
int n, m, k, g[N];
long long a[N], pre[N], dp[N];
void Init() {
  memset(g, 0, sizeof(g));
  memset(dp, 0, sizeof(dp));
  for (int i = (1); i < (n + 1); ++i) scanf("%I64d", a + i);
  sort(a + 1, a + n + 1);
  pre[0] = 0;
  for (int i = (1); i < (n + 1); ++i) pre[i] = pre[i - 1] + a[i];
  for (int i = (0); i < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x] = max(g[x], y);
  }
}
int Solve() {
  dp[0] = 0;
  for (int i = (1); i < (k + 1); ++i)
    for (int j = (0); j < (i); ++j) {
      int t = g[i - j];
      dp[i] = max(dp[i], dp[j] + pre[j + t] - pre[j]);
    }
  return printf("%I64d\n", pre[k] - dp[k]);
}
int main() {
  while (~scanf("%d%d%d", &n, &m, &k)) {
    Init();
    Solve();
  }
  return 0;
}

```


### Prompt

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

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task.

Input

The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number.

Output

Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1.

Examples

Input

11

Output

47

Input

10

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (!(n % 7)) {
    int x = n / 7;
    while (x--) cout << '7';
    return 0;
  }
  int aa = -1, bb = -1;
  for (int a = 0; a < n; a++) {
    int b = (n - a * 7) / 4;
    if (b > 0)
      if (b * 4 + a * 7 == n) {
        if (aa == -1 || a + b < aa + bb || (a + b == aa + bb && aa < a)) aa = a;
        bb = b;
      }
  }
  if (aa != -1) {
    while (bb--) cout << '4';
    while (aa--) cout << '7';
  } else
    cout << -1 << endl;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?

There are n students living in a building, and for each of them the favorite drink a_i is known. So you know n integers a_1, a_2, ..., a_n, where a_i (1 ≤ a_i ≤ k) is the type of the favorite drink of the i-th student. The drink types are numbered from 1 to k.

There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are k types of drink sets, the j-th type contains two portions of the drink j. The available number of sets of each of the k types is infinite.

You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly ⌈ n/2 ⌉, where ⌈ x ⌉ is x rounded up.

After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if n is odd then one portion will remain unused and the students' teacher will drink it.

What is the maximum number of students that can get their favorite drink if ⌈ n/2 ⌉ sets will be chosen optimally and students will distribute portions between themselves optimally?

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000) — the number of students in the building and the number of different drinks.

The next n lines contain student's favorite drinks. The i-th line contains a single integer from 1 to k — the type of the favorite drink of the i-th student.

Output

Print exactly one integer — the maximum number of students that can get a favorite drink.

Examples

Input

5 3
1
3
1
1
2

Output

4

Input

10 3
2
1
3
2
3
3
1
3
1
2

Output

9

Note

In the first example, students could choose three sets with drinks 1, 1 and 2 (so they will have two sets with two drinks of the type 1 each and one set with two drinks of the type 2, so portions will be 1, 1, 1, 1, 2, 2). This way all students except the second one will get their favorite drinks.

Another possible answer is sets with drinks 1, 2 and 3. In this case the portions will be 1, 1, 2, 2, 3, 3. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with a_i = 1 (i.e. the first, the third or the fourth).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int m[1000];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  int x = (n / 2) + (n % 2);
  int res = 0;
  for (int i = 1; i < k + 1; i++) {
    res += (m[i] / 2) * 2;
    x -= m[i] / 2;
  }
  cout << res + x;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given circular array a0, a1, ..., an - 1. There are two types of operations with it:

  * inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v;
  * rmq(lf, rg) — this operation returns minimal value on the segment [lf, rg] (inclusively).

Assume segments to be circular, so if n = 5 and lf = 3, rg = 1, it means the index sequence: 3, 4, 0, 1.

Write program to process given sequence of operations.

Input

The first line contains integer n (1 ≤ n ≤ 200000). The next line contains initial state of the array: a0, a1, ..., an - 1 ( - 106 ≤ ai ≤ 106), ai are integer. The third line contains integer m (0 ≤ m ≤ 200000), m — the number of operartons. Next m lines contain one operation each. If line contains two integer lf, rg (0 ≤ lf, rg ≤ n - 1) it means rmq operation, it contains three integers lf, rg, v (0 ≤ lf, rg ≤ n - 1; - 106 ≤ v ≤ 106) — inc operation.

Output

For each rmq operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples

Input

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

Output

1
0
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> a;
long long t[1600000], lazy[1600000];
void build(int id, int l, int r) {
  if (l == r) {
    t[id] = a[l];
    return;
  }
  int m = (l + r) / 2;
  build(2 * id, l, m);
  build(2 * id + 1, m + 1, r);
  t[id] = min(t[2 * id], t[2 * id + 1]);
}
void push(int id, int l, int r) {
  t[2 * id] += lazy[id];
  t[2 * id + 1] += lazy[id];
  lazy[2 * id] += lazy[id];
  lazy[2 * id + 1] += lazy[id];
  lazy[id] = 0;
}
void increase(int id, int l, int r, int x, int y, long long val) {
  push(id, l, r);
  if (x > r || y < l) return;
  if (x <= l && y >= r) {
    t[id] += val;
    lazy[id] += val;
    return;
  }
  int mid = (l + r) / 2;
  increase(2 * id, l, mid, x, y, val);
  increase(2 * id + 1, mid + 1, r, x, y, val);
  t[id] = min(t[2 * id], t[2 * id + 1]);
}
long long query(int id, int l, int r, int x, int y) {
  push(id, l, r);
  if (x > r || y < l) return 1e9;
  if (x <= l && y >= r) return t[id];
  int m = (l + r) / 2;
  long long p1 = query(2 * id, l, m, x, y);
  long long p2 = query(2 * id + 1, m + 1, r, x, y);
  return min(p1, p2);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    a.push_back(temp);
  }
  build(1, 0, n - 1);
  cin >> m;
  while (m--) {
    int l, r;
    char c;
    long long val;
    scanf("%I64d %I64d%c", &l, &r, &c);
    if (c != '\n') {
      scanf("%lld", &val);
      if (l > r) {
        increase(1, 0, n - 1, l, n - 1, val);
        increase(1, 0, n - 1, 0, r, val);
      } else
        increase(1, 0, n - 1, l, r, val);
    } else {
      if (l > r)
        cout << min(query(1, 0, n - 1, l, n - 1), query(1, 0, n - 1, 0, r))
             << endl;
      else
        cout << query(1, 0, n - 1, l, r) << endl;
    }
  }
  return 0;
}

```


### Prompt

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

To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.

A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?

Input

The only line contains four integers k, n, s, p (1 ≤ k, n, s, p ≤ 10^4) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.

Output

Print a single integer — the minimum number of packs they should buy.

Examples

Input

5 3 2 3

Output

4

Input

5 3 100 1

Output

5

Note

In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.

In the second sample they have to buy a pack for each person as they can't share sheets.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b, c;
  cin >> n >> a >> b >> c;
  long long temp;
  if (a % b == 0)
    temp = a / b;
  else
    temp = a / b + 1;
  long long te = n * temp;
  if (te % c == 0)
    cout << te / c;
  else
    cout << te / c + 1;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters.

Suitability of string s is calculated by following metric:

Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings s, you choose the one with the largest number of non-intersecting occurrences of string t. Suitability is this number of occurrences.

You should replace all '?' characters with small Latin letters in such a way that the suitability of string s is maximal.

Input

The first line contains string s (1 ≤ |s| ≤ 106).

The second line contains string t (1 ≤ |t| ≤ 106).

Output

Print string s with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.

If there are multiple strings with maximal suitability then print any of them.

Examples

Input

?aa?
ab

Output

baab

Input

??b?
za

Output

azbz

Input

abcd
abacaba

Output

abcd

Note

In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.

In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.

In the third example there are no '?' characters and the suitability of the string is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<char, int> freq;
string a, b;
vector<int> v;
int main() {
  cin >> a >> b;
  for (int i = 0; a[i]; ++i) {
    if (a[i] == '?')
      v.push_back(i);
    else
      freq[a[i]]++;
  }
  int i = 0;
  while (i < v.size()) {
    for (auto j : b) {
      if (freq[j] > 0) {
        freq[j]--;
      } else {
        a[v[i]] = j;
        i++;
        if (i == v.size()) break;
      }
    }
  }
  cout << a << endl;
}

```


### Prompt

Generate a Cpp solution to the following problem:

We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1).

Snuke will perform the following operation exactly M times:

* Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1.

Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353.

Constraints

* 2 \leq N \leq 10^6
* 1 \leq M \leq 5 \times 10^5
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of different sequences that can result after M operations, modulo 998244353.

Examples

Input

2 2

Output

3

Input

3 2

Output

19

Input

10 10

Output

211428932

Input

100000 50000

Output

3463133

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const int maxn=4001000,mod=998244353;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
inline int ksm(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) res=1ll*res*a%mod;
	return res;
}
int fac[maxn],invfac[maxn];
inline int C(int n,int m){return 1ll*fac[n]*invfac[m]%mod*invfac[n-m]%mod;}
int n,m;
inline int cal(int n,int m,int lim)
{
	int ans=0;
	for(int i=0;i<=min(n,lim);i++) if(!((m-i)&1))
		Add(ans,1ll*C(n,i)*C((m-i)/2+n-1,n-1)%mod);
	return ans;
}
int main()
{
	for(int i=fac[0]=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[maxn-1]=ksm(fac[maxn-1],mod-2);
	for(int i=maxn-2;i>=0;i--) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	cin>>n>>m;printf("%lld\n",(cal(n,3*m,m)-1ll*n*cal(n,m,m)%mod+1ll*n*cal(n-1,m,m)%mod+mod)%mod);
	return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.

For example:

  * If x = 6 and the crossword is 111011, then its encoding is an array {3, 2};
  * If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1};
  * If x = 5 and the crossword is 11111, then its encoding is an array {5};
  * If x = 5 and the crossword is 00000, then its encoding is an empty array.

Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!

Input

The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked.

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.

Output

Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.

Examples

Input

2 4
1 3

Output

NO

Input

3 10
3 3 2

Output

YES

Input

2 10
1 3

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long x;
  cin >> n >> x;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    int tmp;
    cin >> tmp;
    sum += (tmp + 1);
  }
  sum--;
  if (sum == x)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

There are N strings of lowercase alphabet only. The i-th string is S_i. Every string is unique.

Provide answers for the Q queries below. The i-th query has the following format:

Query: An integer k_i and a string p_{i,1}p_{i,2}...p_{i,26} that results from permuting {`a`,`b`,...,`z`} are given. Output the sequence of the string S_{k_i} among the N strings in lexicographical order when the literal sequence is p_{i,1}<p_{i,2}<...<p_{i,26}.

Constraints

* 1 ≦ N,Q ≦ 100000
* 1 ≦ |S_i| (1 ≦ i ≦ N)
* S_i (1 ≦ i ≦ N) is a string of lowercase alphabet.
* The sum of |S_i| is no more than 400000.
* Every S_i is unique.
* 1 ≦ k_i ≦ N (1 ≦ i ≦ Q)
* For all 1 ≦ i ≦ Q, p_{i,1}p_{i,2}...p_{i,26} is a permutation of `abcd...z`.

Input

Inputs are provided from standard inputs in the following form.

N
S_1
:
S_N
Q
k_1 p_{1,1}p_{1,2}...p_{1,26}
:
k_Q p_{Q,1}p_{Q,2}...p_{Q,26}

Output

Output Q lines.

On line i, for the i-th query, output an integer indicating the sequence of the string S_{k_i} among the N strings in lexicographical order.

Examples

Input

5
aa
abbaa
abbba
aaab
aaaaaba
5
1 abcdefghijklmnopqrstuvwxyz
2 bacdefghijklmnopqrstuvwxyz
3 abcdefghijklmnopqrstuvwxyz
4 bacdefghijklmnopqrstuvwxyz
5 abcdefghijklmnopqrstuvwxyz

Output

1
2
5
4
2

Input

8
abrakatabra
abadaba
abracadabra
atcoder
grand
contest
ababa
a
6
3 abcdefghijklmnopqrstuvwxyz
6 qwertyuiopasdfghjklzxcvbnm
8 poiuytrewqlkjhgfdsamnbvcxz
2 qazwsxedcrfvtgbyhnujmikolp
1 plokmijnuhbygvtfcrdxeszwaq
4 mnbvcxzasdfghjklpoiuytrewq

Output

4
8
2
3
4
7

### Response

```cpp
//Link : https://atcoder.jp/contests/code-festival-2016-qualb/tasks/codefestival_2016_qualB_e

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 400002
#define ALP 26
#define mod 1000000007
int terminal[N];
int nextNode[N][ALP],cc[N];

int alwaysWin[N];
int triePos = 1;

int relation[N][ALP][ALP];
int globalValue[ALP][ALP];

void traverse(int node,char *s,int pos,int id) {
  ++cc[node];
  if(s[pos]==0) {
    terminal[node] = id;
    return;
  }
  int alp = s[pos]-'a';
  ++pos;
  if(nextNode[node][alp]==0) {
    nextNode[node][alp] = triePos++;
  }
  traverse(nextNode[node][alp],s,pos,id);
}

void precompute(int root,int alreadyLoseNumber) {
  int ter = terminal[root];
  if(ter!=0) {
    alwaysWin[ter] += alreadyLoseNumber;
    for(int i=0;i<26;++i) {
      for(int j=0;j<26;++j) {
        if(i!=j) {
          relation[ter][i][j] += globalValue[i][j];
        }
      }
    }
    ++alreadyLoseNumber;
  }
  int tmp[ALP];
  for(int i=0;i<26;++i) {
    tmp[i] = 0;
  }
  for(int i=0;i<26;++i) {
    int node = nextNode[root][i];
    if(node==0) {
      continue;
    }
    tmp[i] = cc[node];
  }
  for(int i=0;i<26;++i) {
    int node = nextNode[root][i];
    if(node==0) {
      continue;
    }
    for(int k=0;k<26;++k) {
      if(i!=k) {
        globalValue[i][k] += tmp[k];
      }
    }
    precompute(node,alreadyLoseNumber);
    for(int k=0;k<26;++k) {
      if(i!=k) {
        globalValue[i][k] -= tmp[k];
      }
    }
  }
}

char tmp[N];

int ord[N];
void solve(){
  int n;scanf("%d ", &n);
  for(int i=1;i<=n;++i) {
    scanf("%s ", tmp);
    traverse(0,tmp,0,i);
  }
  precompute(0,0);
  int q;scanf("%d ", &q);
  while(q--) {
    int k;scanf("%d %s ", &k,tmp);
    for(int i=0;i<26;++i) {
      ord[tmp[i]-'a'] = i;
    }
    int r = 1 + alwaysWin[k];
    for(int i=0;i<26;++i) {
      for(int j=0;j<26;++j) {
        if(i==j) {
          continue;
        }
        if(ord[i]>ord[j]) {
          r += relation[k][i][j];
        }
      }
    }
    printf("%d\n", r);
  }
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}

```