### Prompt

Develop a solution in Cpp to the problem described below:

Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.

There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and ri soldiers, who start to march from right leg.

The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.

No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index i and swap values li and ri.

Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.

The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.

Output

Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.

Consider that columns are numbered from 1 to n in the order they are given in the input data.

If there are several answers, print any of them.

Examples

Input

3
5 6
8 9
10 3

Output

3

Input

2
6 5
5 6

Output

1

Input

6
5 9
1 3
4 8
4 5
23 54
12 32

Output

0

Note

In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.

If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.

It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n;
  int ans = 0;
  int cha = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x1, x2;
    scanf("%d%d", &x1, &x2);
    a[i] = x1 - x2;
    cha += a[i];
  }
  int tmp = cha;
  int tmp1 = tmp;
  for (int i = 1; i <= n; i++) {
    cha -= 2 * a[i];
    if (fabs(cha) > fabs(tmp)) {
      ans = i;
      tmp = cha;
    }
    cha = tmp1;
  }
  printf("%d\n", ans);
}

```


### Prompt

Please create a solution in CPP to the following problem:

The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...

Given is a string S representing the weather in the town today. Predict the weather tomorrow.

Constraints

* S is `Sunny`, `Cloudy`, or `Rainy`.

Input

Input is given from Standard Input in the following format:

S

Output

Print a string representing the expected weather tomorrow, in the same format in which input is given.

Examples

Input

Sunny

Output

Cloudy

Input

Rainy

Output

Sunny

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
  string S,T;
  cin>>S;
  S=="Sunny" ? T="Cloudy" : S=="Cloudy" ? T="Rainy" : T="Sunny";
  cout<<T<<endl;
}

```


### Prompt

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

Taro loves chocolate and when he returns from school he eats his favorite chocolate bar with a heart symbol on it. A recent pleasure is to eat all the heart symbol blocks to the end. Taro , Try to eat as many heartless blocks as possible, with all heartmark blocks connected.

<image>

However, Taro is still young, and even if he tries to eat as above, useless blocks will remain. Therefore, Taro seeks the maximum number of blocks that can be eaten when all the heart-shaped blocks are left connected. I asked you to create a program.

Taro can eat whatever way he wants, as long as all the heart-shaped blocks are connected. If one side of one block does not touch the other block, it will be separated.

Input

The input consists of multiple datasets, each dataset given in the following format:

H W
H x W numbers

H and W are integers indicating the vertical size and horizontal size of the chocolate bar, respectively. H x W numbers represent block information, '0' representing blocks without a heart mark, and blocks with a heart mark. Consists of '1'.

The end of the input is indicated by the dataset where H = W = 0. Do not output for this case.

You can assume that 1 ≤ H, W ≤ 12 and the number of heart-shaped blocks is 6 or less.

Output

For each dataset, output the maximum number of blocks that Taro can eat.

Example

Input

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

Output

7
0
2

### Response

```cpp
#include<vector>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int inf = 987654321;

// ツ氾アツ閉可づ個鳴ウツ古シツグツδ可フツづ可妥篠つオツ、ツタツーツミツナツδ逆sツづ個要ツ素ツづーツ全ツづ甘慊づ楪催渉ャツづ個姪伉づ個コツスツトツづーツ仰づ淞づゥ
#define REP(i, N) for(int i = 0; i < (int)(N); ++i)

const int MAX_N = 150;
int g[MAX_N][MAX_N];
int minimum_steiner_tree(int n, const vector<int> ts) {
  static int dp[1 << 12][MAX_N];
  memset(dp, 0, sizeof(dp));
  int m = ts.size();
  if( m < 2 ) return 0;

  REP(k, n) REP(i, n) REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  REP(i, m) REP(j, n) dp[1 << i][j] = g[ts[i]][j];

  for(int i = 1; i < 1 << m; i++) if((i - 1) & i) {
      REP(j, n) {
        dp[i][j] = inf;
        for(int k = (i - 1) & i; k > 0 ; k = (k - 1) & i)
          dp[i][j] = min(dp[i][j], dp[k][j] + dp[i ^ k][j]);
      }
      REP(j, n) REP(k, n) dp[i][j] = min(dp[i][j], dp[i][k] + g[k][j]);
    }
  return dp[(1 << m) - 1][ts[0]];
}

int main() {
  for(int R, C; cin >> R >> C, (R || C); ) {
    REP(i, MAX_N) REP(j, MAX_N) g[i][j] = inf;
    REP(i, MAX_N) g[i][i] = 0;

    int table[R][C];
    REP(r, R) REP(c, C) cin >> table[r][c];

    const int dr[] = {0, 1, -1, 0};
    const int dc[] = {1, 0, 0, -1};
    REP(r, R) REP(c, C) REP(k, 4) {
      int nr = r + dr[k];
      int nc = c + dc[k];
      if( 0 <= nr && nr < R && 0 <= nc && nc < C )
        g[r * C + c][nr * C + nc] = 1;
    }
    vector<int> ts;
    REP(r, R) REP(c, C) if( table[r][c] == 1 ) ts.push_back(r * C + c);

    int temp = minimum_steiner_tree(R * C, ts);
    cout << R * C - temp - 1 << endl;
  }
}
```


### Prompt

Generate a cpp solution to the following problem:

Life in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are n junctions and m two way roads, at which one can get from each junction to any other one. The mayor wants to close some roads so that the number of roads left totaled to n - 1 roads and it were still possible to get from each junction to any other one. Besides, the mayor is concerned with the number of dead ends which are the junctions from which only one road goes. There shouldn't be too many or too few junctions. Having discussed the problem, the mayor and his assistants decided that after the roads are closed, the road map should contain exactly k dead ends. Your task is to count the number of different ways of closing the roads at which the following conditions are met:

  * There are exactly n - 1 roads left.
  * It is possible to get from each junction to any other one.
  * There are exactly k dead ends on the resulting map.

Two ways are considered different if there is a road that is closed in the first way, and is open in the second one.

Input

The first line contains three integers n, m and k (3 ≤ n ≤ 10, n - 1 ≤ m ≤ n·(n - 1) / 2, 2 ≤ k ≤ n - 1) which represent the number of junctions, roads and dead ends correspondingly. Then follow m lines each containing two different integers v1 and v2 (1 ≤ v1, v2 ≤ n, v1 ≠ v2) which represent the number of junctions connected by another road. There can be no more than one road between every pair of junctions. The junctions are numbered with integers from 1 to n. It is guaranteed that it is possible to get from each junction to any other one along the original roads.

Output

Print a single number — the required number of ways.

Examples

Input

3 3 2
1 2
2 3
1 3

Output

3

Input

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

Output

12

Input

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

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int graph[10][10];
int dp[3000][3000];
int n, m, k, N, a, b, ans;
int bitCount(int val) {
  int retVal = 0;
  for (int i = 0; i < 32; i++)
    if ((val & (1 << i)) != 0) retVal++;
  return retVal;
}
int main() {
  cin >> n >> m >> k;
  N = (1 << (n));
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    graph[b][a] = graph[--a][--b] = 1;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (graph[i][j] == 1) dp[(1 << i) + (1 << j)][(1 << i) + (1 << j)] = 1;
  for (int i = 0; i < N; i++)
    if (bitCount(i) > 2)
      for (int j = 0; j < N; j++) {
        for (int k = 0; k < n; k++)
          if ((i & (1 << k)) && (j & (1 << k)))
            for (int r = 0; r < n; r++)
              if (graph[k][r] == 1 && (i & (1 << r)) && !(j & (1 << r)))
                dp[i][j] += dp[i - (1 << k)][j - (1 << k)] +
                            dp[i - (1 << k)][j - (1 << k) + (1 << r)];
        dp[i][j] /= (bitCount(j) != 0 ? bitCount(j) : 1);
      }
  for (int i = 0; i < N; i++)
    if (bitCount(i) == k) ans += dp[(1 << (n)) - 1][i];
  cout << ans;
  return 0;
}

```


### Prompt

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

Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:

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

Your task is to determine the way the handkerchief will look like by the given n.

Input

The first line contains the single integer n (2 ≤ n ≤ 9).

Output

Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.

Examples

Input

2

Output

    0
  0 1 0
0 1 2 1 0
  0 1 0
    0

Input

3

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ABS(int x) { return x > 0 ? x : -x; }
int main() {
  int i, j, k, csnum, cs;
  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < 2 * n + 1; i++) {
      if (i > n)
        k = 2 * n - i;
      else
        k = i;
      for (j = 0; j < 2 * (n - k); j++) printf(" ");
      printf("0");
      for (j = 1; j < 2 * k + 1; j++) {
        if (j > k)
          printf(" %d", 2 * k - j);
        else
          printf(" %d", j);
      }
      printf("\n");
    }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

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

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

Input

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

Output

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

Examples

Input

3000

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, p;
  cin >> n;
  p = n - (n / 2 + n / 3 + n / 5 + n / 7) +
      (n / 14 + n / 6 + n / 15 + n / 35 + n / 10 + n / 21) -
      (n / 42 + n / 30 + n / 105 + n / 70) + (n / 210);
  cout << p;
  return 0;
}

```


### Prompt

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

We have N bricks arranged in a row from left to right.

The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.

Among them, you can break at most N-1 bricks of your choice.

Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K), the i-th of those brick from the left has the integer i written on it.

Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print `-1` instead.

Constraints

* All values in input are integers.
* 1 \leq N \leq 200000
* 1 \leq a_i \leq N

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print `-1` if his desire is unsatisfiable.

Examples

Input

3
2 1 2

Output

1

Input

3
2 2 2

Output

-1

Input

10
3 1 4 1 5 9 2 6 5 3

Output

7

Input

1
1

Output

0

### Response

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


### Prompt

Develop a solution in Cpp to the problem described below:

Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence a0, a1, ..., ah, where h is the height of the tree, and ai equals to the number of vertices that are at distance of i edges from root.

Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence ai, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree.

Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal.

The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex.

Input

The first line contains a single integer h (2 ≤ h ≤ 105) — the height of the tree.

The second line contains h + 1 integers — the sequence a0, a1, ..., ah (1 ≤ ai ≤ 2·105). The sum of all ai does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence.

Output

If there is only one tree matching this sequence, print "perfect".

Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print <image> integers, the k-th of them should be the parent of vertex k or be equal to zero, if the k-th vertex is the root.

These treese should be non-isomorphic and should match the given sequence.

Examples

Input

2
1 1 1

Output

perfect

Input

2
1 2 2

Output

ambiguous
0 1 1 3 3
0 1 1 3 2

Note

The only tree in the first example and the two printed trees from the second example are shown on the picture:

<image>

### Response

```cpp
#include <bits/stdc++.h>
inline void _RD(int &x) { scanf("%d", &x); }
inline void _RD(long long &x) { scanf("%lld", &x); }
inline void _RD(double &x) { scanf("%lf", &x); }
inline void _RD(long double &x) { scanf("%Lf", &x); }
inline void _RD(char &x) { scanf(" %c", &x); }
inline void RD() {}
template <class T, class... U>
inline void RD(T &head, U &...tail) {
  _RD(head);
  RD(tail...);
}
using namespace std;
using LL = long long;
using VI = vector<int>;
using VLL = vector<LL>;
using VVI = vector<VI>;
int main() {
  int h, j;
  RD(h);
  VI a(h + 1);
  for (int i = (0); i <= (h); ++i) {
    RD(j);
    a[i] = j;
  }
  VI s = {0}, t = s;
  int l = 1, r = 1;
  for (int i = (1); i <= (h); ++i) {
    int now = l;
    for (int j = (r + 1); j <= (r + a[i]); ++j) {
      s.push_back(now);
      if (++now > r) now = l;
      t.push_back(l);
    }
    l = r + 1;
    r += a[i];
  }
  if (s == t)
    printf("perfect\n");
  else {
    printf("ambiguous\n");
    for (auto x : (s)) printf("%d ", x);
    printf("\n");
    for (auto x : (t)) printf("%d ", x);
    printf("\n");
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume.

You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one task at a time, and no more than two tasks total. The first task can be any, the second task on each computer must use strictly less power than the first. You will assign between 1 and 2 tasks to each computer. You will then first execute the first task on each computer, wait for all of them to complete, and then execute the second task on each computer that has two tasks assigned.

If the average compute power per utilized processor (the sum of all consumed powers for all tasks presently running divided by the number of utilized processors) across all computers exceeds some unknown threshold during the execution of the first tasks, the entire system will blow up. There is no restriction on the second tasks execution. Find the lowest threshold for which it is possible.

Due to the specifics of the task, you need to print the answer multiplied by 1000 and rounded up.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of tasks.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108), where ai represents the amount of power required for the i-th task.

The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 100), where bi is the number of processors that i-th task will utilize.

Output

Print a single integer value — the lowest threshold for which it is possible to assign all tasks in such a way that the system will not blow up after the first round of computation, multiplied by 1000 and rounded up.

Examples

Input

6
8 10 9 9 8 10
1 1 1 1 1 1

Output

9000

Input

6
8 10 9 9 8 10
1 10 5 5 1 10

Output

1160

Note

In the first example the best strategy is to run each task on a separate computer, getting average compute per processor during the first round equal to 9.

In the second task it is best to run tasks with compute 10 and 9 on one computer, tasks with compute 10 and 8 on another, and tasks with compute 9 and 8 on the last, averaging (10 + 10 + 9) / (10 + 10 + 5) = 1.16 compute power per processor during the first round.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 70;
struct A {
  long long x, y;
} a[N];
long long n, m;
long long f[N][N][N];
bool cmp(A x, A y) { return x.x > y.x; }
long long gt(A x) {
  if (x.x == 0) return (1 << 30);
  return (double(x.x) / double(x.y));
}
bool dp(long long ans) {
  memset(f, 127, sizeof(f));
  f[1][0][0] = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= i; j++) {
      for (long long k = 0; k <= i - j; k++) {
        if (a[i + 1].x != a[i].x) {
          if (j != 0)
            f[i + 1][j + k - 1][0] = min(f[i + 1][j + k - 1][0], f[i][j][k]);
          f[i + 1][j + k + 1][0] =
              min(f[i + 1][j + k + 1][0], f[i][j][k] + a[i].x - a[i].y * ans);
        }
        if (j != 0) f[i + 1][j - 1][k] = min(f[i + 1][j - 1][k], f[i][j][k]);
        f[i + 1][j][k + 1] =
            min(f[i + 1][j][k + 1], f[i][j][k] + a[i].x - a[i].y * ans);
      }
    }
  }
  long long x = 1125899906842624;
  for (long long i = 0; i <= n + 1; i++)
    for (long long j = 0; j <= n + 1; j++) x = min(x, f[n + 1][i][j]);
  return (x <= 0);
}
int main() {
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i].x), a[i].x *= 1000;
  for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i].y);
  sort(a + 1, a + n + 1, cmp);
  long long ans = 0;
  long long l = 0, r = 1125899906842624, mid;
  while (r >= l) {
    mid = (l + r) / 2;
    if (dp(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%I64d", ans);
  return 0;
}

```


### Prompt

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

A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.

The tournament takes place in the following way (below, m is the number of the participants of the current round):

  * let k be the maximal power of the number 2 such that k ≤ m,
  * k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
  * when only one participant remains, the tournament finishes.

Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.

Find the number of bottles and towels needed for the tournament.

Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).

Input

The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.

Output

Print two integers x and y — the number of bottles and towels need for the tournament.

Examples

Input

5 2 3

Output

20 15

Input

8 2 4

Output

35 32

Note

In the first example will be three rounds:

  1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
  2. in the second round will be only one match, so we need another 5 bottles of water,
  3. in the third round will also be only one match, so we need another 5 bottles of water.

So in total we need 20 bottles of water.

In the second example no participant will move on to some round directly.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, b, p;
  cin >> n >> b >> p;
  cout << (n - 1) * (2 * b + 1) << " " << n * p;
  return 0;
}

```


### Prompt

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

Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i. The process of generating an integer is done independently each time the generator is executed.

Snuke has an integer X, which is now 0. He can perform the following operation any number of times:

* Generate an integer v with the generator and replace X with X \oplus v, where \oplus denotes the bitwise XOR.

For each integer i (0 \leq i \leq 2^N-1), find the expected number of operations until X becomes i, and print it modulo 998244353. More formally, represent the expected number of operations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353, so print this R.

We can prove that, for every i, the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined.

Constraints

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

Input

Input is given from Standard Input in the following format:

N
A_0 A_1 \cdots A_{2^N-1}

Output

Print 2^N lines. The (i+1)-th line (0 \leq i \leq 2^N-1) should contain the expected number of operations until X becomes i, modulo 998244353.

Examples

Input

2
1 1 1 1

Output

0
4
4
4

Input

2
1 2 1 2

Output

0
499122180
4
499122180

Input

4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355

Output

0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908

### Response

```cpp
// Never let them see you bleed...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = (1<<18) + 10, mod = 998244353, inf = 1e9 + 10;

int Pow(int a, int b){
    int ans = 1;
    for(; b; b>>=1, a = 1ll * a * a % mod)
	if(b&1)
	    ans = 1ll * ans * a % mod;
    return ans;
}
void ntt(int *a, int n, bool rev){
    int N = 1<<n;
    for(int stp = 0; stp < n; stp++){
	int ln = 1<<stp;
	for(int l = 0; l < N; l+= ln + ln){
	    for(int i = 0; i < ln; i++){
		int A = a[l + i], B = a[l + ln + i];
		a[l + i] = (A + B) % mod;
		a[l + ln + i] = (A - B) % mod;
	    }
	}
    }
    if(rev){
	int x = Pow(1<<n, mod-2);
	for(int i = 0; i < N; i++){
	    a[i] = 1ll * a[i] * x % mod;
	}
    }
}

int p[maxn];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int n, sm = 0;
    cin >> n;
    for(int i = 0; i < (1<<n); i++){
	cin >> p[i];
	sm+= p[i];
    }
    for(int i = 0; i < (1<<n); i++){
	p[i] = 1ll * p[i] * Pow(sm, mod-2) % mod;
    }
    p[0]--;
    sm = 0;
    ntt(p, n, 0);
    for(int i = 1; i < (1<<n); i++){
	p[i] = 1ll * Pow(p[i], mod-2) * (1<<n) % mod;
	sm = (sm + p[i]) % mod;
    }
    p[0] = -sm;

    ntt(p, n, 1);
    for(int i = 0; i < (1<<n); i++){
	cout << (p[i] + mod) % mod << "\n";
    }
    return 0;
}

```


### Prompt

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

<image>

The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.

One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.

Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.

You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.

Input

The input consists of a number of datasets, each corresponding to a contestant's performance. There are no more than 20 datasets in the input.

A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges' names are kept secret.

The end of the input is indicated by a line with a single zero in it.

Output

For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.

Example

Input

3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0

Output

342
7
300
326

### Response

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

int main(){
	int n,s,min,max,sum;

	while(cin>>n && n>0){
		max=0;
		sum=0;
		for(int i=0;i<n;i++){
			cin>>s;
			sum+=s;
			if(i==0) min=s;
			if(s>max) max=s;
			if(s<min) min=s;
		}
		cout<<(sum-max-min)/(n-2)<<endl;
	}
}
```


### Prompt

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

Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.

He knows that the receptionist starts working after ts minutes have passed after midnight and closes after tf minutes have passed after midnight (so that (tf - 1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves).

Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.

<image> "Reception 1"

For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.

Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!

Input

The first line contains three integers: the point of time when the receptionist begins to work ts, the point of time when the receptionist stops working tf and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.

All times are set in minutes and do not exceed 1012; it is guaranteed that ts < tf. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.

Output

Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.

Examples

Input

10 15 2
2
10 13

Output

12

Input

8 17 3
4
3 4 5 8

Output

2

Note

In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.

In the second example, Vasya has to come before anyone else to be served.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int tbegin, tend, t;
int n;
long long int a[100050];
int main() {
  cin >> tbegin >> tend >> t;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  a[n++] = tend - t + 1;
  sort(a, a + n);
  long long Min = 1e15;
  long long endtime = tbegin;
  long long int Time = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > 0) {
      long long temp = max((long long)0, endtime - a[i] + 1);
      if (endtime + t <= tend) {
        if (Min > temp) {
          Min = temp;
          Time = a[i] - 1;
        }
      }
    }
    endtime = max(endtime + t, a[i] + t);
  }
  cout << Time << endl;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.

Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a sequence of numbers such that each element of this sequence is being mapped into the next element of this sequence (and the last element of the cycle is being mapped into the first element of the cycle). The cyclic representation is a representation of p as a collection of cycles forming p. For example, permutation p = [4, 1, 6, 2, 5, 3] has a cyclic representation that looks like (142)(36)(5) because 1 is replaced by 4, 4 is replaced by 2, 2 is replaced by 1, 3 and 6 are swapped, and 5 remains in place.

Permutation may have several cyclic representations, so Kyoya defines the standard cyclic representation of a permutation as follows. First, reorder the elements within each cycle so the largest element is first. Then, reorder all of the cycles so they are sorted by their first element. For our example above, the standard cyclic representation of [4, 1, 6, 2, 5, 3] is (421)(5)(63).

Now, Kyoya notices that if we drop the parenthesis in the standard cyclic representation, we get another permutation! For instance, [4, 1, 6, 2, 5, 3] will become [4, 2, 1, 5, 6, 3].

Kyoya notices that some permutations don't change after applying operation described above at all. He wrote all permutations of length n that do not change in a list in lexicographic order. Unfortunately, his friend Tamaki Suoh lost this list. Kyoya wishes to reproduce the list and he needs your help. Given the integers n and k, print the permutation that was k-th on Kyoya's list.

Input

The first line will contain two integers n, k (1 ≤ n ≤ 50, 1 ≤ k ≤ min{1018, l} where l is the length of the Kyoya's list).

Output

Print n space-separated integers, representing the permutation that is the answer for the question.

Examples

Input

4 3

Output

1 3 2 4

Input

10 1

Output

1 2 3 4 5 6 7 8 9 10

Note

The standard cycle representation is (1)(32)(4), which after removing parenthesis gives us the original permutation. The first permutation on the list would be [1, 2, 3, 4], while the second permutation would be [1, 2, 4, 3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long fib[1005];
void pre() {
  fib[0] = 0;
  fib[1] = 1;
  fib[2] = 2;
  for (int i = 3; i < 1005; i++) fib[i] = fib[i - 1] + fib[i - 2];
}
int n;
long long k;
int ans[105];
int main() {
  pre();
  while (cin >> n >> k) {
    for (int i = 1; i <= 100; i++) ans[i] = i;
    k--;
    for (int i = 1; i < n; i++) {
      int cnt = n - i + 1;
      if (k <= fib[cnt] && k >= fib[cnt - 1]) {
        k -= fib[cnt - 1];
        swap(ans[i], ans[i + 1]);
        i++;
      }
    }
    for (int i = 1; i <= n; i++) {
      printf("%d ", ans[i]);
    }
    printf("\n");
  }
}

```


### Prompt

Generate a CPP solution to the following problem:

There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n.

Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).

Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} (note that i_j < i_{j+1}, because Orac arranged them properly), i_{j+1} is divisible by i_j and s_{i_j} < s_{i_{j+1}}.

For example, for 6 models with sizes \{3, 6, 7, 7, 7, 7\}, he can buy models with indices 1, 2, and 6, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.

Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.

Input

The first line contains one integer t\ (1 ≤ t≤ 100): the number of queries.

Each query contains two lines. The first line contains one integer n\ (1≤ n≤ 100 000): the number of models in the shop, and the second line contains n integers s_1,...,s_n\ (1≤ s_i≤ 10^9): the sizes of models.

It is guaranteed that the total sum of n is at most 100 000.

Output

Print t lines, the i-th of them should contain the maximum number of models that Orac can buy for the i-th query.

Example

Input

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

Output

2
3
1
1

Note

In the first query, for example, Orac can buy models with indices 2 and 4, the arrangement will be beautiful because 4 is divisible by 2 and 6 is more than 3. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.

In the second query, Orac can buy models with indices 1, 3, and 6. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.

In the third query, there are no beautiful arrangements with more than one model.

### Response

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

```


### Prompt

Please formulate a CPP solution to the following problem:

We have N+M balls, each of which has an integer written on it.
It is known that:

* The numbers written on N of the balls are even.
* The numbers written on M of the balls are odd.

Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.
It can be shown that this count does not depend on the actual values written on the balls.

Constraints

* 0 \leq N,M \leq 100
* 2 \leq N+M
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the answer.

Examples

Input

2 1

Output

1

Input

4 3

Output

9

Input

1 1

Output

0

Input

13 3

Output

81

Input

0 3

Output

3

### Response

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

int main() {
  int N,M;
  cin>>N>>M;
  cout<<(N*(N-1))/2+(M*(M-1))/2<<endl;
}
```


### Prompt

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

There are n students at Berland State University. Every student has two skills, each measured as a number: ai — the programming skill and bi — the sports skill.

It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to take part in the programming track and one to take part in the sports track.

There should be exactly p students in the programming team and exactly s students in the sports team. A student can't be a member of both teams.

The university management considers that the strength of the university on the Olympiad is equal to the sum of two values: the programming team strength and the sports team strength. The strength of a team is the sum of skills of its members in the corresponding area, so the strength of the programming team is the sum of all ai and the strength of the sports team is the sum of all bi over corresponding team members.

Help Berland State University to compose two teams to maximize the total strength of the university on the Olympiad.

Input

The first line contains three positive integer numbers n, p and s (2 ≤ n ≤ 3000, p + s ≤ n) — the number of students, the size of the programming team and the size of the sports team.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 3000), where ai is the programming skill of the i-th student.

The third line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ 3000), where bi is the sports skill of the i-th student.

Output

In the first line, print the the maximum strength of the university on the Olympiad. In the second line, print p numbers — the members of the programming team. In the third line, print s numbers — the members of the sports team.

The students are numbered from 1 to n as they are given in the input. All numbers printed in the second and in the third lines should be distinct and can be printed in arbitrary order.

If there are multiple solutions, print any of them.

Examples

Input

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

Output

18
3 4
1 5

Input

4 2 2
10 8 8 3
10 7 9 4

Output

31
1 2
3 4

Input

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

Output

23
1 3 5
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int mem[3010][3010], S, P, n;
pair<int, int> nxt[3010][3010];
struct pnt {
  int x, y, idx;
} a[3010];
int dp(int x, int s) {
  if ((s >= S) && (x - s) >= P) {
    return 0;
  }
  if (x == n) {
    return -1e9;
  }
  if (mem[x][s] != -1) {
    return mem[x][s];
  }
  int res = 0, tmp;
  if (s < S) {
    tmp = a[x].y + dp(x + 1, s + 1);
    if (tmp > res) {
      res = tmp;
      nxt[x][s] = make_pair(s + 1, 2);
    }
  }
  if ((x - s) < P) {
    tmp = a[x].x + dp(x + 1, s);
    if (tmp > res) {
      res = tmp;
      nxt[x][s] = make_pair(s, 1);
    }
  } else {
    tmp = dp(x + 1, s);
    if (tmp > res) {
      res = tmp;
      nxt[x][s] = make_pair(s, 0);
    }
  }
  mem[x][s] = res;
  return res;
}
bool operator<(pnt c, pnt v) {
  if (c.x == v.x) return c.y > v.y;
  return c.x > v.x;
}
int main() {
  cin >> n >> P >> S;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].x;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i].y;
    a[i].idx = i;
  }
  sort(a, a + n);
  memset(mem, -1, sizeof mem);
  cout << dp(0, 0) << endl;
  int tmp = 0, cnt = 0;
  pair<int, int> pr;
  for (int i = 0; cnt < P; ++i) {
    pr = nxt[i][tmp];
    tmp = pr.first;
    if (pr.second == 1) {
      cout << a[i].idx + 1 << " ";
      ++cnt;
    }
  }
  cout << endl;
  tmp = 0;
  cnt = 0;
  for (int i = 0; cnt < S; ++i) {
    pr = nxt[i][tmp];
    tmp = pr.first;
    if (pr.second == 2) {
      cout << a[i].idx + 1 << " ";
      ++cnt;
    }
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

From beginning till end, this message has been waiting to be conveyed.

For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:

  * Remove any two elements s and t from the set, and add their concatenation s + t to the set.

The cost of such operation is defined to be <image>, where f(s, c) denotes the number of times character c appears in string s.

Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.

Input

The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.

Output

Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.

Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.

Examples

Input

12

Output

abababab

Input

3

Output

codeforces

Note

For the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:

  * {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;
  * {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;
  * {"abab", "a", "b", "a", "b"}, with a cost of 1;
  * {"abab", "ab", "a", "b"}, with a cost of 0;
  * {"abab", "aba", "b"}, with a cost of 1;
  * {"abab", "abab"}, with a cost of 1;
  * {"abababab"}, with a cost of 8.

The total cost is 12, and it can be proved to be the minimum cost of the process.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int tmp = 0;
  if (n == 0) {
    cout << "a" << endl;
    return 0;
  }
  for (int i = 1000; i > 0; i--) {
    if (n == 0) break;
    if ((i * (i - 1)) / 2 <= n) {
      n -= (i * (i - 1)) / 2;
      for (int j = 0; j < i; j++) s += char(tmp + 'a');
      tmp++;
      i++;
    }
  }
  cout << s << endl;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (<https://en.wikipedia.org/wiki/Seven-segment_display>).

<image>

Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.

For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.

Input

The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.

Output

Print the only integer a — the total number of printed segments.

Examples

Input

1 3

Output

12

Input

10 15

Output

39

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int cal(int n) {
  if (n == 0 || n == 6 || n == 9)
    return 6;
  else if (n == 2 || n == 3 || n == 5)
    return 5;
  else if (n == 1)
    return 2;
  else if (n == 4)
    return 4;
  else if (n == 7)
    return 3;
  else if (n == 8)
    return 7;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int a, b, ans = 0;
  cin >> a >> b;
  for (int i = a; i <= b; i++)
    for (int j = 1; i / j > 0; j *= 10) ans += cal((i / j) % 10);
  return cout << ans << endl, 0;
}

```


### Prompt

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

This is an interactive problem. In the interaction section below you will find the information about flushing the output.

The New Year tree of height h is a perfect binary tree with vertices numbered 1 through 2h - 1 in some order. In this problem we assume that h is at least 2. The drawing below shows one example New Year tree of height 3:

<image>

Polar bears love decorating the New Year tree and Limak is no exception. To decorate the tree, he must first find its root, i.e. a vertex with exactly two neighbours (assuming that h ≥ 2). It won't be easy because Limak is a little bear and he doesn't even see the whole tree. Can you help him?

There are t testcases. In each testcase, you should first read h from the input. Then you can ask at most 16 questions of format "? x" (without quotes), where x is an integer between 1 and 2h - 1, inclusive. As a reply you will get the list of neighbours of vertex x (more details in the "Interaction" section below). For example, for a tree on the drawing above after asking "? 1" you would get a response with 3 neighbours: 4, 5 and 7. Your goal is to find the index of the root y and print it in the format "! y". You will be able to read h for a next testcase only after printing the answer in a previous testcase and flushing the output.

Each tree is fixed from the beginning and it doesn't change during your questions.

Input

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

At the beginning of each testcase you should read from the input a single integer h (2 ≤ h ≤ 7) — the height of the tree. You can't read the value of h in a next testcase until you answer a previous testcase.

Interaction

To ask a question about neighbours of vertex x, print "? x" (without quotes) on a separate line. Note, you must print an end-of-line character after the last character of the line and flush your output to get a response.

The response will consist of two lines. The first line will contain a single integer k (1 ≤ k ≤ 3) — the number of neighbours of vertex x. The second line will contain k distinct integers t1, ..., tk (1 ≤ t1 < ... < tk ≤ 2h - 1) — indices of neighbours of vertex x, gives in the increasing order.

After asking at most 16 questions you have to say y — the index of the root. Print "! y" (without quotes) and an end-of-line character, and flush the output.

Each tree is fixed from the beginning and it doesn't change during your questions.

You can get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output.

To flush you can use (just printing a query/answer and end-of-line):

  * fflush(stdout) in C++;
  * System.out.flush() in Java;
  * stdout.flush() in Python;
  * flush(output) in Pascal;
  * See the documentation for other languages.

In any moment if the program reads h = 0 or k = 0 it should immediately terminate normally (for example, calling exit(0)). It means that the system detected incorrect request/output from your program and printed 0 because if can't process your requests anymore. In this case you'll receive verdict "Wrong Answer", but if you ignore case h = 0 or k = 0 it could lead to "Runtime Error", "Time/Memory limit exceeded" or any other verdict because your program could read a trash from the closed input stream.

Hacking. To hack someone, use the following format:

The first line should contain a single integer t equal to 1 (only one testcase is allowed in hacks). The second line should contain a single integer h. Each of next 2h - 2 lines should contain two distinct integers ai and bi (1 ≤ ai, bi ≤ 2h - 1), denoting two nodes connected with an edge. The printed edges must form a perfect binary tree of height h.

Of course, contestant programs will not be able to see this input.

Examples

Input

1
3
3
4 5 7
2
1 2
1
2

Output

? 1
? 5
? 6
! 5

Input

2
2
1
3
2
1 2
2
1 2
4
3
3 12 13

Output

? 1
? 3
? 3
! 3
? 6
! 1

Note

In the first sample, a tree corresponds to the drawing from the statement.

In the second sample, there are two two testcases. A tree in the first testcase has height 2 and thus 3 vertices. A tree in the second testcase has height 4 and thus 15 vertices. You can see both trees on the drawing below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int Test, N, pt, k, last, ans, tim;
int sta[200];
bool vis[200];
int st[200], ne[200], go[200];
void Add(int x, int y) {
  ne[++pt] = st[x];
  st[x] = pt;
  go[pt] = y;
}
void Ask(int x) {
  if (vis[x]) {
    k = 0;
    for (int i = st[x]; i; i = ne[i]) k++;
    return;
  }
  ++tim;
  if (tim > 16) {
    ans = x;
    k = 2;
    return;
  }
  vis[x] = 1;
  printf("? %d\n", x);
  fflush(stdout);
  scanf("%d", &k);
  if (!k) exit(0);
  for (int i = 0; i < k; i++) {
    int y;
    scanf("%d", &y);
    Add(x, y);
  }
}
int main() {
  scanf("%d", &Test);
  while (Test--) {
    int h;
    scanf("%d", &h);
    tim = 0;
    memset(vis, 0, sizeof(vis));
    pt = 0;
    memset(st, 0, sizeof(st));
    ans = 0;
    sta[last = 1] = 1;
    while (last) {
      int x = sta[last];
      Ask(x);
      if (ans) break;
      if (k == 2) {
        ans = x;
        break;
      }
      if (k == 1) break;
      for (int i = st[x]; i; i = ne[i]) {
        int y = go[i];
        if (vis[y]) continue;
        sta[++last] = y;
        break;
      }
    }
    if (ans) {
      printf("! %d\n", ans);
      fflush(stdout);
      continue;
    }
    for (int l = 1, r = last; l < r; l++, r--) swap(sta[l], sta[r]);
    while (last && !ans) {
      int x = sta[last];
      Ask(x);
      if (ans) break;
      if (k == 2) {
        ans = x;
        break;
      }
      if (k == 1 && last > 1) {
        int step = (last + 1) >> 1;
        while (last > step) sta[last--] = 0;
        continue;
      }
      if (last >= 7) {
        sta[last--] = 0;
        continue;
      }
      bool find = 0;
      for (int i = st[x]; i; i = ne[i]) {
        int y = go[i];
        if (vis[y]) continue;
        find = 1;
        sta[++last] = y;
        break;
      }
      if (!find) sta[last--] = 0;
    }
    printf("! %d\n", ans);
    fflush(stdout);
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

One very important person has a piece of paper in the form of a rectangle a × b.

Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).

A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?

Input

The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).

Output

Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

Examples

Input

2 2 2
1 2
2 1

Output

4

Input

4 10 9
2 3
1 1
5 10
9 11

Output

56

Input

3 10 10
6 6
7 7
20 5

Output

0

Note

In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.

In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.

In the third example there is no such pair of seals that they both can fit on a piece of paper.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct st {
  int x, y;
};
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first < b.first) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  st s;
  int n;
  cin >> n >> s.x >> s.y;
  vector<st> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].x >> vec[i].y;
  }
  long long pl;
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if ((vec[i].x + vec[j].x <= s.x && max(vec[i].y, vec[j].y) <= s.y ||
           vec[i].x + vec[j].y <= s.x && max(vec[i].y, vec[j].x) <= s.y ||
           vec[i].y + vec[j].y <= s.x && max(vec[i].x, vec[j].x) <= s.y ||
           vec[i].y + vec[j].x <= s.x && max(vec[i].x, vec[j].y) <= s.y ||
           vec[i].y + vec[j].y <= s.y && max(vec[i].x, vec[j].x) <= s.x ||
           vec[i].x + vec[j].y <= s.y && max(vec[i].y, vec[j].x) <= s.x ||
           vec[i].x + vec[j].x <= s.y && max(vec[i].y, vec[j].y) <= s.x ||
           vec[i].y + vec[j].x <= s.y && max(vec[i].x, vec[j].y) <= s.x) &&
          vec[i].x * vec[i].y + vec[j].x * vec[j].y <= s.x * s.y &&
          vec[i].x * vec[i].y + vec[j].x * vec[j].y > ans)
        ans = vec[i].x * vec[i].y + vec[j].x * vec[j].y;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Curry making

As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals.

On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry.

Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible.

When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value.

However, please note the following points regarding the curry making this time.

* Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux.
* The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer.
* In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both.
* Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur.

Input

The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format.

> R0 W0 C R

Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks.

Output

For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add.

Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer.

Sample Input

10 5 3 4
2 5 2 3
91 13 7 62
10 1 3 5
20 100 2 20
2 14 7 1
0 0 0 0

Output for Sample Input

2
3
0
0
9
96

Example

Input

10 5 3 4
2 5 2 3
91 13 7 62
10 1 3 5
20 100 2 20
2 14 7 1
0 0 0 0

Output

2
3
0
0
9
96

### Response

```cpp
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int R0, W0, C, R;

int main(void) {
  while(cin >> R0 >> W0 >> C >> R, R0 || W0 || C || R) {
    int ans = 0;
    while(1) {
      if(R0 + R * ans >= C * W0) break;
      ans++;
    }
    cout << ans << endl;
  }

  return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:

There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers a and b (a·b = 12), after that he makes a table of size a × b from the cards he put on the table as follows: the first b cards form the first row of the table, the second b cards form the second row of the table and so on, the last b cards form the last (number a) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses.

Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers a and b to choose. Help her win the game: print to her all the possible ways of numbers a, b that she can choose and win.

Input

The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.

The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th character of the string shows the character that is written on the i-th card from the start.

Output

For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces.

Examples

Input

4
OXXXOXOOXOOX
OXOXOXOXOXOX
XXXXXXXXXXXX
OOOOOOOOOOOO

Output

3 1x12 2x6 4x3
4 1x12 2x6 3x4 6x2
6 1x12 2x6 3x4 4x3 6x2 12x1
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[100];
int rec[100], mark[100];
int main() {
  int T, tc, ans, a, b, i, now;
  cin >> T;
  tc = 0;
  while (tc < T) {
    tc++;
    scanf("%s", s);
    ans = 0;
    memset(rec, 0, sizeof(rec));
    for (a = 1; a <= 12; a++) {
      if (12 % a != 0) continue;
      b = 12 / a;
      memset(mark, 0, sizeof(mark));
      for (i = 0; i < 12; i++) {
        if (s[i] == 'O') mark[i % b] = 1;
      }
      now = 0;
      for (i = 0; i < b; i++) now += mark[i];
      if (now < b) {
        ans++;
        rec[a] = 1;
      }
    }
    printf("%d", ans);
    for (a = 1; a <= 12; a++) {
      if (rec[a] == 1) {
        printf(" %dx%d", a, 12 / a);
      }
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake.

Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut.

It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order.

Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off.

A possible process of cutting the cake is presented in the picture below.

<image> Example of 6-sided cake slicing.

You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices.

For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1].

You are interested in two questions.

  * What was the enumeration of the n-sided cake vertices?
  * In what order were the pieces cut?

Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon.

For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3].

Write a program that, based on the given triangular pieces, finds any suitable permutations p and q.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data.

The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake.

The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order.

It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5.

Output

Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines.

In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order.

In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input.

If there are several answers, print any. It is guaranteed that the answer to each of the tests exists.

Example

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct tria {
  int p[3];
} trias[100010];
vector<int> p2t[100010];
int i, j, n, m;
bool checked[100010];
int di[100010];
vector<pair<int, int> > que;
vector<int> ans;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
map<pair<int, int>, int> edgeC;
void addE(int a, int b) {
  if (a > b) swap(a, b);
  auto p = make_pair(a, b);
  if (edgeC[p] == 0) {
    edgeC[p] = 1;
  } else {
    edgeC[p]++;
  }
}
vector<int> edges[100010];
void checkit(int a, int b) {
  if (a > b) swap(a, b);
  if (edgeC[make_pair(a, b)] == 1) {
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
}
int main() {
  int ii;
  scanf("%d", &ii);
  while (ii--) {
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
      p2t[i].clear();
      edges[i].clear();
    }
    edgeC.clear();
    for (i = 1; i <= n - 2; i++) {
      scanf("%d %d %d", &trias[i].p[0], &trias[i].p[1], &trias[i].p[2]);
      addE(trias[i].p[0], trias[i].p[1]);
      addE(trias[i].p[1], trias[i].p[2]);
      addE(trias[i].p[0], trias[i].p[2]);
      for (j = 0; j < 3; j++) {
        p2t[trias[i].p[j]].push_back(i);
      }
    }
    for (i = 1; i <= n - 2; i++) {
      checkit(trias[i].p[0], trias[i].p[1]);
      checkit(trias[i].p[1], trias[i].p[2]);
      checkit(trias[i].p[0], trias[i].p[2]);
    }
    memset(di, 0, sizeof(di));
    memset(checked, 0, sizeof(checked));
    que.clear();
    ans.clear();
    for (i = 1; i <= n; i++) {
      di[i] = (int)(p2t[i].size());
      que.push_back(make_pair(di[i], i));
      push_heap(que.begin(), que.end(), cmp);
    }
    i = 1;
    checked[1] = true;
    bool found = true;
    printf("1");
    while (found) {
      found = false;
      for (const auto e : edges[i])
        if (!checked[e]) {
          checked[e] = true;
          printf(" %d", e);
          found = true;
          i = e;
          break;
        }
    }
    printf("\n");
    memset(checked, 0, sizeof(checked));
    while (que.size()) {
      pop_heap(que.begin(), que.end(), cmp);
      auto now_pair = que.back();
      que.pop_back();
      int now = now_pair.second;
      if (di[now] != now_pair.first || di[now] == 0) continue;
      if (di[now] != 1) {
        printf("no %d %d\n", now, di[now]);
        continue;
      }
      di[now] = 0;
      int tr = 0;
      for (const auto t : p2t[now]) {
        if (!checked[t]) {
          checked[t] = true;
          tr = t;
          break;
        }
      }
      ans.push_back(tr);
      int a = 0, b = 0;
      for (i = 0; i < 3; i++) {
        if (trias[tr].p[i] != now) {
          di[trias[tr].p[i]]--;
          que.push_back(make_pair(di[trias[tr].p[i]], trias[tr].p[i]));
          push_heap(que.begin(), que.end(), cmp);
        }
      }
    }
    for (const auto a : ans) {
      printf("%d ", a);
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

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

Heidi got one brain, thumbs up! But the evening isn't over yet and one more challenge awaits our dauntless agent: after dinner, at precisely midnight, the N attendees love to play a very risky game...

Every zombie gets a number ni (1 ≤ ni ≤ N) written on his forehead. Although no zombie can see his own number, he can see the numbers written on the foreheads of all N - 1 fellows. Note that not all numbers have to be unique (they can even all be the same). From this point on, no more communication between zombies is allowed. Observation is the only key to success. When the cuckoo clock strikes midnight, all attendees have to simultaneously guess the number on their own forehead. If at least one of them guesses his number correctly, all zombies survive and go home happily. On the other hand, if not a single attendee manages to guess his number correctly, all of them are doomed to die!

Zombies aren't very bright creatures though, and Heidi has to act fast if she does not want to jeopardize her life. She has one single option: by performing some quick surgery on the brain she managed to get from the chest, she has the ability to remotely reprogram the decision-making strategy of all attendees for their upcoming midnight game! Can you suggest a sound strategy to Heidi which, given the rules of the game, ensures that at least one attendee will guess his own number correctly, for any possible sequence of numbers on the foreheads?

Given a zombie's rank R and the N - 1 numbers ni on the other attendees' foreheads, your program will have to return the number that the zombie of rank R shall guess. Those answers define your strategy, and we will check if it is flawless or not.

Input

The first line of input contains a single integer T (1 ≤ T ≤ 50000): the number of scenarios for which you have to make a guess.

The T scenarios follow, described on two lines each:

  * The first line holds two integers, N (2 ≤ N ≤ 6), the number of attendees, and R (1 ≤ R ≤ N), the rank of the zombie who has to make the guess.
  * The second line lists N - 1 integers: the numbers on the foreheads of all other attendees, listed in increasing order of the attendees' rank. (Every zombie knows the rank of every other zombie.)

Output

For every scenario, output a single integer: the number that the zombie of rank R shall guess, based on the numbers ni on his N - 1 fellows' foreheads.

Examples

Input

4
2 1
1
2 2
1
2 1
2
2 2
2

Output

1
2
2
1

Input

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

Output

5
2

Note

For instance, if there were N = 2 two attendees, a successful strategy could be:

  * The zombie of rank 1 always guesses the number he sees on the forehead of the zombie of rank 2.
  * The zombie of rank 2 always guesses the opposite of the number he sees on the forehead of the zombie of rank 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  scanf("%d", &q);
  for (int tt = 0; tt < q; tt++) {
    int n, r;
    scanf("%d%d", &n, &r);
    r--;
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
      int x;
      scanf("%d", &x);
      x--;
      sum += x;
    }
    int ans = (n - sum % n + r) % n;
    printf("%d\n", ans + 1);
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell has a candy, it is denoted as a letter of the English alphabet. A level may contain identical candies, in this case the letters in the corresponding cells of the map will be the same.

<image>

When you transmit information via a network, you want to minimize traffic — the total size of the transferred data. The levels can be transmitted in any order. There are two ways to transmit the current level A:

  1. You can transmit the whole level A. Then you need to transmit n·m bytes via the network.
  2. You can transmit the difference between level A and some previously transmitted level B (if it exists); this operation requires to transmit dA, B·w bytes, where dA, B is the number of cells of the field that are different for A and B, and w is a constant. Note, that you should compare only the corresponding cells of levels A and B to calculate dA, B. You cannot transform the maps of levels, i.e. rotate or shift them relatively to each other.

Your task is to find a way to transfer all the k levels and minimize the traffic.

Input

The first line contains four integers n, m, k, w (1 ≤ n, m ≤ 10; 1 ≤ k, w ≤ 1000). Then follows the description of k levels. Each level is described by n lines, each line contains m characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.

Output

In the first line print the required minimum number of transferred bytes.

Then print k pairs of integers x1, y1, x2, y2, ..., xk, yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first way, otherwise yi must be equal to the number of a previously transferred level. It means that you will transfer the difference between levels yi and xi to transfer level xi. Print the pairs in the order of transferring levels. The levels are numbered 1 through k in the order they follow in the input.

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

Examples

Input

2 3 3 2
A.A
...
A.a
..C
X.Y
...

Output

14
1 0
2 1
3 1

Input

1 1 4 1
A
.
B
.

Output

3
1 0
2 0
4 2
3 0

Input

1 3 5 2
ABA
BBB
BBA
BAB
ABB

Output

11
1 0
3 1
2 3
4 2
5 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct road {
  int x, y, cost;
};
struct comp {
  bool operator()(struct road x, struct road y) { return x.cost > y.cost; }
};
int head[1005];
int uf[1005];
bool mark[1005];
vector<int> tree[1005];
priority_queue<road, vector<road>, comp> heap;
char level[1005][11][11];
void dfs(int n) {
  for (int i = 0; i < tree[n].size(); i++) {
    if (!mark[tree[n][i]]) {
      printf("%d %d\n", tree[n][i], n);
      mark[tree[n][i]] = true;
      dfs(tree[n][i]);
    }
  }
}
int findhead(int i) {
  if (i != uf[i]) uf[i] = findhead(uf[i]);
  return uf[i];
}
int main() {
  int n, m, k, w, dif;
  struct road e;
  scanf("%d %d %d %d", &n, &m, &k, &w);
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%s", level[i][j]);
    }
  }
  for (int i = 1; i < k; i++) {
    for (int j = i + 1; j <= k; j++) {
      dif = 0;
      for (int l = 0; l < n; l++) {
        for (int o = 0; o < m; o++) {
          if (level[i][l][o] != level[j][l][o]) {
            dif++;
          }
        }
      }
      dif *= w;
      e.x = i;
      e.y = j;
      e.cost = dif;
      heap.push(e);
    }
  }
  for (int i = 1; i <= k; i++) {
    e.x = 0;
    e.y = i;
    e.cost = n * m;
    heap.push(e);
  }
  for (int i = 0; i <= k; i++) {
    uf[i] = i;
  }
  int sm = 0;
  for (int i = 1; i <= k; i++) {
    while (true) {
      e = heap.top();
      heap.pop();
      if (findhead(e.x) != findhead(e.y)) {
        uf[uf[e.x]] = uf[e.y];
        sm += e.cost;
        tree[e.x].push_back(e.y);
        tree[e.y].push_back(e.x);
        break;
      }
    }
  }
  mark[0] = true;
  printf("%d\n", sm);
  dfs(0);
}

```


### Prompt

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

A famous sculptor Cicasso goes to a world tour!

Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will entirely hold the world tour in his native country — Berland.

Cicasso is very devoted to his work and he wants to be distracted as little as possible. Therefore he will visit only four cities. These cities will be different, so no one could think that he has "favourites". Of course, to save money, he will chose the shortest paths between these cities. But as you have probably guessed, Cicasso is a weird person. Although he doesn't like to organize exhibitions, he likes to travel around the country and enjoy its scenery. So he wants the total distance which he will travel to be as large as possible. However, the sculptor is bad in planning, so he asks you for help.

There are n cities and m one-way roads in Berland. You have to choose four different cities, which Cicasso will visit and also determine the order in which he will visit them. So that the total distance he will travel, if he visits cities in your order, starting from the first city in your list, and ending in the last, choosing each time the shortest route between a pair of cities — will be the largest.

Note that intermediate routes may pass through the cities, which are assigned to the tour, as well as pass twice through the same city. For example, the tour can look like that: <image>. Four cities in the order of visiting marked as overlines: [1, 5, 2, 4].

Note that Berland is a high-tech country. So using nanotechnologies all roads were altered so that they have the same length. For the same reason moving using regular cars is not very popular in the country, and it can happen that there are such pairs of cities, one of which generally can not be reached by car from the other one. However, Cicasso is very conservative and cannot travel without the car. Choose cities so that the sculptor can make the tour using only the automobile. It is guaranteed that it is always possible to do.

Input

In the first line there is a pair of integers n and m (4 ≤ n ≤ 3000, 3 ≤ m ≤ 5000) — a number of cities and one-way roads in Berland.

Each of the next m lines contains a pair of integers ui, vi (1 ≤ ui, vi ≤ n) — a one-way road from the city ui to the city vi. Note that ui and vi are not required to be distinct. Moreover, it can be several one-way roads between the same pair of cities.

Output

Print four integers — numbers of cities which Cicasso will visit according to optimal choice of the route. Numbers of cities should be printed in the order that Cicasso will visit them. If there are multiple solutions, print any of them.

Example

Input

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

Output

2 1 8 7

Note

Let d(x, y) be the shortest distance between cities x and y. Then in the example d(2, 1) = 3, d(1, 8) = 7, d(8, 7) = 3. The total distance equals 13.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
const int INF = 0x3f3f3f3f;
int n, m;
int d[maxn][maxn];
vector<int> g[maxn];
vector<pair<int, int> > dis[maxn], rdis[maxn];
void bfs() {
  for (int i = 1; i <= n; i++) {
    queue<int> que;
    que.push(i);
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (auto v : g[u]) {
        if (d[i][v] != INF) continue;
        d[i][v] = d[i][u] + 1;
        que.push(v);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  memset(d, 0x3f, sizeof(d));
  for (int i = 1; i <= n; i++) d[i][i] = 0;
  bfs();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (i != j) {
        if (d[i][j] < INF) dis[i].push_back(make_pair(d[i][j], j));
        if (d[j][i] < INF) rdis[i].push_back(make_pair(d[j][i], j));
      }
    sort(dis[i].begin(), dis[i].end());
    reverse(dis[i].begin(), dis[i].end());
    sort(rdis[i].begin(), rdis[i].end());
    reverse(rdis[i].begin(), rdis[i].end());
  }
  int maxx = 0, res;
  int r1, r2, r3, r4;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (i != j && d[i][j] < INF) {
        for (int k = 0; k < 3 && k < rdis[i].size(); k++)
          if (rdis[i][k].second != j) {
            for (int x = 0; x < 3 && x < dis[j].size(); x++)
              if (dis[j][x].second != i) {
                if (rdis[i][k].second == dis[j][x].second) continue;
                res = rdis[i][k].first + d[i][j] + dis[j][x].first;
                if (res > maxx) {
                  maxx = res;
                  r1 = rdis[i][k].second;
                  r2 = i;
                  r3 = j;
                  r4 = dis[j][x].second;
                }
              }
          }
      }
  }
  printf("%d %d %d %d\n", r1, r2, r3, r4);
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

The only difference between the easy and the hard versions is the maximum value of k.

You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2, the third one — from 1 to 3, ..., the i-th block consists of all numbers from 1 to i.

So the first 56 elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the 1-st element of the sequence is 1, the 3-rd element of the sequence is 2, the 20-th element of the sequence is 5, the 38-th element is 2, the 56-th element of the sequence is 0.

Your task is to answer q independent queries. In the i-th query you are given one integer k_i. Calculate the digit at the position k_i of the sequence.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries.

The i-th of the following q lines contains one integer k_i (1 ≤ k_i ≤ 10^9) — the description of the corresponding query.

Output

Print q lines. In the i-th line print one digit x_i (0 ≤ x_i ≤ 9) — the answer to the query i, i.e. x_i should be equal to the element at the position k_i of the sequence.

Examples

Input

5
1
3
20
38
56

Output

1
2
5
2
0

Input

4
2132
506
999999999
1000000000

Output

8
2
9
8

Note

Answers on queries from the first example are described in the problem statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[200200];
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long ans = power(a, b / 2);
  ans = ans * ans;
  if (b % 2 != 0) ans *= a;
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int q, i;
  long long k;
  long long last = 0;
  for (i = 1; i <= 2e5; i++) {
    long long y = i;
    int co = 0;
    while (y) {
      co++;
      y /= 10;
    }
    a[i] = (a[i - 1] + last + co);
    last += co;
  }
  cin >> q;
  k = 0;
  while (q--) {
    cin >> k;
    if (k == 1e9) {
      cout << 8 << endl;
      continue;
    }
    int t = 2e5;
    long long *u = lower_bound(a, a + t, k);
    int ind = u - &a[0];
    long long co = 0, ans = 0;
    for (long long i = a[ind - 1] + 1, j = 1; i <= k; i++, j++) {
      long long y = j;
      long long b = 0;
      while (y) {
        y /= 10;
        b++;
      }
      y = j;
      while (b && i <= k) {
        i++;
        b--;
        long long r = pow(10, b);
        ans = y / r;
        y %= r;
      }
      i--;
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given a string s consisting of `A`, `B` and `C`.

Snuke wants to perform the following operation on s as many times as possible:

* Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`.

Find the maximum possible number of operations.

Constraints

* 1 \leq |s| \leq 200000
* Each character of s is `A`, `B` and `C`.

Input

Input is given from Standard Input in the following format:

s

Output

Find the maximum possible number of operations.

Examples

Input

ABCABC

Output

3

Input

C

Output

0

Input

ABCACCBABCBCAABCB

Output

6

### Response

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

ll solve(string s){
    ll ans = 0,cnt = 0;

    for(int i = 0;i < s.size()-1;i ++){
        if(s[i]=='A') cnt ++;
        else if(s[i]=='B' && s[i+1]=='C') ans += cnt,i ++;
        else cnt = 0;
    }
    return ans;
}

int main(){
    string s;
    cin >> s;

    cout << solve(s) << endl;
    return 0;
}
```


### Prompt

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

Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.

Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in which the respective symbols of s and t are the same. Function h(s, t) can be used to define the function of Vasya distance ρ(s, t):

<image> where <image> is obtained from string s, by applying left circular shift i times. For example, ρ("AGC", "CGT") =  h("AGC", "CGT") + h("AGC", "GTC") + h("AGC", "TCG") +  h("GCA", "CGT") + h("GCA", "GTC") + h("GCA", "TCG") +  h("CAG", "CGT") + h("CAG", "GTC") + h("CAG", "TCG") =  1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6

Vasya found a string s of length n on the Internet. Now he wants to count how many strings t there are such that the Vasya distance from the string s attains maximum possible value. Formally speaking, t must satisfy the equation: <image>.

Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109 + 7.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 105).

The second line of the input contains a single string of length n, consisting of characters "ACGT".

Output

Print a single number — the answer modulo 109 + 7.

Examples

Input

1
C

Output

1

Input

2
AG

Output

4

Input

3
TTT

Output

1

Note

Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.

In the first sample, there is ρ("C", "C") = 1, for the remaining strings t of length 1 the value of ρ(s, t) is 0.

In the second sample, ρ("AG", "AG") = ρ("AG", "GA") = ρ("AG", "AA") = ρ("AG", "GG") = 4.

In the third sample, ρ("TTT", "TTT") = 27

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long w = 0, f = 1;
  char c = ' ';
  while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f;
  while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar();
  return w * f;
}
long long read4() {
  char c = getchar();
  while (c != 'A' && c != 'C' && c != 'G' && c != 'T') c = getchar();
  if (c == 'A') return 1;
  if (c == 'C') return 2;
  if (c == 'G') return 3;
  return 4;
}
const long long mod = 1e9 + 7;
long long pown(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    x = x * x % mod, y >>= 1;
  }
  return res;
}
long long n, a[100005], b[5];
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read4(), b[a[i]]++;
  sort(b + 1, b + 4 + 1, [&](long long x, long long y) { return x > y; });
  if (b[1] != b[2]) return puts("1"), 0;
  if (b[2] != b[3]) return printf("%lld\n", pown(2, n)), 0;
  if (b[3] != b[4]) return printf("%lld\n", pown(3, n)), 0;
  printf("%lld\n", pown(4, n));
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct.

Let's define function f(l, r) as follows:

  * let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i};
  * sort array b in increasing order;
  * result of the function f(l, r) is ∑_{i = 1}^{r - l + 1}{b_i ⋅ i}.

Calculate \left(∑_{1 ≤ l ≤ r ≤ n}{f(l, r)}\right) mod (10^9+7), i.e. total sum of f for all subsegments of a modulo 10^9+7.

Input

The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of array a.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9, a_i ≠ a_j for i ≠ j) — array a.

Output

Print one integer — the total sum of f for all subsegments of a modulo 10^9+7

Examples

Input

4
5 2 4 7

Output

167

Input

3
123456789 214365879 987654321

Output

582491518

Note

Description of the first example:

  * f(1, 1) = 5 ⋅ 1 = 5;
  * f(1, 2) = 2 ⋅ 1 + 5 ⋅ 2 = 12;
  * f(1, 3) = 2 ⋅ 1 + 4 ⋅ 2 + 5 ⋅ 3 = 25;
  * f(1, 4) = 2 ⋅ 1 + 4 ⋅ 2 + 5 ⋅ 3 + 7 ⋅ 4 = 53;
  * f(2, 2) = 2 ⋅ 1 = 2;
  * f(2, 3) = 2 ⋅ 1 + 4 ⋅ 2 = 10;
  * f(2, 4) = 2 ⋅ 1 + 4 ⋅ 2 + 7 ⋅ 3 = 31;
  * f(3, 3) = 4 ⋅ 1 = 4;
  * f(3, 4) = 4 ⋅ 1 + 7 ⋅ 2 = 18;
  * f(4, 4) = 7 ⋅ 1 = 7;

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const long long mod = 1e9 + 7;
int n, t[maxn], num[maxn];
map<int, int> ma;
long long zz[maxn], tree[maxn];
void add(int x, int y) {
  for (int i = x; i <= n; i += (i & (-i))) tree[i] += y;
}
long long quer(int x) {
  long long res = 0;
  for (int i = x; i; i -= (i & (-i))) res += tree[i];
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    t[i] = num[i];
  }
  sort(t + 1, t + n + 1);
  for (int i = 1; i <= n; i++) ma[t[i]] = i;
  for (int i = 1; i <= n; i++) {
    zz[i] = quer(ma[num[i]]) * (n - i + 1) % mod;
    add(ma[num[i]], i);
  }
  for (int i = 1; i <= n; i++) tree[i] = 0;
  for (int i = n; i >= 1; i--) {
    zz[i] = (zz[i] + quer(ma[num[i]]) * i % mod) % mod;
    add(ma[num[i]], n - i + 1);
    zz[i] = (zz[i] + (long long)(n - i + 1) * i % mod) % mod;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans = (ans + (long long)num[i] * zz[i] % mod) % mod;
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Berland annual chess tournament is coming!

Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.

Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins.

Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.

After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.

Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?

Input

The first line contains one integer n (1 ≤ n ≤ 100).

The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).

Output

If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".

Examples

Input

2
1 3 2 4

Output

YES

Input

1
3 3

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
void swap(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}
void sort(int a[], int n) {
  int i, j;
  for (i = 2 * n; i > 0; i--)
    for (j = 0; j < i - 1; j++)
      if (a[j] > a[j + 1]) swap(&a[j], &a[j + 1]);
}
int main() {
  int a[200], n, i;
  scanf("%d", &n);
  for (i = 0; i < 2 * n; i++) scanf("%d", &a[i]);
  sort(a, n);
  if (a[n] == a[n - 1])
    printf("NO");
  else
    printf("YES");
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.

Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.

Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Constraints

* 2 \le N \le 10^5
* 1 \le a_i \lt b_i \le N
* All values in input are integers.
* The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}

Output

Print N lines.

The first line should contain K, the number of colors used.

The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \le c_i \le K must hold.

If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.

Examples

Input

3
1 2
2 3

Output

2
1
2

Input

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

Output

4
1
2
3
4
1
1
2

Input

6
1 2
1 3
1 4
1 5
1 6

Output

5
1
2
3
4
5

### Response

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

using namespace std;

const int M = 1e5 + 5;

int n, k = 0, colors[M];
vector<array<int, 2>> g[M];

void DFS(int x, int p, int clr) {
    int color = 1;
    for (auto a : g[x]) {
        if (a[0] == p) continue;
        if (color == clr) color++;
        colors[a[1]] = color++;
        DFS(a[0], x, colors[a[1]]);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n;
    for (int i = 1, a, b; i < n; i++) {
        cin >> a >> b;
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    } // Max Degree = K (Editorial TIME)
    for (int i = 1; i <= n; i++) k = max(k, (int) g[i].size()); cout << k << '\n';
    DFS(1, -1, -1);
    for (int i = 1; i < n; i++) cout << colors[i] << '\n';

    return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

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

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

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

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

Input

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

Output

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

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

Examples

Input

vasyaatgmaildotcom

Output

vasya@gmail.com

Input

dotdotdotatdotdotat

Output

dot..@..at

Input

aatt

Output

a@t

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::string name;
  std::cin >> name;
  bool atFlag = false;
  std::string result = "";
  result += name[0];
  for (int i = 1; i < name.length(); i++) {
    if (!atFlag && name.substr(i, 2) == "at") {
      result += '@';
      ++i;
      atFlag = true;
    } else if (i + 3 < name.length() && name.substr(i, 3) == "dot") {
      result += '.';
      i += 2;
    } else {
      result += name[i];
    }
  }
  std::cout << result;
  return 0;
}

```