### Prompt

Generate a cpp solution to the following problem:

Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.

More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that

  1. 1 ≤ k ≤ 3
  2. pi is a prime
  3. <image>

The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.

Input

The single line contains an odd number n (3 ≤ n < 109).

Output

In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.

In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.

Examples

Input

27

Output

3
5 11 11

Note

A prime is an integer strictly larger than one that is divisible only by one and by itself.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool check_prime(long long k) {
  for (long long i = 2; i * i <= k; i++) {
    if (k % i == 0) return 0;
  }
  return 1;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> ans;
  if (check_prime(n))
    ans.push_back(n);
  else {
    for (long long i = n - 2;; i--) {
      if (check_prime(i)) {
        ans.push_back(i);
        n -= i;
        break;
      }
    }
    if (check_prime(n))
      ans.push_back(n);
    else {
      for (long long i = 2; i <= n; i++) {
        if (check_prime(i) && check_prime(n - i)) {
          ans.push_back(i);
          ans.push_back(n - i);
          break;
        }
      }
    }
  }
  cout << ans.size() << "\n";
  for (auto it : ans) cout << it << " ";
  return 0;
}

```


### Prompt

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

Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.

In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the others are planets. There's a monster in one of the planet. Rick and Morty don't know on which one yet, only that he's not initially in the black hole, but Unity will inform them before the game starts. But for now, they want to be prepared for every possible scenario.

<image>

Each one of them has a set of numbers between 1 and n - 1 (inclusive). Rick's set is s1 with k1 elements and Morty's is s2 with k2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like x from his set and the monster will move to his x-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins.

Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game.

Input

The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game.

The second line contains integer k1 followed by k1 distinct integers s1, 1, s1, 2, ..., s1, k1 — Rick's set.

The third line contains integer k2 followed by k2 distinct integers s2, 1, s2, 2, ..., s2, k2 — Morty's set

1 ≤ ki ≤ n - 1 and 1 ≤ si, 1, si, 2, ..., si, ki ≤ n - 1 for 1 ≤ i ≤ 2.

Output

In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.

Similarly, in the second line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Morty plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.

Examples

Input

5
2 3 2
3 1 2 3

Output

Lose Win Win Loop
Loop Win Win Win

Input

8
4 6 2 3 4
2 3 6

Output

Win Win Win Win Win Win Win
Lose Win Lose Lose Win Lose Lose

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct l {
  int i;
  int type;
};
vector<int> dp1, st1, dp2, st2, lk1, lk2;
queue<l> q;
int main() {
  int n, k1, k2;
  cin >> n;
  cin >> k1;
  for (int i = 0; i < k1; i++) {
    int a;
    cin >> a;
    lk1.push_back(a);
  }
  cin >> k2;
  for (int i = 0; i < k2; i++) {
    int a;
    cin >> a;
    lk2.push_back(a);
  }
  dp1.resize(n, k1);
  st1.resize(n, 0);
  dp2.resize(n, k2);
  st2.resize(n, 0);
  st1[0] = 2;
  st2[0] = 2;
  q.push({0, 1});
  q.push({0, 2});
  while (q.size() > 0) {
    l b = q.front();
    q.pop();
    if (b.type == 1) {
      if (st1[b.i] == 1) {
        for (auto i : lk2) {
          int pos = (n + b.i - i) % n;
          dp2[pos]--;
          if (dp2[pos] == 0 && st2[pos] == 0) {
            q.push({pos, 2});
            st2[pos] = 2;
          }
        }
      } else if (st1[b.i] == 2) {
        for (auto i : lk2) {
          int pos = (n + b.i - i) % n;
          if (st2[pos] == 0) {
            q.push({pos, 2});
            st2[pos] = 1;
          }
        }
      }
    } else {
      if (st2[b.i] == 1) {
        for (auto i : lk1) {
          int pos = (n + b.i - i) % n;
          dp1[pos]--;
          if (dp1[pos] == 0 && st1[pos] == 0) {
            q.push({pos, 1});
            st1[pos] = 2;
          }
        }
      } else if (st2[b.i] == 2) {
        for (auto i : lk1) {
          int pos = (n + b.i - i) % n;
          if (st1[pos] == 0) {
            q.push({pos, 1});
            st1[pos] = 1;
          }
        }
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (st1[i] == 2) {
      cout << "Lose ";
    } else if (st1[i] == 0) {
      cout << "Loop ";
    } else {
      cout << "Win ";
    }
  }
  cout << "\n";
  for (int i = 1; i < n; i++) {
    if (st2[i] == 2) {
      cout << "Lose ";
    } else if (st2[i] == 0) {
      cout << "Loop ";
    } else {
      cout << "Win ";
    }
  }
  cout << "\n";
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2.

At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.

Compute the number of pairs of viewers (x, y) such that y will hate x forever.

Constraints

* 2 \le N \le 500
* The sequence P_1, P_2, \dots, P_{N^2} is a permutation of \\{1, 2, \dots, N^2\\}.

Input

The input is given from Standard Input in the format

N
P_1 P_2 \cdots P_{N^2}

Output

If ans is the number of pairs of viewers described in the statement, you should print on Standard Output

ans

Output

If ans is the number of pairs of viewers described in the statement, you should print on Standard Output

ans

Examples

Input

3
1 3 7 9 5 4 8 6 2

Output

1

Input

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

Output

3

Input

6
11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30

Output

11

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
long long int ans=0;

int dist[500][500],vis[500][500];
bool in(int x,int y){
	return x>=0&&x<n&&y>=0&&y<n;
}
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

void dfs(int x,int y){
	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(in(nx,ny)){
			if(!vis[x][y]){
				if(dist[nx][ny]>dist[x][y]+1)
					dist[nx][ny]=dist[x][y]+1,dfs(nx,ny);
			}
			else{
				if(dist[nx][ny]>dist[x][y])
					dist[nx][ny]=dist[x][y],dfs(nx,ny);
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n*n;i++){
		int x=i/n,y=i%n;
		dist[x][y]=min({x,n-1-x,y,n-1-y});
	}
	for(int i=1,x;i<=n*n;i++){
		cin>>x;
		x--;
		ans+=dist[x/n][x%n];
		vis[x/n][x%n]=true;
		dfs(x/n,x%n);
	}
	cout<<ans<<endl;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

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>
int prims[10010];
bool sito[100010];
int prims_c = 0;
bool is_bad[10010];
std::set<int> bad;
char rozklad[5010][10010];
char _GCD[5010][10010];
char (*GCD)[10010] = _GCD + 1;
char GCD_r[10010];
int tab[5010];
int main() {
  for (int i = 2; i < 100000; i++)
    if (!sito[i]) {
      for (int j = i * 2; j < 100000; j += i) sito[j] = 1;
      prims[prims_c++] = i;
    }
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", tab + i);
  int index = 0;
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    if (x < 100000) {
      while (prims[index] < x) index++;
      is_bad[index] = 1;
    } else
      bad.insert(x);
  }
  memset(GCD[-1], 120, sizeof(GCD[-1]));
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < prims_c && tab[i] > 1; j++)
      while (tab[i] % prims[j] == 0) {
        rozklad[i][j]++;
        if (GCD[i - 1][j] > GCD[i][j]) GCD[i][j]++;
        if (is_bad[j])
          res--;
        else
          res++;
        tab[i] /= prims[j];
      }
    if (i == 0)
      GCD_r[0] = tab[i];
    else if (GCD_r[i - 1] == tab[i])
      GCD_r[i] = tab[i];
    else
      GCD_r[i] = 1;
    if (bad.end() != bad.find(tab[i]))
      res--;
    else if (tab[i] > 1)
      res++;
  }
  int last_change = 0;
  for (int i = n - 1; i >= 0; i--) {
    int val = 0;
    for (int j = 0; j < 10010; j++)
      if (is_bad[j])
        val -= GCD[i][j];
      else
        val += GCD[i][j];
    if (GCD_r[i] > 1)
      if (bad.end() != bad.find(GCD_r[i]))
        val--;
      else
        val++;
    if (val < last_change) {
      res -= (val - last_change) * (i + 1);
      last_change = val;
    }
  }
  printf("%d\n", res);
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given a rooted tree with n nodes, labeled from 1 to n. The tree is rooted at node 1. The parent of the i-th node is p_i. A leaf is node with no children. For a given set of leaves L, let f(L) denote the smallest connected subgraph that contains all leaves L.

You would like to partition the leaves such that for any two different sets x, y of the partition, f(x) and f(y) are disjoint.

Count the number of ways to partition the leaves, modulo 998244353. Two ways are different if there are two leaves such that they are in the same set in one way but in different sets in the other.

Input

The first line contains an integer n (2 ≤ n ≤ 200 000) — the number of nodes in the tree.

The next line contains n-1 integers p_2, p_3, …, p_n (1 ≤ p_i < i).

Output

Print a single integer, the number of ways to partition the leaves, modulo 998244353.

Examples

Input

5
1 1 1 1

Output

12

Input

10
1 2 3 4 5 6 7 8 9

Output

1

Note

In the first example, the leaf nodes are 2,3,4,5. The ways to partition the leaves are in the following image <image>

In the second example, the only leaf is node 10 so there is only one partition. Note that node 1 is not a leaf.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int MOD = 998244353;
int dp[MAXN][3];
vector<int> E[MAXN];
void dfs(int now) {
  if (E[now].size() == 0) {
    dp[now][2] = 1;
    return;
  }
  int sz = E[now].size();
  dp[now][0] = 1;
  for (int v : E[now]) {
    dfs(v);
    dp[now][2] = (1LL * dp[now][2] *
                      (1LL * dp[v][0] + dp[v][2] + dp[v][2] + dp[v][1]) % MOD +
                  1LL * dp[now][1] * (dp[v][1] + dp[v][2]) % MOD) %
                 MOD;
    dp[now][1] = (1LL * dp[now][1] * (dp[v][0] + dp[v][2]) % MOD +
                  1LL * dp[now][0] * (dp[v][2] + dp[v][1]) % MOD) %
                 MOD;
    dp[now][0] = 1LL * dp[now][0] * (dp[v][0] + dp[v][2]) % MOD;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    E[x].push_back(i);
  }
  dfs(1);
  long long ans = (dp[1][0] + dp[1][2]) % MOD;
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

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

In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.

A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.

You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.

Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively.

Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v).

You may assume that there is at most one railway connecting any two towns.

Output

Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.

Examples

Input

4 2
1 3
3 4

Output

2

Input

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

Output

-1

Input

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

Output

3

Note

In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time.

In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int map1[410][410], map2[410][410];
int n, m;
void dijkstra(int map[][410]) {
  int res[410];
  int vis[410];
  int v, min;
  for (int i = 1; i <= n; i++) {
    vis[i] = 0;
    res[i] = map[1][i];
  }
  for (int i = 1; i <= n; i++) {
    min = 1 << 29;
    for (int j = 1; j <= n; j++) {
      if (vis[j] == 0 && res[j] < min) {
        v = j;
        min = res[j];
      }
    }
    vis[v] = 1;
    for (int j = 1; j <= n; j++) {
      if (vis[j] == 0 && res[j] > map[v][j] + res[v]) {
        res[j] = map[v][j] + res[v];
      }
    }
  }
  if (res[n] == 1 << 29) {
    printf("-1\n");
    return;
  } else
    printf("%d\n", res[n]);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i == j) {
          map1[i][j] = 0;
          map1[i][j] = 0;
        } else {
          map1[i][j] = map1[j][i] = 1 << 29;
          map2[i][j] = map2[j][i] = 1 << 29;
        }
      }
    }
    int flag = 0;
    for (int i = 0; i < m; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      if ((a == 1 && b == n) || (a == n && b == 1)) {
        flag = 1;
      }
      map1[a][b] = 1;
      map1[b][a] = 1;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (map1[i][j] == 1 << 29 || map1[i][j] == 0) {
          map2[i][j] = 1;
          map2[j][i] = 1;
        }
      }
    }
    if (m == n * (n - 1) / 2) {
      printf("-1\n");
      continue;
    }
    if (flag == 1) {
      dijkstra(map2);
    } else if (flag == 0) {
      dijkstra(map1);
    }
  }
  return 0;
}

```


### Prompt

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

Let N be a positive integer. You are given a string s of length N - 1, consisting of `<` and `>`.

Find the number of permutations (p_1, p_2, \ldots, p_N) of (1, 2, \ldots, N) that satisfy the following condition, modulo 10^9 + 7:

* For each i (1 \leq i \leq N - 1), p_i < p_{i + 1} if the i-th character in s is `<`, and p_i > p_{i + 1} if the i-th character in s is `>`.

Constraints

* N is an integer.
* 2 \leq N \leq 3000
* s is a string of length N - 1.
* s consists of `<` and `>`.

Input

Input is given from Standard Input in the following format:

N
s

Output

Print the number of permutations that satisfy the condition, modulo 10^9 + 7.

Examples

Input

4
<><

Output

5

Input

5
<<<<

Output

1

Input

20
>>>><>>><>><>>><<>>

Output

217136290

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll md = 1e9+7;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	ll dp[n+1][n+1];
	dp[1][1] = 1;
	for (int q = 2; q <= n; q++)
	{
		if (s[q-2] == '>')
		{
			dp[q][q] = 0;
			for (int w = q-1; w >= 1; w--)
			{
				dp[q][w] = (dp[q][w+1] + dp[q-1][w]) % md;
			}
		}
		else
		{
			dp[q][1] = 0;
			for (int w = 2; w <= q; w++)
			{
				dp[q][w] = (dp[q][w-1] + dp[q-1][w-1]) % md;
			}
		}
	}
	ll tot = 0;
	for (int q = 1; q <= n; q++)
	{
		tot = (tot + dp[n][q]) % md;
	}
	cout << tot <<"\n";
	return 0;
}

```


### Prompt

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

We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.

The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.

Input

The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.

Output

Print the minimum number of steps modulo 109 + 7.

Examples

Input

ab

Output

1

Input

aab

Output

3

Note

The first example: "ab"  →  "bba".

The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
bool is_prime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
inline long long getPow(long long a, long long b) {
  long long res = 1, tp = a;
  while (b) {
    if (b & 1ll) {
      res *= tp;
    }
    tp *= tp;
    b >>= 1ll;
  }
  return res;
}
inline long long to_ll(string s) {
  long long cur = 0;
  for (int i = 0; i < s.size(); i++) {
    cur = cur * 10 + s[i] - '0';
  }
  return cur;
}
inline string to_str(long long x) {
  string s = "";
  while (x) {
    s += char(x % 10 + '0');
    x /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
inline long long nxt() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void ok() {
  puts("YES");
  exit(0);
}
void no() {
  puts("NO");
  exit(0);
}
bool check(long long a, long long b1, long long b2, long long A, long long B) {
  if (b1 + b2 <= B && a <= A) {
    return true;
  } else
    return false;
}
int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  long long ans = 0;
  long long ct = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'b') {
      ct++;
    } else {
      ans += ct;
      ct *= 2;
      ans %= 1000000007;
      ct %= 1000000007;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Bomboslav set up a branding agency and now helps companies to create new logos and advertising slogans. In term of this problems, slogan of the company should be a non-empty substring of its name. For example, if the company name is "hornsandhoofs", then substrings "sand" and "hor" could be its slogans, while strings "e" and "hornss" can not.

Sometimes the company performs rebranding and changes its slogan. Slogan A is considered to be cooler than slogan B if B appears in A as a substring at least twice (this occurrences are allowed to overlap). For example, slogan A =  "abacaba" is cooler than slogan B =  "ba", slogan A =  "abcbcbe" is cooler than slogan B =  "bcb", but slogan A =  "aaaaaa" is not cooler than slogan B =  "aba".

You are given the company name w and your task is to help Bomboslav determine the length of the longest sequence of slogans s1, s2, ..., sk, such that any slogan in the sequence is cooler than the previous one.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the company name that asks Bomboslav to help. The second line contains the string w of length n, that consists of lowercase English letters.

Output

Print a single integer — the maximum possible length of the sequence of slogans of the company named w, such that any slogan in the sequence (except the first one) is cooler than the previous

Examples

Input

3
abc

Output

1

Input

5
ddddd

Output

5

Input

11
abracadabra

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 444444, mod = 998244353;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 0;
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, cnt, lst, fa[maxn], ch[maxn][26], len[maxn], el, head[maxn], to[maxn],
    nxt[maxn], rt[maxn], tot, ls[maxn * 33], rs[maxn * 33], ans, pos[maxn],
    f[maxn], tr[maxn];
char s[maxn];
inline void add(int u, int v) {
  to[++el] = v;
  nxt[el] = head[u];
  head[u] = el;
}
inline void init() { fa[0] = -1; }
void update(int &x, int l, int r, int p) {
  if (!x) x = ++tot;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (mid >= p)
    update(ls[x], l, mid, p);
  else
    update(rs[x], mid + 1, r, p);
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  int now = ++tot;
  ls[now] = merge(ls[x], ls[y]);
  rs[now] = merge(rs[x], rs[y]);
  return now;
}
bool query(int x, int l, int r, int ql, int qr) {
  if (!x) return false;
  if (l >= ql && r <= qr) return true;
  int mid = (l + r) >> 1;
  if (mid < ql) return query(rs[x], mid + 1, r, ql, qr);
  if (mid >= qr) return query(ls[x], l, mid, ql, qr);
  return query(ls[x], l, mid, ql, qr) || query(rs[x], mid + 1, r, ql, qr);
}
void extend(int id, int c) {
  int now = ++cnt;
  pos[now] = id;
  len[now] = len[lst] + 1;
  int p = lst;
  lst = now;
  for (; ~p && !ch[p][c]; p = fa[p]) ch[p][c] = now;
  if (~p) {
    int q = ch[p][c];
    if (len[p] + 1 == len[q])
      fa[now] = q;
    else {
      int cl = ++cnt;
      len[cl] = len[p] + 1;
      fa[cl] = fa[q];
      pos[cl] = pos[q];
      fa[q] = fa[now] = cl;
      for (int i = (0); i <= (25); i++) ch[cl][i] = ch[q][i];
      for (; ~p && ch[p][c] == q; p = fa[p]) ch[p][c] = cl;
    }
  }
}
void dfs(int u) {
  update(rt[u], 1, n, pos[u]);
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    dfs(v);
    rt[u] = merge(rt[u], rt[v]);
  }
}
void dfs2(int u) {
  if (u) {
    if (!fa[u])
      tr[u] = u, f[u] = 1;
    else {
      int tmp = tr[fa[u]];
      if (query(rt[tmp], 1, n, pos[u] - len[u] + len[tmp], pos[u] - 1))
        tr[u] = u, f[u] = f[fa[u]] + 1;
      else
        tr[u] = tmp, f[u] = f[fa[u]];
    }
  }
  ans = max(ans, f[u]);
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    dfs2(v);
  }
}
int main() {
  n = read();
  scanf("%s", s + 1);
  init();
  for (int i = (1); i <= (n); i++) extend(i, s[i] - 'a');
  for (int i = (1); i <= (cnt); i++) add(fa[i], i);
  dfs(0);
  dfs2(0);
  printf("%d\n", ans);
}

```


### Prompt

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

One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.

<image>

Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads S is regular if it can be represented as S = A + B + A + B + A + ... + A + B + A, where A and B are some bead sequences, " + " is the concatenation of sequences, there are exactly 2k + 1 summands in this sum, among which there are k + 1 "A" summands and k "B" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if A or B is an empty sequence.

Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order.

Input

The first line contains two integers n, k (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and number k from the definition of the regular sequence above.

The second line contains the sequence of n lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.

Output

Print a string consisting of n zeroes and ones. Position i (1 ≤ i ≤ n) must contain either number one if the first i beads on the thread form a regular sequence, or a zero otherwise.

Examples

Input

7 2
bcabcab

Output

0000011

Input

21 2
ababaababaababaababaa

Output

000110000111111000011

Note

In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take A = "", B = "bca"), and a sequence of the first 7 beads (we can take A = "b", B = "ca").

In the second sample test, for example, a sequence of the first 13 beads is regular, if we take A = "aba", B = "ba".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int64_t MOD = 1000051373LL;
const int64_t BASE = 100;
const int64_t BASE_MODULAR_INVERSE = 630032365;
string s;
int n, k, max_packet[N], f[N];
int64_t phash[N], BMI[N];
bool ans[N], ask[N];
void hash_preproc();
int64_t get_hash(int, int);
int64_t _sum(int64_t, int64_t);
int64_t _mul(int64_t, int64_t);
int32_t main() {
  cin >> n >> k >> s;
  hash_preproc();
  for (int len = 1; len * k <= n; len++) {
    vector<int64_t> sh;
    for (int i = 0; i < k; i++) sh.push_back(get_hash(i * len, (i + 1) * len));
    sh.resize(unique(sh.begin(), sh.end()) - sh.begin());
    if (sh.size() == 1) ask[len * k - 1] = true;
  }
  int p = 0;
  for (int i = 1; i < n; i++) {
    while (s[i] != s[p] and p > 0) p = f[p];
    if (s[i] == s[p]) p++;
    f[i + 1] = p;
  }
  p = 0;
  for (int i = 1; i < n; i++) {
    while (s[i] != s[p] and p > 0) p = f[p];
    if (s[i] == s[p]) p++;
    while ((!ask[i - p] or (i - p + 1) / k < p) and p > 0) p = f[p];
    if (ask[i - p] and (i - p + 1) / k >= p) ans[i + 1] = true;
  }
  ans[1] = (k == 1);
  for (int i = 1; i <= n; i++) cout << ans[i];
  cout << endl;
}
void hash_preproc() {
  int64_t cur_base = 1;
  for (int i = 1; i <= n; i++) {
    phash[i] = _sum(phash[i - 1], _mul(cur_base, int(s[i - 1] - 'a' + 1)));
    cur_base = _mul(cur_base, BASE);
  }
  BMI[0] = 1;
  for (int i = 1; i <= n; i++) BMI[i] = _mul(BMI[i - 1], BASE_MODULAR_INVERSE);
}
int64_t get_hash(int l, int r) {
  int64_t res = _sum(phash[r], MOD - phash[l]);
  res = _mul(res, BMI[l]);
  return res;
}
int64_t _sum(int64_t a, int64_t b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int64_t _mul(int64_t a, int64_t b) { return 1LL * a * b % MOD; }

```


### Prompt

Generate a Cpp solution to the following problem:

The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:

You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.

You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.

All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.

You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set.

Input

The first line contains integer id (0 ≤ id ≤ 106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.

The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set).

Output

Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to.

Examples

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
string tr[3][50] = {{"BRITISH, FRENCH MINISTERS DISCUSS PUBLIC SPENDING",
                     "FORMER HERSTATT DEALER CAN BE SUED, COURT RULES",
                     "U.K. MONEY MARKET DEFICIT FORECAST AT 700 MLN STG",
                     "BANK OF SPAIN SUSPENDS ASSISTANCE",
                     "U.K. MONEY MARKET GIVEN 265 MLN STG ASSISTANCE",
                     "BANK OF FRANCE AGAIN BUYING DOLLARS, SOURCES SAY",
                     "BUNDESBANK BOUGHT DOLLARS AGAINST YEN, DEALERS SAY",
                     "U.K. MONEY MARKET GIVEN FURTHER 663 MLN STG HELP",
                     "AUSTRIA DOES NOT INTERVENE TO SUPPORT DOLLAR",
                     "TAIWAN TO STUDY SUSPENDING FOREX CONTROLS",
                     "OFFICIAL WANTS ARAB FUND TO HELP LEBANESE POUND",
                     "CHINA POSTPONES PLAN TO SCRAP PARALLEL CURRENCY",
                     "ARAB BANKER SAYS TOO SOON FOR SINGLE CURRENCY",
                     "ARAB FOREX ASSOCIATION ELECTS NEW CHAIRMAN",
                     "JAPAN CAREFULLY CONSIDERING MONEY POLICY -- SUMITA",
                     "BAHRAIN INTRODUCES NEW MONEY MARKET REGIME",
                     "BANK OF ENGLAND FORECASTS SURPLUS IN MONEY MARKET",
                     "PHILADELPHIA EXCHANGE TO EXTEND HOURS FOR ASIA",
                     "JAPAN CONDUCTS CURRENCY SURVEY OF BIG INVESTORS",
                     "BANK OF ENGLAND DOES NOT OPERATE IN MONEY MARKET",
                     "ASIAN DOLLAR MARKET ASSETS FALL IN JANUARY",
                     "PHILADELPHIA EXCHANGE TO EXTEND HOURS FOR ASIA",
                     "JAPAN CAREFULLY CONSIDERING MONEY POLICY - SUMITA",
                     "U.K. MONEY MARKET GIVEN 129 MLN STG ASSISTANCE",
                     "JAPAN CONDUCTS CURRENCY SURVEY OF BIG INVESTORS",
                     "JAPANESE SEEN LIGHTENING U.S. BOND HOLDINGS",
                     "FED ADDS RESERVES VIA CUSTOMER REPURCHASES",
                     "FORMER TREASURY OFFICIAL URGES CURRENCY REFORMS",
                     "FED WILL BUY BILLS FOR CUSTOMER AFTER AUCTION",
                     "TREASURY BALANCES AT FED FELL ON MARCH 27",
                     "U.S. CREDIT MARKETS END UNDER EXTREME PRESSURE",
                     "U.K. MONEY MARKET OFFERED EARLY ASSISTANCE",
                     "UK MONEY MARKET GIVEN FURTHER 570 MLN STG HELP",
                     "CALL MONEY PRESSURE FROM LARGE GERMAN BANKS",
                     "U.K. MONEY MARKET SHORTAGE FORECAST REVISED UP",
                     "U.K. MONEY MARKET GIVEN 215 MLN STG LATE HELP",
                     "U.S. TREASURY'S BAKER SEES RATE STABILITY",
                     "TREASURY'S BAKER SAYS COOPERATION WORKING",
                     "TREASURY'S BAKER SAYS U.S. BACKS STABILITY",
                     "BANGEMANN CALLS FOR CURRENCY CALM",
                     "TREASURY'S BAKER PURSUING S. ASIAN REVALUATIONS",
                     "TREASURY'S BAKER PURSUING S. ASIAN REVALUATIONS",
                     "CURRENCY FUTURES CLIMB LIKELY TO BE CHECKED",
                     "U.S. FED EXPLORES COMMODITY BASKET INDEX",
                     "U.K. MONEY MARKET OFFERED EARLY ASSISTANCE",
                     "U.K. MONEY MARKET GIVEN 689 MLN STG EARLY HELP",
                     "U.K. MONEY MARKET SHORTAGE FORECAST REVISED UP",
                     "U.K. MONEY MARKET DEFICIT REVISED DOWNWARDS",
                     "FED BUYS ONE BILLION DLRS OF BILLS FOR CUSTOMER",
                     "FED BUYS ONE BILLION DLRS OF BILLS FOR CUSTOMER"},
                    {"N.Z. TRADING BANK DEPOSIT GROWTH RISES SLIGHTLY",
                     "NEW YORK BUSINESS LOANS FALL 222 MLN DLRS",
                     "U.S. M-1 MONEY SUPPLY RISES 1.2 BILLION DLR",
                     "CANADIAN MONEY SUPPLY FALLS IN WEEK",
                     "DUTCH MONEY SUPPLY HARDLY CHANGED IN DECEMBER",
                     "U.K. CONFIRMS FEBRUARY STERLING M3 RISE",
                     "SINGAPORE M-1 MONEY SUPPLY 2.7 PCT UP IN JANUARY",
                     "SINGAPORE BANK CREDIT RISES IN JANUARY",
                     "H.K. M3 MONEY SUPPLY RISES 1.4 PCT IN FEBRUARY",
                     "U.S. BANK DISCOUNT BORROWINGS 310 MLN DLRS",
                     "U.S. M-1 MONEY SUPPLY ROSE 2.1 BILLION DLRS",
                     "AUSTRALIAN BROAD MONEY GROWTH 10.3 PCT IN FEBRUARY",
                     "TAIWAN ISSUES MORE CERTIFICATES OF DEPOSIT",
                     "SOUTH KOREAN MONEY SUPPLY FALLS IN MARCH",
                     "BELGIAN MONEY SUPPLY RISES IN FOURTH QUARTER 1986",
                     "CANADIAN MONEY SUPPLY FALLS IN WEEK",
                     "TREASURY BALANCES AT FED ROSE ON FEB 27",
                     "FEBRUARY FOMC VOTES UNCHANGED MONETARY POLICY",
                     "U.S. BUSINESS LOANS FELL 822 MLN DLRS",
                     "GERMAN CAPITAL ACCOUNT IN DEFICIT IN FEBRUARY",
                     "TREASURY BALANCES AT FED ROSE ON APRIL 6",
                     "TAIWAN ISSUES MORE CDS TO CURB MONEY SUPPLY GROWTH",
                     "SOUTH KOREAN MONEY SUPPLY RISES IN FEBRUARY",
                     "SPAIN RAISES BANKS' RESERVE REQUIREMENT",
                     "N.Z. MONEY SUPPLY RISES 3.6 PCT IN DECEMBER",
                     "FED DATA SUGGEST STABLE U.S. MONETARY POLICY",
                     "N.Z. CENTRAL BANK SEES SLOWER MONEY, CREDIT GROWTH",
                     "U.S. M-1 MONEY SUPPLY RISES 1.9 BILLION DLRS",
                     "U.S. MONEY GROWTH SLOWS SHARPLY, ECONOMISTS SAY",
                     "CANADIAN MONEY SUPPLY RISES IN WEEK",
                     "TREASURY BALANCES AT FED FELL ON MARCH 5",
                     "U.S. BUSINESS LOANS FALL 618 MLN DLRS",
                     "SINGAPORE M-1 MONEY SUPPLY UP 3.7 PCT IN DECEMBER",
                     "FRENCH JANUARY M-3 MONEY SUPPLY RISES ONE PCT",
                     "U.K. CONFIRMS JANUARY STERLING M3 RISE",
                     "TREASURY BALANCES AT FED ROSE ON MARCH 6",
                     "SPAIN'S MONEY SUPPLY GROWTH DOUBLES IN FEBRUARY",
                     "TREASURY BALANCES AT FED FELL ON MARCH 10",
                     "NEW YORK BUSINESS LOANS FALL 718 MLN DLRS",
                     "U.S. M-1 MONEY SUPPLY FALLS 600 MLN DLRS",
                     "JAPAN PERSONAL SAVINGS SOAR IN 1986",
                     "CANADIAN MONEY SUPPLY RISES IN WEEK",
                     "U.S. BUSINESS LOANS RISE 377 MLN DLRS",
                     "BANGLADESH MONEY SUPPLY RISES IN DECEMBER",
                     "GERMAN FEBRUARY CENTRAL BANK MONEY GROWTH STEADY",
                     "THAI M-1 MONEY SUPPLY RISES IN JANUARY",
                     "JAPAN FEBRUARY MONEY SUPPLY RISES 8.8 PCT",
                     "ASSETS OF U.S. MONEY FUNDS ROSE IN WEEK",
                     "ITALY M-2 UP 2.8 PCT IN 3 MONTHS TO END JANUARY",
                     "PHILIPPINES' LIQUIDITY RISES, LOAN DEMAND FALLS"},
                    {"WHITE HOUSE UNIT DECIDES ON SEMICONDUCTORS",
                     "CHINA CALLS FOR BETTER TRADE DEAL WITH U.S.",
                     "GATT WARNS U.S. ON FEDERAL BUDGET, PROTECTIONISM",
                     "WHITE HOUSE PANEL SAID URGING JAPAN RETALIATION",
                     "NAKASONE TO VISIT WASHINGTON IN LATE APRIL",
                     "WORLD BANK CHIEF URGES MORE JAPANESE INVESTMENT",
                     "NAKASONE TO VISIT WASHINGTON IN LATE APRIL",
                     "NAKASONE HARD-PRESSED TO SOOTHE U.S ANGER ON TRADE",
                     "INDIA STEPS UP COUNTERTRADE DEALS TO CUT TRADE GAP",
                     "UK MAY REVOKE JAPANESE FINANCIAL LICENSES",
                     "REAGAN READY TO IMPOSE TRADE CURBS AGAINST JAPAN",
                     "JAPAN'S CHIP MAKERS ANGERED BY U.S. SANCTION PLANS",
                     "NAKASONE SOUNDS CONCILIATORY NOTE IN CHIP DISPUTE",
                     "ISLAMIC BANKS ESTABLISH 50 MLN DLR TRADE PORTFOLIO",
                     "TOKYO BIDS TO STOP CHIP ROW TURNING INTO TRADE WAR",
                     "BALDRIGE PREDICTS END OF U.S.-JAPAN TRADE DISPUTE",
                     "JAPAN HAS LITTLE NEW TO OFFER IN MICROCHIP DISPUTE",
                     "NAKASONE SOUNDS CONCILIATORY NOTE IN CHIP DISPUTE",
                     "TOKYO BIDS TO STOP CHIP ROW BECOMING TRADE WAR",
                     "BALDRIGE PREDICTS END OF U.S.-JAPAN TRADE DISPUTE",
                     "YUGOSLAV TRADE FALLS SHARPLY  STATISTICS SHOW",
                     "ECONOMIC SPOTLIGHT - U.S. CONGRESS RAPS JAPAN",
                     "U.S. TRADE OFFICIAL SAYS JAPAN ACTION FOOLISH",
                     "EUROPEAN COMMUNITY TO SET UP OFFICE IN PEKING",
                     "TRADE FRICTION THREATENS TO TOPPLE NAKASONE",
                     " EUROPE ON SIDELINES IN U.S-JAPAN MICROCHIP ROW",
                     "THATCHER SAYS TRADE TARGETS SET WITH MOSCOW",
                     "JAPAN TO CUT MICROCHIP OUTPUT, BOOST IMPORTS",
                     "JAPAN WILL ASK COMPANIES TO BOOST IMPORTS",
                     "U.S./JAPAN TRADE WAR NOT IN UK'S INTEREST - LAWSON",
                     "EC APPROVES MEDITERRANEAN FINANCIAL PACKAGES",
                     "SOVIET UNION SEEN WATCHING CHINA GATT APPLICATION",
                     "U.S. SENATE LEADERS SEE NO TRADE WAR BREWING",
                     "U.S. STOCK MARKET OVERREACTS TO TARIFFS - YEUTTER",
                     "ENVOY ADVISES NAKASONE TO PREPARE FOR U.S. VISIT",
                     "TREASURY'S BAKER SEES SMALLER TRADE DEFICIT",
                     "TREASURY'S BAKER NOT CONCERNED BY BOND DECLINES",
                     "U.S.-JAPAN NOT IN TRADE WAR, YEUTTER SAYS",
                     "CHIRAC, REAGAN DISCUSS ARMS CONTROL, TRADE",
                     "TRADE WAR FEARS MAY PROMPT STOCK MARKETS' DOWNTURN",
                     "WHITE HOUSE DISCOUNTS THREAT OF TRADE WAR",
                     "BALDRIGE SAYS U.S. TO IMPOSE JAPANESE SANCTIONS",
                     "SENIOR U.S. OFFICIAL TO VISIT JAPAN AS TRADE ROW GROWS",
                     "BROADER U.S. EEP SOUGHT BY REPUBLICAN LAWMAKERS",
                     "U.S. OFFICIAL TO VISIT JAPAN AS TRADE ROW GROWS",
                     "U.S. OFFICIAL SEES EVIDENCE OF EXPORT GROWTH",
                     "TAIWAN'S SECOND QUARTER IMPORTS SEEN RISING",
                     "BELGIAN SAYS EC WOULD REACT TO TEXTILE BILL",
                     "ROSTENKOWSKI OPPOSES PROTECTIONIST TRADE BILL",
                     "U.K. EXPORTS BODY GETS NEW EXECUTIVE DIRECTOR"}};
char buf[1100000];
string trim(string s) {
  string res;
  for (int i = 0; i < (int)(s.size()); i++)
    if (isalpha(s[i]) || isdigit(s[i])) res += s[i];
  return res;
}
bool match(string s1, string s2) { return trim(s1) == trim(s2); }
int main() {
  gets(buf);
  string text;
  while (gets(buf)) {
    text += buf;
    break;
  }
  for (int i = 0; i < (int)(3); i++)
    for (int j = 0; j < (int)(i); j++)
      for (int a = 0; a < (int)(50); a++)
        for (int b = 0; b < (int)(50); b++)
          if (match(tr[i][a], tr[j][b])) throw;
  for (int i = 0; i < (int)(3); i++)
    for (int j = 0; j < (int)(50); j++)
      if (match(text, tr[i][j])) {
        printf("%d\n", i + 1);
        return 0;
      }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

The Committee for Research on Binary Viruses discovered a method of replication for a large family of viruses whose genetic codes are sequences of zeros and ones. Each virus originates from a single gene; for simplicity genes are denoted by integers from 0 to G - 1. At each moment in time a virus is a sequence of genes. When mutation occurs, one of the genes from the sequence is replaced by a certain sequence of genes, according to the mutation table. The virus stops mutating when it consists only of genes 0 and 1.

For instance, for the following mutation table: $$$ 2 → ⟨ 0\ 1 ⟩ \\\ 3 → ⟨ 2\ 0\ 0⟩\\\ 3 → ⟨ 1\ 3⟩\\\ 4 → ⟨ 0\ 3\ 1\ 2⟩\\\ 5 → ⟨ 2\ 1⟩\\\ 5 → ⟨ 5⟩  a virus that initially consisted of a single gene 4, could have mutated as follows:  ⟨ 4 ⟩ → ⟨ \underline{0\ 3\ 1\ 2} ⟩ → ⟨ 0\ \underline{2\ 0\ 0}\ 1\ 2 ⟩ → ⟨ 0\ \underline{0\ 1}\ 0\ 0\ 1\ 2 ⟩ → ⟨ 0\ 0\ 1\ 0\ 0\ 1\ \underline{0\ 1} ⟩  or in another way:  ⟨ 4 ⟩ → ⟨ \underline{0\ 3\ 1\ 2} ⟩ → ⟨ 0\ \underline{1\ 3}\ 1\ 2 ⟩ → ⟨ 0\ 1\ 3\ 1\ \underline{0\ 1} ⟩ → ⟨ 0\ 1\ \underline{2\ 0\ 0}\ 1\ 0\ 1 ⟩ → ⟨ 0\ 1\ \underline{0\ 1}\ 0\ 0\ 1\ 0\ 1 ⟩ $$$

Viruses are detected by antibodies that identify the presence of specific continuous fragments of zeros and ones in the viruses' codes. For example, an antibody reacting to a fragment ⟨ 0\ 0\ 1\ 0\ 0 ⟩ will detect a virus ⟨ 0\ 0\ 1\ 0\ 0\ 1\ 0\ 1 ⟩, but it will not detect a virus ⟨ 0\ 1\ 0\ 1\ 0\ 0\ 1\ 0\ 1 ⟩.

For each gene from 2 to G-1, the scientists are wondering whether a given set of antibodies is enough to detect all viruses that can emerge through mutations from this gene. If not, they want to know the length of the shortest virus that cannot be detected.

It may happen that sometimes scientists don't have any antibodies. Then of course no virus can be detected, so the scientists are only interested in the length of the shortest possible virus that can emerge from the gene mutations.

Input

The first line of the input will contain three integers G, N and M (G > 2, N ≥ G - 2, M ≥ 0) specifying the number of genes, the number of rows in the mutation table, and the number of antibodies.

The following N lines contain descriptions of rows of the mutation table; each line begins with two integers a and k (2 ≤ a < G, k ≥ 1), followed by a sequence of k integers b_1, b_2, …, b_k (0 ≤ b_i < G), that encode the row $$$ a → ⟨ b_1\ b_2\ …\ b_k ⟩ $$$

The sum of all values k does not exceed 100. Every integer from 2 to G - 1 appears in the table as a at least once.

The next M lines contain descriptions of the antibodies; each such line begins with an integer ℓ (ℓ ≥ 1), followed by a sequence of ℓ integers c_1, c_2, …, c_ℓ (0 ≤ c_i ≤ 1), describing the antibody. The sum of all values ℓ does not exceed 50.

Output

Your program needs to output exactly G - 2 lines, containing the answers for the subsequent genes from 2 to G - 1.

If all viruses that can mutate from this single gene can be detected by the given set of antibodies, you need to print the word "YES". You also need to print this if there are no viruses that could originate from this gene (it can happen when the sequences never stop mutating).

Otherwise you need to print the word "NO", followed by an integer denoting the minimal length of the undetectable virus. You can assume that for all the prepared input data this value will be smaller than 2^{63}.

Scoring

Subtasks:

  1. (11 points) No antibodies (M = 0)
  2. (14 points) N = G - 2
  3. (25 points) One antibody (M = 1)
  4. (32 points) The sum of all values ℓ does not exceed 10
  5. (18 points) No further constraints

Example

Input

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

Output

NO 2
NO 4
NO 9
YES

### Response

```cpp
#include <bits/stdc++.h>
namespace IAKIOI {
const long long L = 1 << 20 | 1;
char buffer[L], *S, *TT;
inline void read(long long &x) {
  x = 0;
  long long f = 1;
  char s =
      ((S == TT && (TT = (S = buffer) + fread(buffer, 1, L, stdin), S == TT))
           ? EOF
           : *S++);
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = ((S == TT && (TT = (S = buffer) + fread(buffer, 1, L, stdin), S == TT))
             ? EOF
             : *S++);
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = ((S == TT && (TT = (S = buffer) + fread(buffer, 1, L, stdin), S == TT))
             ? EOF
             : *S++);
  }
  x *= f;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
}  // namespace IAKIOI
using namespace IAKIOI;
const unsigned long long oo = 1ull << 63;
unsigned long long f[205][52][52];
long long G, N, M, n, m, b[55], ty[205], v[205][55][55];
std::vector<std::pair<long long, long long>> out[205];
long long ch[55][2], fail[55], ok[55], rt = 1, tot = 1;
inline void insert(long long *a, long long len) {
  long long nw = rt;
  for (long long i = 1; i <= len; i++) {
    if (!ch[nw][a[i]]) ch[nw][a[i]] = ++tot;
    nw = ch[nw][a[i]];
  }
  ok[nw] = 1;
}
std::queue<long long> Q;
inline void getfail() {
  for (long long i = 0; i <= 1; i++)
    if (ch[rt][i])
      fail[ch[rt][i]] = rt, Q.push(ch[rt][i]);
    else
      ch[rt][i] = rt;
  while (Q.size()) {
    long long u = Q.front();
    Q.pop();
    for (long long i = 0; i <= 1; i++)
      if (ch[u][i]) {
        fail[ch[u][i]] = ch[fail[u]][i];
        ok[ch[u][i]] |= ok[fail[ch[u][i]]];
        Q.push(ch[u][i]);
      } else
        ch[u][i] = ch[fail[u]][i];
  }
}
long long id[55], num[55];
struct node {
  long long x, fr, ed;
  unsigned long long num;
  node(long long _x = 0, long long _fr = 0, long long _ed = 0,
       unsigned long long _num = 0) {
    x = _x;
    fr = _fr;
    ed = _ed;
    num = _num;
  }
  friend bool operator<(node a, node b) { return a.num > b.num; }
};
std::priority_queue<node> Heap;
signed main() {
  read(G), G--;
  read(N), read(M), n = G;
  for (long long i = 1, a = 0, k = 0; i <= N; i++, n += k) {
    read(a), read(k);
    for (long long j = 1; j <= k; j++) read(b[j]), ty[n + j] = 1;
    for (long long j = 2; j <= k; j++) {
      out[n + j].push_back(std::make_pair(n + j - 1, b[j - 1]));
      out[b[j - 1]].push_back(std::make_pair(n + j - 1, n + j));
    }
    out[b[k]].push_back(std::make_pair(n + k, -1));
    out[n + 1].push_back(std::make_pair(a, -1));
  }
  for (long long i = 1, len; i <= M; i++) {
    read(len);
    for (long long j = 1; j <= len; j++) read(b[j]);
    insert(b, len);
  }
  getfail();
  long long cnt = 0;
  for (long long i = 1; i <= tot; i++)
    if (!ok[i]) id[i] = ++cnt, num[cnt] = i;
  for (long long i = 0; i <= n; i++)
    for (long long j = 1; j <= cnt; j++)
      for (long long k = 1; k <= cnt; k++) f[i][j][k] = oo;
  for (long long i = 1; i <= cnt; i++) {
    long long x = num[i];
    if (id[ch[x][0]]) {
      f[0][i][id[ch[x][0]]] = 1;
      Heap.push(node(0, i, id[ch[x][0]], 1));
    }
    if (id[ch[x][1]]) {
      f[1][i][id[ch[x][1]]] = 1;
      Heap.push(node(1, i, id[ch[x][1]], 1));
    }
  }
  while (Heap.size()) {
    node tmp = Heap.top();
    Heap.pop();
    long long x = tmp.x, fr = tmp.fr, ed = tmp.ed;
    unsigned long long val = tmp.num;
    if (v[x][fr][ed]) continue;
    v[x][fr][ed] = 1;
    for (std::pair<long long, long long> u : out[x]) {
      long long y = u.first, w = u.second;
      if (w == -1) {
        if (f[y][fr][ed] > val) {
          f[y][fr][ed] = val;
          Heap.push(node(y, fr, ed, f[y][fr][ed]));
        }
      } else {
        if (!ty[x]) {
          for (long long j = 1; j <= cnt; j++)
            if (f[y][fr][j] > val + f[w][ed][j]) {
              f[y][fr][j] = val + f[w][ed][j];
              Heap.push(node(y, fr, j, f[y][fr][j]));
            }
        } else {
          for (long long j = 1; j <= cnt; j++)
            if (f[y][j][ed] > val + f[w][j][fr]) {
              f[y][j][ed] = val + f[w][j][fr];
              Heap.push(node(y, j, ed, f[y][j][ed]));
            }
        }
      }
    }
  }
  for (long long i = 2; i <= G; i++) {
    unsigned long long ans = oo;
    for (long long j = 1; j <= cnt; j++) ans = std::min(ans, f[i][1][j]);
    (ans == oo) ? puts("YES") : printf("NO %lld\n", ans);
  }
  return 0;
}

```


### Prompt

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

Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.

Help him give n bags of candies to each brother so that all brothers got the same number of candies.

Input

The single line contains a single integer n (n is even, 2 ≤ n ≤ 100) — the number of Gerald's brothers.

Output

Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers — the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.

It is guaranteed that the solution exists at the given limits.

Examples

Input

2

Output

1 4
2 3

Note

The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int s[11000];
int main(int argc, char *argv[]) {
  int n = 0;
  cin >> n;
  int i = 0;
  for (i = 0; i < 10001; i++) {
    s[i] = i + 1;
  }
  int j = 0;
  int step = 0;
  int k = 0;
  for (i = 0; i < n; i++) {
    for (j = step; j < step + n / 2; j++) {
      cout << s[j] << ' ';
    }
    for (k = n * n - step - n / 2; k < n * n - step; k++) {
      cout << s[k] << ' ';
    }
    cout << endl;
    step = step + n / 2;
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

We have N balance beams numbered 1 to N. The length of each beam is 1 meters. Snuke walks on Beam i at a speed of 1/A_i meters per second, and Ringo walks on Beam i at a speed of 1/B_i meters per second.

Snuke and Ringo will play the following game:

* First, Snuke connects the N beams in any order of his choice and makes a long beam of length N meters.
* Then, Snuke starts at the left end of the long beam. At the same time, Ringo starts at a point chosen uniformly at random on the long beam. Both of them walk to the right end of the long beam.
* Snuke wins if and only if he catches up to Ringo before Ringo reaches the right end of the long beam. That is, Snuke wins if there is a moment when Snuke and Ringo stand at the same position, and Ringo wins otherwise.

Find the probability that Snuke wins when Snuke arranges the N beams so that the probability of his winning is maximized.

This probability is a rational number, so we ask you to represent it as an irreducible fraction P/Q (to represent 0, use P=0, Q=1).

Constraints

* 1 \leq N \leq 10^5
* 1 \leq A_i,B_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the numerator and denominator of the irreducible fraction that represents the maximum probability of Snuke's winning.

Examples

Input

2
3 2
1 2

Output

1 4

Input

4
1 5
4 7
2 1
8 4

Output

1 2

Input

3
4 1
5 2
6 3

Output

0 1

Input

10
866111664 178537096
705445072 318106937
472381277 579910117
353498483 865935868
383133839 231371336
378371075 681212831
304570952 16537461
955719384 267238505
844917655 218662351
550309930 62731178

Output

697461712 2899550585

### Response

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

int a[200010],b[200010],n,val[200010],l,r,mid,ans,fp,nwp;
long long nw,sum[200010],nww,fa,fb,nwa,nwb;

long long gcd(long long a,long long b) {return (!b)?a:gcd(b,a%b);}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]),val[i]=max(a[i],b[i]),nw+=min(a[i]-b[i],0);
	sort(val+1,val+1+n),sum[0]=0,fp=0,fa=0,fb=1;
	for (int i=1; i<=n; i++) sum[i]=sum[i-1]+val[i];
	for (int i=1; i<=n; i++)
	{
		l=1,r=n,ans=0,nww=(a[i]<b[i]?nw:nw+a[i]-b[i]);
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (sum[mid]-(max(a[i],b[i])<=val[mid]?max(a[i],b[i]):0)+nww<=0) ans=mid,l=mid+1; else r=mid-1;
		}
		nww=nww-(a[i]-b[i])+sum[ans]-(max(a[i],b[i])<=val[ans]?max(a[i],b[i]):0);
		nwp=ans-(max(a[i],b[i])<=val[ans]);
		nwa=b[i]-(a[i]+nww),nwb=b[i];
		if (nwp>fp||nwp==fp&&nwa*fb>nwb*fa) fp=nwp,fa=nwa,fb=nwb;
	}
	fa+=fp*fb,fb*=n;
	long long g=gcd(fa,fb);
	printf("%lld %lld\n",fa/g,fb/g);
	return 0;
}
```


### Prompt

Please create a solution in cpp to the following problem:

Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the stack is empty, then the operation pop() does nothing.

Nikita made m operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the i-th step he remembers an operation he made pi-th. In other words, he remembers the operations in order of some permutation p1, p2, ..., pm. After each step Nikita wants to know what is the integer on the top of the stack after performing the operations he have already remembered, in the corresponding order. Help him!

Input

The first line contains the integer m (1 ≤ m ≤ 105) — the number of operations Nikita made.

The next m lines contain the operations Nikita remembers. The i-th line starts with two integers pi and ti (1 ≤ pi ≤ m, ti = 0 or ti = 1) — the index of operation he remembers on the step i, and the type of the operation. ti equals 0, if the operation is pop(), and 1, is the operation is push(x). If the operation is push(x), the line also contains the integer xi (1 ≤ xi ≤ 106) — the integer added to the stack.

It is guaranteed that each integer from 1 to m is present exactly once among integers pi.

Output

Print m integers. The integer i should equal the number on the top of the stack after performing all the operations Nikita remembered on the steps from 1 to i. If the stack is empty after performing all these operations, print -1.

Examples

Input

2
2 1 2
1 0

Output

2
2

Input

3
1 1 2
2 1 3
3 0

Output

2
3
2

Input

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

Output

-1
-1
-1
-1
2

Note

In the first example, after Nikita remembers the operation on the first step, the operation push(2) is the only operation, so the answer is 2. After he remembers the operation pop() which was done before push(2), answer stays the same.

In the second example, the operations are push(2), push(3) and pop(). Nikita remembers them in the order they were performed.

In the third example Nikita remembers the operations in the reversed order.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int GLL(long long& x) { return scanf("%lld", &x); }
int GI(int& x) { return scanf("%d", &x); }
const int MAXRT = 333;
const int MAXM = MAXRT * MAXRT;
pair<int, int> actions[MAXM];
int pops[MAXRT];
vector<int> pushes[MAXRT];
int m, p, t, x;
void buildBlock(int b) {
  pops[b] = 0;
  pushes[b] = vector<int>();
  for (int i = b * MAXRT; i < (b + 1) * MAXRT; i++) {
    if (actions[i].first == 0) {
      if (pushes[b].size() > 0) {
        pushes[b].pop_back();
      } else {
        pops[b]++;
      }
    } else if (actions[i].first == 1) {
      pushes[b].push_back(actions[i].second);
    }
  }
}
vector<pair<int, int> > state;
int combineBlocks() {
  state = vector<pair<int, int> >();
  for (int i = 0; i < (int)(MAXRT); i++) {
    int pop = pops[i];
    while (pop > 0 && state.size() > 0) {
      if (state[state.size() - 1].second <= pop) {
        pop -= state[state.size() - 1].second;
        state.pop_back();
      } else {
        state[state.size() - 1].second -= pop;
        pop = 0;
      }
    }
    state.push_back(make_pair(i, pushes[i].size()));
  }
  while (state.size() > 0 && state[state.size() - 1].second == 0) {
    state.pop_back();
  }
  if (state.size() == 0) {
    return -1;
  } else {
    return pushes[state[state.size() - 1].first]
                 [state[state.size() - 1].second - 1];
  }
}
int main() {
  for (int i = 0; i < (int)(MAXM); i++) actions[i] = make_pair(-1, -1);
  memset(pops, 0, sizeof pops);
  GI(m);
  for (int i = 0; i < (int)(m); i++) {
    GI(p);
    GI(t);
    if (t == 1) GI(x);
    actions[p] = make_pair(t, x);
    buildBlock(p / MAXRT);
    printf("%d\n", combineBlocks());
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?

Input

The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion.

The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.

Output

Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print  - 1.

Examples

Input

5
1 2 3 4 5

Output

-1

### Response

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

```


### Prompt

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

There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.

New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall

We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.

Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.

Input

The first line of the input contains three integers n, a and b (1 ≤ n ≤ 10 000, 1 ≤ a, b ≤ 100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.

Output

If there is no way to assigns seats to parliamentarians in a proper way print -1.

Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.

Examples

Input

3 2 2

Output

0 3
1 2

Input

8 4 3

Output

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

Input

10 2 2

Output

-1

Note

In the first sample there are many other possible solutions. For example,

    3 2
    0 1

and

    2 1
    3 0

The following assignment

    3 2
    1 0

is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int p, n, m;
  cin >> p >> n >> m;
  if (p > n * m)
    cout << "-1\n";
  else {
    for (int i = 0; i < n; i++) {
      int s, e;
      s = i * m + 1;
      e = (i + 1) * m;
      if (i % 2 == 0 || (m % 2 == 1)) {
        for (int j = s; j <= e; j++)
          if (j <= p)
            cout << j << ' ';
          else
            cout << "0 ";
        cout << '\n';
      } else {
        for (int j = e; j >= s; j--)
          if (j <= p)
            cout << j << ' ';
          else
            cout << "0 ";
        cout << '\n';
      }
    }
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.

For a given sentence, the cipher is processed as:

  1. Convert all letters of the sentence to lowercase.
  2. Reverse each of the words of the sentence individually.
  3. Remove all the spaces in the sentence.

For example, when this cipher is applied to the sentence

Kira is childish and he hates losing

the resulting string is

ariksihsidlihcdnaehsetahgnisol

Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10 000) — the length of the ciphered text. The second line consists of n lowercase English letters — the ciphered text t.

The third line contains a single integer m (1 ≤ m ≤ 100 000) — the number of words which will be considered while deciphering the text. Each of the next m lines contains a non-empty word wi (|wi| ≤ 1 000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1 000 000.

Output

Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.

Examples

Input

30
ariksihsidlihcdnaehsetahgnisol
10
Kira
hates
is
he
losing
death
childish
L
and
Note

Output

Kira is childish and he hates losing

Input

12
iherehtolleh
5
HI
Ho
there
HeLLo
hello

Output

HI there HeLLo

Note

In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000009;
const long long b = 29;
const int N = 100002;
int dp[10003], sa[10003], n, m;
string v[N], s;
unordered_map<long long, int> p;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> s >> m;
  for (int i = 0; i < m; ++i) {
    cin >> v[i];
    long long h = 0ll;
    for (int j = v[i].size() - 1; j >= 0; j--) {
      long long ch = v[i][j] - 'a' + 1;
      if (ch <= 0) ch = v[i][j] - 'A' + 1;
      h = (h * b + ch) % mod;
    }
    p[h] = i + 1;
  }
  int len = s.size() - 1;
  dp[len + 1] = n;
  for (int i = len; i >= 0; --i) {
    long long h = 0ll;
    for (int j = i; j <= len; ++j) {
      long long ch = s[j] - 'a' + 1;
      h = ((h * b) + ch) % mod;
      if (dp[j + 1] and p.find(h) != p.end()) {
        dp[i] = j + 1;
        sa[i] = p[h];
        break;
      }
    }
  }
  for (int i = 0; i <= len; i = dp[i]) {
    cout << v[sa[i] - 1] << " ";
    if (i >= dp[i]) break;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.

The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has n students. Dean's office allows i-th student to use the segment (li, ri) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students!

Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (n - 1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.

Input

The first line contains a positive integer n (1 ≤ n ≤ 100). The (i + 1)-th line contains integers li and ri (0 ≤ li < ri ≤ 100) — the endpoints of the corresponding segment for the i-th student.

Output

On a single line print a single number k, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.

Examples

Input

3
0 5
2 8
1 6

Output

1

Input

3
0 10
1 5
7 15

Output

3

Note

Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.

In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1.

In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int A[1000];
int n, r1, l1, r, l, i, j;
int s = 0;
int main() {
  scanf("%d%d%d", &n, &r1, &l1);
  for (i = 0; i <= 101; i++) {
    A[i] = 0;
  }
  for (i = 2; i <= n; i++) {
    scanf("%d%d", &r, &l);
    for (j = r + 1; j <= l; j++) A[j] = 1;
  }
  for (i = r1 + 1; i <= l1; i++) {
    if (A[i] == 0) {
      s++;
    }
  }
  printf("%d\n", s);
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.

Iahub starts with workout located at line 1 and column 1. He needs to finish with workout a[n][m]. After finishing workout a[i][j], he can go to workout a[i + 1][j] or a[i][j + 1]. Similarly, Iahubina starts with workout a[n][1] and she needs to finish with workout a[1][m]. After finishing workout from cell a[i][j], she goes to either a[i][j + 1] or a[i - 1][j].

There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.

If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.

Input

The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105).

Output

The output contains a single number — the maximum total gain possible.

Examples

Input

3 3
100 100 100
100 1 100
100 100 100

Output

800

Note

Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1010][1010] = {0};
int dp00[1010][1010] = {0}, dp01[1010][1010] = {0}, dp10[1010][1010] = {0},
    dp11[1010][1010] = {0};
int ans = 0;
int ans1 = 0, ans2 = 0;
void init() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp00[i][j] = max(dp00[i - 1][j], dp00[i][j - 1]) + a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      dp01[i][j] = max(dp01[i - 1][j], dp01[i][j + 1]) + a[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      dp10[i][j] = max(dp10[i + 1][j], dp10[i][j - 1]) + a[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      dp11[i][j] = max(dp11[i + 1][j], dp11[i][j + 1]) + a[i][j];
    }
  }
}
void solve() {
  for (int i = 2; i <= n - 1; i++) {
    for (int j = 2; j <= m - 1; j++) {
      ans = max(ans, dp00[i][j - 1] + dp01[i - 1][j] + dp10[i + 1][j] +
                         dp11[i][j + 1]);
      ans = max(ans, dp00[i - 1][j] + dp01[i][j + 1] + dp10[i][j - 1] +
                         dp11[i + 1][j]);
    }
  }
  cout << ans;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  init();
  solve();
}

```


### Prompt

Create a solution in CPP for the following problem:

We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:

* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.

Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.

Constraints

* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.

Examples

Input

xabxa

Output

2

Input

ab

Output

-1

Input

a

Output

0

Input

oxxx

Output

3

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int ans=0;
	cin>>s;
	int n=s.size();
	int l=0; int r=n-1;
	while(l<=r)
	{
		if(s[l]==s[r])
		{
			l++; r--;
			continue;
		}
		if(s[l]!='x' && s[r]!='x')
		{
			cout<<-1<<endl;
			return 0;
		}
		if(s[l]=='x')
		{
			l++;
			ans++;
			continue;
		}
		if(s[r]=='x')
		{
			r--;;
			ans++;
			continue;
		}
	}
	cout<<ans<<endl;
	return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

problem

AOR Ika is a monster buster.
One day, as I was walking down the road, I met a sleeping monster.

AOR Ika, who has a strong fighting spirit, decides to hit the monster with a wake-up blow. However, the current attack power of AOR Ika is $ 0 $, and she cannot make a decent attack as it is.

AOR Ika-chan, who is devoting himself to the monster buster, was actually entrusted with a special whistle by his master. When he plays a specific song with this whistle, his attack power increases for a certain period of time.

Trained AOR Ika can play $ N $ songs. The $ i $ th song takes $ R_i $ seconds to play, and the attack power increases by $ A_i $ after the performance ends. After $ T_i $ seconds, the effect of this performance will be cut off and the attack power will return to that before the performance.

Also, AOR Ika-chan can play over and over. If you finish playing the same song during the effect time of the performance, the attack power will increase by $ W_i $ instead of $ A_i $. The time is not extended. Therefore, when the first effect of the $ i $ th song currently in effect expires, all the effects of the layered performance also expire.

Output the maximum attack power of AOR Ika-chan. No matter how much you play, no monster will occur, and AOR Ika-chan can attack in $ 0.5 $ seconds.

output

Output the maximum value of AOR Ika-chan's attack power. Also, output a line break at the end.

Example

Input

2
5 10 5 5
4 4 2 2

Output

14

### Response

```cpp
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
long long dp[2][2020];
vector<pair<pair<long long,long long>,pair<long long,long long> > >E;
int main()
{
	cin>>N;
	for(int i=0;i<=2000;i++)dp[0][i]=-1e18;
	for(int i=0;i<N;i++)
	{
		long long R,A,W,T;
		cin>>R>>A>>W>>T;
		T--;
		E.push_back({{T,R},{A,W}});
	}
	sort(E.begin(),E.end(),[](
	pair<pair<long long,long long>,pair<long long,long long> >a,
	pair<pair<long long,long long>,pair<long long,long long> >b
	){return a.first.first+a.first.second>b.first.first+b.first.second;}
	);
	for(int i=0;i<N;i++)
	{
		long long R,A,W,T;
		R=E[i].first.second;
		A=E[i].second.first;
		W=E[i].second.second;
		T=E[i].first.first;
		for(int j=0;j<=2000;j++)dp[1][j]=-1e18;
		for(int j=R;j<=2000;j++)
		{
			dp[1][min(T,j-R)]=max(dp[1][min(T,j-R)],dp[0][j]+A);
		}
		dp[1][T]=max(dp[1][T],A);
		for(int j=T;j>=R;j--)
		{
			dp[1][j-R]=max(dp[1][j-R],dp[1][j]+W);
		}
		for(int j=0;j<=2000;j++)dp[0][j]=max(dp[0][j],dp[1][j]);
	}
	long long ans=0;
	for(int j=0;j<=2000;j++)ans=max(ans,dp[0][j]);
	cout<<ans<<endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied:

For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1.

For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1.

<image>

Input

The first and the only line contain one integer n (1 ≤ n ≤ 10^5).

Output

If there is no solution, output "NO" in the first line.

If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them.

Examples

Input

3

Output

YES
1 4 5 2 3 6

Input

4

Output

NO

Note

Example from the statement is shown for the first example.

It can be proved that there is no solution in the second example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int a[(100000 + 5) << 1];
int main() {
  scanf("%d", &n);
  if (!(n & 1)) return printf("NO"), 0;
  const int lim = n + n;
  for (int i = 1; i <= n; ++i) {
    if (i & 1) {
      a[i] = i;
      a[i + n] = a[i] + 1;
    } else {
      a[i] = lim - i + 2;
      a[i + n] = a[i] - 1;
    }
  }
  printf("YES\n");
  for (int i = 1; i <= lim; ++i) {
    printf("%d ", a[i]);
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are organizing a boxing tournament, where n boxers will participate (n is a power of 2), and your friend is one of them. All boxers have different strength from 1 to n, and boxer i wins in the match against boxer j if and only if i is stronger than j.

The tournament will be organized as follows: n boxers will be divided into pairs; the loser in each pair leaves the tournament, and n/2 winners advance to the next stage, where they are divided into pairs again, and the winners in all pairs advance to the next stage, and so on, until only one boxer remains (who is declared the winner).

Your friend really wants to win the tournament, but he may be not the strongest boxer. To help your friend win the tournament, you may bribe his opponents: if your friend is fighting with a boxer you have bribed, your friend wins even if his strength is lower.

Furthermore, during each stage you distribute the boxers into pairs as you wish.

The boxer with strength i can be bribed if you pay him a_i dollars. What is the minimum number of dollars you have to spend to make your friend win the tournament, provided that you arrange the boxers into pairs during each stage as you wish?

Input

The first line contains one integer n (2 ≤ n ≤ 2^{18}) — the number of boxers. n is a power of 2.

The second line contains n integers a_1, a_2, ..., a_n, where a_i is the number of dollars you have to pay if you want to bribe the boxer with strength i. Exactly one of a_i is equal to -1 — it means that the boxer with strength i is your friend. All other values are in the range [1, 10^9].

Output

Print one integer — the minimum number of dollars you have to pay so your friend wins.

Examples

Input

4
3 9 1 -1

Output

0

Input

8
11 -1 13 19 24 7 17 5

Output

12

Note

In the first test case no matter how you will distribute boxers into pairs, your friend is the strongest boxer and anyway wins the tournament.

In the second test case you can distribute boxers as follows (your friend is number 2):

1 : 2, 8 : 5, 7 : 3, 6 : 4 (boxers 2, 8, 7 and 6 advance to the next stage);

2 : 6, 8 : 7 (boxers 2 and 8 advance to the next stage, you have to bribe the boxer with strength 6);

2 : 8 (you have to bribe the boxer with strength 8);

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &x, const T &y) {
  return x > y ? y : x;
}
template <class T>
inline T max(T &x, const T &y) {
  return x < y ? y : x;
}
long long read() {
  long long c = getchar(), Nig = 1, x = 0;
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') Nig = -1, c = getchar();
  while (isdigit(c)) x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
  return Nig * x;
}
namespace usual {
inline long long gcd(long long a, long long b) {
  long long t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}
inline long long qPow(long long x, long long k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = (res * x);
    k >>= 1;
    x = (x * x);
  }
  return res;
}
inline double qPow1(double x, long long k) {
  if (k == 1) return x;
  long long res = 1.0;
  while (k) {
    if (k & 1) res = (res * x);
    k >>= 1;
    x = (x * x);
  }
  return res;
}
inline long long oula(long long x) {
  long long res = x;
  for (long long i = 2; i <= x / i; i++) {
    if (x % i == 0) {
      res = res / i * (i - 1);
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) res = res / x * (x - 1);
  return res;
}
}  // namespace usual
using namespace usual;
priority_queue<int, vector<int>, greater<int>> xiaogen;
priority_queue<int, vector<int>, less<int>> dagen;
const long long inf = 1e15;
const long long INF = 0x3f3f3f3f;
const int maxn = 6e5 + 7;
const int mod = 1000000007;
int n;
long long a[maxn];
multiset<int> st;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  long long ans = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] == -1) break;
    st.insert(a[i]);
    if ((i & (i - 1)) == 0) {
      ans += *st.begin();
      st.erase(st.begin());
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.

Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1, a2, ..., an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.

As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the coins' values. All numbers are separated with spaces.

Output

In the single line print the single number — the minimum needed number of coins.

Examples

Input

2
3 3

Output

2

Input

3
2 1 2

Output

2

Note

In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.

In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, counter = 0, sum = 0, x = 0;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  sort(arr, arr + n);
  int i = n - 1;
  while (counter <= sum && sum != 0) {
    sum -= arr[i];
    counter += arr[i];
    i--;
    x++;
  }
  cout << x << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.

An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.

In the grid shown below, n = 3 and m = 3. There are n + m = 6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n·m = 9 intersection points, numbered from 1 to 9.

<image>

The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).

Assume that both players play optimally. Who will win the game?

Input

The first line of input contains two space-separated integers, n and m (1 ≤ n, m ≤ 100).

Output

Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.

Examples

Input

2 2

Output

Malvika

Input

2 3

Output

Malvika

Input

3 3

Output

Akshat

Note

Explanation of the first sample:

The grid has four intersection points, numbered from 1 to 4.

<image>

If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.

<image>

Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.

In the empty grid, Akshat cannot make any move, hence he will lose.

Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool chance = true;
  while (n > 0 && m > 0) {
    n--, m--;
    chance = !chance;
  }
  if (chance)
    cout << "Malvika";
  else
    cout << "Akshat";
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible.

In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is a palindrome and remove it from the line. After the substring is removed, the remaining gemstones shift to form a solid line again. What is the minimum number of seconds needed to destroy the entire line?

Let us remind, that the string (or substring) is called palindrome, if it reads same backwards or forward. In our case this means the color of the first gemstone is equal to the color of the last one, the color of the second gemstone is equal to the color of the next to last and so on.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 500) — the number of gemstones.

The second line contains n space-separated integers, the i-th of which is ci (1 ≤ ci ≤ n) — the color of the i-th gemstone in a line.

Output

Print a single integer — the minimum number of seconds needed to destroy the entire line.

Examples

Input

3
1 2 1

Output

1

Input

3
1 2 3

Output

3

Input

7
1 4 4 2 3 2 1

Output

2

Note

In the first sample, Genos can destroy the entire line in one second.

In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds.

In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 2 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[505][505];
int mat[505];
int min(int a, int b) { return a < b ? a : b; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> mat[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dp[i][j] = (int)1e9;
  for (int i = 0; i < n; i++) dp[i][i] = 1;
  for (int i = 0; i < n - 1; i++) dp[i][i + 1] = (mat[i] == mat[i + 1] ? 1 : 2);
  for (int diff = 2; diff < n; diff++) {
    for (int i = 0; i + diff < n; i++) {
      int j = i + diff;
      dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
      for (int k = i; k < j; k++) {
        int extra;
        if (mat[k] == mat[j]) {
          extra = 0;
          if (k + 1 == j) extra = 1;
        } else
          extra = 2;
        dp[i][j] =
            min(dp[i][j], (k > i ? dp[i][k - 1] : 0) +
                              (k < j - 1 ? dp[k + 1][j - 1] : 0) + extra);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
}

```


### Prompt

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

The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.

Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:

  * First, he will jump from island 0 to island d.
  * After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.

Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.

Input

The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.

The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤ p1 ≤ p2 ≤ ... ≤ pn ≤ 30000), denoting the number of the island that contains the i-th gem.

Output

Print the maximum number of gems that Mr. Kitayuta can collect.

Examples

Input

4 10
10
21
27
27

Output

3

Input

8 8
9
19
28
36
45
55
66
78

Output

6

Input

13 7
8
8
9
16
17
17
18
21
23
24
24
26
30

Output

4

Note

In the first sample, the optimal route is 0  →  10 (+1 gem)  →  19  →  27 (+2 gems)  → ...

In the second sample, the optimal route is 0  →  8  →  15  →  21 →  28 (+1 gem)  →  36 (+1 gem)  →  45 (+1 gem)  →  55 (+1 gem)  →  66 (+1 gem)  →  78 (+1 gem)  → ...

In the third sample, the optimal route is 0  →  7  →  13  →  18 (+1 gem)  →  24 (+2 gems)  →  30 (+1 gem)  → ...

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
const int INF = (int)1e7;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;
const double PI = M_PI;
const int M = 30001;
int dp[M][250 * 2];
bool used[M][250 * 2] = {};
int d;
int gem[M] = {};
int solve(int i, int j) {
  int jj = j - (d - 250);
  if (i >= M) return 0;
  if (used[i][jj]) return dp[i][jj];
  used[i][jj] = true;
  int res;
  if (j == 1) {
    res = gem[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));
  } else {
    res = gem[i] + max(max(solve(i + j - 1, j - 1), solve(i + j, j)),
                       solve(i + j + 1, j + 1));
  }
  dp[i][jj] = res;
  return res;
}
int main() {
  int n;
  scanf("%d %d", &n, &d);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    gem[x]++;
  }
  printf("%d\n", solve(d, d));
  return 0;
}

```


### Prompt

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

You are given n words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.

Each lyric consists of two lines. Each line consists of two words separated by whitespace.

A lyric is beautiful if and only if it satisfies all conditions below.

  * The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line.
  * The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line.
  * The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.

Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.

For example of a beautiful lyric,

"hello hellooowww"

"whatsup yowowowow"

is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".

For example of a not beautiful lyric,

"hey man"

"iam mcdic"

is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).

How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.

Input

The first line contains single integer n (1 ≤ n ≤ 10^{5}) — the number of words.

The i-th of the next n lines contains string s_{i} consisting lowercase alphabet letters — the i-th word. It is guaranteed that the sum of the total word length is equal or less than 10^{6}. Each word contains at least one vowel.

Output

In the first line, print m — the number of maximum possible beautiful lyrics.

In next 2m lines, print m beautiful lyrics (two lines per lyric).

If there are multiple answers, print any.

Examples

Input

14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that

Output

3
about proud
hooray round
wow first
this is
i that
mcdics am

Input

7
arsijo
suggested
the
idea
for
this
problem

Output

0

Input

4
same
same
same
differ

Output

1
same differ
same same

Note

In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".

In the second example, you cannot form any beautiful lyric from given words.

In the third example, you can use the word "same" up to three times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
string s[maxn];
struct word {
  int id, lst;
  word() {}
  word(int id, int lst) : id(id), lst(lst) {}
  bool operator<(const word &t) const {
    if (lst != t.lst) return lst < t.lst;
    return id < t.id;
  }
};
vector<word> len[maxm];
int cot[maxn], lst[maxn];
int n, mx;
set<word> dq;
set<word>::iterator it, itb;
int ff, fs, sf, ss;
vector<int> ans[4];
inline bool good(char x) {
  return x == 'a' || x == 'e' || x == 'u' || x == 'i' || x == 'o';
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < s[i].length(); j++) {
      if (good(s[i][j])) {
        cot[i]++;
        lst[i] = s[i][j] - 'a';
      }
    }
    len[cot[i]].push_back(word(i, lst[i]));
    mx = max(mx, cot[i]);
  }
  ff = fs = sf = ss = -1;
  word fst;
  for (int i = 1; i <= mx; i++) {
    if (!len[i].empty()) {
      sort(len[i].begin(), len[i].end());
      for (int j = 0; j < len[i].size(); j++) {
        if (j + 1 < len[i].size() && len[i][j].lst == len[i][j + 1].lst) {
          j++;
          continue;
        } else
          dq.insert(word(len[i][j].id, i));
      }
    }
  }
  for (int i = 1; i <= mx; i++) {
    if (!len[i].empty()) {
      for (int j = 0; j < len[i].size(); j++) {
        if (j + 1 < len[i].size() && len[i][j].lst == len[i][j + 1].lst) {
          bool got = 0;
          if (!dq.empty()) {
            for (it = dq.begin(); it != dq.end(); it++) {
              itb = ++it;
              --it;
              if (itb != dq.end() && (*it).lst == (*itb).lst) {
                got = 1;
                ans[0].emplace_back((*it).id);
                ans[1].emplace_back(len[i][j].id);
                ans[2].emplace_back((*itb).id);
                ans[3].emplace_back(len[i][j + 1].id);
                dq.erase(it);
                dq.erase(itb);
                break;
              }
            }
          }
          if (!got) {
            dq.insert(word(len[i][j].id, i));
            dq.insert(word(len[i][j + 1].id, i));
          }
          j++;
          continue;
        } else
          ;
      }
    }
  }
  printf("%d\n", ans[0].size());
  for (int i = 0; i < ans[0].size(); i++) {
    printf("%s %s\n%s %s\n", s[ans[0][i]].c_str(), s[ans[1][i]].c_str(),
           s[ans[2][i]].c_str(), s[ans[3][i]].c_str());
  }
  return 0;
}

```