### Prompt

Generate a CPP solution to the following problem:

Diverta City is a new city consisting of N towns numbered 1, 2, ..., N.

The mayor Ringo is planning to connect every pair of two different towns with a bidirectional road. The length of each road is undecided.

A Hamiltonian path is a path that starts at one of the towns and visits each of the other towns exactly once. The reversal of a Hamiltonian path is considered the same as the original Hamiltonian path.

There are N! / 2 Hamiltonian paths. Ringo wants all these paths to have distinct total lengths (the sum of the lengths of the roads on a path), to make the city diverse.

Find one such set of the lengths of the roads, under the following conditions:

* The length of each road must be a positive integer.
* The maximum total length of a Hamiltonian path must be at most 10^{11}.

Constraints

* N is a integer between 2 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print a set of the lengths of the roads that meets the objective, in the following format:

w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}
w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}
:  :     :
w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}

where w_{i, j} is the length of the road connecting Town i and Town j, which must satisfy the following conditions:

* w_{i, i} = 0
* w_{i, j} = w_{j, i} \ (i \neq j)
* 1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)

If there are multiple sets of lengths of the roads that meet the objective, any of them will be accepted.

Examples

Input

3

Output

0 6 15
6 0 21
15 21 0

Input

4

Output

0 111 157 193
111 0 224 239
157 224 0 258
193 239 258 0

### Response

```cpp
#define DEBUG 0
/**
 * File    : F.cpp
 * Author  : Kazune Takahashi
 * Created : 6/16/2019, 1:52:04 AM
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
typedef long long ll;
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}
const int MAX_SIZE = 1000010;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a) { return (*this *= power(MOD - 2)); }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
mint inv[MAX_SIZE];
mint fact[MAX_SIZE];
mint factinv[MAX_SIZE];
void init()
{
  inv[1] = 1;
  for (int i = 2; i < MAX_SIZE; i++)
  {
    inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
  }
  fact[0] = factinv[0] = 1;
  for (int i = 1; i < MAX_SIZE; i++)
  {
    fact[i] = mint(i) * fact[i - 1];
    factinv[i] = inv[i] * factinv[i - 1];
  }
}
mint choose(int n, int k)
{
  if (n >= 0 && k >= 0 && n - k >= 0)
  {
    return fact[n] * factinv[k] * factinv[n - k];
  }
  return 0;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// const double epsilon = 1e-10;
// const ll infty = 1000000000000000LL;
// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

int N;
ll w[10][10];
int X[10];
vector<ll> V;
unordered_set<int> H;

void make_vector()
{
  for (auto i = 0; i < N; i++)
  {
    for (auto j = 1;; j++)
    {
      bool ok = true;
      if (H.find(j) != H.end())
      {
        ok = false;
      }
      for (auto &x : V)
      {
        if (H.find(x + j) != H.end())
        {
          ok = false;
          break;
        }
      }
      if (!ok)
      {
        continue;
      }
#if DEBUG == 1
      assert(H.find(j) == H.end());
      cerr << "H.insert(" << j << ")" << endl;
#endif
      H.insert(j);
      for (auto &x : V)
      {
#if DEBUG == 1
        assert(H.find(x + j) == H.end());
        cerr << "H.insert(" << x + j << ")" << endl;
#endif
        H.insert(x + j);
      }
      V.push_back(j);
#if DEBUG == 1
      cerr << "V.push_back(" << j << ")" << endl;
#endif
      break;
    }
  }
}

ll hamilton_path(int K)
{
  ll ans = 0;
  for (auto i = 0; i < K; i++)
  {
    X[i] = i;
  }
  do
  {
    ll t = 0;
    for (auto i = 0; i < K - 1; i++)
    {
      t += w[X[i]][X[i + 1]];
    }
    maxs(ans, t);
  } while (next_permutation(X, X + K));
  return ans;
}

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    w[i][i] = 0;
  }
  make_vector();
  for (auto i = 1; i < N; i++)
  {
    ll M = hamilton_path(i) + 1;
    for (auto j = 0; j < i; j++)
    {
      w[i][j] = w[j][i] = M * V[j];
    }
  }
  for (auto i = 0; i < N; i++)
  {
    for (auto j = 0; j < N; j++)
    {
      cout << w[i][j];
      if (j < N - 1)
      {
        cout << " ";
      }
      else
      {
        cout << endl;
      }
    }
  }
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Authors have come up with the string s consisting of n lowercase Latin letters.

You are given two permutations of its indices (not necessary equal) p and q (both of length n). Recall that the permutation is the array of length n which contains each integer from 1 to n exactly once.

For all i from 1 to n-1 the following properties hold: s[p_i] ≤ s[p_{i + 1}] and s[q_i] ≤ s[q_{i + 1}]. It means that if you will write down all characters of s in order of permutation indices, the resulting string will be sorted in the non-decreasing order.

Your task is to restore any such string s of length n consisting of at least k distinct lowercase Latin letters which suits the given permutations.

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

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string and the number of distinct characters required.

The second line of the input contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, all p_i are distinct integers from 1 to n) — the permutation p.

The third line of the input contains n integers q_1, q_2, ..., q_n (1 ≤ q_i ≤ n, all q_i are distinct integers from 1 to n) — the permutation q.

Output

If it is impossible to find the suitable string, print "NO" on the first line.

Otherwise print "YES" on the first line and string s on the second line. It should consist of n lowercase Latin letters, contain at least k distinct characters and suit the given permutations.

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

Example

Input

3 2
1 2 3
1 3 2

Output

YES
abb

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int n, k, p[N], q[N], h[N];
char ans[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int j;
    cin >> j;
    p[j] = i;
    q[i] = j;
  }
  for (int i = 1; i <= n; i++) {
    int j;
    cin >> j;
    int l = min(i, p[j]), r = max(i, p[j]);
    h[l]++;
    h[r]--;
  }
  int v = 0, c = 0;
  for (int i = 1; i <= n; i++) {
    v += h[i];
    ans[q[i]] = 'a' + min(25, c);
    if (!v) c++;
  }
  if (c >= k) {
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      cout << ans[i];
    }
  } else {
    cout << "NO";
  }
  return 0;
}

```


### Prompt

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

You are given a permutation a consisting of n numbers 1, 2, ..., n (a permutation is an array in which each element from 1 to n occurs exactly once).

You can perform the following operation: choose some subarray (contiguous subsegment) of a and rearrange the elements in it in any way you want. But this operation cannot be applied to the whole array.

For example, if a = [2, 1, 4, 5, 3] and we want to apply the operation to the subarray a[2, 4] (the subarray containing all elements from the 2-nd to the 4-th), then after the operation, the array can become a = [2, 5, 1, 4, 3] or, for example, a = [2, 1, 5, 4, 3].

Your task is to calculate the minimum number of operations described above to sort the permutation a in ascending order.

Input

The first line contains a single integer t (1 ≤ t ≤ 2000) — the number of test cases.

The first line of the test case contains a single integer n (3 ≤ n ≤ 50) — the number of elements in the permutation.

The second line of the test case contains n distinct integers from 1 to n — the given permutation a.

Output

For each test case, output a single integer — the minimum number of operations described above to sort the array a in ascending order.

Example

Input

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

Output

1
0
2

Note

In the explanations, a[i, j] defines the subarray of a that starts from the i-th element and ends with the j-th element.

In the first test case of the example, you can select the subarray a[2, 3] and swap the elements in it.

In the second test case of the example, the permutation is already sorted, so you don't need to apply any operations.

In the third test case of the example, you can select the subarray a[3, 5] and reorder the elements in it so a becomes [2, 1, 3, 4, 5], and then select the subarray a[1, 2] and swap the elements in it, so a becomes [1, 2, 3, 4, 5].

### Response

```cpp
#include<iostream>
#include<cstdio>
using namespace std;
int T,n,a[100],ans;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		ans=0;
		scanf("%d",&n);
		for(int k=1;k<=n;k++) scanf("%d",&a[k]);
		for(int i=1;i<=n;i++) if(a[i]!=i) ans=1;
		if(a[1]!=1 && a[n]!=n) ans=2;
		if(a[1]==n && a[n]==1) ans=3;
		printf("%d\n",ans);
	}
	return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occurrences of s into the subarray. We call the power of the subarray the sum of products Ks·Ks·s for every positive integer s. The sum contains only finite number of nonzero summands as the number of different values in the array is indeed finite.

You should calculate the power of t given subarrays.

Input

First line contains two integers n and t (1 ≤ n, t ≤ 200000) — the array length and the number of queries correspondingly.

Second line contains n positive integers ai (1 ≤ ai ≤ 106) — the elements of the array.

Next t lines contain two positive integers l, r (1 ≤ l ≤ r ≤ n) each — the indices of the left and the right ends of the corresponding subarray.

Output

Output t lines, the i-th line of the output should contain single positive integer — the power of the i-th query subarray.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d).

Examples

Input

3 2
1 2 1
1 2
1 3

Output

3
6

Input

8 3
1 1 2 2 1 3 1 1
2 7
1 6
2 7

Output

20
20
20

Note

Consider the following array (see the second sample) and its [2, 7] subarray (elements of the subarray are colored):

<image> Then K1 = 3, K2 = 2, K3 = 1, so the power is equal to 32·1 + 22·2 + 12·3 = 20.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const int P = 131;
int block, n, m, a[N];
long long cnt[N], ans[N];
long long sum;
struct node {
  int l, r, id;
} Q[N];
bool cmp(node &a, struct node &b) {
  if (a.l / block != b.l / block) return a.l < b.l;
  return a.r < b.r;
}
void add(int x) {
  sum -= (long long)cnt[a[x]] * cnt[a[x]] * a[x];
  cnt[a[x]]++;
  sum += (long long)cnt[a[x]] * cnt[a[x]] * a[x];
}
void del(int x) {
  sum -= (long long)cnt[a[x]] * cnt[a[x]] * a[x];
  cnt[a[x]]--;
  sum += (long long)cnt[a[x]] * cnt[a[x]] * a[x];
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &Q[i].l, &Q[i].r);
    Q[i].id = i;
  }
  block = sqrt(m * 2 / 3.0);
  sort(Q + 1, Q + 1 + m, cmp);
  int l = 1, r = 0;
  for (int i = 1; i <= m; i++) {
    while (l < Q[i].l) del(l++);
    while (l > Q[i].l) add(--l);
    while (r < Q[i].r) add(++r);
    while (r > Q[i].r) del(r--);
    ans[Q[i].id] = sum;
  }
  for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

This problem is given in two editions, which differ exclusively in the constraints on the number n.

You are given an array of integers a[1], a[2], ..., a[n]. A block is a sequence of contiguous (consecutive) elements a[l], a[l+1], ..., a[r] (1 ≤ l ≤ r ≤ n). Thus, a block is defined by a pair of indices (l, r).

Find a set of blocks (l_1, r_1), (l_2, r_2), ..., (l_k, r_k) such that:

  * They do not intersect (i.e. they are disjoint). Formally, for each pair of blocks (l_i, r_i) and (l_j, r_j) where i ≠ j either r_i < l_j or r_j < l_i.
  * For each block the sum of its elements is the same. Formally, $$$a[l_1]+a[l_1+1]+...+a[r_1]=a[l_2]+a[l_2+1]+...+a[r_2]= ... = a[l_k]+a[l_k+1]+...+a[r_k].$$$
  * The number of the blocks in the set is maximum. Formally, there does not exist a set of blocks (l_1', r_1'), (l_2', r_2'), ..., (l_{k'}', r_{k'}') satisfying the above two requirements with k' > k.

<image> The picture corresponds to the first example. Blue boxes illustrate blocks.

Write a program to find such a set of blocks.

Input

The first line contains integer n (1 ≤ n ≤ 1500) — the length of the given array. The second line contains the sequence of elements a[1], a[2], ..., a[n] (-10^5 ≤ a_i ≤ 10^5).

Output

In the first line print the integer k (1 ≤ k ≤ n). The following k lines should contain blocks, one per line. In each line print a pair of indices l_i, r_i (1 ≤ l_i ≤ r_i ≤ n) — the bounds of the i-th block. You can print blocks in any order. If there are multiple answers, print any of them.

Examples

Input

7
4 1 2 2 1 5 3

Output

3
7 7
2 3
4 5

Input

11
-5 -4 -3 -2 -1 0 1 2 3 4 5

Output

2
3 4
1 1

Input

4
1 1 1 1

Output

4
4 4
1 1
2 2
3 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n + 1], partial[n + 1];
  partial[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    partial[i] = partial[i - 1] + a[i];
  }
  map<int, vector<pair<int, int>>> block;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= i - 1; j++) {
      int sum = partial[i] - partial[j];
      block[sum].push_back({j + 1, i});
    }
  int mx = 0, mxi = 0;
  for (auto x : block) {
    int ptr = 0, count = 0;
    for (auto i : x.second)
      if (i.first > ptr) {
        count++;
        ptr = i.second;
      }
    if (count > mx) {
      mx = count;
      mxi = x.first;
    }
  }
  int ptr = 0;
  cout << mx << endl;
  for (auto i : block[mxi])
    if (i.first > ptr) {
      cout << i.first << " " << i.second << endl;
      ptr = i.second;
    }
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.

Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.

If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 105) — the number of cities and the number of cellular towers.

The second line contains a sequence of n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.

The third line contains a sequence of m integers b1, b2, ..., bm ( - 109 ≤ bj ≤ 109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.

Output

Print minimal r so that each city will be covered by cellular network.

Examples

Input

3 2
-2 2 4
-3 0

Output

4

Input

5 3
1 5 10 14 17
4 11 15

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e5 + 10;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> v1(n + 2), v2(m + 2);
  for (int i = 1; i <= n; i++) cin >> v1[i];
  for (int i = 1; i <= m; i++) cin >> v2[i];
  v1[0] = v2[0] = -INF * INF;
  v1[n + 1] = v2[m + 1] = INF * INF;
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  n = v1.size();
  m = v2.size();
  int r = 0;
  int ans = 0;
  for (auto &x : v1) {
    while (r < m - 1) {
      if (v2[r] <= x && x <= v2[r + 1]) break;
      r++;
    }
    int tmp = min(abs(x - v2[r]), abs(x - v2[r + 1]));
    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.

At each step he selects one of his guests A, who pairwise introduces all of his friends to each other. After this action any two friends of A become friends. This process is run until all pairs of guests are friends.

Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.

Input

The first line contains two integers n and m (1 ≤ n ≤ 22; <image>) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.

Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n; u ≠ v), which means that people with numbers u and v are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.

Output

In the first line print the minimum number of steps required to make all pairs of guests friends.

In the second line print the ids of guests, who are selected at each step.

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

Examples

Input

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

Output

2
2 3

Input

4 4
1 2
1 3
1 4
3 4

Output

1
1

Note

In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.

In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int f[23][23], n, m, ans1, ans2, maxsta;
bool vis[1 << 23];
void dfs(int x, int sta) {
  vis[sta] = 1;
  if (x >= ans1) return;
  if (clock() >= 0.5 * CLOCKS_PER_SEC) return;
  int flag = 1;
  for (int i = 0; i < n && flag; i++)
    if (f[x][i] != (1 << n) - 1) flag = 0;
  if (flag) {
    ans1 = x, ans2 = sta;
    return;
  } else {
    for (int i = 0; i < n; i++) {
      if (vis[sta | (1 << i)]) continue;
      for (int j = 0; j < n; j++) {
        f[x + 1][j] = ((f[x][i] >> j) & 1 ? (f[x][i] | f[x][j]) : f[x][j]);
      }
      dfs(x + 1, sta | (1 << i));
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) f[0][i] = (1 << i);
  for (int i = 0, x, y; i < m; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    f[0][x] |= (1 << y);
    f[0][y] |= (1 << x);
  }
  ans1 = 100, ans2 = 0;
  clock();
  dfs(0, 0);
  printf("%d\n", ans1);
  for (int i = 0; i < n; i++) {
    if ((ans2 >> i) & 1) {
      printf("%d", i + 1);
      ans1--;
      if (ans1 == 0)
        printf("\n");
      else
        printf(" ");
    }
  }
  return 0;
}

```


### Prompt

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

You are given a tree with N vertices. The vertices are numbered 0 through N-1, and the edges are numbered 1 through N-1. Edge i connects Vertex x_i and y_i, and has a value a_i. You can perform the following operation any number of times:

* Choose a simple path and a non-negative integer x, then for each edge e that belongs to the path, change a_e by executing a_e ← a_e ⊕ x (⊕ denotes XOR).

Your objective is to have a_e = 0 for all edges e. Find the minimum number of operations required to achieve it.

Constraints

* 2 ≤ N ≤ 10^5
* 0 ≤ x_i,y_i ≤ N-1
* 0 ≤ a_i ≤ 15
* The given graph is a tree.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_{N-1} y_{N-1} a_{N-1}

Output

Find the minimum number of operations required to achieve the objective.

Examples

Input

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

Output

3

Input

2
1 0 0

Output

0

### Response

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

using namespace std;

const int Nmax = 1e5 + 5;
int i, dp[1<<15], j, x, y, z, n, m, xr, val[Nmax], cnt[20], ans;
vector<int> v;

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n;
    for(i=1; i<n; ++i)
    {
        cin >> x >> y >> z;
        val[x] ^= z; val[y] ^= z;
    }

    for(i=0; i<n; ++i) cnt[val[i]]++;
    ans = cnt[0];
    for(i=1; i<=15; ++i)
    {
        ans += cnt[i] / 2;
        if(cnt[i] & 1) v.push_back(i);
    }

    m = v.size();
    if(m)
    {
        for(i=0; i<(1<<m); ++i)
        {
            xr = 0;
            for(j=0; j<m; ++j)
                if(i&(1<<j)) xr ^= v[j];

            if(!xr) dp[i] = 1;
                else
                {
                    dp[i] = -1e9;
                    continue;
                }

            for(j=i&(i-1); j; j = i&(j-1))
                dp[i] = max(dp[i], dp[j] + dp[i^j]);
        }
        ans += dp[i-1];
    }

    ans = n - ans;
    cout << ans << '\n';;

    return 0;
}

```


### Prompt

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

Andre has very specific tastes. Recently he started falling in love with arrays.

Andre calls an nonempty array b good, if sum of its elements is divisible by the length of this array. For example, array [2, 3, 1] is good, as sum of its elements — 6 — is divisible by 3, but array [1, 1, 2, 3] isn't good, as 7 isn't divisible by 4.

Andre calls an array a of length n perfect if the following conditions hold:

  * Every nonempty subarray of this array is good.
  * For every i (1 ≤ i ≤ n), 1 ≤ a_i ≤ 100.

Given a positive integer n, output any perfect array of length n. We can show that for the given constraints such an array always exists.

An array c is a subarray of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input

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

The first and only line of every test case contains a single integer n (1 ≤ n ≤ 100).

Output

For every test, output any perfect array of length n on a separate line.

Example

Input

3
1
2
4

Output

24
19 33
7 37 79 49

Note

Array [19, 33] is perfect as all 3 its subarrays: [19], [33], [19, 33], have sums divisible by their lengths, and therefore are good.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d\n", &n);
    for (int a = 0; a < n; a++) {
      printf("%d ", 1);
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

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

Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative.

She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.

A value of an array [a_1, a_2, ..., a_n] is defined as f(f(... f(f(a_1, a_2), a_3), ... a_{n-1}), a_n) (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9). Elements of the array are not guaranteed to be different.

Output

Output n integers, the reordering of the array with maximum value. If there are multiple answers, print any.

Examples

Input

4
4 0 11 6

Output

11 6 4 0

Input

1
13

Output

13

Note

In the first testcase, value of the array [11, 6, 4, 0] is f(f(f(11, 6), 4), 0) = f(f(9, 4), 0) = f(9, 0) = 9.

[11, 4, 0, 6] is also a valid answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ioo = INT_MAX;
long long Loo = LONG_LONG_MAX;
long long power(long long fa, long long n) {
  long long k = 1;
  while (n) {
    if (n % 2) k = (k * fa) % (long long)(1000000000 + 7);
    fa = (fa * fa) % (long long)(1000000000 + 7);
    n /= 2;
  }
  return k;
}
int a[100005];
int cnt[30];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int k = 0; k <= 29; k++) {
      if ((a[i] & (1 << k)) != 0) cnt[k]++;
    }
  }
  int ans = 0, idx = 1;
  for (int i = 1; i <= n; i++) {
    int in = a[i];
    int cur = 0;
    for (int k = 0; k <= 29; k++) {
      if ((in & (1 << k)) != 0 && cnt[k] == 1) cur |= (1 << k);
    }
    if (cur > ans) ans = cur, idx = i;
  }
  cout << a[idx] << " ";
  for (int i = 1; i <= n; i++)
    if (i != idx) cout << a[i] << " ";
  return 0;
}

```


### Prompt

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

There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.

Consider performing the following operation:

* Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.

Find the maximum possible number of times this operation can be performed.

Constraints

* 1 \leq |S| \leq 2\times 10^5
* S_i=`B` or `W`

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum possible number of times the operation can be performed.

Examples

Input

BBW

Output

2

Input

BWBWBW

Output

6

### Response

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

char ch;
long ans, b;

int main() {
    while(cin >> ch) {
        if (ch == 'B') b++;
        else ans += b;
    }
    cout << ans << endl;
    return 0;
}
```


### Prompt

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

You, the mighty Blackout, are standing in the upper-left (0,0) corner of NxM matrix. You must move either right or down each second.

There are K transformers jumping around the matrix in the following way. Each transformer starts jumping from position (x,y), at time t, and jumps to the next position each second. The x-axes grows downwards, and y-axes grows to the right. The order of jumping positions is defined as {(x,y),(x+d,y-d),(x+d,y),(x,y+d)}, and is periodic. Before time t transformer is not in the matrix.

You want to arrive to the bottom-right corner (N-1,M-1), while slaying transformers and losing the least possible amount of energy. When you meet the transformer (or more of them) in the matrix field, you must kill them all, and you lose the sum of the energy amounts required to kill each transformer.

After the transformer is killed, he of course stops jumping, falls into the abyss and leaves the matrix world. Output minimum possible amount of energy wasted.

Input

In the first line, integers N,M (1 ≤ N, M ≤ 500), representing size of the matrix, and K (0 ≤ K ≤ 5*10^5) , the number of jumping transformers.

In next K lines, for each transformer, numbers x, y, d (d ≥ 1), t (0 ≤ t ≤ N+M-2), and e (0 ≤ e ≤ 10^9), representing starting coordinates of transformer, jumping positions distance in pattern described above, time when transformer starts jumping, and energy required to kill it.

It is guaranteed that all 4 of jumping points of the transformers are within matrix coordinates

Output

Print single integer, the minimum possible amount of energy wasted, for Blackout to arrive at bottom-right corner.

Example

Input

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

Output

9

Note

If Blackout takes the path from (0, 0) to (2, 0), and then from (2, 0) to (2, 2) he will need to kill the first and third transformer for a total energy cost of 9. There exists no path with less energy value.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXH = 500;
const int MAXW = 500;
const int MAXGUARD = 500000;
int h, w, nguard;
int gx[MAXGUARD], gy[MAXGUARD], gd[MAXGUARD], gt[MAXGUARD], ge[MAXGUARD];
long long cost[MAXH][MAXW];
vector<pair<int, int>> horsave[MAXH][MAXW];
vector<pair<int, int>> versave[MAXH][MAXW];
long long hordp[MAXW][MAXW], nhordp[MAXW][MAXW];
long long verdp[MAXW][MAXH], nverdp[MAXW][MAXH];
long long chorsave[MAXW], cversave[MAXH];
long long solve() {
  for (int x = (0); x < (h); ++x)
    for (int y = (0); y < (w); ++y) cost[x][y] = 0;
  for (int x = (0); x < (h); ++x)
    for (int y = (0); y < (w); ++y) horsave[x][y].clear();
  for (int x = (0); x < (h); ++x)
    for (int y = (0); y < (w); ++y) versave[x][y].clear();
  for (int i = (0); i < (nguard); ++i) {
    int ax = gx[i], ay = gy[i], at = gt[i];
    int bx = gx[i] + gd[i], by = gy[i] - gd[i], bt = gt[i] + 1;
    int cx = gx[i] + gd[i], cy = gy[i], ct = gt[i] + 2;
    int dx = gx[i], dy = gy[i] + gd[i], dt = gt[i] + 3;
    bool hita = false;
    if ((ax + ay) % 4 == at % 4 && at <= ax + ay) hita = true, at = ax + ay;
    bool hitb = false;
    if ((bx + by) % 4 == bt % 4 && bt <= bx + by) hitb = true, bt = bx + by;
    bool hitc = false;
    if ((cx + cy) % 4 == ct % 4 && ct <= cx + cy) hitc = true, ct = cx + cy;
    bool hitd = false;
    if ((dx + dy) % 4 == dt % 4 && dt <= dx + dy) hitd = true, dt = dx + dy;
    if (hita) cost[ax][ay] += ge[i];
    if (hitb) cost[bx][by] += ge[i];
    if (hitc) {
      cost[cx][cy] += ge[i];
      if (hita) versave[cx][cy].push_back(make_pair(ax, ge[i]));
      if (hitb) horsave[cx][cy].push_back(make_pair(by, ge[i]));
    }
    if (hitd) {
      cost[dx][dy] += ge[i];
      if (hita) horsave[dx][dy].push_back(make_pair(ay, ge[i]));
    }
  }
  for (int x = (0); x < (h); ++x) {
    for (int y = (0); y < (w); ++y) {
      for (int k = (0); k <= (y); ++k) chorsave[k] = 0;
      for (int i = (0); i < (((int)(horsave[x][y]).size())); ++i)
        chorsave[horsave[x][y][i].first] += horsave[x][y][i].second;
      for (int k = y; k > 0; --k) chorsave[k - 1] += chorsave[k];
      for (int k = (0); k <= (x); ++k) cversave[k] = 0;
      for (int i = (0); i < (((int)(versave[x][y]).size())); ++i)
        cversave[versave[x][y][i].first] += versave[x][y][i].second;
      for (int k = x; k > 0; --k) cversave[k - 1] += cversave[k];
      nhordp[y][y] = x == 0 && y == 0 ? cost[x][y] : LLONG_MAX;
      for (int k = (0); k < (x); ++k)
        if (verdp[y][k] != LLONG_MAX)
          nhordp[y][y] =
              min(nhordp[y][y], verdp[y][k] + cost[x][y] - cversave[k]);
      for (int k = (0); k < (y); ++k)
        nhordp[y][k] = nhordp[y - 1][k] == LLONG_MAX
                           ? LLONG_MAX
                           : nhordp[y - 1][k] + cost[x][y] - chorsave[k];
      nverdp[y][x] = x == 0 && y == 0 ? cost[x][y] : LLONG_MAX;
      for (int k = (0); k < (y); ++k)
        if (nhordp[y - 1][k] != LLONG_MAX)
          nverdp[y][x] =
              min(nverdp[y][x], nhordp[y - 1][k] + cost[x][y] - chorsave[k]);
      for (int k = (0); k < (x); ++k)
        nverdp[y][k] = verdp[y][k] == LLONG_MAX
                           ? LLONG_MAX
                           : verdp[y][k] + cost[x][y] - cversave[k];
    }
    for (int y = (0); y < (w); ++y)
      for (int k = (0); k <= (y); ++k) hordp[y][k] = nhordp[y][k];
    for (int y = (0); y < (w); ++y)
      for (int k = (0); k <= (x); ++k) verdp[y][k] = nverdp[y][k];
  }
  long long ret = LLONG_MAX;
  for (int k = (0); k < (w); ++k) ret = min(ret, hordp[w - 1][k]);
  for (int k = (0); k < (h); ++k) ret = min(ret, verdp[w - 1][k]);
  return ret;
}
void run() {
  scanf("%d%d%d", &h, &w, &nguard);
  for (int i = (0); i < (nguard); ++i)
    scanf("%d%d%d%d%d", &gx[i], &gy[i], &gd[i], &gt[i], &ge[i]);
  printf("%lld\n", solve());
}
int main() {
  run();
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Snuke loves colorful balls. He has a total of N×K balls, K in each of his favorite N colors. The colors are numbered 1 through N.

He will arrange all of the balls in a row from left to right, in arbitrary order. Then, for each of the N colors, he will paint the leftmost ball of that color into color 0, a color different from any of the N original colors.

After painting, how many sequences of the colors of the balls are possible? Find this number modulo 10^9+7.

Constraints

* 1≤N,K≤2,000

Input

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

N K

Output

Print the number of the possible sequences of the colors of the balls after painting, modulo 10^9+7.

Examples

Input

2 2

Output

4

Input

3 1

Output

1

Input

2 3

Output

14

Input

2000 2000

Output

546381702

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+7,p=1e9+7;
int n,k,dp[N][N]; long long fac[N*N],ifac[N*N];
inline int pows(long long u,int v){
	long long ans=1; while(v>0) {if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;} return ans;
}
inline long long getans(int a,int b){
	return fac[a]*ifac[b]%p*ifac[a-b]%p;
}
int main(){
	cin>>n>>k,fac[0]=ifac[0]=1;
	for(int i=1;i<=n*k;i++) fac[i]=fac[i-1]*i%p,ifac[i]=pows(fac[i],p-2); dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++){
			if(j>0) dp[i][j]=(dp[i][j-1]*getans(n*k-(k-1)*(j-1)-i-1,k-2)+dp[i-1][j])%p;
			else dp[i][j]=dp[i-1][j];
		}
	if(k==1) cout<<1<<endl; else cout<<dp[n][n]*fac[n]%p<<endl;
    return 0;
}
```


### Prompt

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

You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.

According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:

* All even numbers written on the document are divisible by 3 or 5.

If the immigrant should be allowed entry according to the regulation, output `APPROVED`; otherwise, print `DENIED`.

Constraints

* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

If the immigrant should be allowed entry according to the regulation, print `APPROVED`; otherwise, print `DENIED`.

Examples

Input

5
6 7 9 10 31

Output

APPROVED

Input

3
28 27 24

Output

DENIED

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]%2==0 && (A[i]%3!=0 && A[i]%5!=0)){
      cout<<"DENIED";
      return 0;
    }
  }
  cout<<"APPROVED";
  return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct.

Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information.

Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out.

Input

The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format.

Output

The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations.

Examples

Input

4
XOOO
XXOO
OOOO
XXXX
XOOO
XOOO
XOXO
XOXX

Output

Yes

Input

2
XX
OO
XO
OX

Output

No

Note

In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > matrix1, matrix2;
vector<vector<bool> > copy(vector<vector<bool> > matrix) {
  int N = matrix.size();
  vector<vector<bool> > ans(N);
  for (int i = 0; i < N; i++) {
    ans[i].resize(N);
    for (int j = 0; j < N; j++) ans[i][j] = matrix[i][j];
  }
  return ans;
}
vector<vector<bool> > flip_vertical(vector<vector<bool> > matrix) {
  int N = matrix.size();
  vector<vector<bool> > ans(N);
  for (int i = 0; i < N; i++) {
    ans[i].resize(N);
    for (int j = 0; j < N; j++) ans[i][j] = matrix[i][N - 1 - j];
  }
  return ans;
}
vector<vector<bool> > flip_horizontal(vector<vector<bool> > matrix) {
  int N = matrix.size();
  vector<vector<bool> > ans(N);
  for (int i = 0; i < N; i++) {
    ans[i].resize(N);
    for (int j = 0; j < N; j++) ans[i][j] = matrix[N - 1 - i][j];
  }
  return ans;
}
vector<vector<bool> > rotate_90(vector<vector<bool> > matrix) {
  int N = matrix.size();
  vector<vector<bool> > ans(N);
  for (int i = 0; i < N; i++) {
    ans[i].resize(N);
    for (int j = 0; j < N; j++) ans[i][j] = matrix[N - 1 - j][i];
  }
  return ans;
}
vector<vector<bool> > rotate_180(vector<vector<bool> > matrix) {
  int N = matrix.size();
  vector<vector<bool> > ans(N);
  for (int i = 0; i < N; i++) {
    ans[i].resize(N);
    for (int j = 0; j < N; j++) ans[i][j] = matrix[j][i];
  }
  return ans;
}
vector<vector<bool> > rotate_270(vector<vector<bool> > matrix) {
  int N = matrix.size();
  vector<vector<bool> > ans(N);
  for (int i = 0; i < N; i++) {
    ans[i].resize(N);
    for (int j = 0; j < N; j++) ans[i][j] = matrix[j][N - 1 - i];
  }
  return ans;
}
bool isEqual(vector<vector<bool> > matrix1, vector<vector<bool> > matrix2) {
  for (int i = 0; i < matrix1.size(); i++)
    for (int j = 0; j < matrix1[i].size(); j++)
      if (matrix1[i][j] != matrix2[i][j]) return false;
  return true;
}
void display(vector<vector<bool> > matrix) {
  int N = matrix.size();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) cout << matrix[i][j] << " ";
    cout << "\n";
  }
}
bool checkEquality() {
  vector<vector<bool> > tmp1, tmp2;
  for (int i = 0; i < 6; i++)
    for (int j = 0; j < 6; j++) {
      switch (i) {
        case 0:
          tmp1 = copy(matrix1);
          break;
        case 1:
          tmp1 = flip_vertical(matrix1);
          break;
        case 2:
          tmp1 = flip_horizontal(matrix1);
          break;
        case 3:
          tmp1 = rotate_90(matrix1);
          break;
        case 4:
          tmp1 = rotate_180(matrix1);
          break;
        case 5:
          tmp1 = rotate_270(matrix1);
          break;
      }
      switch (j) {
        case 0:
          tmp2 = copy(matrix2);
          break;
        case 1:
          tmp2 = flip_vertical(matrix2);
          break;
        case 2:
          tmp2 = flip_horizontal(matrix2);
          break;
        case 3:
          tmp2 = rotate_90(matrix2);
          break;
        case 4:
          tmp2 = rotate_180(matrix2);
          break;
        case 5:
          tmp2 = rotate_270(matrix2);
          break;
      }
      if (isEqual(tmp1, tmp2)) return true;
    }
  return false;
}
int main() {
  int N;
  cin >> N;
  matrix1.resize(N);
  matrix2.resize(N);
  string str;
  cin.ignore();
  for (int i = 0; i < N; i++) {
    cin >> str;
    matrix1[i].assign(N, false);
    for (int j = 0; j < N; j++)
      if (str[j] == 'X') matrix1[i][j] = true;
  }
  for (int i = 0; i < N; i++) {
    cin >> str;
    matrix2[i].assign(N, false);
    for (int j = 0; j < N; j++)
      if (str[j] == 'X') matrix2[i][j] = true;
  }
  if (checkEquality())
    cout << "Yes";
  else
    cout << "No";
  cout << "\n";
  return 0;
}

```


### Prompt

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

A string t is called an anagram of the string s, if it is possible to rearrange letters in t so that it is identical to the string s. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not.

The string t is called a substring of the string s if it can be read starting from some position in the string s. For example, the string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".

You are given a string s, consisting of lowercase Latin letters and characters "?". You are also given a string p, consisting of lowercase Latin letters only. Let's assume that a string is good if you can obtain an anagram of the string p from it, replacing the "?" characters by Latin letters. Each "?" can be replaced by exactly one character of the Latin alphabet. For example, if the string p = «aba», then the string "a??" is good, and the string «?bc» is not.

Your task is to find the number of good substrings of the string s (identical substrings must be counted in the answer several times).

Input

The first line is non-empty string s, consisting of no more than 105 lowercase Latin letters and characters "?". The second line is non-empty string p, consisting of no more than 105 lowercase Latin letters. Please note that the length of the string p can exceed the length of the string s.

Output

Print the single number representing the number of good substrings of string s.

Two substrings are considered different in their positions of occurrence are different. Thus, if some string occurs several times, then it should be counted the same number of times.

Examples

Input

bb??x???
aab

Output

2

Input

ab?c
acb

Output

2

Note

Consider the first sample test. Here the string s has two good substrings: "b??" (after we replace the question marks we get "baa"), "???" (after we replace the question marks we get "baa").

Let's consider the second sample test. Here the string s has two good substrings: "ab?" ("?" can be replaced by "c"), "b?c" ("?" can be replaced by "a").

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, a[111111][27], i, j, ans, l, m, b[26];
string s, t;
int main() {
  cin >> s >> t;
  for (i = 0; i < t.size(); i++) b[t[i] - 97]++;
  for (i = 0; i < s.size(); i++) {
    if (i)
      for (j = 0; j < 27; j++) a[i][j] = a[i - 1][j];
    if (s[i] == '?')
      a[i][26]++;
    else
      a[i][s[i] - 97]++;
  }
  long long sss = 0;
  for (j = 0; j < 26; j++) {
    if (a[t.size() - 1][j] > b[j])
      break;
    else
      sss += b[j] - a[t.size() - 1][j];
  }
  if (j == 26 && sss <= a[t.size() - 1][26]) ans++;
  l = 1;
  for (i = t.size(); i < s.size(); i++, l++) {
    sss = 0;
    for (j = 0; j < 26; j++) {
      if (a[i][j] - a[l - 1][j] > b[j])
        break;
      else
        sss += b[j] - a[i][j] + a[l - 1][j];
    }
    if (j == 26 && sss <= a[i][26] - a[l - 1][26]) ans++;
  }
  cout << ans;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given integers N and M.

Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

Constraints

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

Input

Input is given from Standard Input in the following format:

N M

Output

Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

Examples

Input

3 14

Output

2

Input

10 123

Output

3

Input

100000 1000000000

Output

10000

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,ans;
  cin>>n>>m;
  for(int i=m/n;i>=0;i--){
    if(m%i==0){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal.

Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions simultaneously:

* Add 2 to a_i.
* Add 1 to b_j.

Constraints

* 1 ≤ N ≤ 10 000
* 0 ≤ a_i,b_i ≤ 10^9 (1 ≤ i ≤ N)
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 .. a_N
b_1 b_2 .. b_N

Output

If we can repeat the operation zero or more times so that the sequences a and b become equal, print `Yes`; otherwise, print `No`.

Examples

Input

3
1 2 3
5 2 2

Output

Yes

Input

5
3 1 4 1 5
2 7 1 8 2

Output

No

Input

5
2 7 1 8 2
3 1 4 1 5

Output

No

### Response

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

using namespace std;

#define N 12000

int n,a[N],b[N];
long long cnt;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	for (int i=1;i<=n;i++){
		if (a[i]<b[i]) cnt+=(b[i]-a[i]+1)/2,a[i]+=(b[i]-a[i]+1)/2*2;
		if (a[i]>b[i]) cnt-=a[i]-b[i];
	}
	if (cnt>=0) puts("Yes");
	else puts("No");

	return 0;
}

```


### Prompt

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

Vasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one — a_2, and so on. The book at the bottom of the stack has number a_n. All numbers are distinct.

Vasya wants to move all the books to his backpack in n steps. During i-th step he wants to move the book number b_i into his backpack. If the book with number b_i is in the stack, he takes this book and all the books above the book b_i, and puts them into the backpack; otherwise he does nothing and begins the next step. For example, if books are arranged in the order [1, 2, 3] (book 1 is the topmost), and Vasya moves the books in the order [2, 1, 3], then during the first step he will move two books (1 and 2), during the second step he will do nothing (since book 1 is already in the backpack), and during the third step — one book (the book number 3). Note that b_1, b_2, ..., b_n are distinct.

Help Vasya! Tell him the number of books he will put into his backpack during each step.

Input

The first line contains one integer n~(1 ≤ n ≤ 2 ⋅ 10^5) — the number of books in the stack.

The second line contains n integers a_1, a_2, ..., a_n~(1 ≤ a_i ≤ n) denoting the stack of books.

The third line contains n integers b_1, b_2, ..., b_n~(1 ≤ b_i ≤ n) denoting the steps Vasya is going to perform.

All numbers a_1 ... a_n are distinct, the same goes for b_1 ... b_n.

Output

Print n integers. The i-th of them should be equal to the number of books Vasya moves to his backpack during the i-th step.

Examples

Input

3
1 2 3
2 1 3

Output

2 0 1

Input

5
3 1 4 2 5
4 5 1 3 2

Output

3 2 0 0 0

Input

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

Output

1 1 2 0 1 1

Note

The first example is described in the statement.

In the second example, during the first step Vasya will move the books [3, 1, 4]. After that only books 2 and 5 remain in the stack (2 is above 5). During the second step Vasya will take the books 2 and 5. After that the stack becomes empty, so during next steps Vasya won't move any books.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long ind[200001], arr[200001];
int main() {
  ios::sync_with_stdio(false);
  long long i, j, k, n, l = 1, a;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    ind[arr[i]] = i + 1;
  }
  for (i = 0; i < n; i++) {
    cin >> a;
    if (ind[a] >= l) {
      cout << ind[a] - l + 1 << " ";
      l = ind[a] + 1;
    } else
      cout << 0 << " ";
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:

    ABCDEFGHIJKLM
    NOPQRSTUVWXYZ

We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.

A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).

You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).

Input

The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.

Output

Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".

Examples

Input

ABCDEFGHIJKLMNOPQRSGTUVWXYZ

Output

YXWVUTGHIJKLM
ZABCDEFSRQPON

Input

BUVTYZFQSNRIWOXXGJLKACPEMDH

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int i, j, x, y, c, l, cnt[26];
string s, str;
char ans[13][2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(cnt, 0, sizeof(cnt));
  cin >> s;
  for (i = 0; i < 27; i++) cnt[s[i] - 'A']++;
  x = y = -1;
  for (i = 0; i < 27; i++) {
    if (cnt[s[i] - 'A'] > 1) {
      if (x == -1)
        x = i;
      else
        y = i;
    }
  }
  if (y - x == 1) {
    cout << "Impossible\n";
    return 0;
  }
  c = (y - x - 1) / 2;
  if ((y - x - 1) % 2 == 0) {
    j = x + 1;
    for (i = 12 - c + 1; i <= 12; i++) {
      ans[i][0] = s[j];
      j++;
    }
    for (i = 12; i >= 12 - c + 1; i--) {
      ans[i][1] = s[j];
      j++;
    }
    ans[i][0] = s[j];
    str = "";
    if (y + 1 < 27) str += (s.substr(y + 1));
    if (x > 0) str += s.substr(0, x);
    l = str.length();
    i--;
    j = 0;
    while (i >= 0 && j < l) {
      ans[i][0] = str[j];
      j++;
      i--;
    }
    i = 0;
    while (j < l) {
      ans[i][1] = str[j];
      j++;
      i++;
    }
  } else {
    j = x + 1;
    for (i = 12 - c + 1; i <= 12; i++) {
      ans[i][0] = s[j];
      j++;
    }
    for (i = 12; i >= 12 - c + 1; i--) {
      ans[i][1] = s[j];
      j++;
    }
    ans[i][1] = s[j];
    ans[i][0] = s[y];
    str = "";
    if (y + 1 < 27) str += s.substr(y + 1);
    if (x > 0) str += s.substr(0, x);
    l = str.length();
    i--;
    j = 0;
    while (i >= 0 && j < l) {
      ans[i][0] = str[j];
      j++;
      i--;
    }
    i = 0;
    while (j < l) {
      ans[i][1] = str[j];
      j++;
      i++;
    }
  }
  for (i = 0; i < 2; i++) {
    for (j = 0; j < 13; j++) cout << ans[j][i];
    cout << "\n";
  }
  return 0;
}

```


### Prompt

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

You are given a rectangular matrix of size n × m consisting of integers from 1 to 2 ⋅ 10^5.

In one move, you can:

  * choose any element of the matrix and change its value to any integer between 1 and n ⋅ m, inclusive;
  * take any column and shift it one cell up cyclically (see the example of such cyclic shift below).

A cyclic shift is an operation such that you choose some j (1 ≤ j ≤ m) and set a_{1, j} := a_{2, j}, a_{2, j} := a_{3, j}, ..., a_{n, j} := a_{1, j} simultaneously.

<image> Example of cyclic shift of the first column

You want to perform the minimum number of moves to make this matrix look like this:

<image>

In other words, the goal is to obtain the matrix, where a_{1, 1} = 1, a_{1, 2} = 2, ..., a_{1, m} = m, a_{2, 1} = m + 1, a_{2, 2} = m + 2, ..., a_{n, m} = n ⋅ m (i.e. a_{i, j} = (i - 1) ⋅ m + j) with the minimum number of moves performed.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5, n ⋅ m ≤ 2 ⋅ 10^5) — the size of the matrix.

The next n lines contain m integers each. The number at the line i and position j is a_{i, j} (1 ≤ a_{i, j} ≤ 2 ⋅ 10^5).

Output

Print one integer — the minimum number of moves required to obtain the matrix, where a_{1, 1} = 1, a_{1, 2} = 2, ..., a_{1, m} = m, a_{2, 1} = m + 1, a_{2, 2} = m + 2, ..., a_{n, m} = n ⋅ m (a_{i, j} = (i - 1)m + j).

Examples

Input

3 3
3 2 1
1 2 3
4 5 6

Output

6

Input

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

Output

0

Input

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

Output

2

Note

In the first example, you can set a_{1, 1} := 7, a_{1, 2} := 8 and a_{1, 3} := 9 then shift the first, the second and the third columns cyclically, so the answer is 6. It can be shown that you cannot achieve a better answer.

In the second example, the matrix is already good so the answer is 0.

In the third example, it is enough to shift the second column cyclically twice to obtain a good matrix, so the answer is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<long long> > cost(m, vector<long long>(n, n));
  for (int i = (0); i < (m); ++i)
    for (int j = (0); j < (n); ++j) cost[i][j] += j;
  vector<vector<long long> > mat(n, vector<long long>(m));
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) {
      cin >> mat[i][j];
    }
  for (int j = (0); j < (m); ++j) {
    for (int i = (0); i < (n); ++i) {
      int val = mat[i][j];
      val -= j + 1;
      if (val % m == 0) {
        int k = val / m;
        if (k < n) {
          int shft = 0;
          if (k <= i)
            shft = i - k;
          else
            shft = i + n - k;
          cost[j][shft]--;
        }
      }
    }
  }
  vector<long long> ans(m, n);
  for (int j = (0); j < (m); ++j) {
    int tot = n;
    for (int i = (0); i < (n); ++i)
      tot = ((tot) < (cost[j][i]) ? (tot) : (cost[j][i]));
    ans[j] = ((ans[j]) < (tot) ? (ans[j]) : (tot));
  }
  cout << accumulate(ans.begin(), ans.end(), 0LL) << endl;
}

```


### Prompt

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

The problem set at CODE FESTIVAL 20XX Finals consists of N problems.

The score allocated to the i-th (1≦i≦N) problem is i points.

Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve.

As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.

Determine the set of problems that should be solved.

Constraints

* 1≦N≦10^7

Input

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

N

Output

Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line.

If there exists more than one such set, any of them will be accepted.

Examples

Input

4

Output

1
3

Input

7

Output

1
2
4

Input

1

Output

1

### Response

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

int main(){
	int N;
	cin >> N;
	int count=1;
	int sum=1;
	while(sum<N){
		count++;
		sum+=count;
	}
	if(sum==N){
		for(int i=1;i<=count;i++){
			cout<<i<<endl;
		}
	}
	else{
		int dif=sum-N;
		for(int i=1;i<=count;i++){
			if(i!=dif){
				cout<<i<<endl;
			}
		}
	}
	return 0;
}

```


### Prompt

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

For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence).

You are given two positive integers n and m. Let S be the set of all sequences of length n consisting of numbers from 1 to m. Compute the sum f(a) over all a in S modulo 109 + 7.

Input

The only line contains two integers n and m (1 ≤ n, m ≤ 106) — the number of elements in arrays and the upper bound for elements.

Output

Print the only integer c — the desired sum modulo 109 + 7.

Examples

Input

1 3

Output

6

Input

2 2

Output

14

Input

3 3

Output

174

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1123456;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long potencia(long long m, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    return potencia(m * m % MOD, n / 2);
  }
  return (potencia(m * m % MOD, n / 2) * m) % MOD;
}
int main() {
  long long n, m;
  scanf("%I64d %I64d", &n, &m);
  long long ans = 0;
  if (m == 1) {
    printf("%I64d", n + 1);
    return 0;
  }
  ans += potencia(m, n) % MOD;
  long long aux = (m * potencia(m - 1, n - 1)) % MOD;
  ans = (ans + aux) % MOD;
  for (long long s = 1; s < n; s++) {
    aux *= m;
    aux %= MOD;
    aux *= n - s + 1;
    aux %= MOD;
    aux *= potencia(s, MOD - 2);
    aux %= MOD;
    aux *= potencia(m - 1, MOD - 2);
    aux %= MOD;
    ans = (ans + aux) % MOD;
  }
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

This problem is same as the previous one, but has larger constraints.

Aki is playing a new video game. In the video game, he will control Neko, the giant cat, to fly between planets in the Catniverse.

There are n planets in the Catniverse, numbered from 1 to n. At the beginning of the game, Aki chooses the planet where Neko is initially located. Then Aki performs k - 1 moves, where in each move Neko is moved from the current planet x to some other planet y such that:

  * Planet y is not visited yet.
  * 1 ≤ y ≤ x + m (where m is a fixed constant given in the input)

This way, Neko will visit exactly k different planets. Two ways of visiting planets are called different if there is some index i such that, the i-th planet visited in the first way is different from the i-th planet visited in the second way.

What is the total number of ways to visit k planets this way? Since the answer can be quite large, print it modulo 10^9 + 7.

Input

The only line contains three integers n, k and m (1 ≤ n ≤ 10^9, 1 ≤ k ≤ min(n, 12), 1 ≤ m ≤ 4) — the number of planets in the Catniverse, the number of planets Neko needs to visit and the said constant m.

Output

Print exactly one integer — the number of different ways Neko can visit exactly k planets. Since the answer can be quite large, print it modulo 10^9 + 7.

Examples

Input

3 3 1

Output

4

Input

4 2 1

Output

9

Input

5 5 4

Output

120

Input

100 1 2

Output

100

Note

In the first example, there are 4 ways Neko can visit all the planets:

  * 1 → 2 → 3
  * 2 → 3 → 1
  * 3 → 1 → 2
  * 3 → 2 → 1

In the second example, there are 9 ways Neko can visit exactly 2 planets:

  * 1 → 2
  * 2 → 1
  * 2 → 3
  * 3 → 1
  * 3 → 2
  * 3 → 4
  * 4 → 1
  * 4 → 2
  * 4 → 3

In the third example, with m = 4, Neko can visit all the planets in any order, so there are 5! = 120 ways Neko can visit all the planets.

In the fourth example, Neko only visit exactly 1 planet (which is also the planet he initially located), and there are 100 ways to choose the starting planet for Neko.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int k;
long long int dp[14][1 << 4];
long long int tmp[14][1 << 14];
long long int bt[208][208];
int mxt;
inline int id(int a, int b) {
  mxt = max(mxt, (a << m) + b + 1);
  return (a << m) + b;
}
long long int mat[208][208];
long long int ret[208][208];
int main() {
  cin >> n >> k >> m;
  for (int i2 = n; i2 >= n; i2--) {
    int cnt = 0;
    for (int i = 0; i <= k; i++) {
      for (int j = 0; j < (1 << m); j++) {
        int ava = 0;
        for (int k = 0; k < m; k++) {
          if ((j >> k) & 1) {
            ava++;
          }
        }
        ava++;
        int wa = ((j << 1) & ((1 << m) - 1));
        bt[id(i, wa)][id(i, j)] = 1;
        wa++;
        if (i + 1 <= k) {
          bt[id(i + 1, wa)][id(i, j)] = ava;
        }
      }
    }
  }
  for (int i = 0; i < mxt; i++) mat[i][i] = 1;
  int N = n;
  n = mxt;
  while (N) {
    if ((N & 1LL)) {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) ret[i][j] = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          for (int k = 0; k < n; k++) {
            ret[i][j] += mat[i][k] * bt[k][j];
            if (ret[i][j] >= 1000000007LL * 1000000007LL)
              ret[i][j] -= 1000000007LL * 1000000007LL;
          }
        }
      }
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
          mat[i][j] = ret[i][j];
          if (mat[i][j] >= 1000000007LL) mat[i][j] %= 1000000007LL;
        }
    }
    N >>= 1LL;
    if (N == 0) break;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) ret[i][j] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          ret[i][j] += bt[i][k] * bt[k][j];
          if (ret[i][j] >= 1000000007LL * 1000000007LL)
            ret[i][j] -= 1000000007LL * 1000000007LL;
        }
      }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        bt[i][j] = ret[i][j];
        if (bt[i][j] >= 1000000007LL) bt[i][j] %= 1000000007LL;
      }
  }
  long long int ans = 0;
  for (int j = 0; j < (1 << m); j++) {
    ans += mat[id(k, j)][0];
    if (ans >= 1000000007LL * 1000000007LL) ans -= 1000000007LL * 1000000007LL;
  }
  ans %= 1000000007LL;
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x = 0. Mezo starts sending n commands to Zoma. There are two possible commands:

  * 'L' (Left) sets the position x: =x - 1;
  * 'R' (Right) sets the position x: =x + 1.

Unfortunately, Mezo's controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position x doesn't change and Mezo simply proceeds to the next command.

For example, if Mezo sends commands "LRLR", then here are some possible outcomes (underlined commands are sent successfully):

  * "LRLR" — Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position 0;
  * "LRLR" — Zoma recieves no commands, doesn't move at all and ends up at position 0 as well;
  * "LRLR" — Zoma moves to the left, then to the left again and ends up in position -2.

Mezo doesn't know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.

Input

The first line contains n (1 ≤ n ≤ 10^5) — the number of commands Mezo sends.

The second line contains a string s of n commands, each either 'L' (Left) or 'R' (Right).

Output

Print one integer — the number of different positions Zoma may end up at.

Example

Input

4
LRLR

Output

5

Note

In the example, Zoma may end up anywhere between -2 and 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  map<char, int> arr;
  for (int i = 0; i < s.size(); i++) {
    arr[s[i]]++;
  }
  int count = arr['L'] + arr['R'] + 1;
  cout << count << endl;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

This problem is same as the previous one, but has larger constraints.

It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.

At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates (x_i, y_i). Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.

Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

Input

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of electric poles.

Each of the following n lines contains two integers x_i, y_i (-10^4 ≤ x_i, y_i ≤ 10^4) — the coordinates of the poles.

It is guaranteed that all of these n points are distinct.

Output

Print a single integer — the number of pairs of wires that are intersecting.

Examples

Input

4
0 0
1 1
0 3
1 2

Output

14

Input

4
0 0
0 2
0 4
2 0

Output

6

Input

3
-1 -1
1 0
3 1

Output

0

Note

In the first example:

<image>

In the second example:

<image>

Note that the three poles (0, 0), (0, 2) and (0, 4) are connected by a single wire.

In the third example:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long mabs(long long a) { return a < 0 ? -a : a; }
struct Fraction {
  long long numerator;
  long long denominator;
  Fraction() {}
  Fraction(long long numerator, long long denominator)
      : numerator(numerator), denominator(denominator) {}
  Fraction operator+(const Fraction &rhs) const {
    long long n = numerator * rhs.denominator + rhs.numerator * denominator;
    long long d = denominator * rhs.denominator;
    auto ele = Fraction(n, d);
    ele.reduce();
    return ele;
  }
  Fraction operator-(const Fraction &rhs) const {
    long long n = numerator * rhs.denominator - rhs.numerator * denominator;
    long long d = denominator * rhs.denominator;
    auto ele = Fraction(n, d);
    ele.reduce();
    return ele;
  }
  Fraction operator*(const Fraction &rhs) const {
    auto ele =
        Fraction(numerator * rhs.numerator, denominator * rhs.denominator);
    ele.reduce();
    return ele;
  }
  bool operator==(const Fraction &rhs) const {
    return denominator == rhs.denominator && numerator == rhs.numerator;
  }
  bool operator!=(const Fraction &rhs) const { return !(rhs == *this); }
  bool operator<(const Fraction &rhs) const {
    if (denominator != rhs.denominator) return denominator < rhs.denominator;
    return numerator < rhs.numerator;
  }
  bool operator>(const Fraction &rhs) const { return rhs < *this; }
  bool operator<=(const Fraction &rhs) const { return !(rhs < *this); }
  bool operator>=(const Fraction &rhs) const { return !(*this < rhs); }
  void reduce() {
    long long num = gcd(mabs(denominator), mabs(numerator));
    if (numerator <= 0 && denominator >= 0) {
      numerator *= -1;
      denominator *= -1;
    }
    if (numerator <= 0 && denominator <= 0) {
      numerator *= -1;
      denominator *= -1;
    }
    denominator /= num;
    numerator /= num;
  }
  friend std::ostream &operator<<(std::ostream &os, const Fraction &fraction) {
    os << "denominator: " << fraction.denominator
       << " numerator: " << fraction.numerator;
    return os;
  }
};
long long cn2(long long n) { return n * (n - 1) / 2; }
const int N = (int)1e3 + 50;
long long x[N];
long long y[N];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    map<Fraction, int> mp;
    set<pair<Fraction, Fraction> > st;
    for (int i = 0; i < n; i++) {
      scanf("%lld%lld", &x[i], &y[i]);
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        Fraction k(y[j] - y[i], x[j] - x[i]);
        Fraction b;
        if (k.denominator == 0) {
          k.numerator = 1;
          b = Fraction(x[i], 1);
        } else {
          b = Fraction(y[i], 1) - k * Fraction(x[i], 1);
        }
        k.reduce();
        b.reduce();
        st.insert(pair<Fraction, Fraction>(k, b));
      }
    }
    for (auto p : st) {
      mp[p.first]++;
    }
    long long res = cn2(st.size());
    for (auto &p : mp) {
      if (p.second >= 2) {
        res -= cn2(p.second);
      }
    }
    printf("%lld\n", res);
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Kode Festival is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for "hardness".)

This year, 2^N stones participated. The hardness of the i-th stone is A_i.

In the contest, stones are thrown at each other in a knockout tournament.

When two stones with hardness X and Y are thrown at each other, the following will happen:

* When X > Y: The stone with hardness Y will be destroyed and eliminated. The hardness of the stone with hardness X will become X-Y.

* When X = Y: One of the stones will be destroyed and eliminated. The hardness of the other stone will remain the same.

* When X < Y: The stone with hardness X will be destroyed and eliminated. The hardness of the stone with hardness Y will become Y-X.

The 2^N stones will fight in a knockout tournament as follows:

1. The following pairs will fight: (the 1-st stone versus the 2-nd stone), (the 3-rd stone versus the 4-th stone), ...

2. The following pairs will fight: (the winner of (1-st versus 2-nd) versus the winner of (3-rd versus 4-th)), (the winner of (5-th versus 6-th) versus the winner of (7-th versus 8-th)), ...

3. And so forth, until there is only one stone remaining.

Determine the eventual hardness of the last stone remaining.

Constraints

* 1 \leq N \leq 18
* 1 \leq A_i \leq 10^9
* A_i is an integer.

Input

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

N
A_1
A_2
:
A_{2^N}

Output

Print the eventual hardness of the last stone remaining.

Examples

Input

2
1
3
10
19

Output

7

Input

3
1
3
2
4
6
8
100
104

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    cin >> n;
    vi a(1 << n);
    rep(i, 1 << n) cin >> a[i];

    while (a.size() > 1) {
        vi b;
        for (int i = 0; i < a.size(); i += 2) {
            if (a[i] == a[i + 1]) {
                b.emplace_back(a[i]);
            } else {
                b.emplace_back(abs(a[i] - a[i + 1]));
            }
        }
        a = b;
    }

    cout << a[0] << endl;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Alice guesses the strings that Bob made for her.

At first, Bob came up with the secret string a consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers Alice the string b so that she can guess the string a.

Bob builds b from a as follows: he writes all the substrings of length 2 of the string a in the order from left to right, and then joins them in the same order into the string b.

For example, if Bob came up with the string a="abac", then all the substrings of length 2 of the string a are: "ab", "ba", "ac". Therefore, the string b="abbaac".

You are given the string b. Help Alice to guess the string a that Bob came up with. It is guaranteed that b was built according to the algorithm given above. It can be proved that the answer to the problem is unique.

Input

The first line contains a single positive integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then t test cases follow.

Each test case consists of one line in which the string b is written, consisting of lowercase English letters (2 ≤ |b| ≤ 100) — the string Bob came up with, where |b| is the length of the string b. It is guaranteed that b was built according to the algorithm given above.

Output

Output t answers to test cases. Each answer is the secret string a, consisting of lowercase English letters, that Bob came up with.

Example

Input

4
abbaac
ac
bccddaaf
zzzzzzzzzz

Output

abac
ac
bcdaf
zzzzzz

Note

The first test case is explained in the statement.

In the second test case, Bob came up with the string a="ac", the string a has a length 2, so the string b is equal to the string a.

In the third test case, Bob came up with the string a="bcdaf", substrings of length 2 of string a are: "bc", "cd", "da", "af", so the string b="bccddaaf".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string b;
    cin >> b;
    string a = b.substr(0, 2);
    for (int i = 2; i < b.length(); i += 2) {
      string s = b.substr(i, 2);
      a += s[1];
    }
    cout << a << endl;
  }
}

```


### Prompt

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

A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.

A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an.

Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum.

A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k.

Input

The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence.

The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n).

Output

Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence.

Examples

Input

4
1 2 1 2

Output

4

Input

10
1 1 2 2 2 1 1 2 2 1

Output

9

Note

In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4.

In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.

### Response

```cpp
#include <bits/stdc++.h>
int n;
int a[2005];
int ones[2005];
int twos[2005];
int dp[2005][2005][2];
int LMSL[2005][2005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  ones[0] = 0;
  for (int i = 1; i <= n; ++i) ones[i] = ones[i - 1] + (a[i] == 1);
  twos[n + 1] = 0;
  for (int i = n; i >= 1; --i) twos[i] = twos[i + 1] + (a[i] == 2);
  for (int l = 1; l <= n; ++l) {
    dp[l][l][1] = (a[l] == 2);
    dp[l][l][0] = (a[l] == 1);
    for (int r = l + 1; r <= n; ++r) {
      dp[l][r][1] = dp[l][r - 1][1] + (a[r] == 2);
      dp[l][r][0] = std::max(dp[l][r - 1][0], dp[l][r - 1][1]) + (a[r] == 1);
    }
  }
  int ans = 0;
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      LMSL[l][r] = std::max(dp[l][r][0], dp[l][r][1]);
      ans = std::max(ans, LMSL[l][r] + ones[l - 1] + twos[r + 1]);
    }
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Arkady the air traffic controller is now working with n planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The i-th plane, small enough to be represented by a point, currently has a coordinate of xi and is moving with speed vi. It's guaranteed that xi·vi < 0, i.e., all planes are moving towards the station.

Occasionally, the planes are affected by winds. With a wind of speed vwind (not necessarily positive or integral), the speed of the i-th plane becomes vi + vwind.

According to weather report, the current wind has a steady speed falling inside the range [ - w, w] (inclusive), but the exact value cannot be measured accurately since this value is rather small — smaller than the absolute value of speed of any plane.

Each plane should contact Arkady at the exact moment it passes above his station. And you are to help Arkady count the number of pairs of planes (i, j) (i < j) there are such that there is a possible value of wind speed, under which planes i and j contact Arkady at the same moment. This value needn't be the same across different pairs.

The wind speed is the same for all planes. You may assume that the wind has a steady speed and lasts arbitrarily long.

Input

The first line contains two integers n and w (1 ≤ n ≤ 100 000, 0 ≤ w < 105) — the number of planes and the maximum wind speed.

The i-th of the next n lines contains two integers xi and vi (1 ≤ |xi| ≤ 105, w + 1 ≤ |vi| ≤ 105, xi·vi < 0) — the initial position and speed of the i-th plane.

Planes are pairwise distinct, that is, no pair of (i, j) (i < j) exists such that both xi = xj and vi = vj.

Output

Output a single integer — the number of unordered pairs of planes that can contact Arkady at the same moment.

Examples

Input

5 1
-3 2
-3 3
-1 2
1 -3
3 -5

Output

3

Input

6 1
-3 2
-2 2
-1 2
1 -2
2 -2
3 -2

Output

9

Note

In the first example, the following 3 pairs of planes satisfy the requirements:

  * (2, 5) passes the station at time 3 / 4 with vwind = 1;
  * (3, 4) passes the station at time 2 / 5 with vwind = 1 / 2;
  * (3, 5) passes the station at time 4 / 7 with vwind = - 1 / 4.

In the second example, each of the 3 planes with negative coordinates can form a valid pair with each of the other 3, totaling 9 pairs.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int w;
struct data {
  long long int x, v;
} a[100005];
bool operator<(const data &a, const data &b) {
  long long int t = (a.x * (b.v + w) - b.x * (a.v + w));
  if (t > 0)
    t = 1;
  else if (t == 0)
    t = 0;
  else
    t = -1;
  t *= (a.v + w) * (b.v + w);
  if (t != 0) return t < 0;
  t = (a.x * (b.v - w) - b.x * (a.v - w));
  if (t > 0)
    t = 1;
  else if (t == 0)
    t = 0;
  else
    t = -1;
  t *= (a.v - w) * (b.v - w);
  return t > 0;
}
long double b[100005];
int fen[100005];
int n;
void update(int p, int val) {
  for (int i = p; i <= n; i += i & -i) {
    fen[i] += val;
  }
}
int sum(int p) {
  int ans = 0;
  for (int i = p; i; i -= i & -i) {
    ans += fen[i];
  }
  return ans;
}
vector<pair<long double, long long int> > v;
long long int c[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> w;
  for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].v;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) b[i] = a[i].x * 1.0 / (a[i].v - w);
  for (int i = 1; i <= n; i++)
    v.push_back(pair<long double, long long int>(b[i], -i));
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) c[-v[i].second] = i + 1;
  long long int res = 0;
  for (int i = n; i >= 1; i--) {
    res += sum(c[i]);
    update(c[i], 1);
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.

Input

The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets.

Output

Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.

Examples

Input

5 3
-6 0 35 -2 4

Output

8

Input

4 2
7 0 0 -7

Output

7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1004];
int size;
int n, m;
int main(void) {
  while (scanf("%d %d", &n, &m) != EOF) {
    size = 0;
    int i;
    for (i = 0; i < n; i++) {
      int p;
      scanf("%d", &p);
      if (p < 0) a[size++] = p;
    }
    sort(a, a + size);
    int sum = 0;
    for (i = 0; i < m && i < size; i++) {
      sum += a[i];
    }
    printf("%d\n", -sum);
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and the coins of each value are not limited in number. The task is to collect the sum x with the minimum amount of coins. Greedy algorithm with each its step takes the coin of the highest face value, not exceeding x. Obviously, if among the coins' face values exists the face value 1, any sum x can be collected with the help of greedy algorithm. However, greedy algorithm does not always give the optimal representation of the sum, i.e. the representation with the minimum amount of coins. For example, if there are face values {1, 3, 4} and it is asked to collect the sum 6, greedy algorithm will represent the sum as 4 + 1 + 1, while the optimal representation is 3 + 3, containing one coin less. By the given set of face values find out if there exist such a sum x that greedy algorithm will collect in a non-optimal way. If such a sum exists, find out the smallest of these sums.

Input

The first line contains an integer n (1 ≤ n ≤ 400) — the amount of the coins' face values. The second line contains n integers ai (1 ≤ ai ≤ 109), describing the face values. It is guaranteed that a1 > a2 > ... > an and an = 1.

Output

If greedy algorithm collects any sum in an optimal way, output -1. Otherwise output the smallest sum that greedy algorithm collects in a non-optimal way.

Examples

Input

5
25 10 5 2 1

Output

-1

Input

3
4 3 1

Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
static int N;
static int C[400];
long long value(int V[]) {
  long long res = 0;
  for (int n = 0; n < int(N); ++n) res += (long long)V[n] * C[n];
  return res;
}
int size(int V[]) {
  int res = 0;
  for (int n = 0; n < int(N); ++n) res += V[n];
  return res;
}
void greedy(int V[], long long tot) {
  for (int n = 0; n < int(N); ++n) {
    V[n] = tot / C[n];
    tot %= C[n];
  }
}
int main() {
  int M[400], G[400];
  long long tot, res = -1;
  cin >> N;
  for (int n = 0; n < int(N); ++n) cin >> C[n];
  for (int i = 1; i < int(N); ++i) {
    greedy(M, C[i - 1] - 1);
    for (int j = N - 1; j >= int(i); --j) {
      ++M[j];
      tot = value(M);
      greedy(G, tot);
      if (size(M) < size(G) && (res == -1 || tot < res)) res = tot;
      M[j] = 0;
    }
  }
  cout << res << endl;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Mark and his crew are sailing across the sea of Aeolus (in Greek mythology Aeolus was the keeper of the winds). They have the map which represents the NxM matrix with land and sea fields and they want to get to the port (the port is considered as sea field). They are in a hurry because the wind there is very strong and changeable and they have the food for only K days on the sea (that is the maximum that they can carry on the ship). John, the guy from Mark's crew, knows how to predict the direction of the wind on daily basis for W days which is enough time for them to reach the port or to run out of the food. Mark can move the ship in four directions (north, east, south, west) by one field for one day, but he can also stay in the same place. Wind can blow in four directions (north, east, south, west) or just not blow that day. The wind is so strong at the sea of Aeolus that it moves the ship for one whole field in the direction which it blows at. The ship's resulting movement is the sum of the ship's action and wind from that day. Mark must be careful in order to keep the ship on the sea, the resulting movement must end on the sea field and there must be a 4-connected path through the sea from the starting field. A 4-connected path is a path where you can go from one cell to another only if they share a side.

For example in the following image, the ship can't move to the port as there is no 4-connected path through the sea.

<image>

In the next image, the ship can move to the port as there is a 4-connected path through the sea as shown with the red arrow. Furthermore, the ship can move to the port in one move if one of the following happens. Wind is blowing east and Mark moves the ship north, or wind is blowing north and Mark moves the ship east. In either of these scenarios the ship will end up in the port in one move.

<image>

Mark must also keep the ship on the map because he doesn't know what is outside. Lucky for Mark and his crew, there are T fish shops at the sea where they can replenish their food supplies to the maximum, but each shop is working on only one day. That means that Mark and his crew must be at the shop's position on the exact working day in order to replenish their food supplies. Help Mark to find the minimum of days that he and his crew need to reach the port or print -1 if that is impossible with the food supplies that they have.

Input

First line contains two integer numbers N and M (1 ≤ N, M ≤ 200) - representing the number of rows and number of columns of the map.

Second line contains three integers, K (0 ≤ K ≤ 200) which is the number of days with the available food supplies, T (0 ≤ T ≤ 20) which is the number of fields with additional food supplies and W (0 ≤ W ≤ 10^6) which is the number of days with wind information.

Next is the NxM char matrix filled with the values of 'L', 'S', 'P' or 'M'. 'L' is for the land and 'S' is for the sea parts. 'P' is for the port field and 'M' is the starting field for the ship.

Next line contains W chars with the wind direction information for every day. The possible inputs are 'N' - north, 'S' - south, 'E' - east, 'W' - west and 'C' - no wind. If Mark's crew can reach the port, it is guaranteed that they will not need more than W days to reach it.

In the end there are T lines with the food supplies positions. Each line contains three integers, Y_i and X_i (0 ≤ Y_i < N, 0 ≤ X_i < M) representing the coordinates (Y is row number and X is column number) of the food supply and F_i (0 ≤ F_i ≤ 10^6) representing the number of days from the starting day on which the food supply is available.

Output

One integer number representing the minimal days to reach the port or -1 if that is impossible.

Examples

Input

3 3
5 2 15
M S S
S S S
S S P
S W N N N N N N N N N N N N N
2 1 0
1 2 0

Output

-1

Input

3 3
5 2 15
M S S
S S S
S S P
S E N N N N N N N N N N N N N
2 1 0
1 2 0

Output

2

Input

5 5
4 1 15
M S S S S
S S S S L
S S S L L
S S S S S
S S S S P
C C C C S S E E C C C C C C C
0 1 4

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e2 + 10, M = 2e6 + 10, dx[] = {-1, 1, 0, 0, 0},
          dy[] = {0, 0, -1, 1, 0};
int n, m, k, t, w, W[M], f[M], sx, sy;
char mat[N][N];
bool vis[25][N][N][N];
vector<int> vec[N][N];
struct Node {
  int x, y, last, k;
};
map<char, int> mp = {{'N', 0}, {'S', 1}, {'W', 2}, {'E', 3}, {'C', 4}};
inline bool check(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m) return false;
  if (mat[x][y] == 'L') return false;
  return true;
}
inline void ha(Node x) { printf("ha:%d %d %d %d\n", x.x, x.y, x.last, x.k); }
inline int bfs() {
  queue<Node> q;
  q.push((Node){sx, sy, 0, k});
  while (!q.empty()) {
    Node u = q.front();
    q.pop();
    int x = u.x, y = u.y, last = u.last, cur = u.k, t = f[last] + k - cur;
    if (mat[x][y] == 'P') return t;
    if (mat[x][y] == 'L') continue;
    if (vis[last][x][y][cur]) continue;
    vis[last][x][y][cur] = true;
    for (int i = 0; i < vec[x][y].size(); ++i)
      if (t == f[vec[x][y][i]]) {
        cur = k;
        last = vec[x][y][i];
      }
    if (cur == 0) continue;
    u = (Node){u.x + dx[W[t]], u.y + dy[W[t]], last, cur - 1};
    if (check(u.x, u.y)) q.push(u);
    for (int i = 0; i < 4; ++i) {
      int tx = x + dx[i] + dx[W[t]], ty = y + dy[i] + dy[W[t]];
      if ((check(x + dx[i], y + dy[i]) && check(tx, ty)) ||
          (check(x + dx[W[t]], y + dy[W[t]]) && check(tx, ty))) {
        u = (Node){tx, ty, last, cur - 1};
        if (!vis[last][tx][ty][cur - 1]) q.push(u);
      }
    }
  }
  return -1;
}
int main() {
  n = read();
  m = read();
  k = read();
  t = read();
  w = read();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> mat[i][j];
      if (mat[i][j] == 'M') {
        sx = i;
        sy = j;
      }
    }
  for (int i = 0; i < w; ++i) {
    char ch;
    cin >> ch;
    W[i] = mp[ch];
  }
  for (int i = 1; i <= t; ++i) {
    int x = read(), y = read();
    vec[x][y].push_back(i);
    f[i] = read();
  }
  printf("%d\n", bfs());
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

The fundamental idea in the JPEG compression algorithm is to sort coeffi- cient of given image by zigzag path and encode it. In this problem, we don’t discuss about details of the algorithm, but you are asked to make simple pro- gram. You are given single integer N , and you must output zigzag path on a matrix where size is N by N . The zigzag scanning is start at the upper-left corner (0, 0) and end up at the bottom-right corner. See the following Figure and sample output to make sure rule of the zigzag scanning. For example, if you are given N = 8, corresponding output should be a matrix shown in right-side of the Figure. This matrix consists of visited time for each element.

<image>

Input

Several test cases are given. Each test case consists of one integer N (0 < N < 10) in a line. The input will end at a line contains single zero.

Output

For each input, you must output a matrix where each element is the visited time. All numbers in the matrix must be right justified in a field of width 3. Each matrix should be prefixed by a header “Case x:” where x equals test case number.

Example

Input

3
4
0

Output

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

### Response

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

int n;

int dy[] = { -1,1 };
int dx[] = { 1,-1 };
int A[10][10];

bool isinrange(int y, int x) {
	return 0 <= y&&y < n && 0 <= x&&x < n;
}

signed main() {
	int c = 1;
	while (cin >> n&&n) {
		int y = 0, x = 0, idx = 1;

		for (int i = 0; i < n * 2 - 1; i++) {
			A[y][x] = idx++;
			while (isinrange(y + dy[i % 2], x + dx[i % 2])) {
				y += dy[i % 2];
				x += dx[i % 2];
				A[y][x] = idx++;
			}
			if (i < n - 1) {
				if (i % 2 == 0)x++;
				else y++;
			}
			else {
				if (i % 2 == 1)x++;
				else y++;
			}
		}

		A[n - 1][n - 1] = n*n;

		cout << "Case " << c++ << ":" << endl;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)
				printf("%3d", A[i][j]);
			cout << endl;
		}
	}
	return 0;
}
```


### Prompt

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

Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates.

There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. After that, Technogoblet selects the strongest student from each school to participate.

Arkady is a hacker who wants to have k Chosen Ones selected by the Technogoblet. Unfortunately, not all of them are the strongest in their schools, but Arkady can make up some new school names and replace some names from Technogoblet with those. You can't use each made-up name more than once. In that case, Technogoblet would select the strongest student in those made-up schools too.

You know the power of each student and schools they study in. Calculate the minimal number of schools Arkady has to make up so that k Chosen Ones would be selected by the Technogoblet.

Input

The first line contains three integers n, m and k (1 ≤ n ≤ 100, 1 ≤ m, k ≤ n) — the total number of students, the number of schools and the number of the Chosen Ones.

The second line contains n different integers p_1, p_2, …, p_n (1 ≤ p_i ≤ n), where p_i denotes the power of i-th student. The bigger the power, the stronger the student.

The third line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ m), where s_i denotes the school the i-th student goes to. At least one student studies in each of the schools.

The fourth line contains k different integers c_1, c_2, …, c_k (1 ≤ c_i ≤ n) — the id's of the Chosen Ones.

Output

Output a single integer — the minimal number of schools to be made up by Arkady so that k Chosen Ones would be selected by the Technogoblet.

Examples

Input

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

Output

1

Input

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

Output

2

Note

In the first example there's just a single Chosen One with id 3. His power is equal to 3, but in the same school 1, there's a student with id 5 and power 6, and that means inaction would not lead to the latter being chosen. If we, however, make up a new school (let its id be 4) for the Chosen One, Technogoblet would select students with ids 2 (strongest in 3), 5 (strongest in 1), 6 (strongest in 2) and 3 (strongest in 4).

In the second example, you can change the school of student 3 to the made-up 5 and the school of student 4 to the made-up 6. It will cause the Technogoblet to choose students 8, 7, 6, 5, 3 and 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[105];
vector<pair<int, int>> g[105];
int mp[105];
int c[105];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int id;
  for (int i = 1; i <= n; i++) {
    cin >> id;
    mp[i] = id;
    g[id].push_back(make_pair(a[i], i));
  }
  for (int i = 1; i <= k; i++) cin >> c[i];
  for (int i = 1; i <= m; i++)
    sort(g[i].begin(), g[i].end(), greater<pair<int, int>>());
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    if (a[c[i]] != g[mp[c[i]]][0].first) ans++;
  }
  cout << ans << endl;
  return 0;
}

```