### Prompt

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

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

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

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

Input

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

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

Output

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

Examples

Input

3 3 3 100
1 1 1

Output

10

Input

3 6 5 1000000007
1 2 3

Output

0

Input

3 5 6 11
1 2 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[2][505][505];
int N, M, K;
long long MOD;
int arr[505];
int main() {
  cin >> N >> M >> K >> MOD;
  for (int i = 1; i <= N; i++) {
    cin >> arr[i];
  }
  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      for (int k = 0; k <= K; k++) {
        dp[i & 1][j][k] = dp[i & 1 ^ 1][j][k];
        if (k >= arr[i] && j) {
          dp[i & 1][j][k] += dp[i & 1][j - 1][k - arr[i]];
        }
        dp[i & 1][j][k] %= MOD;
      }
    }
  }
  long long tot = 0;
  for (int i = 0; i <= K; i++) {
    tot += dp[N & 1][M][i];
    tot %= MOD;
  }
  cout << tot << endl;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (n + 1) meters, he draws a cross (see picture for clarifications).

John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?

<image> The figure shows the order in which John draws crosses for a square with side 4. The lower left square has two crosses. Overall John paints 17 crosses.

Input

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

The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample.

Output

For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.

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

Examples

Input

3
4 8 100

Output

17
33
401

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, x;
  cin >> t;
  while (t--) {
    cin >> n, x = n % 4;
    if (x == 0) cout << 4 * n + 1 << endl;
    if (x == 1) cout << 2 * n + 1 << endl;
    if (x == 2) cout << 4 * n + 1 << endl;
    if (x == 3) cout << n + 1 << endl;
  }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Nezzar loves the game osu!.

osu! is played on beatmaps, which can be seen as an array consisting of distinct points on a plane. A beatmap is called nice if for any three consecutive points A,B,C listed in order, the angle between these three points, centered at B, is strictly less than 90 degrees.

<image> Points A,B,C on the left have angle less than 90 degrees, so they can be three consecutive points of a nice beatmap; Points A',B',C' on the right have angle greater or equal to 90 degrees, so they cannot be three consecutive points of a nice beatmap.

Now Nezzar has a beatmap of n distinct points A_1,A_2,…,A_n. Nezzar would like to reorder these n points so that the resulting beatmap is nice.

Formally, you are required to find a permutation p_1,p_2,…,p_n of integers from 1 to n, such that beatmap A_{p_1},A_{p_2},…,A_{p_n} is nice. If it is impossible, you should determine it.

Input

The first line contains a single integer n (3 ≤ n ≤ 5000).

Then n lines follow, i-th of them contains two integers x_i, y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — coordinates of point A_i.

It is guaranteed that all points are distinct.

Output

If there is no solution, print -1.

Otherwise, print n integers, representing a valid permutation p.

If there are multiple possible answers, you can print any.

Example

Input

5
0 0
5 0
4 2
2 1
3 0

Output

1 2 5 3 4

Note

Here is the illustration for the first test:

<image>

Please note that the angle between A_1, A_2 and A_5, centered at A_2, is treated as 0 degrees. However, angle between A_1, A_5 and A_2, centered at A_5, is treated as 180 degrees.

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define MN 5005
#define ll long long
#define mod 998244353
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
typedef pair<int,int> pii;
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
int n,x[MN],y[MN],v[MN],ans[MN];
int cal(int i,int j,int k){return (ll)(x[j]-x[i])*(x[k]-x[j])+(ll)(y[j]-y[i])*(y[k]-y[j])<0;}
ll dis(int i,int j){return (ll)(x[i]-x[j])*(x[i]-x[j])+(ll)(y[i]-y[j])*(y[i]-y[j]);}
int main(){
	scanf("%d",&n);
	F(i,1,n)scanf("%d%d",x+i,y+i);
	int p=1;
	v[1]=1;
	ans[1]=1;
	F(i,2,n){
		int w=0;
		F(j,1,n)if(!v[j]&&(!w||dis(p,j)>dis(p,w)))w=j;
		v[w]=1,ans[i]=w,p=w;
	}
	F(i,1,n)printf("%d ",ans[i]);
	return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible.

The kingdom currently consists of n cities. Cities are connected by n - 1 bidirectional road, such that one can get from any city to any other city. As the King had to save a lot, there is only one path between any two cities.

What is the point of the reform? The key ministries of the state should be relocated to distinct cities (we call such cities important). However, due to the fact that there is a high risk of an attack by barbarians it must be done carefully. The King has made several plans, each of which is described by a set of important cities, and now wonders what is the best plan.

Barbarians can capture some of the cities that are not important (the important ones will have enough protection for sure), after that the captured city becomes impassable. In particular, an interesting feature of the plan is the minimum number of cities that the barbarians need to capture in order to make all the important cities isolated, that is, from all important cities it would be impossible to reach any other important city.

Help the King to calculate this characteristic for each of his plan.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cities in the kingdom.

Each of the next n - 1 lines contains two distinct integers ui, vi (1 ≤ ui, vi ≤ n) — the indices of the cities connected by the i-th road. It is guaranteed that you can get from any city to any other one moving only along the existing roads.

The next line contains a single integer q (1 ≤ q ≤ 100 000) — the number of King's plans.

Each of the next q lines looks as follows: first goes number ki — the number of important cities in the King's plan, (1 ≤ ki ≤ n), then follow exactly ki space-separated pairwise distinct numbers from 1 to n — the numbers of important cities in this plan.

The sum of all ki's does't exceed 100 000.

Output

For each plan print a single integer — the minimum number of cities that the barbarians need to capture, or print  - 1 if all the barbarians' attempts to isolate important cities will not be effective.

Examples

Input

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

Output

1
-1
1
-1

Input

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

Output

2

Note

In the first sample, in the first and the third King's plan barbarians can capture the city 3, and that will be enough. In the second and the fourth plans all their attempts will not be effective.

In the second sample the cities to capture are 3 and 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
struct greateri {
  template <class T>
  bool operator()(T const &a, T const &b) const {
    return a > b;
  }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
vector<long long> trt[100001], tree[100001];
long long tin[100001], tout[100001], impo[100001], dep[100001];
long long par[100001][37];
long long n, in, l;
void dfs(long long node, long long p, long long d) {
  tin[node] = in++;
  par[node][0] = p;
  dep[node] = d;
  for (long long i = 1; i <= l; ++i) {
    par[node][i] = par[par[node][i - 1]][i - 1];
  }
  for (auto it : tree[node]) {
    if (it != p) {
      dfs(it, node, d + 1);
    }
  }
  tout[node] = in++;
}
bool up(long long u, long long v) {
  return tin[u] <= tin[v] && tout[u] >= tout[v];
}
long long lca(long long u, long long v) {
  if (up(u, v)) return u;
  if (up(v, u)) return v;
  for (long long i = l; i >= 0; --i) {
    if (!up(par[u][i], v)) u = par[u][i];
  }
  return par[u][0];
}
bool ka = true;
pair<long long, long long> solve(long long node, long long p) {
  pair<long long, long long> ans;
  ans.first = 0;
  ans.second = 0;
  long long counti = 0;
  long long cna = 0;
  for (auto it : trt[node]) {
    if (it != p) {
      long long len = dep[it] - dep[node];
      if (impo[node]) {
        if (impo[it] && len == 1) ka = false;
        auto v = solve(it, node);
        ans.first += v.first;
        if ((v.second) != 0) counti++;
      } else {
        auto v = solve(it, node);
        ans.first += v.first;
        if ((v.second) != 0) cna++;
      }
    }
  }
  if (impo[node]) {
    ans.first += counti;
    ans.second = 1;
  } else {
    if (cna <= 1) {
      ans.second += cna;
    } else {
      ans.first++;
      ans.second = 0;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  l = log2(n);
  for (long long i = 0; i < n - 1; ++i) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  dfs(0, 0, 0);
  long long q;
  cin >> q;
  while (q--) {
    ka = true;
    long long k;
    cin >> k;
    vector<pair<long long, long long> > imp;
    set<pair<long long, long long> > cum;
    for (long long i = 0; i < k; ++i) {
      long long yo;
      cin >> yo;
      yo--;
      impo[yo]++;
      imp.push_back({tin[yo], yo});
      cum.insert({tin[yo], yo});
    }
    sort((imp).begin(), (imp).end());
    for (long long i = 0; i < k - 1; ++i) {
      long long k = lca(imp[i].second, imp[i + 1].second);
      cum.insert({tin[k], k});
    }
    imp.clear();
    for (auto it : cum) {
      imp.push_back(it);
    }
    vector<long long> yom;
    yom.push_back(imp[0].second);
    for (long long i = 1; i < (long long)imp.size(); ++i) {
      long long cur = imp[i].second;
      while ((long long)yom.size() >= 2 &&
             !up(yom[(long long)yom.size() - 1], cur)) {
        trt[yom[(long long)yom.size() - 2]].push_back(yom.back());
        yom.pop_back();
      }
      yom.push_back(cur);
    }
    while ((long long)yom.size() >= 2) {
      trt[yom[(long long)yom.size() - 2]].push_back(yom.back());
      yom.pop_back();
    }
    auto ans = solve(yom[0], -1);
    if (ka)
      cout << ans.first << '\n';
    else
      cout << -1 << '\n';
    for (long long i = 0; i < imp.size(); ++i) {
      trt[imp[i].second].clear();
      if (impo[imp[i].second]) impo[imp[i].second]--;
    }
    imp.clear();
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.

While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn.

Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).

Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.

Input

The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order.

The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of integers written on cubes after Stepan rearranged their order.

It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.

Output

Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).

Examples

Input

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

Output

TRUTH

Input

3 1 2
1 2 3
3 1 2

Output

LIE

Input

4 2 4
1 1 1 1
1 1 1 1

Output

TRUTH

Note

In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).

In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.

In the third example for any values l and r there is a situation when Stepan said the truth.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int POWER[65];
void precompute() {
  POWER[0] = 1;
  for (int i = 1; i < 31; i++) POWER[i] = POWER[i - 1] << 1LL;
}
long long int power(long long int x, long long int y, long long int mod) {
  long long int res = 1;
  x %= mod;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}
int main() {
  long long int n, l, r;
  cin >> n >> l >> r;
  long long int a[n];
  long long int b[n];
  map<long long int, long long int> ma, mb;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (long long int i = l - 1; i < r; i++) {
    ma[a[i]]++;
    mb[b[i]]++;
  }
  for (long long int i = l - 1; i < r; i++) {
    if (ma[a[i]] != mb[a[i]]) {
      cout << "LIE";
      return 0;
    }
  }
  for (long long int i = 0; i < l - 1; i++) {
    if (a[i] != b[i]) {
      cout << "LIE";
      return 0;
    }
  }
  for (long long int i = r + 2; i < n; i++) {
    if (a[i] != b[i]) {
      cout << "LIE";
      return 0;
    }
  }
  cout << "TRUTH";
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Chef Monocarp has just put n dishes into an oven. He knows that the i-th dish has its optimal cooking time equal to t_i minutes.

At any positive integer minute T Monocarp can put no more than one dish out of the oven. If the i-th dish is put out at some minute T, then its unpleasant value is |T - t_i| — the absolute difference between T and t_i. Once the dish is out of the oven, it can't go back in.

Monocarp should put all the dishes out of the oven. What is the minimum total unpleasant value Monocarp can obtain?

Input

The first line contains a single integer q (1 ≤ q ≤ 200) — the number of testcases.

Then q testcases follow.

The first line of the testcase contains a single integer n (1 ≤ n ≤ 200) — the number of dishes in the oven.

The second line of the testcase contains n integers t_1, t_2, ..., t_n (1 ≤ t_i ≤ n) — the optimal cooking time for each dish.

The sum of n over all q testcases doesn't exceed 200.

Output

Print a single integer for each testcase — the minimum total unpleasant value Monocarp can obtain when he puts out all the dishes out of the oven. Remember that Monocarp can only put the dishes out at positive integer minutes and no more than one dish at any minute.

Example

Input

6
6
4 2 4 4 5 2
7
7 7 7 7 7 7 7
1
1
5
5 1 2 4 3
4
1 4 4 4
21
21 8 1 4 1 5 21 1 8 21 11 21 11 3 12 8 19 15 9 11 13

Output

4
12
0
0
2
21

Note

In the first example Monocarp can put out the dishes at minutes 3, 1, 5, 4, 6, 2. That way the total unpleasant value will be |4 - 3| + |2 - 1| + |4 - 5| + |4 - 4| + |6 - 5| + |2 - 2| = 4.

In the second example Monocarp can put out the dishes at minutes 4, 5, 6, 7, 8, 9, 10.

In the third example Monocarp can put out the dish at minute 1.

In the fourth example Monocarp can put out the dishes at minutes 5, 1, 2, 4, 3.

In the fifth example Monocarp can put out the dishes at minutes 1, 3, 4, 5.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int time;
  scanf("%d", &time);
  while (time--) {
    int n;
    scanf("%d", &n);
    int a[300];
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int z = -1;
    for (int i = n; i > 1; i--) {
      for (int j = 1; j < i; j++) {
        if (a[j] > a[j + 1]) {
          z = a[j];
          a[j] = a[j + 1];
          a[j + 1] = z;
        }
      }
    }
    int b[300][500];
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n * 2; j++) b[i][j] = 2000000000;
    for (int j = 0; j <= n * 2; j++) b[0][j] = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n * 2; j++)
        b[i][j] = (((b[i][j - 1]) > (b[i - 1][j - 1] + abs(j - a[i])))
                       ? (b[i - 1][j - 1] + abs(j - a[i]))
                       : (b[i][j - 1]));
    printf("%d\n", b[n][n * 2]);
  }
  return 0;
}

```


### Prompt

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

The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:

  * Elements of the main diagonal.
  * Elements of the secondary diagonal.
  * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
  * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.

<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.

Help the Smart Beaver count the sum of good elements of the given matrix.

Input

The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.

The input limitations for getting 30 points are:

  * 1 ≤ n ≤ 5

The input limitations for getting 100 points are:

  * 1 ≤ n ≤ 101

Output

Print a single integer — the sum of good matrix elements.

Examples

Input

3
1 2 3
4 5 6
7 8 9

Output

45

Input

5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

Output

17

Note

In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  int s = 0;
  for (int i = 0; i < n; ++i) {
    s += a[i][i];
    if (i != n / 2) {
      s += a[i][n - 1 - i] + a[i][n / 2] + a[n / 2][i];
    }
  }
  cout << s << endl;
  return 0;
}

```


### Prompt

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

You are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as <image>. The weight of some partition R of a given set into k subsets is <image> (recall that a partition of a given set is a set of its subsets such that every element of the given set belongs to exactly one subset in partition).

Calculate the sum of weights of all partitions of a given set into exactly k non-empty subsets, and print it modulo 109 + 7. Two partitions are considered different iff there exist two elements x and y such that they belong to the same set in one of the partitions, and to different sets in another partition.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2·105) — the number of elements and the number of subsets in each partition, respectively.

The second line contains n integers wi (1 ≤ wi ≤ 109)— weights of elements of the set.

Output

Print one integer — the sum of weights of all partitions of a given set into k non-empty subsets, taken modulo 109 + 7.

Examples

Input

4 2
2 3 2 3

Output

160

Input

5 2
1 2 3 4 5

Output

645

Note

Possible partitions in the first sample:

  1. {{1, 2, 3}, {4}}, W(R) = 3·(w1 + w2 + w3) + 1·w4 = 24;
  2. {{1, 2, 4}, {3}}, W(R) = 26;
  3. {{1, 3, 4}, {2}}, W(R) = 24;
  4. {{1, 2}, {3, 4}}, W(R) = 2·(w1 + w2) + 2·(w3 + w4) = 20;
  5. {{1, 3}, {2, 4}}, W(R) = 20;
  6. {{1, 4}, {2, 3}}, W(R) = 20;
  7. {{1}, {2, 3, 4}}, W(R) = 26;

Possible partitions in the second sample:

  1. {{1, 2, 3, 4}, {5}}, W(R) = 45;
  2. {{1, 2, 3, 5}, {4}}, W(R) = 48;
  3. {{1, 2, 4, 5}, {3}}, W(R) = 51;
  4. {{1, 3, 4, 5}, {2}}, W(R) = 54;
  5. {{2, 3, 4, 5}, {1}}, W(R) = 57;
  6. {{1, 2, 3}, {4, 5}}, W(R) = 36;
  7. {{1, 2, 4}, {3, 5}}, W(R) = 37;
  8. {{1, 2, 5}, {3, 4}}, W(R) = 38;
  9. {{1, 3, 4}, {2, 5}}, W(R) = 38;
  10. {{1, 3, 5}, {2, 4}}, W(R) = 39;
  11. {{1, 4, 5}, {2, 3}}, W(R) = 40;
  12. {{2, 3, 4}, {1, 5}}, W(R) = 39;
  13. {{2, 3, 5}, {1, 4}}, W(R) = 40;
  14. {{2, 4, 5}, {1, 3}}, W(R) = 41;
  15. {{3, 4, 5}, {1, 2}}, W(R) = 42.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n;
long long k;
long long a[200005];
long long s1;
long long s2;
long long inv[200005];
long long p;
long long ans;
long long quick_pow(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % 1000000007;
    x = x * x % 1000000007;
    n >>= 1;
  }
  return res;
}
int main() {
  scanf("%lld %lld", &n, &k);
  inv[1] = inv[0] = 1LL;
  for (long long i = 2; i <= n; i++)
    inv[i] = (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;
  for (long long i = 1; i <= n; ++i) inv[i] = inv[i - 1] * inv[i] % 1000000007;
  for (long long i = 1; i <= n; ++i) scanf("%lld", a + i);
  for (long long i = 0; i <= k; ++i) {
    long long fg = 1;
    if (i & 1) fg = -1;
    (s1 += fg * inv[i] * inv[k - i] % 1000000007 * quick_pow(k - i, n) %
           1000000007) %= 1000000007;
    (s2 += fg * inv[i] * inv[k - i] % 1000000007 * quick_pow(k - i, n - 1) %
           1000000007) %= 1000000007;
  }
  p = (s1 + s2 * (n - 1) % 1000000007) % 1000000007;
  p = (p + 1000000007) % 1000000007;
  for (long long i = 1; i <= n; ++i)
    ans = (ans + a[i] * p % 1000000007) % 1000000007;
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Vasily the bear has got a large square white table of n rows and n columns. The table has got a black border around this table.

<image> The example of the initial table at n = 5.

Vasily the bear wants to paint his square table in exactly k moves. Each move is sequence of actions:

  1. The bear chooses some square inside his table. At that the square must have a black border painted around it. Also, the square shouldn't contain a black cell. The number of cells in the square shouldn't be less than 2.
  2. The bear chooses some row and some column inside the chosen square. Then he paints each cell of this row and this column inside the chosen square. After that the rectangles, formed by the square's border and the newly painted cells, must be squares of a non-zero area.

<image> An example of correct painting at n = 7 и k = 2.

The bear already knows numbers n and k. Help him — find the number of ways to paint the square in exactly k moves. Two ways to paint are called distinct if the resulting tables will differ in at least one cell. As the answer can be rather large, print the remainder after dividing it by 7340033.

Input

The first line contains integer q (1 ≤ q ≤ 105) — the number of test data.

Each of the following q lines contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 1000) — the size of the initial table and the number of moves for the corresponding test.

Output

For each test from the input print the answer to the problem modulo 7340033. Print the answers to the tests in the order in which the tests are given in the input.

Examples

Input

8
1 0
1 1
3 0
3 1
2 0
2 1
3 2
7 2

Output

1
0
1
1
1
0
0
4

Note

All possible painting ways for the test n = 7 and k = 2 are:

<image>

### Response

```cpp
#include <bits/stdc++.h>
const long long delta = 7340033;
long long n, q, k;
using namespace std;
long long dp[35][1001], tmp[1000];
long long cut(long long x) {
  if (x & 1) return cut(x / 2) + 1;
  return 0;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> q;
  for (long long i = 0; i < 35; i++) dp[i][0] = 1;
  for (long long i = 1; i < 35; i++) dp[i][1] = 1;
  for (long long i = 1; i < 34; i++)
    for (long long c = 0; c < 4; c++) {
      for (long long k = 0; k < 1001; k++) tmp[k] = 0;
      for (long long j = 1; j < 1001; j++)
        for (long long aj = j + 1; aj < 1001; aj++) {
          tmp[aj] += (dp[i + 1][aj - j] * dp[i][j]) % delta;
          tmp[aj] %= delta;
        }
      for (long long k = 1; k < 1001; k++) {
        dp[i + 1][k] += tmp[k];
        dp[i + 1][k] %= delta;
      }
    }
  dp[0][0] = 1;
  while (q--) {
    cin >> n >> k;
    if ((1 << (cut(n))) > n)
      cout << dp[cut(n) - 1][k] << endl;
    else
      cout << dp[cut(n)][k] << endl;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color ci and size si. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the cubes in the tower must alternate (colors of adjacent cubes must differ). The Zebra Tower should have at least two cubes. There are no other limitations. The figure below shows an example of a Zebra Tower.

<image>

A Zebra Tower's height is the sum of sizes of all cubes that form the tower. Help little Janet build the Zebra Tower of the maximum possible height, using the available cubes.

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of cubes. Next n lines contain the descriptions of the cubes, one description per line. A cube description consists of two space-separated integers ci and si (1 ≤ ci, si ≤ 109) — the i-th cube's color and size, correspondingly. It is guaranteed that there are at least two cubes of different colors.

Output

Print the description of the Zebra Tower of the maximum height in the following form. In the first line print the tower's height, in the second line print the number of cubes that form the tower, and in the third line print the space-separated indices of cubes in the order in which they follow in the tower from the bottom to the top. Assume that the cubes are numbered from 1 to n in the order in which they were given in the input.

If there are several existing Zebra Towers with maximum heights, it is allowed to print any of them.

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

Examples

Input

4
1 2
1 3
2 4
3 3

Output

9
3
2 3 1

Input

2
1 1
2 1

Output

2
2
2 1

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const long long inf = (long long)1e17;
long long ans = 0, c1 = 0, c2 = 0, cnt1 = 0, cnt2 = 0;
long long b[100005][2][2] = {}, mx, n, cnt;
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
void f(long long c, long long cnt) {
  long long cu = b[cnt][c][0], cc = b[cnt][c][1];
  if (b[cnt][c ^ 1][1] != cc) {
    if (ans < cu + b[cnt][c ^ 1][0]) {
      ans = cu + b[cnt][c ^ 1][0];
      cnt1 = cnt2 = cnt;
      c1 = c;
      c2 = c ^ 1;
    }
  }
  if (cnt > 1) {
    if (b[cnt - 1][c][1] != cc) {
      if (b[cnt - 1][c][0] + cu > ans) {
        ans = b[cnt - 1][c][0] + cu;
        cnt1 = cnt;
        cnt2 = cnt - 1;
        c1 = c2 = c;
      }
    }
    if (b[cnt - 1][c ^ 1][1] != cc) {
      if (b[cnt - 1][c ^ 1][0] + cu > ans) {
        ans = b[cnt - 1][c ^ 1][0] + cu;
        cnt1 = cnt;
        cnt2 = cnt - 1;
        c1 = c;
        c2 = c ^ 1;
      }
    }
  }
  if (b[cnt + 1][c][1] != cc) {
    if (b[cnt + 1][c][0] + cu > ans) {
      ans = b[cnt + 1][c][0] + cu;
      cnt1 = cnt;
      cnt2 = cnt + 1;
      c1 = c2 = c;
    }
  }
  if (b[cnt + 1][c ^ 1][1] != cc) {
    if (b[cnt + 1][c ^ 1][0] + cu > ans) {
      ans = b[cnt + 1][c ^ 1][0] + cu;
      cnt1 = cnt;
      cnt2 = cnt + 1;
      c1 = c;
      c2 = c ^ 1;
    }
  }
}
struct cube {
  long long c, w, num;
};
struct cmp {
  bool operator()(const cube& a, const cube& b) {
    return (a.c < b.c || (a.c == b.c && a.w > b.w));
  }
};
int main() {
  cin >> n;
  for (int i = 0; i < 100005; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k) b[i][j][k] = -inf;
  vector<cube> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].c >> a[i].w;
    a[i].num = i;
  }
  sort(a.begin(), a.end(), cmp());
  for (int i = 0, j; i < n; ++i) {
    for (j = i; j < n && a[j].c == a[i].c; ++j)
      ;
    mx = 0, cnt = 0;
    for (int k = i; k < j; ++k) {
      mx += a[k].w;
      ++cnt;
      if (mx >= b[cnt][0][0]) {
        b[cnt][1][0] = b[cnt][0][0];
        b[cnt][1][1] = b[cnt][0][1];
        b[cnt][0][0] = mx;
        b[cnt][0][1] = a[i].c;
      } else if (mx > b[cnt][1][0]) {
        b[cnt][1][0] = mx;
        b[cnt][1][1] = a[i].c;
      }
    }
    i = j - 1;
  }
  for (int i = 1; i <= n; ++i) {
    f(0, i);
    f(1, i);
  }
  cout << ans << '\n' << cnt1 + cnt2 << '\n';
  vector<int> help1, help2;
  for (int i = 0; i < n; ++i)
    if (a[i].c == b[cnt1][c1][1] && cnt1 > help1.size())
      help1.push_back(a[i].num);
  for (int i = 0; i < n; ++i)
    if (a[i].c == b[cnt2][c2][1] && cnt2 > help2.size())
      help2.push_back(a[i].num);
  if (cnt2 > cnt1) swap(help1, help2);
  while (help2.size() != 0) {
    cout << help1.back() + 1 << ' ' << help2.back() + 1 << ' ';
    help1.pop_back();
    help2.pop_back();
  }
  if (help1.size() != 0)
    cout << help1.back() + 1 << '\n';
  else
    cout << '\n';
}

```


### Prompt

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

Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of blocks of size 1 × 1.

Each block of the labyrinth has a button that rotates all blocks 90 degrees clockwise. Each block rotates around its center and doesn't change its position in the labyrinth. Also, each block has some number of doors (possibly none). In one minute, Theseus can either push the button in order to rotate all the blocks 90 degrees clockwise or pass to the neighbouring block. Theseus can go from block A to some neighbouring block B only if block A has a door that leads to block B and block B has a door that leads to block A.

Theseus found an entrance to labyrinth and is now located in block (xT, yT) — the block in the row xT and column yT. Theseus know that the Minotaur is hiding in block (xM, yM) and wants to know the minimum number of minutes required to get there.

Theseus is a hero, not a programmer, so he asks you to help him.

Input

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

Each of the following n lines contains m characters, describing the blocks of the labyrinth. The possible characters are:

  * «+» means this block has 4 doors (one door to each neighbouring block);
  * «-» means this block has 2 doors — to the left and to the right neighbours;
  * «|» means this block has 2 doors — to the top and to the bottom neighbours;
  * «^» means this block has 1 door — to the top neighbour;
  * «>» means this block has 1 door — to the right neighbour;
  * «<» means this block has 1 door — to the left neighbour;
  * «v» means this block has 1 door — to the bottom neighbour;
  * «L» means this block has 3 doors — to all neighbours except left one;
  * «R» means this block has 3 doors — to all neighbours except right one;
  * «U» means this block has 3 doors — to all neighbours except top one;
  * «D» means this block has 3 doors — to all neighbours except bottom one;
  * «*» means this block is a wall and has no doors.

Left, right, top and bottom are defined from representing labyrinth as a table, where rows are numbered from 1 to n from top to bottom and columns are numbered from 1 to m from left to right.

Next line contains two integers — coordinates of the block (xT, yT) (1 ≤ xT ≤ n, 1 ≤ yT ≤ m), where Theseus is initially located.

Last line contains two integers — coordinates of the block (xM, yM) (1 ≤ xM ≤ n, 1 ≤ yM ≤ m), where Minotaur hides.

It's guaranteed that both the block where Theseus starts and the block where Minotaur is hiding have at least one door. Theseus and Minotaur may be initially located at the same block.

Output

If Theseus is not able to get to Minotaur, then print -1 in the only line of the output. Otherwise, print the minimum number of minutes required to get to the block where Minotaur is hiding.

Examples

Input

2 2
+*
*U
1 1
2 2

Output

-1

Input

2 3
<><
><>
1 1
2 1

Output

4

Note

Assume that Theseus starts at the block (xT, yT) at the moment 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ps, n, m, a[4000005], nm, nm2, nm3, s, xt, yt, xm, ym, q[4000005],
    ans = 1000000007;
vector<int> v[4000005];
void addup(int x, int y, int s) {
  if (x > 1) v[s].push_back(s - m);
  if (y < m) v[s + nm].push_back(s + nm + 1);
  if (x < n) v[s + nm2].push_back(s + nm2 + m);
  if (y > 1) v[s + nm3].push_back(s + nm3 - 1);
}
void addright(int x, int y, int s) {
  if (x > 1) v[s + nm3].push_back(s + nm3 - m);
  if (y < m) v[s].push_back(s + 1);
  if (x < n) v[s + nm].push_back(s + nm + m);
  if (y > 1) v[s + nm2].push_back(s + nm2 - 1);
}
void adddown(int x, int y, int s) {
  if (x > 1) v[s + nm2].push_back(s + nm2 - m);
  if (y < m) v[s + nm3].push_back(s + nm3 + 1);
  if (x < n) v[s].push_back(s + m);
  if (y > 1) v[s + nm].push_back(s + nm - 1);
}
void addleft(int x, int y, int s) {
  if (x > 1) v[s + nm].push_back(s + nm - m);
  if (y < m) v[s + nm2].push_back(s + nm2 + 1);
  if (x < n) v[s + nm3].push_back(s + nm3 + m);
  if (y > 1) v[s].push_back(s - 1);
}
int main() {
  scanf("%d%d", &n, &m);
  nm = n * m, nm2 = nm << 1, nm3 = nm2 + nm;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      s++;
      char c;
      scanf(" %c", &c);
      v[s].push_back(s + nm);
      v[s + nm].push_back(s + nm2);
      v[s + nm2].push_back(s + nm3);
      v[s + nm3].push_back(s);
      if (c == '*') continue;
      if (c == '+' || c == '|' || c == '^' || c == 'L' || c == 'R' || c == 'D')
        addup(i, j, s);
      if (c == '+' || c == '-' || c == '>' || c == 'L' || c == 'U' || c == 'D')
        addright(i, j, s);
      if (c == '+' || c == '|' || c == 'v' || c == 'L' || c == 'R' || c == 'U')
        adddown(i, j, s);
      if (c == '+' || c == '-' || c == '<' || c == 'U' || c == 'R' || c == 'D')
        addleft(i, j, s);
    }
  }
  scanf("%d%d%d%d", &xt, &yt, &xm, &ym);
  int start = (xt - 1) * m + yt, end = (xm - 1) * m + ym, qs = 1, qe = 0;
  a[start] = 1, q[1] = start;
  while (qs != qe) {
    int o = q[++qe], z = a[o] + 1;
    if (o % nm == end) break;
    for (int i = 0; i < v[o].size(); i++) {
      if (!a[v[o][i]]) {
        bool b = (v[o][i] == o + nm) || (v[o][i] + nm3 == o);
        for (int j = 0; j < v[v[o][i]].size(); j++)
          if (v[v[o][i]][j] == o) b = 1;
        if (b) a[v[o][i]] = z, q[++qs] = v[o][i];
      }
    }
  }
  if (a[end]) ans = min(ans, a[end]);
  if (a[end + nm]) ans = min(ans, a[end + nm]);
  if (a[end + nm2]) ans = min(ans, a[end + nm2]);
  if (a[end + nm3]) ans = min(ans, a[end + nm3]);
  if (ans == 1000000007) ans = 0;
  ans--;
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.

This problem is similar to a standard problem but it has a different format and constraints.

In the standard problem you are given an array of integers, and you have to find one or more consecutive elements in this array where their sum is the maximum possible sum.

But in this problem you are given n small arrays, and you will create one big array from the concatenation of one or more instances of the small arrays (each small array could occur more than once). The big array will be given as an array of indexes (1-based) of the small arrays, and the concatenation should be done in the same order as in this array. Then you should apply the standard problem mentioned above on the resulting big array.

For example let's suppose that the small arrays are {1, 6, -2}, {3, 3} and {-5, 1}. And the indexes in the big array are {2, 3, 1, 3}. So the actual values in the big array after formatting it as concatenation of the small arrays will be {3, 3, -5, 1, 1, 6, -2, -5, 1}. In this example the maximum sum is 9.

Can you help Mostafa solve this problem?

Input

The first line contains two integers n and m, n is the number of the small arrays (1 ≤ n ≤ 50), and m is the number of indexes in the big array (1 ≤ m ≤ 250000). Then follow n lines, the i-th line starts with one integer l which is the size of the i-th array (1 ≤ l ≤ 5000), followed by l integers each one will be greater than or equal -1000 and less than or equal 1000. The last line contains m integers which are the indexes in the big array, and you should concatenate the small arrays in the same order, and each index will be greater than or equal to 1 and less than or equal to n.

The small arrays are numbered from 1 to n in the same order as given in the input. Some of the given small arrays may not be used in big array.

Note, that the array is very big. So if you try to build it straightforwardly, you will probably get time or/and memory limit exceeded.

Output

Print one line containing the maximum sum in the big array after formatting it as described above. You must choose at least one element for the sum, i. e. it cannot be empty.

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

Examples

Input

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

Output

9

Input

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

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, l, ans, c, cc, mx, a[55][5005], b[250005], best_prefix[55],
    best_suffix[55], best_mid[55], sum[55], mem[250005][3];
bool flag;
long long solve(long long p = 0, bool token = 0) {
  if (p == m) return -1e18;
  if (mem[p][token] > -1e18) return mem[p][token];
  if (token)
    mem[p][token] = max(best_prefix[b[p]], sum[b[p]] + solve(p + 1, 1));
  else
    mem[p][token] =
        max(best_mid[b[p]],
            max(solve(p + 1, 0), best_suffix[b[p]] + solve(p + 1, 1)));
  return mem[p][token];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> l;
    c = cc = 0;
    flag = 0;
    mx = -1e18;
    for (long long j = 0; j < l; j++) {
      cin >> a[i][j];
      mx = max(mx, a[i][j]);
      c += a[i][j];
      if (c > -1)
        flag = 1;
      else
        c = 0;
      cc = max(cc, c);
    }
    if (!flag) cc = mx;
    best_mid[i] = cc;
    c = 0;
    best_prefix[i] = 0;
    flag = 0;
    for (long long j = 0; j < l; j++) {
      c += a[i][j];
      if (c >= best_prefix[i]) {
        best_prefix[i] = c;
        flag = 1;
      }
    }
    sum[i] = c;
    if (!flag) best_prefix[i] = -1e14;
    c = 0;
    best_suffix[i] = 0;
    flag = 0;
    for (long long j = l - 1; ~j; j--) {
      c += a[i][j];
      if (c >= best_suffix[i]) {
        best_suffix[i] = c;
        flag = 1;
      }
    }
    if (!flag) best_suffix[i] = -1e14;
  }
  for (long long i = 0; i < m; i++) {
    cin >> b[i];
    b[i]--;
  }
  for (long long i = 0; i < 250005; i++)
    for (long long j = 0; j < 3; j++) mem[i][j] = -1e18;
  cout << solve();
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

There are N rabbits on a number line. The rabbits are conveniently numbered 1 through N. The coordinate of the initial position of rabbit i is x_i.

The rabbits will now take exercise on the number line, by performing sets described below. A set consists of M jumps. The j-th jump of a set is performed by rabbit a_j (2≤a_j≤N-1). For this jump, either rabbit a_j-1 or rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit x), then rabbit a_j will jump to the symmetric point of its current position with respect to rabbit x.

The rabbits will perform K sets in succession. For each rabbit, find the expected value of the coordinate of its eventual position after K sets are performed.

Constraints

* 3≤N≤10^5
* x_i is an integer.
* |x_i|≤10^9
* 1≤M≤10^5
* 2≤a_j≤N-1
* 1≤K≤10^{18}

Input

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

N
x_1 x_2 ... x_N
M K
a_1 a_2 ... a_M

Output

Print N lines. The i-th line should contain the expected value of the coordinate of the eventual position of rabbit i after K sets are performed. The output is considered correct if the absolute or relative error is at most 10^{-9}.

Examples

Input

3
-1 0 2
1 1
2

Output

-1.0
1.0
2.0

Input

3
1 -1 1
2 2
2 2

Output

1.0
-1.0
1.0

Input

5
0 1 3 6 10
3 10
2 3 4

Output

0.0
3.0
7.0
8.0
10.0

### Response

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

int N,M;long long K;
long long X[100005],D[100005];

int P[61][100005];
int ans[100005];

int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%lld",&X[i]),D[i]=X[i]-X[i-1],P[0][i]=i;
	scanf("%d%lld",&M,&K);
	while(M--){
		int x;scanf("%d",&x);
		swap(P[0][x],P[0][x+1]);
	}
	for(int i=1;i<=60;i++)
	for(int j=1;j<=N;j++)
		P[i][j]=P[i-1][P[i-1][j]];
	for(int j=1;j<=N;j++) ans[j]=j;
	for(int i=60;~i;i--)if((K>>i)&1)
	for(int j=1;j<=N;j++)
		ans[j]=P[i][ans[j]];
	for(int i=1;i<=N;i++) printf("%lld\n",X[i]=X[i-1]+D[ans[i]]);
}
```


### Prompt

Please create a solution in CPP to the following problem:

You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).

You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).

You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.

To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

Input

The first line contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of chocolate bars in the shop.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the cost of i-th chocolate bar.

The third line contains one integer m (1 ≤ m ≤ n - 1) — the number of coupons you have.

The fourth line contains m integers q_1, q_2, ..., q_m (2 ≤ q_i ≤ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.

Output

Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.

Example

Input

7
7 1 3 1 4 10 8
2
3 4

Output

27
30

Note

Consider the first example.

If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.

If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[300005];
  cin >> n;
  long long s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (int i = 0; i < m; i++) {
    int r;
    cin >> r;
    cout << s - a[r - 1] << endl;
  }
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

What are you doing at the end of the world? Are you busy? Will you save us?

<image>

Nephren is playing a game with little leprechauns.

She gives them an infinite array of strings, f0... ∞.

f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".

She wants to let more people know about it, so she defines fi =  "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.

For example, f1 is

"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.

It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.

Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).

Can you answer her queries?

Input

The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.

Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).

Output

One line containing q characters. The i-th character in it should be the answer for the i-th query.

Examples

Input

3
1 1
1 2
1 111111111111

Output

Wh.

Input

5
0 69
1 194
1 139
0 47
1 66

Output

abdef

Input

10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474

Output

Areyoubusy

Note

For the first two examples, refer to f0 and f1 given in the legend.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long numc[100001];
string s1 =
    "What are you doing at the end of the world? Are you busy? Will you save "
    "us?";
string s2 =
    "What are you doing while sending \"\"? Are you busy? Will you send \"\"?";
string s3 = "What are you doing while sending \"";
string s4 = "\"? Are you busy? Will you send \"";
string s5 = "\"?";
int main() {
  long long q, n, k;
  long long i;
  numc[0] = s1.length();
  for (i = 1; i <= 54; i++) {
    numc[i] = 2 * numc[i - 1] + s2.length();
  }
  for (i = 55; i <= 100000; i++) numc[i] = numc[54];
  cin >> q;
  for (i = 1; i <= q; i++) {
    cin >> n >> k;
    if (n == 0 && k <= numc[0]) {
      cout << s1[k - 1];
      continue;
    }
    if (k > numc[n]) {
      cout << ".";
      continue;
    }
    long long level = n;
    while (1 == 1) {
      if (level == 0) {
        cout << s1[k - 1];
        break;
      }
      if (k <= s3.length()) {
        cout << s3[k - 1];
        break;
      }
      if (k > s3.length() + numc[level - 1] &&
          k <= s4.length() + s3.length() + numc[level - 1]) {
        cout << s4[k - 1 - s3.length() - numc[level - 1]];
        break;
      }
      if (k > s4.length() + s3.length() + numc[level - 1] + numc[level - 1]) {
        cout << s5[k - 1 - 2 * numc[level - 1] - s3.length() - s4.length()];
        break;
      }
      if (k <= numc[level - 1] + s3.length())
        k -= s3.length();
      else
        k -= (s3.length() + s4.length() + numc[level - 1]);
      level--;
    }
  }
  return 0;
}

```


### Prompt

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

Oleg the bank client solves an interesting chess problem: place on n × n chessboard the maximum number of rooks so that they don't beat each other. Of course, no two rooks can share the same cell.

Remind that a rook standing in the cell (a, b) beats a rook standing in the cell (x, y) if and only if a = x or b = y.

Unfortunately (of fortunately?) for Oleg the answer in this problem was always n, so the task bored Oleg soon. He decided to make it more difficult by removing some cells from the board. If a cell is deleted, Oleg can't put a rook there, but rooks do beat each other "through" deleted cells.

Oleg deletes the cells in groups, namely, he repeatedly choose a rectangle with sides parallel to the board sides and deletes all the cells inside the rectangle. Formally, if he chooses a rectangle, lower left cell of which has coordinates (x1, y1), and upper right cell of which has coordinates (x2, y2), then he deletes all such cells with coordinates (x, y) that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2. It is guaranteed that no cell is deleted twice, i.e. the chosen rectangles do not intersect.

This version of the problem Oleg can't solve, and his friend Igor is busy at a conference, so he can't help Oleg.

You are the last hope for Oleg! Help him: given the size of the board and the deleted rectangles find the maximum possible number of rooks that could be placed on the board so that no two rooks beat each other.

Input

The first line contains single integer n (1 ≤ n ≤ 10000) — the size of the board.

The second line contains single integer q (0 ≤ q ≤ 10000) — the number of deleted rectangles.

The next q lines contain the information about the deleted rectangles.

Each of these lines contains four integers x1, y1, x2 and y2 (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ n) — the coordinates of the lower left and the upper right cells of a deleted rectangle.

If is guaranteed that the rectangles do not intersect.

Output

In the only line print the maximum number of rooks Oleg can place on the board so that no two rooks beat each other.

Examples

Input

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

Output

3

Input

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

Output

8

Note

Here is the board and the example of rooks placement in the first example:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
namespace network_flow {
const int max0 = 3000000, max1 = 10000000;
struct edge {
  int id, g, nxt;
  edge() {}
  edge(int _id, int _g, int _nxt) : id(_id), g(_g), nxt(_nxt) {}
};
int st[max0 + 5], en = 0;
edge e[max1 + 5];
inline void add_edge(int first, int second, int z) {
  e[en] = edge(second, z, st[first]), st[first] = en++;
}
inline void add_biedge(int first, int second, int z) {
  add_edge(first, second, z), add_edge(second, first, 0);
}
int S, T, N;
int dis[max0 + 5];
inline bool bfs() {
  static int q[max0 + 5];
  static bool vis[max0 + 5];
  int head = 0, rear = 0;
  memset(dis, -1, sizeof(dis[0]) * N);
  memset(vis, 0, sizeof(vis[0]) * N);
  vis[q[rear++] = S] = 1;
  dis[S] = 0;
  while (head != rear) {
    int first = q[head++];
    for (int i = st[first]; i != -1; i = e[i].nxt) {
      if (!e[i].g) continue;
      int second = e[i].id;
      if (!vis[second]) {
        dis[second] = dis[first] + 1;
        if (second == T) return 1;
        q[rear++] = second;
        vis[second] = 1;
      }
    }
  }
  return 0;
}
int cur[max0 + 5];
inline int dfs(int first, int flow) {
  if (first == T) return flow;
  int res = flow;
  for (int &i = cur[first]; i != -1; i = e[i].nxt) {
    if (!e[i].g) continue;
    int second = e[i].id;
    if (dis[second] == dis[first] + 1) {
      int F = dfs(second, min(e[i].g, res));
      res -= F;
      e[i].g -= F;
      e[i ^ 1].g += F;
      if (res <= 0) return flow;
    }
  }
  dis[first] = -1;
  return flow - res;
}
inline int work() {
  if (S == T) return oo;
  int ret = 0;
  for (; bfs();) {
    for (int i = (0), i_end_ = (N); i < i_end_; ++i) cur[i] = st[i];
    ret += dfs(S, oo);
  }
  return ret;
}
}  // namespace network_flow
using network_flow::add_biedge;
using network_flow::add_edge;
using network_flow::en;
using network_flow::N;
using network_flow::S;
using network_flow::st;
using network_flow::T;
using network_flow::work;
const int maxn = 10100;
int n, qn;
struct node;
node *newnode();
node *copy(node *first);
struct node {
  int id;
  int link;
  node *c[2];
  bool has, con;
  node() : has(0), con(0) { memset(c, 0, sizeof c); }
  void update() {
    has = con;
    for (int i = (0), i_end_ = (2); i < i_end_; ++i)
      if (c[i] && c[i]->has) has = 1;
  }
  void flag_label() {
    if (!con) add_biedge(id, link, oo);
    has = con = 1;
  }
};
const int max0 = 100000;
node *nd_pool;
int nd_res = 0;
inline node *newnode() {
  if (!nd_res) nd_pool = new node[max0], nd_res = max0;
  node *ret = nd_pool + (--nd_res);
  ret->id = N++;
  return ret;
}
inline node *copy(node *first) {
  node *tmp = newnode();
  int tmpid = tmp->id;
  *tmp = *first;
  tmp->id = tmpid;
  return tmp;
}
void build(node *&rt, int l, int r) {
  if (!rt) {
    rt = newnode();
    rt->link = N++;
  }
  if (r - l <= 1) {
    add_biedge(rt->link, T, 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(rt->c[0], l, mid);
  build(rt->c[1], mid, r);
  for (int i = (0), i_end_ = (2); i < i_end_; ++i)
    add_biedge(rt->link, rt->c[i]->link, oo);
}
int seg_x, seg_y, seg_ty;
void clear(node *&rt) {
  if (!rt->has) return;
  rt = copy(rt);
  if (rt->con) rt->con = 0;
  rt->update();
  if (rt->has)
    for (int i = (0), i_end_ = (2); i < i_end_; ++i)
      if (rt->c[i]) clear(rt->c[i]);
  rt->update();
  for (int i = (0), i_end_ = (2); i < i_end_; ++i)
    if (rt->c[i]) add_biedge(rt->id, rt->c[i]->id, oo);
}
void add(node *&rt, int l, int r) {
  if (seg_x <= l && r <= seg_y) {
    if (!seg_ty) {
      clear(rt);
    } else
      rt = copy(rt), rt->flag_label();
    return;
  }
  rt = copy(rt);
  int mid = (l + r) >> 1;
  if (rt->con) {
    for (int i = (0), i_end_ = (2); i < i_end_; ++i)
      if (rt->c[i]) {
        rt->c[i] = copy(rt->c[i]);
        rt->c[i]->flag_label();
      }
    rt->con = 0;
  }
  if (seg_x < mid) add(rt->c[0], l, mid);
  if (seg_y > mid) add(rt->c[1], mid, r);
  rt->update();
  for (int i = (0), i_end_ = (2); i < i_end_; ++i)
    if (rt->c[i]) add_biedge(rt->id, rt->c[i]->id, oo);
}
vector<pair<int, pair<int, int> > > all[maxn + 5];
node *rt;
int main() {
  memset(st, -1, sizeof st);
  S = N++, T = N++;
  scanf("%d", &n);
  scanf("%d", &qn);
  build(rt, 0, n);
  rt->flag_label();
  for (int i = (0), i_end_ = (qn); i < i_end_; ++i) {
    int ux, uy, vx, vy;
    scanf("%d%d%d%d", &ux, &uy, &vx, &vy), --ux, --uy;
    all[ux].push_back(make_pair(0, make_pair(uy, vy)));
    all[vx].push_back(make_pair(1, make_pair(uy, vy)));
  }
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    sort((all[i]).begin(), (all[i]).end());
    reverse((all[i]).begin(), (all[i]).end());
    for (auto u : all[i]) {
      seg_x = u.second.first, seg_y = u.second.second, seg_ty = u.first;
      add(rt, 0, n);
    }
    add_biedge(S, rt->id, 1);
  }
  printf("%d\n", work());
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Rick is in love with Unity. But Mr. Meeseeks also love Unity, so Rick and Mr. Meeseeks are "love rivals".

Unity loves rap, so it decided that they have to compete in a rap game (battle) in order to choose the best. Rick is too nerds, so instead he's gonna make his verse with running his original algorithm on lyrics "Rap God" song.

<image>

His algorithm is a little bit complicated. He's made a tree with n vertices numbered from 1 to n and there's a lowercase english letter written on each edge. He denotes str(a, b) to be the string made by writing characters on edges on the shortest path from a to b one by one (a string of length equal to distance of a to b). Note that str(a, b) is reverse of str(b, a) and str(a, a) is empty.

In order to make the best verse he can, he needs to answer some queries, but he's not a computer scientist and is not able to answer those queries, so he asked you to help him. Each query is characterized by two vertices x and y (x ≠ y). Answer to this query is the number of vertices like z such that z ≠ x, z ≠ y and str(x, y) is lexicographically larger than str(x, z).

String x = x1x2...x|x| is lexicographically larger than string y = y1y2...y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ..., x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ..., xr = yr and xr + 1 > yr + 1. Characters are compared like their ASCII codes (or alphabetic order).

Help Rick get the girl (or whatever gender Unity has).

Input

The first line of input contain two integers n and q (2 ≤ n ≤ 20000, 1 ≤ q ≤ 20000) — number of vertices in tree and number of queries respectively.

The next n - 1 lines contain the edges. Each line contains two integers v and u (endpoints of the edge) followed by an English lowercase letter c (1 ≤ v, u ≤ n, v ≠ u).

The next q line contain the queries. Each line contains two integers x and y (1 ≤ x, y ≤ n, x ≠ y).

Output

Print the answer for each query in one line.

Examples

Input

4 3
4 1 t
3 2 p
1 2 s
3 2
1 3
2 1

Output

0
1
1

Input

8 4
4 6 p
3 7 o
7 8 p
4 5 d
1 3 o
4 3 p
3 2 e
8 6
3 7
8 1
4 3

Output

6
1
3
1

Note

Here's the tree of first sample testcase:

<image>

Here's the tree of second sample testcase:

<image>

In this test:

  * str(8, 1) = poo
  * str(8, 2) = poe
  * str(8, 3) = po
  * str(8, 4) = pop
  * str(8, 5) = popd
  * str(8, 6) = popp
  * str(8, 7) = p

So, for the first query, <image> and for the third query <image> is the answer.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 20054, M = N * 2;
struct edge {
  int u, v;
  char w;
  edge(int u0 = 0, int v0 = 0, char w0 = 0) : u(u0), v(v0), w(w0) {}
} e[M];
int n, q, E = 0;
int first[N], next[M];
int p[N], dep[N], status[N];
int cnt = 0, o[N];
int stamp = 0, tag[N], L[N];
char s[M], pst[N];
inline int cmp(const char x, const char y) { return x < y ? -1 : x > y; }
inline void addedge(int u, int v, char w) {
  e[++E] = edge(u, v, w), next[E] = first[u], first[u] = E;
  e[++E] = edge(v, u, w), next[E] = first[v], first[v] = E;
}
void dfs(int x) {
  int i, y;
  o[++cnt] = x;
  for (i = first[x]; i; i = next[i])
    if ((y = e[i].v) != p[x])
      p[y] = x, pst[y] = e[i].w, dep[y] = dep[x] + 1, dfs(y);
}
int genstr(int x, int y) {
  char *_beg = s, *_end = s + M;
  for (; x != y; dep[x] < dep[y] ? (*--_end = pst[y], y = p[y])
                                 : (*_beg++ = pst[x], x = p[x]))
    ;
  return memcpy(_beg, _end, s + M - _end), M - (_end - _beg);
}
int main() {
  int i, u, v, x, l;
  char w[3];
  scanf("%d%d", &n, &q);
  for (i = 1; i < n; ++i) scanf("%d%d%s", &u, &v, w), addedge(u, v, *w);
  for (dfs(1); q; --q) {
    scanf("%d%d", &u, &v), l = genstr(u, v), --s[l - 1], s[l] = 127;
    status[u] = L[u] = 0, tag[u] = ++stamp;
    for (x = u; p[x]; x = p[x])
      tag[p[x]] = stamp, L[p[x]] = L[x] + 1,
      status[p[x]] = (status[x] ? status[x] : cmp(pst[x], s[L[x]]));
    for (i = 2; i <= n; ++i)
      if (tag[x = o[i]] != stamp)
        L[x] = L[p[x]] + 1,
        status[x] = (status[p[x]] ? status[p[x]] : cmp(pst[x], s[L[p[x]]]));
    printf("%d\n", int(n - 1 - std::count(status + 1, status + (n + 1), 1)));
  }
  return 0;
}

```


### Prompt

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

Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.

Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.

This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.

Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".

You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

Input

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Output

Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

Examples

Input

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

Output

word
l10n
i18n
p43s

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string tmp;
  cin >> n;
  while (n--) {
    cin >> tmp;
    if (tmp.length() <= 10)
      cout << tmp << endl;
    else {
      cout << tmp[0] << tmp.length() - 2 << tmp[tmp.length() - 1] << endl;
    }
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi is back color of the i-th t-shirt. All values pi are distinct, and values ai and bi are integers from 1 to 3.

m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color cj.

A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.

You are to compute the prices each buyer will pay for t-shirts.

Input

The first line contains single integer n (1 ≤ n ≤ 200 000) — the number of t-shirts.

The following line contains sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ 1 000 000 000), where pi equals to the price of the i-th t-shirt.

The following line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3), where ai equals to the front color of the i-th t-shirt.

The following line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 3), where bi equals to the back color of the i-th t-shirt.

The next line contains single integer m (1 ≤ m ≤ 200 000) — the number of buyers.

The following line contains sequence c1, c2, ..., cm (1 ≤ cj ≤ 3), where cj equals to the favorite color of the j-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.

Output

Print to the first line m integers — the j-th integer should be equal to the price of the t-shirt which the j-th buyer will buy. If the j-th buyer won't buy anything, print -1.

Examples

Input

5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1

Output

200 400 300 500 911 -1

Input

2
1000000000 1
1 1
1 2
2
2 1

Output

1 1000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long t, n, m, x, ans[N], p[N];
vector<pair<long long, long long> > v1, v2, v3;
bool f[N];
int main() {
  t = 1;
  while (t--) {
    scanf("%lld", &n);
    for (long long i = 0; i < n; i++) {
      scanf("%lld", &x);
      p[i] = x;
    }
    for (long long i = 0; i < n; i++) {
      scanf("%lld", &x);
      if (x == 1) v1.push_back({p[i], i});
      if (x == 2) v2.push_back({p[i], i});
      if (x == 3) v3.push_back({p[i], i});
    }
    for (long long i = 0; i < n; i++) {
      scanf("%lld", &x);
      if (x == 1) v1.push_back({p[i], i});
      if (x == 2) v2.push_back({p[i], i});
      if (x == 3) v3.push_back({p[i], i});
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    sort(v3.begin(), v3.end());
    long long q = 0, i1 = 0, i2 = 0, i3 = 0;
    scanf("%lld", &m);
    while (m--) {
      scanf("%lld", &x);
      if (x == 1 && i1 < v1.size()) {
        while (i1 < v1.size() && f[v1[i1].second]) i1++;
        if (i1 < v1.size() && !f[v1[i1].second]) {
          ans[q] = v1[i1].first;
          f[v1[i1].second] = 1;
          i1++;
        } else
          ans[q] = -1;
      } else if (x == 2 && i2 < v2.size()) {
        while (i2 < v2.size() && f[v2[i2].second]) i2++;
        if (i2 < v2.size() && !f[v2[i2].second]) {
          ans[q] = v2[i2].first;
          f[v2[i2].second] = 1;
          i2++;
        } else
          ans[q] = -1;
      } else if (x == 3 && i3 < v3.size()) {
        while (i3 < v3.size() && f[v3[i3].second]) i3++;
        if (i3 < v3.size() && !f[v3[i3].second]) {
          ans[q] = v3[i3].first;
          f[v3[i3].second] = 1;
          i3++;
        } else
          ans[q] = -1;
      } else
        ans[q] = -1;
      q++;
    }
    for (long long i = 0; i < q; i++) {
      printf("%d ", ans[i]);
    }
    puts("");
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.

You are given the integers written in the following three squares in a magic square:

* The integer A at the upper row and left column
* The integer B at the upper row and middle column
* The integer C at the middle row and middle column

Determine the integers written in the remaining squares in the magic square.

It can be shown that there exists a unique magic square consistent with the given information.

Constraints

* 0 \leq A, B, C \leq 100

Input

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

A
B
C

Output

Output the integers written in the magic square, in the following format:

X_{1,1} X_{1,2} X_{1,3}
X_{2,1} X_{2,2} X_{2,3}
X_{3,1} X_{3,2} X_{3,3}

where X_{i,j} is the integer written in the square at the i-th row and j-th column.

Examples

Input

8
3
5

Output

8 3 4
1 5 9
6 7 2

Input

1
1
1

Output

1 1 1
1 1 1
1 1 1

### Response

```cpp
#include<iostream>
using namespace std ;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a<<" "<<b<<" "<<3*c-a-b<<" "<<endl;
    cout<<4*c-2*a-b<<" "<<c<<" "<<2*a+b-2*c<<" "<<endl;
    cout<<a+b-c<<" "<<2*c-b<<" "<<2*c-a<<" "<<endl;
}
```


### Prompt

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

Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.

Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007 = 109 + 7.

Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.

Input

The only line contains three integers n, m and k (1 ≤ n, m ≤ 1018, k is either 1 or -1).

Output

Print a single number denoting the answer modulo 1000000007.

Examples

Input

1 1 -1

Output

1

Input

1 3 1

Output

1

Input

3 3 -1

Output

16

Note

In the first example the only way is to put -1 into the only block.

In the second example the only way is to put 1 into every block.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int k;
long long n, m, x, y;
const int MO = 1000000007;
long long powmod(long long n, long long m) {
  if (m == 0) return 1;
  if (m == 1)
    return n % MO;
  else
    return ((powmod(n, m / 2) * powmod(n, m / 2)) % MO * powmod(n, m % 2)) % MO;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  if (k == -1 && abs(n - m) % 2 == 1)
    cout << 0;
  else {
    x = powmod(2, n - 1);
    y = powmod(x, m - 1);
    cout << y;
  }
}

```


### Prompt

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

Ann and Borya have n piles with candies and n is even number. There are ai candies in pile with number i.

Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is new and doesn't belong to any other pile) or remove one candy (if there is at least one candy in this pile).

Find out minimal number of moves that is required to make exactly n / 2 piles contain number of candies that is a square of some integer and exactly n / 2 piles contain number of candies that is not a square of any integer.

Input

First line contains one even integer n (2 ≤ n ≤ 200 000) — number of piles with candies.

Second line contains sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 109) — amounts of candies in each pile.

Output

Output minimal number of steps required to make exactly n / 2 piles contain number of candies that is a square of some integer and exactly n / 2 piles contain number of candies that is not a square of any integer. If condition is already satisfied output 0.

Examples

Input

4
12 14 30 4

Output

2

Input

6
0 0 0 0 0 0

Output

6

Input

6
120 110 23 34 25 45

Output

3

Input

10
121 56 78 81 45 100 1 0 54 78

Output

0

Note

In first example you can satisfy condition in two moves. During each move you should add one candy to second pile. After it size of second pile becomes 16. After that Borya and Ann will have two piles with number of candies which is a square of integer (second and fourth pile) and two piles with number of candies which is not a square of any integer (first and third pile).

In second example you should add two candies to any three piles.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200001];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  priority_queue<long long, vector<long long>, greater<long long> > differences;
  priority_queue<long long, vector<long long>, greater<long long> >
      differences_2;
  int square_counter = 0;
  for (int i = 0; i < n; i++) {
    long long number = a[i];
    long long square_root = (long long)sqrt(number);
    if (square_root * square_root == number) {
      square_counter++;
      differences_2.push(number == 0 ? 2 : 1);
    } else {
      differences.push(min(number - square_root * square_root,
                           (square_root + 1) * (square_root + 1) - number));
    }
  }
  long long moves = 0;
  while (square_counter < n / 2) {
    square_counter++;
    moves += differences.top();
    differences.pop();
  }
  while (square_counter > n / 2) {
    square_counter--;
    moves += differences_2.top();
    differences_2.pop();
  }
  cout << moves << endl;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R and x = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0.

Input

The only line contains six integers a1, b1, a2, b2, L, R (0 < a1, a2 ≤ 2·109, - 2·109 ≤ b1, b2, L, R ≤ 2·109, L ≤ R).

Output

Print the desired number of integers x.

Examples

Input

2 0 3 3 5 21

Output

3

Input

2 4 3 0 6 17

Output

2

### Response

```cpp
#include <bits/stdc++.h>
template <class T>
inline void chkmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void read(T &x) {
  char c;
  int f = 1;
  x = 0;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    f = -1;
  else
    x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= f;
}
long long extgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long long ret = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return ret;
}
long long ceil(long long u, long long v) {
  long long t = u / v;
  if (t * v < u) ++t;
  return t;
}
long long floor(long long u, long long v) {
  long long t = u / v;
  if (t * v > u) --t;
  return t;
}
long long fmm(long long a, long long b, long long mod) {
  long long ret = 0;
  while (b) {
    if (b & 1) (ret += a) %= mod;
    (a += a) %= mod, b >>= 1;
  }
  return ret;
}
int main() {
  long long a1, b1, a2, b2, L, R;
  read(a1), read(b1), read(a2), read(b2), read(L), read(R);
  if (b2 < b1) std::swap(a1, a2), std::swap(b1, b2);
  long long x, y, gcd = extgcd(a1, a2, x, y);
  if ((b2 - b1) % gcd)
    puts("0");
  else {
    long long t = (b2 - b1) / gcd;
    x *= t, y *= t;
    long long u = a1 * a2 / gcd, v = fmm((x % u + u) % u, a1, u) + b1;
    long long l = ceil(L - v, u), r = floor(R - v, u);
    chkmax(l, std::max(ceil(b1 - v, u), ceil(b2 - v, u)));
    if (l > r)
      puts("0");
    else
      std::cout << r - l + 1 << std::endl;
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

A balancing network is an abstract device built up of N wires, thought of as running from left to right, and M balancers that connect pairs of wires. The wires are numbered from 1 to N from top to bottom, and the balancers are numbered from 1 to M from left to right. Balancer i connects wires x_i and y_i (x_i < y_i).

pic1-small-2acea94b.png

Each balancer must be in one of two states: up or down.

Consider a token that starts moving to the right along some wire at a point to the left of all balancers. During the process, the token passes through each balancer exactly once. Whenever the token encounters balancer i, the following happens:

* If the token is moving along wire x_i and balancer i is in the down state, the token moves down to wire y_i and continues moving to the right.
* If the token is moving along wire y_i and balancer i is in the up state, the token moves up to wire x_i and continues moving to the right.
* Otherwise, the token doesn't change the wire it's moving along.

Let a state of the balancing network be a string of length M, describing the states of all balancers. The i-th character is `^` if balancer i is in the up state, and `v` if balancer i is in the down state.

A state of the balancing network is called uniforming if a wire w exists such that, regardless of the starting wire, the token will always end up at wire w and run to infinity along it. Any other state is called non-uniforming.

You are given an integer T (1 \le T \le 2). Answer the following question:

* If T = 1, find any uniforming state of the network or determine that it doesn't exist.
* If T = 2, find any non-uniforming state of the network or determine that it doesn't exist.

Note that if you answer just one kind of questions correctly, you can get partial score.

Constraints

* 2 \leq N \leq 50000
* 1 \leq M \leq 100000
* 1 \leq T \leq 2
* 1 \leq x_i < y_i \leq N
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N M T
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print any uniforming state of the given network if T = 1, or any non-uniforming state if T = 2. If the required state doesn't exist, output `-1`.

Examples

Input

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

Output

^^^^^

Input

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

Output

v^^^^

Input

3 1 1
1 2

Output

-1

Input

2 1 2
1 2

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
bitset<50001> B[50005];
int main() {
	int n, m, t;
	scanf("%d%d%d", &n, &m, &t);
	vector<int> x(m), y(m);
	for (int i = 0; i < m; ++i) scanf("%d%d", &x[i], &y[i]);
	if (t == 2) {
		if (n < 3) {
			printf("-1\n");
			return 0;
		}
		auto dir = [](int a, int b) {
			return a > b ? '^' : 'v';
		};
		vector<pair<char, int>> p;
		int a = 1, b = 2, c = 3;
		int ab = -1, ac = -1;
		for (int i = 0; i < m; ++i) {
			if (y[i] == a) swap(x[i], y[i]);
			if (x[i] == a && y[i] == b) {
				p.emplace_back(dir(a, b), ac); // b-c
				p.emplace_back(dir(b, a), ac); // a-c
				swap(a, c);
			} else if (x[i] == a && y[i] == c) {
				p.emplace_back(dir(c, a), ab); // a-b
				p.emplace_back(dir(a, c), ab); // c-b
				swap(a, b);
			} else {
				// a-b
				p.emplace_back((y[i] == a || y[i] == b) ? dir(x[i], y[i]) : dir(y[i], x[i]), ab);
				// a-c
				p.emplace_back((y[i] == a || y[i] == c) ? dir(x[i], y[i]) : dir(y[i], x[i]), ac);
			}
			ab = p.size() - 2;
			ac = p.size() - 1;
		}
		string ans;
		for (; ab != -1;) {
			ans += p[ab].first;
			ab = p[ab].second;
		}
		reverse(ans.begin(), ans.end());
		printf("%s\n", ans.c_str());
		return 0;
	}
	for (int i = 1; i <= n; ++i) B[i][i] = 1;
	for (int i = m - 1; i >= 0; --i) {
		B[x[i]] |= B[y[i]];
		B[y[i]] = B[x[i]];
	}
	auto sum = B[1];
	for (int i = 2; i <= n; ++i) {
		sum &= B[i];
	}
	int take = -1;
	for (int i = 1; i <= n; ++i) {
		if (sum[i] == 1) {
			take = i;
			break;
		}
	}
	if (take == -1) printf("-1\n");
	else {
		auto b = sum;
		b.reset();
		b[take] = 1;
		string ans;
		for (int i = m - 1; i >= 0; --i) {
			if (b[x[i]] == 1) {
				b[y[i]] = 1;
				ans += '^';
			} else if (b[y[i]] == 1) {
				b[x[i]] = 1;
				ans += 'v';
			} else {
				ans += '^';
			}
		}
		reverse(ans.begin(), ans.end());
		printf("%s\n", ans.c_str());
	}
}

```


### Prompt

Create a solution in Cpp for the following problem:

There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.

Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities.

Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link <https://en.wikipedia.org/wiki/Expected_value>.

Input

The first line contains a single integer n (1 ≤ n ≤ 100000) — number of cities.

Then n - 1 lines follow. The i-th line of these lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the cities connected by the i-th road.

It is guaranteed that one can reach any city from any other by the roads.

Output

Print a number — the expected length of their journey. The journey starts in the city 1.

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

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

Examples

Input

4
1 2
1 3
2 4

Output

1.500000000000000

Input

5
1 2
1 3
3 4
2 5

Output

2.000000000000000

Note

In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.

In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int N;
double answer = 0;
vector<int> adjacency[MAXN];
void dfs(int current_node, int parent, double probability, int depth) {
  int num_children = 0;
  for (auto i : adjacency[current_node]) {
    if (i != parent) {
      num_children++;
    }
  }
  for (auto i : adjacency[current_node]) {
    if (i != parent) {
      dfs(i, current_node, double(probability / num_children), depth + 1);
    }
  }
  if (num_children == 0) {
    answer += probability * depth;
  }
}
int main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adjacency[u].push_back(v);
    adjacency[v].push_back(u);
  }
  dfs(0, 0, 1.0, 0);
  cout << fixed << setprecision(7) << answer << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.

Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.

A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.

On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood.

<image>

King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not.

Input

The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood.

Output

Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO".

Examples

Input

3
1 1 1

Output

YES

Input

6
1 0 1 1 1 0

Output

YES

Input

6
1 0 0 1 0 1

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long const M = 1000000007;
double const pi = acos(-1);
long long const inf = 2e18;
long long const N = 200001;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, t, n, k;
  cin >> n;
  vector<long long> a(n);
  bool ok = false;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      long long counter = n / i, mxi = 0;
      vector<long long> dp(n, 0);
      if (i != 2) {
        for (j = 0; j < n; j++) {
          if (a[j] == 1) {
            dp[j] = 1;
            if (j - counter >= 0) dp[j] += dp[j - counter];
          }
          mxi = max(mxi, dp[j]);
        }
      }
      if (mxi >= i) ok = true;
      counter = i, mxi = 0;
      for (j = 0; j < n; j++) dp[i] = 0;
      for (j = 0; j < n; j++) {
        if (a[j] == 1) {
          dp[j] = 1;
          if (j - counter >= 0) dp[j] += dp[j - counter];
        }
        mxi = max(mxi, dp[j]);
      }
      if (mxi >= (n / i) && (n / i != 2)) ok = true;
    }
    if (ok) break;
  }
  long long cnt = 0;
  for (i = 0; i < n; i++)
    if (a[i] == 1) cnt++;
  if (cnt == n) ok = true;
  if (ok)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not.

A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, "abc", "ab", and "c" are substrings of the string "abc", while "ac" and "d" are not.

Let's define a palindromic count of the string as the number of its substrings that are palindromes. For example, the palindromic count of the string "aaa" is 6 because all its substrings are palindromes, and the palindromic count of the string "abc" is 3 because only its substrings of length 1 are palindromes.

You are given a string s. You can arbitrarily rearrange its characters. You goal is to obtain a string with the maximum possible value of palindromic count.

Input

The first line contains an integer n (1 ≤ n ≤ 100 000) — the length of string s.

The second line contains string s that consists of exactly n lowercase characters of Latin alphabet.

Output

Print string t, which consists of the same set of characters (and each characters appears exactly the same number of times) as string s. Moreover, t should have the maximum possible value of palindromic count among all such strings strings.

If there are multiple such strings, print any of them.

Examples

Input

5
oolol

Output

ololo

Input

16
gagadbcgghhchbdf

Output

abccbaghghghgdfd

Note

In the first example, string "ololo" has 9 palindromic substrings: "o", "l", "o", "l", "o", "olo", "lol", "olo", "ololo". Note, that even though some substrings coincide, they are counted as many times as they appear in the resulting string.

In the second example, the palindromic count of string "abccbaghghghgdfd" is 29.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;
  sort(s.begin(), s.end());
  cout << s << '\n';
}

```


### Prompt

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

Sereja has two sequences a1, a2, ..., an and b1, b2, ..., bm, consisting of integers. One day Sereja got bored and he decided two play with them. The rules of the game was very simple. Sereja makes several moves, in one move he can perform one of the following actions:

  1. Choose several (at least one) first elements of sequence a (non-empty prefix of a), choose several (at least one) first elements of sequence b (non-empty prefix of b); the element of sequence a with the maximum index among the chosen ones must be equal to the element of sequence b with the maximum index among the chosen ones; remove the chosen elements from the sequences.
  2. Remove all elements of both sequences.

The first action is worth e energy units and adds one dollar to Sereja's electronic account. The second action is worth the number of energy units equal to the number of elements Sereja removed from the sequences before performing this action. After Sereja performed the second action, he gets all the money that he earned on his electronic account during the game.

Initially Sereja has s energy units and no money on his account. What maximum number of money can Sereja get? Note, the amount of Seraja's energy mustn't be negative at any time moment.

Input

The first line contains integers n, m, s, e (1 ≤ n, m ≤ 105; 1 ≤ s ≤ 3·105; 103 ≤ e ≤ 104). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105). The third line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 105).

Output

Print a single integer — maximum number of money in dollars that Sereja can get.

Examples

Input

5 5 100000 1000
1 2 3 4 5
3 2 4 5 1

Output

3

Input

3 4 3006 1000
1 2 3
1 2 4 3

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const int maxn = 1000 * 100 + 50;
int a[maxn], b[maxn], n, m, s, e, dp[maxn][300 + 20];
vector<int> v[maxn];
int main() {
  cin >> n >> m >> s >> e;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    v[b[i]].push_back(i);
  }
  for (int i = 0; i < maxn; i++) {
    for (int j = 0; j < 310; j++) {
      dp[i][j] = INF;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    dp[i][0] = 0;
    for (int j = 1; j <= min(i + 1, 300); j++) {
      int help = 0;
      if (i > 0) {
        dp[i][j] = dp[i - 1][j];
        help = dp[i - 1][j - 1];
      } else {
        dp[i][j] = INF;
      }
      if (v[a[i]].size() == 0) {
        continue;
      }
      int hh =
          lower_bound(v[a[i]].begin(), v[a[i]].end(), help) - v[a[i]].begin();
      if (hh == v[a[i]].size()) {
        continue;
      }
      dp[i][j] = min(dp[i][j], v[a[i]][hh] + 1);
      if (j * e + (i + 1 + dp[i][j]) <= s) {
        ans = max(ans, j);
      }
    }
  }
  cout << ans;
}

```


### Prompt

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

PMP is getting a warrior. He is practicing a lot, but the results are not acceptable yet. This time instead of programming contests, he decided to compete in a car racing to increase the spirit of victory. He decides to choose a competition that also exhibits algorithmic features.

AlgoRace is a special league of car racing where different teams compete in a country of n cities. Cities are numbered 1 through n. Every two distinct cities in the country are connected with one bidirectional road. Each competing team should introduce one driver and a set of cars.

The competition is held in r rounds. In i-th round, drivers will start at city si and finish at city ti. Drivers are allowed to change their cars at most ki times. Changing cars can take place in any city in no time. One car can be used multiple times in one round, but total number of changes should not exceed ki. Drivers can freely choose their path to destination.

PMP has prepared m type of purpose-built cars. Beside for PMP’s driving skills, depending on properties of the car and the road, a car traverses each road in each direction in different times.

PMP Warriors wants to devise best strategies of choosing car and roads in each round to maximize the chance of winning the cup. For each round they want to find the minimum time required to finish it.

Input

The first line contains three space-separated integers n, m, r (2 ≤ n ≤ 60, 1 ≤ m ≤ 60, 1 ≤ r ≤ 105) — the number of cities, the number of different types of cars and the number of rounds in the competition, correspondingly.

Next m sets of n × n matrices of integers between 0 to 106 (inclusive) will follow — describing the time one car requires to traverse different roads. The k-th integer in j-th line of the i-th set is the time that i-th car requires to traverse the road from j-th city to k-th city. These matrices are not necessarily symmetric, but their diagonal is always zero.

Next r lines contain description of the rounds. The i-th of these lines contains space-separated integers si, ti, ki (1 ≤ si, ti ≤ n, si ≠ ti, 0 ≤ ki ≤ 1000) — the number of starting city, finishing city and the number of possible car changes in i-th round, correspondingly.

Output

For each round you should print the minimum required time to complete the round in a single line.

Examples

Input

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

Output

3
4
3

Input

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

Output

4
5
3

Note

In the first sample, in all rounds PMP goes from city #1 to city #2, then city #3 and finally city #4. But the sequences of types of the cars he uses are (1, 2, 1) in the first round and (1, 2, 2) in the second round. In the third round, although he can change his car three times, he uses the same strategy as the first round which only needs two car changes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int d[70][70][70];
int dp[70][70][1010];
int r, s, k, n, m, t;
void floyd(int x) {
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        d[x][i][j] = min(d[x][i][j], d[x][i][k] + d[x][k][j]);
}
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      for (int w = 1; w <= n; w++) scanf("%d", &d[i][j][w]);
  for (int i = 1; i <= m; i++) floyd(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int w = 0; w <= 1000; w++) dp[i][j][w] = inf;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int w = 1; w <= m; w++) dp[i][j][0] = min(dp[i][j][0], d[w][i][j]);
  for (int l = 1; l <= 300; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int w = 1; w <= n; w++)
          dp[i][j][l] = min(dp[i][j][l], dp[i][w][l - 1] + dp[w][j][0]);
  while (r--) {
    scanf("%d%d%d", &s, &t, &k);
    if (k > 300) k = 300;
    printf("%d\n", dp[s][t][k]);
  }
  return 0;
}

```


### Prompt

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

Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.

Now he wonders what is an average value of sum of digits of the number A written in all bases from 2 to A - 1.

Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.

Input

Input contains one integer number A (3 ≤ A ≤ 1000).

Output

Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.

Examples

Input

5

Output

7/3

Input

3

Output

2/1

Note

In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  unsigned long long int sum = 0;
  cin >> a;
  int array2[a];
  for (int i = 2; i < a; i++) {
    for (int n = 0; n < a; n++) array2[n] = 0;
    for (int j = 0, k = a; k != 0; j++) {
      array2[j] = k % i;
      k /= i;
    }
    for (int c = 0; c < a; c++) sum += array2[c];
  }
  int k = a - 2;
  unsigned long long int m = sum;
  for (int i = 2; i < sum; i++)
    while (1) {
      if (k % i == 0 && m % i == 0) {
        k /= i;
        m /= i;
      } else
        break;
    }
  cout << m << "/" << k << endl;
  return 0;
}

```