### Prompt

Create a solution in cpp for the following problem:

problem

JOI decided to make a signboard for the store.

There are N old signboards with letters written at equal intervals. JOI makes a sign by erasing some letters from the old sign. I want the remaining characters to be the name of the store, and the remaining characters to be evenly spaced. Signs must be made from one old sign, and old signs must not be cut or connected.

Given the name of the store and information on N old signboards, create a program that asks for the number of signboards that JOI can make. However, even if there are multiple signboards that can be made from one old signboard, it is considered that only one signboard can be made.

input

The input consists of 2 + N lines.

The integer N (1 & leqq; N & leqq; 100) is written on the first line, which indicates the number of old signboards.

On the second line, a character string consisting of 3 to 25 characters of lowercase letters is written, which indicates the name of the store.

The i-th line (1 & leqq; i & leqq; N) of the following N lines contains a character string consisting of 1 to 100 lowercase letters of the alphabet, which is written on the i-th old signboard. Represents a character string.

output

JOI Output an integer representing the number of signboards you can make in one line.

Input / output example

Input example

Four
bar
abracadabra
bear
bar
baraxbara

Output example

3

The name of the shop is bar.

The first old sign has the string abracadabra written on it. You can make a sign by erasing all but the 2nd, 6th, and 10th letters from this old sign.

On the second sheet, if you erase the second character, you can create a character string called bar, but this means that the remaining characters are not evenly spaced.

The third piece is a signboard without erasing any characters.

There are two ways to make a sign from the fourth old sign. One method is to erase all but the first, second, and third characters. Another method is to erase all but the 6th, 7th, and 8th characters.

Therefore, JOI can make a signboard from the 1st, 3rd, and 4th old signboards, so 3 is output.

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

Example

Input

4
bar
abracadabra
bear
bar
baraxbara

Output

3

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

	int n;
	string name;
	cin >> n >> name;
	int cnt = 0;

	while(n--){
		string old;
		cin >> old;
		for(int i=0; i<old.size(); i++){
			bool flag = false;
			for(int j=1; j<old.size(); j++){
				string tar;
				for(int k=i; k<old.size(); k+=j){
					tar += old[k];
				}
				if(~tar.find(name)){cnt++; flag = true; break;}
			}
			if(flag) break;
		}
	}
	cout << cnt << endl;

	return 0;
}
```


### Prompt

Please formulate a CPP solution to the following problem:

Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated n Mr. Meeseeks, standing in a line numbered from 1 to n. Each of them has his own color. i-th Mr. Meeseeks' color is ai.

Rick and Morty are gathering their army and they want to divide Mr. Meeseeks into some squads. They don't want their squads to be too colorful, so each squad should have Mr. Meeseeks of at most k different colors. Also each squad should be a continuous subarray of Mr. Meeseeks in the line. Meaning that for each 1 ≤ i ≤ e ≤ j ≤ n, if Mr. Meeseeks number i and Mr. Meeseeks number j are in the same squad then Mr. Meeseeks number e should be in that same squad.

<image>

Also, each squad needs its own presidio, and building a presidio needs money, so they want the total number of squads to be minimized.

Rick and Morty haven't finalized the exact value of k, so in order to choose it, for each k between 1 and n (inclusive) need to know the minimum number of presidios needed.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105) — number of Mr. Meeseeks.

The second line contains n integers a1, a2, ..., an separated by spaces (1 ≤ ai ≤ n) — colors of Mr. Meeseeks in order they standing in a line.

Output

In the first and only line of input print n integers separated by spaces. i-th integer should be the minimum number of presidios needed if the value of k is i.

Examples

Input

5
1 3 4 3 3

Output

4 2 1 1 1

Input

8
1 5 7 8 1 7 6 1

Output

8 4 3 2 1 1 1 1

Note

For the first sample testcase, some optimal ways of dividing army into squads for each k are:

  1. [1], [3], [4], [3, 3]
  2. [1], [3, 4, 3, 3]
  3. [1, 3, 4, 3, 3]
  4. [1, 3, 4, 3, 3]
  5. [1, 3, 4, 3, 3]

For the second testcase, some optimal ways of dividing army into squads for each k are:

  1. [1], [5], [7], [8], [1], [7], [6], [1]
  2. [1, 5], [7, 8], [1, 7], [6, 1]
  3. [1, 5, 7], [8], [1, 7, 6, 1]
  4. [1, 5, 7, 8], [1, 7, 6, 1]
  5. [1, 5, 7, 8, 1, 7, 6, 1]
  6. [1, 5, 7, 8, 1, 7, 6, 1]
  7. [1, 5, 7, 8, 1, 7, 6, 1]
  8. [1, 5, 7, 8, 1, 7, 6, 1]

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int used[N], a[N], vis[N], tot, Res, Ans[N], n;
inline int Read() {
  int t = 0, f = 1;
  char c = getchar();
  for (; c > 57 || c < 48; c = getchar())
    if (c == '-') f = -1;
  for (; c > 47 && c < 58; c = getchar()) t = (t << 1) + (t << 3) + c - 48;
  return t * f;
}
inline int calc(int k) {
  tot = Res = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[a[i]]) {
      if (tot == k) {
        for (int j = 1; j <= tot; j++) vis[used[j]] = 0;
        tot = 0, Res++;
      }
      vis[a[i]] = 1, used[++tot] = a[i];
    }
  for (int i = 1; i <= tot; i++) vis[used[i]] = 0;
  return Res + 1;
}
int solve(int l, int r) {
  if (Ans[l] == Ans[r]) {
    for (int i = l; i <= r; i++) Ans[i] = Ans[l];
    return 0;
  }
  int mid = l + r >> 1;
  Ans[mid] = calc(mid), Ans[mid + 1] = calc(mid + 1);
  solve(l, mid), solve(mid + 1, r);
}
int main() {
  n = Read();
  for (int i = 1; i <= n; i++) a[i] = Read();
  Ans[1] = calc(1), Ans[n] = calc(n);
  solve(1, n);
  for (int i = 1; i <= n; i++) printf("%d ", Ans[i]);
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.

Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m different colors, so 0 ≤ ci ≤ m, where ci = 0 means that tree i is uncolored.

ZS the Coder and Chris the Baboon decides to color only the uncolored trees, i.e. the trees with ci = 0. They can color each of them them in any of the m colors from 1 to m. Coloring the i-th tree with color j requires exactly pi, j litres of paint.

The two friends define the beauty of a coloring of the trees as the minimum number of contiguous groups (each group contains some subsegment of trees) you can split all the n trees into so that each group contains trees of the same color. For example, if the colors of the trees from left to right are 2, 1, 1, 1, 3, 2, 2, 3, 1, 3, the beauty of the coloring is 7, since we can partition the trees into 7 contiguous groups of the same color : {2}, {1, 1, 1}, {3}, {2, 2}, {3}, {1}, {3}.

ZS the Coder and Chris the Baboon wants to color all uncolored trees so that the beauty of the coloring is exactly k. They need your help to determine the minimum amount of paint (in litres) needed to finish the job.

Please note that the friends can't color the trees that are already colored.

Input

The first line contains three integers, n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of trees, number of colors and beauty of the resulting coloring respectively.

The second line contains n integers c1, c2, ..., cn (0 ≤ ci ≤ m), the initial colors of the trees. ci equals to 0 if the tree number i is uncolored, otherwise the i-th tree has color ci.

Then n lines follow. Each of them contains m integers. The j-th number on the i-th of them line denotes pi, j (1 ≤ pi, j ≤ 109) — the amount of litres the friends need to color i-th tree with color j. pi, j's are specified even for the initially colored trees, but such trees still can't be colored.

Output

Print a single integer, the minimum amount of paint needed to color the trees. If there are no valid tree colorings of beauty k, print  - 1.

Examples

Input

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

Output

10

Input

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

Output

-1

Input

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

Output

5

Input

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

Output

0

Note

In the first sample case, coloring the trees with colors 2, 1, 1 minimizes the amount of paint used, which equals to 2 + 3 + 5 = 10. Note that 1, 1, 1 would not be valid because the beauty of such coloring equals to 1 ({1, 1, 1} is a way to group the trees into a single group of the same color).

In the second sample case, all the trees are colored, but the beauty of the coloring is 3, so there is no valid coloring, and the answer is  - 1.

In the last sample case, all the trees are colored and the beauty of the coloring matches k, so no paint is used and the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long c[105], x[105][105], dp[105][105][105];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, k, i, j, l, p, ans = 10000000000000000;
  cin >> n >> m >> k;
  for (i = 1; i <= n; i++) cin >> c[i];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> x[i][j];
  for (i = 0; i <= 100; i++)
    for (j = 0; j <= 100; j++)
      for (l = 0; l <= 100; l++) dp[i][j][l] = 10000000000000000;
  if (c[1] == 0) {
    for (i = 1; i <= m; i++) dp[1][1][i] = x[1][i];
  } else
    dp[1][1][c[1]] = 0;
  for (i = 2; i <= n; i++) {
    if (c[i] == 0) {
      for (p = 1; p <= k; p++) {
        for (j = 1; j <= m; j++) {
          for (l = 1; l <= m; l++) {
            if (j == l) {
              dp[i][p][l] = min(dp[i][p][l], dp[i - 1][p][j] + x[i][l]);
            } else {
              dp[i][p + 1][l] = min(dp[i][p + 1][l], dp[i - 1][p][j] + x[i][l]);
            }
          }
        }
      }
    } else {
      for (p = 1; p <= k; p++) {
        for (j = 1; j <= m; j++) {
          if (j == c[i]) {
            dp[i][p][c[i]] = min(dp[i][p][c[i]], dp[i - 1][p][j]);
          } else {
            dp[i][p + 1][c[i]] = min(dp[i][p + 1][c[i]], dp[i - 1][p][j]);
          }
        }
      }
    }
  }
  if (c[n] == 0) {
    for (i = 1; i <= m; i++) ans = min(ans, dp[n][k][i]);
  } else
    ans = dp[n][k][c[n]];
  if (ans != 10000000000000000)
    cout << ans;
  else
    cout << -1;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i.

When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.

After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Constraints

* 2 \leq N \leq 50
* 1 \leq v_i \leq 1000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
v_1 v_2 \ldots v_N

Output

Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.

Your output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.

Examples

Input

2
3 4

Output

3.5

Input

3
500 300 200

Output

375

Input

5
138 138 138 138 138

Output

138

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<double> A(N);
  for(int i=0;i<N;i++) cin>>A[i];
  sort(A.begin(),A.end());
  for(int k=0;k<N-1;k++){A[k+1]=(A[k]+A[k+1])/2;}
  cout<<A[N-1]<<endl;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges.

For each edge (u, v) find the minimal possible weight of the spanning tree that contains the edge (u, v).

The weight of the spanning tree is the sum of weights of all edges included in spanning tree.

Input

First line contains two integers n and m (1 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105) — the number of vertices and edges in graph.

Each of the next m lines contains three integers ui, vi, wi (1 ≤ ui, vi ≤ n, ui ≠ vi, 1 ≤ wi ≤ 109) — the endpoints of the i-th edge and its weight.

Output

Print m lines. i-th line should contain the minimal possible weight of the spanning tree that contains i-th edge.

The edges are numbered from 1 to m in order of their appearing in input.

Examples

Input

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

Output

9
8
11
8
8
8
9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int ms = 2e5 + 5, mlg = 21;
int ds[ms], sz[ms];
vector<pair<long long, pair<int, int>>> ed;
vector<pair<int, long long>> g[ms];
int par[ms][mlg + 1], lvl[ms];
long long maior[ms][mlg + 1];
int n, m;
long long best;
int find(int i) {
  while (ds[i] != i) {
    ds[i] = ds[ds[i]];
    i = ds[i];
  }
  return i;
}
void dsunion(int a, int b) {
  a = find(a);
  b = find(b);
  if (sz[a] < sz[b]) swap(a, b);
  sz[a] += sz[b];
  ds[b] = a;
}
void kruskall() {
  vector<pair<long long, pair<int, int>>> e = ed;
  sort(e.begin(), e.end());
  for (int i = 0; i < m; ++i) {
    int w = e[i].first, u = e[i].second.first, v = e[i].second.second;
    if (find(u) != find(v)) {
      dsunion(u, v);
      g[u].push_back({v, w});
      g[v].push_back({u, w});
      best += w;
    }
  }
}
void dfs(int v, int p, int l = 0) {
  lvl[v] = l;
  par[v][0] = p;
  for (int k = 1; k <= mlg; ++k) {
    maior[v][k] = max(maior[par[v][k - 1]][k - 1], maior[v][k - 1]);
    par[v][k] = par[par[v][k - 1]][k - 1];
  }
  for (auto u : g[v]) {
    if (u.first != p) {
      maior[u.first][0] = u.second;
      dfs(u.first, v, l + 1);
    }
  }
}
int lca(int a, int b) {
  long long melhor = -1;
  if (lvl[b] > lvl[a]) swap(a, b);
  for (int i = mlg; i >= 0; --i) {
    if (lvl[a] - (1 << i) >= lvl[b]) {
      melhor = max(melhor, maior[a][i]);
      a = par[a][i];
    }
  }
  if (a == b) return melhor;
  for (int i = mlg; i >= 0; --i) {
    if (par[a][i] != par[b][i]) {
      melhor = max(melhor, max(maior[a][i], maior[b][i]));
      a = par[a][i];
      b = par[b][i];
    }
  }
  melhor = max(melhor, max(maior[a][0], maior[b][0]));
  return melhor;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    ds[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int w, u, v;
    cin >> u >> v >> w;
    u--;
    v--;
    ed.push_back({w, {u, v}});
  }
  kruskall();
  maior[0][0] = 0;
  dfs(0, 0);
  for (int i = 0; i < m; ++i) {
    int kp = lca(ed[i].second.first, ed[i].second.second);
    cout << best - kp + ed[i].first << '\n';
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given an integer N. Determine if there exists a tuple of subsets of \\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions:

* Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
* Any two of the sets S_1,S_2,...,S_k have exactly one element in common.

If such a tuple exists, construct one such tuple.

Constraints

* 1 \leq N \leq 10^5
* N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If a tuple of subsets of \\{1,2,...N\\} that satisfies the conditions does not exist, print `No`. If such a tuple exists, print `Yes` first, then print such subsets in the following format:

k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}

where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.

If there are multiple such tuples, any of them will be accepted.

Examples

Input

3

Output

Yes
3
2 1 2
2 3 1
2 2 3

Input

4

Output

No

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i =a; i<n; i++)
#define ll long long
#define MOD 1000000007
using namespace std;

int main() {
  int N; cin >> N;
  bool check = false; int S;
  rep(i,0,100001) {
    if (i * (i+1) == 2*N) {
      check = true; S = i+1;
    }
  }

  if (!check) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl << S << endl;
    vector<vector<int>> d(S);
    int x =0;
    rep(i,0,S) {
      rep(j,i+1,S) {
        x++;
        d[i].push_back(x);
        d[j].push_back(x);
      }
    }
    rep(i,0,S) {
      cout << S-1;
      rep(j,0,S-1) {
        cout << " " << d[i][j];
      }
      cout << endl;
    }
  }
}
```


### Prompt

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

You have an array of positive integers a[1], a[2], ..., a[n] and a set of bad prime numbers b1, b2, ..., bm. The prime numbers that do not occur in the set b are considered good. The beauty of array a is the sum <image>, where function f(s) is determined as follows:

  * f(1) = 0;
  * Let's assume that p is the minimum prime divisor of s. If p is a good prime, then <image>, otherwise <image>.

You are allowed to perform an arbitrary (probably zero) number of operations to improve array a. The operation of improvement is the following sequence of actions:

  * Choose some number r (1 ≤ r ≤ n) and calculate the value g = GCD(a[1], a[2], ..., a[r]).
  * Apply the assignments: <image>, <image>, ..., <image>.

What is the maximum beauty of the array you can get?

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 5000) showing how many numbers are in the array and how many bad prime numbers there are.

The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — array a. The third line contains m space-separated integers b1, b2, ..., bm (2 ≤ b1 < b2 < ... < bm ≤ 109) — the set of bad prime numbers.

Output

Print a single integer — the answer to the problem.

Examples

Input

5 2
4 20 34 10 10
2 5

Output

-2

Input

4 5
2 4 8 16
3 5 7 11 17

Output

10

Note

Note that the answer to the problem can be negative.

The GCD(x1, x2, ..., xk) is the maximum positive integer that divides each xi.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[5111];
int gcda[5111];
set<int> b;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int beauty(int n) {
  int ans = 0;
  int h;
  for (int i = 2; i * i <= n; ++i) {
    h = 0;
    while (n % i == 0) {
      ++h;
      n /= i;
    }
    if (h) {
      if (b.count(i))
        ans -= h;
      else
        ans += h;
    }
  }
  if (n != 1) {
    if (b.count(n))
      ans--;
    else
      ans++;
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int bad;
  for (int i = 0; i < (m); ++i) {
    cin >> bad;
    b.insert(bad);
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) ans += beauty(a[i]);
  gcda[0] = a[0];
  for (int i = (1); i <= (n - 1); ++i) gcda[i] = gcd(gcda[i - 1], a[i]);
  int bg, cgcd = 1;
  for (int i = n - 1; i >= 0; i--) {
    bg = beauty(gcda[i] / cgcd);
    if (bg < 0) {
      ans -= bg * (i + 1);
      cgcd = gcda[i];
    }
  }
  cout << ans << "\n";
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

On one of the planets of Solar system, in Atmosphere University, many students are fans of bingo game.

It is well known that one month on this planet consists of n^2 days, so calendars, represented as square matrix n by n are extremely popular.

Weather conditions are even more unusual. Due to the unique composition of the atmosphere, when interacting with sunlight, every day sky takes one of three colors: blue, green or red.

To play the bingo, you need to observe the sky for one month — after each day, its cell is painted with the color of the sky in that day, that is, blue, green or red.

At the end of the month, students examine the calendar. If at least one row or column contains only cells of one color, that month is called lucky.

Let's call two colorings of calendar different, if at least one cell has different colors in them. It is easy to see that there are 3^{n ⋅ n} different colorings. How much of them are lucky? Since this number can be quite large, print it modulo 998244353.

Input

The first and only line of input contains a single integer n (1 ≤ n ≤ 1000 000) — the number of rows and columns in the calendar.

Output

Print one number — number of lucky colorings of the calendar modulo 998244353

Examples

Input

1

Output

3

Input

2

Output

63

Input

3

Output

9933

Note

In the first sample any coloring is lucky, since the only column contains cells of only one color.

In the second sample, there are a lot of lucky colorings, in particular, the following colorings are lucky:

<image>

While these colorings are not lucky:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, fac[1000005], inv[1000005];
long long mo(long long x) { return x >= 998244353 ? x - 998244353 : x; }
long long calc(long long x) { return x < 0 ? x + 998244353 : x; }
void update(int &x, int y) {
  x += y;
  if (x < 0) x += 998244353;
  if (x >= 998244353) x -= 998244353;
}
int Q_P(int x, int y) {
  update(x, 0);
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = 1ll * z * x % 998244353;
    x = 1ll * x * x % 998244353;
  }
  return z;
}
long long C(long long n, long long m) {
  return fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
long long ans, Ans, tmp = 1;
int main() {
  scanf("%lld", &n);
  fac[0] = 1;
  fac[0] = 1, inv[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = 1ll * fac[i - 1] * i % 998244353;
    inv[i] = Q_P(fac[i], 998244353 - 2);
  }
  for (int i = 1; i <= n; i++) {
    int a = 1ll * C(n, i) * Q_P(-1, i + 1) % 998244353;
    int x = Q_P(3, (1ll * n * (n - i) + i) % (998244353 - 1));
    ans = (ans + 1ll * a * x % 998244353) % 998244353;
  }
  ans = 2 * ans % 998244353;
  for (int i = 0; i < n; i++) {
    int t = 998244353 - Q_P(3, i);
    int x = (Q_P(t + 1, n) + 998244353 - Q_P(t, n)) % 998244353;
    int a = 1ll * C(n, i) * Q_P(-1, i + 1) % 998244353;
    Ans = (Ans + 1ll * a * x % 998244353) % 998244353;
  }
  Ans = 3ll * Ans % 998244353;
  printf("%lld\n", (Ans + ans + 998244353) % 998244353);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...

Input

The only line of the input is a string between 1 and 106 characters long.

Output

Output "Yes" or "No".

Examples

Input

HHHH

Output

Yes

Input

HQHQH

Output

No

Input

HHQHHQH

Output

No

Input

HHQQHHQQHH

Output

Yes

Note

The rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s, res;
bool check() {
  string wynik;
  for (int i = 0; i < res.size(); i++) {
    if (res[i] == 'H')
      wynik += 'H';
    else {
      for (int j = 0; j < res.size(); j++) wynik += res[j];
    }
    if (wynik.size() > 1000 * 1000) break;
  }
  return wynik == s;
}
int main() {
  cin >> s;
  bool czy = 0;
  int Q = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'Q') Q++;
  }
  if (Q == 0) {
    cout << "Yes\n";
    return 0;
  }
  int sq = sqrt(Q);
  if (sq * sq != Q) {
    cout << "No\n";
    return 0;
  }
  int ctr = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'Q') break;
    ctr++;
  }
  if (ctr & 1) {
    cout << "No\n";
    return 0;
  }
  for (int i = 0; i < ctr / 2; i++) res += 'H';
  for (int i = ctr; i < s.size() && sq; i++) {
    if (s[i] == 'Q') sq--;
    res += s[i];
  }
  ctr = 0;
  for (int i = s.size() - 1; s[i] != 'Q'; i--) {
    ctr++;
  }
  if (ctr & 1) {
    cout << "No\n";
    return 0;
  }
  for (int i = 0; i < ctr / 2; i++) res += 'H';
  if (check()) {
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Mashmokh works in a factory. At the end of each day he must turn off all of the lights.

The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.

Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.

Please, help Mashmokh, print these indices.

Input

The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).

It is guaranteed that all lights will be turned off after pushing all buttons.

Output

Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.

Examples

Input

5 4
4 3 1 2

Output

1 1 3 4 4

Input

5 5
5 4 3 2 1

Output

1 2 3 4 5

Note

In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v(m);
  for (int i = 0; i < m; i++) cin >> v[i];
  vector<int> ans(n);
  for (int i = 0; i < m; i++) {
    for (int j = v[i] - 1; j < n; j++) {
      if (ans[j] == 0) {
        ans[j] = v[i];
      }
    }
  }
  for (int x : ans) cout << x << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  cerr << endl
       << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points t minutes after the contest started, you get <image> points.

Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.

Input

The first line contains four integers a, b, c, d (250 ≤ a, b ≤ 3500, 0 ≤ c, d ≤ 180).

It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).

Output

Output on a single line:

"Misha" (without the quotes), if Misha got more points than Vasya.

"Vasya" (without the quotes), if Vasya got more points than Misha.

"Tie" (without the quotes), if both of them got the same number of points.

Examples

Input

500 1000 20 30

Output

Vasya

Input

1000 1000 1 1

Output

Tie

Input

1500 1000 176 177

Output

Misha

### Response

```cpp
#include <bits/stdc++.h>
int max(int x, int y) {
  if (x >= y) {
    return x;
  } else {
    return y;
  }
}
int Misha(int a, int c) {
  int p1 = (3 * a / 10);
  int p2 = a - ((a / 250) * c);
  int misha = max(p1, p2);
  return misha;
}
int Vasya(int b, int d) {
  int p1 = 3 * b / 10;
  int p2 = b - ((b / 250) * d);
  int vasya = max(p1, p2);
  return vasya;
}
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  int vasya = Vasya(b, d);
  int misha = Misha(a, c);
  if (misha > vasya) {
    printf("Misha");
  } else if (vasya > misha) {
    printf("Vasya");
  } else {
    printf("Tie");
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.

The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:

  * Is it true that y is strictly larger than number x?
  * Is it true that y is strictly smaller than number x?
  * Is it true that y is larger than or equal to number x?
  * Is it true that y is smaller than or equal to number x?

On each question the host answers truthfully, "yes" or "no".

Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:

  * ">" (for the first type queries),
  * "<" (for the second type queries),
  * ">=" (for the third type queries),
  * "<=" (for the fourth type queries).

All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").

Consequtive elements in lines are separated by a single space.

Output

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

Examples

Input

4
>= 1 Y
< 3 N
<= -3 N
> 55 N

Output

17

Input

2
> 100 Y
< -100 Y

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, first = -2e9, last = 2e9, num;
  string op, ans;
  cin >> n;
  while (n--) {
    cin >> op >> num >> ans;
    if (op == ">=" && ans == "Y" || op == "<" && ans == "N") {
      if (num >= first) first = num;
    } else if (op == ">" && ans == "Y" || op == "<=" && ans == "N") {
      if (num >= first) first = num + 1;
    } else if (op == ">=" && ans == "N" || op == "<" && ans == "Y") {
      if (num - 1 <= last) last = num - 1;
    } else if (op == ">" && ans == "N" || op == "<=" && ans == "Y") {
      if (num <= last) last = num;
    }
  }
  if (first <= last)
    cout << first << endl;
  else
    cout << "Impossible" << endl;
  return 0;
}

```


### Prompt

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

Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.

A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1, m), then goes down 2 rows to (3, m), then goes left to (3, 1) and so on.

Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').

Consider sample tests in order to understand the snake pattern.

Input

The only line contains two integers: n and m (3 ≤ n, m ≤ 50).

n is an odd number.

Output

Output n lines. Each line should contain a string consisting of m characters. Do not output spaces.

Examples

Input

3 3

Output

###
..#
###

Input

3 4

Output

####
...#
####

Input

5 3

Output

###
..#
###
#..
###

Input

9 9

Output

#########
........#
#########
#........
#########
........#
#########
#........
#########

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      for (int j = 1; j <= m; j++) {
        printf("#");
      }
    } else if (i % 4 == 1) {
      for (int j = 1; j < m; j++) {
        printf(".");
      }
      printf("#");
    } else if (i % 4 == 3) {
      printf("#");
      for (int j = 1; j < m; j++) {
        printf(".");
      }
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

k people want to split n candies between them. Each candy should be given to exactly one of them or be thrown away.

The people are numbered from 1 to k, and Arkady is the first of them. To split the candies, Arkady will choose an integer x and then give the first x candies to himself, the next x candies to the second person, the next x candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by x) will be thrown away.

Arkady can't choose x greater than M as it is considered greedy. Also, he can't choose such a small x that some person will receive candies more than D times, as it is considered a slow splitting.

Please find what is the maximum number of candies Arkady can receive by choosing some valid x.

Input

The only line contains four integers n, k, M and D (2 ≤ n ≤ 10^{18}, 2 ≤ k ≤ n, 1 ≤ M ≤ n, 1 ≤ D ≤ min{(n, 1000)}, M ⋅ D ⋅ k ≥ n) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.

Output

Print a single integer — the maximum possible number of candies Arkady can give to himself.

Note that it is always possible to choose some valid x.

Examples

Input

20 4 5 2

Output

8

Input

30 9 4 1

Output

4

Note

In the first example Arkady should choose x = 4. He will give 4 candies to himself, 4 candies to the second person, 4 candies to the third person, then 4 candies to the fourth person and then again 4 candies to himself. No person is given candies more than 2 times, and Arkady receives 8 candies in total.

Note that if Arkady chooses x = 5, he will receive only 5 candies, and if he chooses x = 3, he will receive only 3 + 3 = 6 candies as well as the second person, the third and the fourth persons will receive 3 candies, and 2 candies will be thrown away. He can't choose x = 1 nor x = 2 because in these cases he will receive candies more than 2 times.

In the second example Arkady has to choose x = 4, because any smaller value leads to him receiving candies more than 1 time.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, m, d;
  while (~scanf("%lld%lld%lld%lld", &n, &k, &m, &d)) {
    long long int ans = 0;
    for (int i = 1; i <= d; i++) {
      long long int x = n / ((i - 1) * k + 1);
      if (x == 0) break;
      if (x > m) x = m;
      if ((n - x) / (x * k) + 1 != i) continue;
      ans = max(x * i, ans);
    }
    printf("%lld\n", ans);
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.

Input

The first line of the input contain three integers a, b and c ( - 109 ≤ a, b, c ≤ 109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.

Output

If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).

Examples

Input

1 7 3

Output

YES

Input

10 10 0

Output

YES

Input

1 -4 5

Output

NO

Input

0 60 50

Output

NO

Note

In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.

In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.

In the third sample all elements of the sequence are greater than Vasya's favorite integer.

In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c == 0) {
    if (a == b)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  } else if (a == b) {
    cout << "YES" << endl;
  } else if (a >= 0 && b >= 0) {
    if (c > 0) {
      if (a > b) {
        cout << "NO" << endl;
      } else if (a < b) {
        if ((b - a) % c == 0)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
      }
    } else if (c < 0) {
      if (a > b) {
        if ((a - b) % abs(c) == 0)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  } else if (a >= 0 && b < 0) {
    if (c > 0) {
      cout << "NO" << endl;
    } else if (c < 0) {
      if ((a - b) % abs(c) == 0)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  } else if (a < 0 && b >= 0) {
    if (c < 0) {
      cout << "NO" << endl;
    } else if (c > 0) {
      if ((b - a) % c == 0)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  } else {
    if (c > 0) {
      if (a > b) {
        cout << "NO" << endl;
      } else {
        if (abs(b - a) % c == 0) {
          cout << "YES" << endl;
        } else {
          cout << "NO" << endl;
        }
      }
    } else if (c < 0) {
      if (a > b) {
        if (abs(a - b) % abs(c) == 0) {
          cout << "YES" << endl;
        } else {
          cout << "NO" << endl;
        }
      } else if (a < b) {
        cout << "NO" << endl;
      } else {
        if (c == 0) {
          cout << "YES" << endl;
        } else {
          cout << "NO" << endl;
        }
      }
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

A graph is called planar, if it can be drawn in such a way that its edges intersect only at their vertexes.

An articulation point is such a vertex of an undirected graph, that when removed increases the number of connected components of the graph.

A bridge is such an edge of an undirected graph, that when removed increases the number of connected components of the graph.

You've got a connected undirected planar graph consisting of n vertexes, numbered from 1 to n, drawn on the plane. The graph has no bridges, articulation points, loops and multiple edges. You are also given q queries. Each query is a cycle in the graph. The query response is the number of graph vertexes, which (if you draw a graph and the cycle on the plane) are located either inside the cycle, or on it. Write a program that, given the graph and the queries, will answer each query.

Input

The first line contains two space-separated integers n and m (3 ≤ n, m ≤ 105) — the number of vertexes and edges of the graph. Next m lines contain the edges of the graph: the i-th line contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n) — the numbers of vertexes, connecting the i-th edge. The next n lines contain the positions of the planar graph vertexes on the plane: the i-th line contains a pair of space-separated integers xi and yi (|xi|, |yi| ≤ 109) — the coordinates of the i-th vertex of the graph on the plane.

The next line contains integer q (1 ≤ q ≤ 105) — the number of queries. Then follow q lines that describe the queries: the i-th line contains the sequence of space-separated integers ki, a1, a2, ..., aki (1 ≤ aj ≤ n; ki > 2), where ki is the cycle length in the i-th query, aj are numbers of the vertexes that form a cycle. The numbers of vertexes in the cycle are given in the clockwise or counterclockwise order. The given cycles are simple, that is they cannot go through a graph vertex more than once. The total length of all cycles in all queries does not exceed 105.

It is guaranteed that the given graph contains no bridges, articulation points, loops and multiple edges. It is guaranteed that the edge segments can have common points only at the graph's vertexes.

Output

For each query print a single integer — the number of vertexes inside the cycle or on it. Print the answers in the order, in which the queries follow in the input. Separate the numbers by spaces.

Examples

Input

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

Output

3

Input

5 8
1 2
2 3
3 4
4 1
1 5
2 5
3 5
4 5
0 0
2 0
2 2
0 2
1 1
1
4 1 2 3 4

Output

5

Input

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

Output

3
3
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Point {
  long long x, y;
  Point(const long long &x = 0, const long long &y = 0) : x(x), y(y) {}
  Point operator+(const Point &B) const { return Point(x + B.x, y + B.y); }
  Point operator-(const Point &B) const { return Point(x - B.x, y - B.y); }
  long long operator*(const Point &B) const { return x * B.y - y * B.x; }
} P[100005];
int F[100005];
int Find(int u) { return !F[u] ? u : F[u] = Find(F[u]); }
vector<pair<double, int> > G[100005];
int sz[100005], sx[100005], ty[100005];
void dfs(int u, int ff) {
  sz[u] = 1;
  for (int i = 0, v; i < G[u].size() - 1; i++) {
    if ((v = G[u][i].second) == ff) swap(G[u][i], G[u].back());
    v = G[u][i].second;
    dfs(v, u);
    sz[u] += sz[v];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1), LIM = (m); i <= LIM; i++) scanf("%d%d", &sx[i], &ty[i]);
  int rt = 0;
  for (int i = (1), LIM = (n); i <= LIM; i++) {
    scanf("%lld%lld", &P[i].x, &P[i].y);
    if (!rt || (P[i].x < P[rt].x)) rt = i;
  }
  for (int i = (1), LIM = (m); i <= LIM; i++) {
    int u = sx[i], v = ty[i];
    if (Find(u) ^ Find(v)) {
      G[u].push_back(make_pair(atan2(P[v].y - P[u].y, P[v].x - P[u].x), v)),
          G[v].push_back(make_pair(atan2(P[u].y - P[v].y, P[u].x - P[v].x), u));
      F[Find(u)] = Find(v);
    }
  }
  G[rt].push_back(make_pair(3.1415926535897932384626433832795, 0));
  dfs(rt, 0);
  for (int i = (1), LIM = (n); i <= LIM; i++) {
    sort(G[i].begin(), G[i].end() - 1);
    for (int j = (0), LIM = (G[i].size() - 2); j <= LIM; j++)
      G[i][j].second = sz[G[i][j].second] + (j ? G[i][j - 1].second : 0);
  }
  int q;
  scanf("%d", &q);
  for (int S; q--;) {
    scanf("%d", &S);
    static int ar[100005];
    long long area = 0;
    for (int i = (1), LIM = (S); i <= LIM; i++) scanf("%d", &ar[i]);
    for (int i = (1), LIM = (S); i <= LIM; i++) {
      int v = i % S + 1;
      area += P[ar[i]] * P[ar[v]];
    }
    if (area < 0) reverse(ar + 1, ar + 1 + S);
    int ans = 0;
    for (int i = (1), LIM = (S); i <= LIM; i++) {
      int pr = (i + S - 2) % S + 1, sc = i % S + 1, u = ar[i];
      double pa = atan2(P[ar[pr]].y - P[ar[i]].y, P[ar[pr]].x - P[ar[i]].x),
             sa = atan2(P[ar[sc]].y - P[ar[i]].y, P[ar[sc]].x - P[ar[i]].x);
      if (pa < sa) {
        if (pa + 1e-8 < G[u].back().first && G[u].back().first < sa - 1e-8)
          ans += sz[u];
        int tl = lower_bound(G[u].begin(), G[u].end() - 1,
                             make_pair(pa + 1e-8, 0x3f3f3f3f)) -
                 G[u].begin() - 1,
            tr = lower_bound(G[u].begin(), G[u].end() - 1,
                             make_pair(sa - 1e-8, 0)) -
                 G[u].begin() - 1;
        if (tr >= 0) ans -= G[u][tr].second;
        if (tl >= 0) ans += G[u][tl].second;
      } else {
        if (pa + 1e-8 < G[u].back().first || G[u].back().first < sa - 1e-8)
          ans += sz[u];
        swap(pa, sa);
        int tl = lower_bound(G[u].begin(), G[u].end() - 1,
                             make_pair(pa - 1e-8, 0)) -
                 G[u].begin() - 1,
            tr = lower_bound(G[u].begin(), G[u].end() - 1,
                             make_pair(sa + 1e-8, 0x3f3f3f3f)) -
                 G[u].begin() - 1;
        if (G[u].size() > 1) ans -= G[u][G[u].size() - 2].second;
        if (tr >= 0) ans += G[u][tr].second;
        if (tl >= 0) ans -= G[u][tl].second;
      }
    }
    printf("%d\n", ans);
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.

Input

First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».

Output

Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.

Examples

Input

2 2
AG
CT

Output

AG
CT

Input

3 5
AGCAG
AGCAG
AGCAG

Output

TGCAT
CATGC
TGCAT

Note

In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string str[200000 + 1];
int N, M;
char c[2][2];
char alpha[4] = {'A', 'C', 'G', 'T'};
int t[4] = {0, 1, 2, 3};
string ans[200000 + 1], now[200000 + 1];
int acnt = -1, ncnt = 0, cnt1 = 0, cnt2;
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    cin >> str[i];
    ans[i] = now[i] = str[i];
  }
  for (int k = 1; k <= 24; k++) {
    for (int ii = 0; ii < 2; ii++) {
      for (int jj = 0; jj < 2; jj++) {
        c[ii][jj] = alpha[t[ii * 2 + jj]];
      }
    }
    ncnt = 0;
    for (int i = 0; i < N; i++) {
      cnt1 = 0;
      cnt2 = 0;
      for (int j = 0; j < M; j++) {
        if (str[i][j] == c[i % 2][j % 2]) {
          cnt1++;
        }
        if (str[i][j] == c[i % 2][(j + 1) % 2]) {
          cnt2++;
        }
      }
      if (cnt1 > cnt2) {
        for (int j = 0; j < M; j++) {
          now[i][j] = c[i % 2][j % 2];
        }
        ncnt += cnt1;
      } else {
        for (int j = 0; j < M; j++) {
          now[i][j] = c[i % 2][(j + 1) % 2];
        }
        ncnt += cnt2;
      }
    }
    if (ncnt > acnt) {
      acnt = ncnt;
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
          ans[i][j] = now[i][j];
        }
      }
    }
    ncnt = 0;
    for (int j = 0; j < M; j++) {
      cnt1 = 0;
      cnt2 = 0;
      for (int i = 0; i < N; i++) {
        if (str[i][j] == c[i % 2][j % 2]) {
          cnt1++;
        }
        if (str[i][j] == c[(i + 1) % 2][j % 2]) {
          cnt2++;
        }
      }
      if (cnt1 > cnt2) {
        for (int i = 0; i < N; i++) {
          now[i][j] = c[i % 2][j % 2];
        }
        ncnt += cnt1;
      } else {
        for (int i = 0; i < N; i++) {
          now[i][j] = c[(i + 1) % 2][j % 2];
        }
        ncnt += cnt2;
      }
    }
    if (ncnt > acnt) {
      acnt = ncnt;
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
          ans[i][j] = now[i][j];
        }
      }
    }
    next_permutation(t, t + 4);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      printf("%c", ans[i][j]);
    }
    printf("\n");
  }
}

```


### Prompt

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

Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug.

Ivan clearly remembers that there were n elements in the array, and each element was not less than 1 and not greater than n. Also he remembers q facts about the array. There are two types of facts that Ivan remembers:

  * 1 li ri vi — for each x such that li ≤ x ≤ ri ax ≥ vi;
  * 2 li ri vi — for each x such that li ≤ x ≤ ri ax ≤ vi.

Also Ivan thinks that this array was a permutation, but he is not so sure about it. He wants to restore some array that corresponds to the q facts that he remembers and is very similar to permutation. Formally, Ivan has denoted the cost of array as follows:

<image>, where cnt(i) is the number of occurences of i in the array.

Help Ivan to determine minimum possible cost of the array that corresponds to the facts!

Input

The first line contains two integer numbers n and q (1 ≤ n ≤ 50, 0 ≤ q ≤ 100).

Then q lines follow, each representing a fact about the array. i-th line contains the numbers ti, li, ri and vi for i-th fact (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n, 1 ≤ vi ≤ n, ti denotes the type of the fact).

Output

If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible cost of the array.

Examples

Input

3 0

Output

3

Input

3 1
1 1 3 2

Output

5

Input

3 2
1 1 3 2
2 1 3 2

Output

9

Input

3 2
1 1 3 2
2 1 3 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool print = 0;
struct Edge {
  Edge() { x = y = c = f = w = 0; }
  Edge(long long _x, long long _y, long long _c, long long _f, long long _w)
      : x(_x), y(_y), c(_c), f(_f), w(_w) {}
  long long x, y, c, f, w;
};
struct MinCostMaxFlow {
  int n, m, idm = 0, s, t;
  int totCost, totFlow, oo = int(1e9);
  vector<Edge> EdgeList;
  vector<int> dist;
  vector<vector<int>> adj;
  vector<int> trace;
  MinCostMaxFlow() { n = 0; }
  MinCostMaxFlow(int n) {
    this->n = n;
    adj.assign(n + 5, vector<int>(0, 0));
    EdgeList.clear();
    dist = vector<int>(n + 5);
    trace = vector<int>(n + 5);
  }
  void addEdge(int u, int v, int c, int w) {
    adj[u].push_back(EdgeList.size());
    EdgeList.push_back(Edge(u, v, c, 0, w));
    adj[v].push_back(EdgeList.size());
    EdgeList.push_back(Edge(v, u, 0, 0, -w));
  }
  bool FordBellman(int s, int t) {
    for (int i = 1; i <= n; ++i) dist[i] = oo, trace[i] = -1;
    vector<bool> inq = vector<bool>(n + 5, false);
    queue<int> q;
    q.push(s);
    inq[s] = true;
    dist[s] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      inq[u] = false;
      for (int id : adj[u])
        if (EdgeList[id].c > EdgeList[id].f) {
          int v = EdgeList[id].y;
          Edge e = EdgeList[id];
          int co = 0;
          if (e.w == 1) co = (e.f + 1) * (e.f + 1) - (e.f) * (e.f);
          if (dist[v] > dist[u] + co) {
            dist[v] = dist[u] + co;
            trace[v] = id;
            if (!inq[v]) {
              q.push(v);
              inq[v] = true;
            }
          }
        }
    }
    return (dist[t] < oo);
  }
  void solve() {
    totFlow = totCost = 0;
    while (FordBellman(s, t)) {
      long long delta = oo;
      for (int u = t; u != s; u = EdgeList[trace[u]].x) {
        if (print) cerr << u << " <- ";
        delta = min(delta, EdgeList[trace[u]].c - EdgeList[trace[u]].f);
      }
      for (int u = t; u != s; u = EdgeList[trace[u]].x) {
        EdgeList[trace[u]].f += delta;
        EdgeList[trace[u] ^ 1].f -= delta;
      }
      totCost += dist[t];
      totFlow += delta;
    }
  }
};
const int N = 55, oo = 1e8 + 7;
int n, q, lwb[N], upb[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) upb[i] = n, lwb[i] = 1;
  for (int i = 1; i <= q; ++i) {
    int t, l, r, v;
    cin >> t >> l >> r >> v;
    if (t == 1) {
      for (int j = l; j <= r; j++) lwb[j] = max(lwb[j], v);
    } else {
      for (int j = l; j <= r; ++j) upb[j] = min(upb[j], v);
    }
  }
  for (int i = 1; i <= n; ++i)
    if (lwb[i] > upb[i]) {
      cout << -1;
      return 0;
    }
  MinCostMaxFlow mcmf = MinCostMaxFlow(2 * n + 2);
  mcmf.s = 2 * n + 1;
  mcmf.t = mcmf.s + 1;
  for (int i = 1; i <= n; ++i) {
    mcmf.addEdge(n + i, mcmf.t, oo, 1);
    mcmf.addEdge(mcmf.s, i, 1, 0);
    for (int j = lwb[i]; j <= upb[i]; j++) {
      mcmf.addEdge(i, n + j, 1, 0);
    }
  }
  mcmf.solve();
  if (mcmf.totFlow < n) {
    cout << -1;
    return 0;
  } else
    cout << mcmf.totCost << endl;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis.

We know that any of the k citizens can become a member of the Embezzland government. The citizens' surnames are a1, a2, ..., ak. All surnames are different. Initially all k citizens from this list are members of the government. The system should support the following options:

  * Include citizen ai to the government.
  * Exclude citizen ai from the government.
  * Given a newspaper article text, calculate how politicized it is. To do this, for every active government member the system counts the number of times his surname occurs in the text as a substring. All occurrences are taken into consideration, including the intersecting ones. The degree of politicization of a text is defined as the sum of these values for all active government members.

Implement this system.

Input

The first line contains space-separated integers n and k (1 ≤ n, k ≤ 105) — the number of queries to the system and the number of potential government members.

Next k lines contain the surnames a1, a2, ..., ak, one per line. All surnames are pairwise different.

Next n lines contain queries to the system, one per line. Each query consists of a character that determines an operation and the operation argument, written consecutively without a space.

Operation "include in the government" corresponds to the character "+", operation "exclude" corresponds to "-". An argument of those operations is an integer between 1 and k — the index of the citizen involved in the operation. Any citizen can be included and excluded from the government an arbitrary number of times in any order. Including in the government a citizen who is already there or excluding the citizen who isn't there changes nothing.

The operation "calculate politicization" corresponds to character "?". Its argument is a text.

All strings — surnames and texts — are non-empty sequences of lowercase Latin letters. The total length of all surnames doesn't exceed 106, the total length of all texts doesn't exceed 106.

Output

For any "calculate politicization" operation print on a separate line the degree of the politicization of the given text. Print nothing for other operations.

Examples

Input

7 3
a
aa
ab
?aaab
-2
?aaab
-3
?aaab
+2
?aabbaa

Output

6
4
3
6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int ch[maxn][26], cnt = 0;
int pos[maxn], st[maxn];
int Laxt[maxn], Next[maxn], To[maxn], tot;
int q[maxn], fail[maxn], head, tail;
int in[maxn], out[maxn], sum[maxn], times;
char c[maxn];
char getopt() {
  char c = getchar();
  while (c != '+' && c != '-' && c != '?') c = getchar();
  return c;
}
void addedge(int u, int v) {
  Next[++tot] = Laxt[u];
  Laxt[u] = tot;
  To[tot] = v;
}
int insert() {
  int L = strlen(c + 1), Now = 0;
  for (int i = 1; i <= L; i++) {
    if (!ch[Now][c[i] - 'a']) ch[Now][c[i] - 'a'] = ++cnt;
    Now = ch[Now][c[i] - 'a'];
  }
  return Now;
}
void buildfail() {
  for (int i = 0; i < 26; i++) {
    if (ch[0][i])
      q[++head] = ch[0][i], fail[ch[0][i]] = 0;
    else
      ch[0][i] = 0;
  }
  while (tail < head) {
    int Now = q[++tail];
    for (int i = 0; i < 26; i++) {
      if (ch[Now][i]) {
        q[++head] = ch[Now][i];
        fail[ch[Now][i]] = ch[fail[Now]][i];
      } else
        ch[Now][i] = ch[fail[Now]][i];
    }
  }
  for (int i = 1; i <= cnt; i++) addedge(fail[i], i);
}
void dfs(int u) {
  in[u] = ++times;
  for (int i = Laxt[u]; i; i = Next[i]) dfs(To[i]);
  out[u] = times;
}
void addsum(int x, int val) {
  while (x <= times) {
    sum[x] += val;
    x += (-x) & x;
  }
}
int query(int x) {
  int res = 0;
  while (x) {
    res += sum[x];
    x -= (-x) & x;
  }
  return res;
}
void solve() {
  int L = strlen(c + 1), Now = 0;
  long long ans = 0;
  for (int i = 1; i <= L; i++) {
    Now = ch[Now][c[i] - 'a'];
    ans += query(in[Now]);
  }
  printf("%I64d\n", ans);
}
int main() {
  int N, M, x, i, j;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= M; i++) {
    st[i] = 1;
    scanf("%s", c + 1);
    pos[i] = insert();
  }
  buildfail();
  dfs(0);
  for (i = 1; i <= M; i++) {
    addsum(in[pos[i]], 1);
    addsum(out[pos[i]] + 1, -1);
  }
  for (i = 1; i <= N; i++) {
    char opt = getopt();
    if (opt == '?') {
      scanf("%s", c + 1);
      solve();
    } else {
      scanf("%d", &x);
      if (opt == '+') {
        if (st[x] == 1) continue;
        addsum(in[pos[x]], 1);
        addsum(out[pos[x]] + 1, -1);
        st[x] = 1;
      } else {
        if (st[x] == 0) continue;
        addsum(in[pos[x]], -1);
        addsum(out[pos[x]] + 1, 1);
        st[x] = 0;
      }
    }
  }
  return 0;
}

```


### Prompt

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

Space Coconut Crab

Space coconut crab

English text is not available in this practice contest.

Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crustacean in the universe, and it is said that the body length after growth is 400 meters or more, and if you spread your legs, it will reach 1,000 meters or more. Many people have already witnessed the space coconut crab, but none have succeeded in catching it.

Through a long-term study, Ken uncovered important facts about the ecology of space coconut crabs. Surprisingly, the space coconut crab did the same thing as the latest warp technology called phase transition navigation, and lived back and forth between normal space and hyperspace. Furthermore, it was found that it takes a long time for the space coconut crab to warp out from the hyperspace to the normal space, and that it cannot move to the hyperspace for a while after the warp out.

So Ken finally decided to catch the space coconut crab. The strategy is as follows. First, we observe the energy of the space coconut crab as it plunges from normal space into hyperspace. When this energy is e, it is known that the coordinates (x, y, z) at which the space coconut crab warps out of hyperspace satisfy the following conditions.

* x, y, z are all non-negative integers.
* x + y2 + z3 = e.
* Minimize the value of x + y + z under the above conditions.

These conditions alone do not always uniquely determine the coordinates, but it is certain that the coordinates to warp out are on the plane x + y + z = m, where m is the minimum value of x + y + z. Is. Therefore, a barrier of sufficient size is placed on this plane. Then, the space coconut crab will warp out to the place where the barrier is stretched. Space coconut crabs affected by the barrier get stuck. It is a setup to capture it with the weapon breaker, which is a state-of-the-art spacecraft operated by Ken.

The barrier can only be set once, so it cannot fail. So Ken decided to use a calculator to carry out his mission. Your job is to write a program that finds the plane x + y + z = m to which the barrier should be placed when the energy for the space coconut crab to enter the hyperspace is given. Your program will be accepted when it outputs the correct results for all of the prepared test cases.

Input

The input consists of multiple datasets. Each dataset consists of only one row and contains one positive integer e (e ≤ 1,000,000). This represents the energy when the space coconut crab rushes into hyperspace. The input ends when e = 0, which is not included in the dataset.

Output

For each dataset, output the value of m on one line. The output must not contain any other characters.

Sample Input

1
2
Four
27
300
1250
0

Output for the Sample Input

1
2
2
3
18
44

Example

Input

1
2
4
27
300
1250
0

Output

1
2
2
3
18
44

### Response

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

int main() {
	int e;
	while (cin >> e, e) {
		int x = 0, m = 81671422;
		for (int z = 0; z*z*z <= e; z++) {
			for (int y = 0; y*y <= e - z*z*z; y++) {
				x = e - z*z*z - y*y;
				m = min(m, x + y + z);
			}
		}
		cout << m << endl;
	}
}
```


### Prompt

Create a solution in Cpp for the following problem:

The only difference between the easy and the hard versions is constraints.

A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa".

You are given a string s consisting of n lowercase Latin letters.

In one move you can take any subsequence t of the given string and add it to the set S. The set S can't contain duplicates. This move costs n - |t|, where |t| is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).

Your task is to find out the minimum possible total cost to obtain a set S of size k or report that it is impossible to do so.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the length of the string and the size of the set, correspondingly.

The second line of the input contains a string s consisting of n lowercase Latin letters.

Output

Print one integer — if it is impossible to obtain the set S of size k, print -1. Otherwise, print the minimum possible total cost to do it.

Examples

Input

4 5
asdf

Output

4

Input

5 6
aaaaa

Output

15

Input

5 7
aaaaa

Output

-1

Input

10 100
ajihiushda

Output

233

Note

In the first example we can generate S = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in S is 0 and the cost of the others is 1. So the total cost of S is 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long m) {
  long long r = 1;
  a %= m;
  for (; b; b >>= 1) {
    if (b & 1) r = r * a % m;
    a = a * a % m;
  }
  return r;
}
const int inf = 0x7fffffff;
queue<string> que;
set<string> s;
int n, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  string a;
  cin >> a;
  que.push(a);
  s.insert(a);
  int ans = 0;
  while (!que.empty()) {
    string b = que.front();
    que.pop();
    for (int i = 0; i < (int)(b).size(); i++) {
      string c = b;
      c.erase(i, 1);
      if (!s.count(c) && (int)(s).size() < k) {
        ans += n - (int)c.length();
        s.insert(c);
        que.push(c);
      }
    }
  }
  if ((int)(s).size() < k) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

<image>

Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.

The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.

Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.

Input

In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

Output

For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.

You can output each letter in arbitrary case (upper or lower).

Example

Input

6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000

Output

Yes
Yes
Yes
No
No
Yes

Note

First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.

The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long tr[1000010];
int main() {
  for (long long i = 0; i < 1000010; i++) {
    tr[i] = i * i * i;
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    long long a, b;
    scanf("%I64d %I64d", &a, &b);
    int l = 1, r = 1000010;
    int mid;
    while (l <= r) {
      mid = (l + r) / 2;
      if (tr[mid] > a * b)
        r = mid - 1;
      else if (tr[mid] < a * b)
        l = mid + 1;
      else if (tr[mid] == a * b) {
        break;
      }
    }
    if (a % mid == 0 && b % mid == 0)
      printf("Yes\n");
    else
      printf("No\n");
  }
}

```


### Prompt

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

As the first step in algebra, students learn quadratic formulas and their factorization. Often, the factorization is a severe burden for them. A large number of students cannot master the factorization; such students cannot be aware of the elegance of advanced algebra. It might be the case that the factorization increases the number of people who hate mathematics.

Your job here is to write a program which helps students of an algebra course. Given a quadratic formula, your program should report how the formula can be factorized into two linear formulas. All coefficients of quadratic formulas and those of resultant linear formulas are integers in this problem.

The coefficients a, b and c of a quadratic formula ax2 + bx + c are given. The values of a, b and c are integers, and their absolute values do not exceed 10000. From these values, your program is requested to find four integers p, q, r and s, such that ax2 + bx + c = (px + q)(rx + s).

Since we are considering integer coefficients only, it is not always possible to factorize a quadratic formula into linear formulas. If the factorization of the given formula is impossible, your program should report that fact.

Input

The input is a sequence of lines, each representing a quadratic formula. An input line is given in the following format.

> a b c

Each of a, b and c is an integer. They satisfy the following inequalities.

> 0 < a <= 10000
>  -10000 <= b <= 10000
>  -10000 <= c <= 10000

The greatest common divisor of a, b and c is 1. That is, there is no integer k, greater than 1, such that all of a, b and c are divisible by k.

The end of input is indicated by a line consisting of three 0's.

Output

For each input line, your program should output the four integers p, q, r and s in a line, if they exist. These integers should be output in this order, separated by one or more white spaces. If the factorization is impossible, your program should output a line which contains the string "Impossible" only.

The following relations should hold between the values of the four coefficients.

> p > 0
>  r > 0
>  (p > r) or (p = r and q >= s)

These relations, together with the fact that the greatest common divisor of a, b and c is 1, assure the uniqueness of the solution. If you find a way to factorize the formula, it is not necessary to seek another way to factorize it.

Example

Input

2 5 2
1 1 1
10 -7 0
1 0 -3
0 0 0

Output

2 1 1 2
Impossible
10 -7 1 0
Impossible

### Response

```cpp
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long sqrt(long long n) {
    long long res = (long long)(pow(n, 1.0/2)) + 10;
    while (res >= 1) {
        if (n/res/res == 0) --res;
        else break;
    }
    return res;
}

long long a, b, c;

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );

    while (cin >> a >> b >> c) {
        if (a == 0) break;
        long long han = b*b - a*c*4;

        if (han < 0) {
            puts("Impossible");
            continue;
        }

        long long sq = sqrt(han);
        if (han != sq*sq) {
            puts("Impossible");
            continue;
        }

        pll x[2];
        x[0] = pll(a*2, b+sq), x[1] = pll(a*2, b-sq);
        for (int i = 0; i < 2; ++i) {
            if (x[i].first == 0 && x[i].second == 0) continue;
            long long div = gcd(abs(x[i].first), abs(x[i].second));
            x[i].first /= div, x[i].second /= div;
        }
        sort( x, x+2 );
        cout << x[1].first << " " << x[1].second << " " << x[0].first << " " << x[0].second << endl;
    }
    return 0;
}

```


### Prompt

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

Alice wants to send an important message to Bob. Message a = (a1, ..., an) is a sequence of positive integers (characters).

To compress the message Alice wants to use binary Huffman coding. We recall that binary Huffman code, or binary prefix code is a function f, that maps each letter that appears in the string to some binary string (that is, string consisting of characters '0' and '1' only) such that for each pair of different characters ai and aj string f(ai) is not a prefix of f(aj) (and vice versa). The result of the encoding of the message a1, a2, ..., an is the concatenation of the encoding of each character, that is the string f(a1)f(a2)... f(an). Huffman codes are very useful, as the compressed message can be easily and uniquely decompressed, if the function f is given. Code is usually chosen in order to minimize the total length of the compressed message, i.e. the length of the string f(a1)f(a2)... f(an).

Because of security issues Alice doesn't want to send the whole message. Instead, she picks some substrings of the message and wants to send them separately. For each of the given substrings ali... ari she wants to know the minimum possible length of the Huffman coding. Help her solve this problem.

Input

The first line of the input contains the single integer n (1 ≤ n ≤ 100 000) — the length of the initial message. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000) — characters of the message.

Next line contains the single integer q (1 ≤ q ≤ 100 000) — the number of queries.

Then follow q lines with queries descriptions. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the position of the left and right ends of the i-th substring respectively. Positions are numbered from 1. Substrings may overlap in any way. The same substring may appear in the input more than once.

Output

Print q lines. Each line should contain a single integer — the minimum possible length of the Huffman encoding of the substring ali... ari.

Example

Input

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

Output

10
3
3
5
0

Note

In the first query, one of the optimal ways to encode the substring is to map 1 to "0", 2 to "10" and 3 to "11".

Note that it is correct to map the letter to the empty substring (as in the fifth query from the sample).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 62;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int blo[500005];
struct node {
  int l, r, id;
  node() {}
  node(int _l, int _r, int _id) : l(_l), r(_r), id(_id) {}
  bool operator<(const node &x) const {
    return blo[l] == blo[x.l] ? r < x.r : blo[l] < blo[x.l];
  }
} q[500005];
const int sqrtn = 333;
int n, m;
int a[500005], ans[500005];
int num1[500005], num2[500005];
int cnt[500005];
vector<int> big;
void add(int x, int y) {
  --num2[num1[a[x]]];
  num1[a[x]] += y;
  ++num2[num1[a[x]]];
}
int calc() {
  static int tmp[sqrtn + 2];
  memcpy(tmp, num2, sizeof tmp);
  priority_queue<int, vector<int>, greater<int> > BIG;
  int lst = 0, res = 0;
  for (int i = 1; i < sqrtn; i++)
    if (tmp[i]) {
      if (lst) {
        res += lst + i;
        --tmp[i];
        if (lst + i >= sqrtn)
          BIG.push(lst + i);
        else
          ++tmp[lst + i];
        lst = 0;
      }
      res += i * (tmp[i] - (tmp[i] & 1));
      if ((i << 1) >= sqrtn) {
        for (int j = 0; j < (tmp[i] >> 1); j++) BIG.push(i << 1);
      } else
        tmp[i << 1] += tmp[i] >> 1;
      if (tmp[i] & 1) lst = i;
    }
  for (auto v : big)
    if (num1[v] >= sqrtn) BIG.push(num1[v]);
  while (!BIG.empty()) {
    int x = BIG.top();
    BIG.pop();
    if (lst) {
      res += lst + x;
      BIG.push(lst + x);
      lst = 0;
    } else
      lst = x;
  }
  return res;
}
int main() {
  n = read();
  for (int i = 0; i <= n; i++) blo[i] = i / sqrtn;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    cnt[a[i]]++;
    if (cnt[a[i]] == sqrtn) big.push_back(a[i]);
  }
  m = read();
  for (int i = 0; i < m; i++) {
    q[i].l = read(), q[i].r = read();
    q[i].id = i;
  }
  sort(q, q + m);
  int L = 1, R = 0;
  for (int i = 0; i < m; i++) {
    while (R < q[i].r) add(++R, 1);
    while (L > q[i].l) add(--L, 1);
    while (L < q[i].l) add(L++, -1);
    while (R > q[i].r) add(R--, -1);
    ans[q[i].id] = calc();
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}

```


### Prompt

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

Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows:

  * F(k, n) = 0, for integer n, 1 ≤ n < k;
  * F(k, k) = 1;
  * F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k.

Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k.

You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers.

Input

The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1).

Output

In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s.

It is guaranteed that the answer exists. If there are several possible answers, print any of them.

Examples

Input

5 2

Output

3
0 2 3

Input

21 5

Output

3
4 1 16

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, f[110] = {0};
  scanf("%d%d", &n, &k);
  f[0] = 0;
  f[1] = 1;
  int i = 1;
  while (i++) {
    for (int j = 1; j <= k && i - j > 0; j++) f[i] += f[i - j];
    if (f[i] > n) break;
  }
  i--;
  int tmp[110] = {0}, b = 0;
  for (int j = i; j >= 0; j--) {
    if (n >= f[j]) {
      if ((n - f[j]) != 0 || b != 0 || j > 1) {
        n -= f[j];
        tmp[b] = f[j];
        b++;
      }
    }
  }
  printf("%d\n", b);
  printf("%d", tmp[b - 1]);
  for (int j = b - 2; j >= 0; j--) printf(" %d", tmp[j]);
  printf("\n");
  return 0;
}

```


### Prompt

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

You are given an undirected graph with n vertices and m edges. Also, you are given an integer k.

Find either a clique of size k or a non-empty subset of vertices such that each vertex of this subset has at least k neighbors in the subset. If there are no such cliques and subsets report about it.

A subset of vertices is called a clique of size k if its size is k and there exists an edge between every two vertices from the subset. A vertex is called a neighbor of the other vertex if there exists an edge between them.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases. The next lines contain descriptions of test cases.

The first line of the description of each test case contains three integers n, m, k (1 ≤ n, m, k ≤ 10^5, k ≤ n).

Each of the next m lines contains two integers u, v (1 ≤ u, v ≤ n, u ≠ v), denoting an edge between vertices u and v.

It is guaranteed that there are no self-loops or multiple edges. It is guaranteed that the sum of n for all test cases and the sum of m for all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case:

If you found a subset of vertices such that each vertex of this subset has at least k neighbors in the subset in the first line output 1 and the size of the subset. On the second line output the vertices of the subset in any order.

If you found a clique of size k then in the first line output 2 and in the second line output the vertices of the clique in any order.

If there are no required subsets and cliques print -1.

If there exists multiple possible answers you can print any of them.

Example

Input

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

Output

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

Note

In the first test case: the subset \{1, 2, 3, 4\} is a clique of size 4.

In the second test case: degree of each vertex in the original graph is at least 3. So the set of all vertices is a correct answer.

In the third test case: there are no cliques of size 4 or required subsets, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
namespace FastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline bool read(T& x) {
  bool sign = 0;
  char ch = nc();
  x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return false;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (sign) x = -x;
  return true;
}
template <class T, class... U>
bool read(T& h, U&... t) {
  return read(h) && read(t...);
}
};  // namespace FastIO
using namespace std;
using namespace FastIO;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int deg[N], vis[N];
vector<int> e[N];
int main() {
  int T;
  read(T);
  while (T--) {
    int n, m, k;
    read(n, m, k);
    for (int i = 1; i <= n; i++) e[i].clear(), vis[i] = 0;
    for (int i = 1; i <= m; i++) {
      int u, v;
      read(u, v);
      e[u].push_back(v);
      e[v].push_back(u);
    }
    queue<int> q;
    vector<int> clique;
    for (int i = 1; i <= n; i++) {
      deg[i] = (e[i]).size();
      sort((e[i]).begin(), (e[i]).end());
      if (deg[i] < k) {
        vis[i] = 1;
        q.push(i);
      }
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      vis[u] = 2;
      if (1LL * k * (k - 1) / 2 <= 1LL * m && deg[u] == k - 1 &&
          clique.empty()) {
        int ok = 1;
        clique.push_back(u);
        for (auto v : e[u])
          if (vis[v] != 2) clique.push_back(v);
        for (auto x : clique) {
          if (!ok) break;
          for (auto y : clique) {
            if (x != y && !binary_search((e[x]).begin(), (e[x]).end(), y)) {
              ok = 0;
              break;
            }
          }
        }
        if (!ok) clique.clear();
      }
      for (auto v : e[u]) {
        --deg[v];
        if (deg[v] < k && !vis[v]) {
          q.push(v);
          vis[v] = 1;
        }
      }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      if (!vis[i]) cnt++;
    if (cnt) {
      printf("1 %d\n", cnt);
      for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
      puts("");
    } else if (!clique.empty()) {
      puts("2");
      for (int i = 0; i < k; i++) printf("%d ", clique[i]);
      puts("");
    } else {
      puts("-1");
    }
  }
  return 0;
}

```


### Prompt

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

Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).

In this contest, a contestant will first select some number of problems to solve. Then, the contestant will solve the selected problems. After that, the score of the contestant will be calculated as follows:

* (The score) = (The number of the pairs of integers L and R (1≦L≦R≦N) such that for every i satisfying L≦i≦R, problem i is solved) - (The total number of seconds it takes for the contestant to solve the selected problems)

Note that a contestant is allowed to choose to solve zero problems, in which case the score will be 0.

Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. Here, X_i may be greater than the length of time originally required to solve problem P_i. Taking drink i does not affect the time required to solve the other problems.

A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know the maximum score that can be obtained in the contest if she takes that drink. Your task is to write a program to calculate it instead of her.

Constraints

* All input values are integers.
* 1≦N≦3*10^5
* 1≦T_i≦10^9
* (The sum of T_i) ≦10^{12}
* 1≦M≦3*10^5
* 1≦P_i≦N
* 1≦X_i≦10^9

Input

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

N
T_1 T_2 ... T_N
M
P_1 X_1
P_2 X_2
:
P_M X_M

Output

For each drink, print the maximum score that can be obtained if Joisino takes that drink, in order, one per line.

Examples

Input

5
1 1 4 1 1
2
3 2
3 10

Output

9
2

Input

12
1 2 1 3 4 1 2 1 12 3 12 12
10
9 3
11 1
5 35
6 15
12 1
1 9
4 3
10 2
5 1
7 6

Output

34
35
5
11
35
17
25
26
28
21

### Response

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<typename V> struct ConvexHull {
	deque<pair<V,V>> Q;
	int cmptype=1; // 0-min 1-max
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
		return cmptype^((B.second-C.second)*(B.first-A.first)<=(A.second-B.second)*(C.first-B.first));
	}
	void add(V a, V b) { // add ax+b
		Q.push_front({a,b});
		while(Q.size()>=3 && !dodo(Q[0],Q[1],Q[2]))
			Q[1]=Q[0], Q.pop_front();
	}
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			((cmptype^((calc(Q[M],x)>=calc(Q[M+1],x))))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};

int N;
ll T[303030],LS[303030],RS[303030];
int M;
ConvexHull<ll> LC, RC;
ll LD[303030],RD[303030],inc[303030],ninc[303030];
ll tmemo[303030];

void dfs(int LL,int RR) {
	if(RR-LL<=1) return;
	int MM=(LL+RR)/2;
	dfs(LL,MM);
	dfs(MM,RR);

	ConvexHull<ll> TLC, TRC;
	TLC.add(0,0);
	TRC.add(0,0);
	int i,j;
	for(i=LL;i<RR;i++) {
		if(i<MM) TLC.add(-(i+1), 1LL*i*(i+1)/2 + LD[i+1] + LS[i+1]);
		else tmemo[i]=TLC.query(i+1) + 1LL*(i+1)*(i+2)/2 - LS[i+1]+RD[N-1-i];
	}
	for(j=RR-1;j>=LL;j--) {
		i=N-1-j;
		if(j>=MM) TRC.add(-(i+1), 1LL*i*(i+1)/2 + RD[i+1] + RS[i+1]);
		else tmemo[j]=TRC.query(i+1) + 1LL*(i+1)*(i+2)/2 - RS[i+1]+LD[j];
	}

	ll ma=-1LL<<60;
	for(i=RR-1;i>=MM;i--){
		ma=max(ma,tmemo[i]);
		inc[i]=max(inc[i],ma);
	}
	ma=-1LL<<60;
	for(i=LL;i<MM;i++){
		ma=max(ma,tmemo[i]);
		inc[i]=max(inc[i],ma);
	}

}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N;
	FOR(i,N) cin>>T[i];

	LC.add(0,0);
	RC.add(0,0);
	FOR(i,N) {
		LS[i+1]=LS[i]+T[i];
		LD[i+1]=max(LD[i], LC.query(i+1) + 1LL*(i+1)*(i+2)/2 - LS[i+1]);
		LC.add(-(i+1), 1LL*i*(i+1)/2 + LD[i+1] + LS[i+1]);

		RS[i+1]=RS[i]+T[N-1-i];
		RD[i+1]=max(RD[i], RC.query(i+1) + 1LL*(i+1)*(i+2)/2 - RS[i+1]);
		RC.add(-(i+1), 1LL*i*(i+1)/2 + RD[i+1] + RS[i+1]);
	}
	FOR(i,N) {
		ninc[i]=LD[i]+RD[N-1-i];
		inc[i]=1-T[i];
	}
	dfs(0,N);

	cin>>M;
	FOR(i,M) {
		cin>>x>>y;
		x--;
		cout<<max(ninc[x], inc[x] + T[x] - y)<<endl;
	}

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Transformation

Write a program which performs a sequence of commands to a given string $str$. The command is one of:

* print a b: print from the a-th character to the b-th character of $str$
* reverse a b: reverse from the a-th character to the b-th character of $str$
* replace a b p: replace from the a-th character to the b-th character of $str$ with p

Note that the indices of $str$ start with 0.

Constraints

* $1 \leq $ length of $str \leq 1000$
* $1 \leq q \leq 100$
* $0 \leq a \leq b < $ length of $str$
* for replace command, $b - a + 1 = $ length of $p$

Input

In the first line, a string $str$ is given. $str$ consists of lowercase letters. In the second line, the number of commands q is given. In the next q lines, each command is given in the above mentioned format.

Output

For each print command, print a string in a line.

Examples

Input

abcde
3
replace 1 3 xyz
reverse 0 2
print 1 4

Output

xaze

Input

xyz
3
print 0 2
replace 0 2 abc
print 0 2

Output

xyz
abc

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
	string op, s, p;
	int q, a, b;
	cin >> s;
	cin >> q;
	for(int i=1; i<=q; i++){
		cin >> op >> a >> b;
		if(op=="replace"){
			cin >> p;
			s.replace(a, b-a+1, p);   // replace(起始位置，长度，替换字符串)
		}
		if(op=="reverse"){
			for(int j=a; j<=(a+b)/2; j++)  // 反转
				swap(s[j], s[a+b-j]);
		}
		if(op=="print"){
			for(int j=a; j<=b; j++)
				cout << s[j];
			cout << endl;
		}
	}
	return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.

We know that each server takes one second to recompress a one minute fragment. Thus, any server takes m seconds to recompress a m minute video.

We know the time when each of the n videos were uploaded to the network (in seconds starting from the moment all servers started working). All videos appear at different moments of time and they are recompressed in the order they appear. If some video appeared at time s, then its recompressing can start at that very moment, immediately. Some videos can await recompressing when all the servers are busy. In this case, as soon as a server is available, it immediately starts recompressing another video. The videos that await recompressing go in a queue. If by the moment the videos started being recompressed some servers are available, then any of them starts recompressing the video.

For each video find the moment it stops being recompressed.

Input

The first line of the input contains integers n and k (1 ≤ n, k ≤ 5·105) — the number of videos and servers, respectively.

Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 ≤ si, mi ≤ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. It is guaranteed that all the si's are distinct and the videos are given in the chronological order of upload, that is in the order of increasing si.

Output

Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed.

Examples

Input

3 2
1 5
2 5
3 5

Output

6
7
11

Input

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

Output

1000000001
2000000001
3000000001
4000000001
5000000001
5000000004

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long m, n, s, x, dq;
priority_queue<long long> q;
int main() {
  scanf("%I64d%I64d", &m, &n);
  for (int i = 1; i <= n; ++i) q.push(0);
  for (int i = 1; i <= m; ++i) {
    scanf("%I64d%I64d", &s, &x);
    dq = q.top();
    q.pop();
    dq = -dq;
    dq = max(dq, s);
    dq += x;
    printf("%I64d\n", dq);
    q.push(-dq);
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art.

First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string.

Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer.

Input

First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100.

Output

The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating.

If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t.

Examples

Input

abc
cbaabc

Output

2
3 1
1 3

Input

aaabrytaaa
ayrat

Output

3
1 1
6 5
8 7

Input

ami
no

Output

-1

Note

In the first sample string "cbaabc" = "cba" + "abc".

In the second sample: "ayrat" = "a" + "yr" + "at".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string start, end;
  cin >> start >> end;
  string srev = start;
  reverse(srev.begin(), srev.end());
  vector<int> vs[26], vr[26];
  int slen = start.length();
  for (int i = 0; i < slen; i++) {
    vs[start[i] - 'a'].push_back(i);
    vr[srev[i] - 'a'].push_back(i);
  }
  int elen = end.length();
  bool flag = true;
  for (int i = 0; i < elen; i++) {
    if (vs[end[i] - 'a'].size() == 0) {
      flag = false;
      break;
    }
  }
  if (!flag)
    cout << -1 << endl;
  else {
    int no = 0;
    vector<pair<int, int> > res;
    for (int i = 0; i < elen;) {
      int size = vs[end[i] - 'a'].size();
      pair<int, int> p;
      int maxl, ans = 0, index, tmp;
      for (int j = 0; j < size; j++) {
        index = vs[end[i] - 'a'][j];
        tmp = index;
        maxl = i;
        while ((index < slen - 1) && (maxl < elen - 1) &&
               start[index + 1] == end[maxl + 1]) {
          index++;
          maxl++;
        }
        if (maxl - i + 1 > ans) {
          ans = maxl - i + 1;
          p = make_pair(tmp, index);
        }
      }
      maxl = i;
      for (int j = 0; j < size; j++) {
        index = vr[end[i] - 'a'][j];
        tmp = index;
        maxl = i;
        while ((index < slen - 1) && (maxl < elen - 1) &&
               srev[index + 1] == end[maxl + 1]) {
          index++;
          maxl++;
        }
        if (maxl - i + 1 > ans) {
          ans = maxl - i + 1;
          p = make_pair(slen - 1 - tmp, slen - 1 - index);
        }
      }
      i += ans;
      no++;
      res.push_back(p);
    }
    cout << no << endl;
    for (int i = 0; i < res.size(); i++)
      cout << res[i].first + 1 << " " << res[i].second + 1 << endl;
  }
}

```


### Prompt

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

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.

Input

The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.

Output

In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

Examples

Input

47

Output

YES

Input

16

Output

YES

Input

78

Output

NO

Note

Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.

In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.

### Response

```cpp
#include <bits/stdc++.h>
using ll = long long;
const int inf = (int)1e18;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  vector<int> a{4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777};
  int n;
  cin >> n;
  string ans = "NO";
  for (auto i : a) {
    if (n % i == 0) {
      ans = "YES";
      break;
    }
  }
  cout << ans << '\n';
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.

You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:

  * Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
  * move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).

Note that it's allowed to move chips to any integer coordinate, including negative and zero.

Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).

Input

The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.

The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.

Output

Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.

Examples

Input

3
1 2 3

Output

1

Input

5
2 2 2 3 3

Output

2

Note

In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.

In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a = 0, b = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int xi;
    cin >> xi;
    if (xi % 2 == 0)
      a++;
    else
      b++;
  }
  cout << min(a, b) << endl;
  return 0;
}

```