### Prompt

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

After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help.

Formally the parking can be represented as a matrix 109 × 109. There is exactly one car in every cell of the matrix. All cars have their own machine numbers represented as a positive integer. Let's index the columns of the matrix by integers from 1 to 109 from left to right and the rows by integers from 1 to 109 from top to bottom. By coincidence it turned out, that for every cell (x, y) the number of the car, which stands in this cell, is equal to the minimum positive integer, which can't be found in the cells (i, y) and (x, j), 1 ≤ i < x, 1 ≤ j < y.

<image> The upper left fragment 5 × 5 of the parking

Leha wants to ask the watchman q requests, which can help him to find his car. Every request is represented as five integers x1, y1, x2, y2, k. The watchman have to consider all cells (x, y) of the matrix, such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2, and if the number of the car in cell (x, y) does not exceed k, increase the answer to the request by the number of the car in cell (x, y). For each request Leha asks the watchman to tell him the resulting sum. Due to the fact that the sum can turn out to be quite large, hacker asks to calculate it modulo 109 + 7.

However the requests seem to be impracticable for the watchman. Help the watchman to answer all Leha's requests.

Input

The first line contains one integer q (1 ≤ q ≤ 104) — the number of Leha's requests.

The next q lines contain five integers x1, y1, x2, y2, k (1 ≤ x1 ≤ x2 ≤ 109, 1 ≤ y1 ≤ y2 ≤ 109, 1 ≤ k ≤ 2·109) — parameters of Leha's requests.

Output

Print exactly q lines — in the first line print the answer to the first request, in the second — the answer to the second request and so on.

Example

Input

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

Output

1
13
93
0

Note

Let's analyze all the requests. In each case the requested submatrix is highlighted in blue.

In the first request (k = 1) Leha asks only about the upper left parking cell. In this cell the car's number is 1. Consequentally the answer is 1.

<image>

In the second request (k = 5) suitable numbers are 4, 1, 2, 3, 2, 1. Consequentally the answer is 4 + 1 + 2 + 3 + 2 + 1 = 13.

<image>

In the third request (k = 10000) Leha asks about the upper left frament 5 × 5 of the parking. Since k is big enough, the answer is equal to 93.

<image>

In the last request (k = 2) none of the cur's numbers are suitable, so the answer is 0.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int bitx[32], bity[32], bitk[32];
long long dp[32][2][2][2], dp1[32][2][2][2], f[32];
pair<long long, long long> dfs(int pos, int limit1, int limit2, int limit3) {
  if (pos == 0) return make_pair(1, 0);
  if (dp[pos][limit1][limit2][limit3] != -1)
    return make_pair(dp[pos][limit1][limit2][limit3],
                     dp1[pos][limit1][limit2][limit3]);
  int x = limit1 ? bitx[pos] : 1;
  int y = limit2 ? bity[pos] : 1;
  long long ret = 0;
  long long ret1 = 0;
  for (int i = 0; i <= x; ++i) {
    for (int j = 0; j <= y; ++j) {
      if (limit3 && (i ^ j) > bitk[pos]) continue;
      pair<long long, long long> t =
          dfs(pos - 1, limit1 && (i == x), limit2 && (j == y),
              limit3 && ((i ^ j) == bitk[pos]));
      (ret += t.first) %= mod;
      (ret1 += t.second + ((i ^ j) ? f[pos - 1] : 0) * t.first % mod) %= mod;
    }
  }
  dp[pos][limit1][limit2][limit3] = ret,
  dp1[pos][limit1][limit2][limit3] = ret1;
  return make_pair(ret, ret1);
}
long long solve(long long x, long long y, long long k) {
  memset(dp, -1, sizeof(dp));
  if (x < 0 || y < 0) return 0;
  memset(bitx, 0, sizeof(bitx));
  memset(bity, 0, sizeof(bity));
  memset(bitk, 0, sizeof(bitk));
  int lenx = 0;
  while (x) {
    bitx[++lenx] = x & 1;
    x >>= 1;
  }
  int leny = 0;
  while (y) {
    bity[++leny] = y & 1;
    y >>= 1;
  }
  int lenk = 0;
  while (k) {
    bitk[++lenk] = k & 1;
    k >>= 1;
  }
  pair<long long, long long> t = dfs(31, 1, 1, 1);
  return (t.first + t.second) % mod;
}
int main() {
  f[0] = 1;
  for (int i = 1; i < 31; ++i) f[i] = f[i - 1] * 2 % mod;
  int T, x1, y1, x2, y2, k;
  scanf("%d", &T);
  memset(dp, -1, sizeof(dp));
  while (T--) {
    scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &k);
    x1--;
    y1--;
    x2--;
    y2--;
    k--;
    printf("%I64d\n", ((solve(x2, y2, k) - solve(x1 - 1, y2, k) -
                        solve(x2, y1 - 1, k) + solve(x1 - 1, y1 - 1, k)) %
                           mod +
                       mod) %
                          mod);
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:

* 1 yen (the currency of Japan)

* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...

* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...

At least how many operations are required to withdraw exactly N yen in total?

It is not allowed to re-deposit the money you withdrew.

Constraints

* 1 \leq N \leq 100000
* N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If at least x operations are required to withdraw exactly N yen in total, print x.

Examples

Input

127

Output

4

Input

3

Output

3

Input

44852

Output

16

### Response

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

int bank (int n) {
  if (n<6)
    return n;
  else if (n<9)
    return bank(n-6) + 1;
  else {
    int n6=1, n9=1;
    while (n>=n6*6) {
      n6 *= 6;
    }
    while (n>=n9*9) {
      n9 *= 9;
    }
    return min(bank(n-n6),bank(n-n9))+1;
  }
}

int main() {
  int n;
  cin >> n;

  cout << bank(n) << endl;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once.

Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.

Constraints

* The length of S is between 7 and 100 (inclusive).
* S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S is a KEYENCE string, print `YES`; otherwise, print `NO`.

Examples

Input

keyofscience

Output

YES

Input

mpyszsbznf

Output

NO

Input

ashlfyha

Output

NO

Input

keyence

Output

YES

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t="keyence";
  cin>>s;
  for(int i=0;i<=7;i++){
    string a=t.substr(0,i),b=t.substr(i,7-i);
    if(a==s.substr(0,i)&&b==s.substr(s.size()-(7-i),7-i)){
      cout<<"YES";
      return 0;
    }
  }
  cout<<"NO";
}
```


### Prompt

Create a solution in CPP for the following problem:

Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.

There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.

Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i - 1)-th man in the line (for the current moment) talks with the (2i)-th one.

Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.

We know that if students i and j talk, then the i-th student's happiness increases by gij and the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.

Input

The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0 ≤ gij ≤ 105). It is guaranteed that gii = 0 for all i.

Assume that the students are numbered from 1 to 5.

Output

Print a single integer — the maximum possible total happiness of the students.

Examples

Input

0 0 0 0 9
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
7 0 0 0 0

Output

32

Input

0 43 21 18 2
3 0 21 11 65
5 2 0 1 4
54 62 12 0 99
87 64 81 33 0

Output

620

Note

In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:

(g23 + g32 + g15 + g51) + (g13 + g31 + g54 + g45) + (g15 + g51) + (g54 + g45) = 32.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
void solve() {
  int a[5][5];
  int ans = 0;
  int arr[5];
  for (int i = 0; i < 5; i++) arr[i] = i;
  int val = -1;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) cin >> a[i][j];
  do {
    ans = 0;
    ans += a[arr[0]][arr[1]] + a[arr[1]][arr[0]] + a[arr[1]][arr[2]] +
           a[arr[2]][arr[1]] +
           2 * (a[arr[2]][arr[3]] + a[arr[3]][arr[2]] + a[arr[3]][arr[4]] +
                a[arr[4]][arr[3]]);
    if (ans > val) val = ans;
  } while (next_permutation(arr, arr + 5));
  cout << val << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  solve();
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

The full exploration sister is a very talented woman. Your sister can easily count the number of routes in a grid pattern if it is in the thousands. You and your exploration sister are now in a room lined with hexagonal tiles. The older sister seems to be very excited about the hexagon she sees for the first time. The older sister, who is unfamiliar with expressing the arrangement of hexagons in coordinates, represented the room in the coordinate system shown in Fig. 1.

<image> Figure 1

You want to move from one point on this coordinate system to another. But every minute your sister tells you the direction you want to move. Your usual sister will instruct you to move so that you don't go through locations with the same coordinates. However, an older sister who is unfamiliar with this coordinate system corresponds to the remainder of | x × y × t | (x: x coordinate, y: y coordinate, t: elapsed time [minutes] from the first instruction) divided by 6. Simply indicate the direction (corresponding to the number shown in the figure) and it will guide you in a completely random direction.

<image> Figure 2

If you don't want to hurt your sister, you want to reach your destination while observing your sister's instructions as much as possible. You are allowed to do the following seven actions.

* Move 1 tile to direction 0
* Move 1 tile to direction 1
* Move 1 tile in direction 2
* Move 1 tile in direction 3
* Move 1 tile in direction 4
* Move 1 tile in direction 5
* Stay on the spot

You always do one of these actions immediately after your sister gives instructions. The room is furnished and cannot be moved into the tiles where the furniture is placed. Also, movements where the absolute value of the y coordinate exceeds ly or the absolute value of the x coordinate exceeds lx are not allowed. However, the older sister may instruct such a move. Ignoring instructions means moving in a different direction than your sister indicated, or staying there. Output the minimum number of times you should ignore the instructions to get to your destination. Output -1 if it is not possible to reach your destination.

Constraints

* All inputs are integers
* -lx ≤ sx, gx ≤ lx
* -ly ≤ sy, gy ≤ ly
* (sx, sy) ≠ (gx, gy)
* (xi, yi) ≠ (sx, sy) (1 ≤ i ≤ n)
* (xi, yi) ≠ (gx, gy) (1 ≤ i ≤ n)
* (xi, yi) ≠ (xj, yj) (i ≠ j)
* 0 ≤ n ≤ 1000
* -lx ≤ xi ≤ lx (1 ≤ i ≤ n)
* -ly ≤ yi ≤ ly (1 ≤ i ≤ n)
* 0 <lx, ly ≤ 100

Input

The input is given in the following format.

> sx sy gx gy
> n
> x1 y1
> ...
> xi yi
> ...
> xn yn
> lx ly
>

here,

* sx, sy are the coordinates of the starting point
* gx, gy are the coordinates of the destination
* n is the number of furniture placed in the room
* xi, yi are the coordinates of the tile with furniture
* lx, ly are the upper limits of the absolute values of the movable X and Y coordinates.

Output

Output in one line containing one integer. If you can reach your destination, print the number of times you ignore the minimum instructions. Output -1 if it is not possible to reach your destination.

Examples

Input

0 0 0 2
0
2 2

Output

0

Input

0 0 0 2
6
0 1
1 0
1 -1
0 -1
-1 -1
-1 0
2 2

Output

-1

Input

0 0 0 2
1
0 1
2 2

Output

1

### Response

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

#define MAX_H 5000
#define MAX_N 300
#define MAX_M 150

short dx1[7] = { 0,1,1,0,-1,-1,0 };
short dy1[7] = { 1,0,-1,-1,-1,0,0 };
short dx2[7] = { 0,1,1,0,-1,-1,0 };
short dy2[7] = { 1,1,0,-1,0,1,0 };
short dp[2][MAX_N + 1][MAX_N + 1], n, sx, sy, gx, gy, x, y, lx, ly;
short X[MAX_N + 1][MAX_N + 1], minx = (1 << 14);

int main() {
	cin >> sx >> sy >> gx >> gy;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		X[x + MAX_M][y + MAX_M] = 1;
	}
	cin >> lx >> ly;
	for (int i = 0; i <= MAX_N; i++) {
		for (int j = 0; j <= MAX_N; j++) {
			if (abs(i - MAX_M) > lx || abs(j - MAX_M)>ly) {
				X[i][j] = 1;
			}
		}
	}
	memset(dp, 127, sizeof(dp));
	dp[0][sx + MAX_M][sy + MAX_M] = 0;
	for (int i = 0; i < MAX_H; i++) {
		for (int j = 0; j < MAX_N; j++) {
			for (int k = 0; k < MAX_N; k++) {
				dp[(i + 1) % 2][j][k] = (1 << 14);
			}
		}
		for (int j = 0; j <= MAX_N; j++) {
			for (int k = 0; k <= MAX_N; k++) {
				if (dp[i % 2][j][k] < (1 << 14)) {
					int t = abs(i*(j - MAX_M)*(k - MAX_M)) % 6;
					if (abs(j - MAX_M) % 2 == 0) {
						for (int l = 0; l < 7; l++) {
							if (l == t) {
								if (X[j + dx1[l]][k + dy1[l]] == 0) {
									dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]] = min(dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]], dp[i % 2][j][k]);
								}
							}
							else {
								if (X[j + dx1[l]][k + dy1[l]] == 0) {
									dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]] = min(dp[(i + 1) % 2][j + dx1[l]][k + dy1[l]], (short)(dp[i % 2][j][k] + 1));
								}
							}
						}
					}
					if (abs(j - MAX_M) % 2 == 1) {
						for (int l = 0; l < 7; l++) {
							if (l == t) {
								if (X[j + dx2[l]][k + dy2[l]] == 0) {
									dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]] = min(dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]], dp[i % 2][j][k]);
								}
							}
							else {
								if (X[j + dx2[l]][k + dy2[l]] == 0) {
									dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]] = min(dp[(i + 1) % 2][j + dx2[l]][k + dy2[l]], (short)(dp[i % 2][j][k] + 1));
								}
							}
						}
					}
				}
			}
		}
		minx = min(minx, min(dp[0][gx + MAX_M][gy + MAX_M], dp[1][gx + MAX_M][gy + MAX_M]));
	}
	if (minx == (1 << 14)) { cout << "-1" << endl; }
	else { cout << minx << endl; }
	return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

* D is 0, 1 or 2.
* N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Examples

Input

0 5

Output

5

Input

1 11

Output

1100

Input

2 85

Output

850000

### Response

```cpp
#include<bits/stdc++.h>
using namespace std ;
int main ()  {
  int D , N ;
  cin >> D >> N ;
  cout<<N+(N==100)<<string(D*2,'0');
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.

The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.

Input

The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.

The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.

All the values are integer and between -100 and 100.

Output

Print "Yes" if squares intersect, otherwise print "No".

You can print each letter in any case (upper or lower).

Examples

Input

0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1

Output

YES

Input

0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1

Output

NO

Input

6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7

Output

YES

Note

In the first example the second square lies entirely within the first square, so they do intersect.

In the second sample squares do not have any points in common.

Here are images corresponding to the samples:

<image> <image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
set<long long int> s1, s2;
vector<long long int> v1, v2;
bool ans = false;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int x[5], y[5], a[4], b[4], c[4], d[4];
  x[4] = 0;
  y[4] = 0;
  for (int i = 0; i < 4; i++) {
    cin >> x[i] >> y[i];
    s1.insert(x[i]);
    s2.insert(y[i]);
    x[4] += x[i];
    y[4] += y[i];
  }
  x[4] /= 4;
  y[4] /= 4;
  for (auto it1 : s1) {
    v1.push_back(it1);
  }
  for (auto it1 : s2) {
    v2.push_back(it1);
  }
  for (int i = 0; i < 4; i++) {
    cin >> a[i] >> b[i];
    if (a[i] >= v1[0] && a[i] <= v1[1]) {
      if (b[i] >= v2[0] && b[i] <= v2[1]) {
        ans = true;
      }
    }
  }
  if (!ans) {
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 4; j++) {
        c[j] = (a[(j + 1) % 4] - a[j]) * (y[i] - b[j]) -
               (b[(j + 1) % 4] - b[j]) * (x[i] - a[j]);
      }
      bool ch = true;
      for (int j = 0; j < 4; j++) {
        x[i] = a[(j + 2) % 4];
        y[i] = b[(j + 2) % 4];
        d[j] = (a[(j + 1) % 4] - a[j]) * (y[i] - b[j]) -
               (b[(j + 1) % 4] - b[j]) * (x[i] - a[j]);
        c[j] *= d[j];
        if (c[j] < 0) ch = false;
      }
      if (ch) ans = true;
    }
  }
  if (ans)
    cout << "YES";
  else
    cout << "NO";
}

```


### Prompt

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

Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.

Input

The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.

Output

Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.

Examples

Input

3 3
000
010
000

Output

8

Input

5 4
1100
0000
0000
0000
0000

Output

16

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int n, m, a[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      a[i][j] = (c == '1') ? 1 : 0;
    }
  int res = 0;
  for (int hi = 0; hi < n; ++hi) {
    for (int hj = n - 1; hj >= hi; --hj) {
      for (int wi = 0; wi <= m; ++wi) {
        for (int wj = m - 1; wj >= wi; --wj) {
          int ok = 1;
          for (int i = hi; i <= hj; ++i) {
            for (int j = wi; j <= wj; ++j) {
              if (a[i][j]) {
                ok = 0;
                break;
              }
            }
            if (!ok) break;
          }
          if (ok) {
            res = max(res, (hj - hi + 1) * 2 + (wj - wi + 1) * 2);
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

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

In this problem you have to build tournament graph, consisting of n vertices, such, that for any oriented pair of vertices (v, u) (v ≠ u) there exists a path from vertex v to vertex u consisting of no more then two edges.

A directed graph without self-loops is a tournament, if there is exactly one edge between any two distinct vertices (in one out of two possible directions).

Input

The first line contains an integer n (3 ≤ n ≤ 1000), the number of the graph's vertices.

Output

Print -1 if there is no graph, satisfying the described conditions.

Otherwise, print n lines with n integers in each. The numbers should be separated with spaces. That is adjacency matrix a of the found tournament. Consider the graph vertices to be numbered with integers from 1 to n. Then av, u = 0, if there is no edge from v to u, and av, u = 1 if there is one.

As the output graph has to be a tournament, following equalities must be satisfied:

  * av, u + au, v = 1 for each v, u (1 ≤ v, u ≤ n; v ≠ u);
  * av, v = 0 for each v (1 ≤ v ≤ n).

Examples

Input

3

Output

0 1 0
0 0 1
1 0 0

Input

4

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int e[1000][1000];
int main() {
  cin >> n;
  if (n == 4) {
    puts("-1");
    return 0;
  }
  int m = n - (n & 1 ^ 1);
  for (int i = 0; i < m; ++i)
    for (int j = 1; j * 2 < m; ++j) e[i][(i + j) % m] = 1;
  if (m < n) {
    for (int i = 0; i < m; ++i) (i % 2 ? e[i][n - 1] : e[n - 1][i]) = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) printf("%d ", e[i][j]);
    puts("");
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.

The main school of the capital is located in (s_x, s_y). There are n students attending this school, the i-th of them lives in the house located in (x_i, y_i). It is possible that some students live in the same house, but no student lives in (s_x, s_y).

After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the i-th student goes from the school to his house is |s_x - x_i| + |s_y - y_i|.

The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the i-th student will buy a shawarma if at least one of the shortest paths from the school to the i-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).

You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.

Input

The first line contains three integers n, s_x, s_y (1 ≤ n ≤ 200 000, 0 ≤ s_x, s_y ≤ 10^{9}) — the number of students and the coordinates of the school, respectively.

Then n lines follow. The i-th of them contains two integers x_i, y_i (0 ≤ x_i, y_i ≤ 10^{9}) — the location of the house where the i-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.

Output

The output should consist of two lines. The first of them should contain one integer c — the maximum number of students that will buy shawarmas at the tent.

The second line should contain two integers p_x and p_y — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of p_x and p_y should be not less than 0 and not greater than 10^{9}.

Examples

Input

4 3 2
1 3
4 2
5 1
4 1

Output

3
4 2

Input

3 100 100
0 0
0 0
100 200

Output

2
99 100

Input

7 10 12
5 6
20 23
15 4
16 5
4 54
12 1
4 15

Output

4
10 11

Note

In the first example, If we build the shawarma tent in (4, 2), then the students living in (4, 2), (4, 1) and (5, 1) will visit it.

In the second example, it is possible to build the shawarma tent in (1, 1), then both students living in (0, 0) will visit it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
char num[maxn];
char num2[maxn];
vector<int> vec;
queue<int> que;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  int n = read(), sx = read(), sy = read();
  int s1 = 0, s2 = 0, s3 = 0, s4 = 0;
  int u = 0, d = 0, l = 0, r = 0;
  for (int i = 1; i <= n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x < sx) {
      if (y < sy) {
        s2++;
        s4++;
      } else if (y > sy) {
        s2++;
        s3++;
      } else if (y == sy) {
        d++;
      }
    } else if (x > sx) {
      if (y < sy) {
        s1++;
        s4++;
      } else if (y > sy) {
        s1++;
        s3++;
      } else {
        u++;
      }
    } else if (x == sx) {
      if (y < sy) {
        l++;
      } else if (y > sy) {
        r++;
      } else {
        continue;
      }
    }
  }
  int num1 = s1 + u;
  int num2 = s3 + r;
  int num3 = s2 + d;
  int num4 = s4 + l;
  if (num1 >= num2 && num1 > num3 && num1 >= num4) {
    printf("%d\n", num1);
    printf("%d %d\n", sx + 1, sy);
  } else if (num2 >= num1 && num2 > num3 && num2 >= num4) {
    cout << num2 << endl;
    printf("%d %d\n", sx, sy + 1);
  } else if (num3 >= num2 && num3 > num1 && num3 >= num4) {
    cout << num3 << endl;
    printf("%d %d\n", sx - 1, sy);
  } else if (num4 >= num2 && num4 > num3 && num4 >= num1) {
    cout << num4 << endl;
    printf("%d %d\n", sx, sy - 1);
  }
  return 0;
}

```


### Prompt

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

problem

Given the sequence $ A $ of length $ N $. The $ i $ item in $ A $ is $ A_i $. You can do the following for this sequence:

* $ 1 \ leq i \ leq N --Choose the integer i that is 1 $. Swap the value of $ A_i $ with the value of $ A_ {i + 1} $.

Find the minimum number of operations required to make $ A $ a sequence of bumps.

A sequence of length $ N $ that satisfies the following conditions is defined as a sequence of irregularities.

* For any $ i $ that satisfies $ 1 <i <N $, $ A_ {i + 1}, A_ {i --1}> A_i $ or $ A_ {i + 1}, A_ {i --1} <A_i Satisfy $.
Intuitively, increase, decrease, increase ... (decrease, like $ 1, \ 10, \ 2, \ 30, \ \ dots (10, \ 1, \ 30, \ 2, \ \ dots) $ It is a sequence that repeats increase, decrease ...).

output

Output the minimum number of operations required to make a sequence of bumps. Also, output a line break at the end.

Example

Input

5
1 2 3 4 5

Output

2

### Response

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

int n;
int a[125252];

int main(){
  scanf("%d",&n);
  int ans = 0;
  REP(i,n)scanf("%d",a+i);
  REP(i,n-2){
    int x = a[i];
    int y = a[i+1];
    int z = a[i+2];
    if((x<y&&y>z) || (x>y&&y<z))continue;
    if(i+2==n-1){
      swap(a[i+1], a[i+2]);
      ans++;
      continue;
    }
    int w = a[i+3];
    if(x>y && y>z){
      x *= -1;
      y *= -1;
      z *= -1;
      w *= -1;
    }
    // x < y < z ? w
    // x < y < z < w -> x < y > z < w
    // x < y < z > w -> x < y > w < z   or   x < z > y < w
    if(z<w){
      swap(a[i+1], a[i+2]);
      ans++;
    }else if(w<y){
      swap(a[i+2], a[i+3]);
      ans++;
    }else if(w>y){
      swap(a[i+1], a[i+2]);
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch.

You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income efficiency per hour.

You have to buy seeds to grow crops. Here, the name of the species of crop i is given by Li, and the price is given by Pi. When seeds are planted in the field, they sprout after time Ai. Young leaves appear 2 hours after the buds emerge. The leaves grow thick after Ci. The flowers bloom 10 hours after the leaves grow. Fruits come out time Ei after the flowers bloom. One seed produces Fi fruits, each of which sells at the price of Si. Some crops are multi-stage crops and bear a total of Mi fruit. In the case of a single-stage crop, it is represented by Mi = 1. Multi-season crops return to leaves after fruiting until the Mith fruit. The income for a seed is the amount of money sold for all the fruits of that seed minus the price of the seed. In addition, the income efficiency of the seed is the value obtained by dividing the income by the time from planting the seed to the completion of all the fruits.

Your job is to write a program that sorts and outputs crop information given as input, sorted in descending order of income efficiency.

Input

The input is a sequence of datasets, and each dataset is given in the following format.

> N
> L1 P1 A1 B1 C1 D1 E1 F1 S1 M1
> L2 P2 A2 B2 C2 D2 E2 F2 S2 M2
> ...
> LN PN AN BN CN DN EN FN SN MN
>

The first line is the number of crops N in the dataset (1 ≤ N ≤ 50).

The N lines that follow contain information about one crop in each line. The meaning of each variable is as described in the problem statement. The crop name Li is a string of up to 20 characters consisting of only lowercase letters, and 1 ≤ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≤ 100, 1 ≤ Mi ≤ 5. It can be assumed that no crop has the same name in one case.

The end of the input is represented by a line containing only one zero.

Output

For each dataset, output the crop names, one for each row, in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending dictionary order.

After the output of each data set, output one line consisting of only "#".

Example

Input

5
apple 1 1 1 1 1 1 1 10 1
banana 1 2 2 2 2 2 1 10 1
carrot 1 2 2 2 2 2 1 10 2
durian 1 3 3 3 3 3 1 10 1
eggplant 1 3 3 3 3 3 1 100 1
4
enoki 1 3 3 3 3 3 1 10 1
tomato 1 3 3 3 3 3 1 10 1
potato 1 3 3 3 3 3 1 10 1
onion 1 3 3 3 3 3 1 10 1
3
a 10 1 1 1 1 1 1 10 1
b 10 2 2 2 2 2 2 10 1
c 10 2 2 2 2 2 2 10 1
0

Output

eggplant
apple
carrot
banana
durian
#
enoki
onion
potato
tomato
#
b
c
a
#

### Response

```cpp
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct gds{
    string name;
    int a;
    int b;
};

int main(){
    int n,i,P,A,B,C,D,E,F,S,M;
    int a,b;
    string L;
    while(1){
        cin>>n;
        if(!n){break;}
        vector<gds> items(n);
        for(i=0;i<n;i++){
            cin>>L>>P>>A>>B>>C>>D>>E>>F>>S>>M;
            a=F*S*M-P;
            b=A+B+C+D+E+(D+E)*(M-1);
            struct gds buf={L,a,b};
            items[i]=buf;
        }
        sort(items.begin(),items.end(),[](const gds& a, const gds& b){return a.a*b.b==b.a*a.b ? a.name<b.name : a.a*b.b>b.a*a.b;});

        for(auto it=items.begin();it!=items.end();it++){
            cout<<it->name<<endl;
        }
        cout<<"#"<<endl;
    }
    return 0;
}

```


### Prompt

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

Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all.

Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula:

<image> The less value c(a) is, the more beautiful the array is.

It’s time to change the world and Levko is going to change his array for the better. To be exact, Levko wants to change the values of at most k array elements (it is allowed to replace the values by any integers). Of course, the changes should make the array as beautiful as possible.

Help Levko and calculate what minimum number c(a) he can reach.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2000). The second line contains space-separated integers a1, a2, ... , an ( - 109 ≤ ai ≤ 109).

Output

A single number — the minimum value of c(a) Levko can get.

Examples

Input

5 2
4 7 4 7 4

Output

0

Input

3 1
-100 0 100

Output

100

Input

6 3
1 2 3 7 8 9

Output

1

Note

In the first sample Levko can change the second and fourth elements and get array: 4, 4, 4, 4, 4.

In the third sample he can get array: 1, 2, 3, 4, 5, 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
int dp[maxn], n, k;
int a[maxn];
bool check(int d) {
  int x, y, z;
  for (int i = 1; i <= n; ++i) {
    dp[i] = i - 1;
    for (int j = 1; j < i; ++j) {
      if ((i - j - 1) >= dp[i]) break;
      x = a[j];
      y = a[i];
      if (x > y) {
        z = x;
        x = y;
        y = z;
      }
      if (x + (long long)(i - j) * d < y) continue;
      if (dp[j] + (i - j - 1) < dp[i]) dp[i] = dp[j] + (i - j - 1);
    }
  }
  for (int i = n; i >= 1; --i) {
    if (dp[i] + (n - i) <= k) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &k);
  long long L = 0, R = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (i > 1) R = max(R, (long long)abs(a[i] - a[i - 1]));
  }
  while (L < R) {
    int m = (L + R) >> 1;
    if (check(m))
      R = m;
    else
      L = m + 1;
  }
  printf("%I64d\n", L);
  return 0;
}

```


### Prompt

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

There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.

Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.

They want to divide the balloons among themselves. In addition, there are several conditions to hold:

  * Do not rip the packets (both Grigory and Andrew should get unbroken packets);
  * Distribute all packets (every packet should be given to someone);
  * Give both Grigory and Andrew at least one packet;
  * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.

Help them to divide the balloons or determine that it's impossible under these conditions.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons.

The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet.

Output

If it's impossible to divide the balloons satisfying the conditions above, print -1.

Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter.

If there are multiple ways to divide balloons, output any of them.

Examples

Input

3
1 2 1

Output

2
1 2

Input

2
5 5

Output

-1

Input

1
10

Output

-1

Note

In the first test Grigory gets 3 balloons in total while Andrey gets 1.

In the second test there's only one way to divide the packets which leads to equal numbers of balloons.

In the third test one of the boys won't get a packet at all.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int z, n, s, p;
  s = 0;
  p = 0;
  vector<int> b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> z;
    b.push_back(z);
  }
  if (n == 1)
    cout << "-1" << endl;
  else {
    for (int i = 0; i < n - 1; i++) s = s + b[i];
    if (s == b[n - 1]) {
      if (b[n - 2] == b[n - 1])
        cout << "-1" << endl;
      else {
        cout << n - 1 << endl;
        for (int i = 1; i < n - 1; i++) cout << i << " ";
        cout << n << endl;
      }
    } else {
      cout << n - 1 << endl;
      for (int i = 1; i < n; i++) cout << i << " ";
      cout << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.

The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)

Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.

Input

The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated.

Output

Print the required number of different ways to decorate the box.

Examples

Input

YYYYYY

Output

1

Input

BOOOOB

Output

2

Input

ROYGBV

Output

30

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int a[6] = {0}, b[7] = {0};
  char s[7];
  int i;
  scanf("%s", s);
  for (i = 0; i < 6; i++) {
    switch (s[i]) {
      case 'R':
        a[0]++;
        break;
      case 'O':
        a[1]++;
        break;
      case 'Y':
        a[2]++;
        break;
      case 'G':
        a[3]++;
        break;
      case 'B':
        a[4]++;
        break;
      case 'V':
        a[5]++;
        break;
    }
  }
  for (i = 0; i < 6; i++) b[a[i]]++;
  if (b[6] == 1 || b[5] == 1) {
    puts("1");
  } else if (b[4] == 1 || b[3] == 2) {
    puts("2");
  } else if (b[3] == 1) {
    if (b[2] == 1) {
      puts("3");
    } else {
      puts("5");
    }
  } else if (b[2] == 3) {
    puts("6");
  } else if (b[2] == 2) {
    puts("8");
  } else if (b[2] == 1) {
    puts("15");
  } else {
    puts("30");
  }
  return 0;
}

```


### Prompt

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

Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).

Find the number on the n-th position of the sequence.

Input

The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find.

Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Output

Print the element in the n-th position of the sequence (the elements are numerated from one).

Examples

Input

3

Output

2

Input

5

Output

2

Input

10

Output

4

Input

55

Output

10

Input

56

Output

1

### Response

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

```


### Prompt

Generate a CPP solution to the following problem:

Snuke found N strange creatures. Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.

Every creature can absorb another creature whose size is at most twice the size of itself. When a creature of size A and color B absorbs another creature of size C and color D (C \leq 2 \times A), they will merge into one creature of size A+C and color B. Here, depending on the sizes of two creatures, it is possible that both of them can absorb the other.

Snuke has been watching these creatures merge over and over and ultimately become one creature. Find the number of the possible colors of this creature.

Constraints

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

Input

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

N
A_1 A_2 … A_N

Output

Print the number of the possible colors of the last remaining creature after the N creatures repeatedly merge and ultimately become one creature.

Examples

Input

3
3 1 4

Output

2

Input

5
1 1 1 1 1

Output

5

Input

6
40 1 30 2 7 20

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define N 200000
#define LL long long
int n, ai[N], l;
LL s;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> ai[i];
    sort(ai + 1, ai + n + 1);
    for (int i = 1; i <= n; ++ i)
    {
        if (s * 2 < ai[i]) l = i;
        s += ai[i];
    }
    cout << n - l + 1;
}

```


### Prompt

Create a solution in CPP for the following problem:

There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting sequence, i.e. the number of such index pairs (i, j), that i < j and pi > pj.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of swap operations applied to the sequence.

Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109, ai ≠ bi) — the arguments of the swap operation.

Output

Print a single integer — the number of inversions in the resulting sequence.

Examples

Input

2
4 2
1 4

Output

4

Input

3
1 6
3 4
2 5

Output

15

Note

In the first sample the sequence is being modified as follows: <image>. It has 4 inversions formed by index pairs (1, 4), (2, 3), (2, 4) and (3, 4).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, tmp;
int T[4 * 300009];
long long ans;
map<int, int> M, N, pos, id;
pair<long long, long long> v[300009];
vector<int> q;
vector<pair<int, int> > qq;
void upd(int x, int l, int r, int node) {
  T[node]++;
  if (l == r) return;
  if (x <= (l + r) / 2)
    upd(x, l, (l + r) / 2, node * 2);
  else
    upd(x, (l + r) / 2 + 1, r, node * 2 + 1);
}
int tap(int x, int l, int r, int node) {
  if (l == r) return T[node];
  if (x <= (l + r) / 2)
    return tap(x, l, (l + r) / 2, node * 2);
  else
    return tap(x, (l + r) / 2 + 1, r, node * 2 + 1) + T[node * 2];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (!M[a]) M[a] = a;
    if (!M[b]) M[b] = b;
    swap(M[a], M[b]);
    id[a] = id[b] = 1;
  }
  for (typeof((M).begin()) i = (M).begin(); i != (M).end(); i++) {
    pos[i->second] = i->first;
    q.push_back(i->second);
    qq.push_back(make_pair(i->first, i->second));
  }
  for (typeof((id).begin()) i = (id).begin(); i != (id).end(); i++)
    i->second = ++tmp;
  sort(q.begin(), q.end());
  tmp = 0;
  for (int i = 0; i < q.size(); i++) N[q[i]] = ++tmp;
  for (int i = qq.size() - 1; i >= 0; i--) {
    ans += tap(N[qq[i].second], 1, 300009, 1);
    upd(N[qq[i].second], 1, 300009, 1);
  }
  for (typeof((pos).begin()) i = (pos).begin(); i != (pos).end(); i++) {
    int l = min(i->first, i->second);
    int r = max(i->first, i->second);
    if (l < r) {
      ans += r - l - 1;
      ans -= id[r] - id[l] - 1;
    }
  }
  cout << ans;
}

```


### Prompt

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

After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.

The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.

A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of 7 because its subribbon a appears 7 times, and the ribbon abcdabc has the beauty of 2 because its subribbon abc appears twice.

The rules are simple. The game will have n turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after n turns wins the treasure.

Could you find out who is going to be the winner if they all play optimally?

Input

The first line contains an integer n (0 ≤ n ≤ 10^{9}) — the number of turns.

Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than 10^{5} uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.

Output

Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".

Examples

Input

3
Kuroo
Shiro
Katie

Output

Kuro

Input

7
treasurehunt
threefriends
hiCodeforces

Output

Shiro

Input

1
abcabc
cbabac
ababca

Output

Katie

Input

15
foPaErcvJ
mZaxowpbt
mkuOlaHRE

Output

Draw

Note

In the first example, after 3 turns, Kuro can change his ribbon into ooooo, which has the beauty of 5, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most 4, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.

In the fourth example, since the length of each of the string is 9 and the number of turn is 15, everyone can change their ribbons in some way to reach the maximal beauty of 9 by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[3];
  int n, i, j, k, maxn[3] = {0};
  cin >> n;
  getchar();
  for (i = 0; i < 3; i++) getline(cin, s[i]);
  int cnt = 0;
  map<char, int> ys[3];
  for (i = 0; i < 3; i++) {
    cnt = 0;
    for (auto a : s[i]) {
      cnt = max(cnt, ++ys[i][a]);
    }
    int len = s[i].size();
    maxn[i] = cnt;
    if (len == cnt) {
      if (n == 1) maxn[i]--;
    } else {
      if (len - cnt <= n)
        maxn[i] = len;
      else
        maxn[i] = cnt + n;
    }
  }
  if (maxn[0] > maxn[1] && maxn[0] > maxn[2]) {
    puts("Kuro");
  } else if (maxn[1] > maxn[0] && maxn[1] > maxn[2]) {
    puts("Shiro");
  } else if (maxn[2] > maxn[0] && maxn[2] > maxn[1]) {
    puts("Katie");
  } else {
    puts("Draw");
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are planning to buy an apartment in a n-floor building. The floors are numbered from 1 to n from the bottom to the top. At first for each floor you want to know the minimum total time to reach it from the first (the bottom) floor.

Let:

  * a_i for all i from 1 to n-1 be the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i-th as well) using the stairs;
  * b_i for all i from 1 to n-1 be the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i-th as well) using the elevator, also there is a value c — time overhead for elevator usage (you need to wait for it, the elevator doors are too slow!).

In one move, you can go from the floor you are staying at x to any floor y (x ≠ y) in two different ways:

  * If you are using the stairs, just sum up the corresponding values of a_i. Formally, it will take ∑_{i=min(x, y)}^{max(x, y) - 1} a_i time units.
  * If you are using the elevator, just sum up c and the corresponding values of b_i. Formally, it will take c + ∑_{i=min(x, y)}^{max(x, y) - 1} b_i time units.

You can perform as many moves as you want (possibly zero).

So your task is for each i to determine the minimum total time it takes to reach the i-th floor from the 1-st (bottom) floor.

Input

The first line of the input contains two integers n and c (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ c ≤ 1000) — the number of floors in the building and the time overhead for the elevator rides.

The second line of the input contains n - 1 integers a_1, a_2, ..., a_{n-1} (1 ≤ a_i ≤ 1000), where a_i is the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i-th as well) using the stairs.

The third line of the input contains n - 1 integers b_1, b_2, ..., b_{n-1} (1 ≤ b_i ≤ 1000), where b_i is the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i-th as well) using the elevator.

Output

Print n integers t_1, t_2, ..., t_n, where t_i is the minimum total time to reach the i-th floor from the first floor if you can perform as many moves as you want.

Examples

Input

10 2
7 6 18 6 16 18 1 17 17
6 9 3 10 9 1 10 1 5

Output

0 7 13 18 24 35 36 37 40 45

Input

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

Output

0 2 4 7 8 11 13 14 16 17

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a, b;
  for (long long int i = 0; i < n - 1; i++) {
    long long int x;
    cin >> x;
    a.push_back(x);
  }
  for (long long int i = 0; i < n - 1; i++) {
    long long int y;
    cin >> y;
    b.push_back(y);
  }
  vector<vector<long long int>> dp(n + 1, vector<long long int>(2, INT_MAX));
  dp[0][1] = k;
  dp[0][0] = 0;
  for (long long int i = 0; i <= n - 2; i++) {
    dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + a[i]);
    dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + a[i]);
    dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + b[i] + k);
    dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + b[i]);
    if (i == 0) {
    }
  }
  for (long long int i = 0; i <= n - 1; i++) {
    cout << min(dp[i][0], dp[i][1]) << " ";
  }
  cout << '\n';
  return 0;
}

```


### Prompt

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

There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input

The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output

Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples

Input

great10

Output

7

Input

aaaaaaaaaa

Output

100

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int kei[0x100];
int de(char a) {
  if (a <= 'z' && a >= 'a')
    return (a - 'a');
  else
    return (a - '0') + 26;
}
int main() {
  int i;
  string s;
  long long out = 0;
  memset(kei, 0, sizeof(kei));
  cin >> s;
  for (i = 0; i < s.size(); i++) kei[s[i]]++;
  for (i = 0; i < 0x100; i++) out += (long long)kei[i] * kei[i];
  cout << out << endl;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given a sequence a_1, a_2, ..., a_n, consisting of integers.

You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning, or to the end of a. Note that you have to move all these elements in one direction in one operation.

For example, if a = [2, 1, 3, 1, 1, 3, 2], you can get the following sequences in one operation (for convenience, denote elements equal to x as x-elements):

  * [1, 1, 1, 2, 3, 3, 2] if you move all 1-elements to the beginning;
  * [2, 3, 3, 2, 1, 1, 1] if you move all 1-elements to the end;
  * [2, 2, 1, 3, 1, 1, 3] if you move all 2-elements to the beginning;
  * [1, 3, 1, 1, 3, 2, 2] if you move all 2-elements to the end;
  * [3, 3, 2, 1, 1, 1, 2] if you move all 3-elements to the beginning;
  * [2, 1, 1, 1, 2, 3, 3] if you move all 3-elements to the end;

You have to determine the minimum number of such operations so that the sequence a becomes sorted in non-descending order. Non-descending order means that for all i from 2 to n, the condition a_{i-1} ≤ a_i is satisfied.

Note that you have to answer q independent queries.

Input

The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of the queries. Each query is represented by two consecutive lines.

The first line of each query contains one integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of elements.

The second line of each query contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ n) — the elements.

It is guaranteed that the sum of all n does not exceed 3 ⋅ 10^5.

Output

For each query print one integer — the minimum number of operation for sorting sequence a in non-descending order.

Example

Input

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

Output

2
0
1

Note

In the first query, you can move all 1-elements to the beginning (after that sequence turn into [1, 1, 1, 3, 6, 6, 3]) and then move all 6-elements to the end.

In the second query, the sequence is sorted initially, so the answer is zero.

In the third query, you have to move all 2-elements to the beginning.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    set<int> s;
    vector<int> f(n + 1, 0), l(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if (f[x] == 0) f[x] = i;
      l[x] = i;
      s.insert(x);
    }
    int ans = n;
    int prev = -1;
    int last = -1;
    for (auto &it : s) {
      if (prev == -1)
        prev = 1;
      else if (l[last] > f[it])
        prev = 1;
      else
        prev++;
      ans = min(ans, (int)s.size() - prev);
      last = it;
    }
    cout << ans << "\n";
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people, so each person agrees to swap places with the person right behind him for just 1 dollar. More formally, if person a stands just behind person b, then person a can pay person b 1 dollar, then a and b get swapped. Of course, if person a has zero dollars, he can not swap places with person b.

Residents of Berland are strange people. In particular, they get upset when there is someone with a strictly smaller sum of money in the line in front of them.

Can you help the residents of Berland form such order in the line so that they were all happy? A happy resident is the one who stands first in the line or the one in front of who another resident stands with not less number of dollars. Note that the people of Berland are people of honor and they agree to swap places only in the manner described above.

Input

The first line contains integer n (1 ≤ n ≤ 200 000) — the number of residents who stand in the line.

The second line contains n space-separated integers ai (0 ≤ ai ≤ 109), where ai is the number of Berland dollars of a man standing on the i-th position in the line. The positions are numbered starting from the end of the line.

Output

If it is impossible to make all the residents happy, print ":(" without the quotes. Otherwise, print in the single line n space-separated integers, the i-th of them must be equal to the number of money of the person on position i in the new line. If there are multiple answers, print any of them.

Examples

Input

2
11 8

Output

9 10

Input

5
10 9 7 10 6

Output

:(

Input

3
12 3 3

Output

4 4 10

Note

In the first sample two residents should swap places, after that the first resident has 10 dollars and he is at the head of the line and the second resident will have 9 coins and he will be at the end of the line.

In the second sample it is impossible to achieve the desired result.

In the third sample the first person can swap with the second one, then they will have the following numbers of dollars: 4 11 3, then the second person (in the new line) swaps with the third one, and the resulting numbers of dollars will equal to: 4 4 10. In this line everybody will be happy.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int val[500005], lazy[500005], data[500005], size[500005];
int lc[500005], rc[500005], fa[500005];
void Add(int t, int ret) {
  val[t] += ret;
  lazy[t] += ret;
  data[t] += ret;
}
void down(int t) {
  if (lazy[t]) {
    if (lc[t]) Add(lc[t], lazy[t]);
    if (rc[t]) Add(rc[t], lazy[t]);
    lazy[t] = 0;
  }
}
void update(int t) {
  data[t] = val[t];
  size[t] = 1;
  if (lc[t]) data[t] = max(data[t], data[lc[t]]), size[t] += size[lc[t]];
  if (rc[t]) data[t] = max(data[t], data[rc[t]]), size[t] += size[rc[t]];
}
void zig(int x) {
  int y = fa[x], z = fa[y];
  fa[x] = z;
  fa[y] = x;
  fa[rc[x]] = y;
  lc[y] = rc[x];
  rc[x] = y;
  if (lc[z] == y) lc[z] = x;
  if (rc[z] == y) rc[z] = x;
  update(y);
}
void zag(int x) {
  int y = fa[x], z = fa[y];
  fa[x] = z;
  fa[y] = x;
  fa[lc[x]] = y;
  rc[y] = lc[x];
  lc[x] = y;
  if (lc[z] == y) lc[z] = x;
  if (rc[z] == y) rc[z] = x;
  update(y);
}
int stk[500005], root, tot, ans[500005];
void splay(int x) {
  int y, z = 0;
  for (y = x; y; y = fa[y]) stk[++z] = y;
  for (; z; z--) down(stk[z]);
  while (fa[x]) {
    y = fa[x];
    z = fa[y];
    if (fa[y]) {
      if (lc[z] == y) {
        if (lc[y] == x)
          zig(y), zig(x);
        else
          zag(x), zig(x);
      } else {
        if (rc[y] == x)
          zag(y), zag(x);
        else
          zig(x), zag(x);
      }
    } else if (lc[y] == x)
      zig(x);
    else
      zag(x);
  }
  root = x;
  update(x);
}
void solve(int t) {
  if (!t) return;
  down(t);
  solve(lc[t]);
  ++tot;
  ans[tot] = val[t] - tot;
  solve(rc[t]);
}
int tmp = 0;
void writeln(int t) {
  if (!t) return;
  down(t);
  writeln(lc[t]);
  ++tmp;
  printf("%d ", val[t] - tmp);
  writeln(rc[t]);
}
int find(int x, int key) {
  if (!x) return 0;
  if (data[lc[x]] <= key) {
    if (val[x] > key) return find(lc[x], key);
    int t = find(rc[x], key);
    if (t == 0) t = x;
    return t;
  } else
    return find(lc[x], key);
}
int a[500005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = n; i >= 1; i--) {
    val[i] = a[i] + i;
    int t = find(root, val[i]);
    if (t) {
      splay(t);
      if (!rc[t]) {
        rc[t] = i;
        fa[i] = t;
        splay(i);
      } else {
        for (t = rc[t]; lc[t]; t = lc[t])
          ;
        lc[t] = i;
        fa[i] = t;
        splay(i);
      }
    } else {
      if (!root) {
        root = i;
        update(root);
        continue;
      }
      for (t = root; lc[t]; t = lc[t])
        ;
      lc[t] = i;
      fa[i] = t;
      splay(i);
    }
  }
  tot = 0;
  solve(root);
  for (int i = 1; i <= n - 1; i++)
    if (ans[i] > ans[i + 1]) {
      printf(":(\n");
      return 0;
    }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
}

```


### Prompt

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

The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates. The flamingos are currently sleeping and you can assume that they don't move.

In order to get a good view over the flamingos, each of the binoculars can be independently rotated to face any angle (not necessarily integer). Then, the binocular can be used to observe all flamingos that is located at the straight line passing through the binocular at the angle it is set. In other words, you can assign each binocular a direction corresponding to any straight line passing through the binocular, and the binocular will be able to see all flamingos located on that line.

Today, some kids from the prestigious Codeforces kindergarten went on a Field Study to the Zoo. Their teacher would like to set each binocular an angle to maximize the number of flamingos that can be seen by the binocular. The teacher is very interested in the sum of these values over all binoculars. Please help him find this sum.

Input

The first line contains two space-separated integers n and m (1 ≤ n ≤ 106, 1 ≤ m ≤ 250), denoting the number of binoculars and the number of flamingos, respectively.

Then m lines follow, the i-th line will contain two space-separated integers xi and yi (1 ≤ xi, yi ≤ 109), which means that the i-th flamingo is located at point (xi, yi).

All flamingos will be located at distinct points.

Output

Print a single integer denoting the maximum total number of flamingos that can be seen by all the binoculars.

Examples

Input

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

Output

11

Note

This picture shows the answer to the example test case.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int maxans[1000005];
long long x[255];
long long y[255];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
  }
  for (int i = 1; i <= n; i++) {
    maxans[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      long long t = 0;
      if (y[i] != y[j]) {
        if ((((x[i] - x[j]) * y[i]) % (y[i] - y[j])) == 0) {
          t = x[i] - (((x[i] - x[j]) * y[i]) / (y[i] - y[j]));
          if (t >= 1 && t <= n) {
            int cur = 2;
            for (int k = j + 1; k < m; k++) {
              if (((y[i] - y[j]) * (x[i] - x[k])) ==
                  ((y[i] - y[k]) * (x[i] - x[j]))) {
                cur++;
              }
            }
            maxans[t] = max(maxans[t], cur);
          }
        }
      } else {
        t = x[i];
        if (t >= 1 && t <= n) {
          int cur = 1;
          for (int k = i + 1; k < m; k++) {
            if (x[k] == t) {
              cur++;
            }
          }
          maxans[t] = max(maxans[t], cur);
        }
      }
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += maxans[i];
  }
  printf("%lld\n", sum);
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N.

The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional.

We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i.

* Each a_i is a non-negative integer.
* For each edge (i, j), a_i \neq a_j holds.
* For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds.

Determine whether there exists such an assignment.

Constraints

* 2 ≤ N ≤ 200 000
* 1 ≤ p_i ≤ N
* p_i \neq i
* The graph is weakly connected.

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

If the assignment is possible, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.

Examples

Input

4
2 3 4 1

Output

POSSIBLE

Input

3
2 3 1

Output

IMPOSSIBLE

Input

4
2 3 1 1

Output

POSSIBLE

Input

6
4 5 6 5 6 4

Output

IMPOSSIBLE

### Response

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

int n;
vector<int> out[200010];
int in[200010];
int cycle[200010];
int grundy[200010];
int st = -1;
const int CYCLE = 42;

int dfs(int x) {
	cycle[x] = 1;
	for(int i : out[x]) {
		if(cycle[i] == 1) {
			st = i;
			cycle[x] = CYCLE;
			return CYCLE;
		}
		else if(cycle[i] == 0) {
			if(dfs(i) == CYCLE) {
				cycle[x] = CYCLE;
				if(x == st) return 0;
				else return CYCLE;
			}
		}
	}
	cycle[x] = 2;
	return 0;
}

int getgrundy(int x) {
	set<int> s;
	for(int i : out[x])
		if(cycle[i] != CYCLE)
			s.insert(getgrundy(i));
	int ans = 0;
	auto it = s.begin();
	while(it != s.end()) {
		if(*it == ans) {
			++ans;
			++it;
		}
		else return grundy[x] = ans;
	}
	return grundy[x] = ans;
}

bool chk(int x, int val, int res) {
	if(x == st) return res == val;
	int nxt = -1;
	for(int i : out[x]) {
		if(cycle[i] == CYCLE) {
			nxt = i;
		}
	}
	return chk(nxt, grundy[nxt] + (grundy[nxt] == val), res);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	memset(cycle, 0, sizeof cycle);
	for(int i = 0; i < n; ++i){
		int x;
		cin >> x;
		--x;
		out[x].push_back(i);
		in[i] = x;
		if(x < i and in[x] == i) {
			st = i;
			cycle[x] = cycle[i] = CYCLE;
		}
	}
	for(int i = 0; st == -1 and i < n; ++i) if(cycle[i] == 0) dfs(i);
	for(int i = 0; i < n; ++i) if(cycle[i] == CYCLE) getgrundy(i);
	int nxt;
	for(int i : out[st]) {
		if(cycle[i] == CYCLE) {
			nxt = i;
		}
	}
	if(st == nxt or chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
	else if (chk(nxt, grundy[nxt] + ((grundy[st] + 1) == grundy[nxt]), grundy[st] + 1)) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;

}

```


### Prompt

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

Snuke has two boards, each divided into a grid with N rows and N columns. For both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j).

There is a lowercase English letter written in each square on the first board. The letter written in Square (i,j) is S_{i,j}. On the second board, nothing is written yet.

Snuke will write letters on the second board, as follows:

* First, choose two integers A and B ( 0 \leq A, B < N ).
* Write one letter in each square on the second board. Specifically, write the letter written in Square ( i+A, j+B ) on the first board into Square (i,j) on the second board. Here, the k-th row is also represented as the (N+k)-th row, and the k-th column is also represented as the (N+k)-th column.

After this operation, the second board is called a good board when, for every i and j ( 1 \leq i, j \leq N ), the letter in Square (i,j) and the letter in Square (j,i) are equal.

Find the number of the ways to choose integers A and B ( 0 \leq A, B < N ) such that the second board is a good board.

Constraints

* 1 \leq N \leq 300
* S_{i,j} ( 1 \leq i, j \leq N ) is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

N
S_{1,1}S_{1,2}..S_{1,N}
S_{2,1}S_{2,2}..S_{2,N}
:
S_{N,1}S_{N,2}..S_{N,N}

Output

Print the number of the ways to choose integers A and B ( 0 \leq A, B < N ) such that the second board is a good board.

Examples

Input

2
ab
ca

Output

2

Input

4
aaaa
aaaa
aaaa
aaaa

Output

16

Input

5
abcde
fghij
klmno
pqrst
uvwxy

Output

0

### Response

```cpp
// https://atcoder.jp/contests/agc023/tasks/agc023_b
#include <bits/stdc++.h>
int n, t;
char s[305][305];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%s", s[i]);
    for (int i = 0; i < n; i++) {
        bool ok = true;
        for (int j = 0; ok & j < n - 1; j++)
            for (int k = j + 1; ok & k < n; k++)
                if (s[(j + i) % n][k] != s[(k + i) % n][j])
                    ok = false;
        t += ok;
    }
    printf("%d\n", t * n);
}
```


### Prompt

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

Diameter of a Tree

Given a tree T with non-negative weight, find the diameter of the tree.

The diameter of a tree is the maximum distance between two nodes in a tree.

Constraints

* 1 ≤ n ≤ 100,000
* 0 ≤ wi ≤ 1,000

Input

n
s1 t1 w1
s2 t2 w2
:
sn-1 tn-1 wn-1

The first line consists of an integer n which represents the number of nodes in the tree. Every node has a unique ID from 0 to n-1 respectively.

In the following n-1 lines, edges of the tree are given. si and ti represent end-points of the i-th edge (undirected) and wi represents the weight (distance) of the i-th edge.

Output

Print the diameter of the tree in a line.

Examples

Input

4
0 1 2
1 2 1
1 3 3

Output

5

Input

4
0 1 1
1 2 2
2 3 4

Output

7

### Response

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

typedef pair<int, int> P;

int n;

vector<int> dijkstra(int s, vector<vector<P>> &G){
    vector<int> dist(n, 1e9);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(!que.empty()){
        int ccost, cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[cv] < ccost) continue;

        for(auto x : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = x;

            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist;
}

int main(){
    cin>>n;
    vector<vector<P>> G(n);
    for(int i=0; i<n-1; i++){
        int s, t, w; cin>>s>>t>>w;
        G[s].emplace_back(t, w);
        G[t].emplace_back(s, w);
    }

    vector<int> dist1 = dijkstra(0, G);
    int v1 = max_element(dist1.begin(), dist1.end()) - dist1.begin();
    vector<int> dist2 = dijkstra(v1, G);

    cout << *max_element(dist2.begin(), dist2.end()) << endl;
}

```


### Prompt

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

Ujan decided to make a new wooden roof for the house. He has n rectangular planks numbered from 1 to n. The i-th plank has size a_i × 1 (that is, the width is 1 and the height is a_i).

Now, Ujan wants to make a square roof. He will first choose some of the planks and place them side by side in some order. Then he will glue together all of these planks by their vertical sides. Finally, he will cut out a square from the resulting shape in such a way that the sides of the square are horizontal and vertical.

For example, if Ujan had planks with lengths 4, 3, 1, 4 and 5, he could choose planks with lengths 4, 3 and 5. Then he can cut out a 3 × 3 square, which is the maximum possible. Note that this is not the only way he can obtain a 3 × 3 square.

<image>

What is the maximum side length of the square Ujan can get?

Input

The first line of input contains a single integer k (1 ≤ k ≤ 10), the number of test cases in the input.

For each test case, the first line contains a single integer n (1 ≤ n ≤ 1 000), the number of planks Ujan has in store. The next line contains n integers a_1, …, a_n (1 ≤ a_i ≤ n), the lengths of the planks.

Output

For each of the test cases, output a single integer, the maximum possible side length of the square.

Example

Input

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

Output

3
4
1
3

Note

The first sample corresponds to the example in the statement.

In the second sample, gluing all 4 planks will result in a 4 × 4 square.

In the third sample, the maximum possible square is 1 × 1 and can be taken simply as any of the planks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  int k, n, ans, a[1001], i, t;
  cin >> k;
  while (k--) {
    ans = 0;
    cin >> n;
    for (i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + n);
    for (i = 0; i < n; ++i) {
      t = min(n - i, a[i]);
      ans = max(ans, t);
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

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

In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is commonly encountered while you are in America.

A value in Fahrenheit can be converted to Celsius by first subtracting $32$ and then multiplying by $\frac{5}{9}$. A simplified method may be used to produce a rough estimate: first subtract $30$ and then divide by $2$. Using the latter method, $68$ Fahrenheit is converted to $19$ Centigrade, i.e., $\frac{(68-30)}{2}$.

Make a program to convert Fahrenheit to Celsius using the simplified method: $C = \frac{F - 30}{2}$.

Input

The input is given in the following format.

$F$

The input line provides a temperature in Fahrenheit $F$ ($30 \leq F \leq 100$), which is an integer divisible by $2$.

Output

Output the converted Celsius temperature in a line.

Examples

Input

68

Output

19

Input

50

Output

10

### Response

```cpp
#include "bits/stdc++.h"

using namespace std;

int main()
{
    int f;
    cin >> f;
    cout << (f-30)/2<< endl;
    return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:

  * a1 = p, where p is some integer;
  * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is some integer.

Right now Gena has a piece of paper with sequence b, consisting of n integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.

Sequence s1, s2, ..., sk is a subsequence of sequence b1, b2, ..., bn, if there is such increasing sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n), that bij = sj. In other words, sequence s can be obtained from b by crossing out some elements.

Input

The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106).

Output

Print a single integer — the length of the required longest subsequence.

Examples

Input

2
3 5

Output

2

Input

4
10 20 10 30

Output

3

Note

In the first test the sequence actually is the suitable subsequence.

In the second test the following subsequence fits: 10, 20, 10.

### Response

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

```


### Prompt

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

Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.

Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.

The English alphabet vowels are: A, E, I, O, U, Y

The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z

Input

The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.

Output

Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".

Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.

Examples

Input

Is it a melon?

Output

NO

Input

Is it an apple?

Output

YES

Input

  Is     it a banana ?

Output

YES

Input

Is   it an apple  and a  banana   simultaneouSLY?

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  string s;
  getline(cin, s);
  for (int i = s.size() - 1; i >= 0; --i) {
    char c = tolower(s[i]);
    if (isalpha(c)) {
      if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y')
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
      break;
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.

Output

Print a single line containing n digits — the desired state of the display containing the smallest possible number.

Examples

Input

3
579

Output

024

Input

4
2014

Output

0142

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  string s, mini;
  cin >> n >> s;
  mini = s;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < n; ++j) {
      char c = s[n - 1];
      s = s.substr(0, n - 1);
      string aux = "";
      aux.push_back(c);
      aux.append(s);
      s = aux;
      mini = min(mini, s);
    }
    for (int j = 0; j < n; ++j) s[j] = s[j] != '9' ? s[j] + 1 : '0';
  }
  cout << mini << "\n";
  return 0;
}

```


### Prompt

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

In this problem you have to solve a simple classification task: given an image, determine whether it depicts a Fourier doodle.

You are given a set of 50 images with ids 1 through 50. You are also given a text file labels.txt containing the labels for images with ids 1 through 20, which comprise the learning data set.

You have to output the classification results for images with ids 21 through 50 in the same format.

Input

[Download the images and the training labels](http://tc-alchemy.progopedia.com/fourier-doodles.zip)

Each line of the file labels.txt contains a single integer 0 or 1. Line i (1-based) contains the label of the image {i}.png. Label 1 means that the image depicts a Fourier doodle, label 0 - that it does not.

Output

Output 30 lines, one line per image 21 through 50. Line i (1-based) should contain the classification result for the image {i + 20}.png.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
bool p[364] = {};
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  ios::sync_with_stdio(false);
  for (int id = 21; id <= 50; id++) {
    if (((min(id, 25) + id) % (2 + id % 3)) > 0)
      cout << 1;
    else
      cout << 0;
    cout << endl;
  }
  return 0;
}

```


### Prompt

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

A binary matrix is called good if every even length square sub-matrix has an odd number of ones.

Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.

All the terms above have their usual meanings — refer to the Notes section for their formal definitions.

Input

The first line of input contains two integers n and m (1 ≤ n ≤ m ≤ 10^6 and n⋅ m ≤ 10^6) — the number of rows and columns in a, respectively.

The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.

Output

Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.

Examples

Input

3 3
101
001
110

Output

2

Input

7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011

Output

-1

Note

In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough.

You can verify that there is no way to make the matrix in the second case good.

Some definitions —

  * A binary matrix is one in which every element is either 1 or 0.
  * A sub-matrix is described by 4 parameters — r_1, r_2, c_1, and c_2; here, 1 ≤ r_1 ≤ r_2 ≤ n and 1 ≤ c_1 ≤ c_2 ≤ m.
  * This sub-matrix contains all elements a_{i,j} that satisfy both r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2.
  * A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void fastio(void);
int find_val2(char a, char b) { return (a - '0') + 2 * (b - '0'); }
int find_val3(char a, char b, char c) {
  return (a - '0') + 2 * (b - '0') + 4 * (c - '0');
}
int find_dif(int a, int b) {
  int cnt = 0;
  while (a > 0 || b > 0) {
    if ((a & 1) != (b & 1)) cnt++;
    a /= 2;
    b /= 2;
  }
  return cnt;
}
bool poss(int a, int b, int n) {
  if (n == 2) {
    int c = (a ^ b);
    if (c == 1 || c == 2) return true;
  }
  if (n == 3) {
    int c = (a ^ b);
    if (c == 2 || c == 5) return true;
  }
  return false;
}
void solve() {
  int n, m, la, lb, lc;
  cin >> n >> m;
  vector<string> st(n);
  for (la = 0; la < n; la++) cin >> st[la];
  if (n <= 1) {
    cout << 0 << endl;
    return;
  }
  if (n > 3) {
    cout << -1 << endl;
    return;
  }
  vector<vector<int>> dp((1 << n), vector<int>(m, INT_MAX));
  for (la = 0; la < m; la++) {
    int val = 0;
    if (n == 2) val = find_val2(st[0][la], st[1][la]);
    if (n == 3) val = find_val3(st[0][la], st[1][la], st[2][la]);
    if (la == 0) {
      for (lb = 0; lb < (1 << n); lb++) dp[lb][la] = find_dif(val, lb);
      continue;
    }
    for (lb = 0; lb < (1 << n); lb++) {
      for (lc = 0; lc < (1 << n); lc++) {
        if (poss(lb, lc, n))
          dp[lc][la] = min(dp[lc][la], dp[lb][la - 1] + find_dif(val, lc));
      }
    }
  }
  int ans = INT_MAX;
  for (la = 0; la < (1 << n); la++) ans = min(ans, dp[la][m - 1]);
  cout << ans << endl;
}
int main() {
  fastio();
  solve();
  return 0;
}
void fastio(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.

To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:

* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.

Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?

Constraints

* 1 ≦ |s| ≦ 10 (|s| denotes the length of s)
* s consists of the letters `0`, `1` and `B`.
* The correct answer is not an empty string.

Input

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

s

Output

Print the string displayed in the editor in the end.

Examples

Input

01B0

Output

00

Input

0BB1

Output

1

### Response

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

int main()
{
	string s,an="";
	cin>>s;
	for(auto i: s)
	if(i=='B'){if(an.size())an.pop_back();}

	else an.push_back(i);
	cout<<an<<endl;

}

```


### Prompt

Please create a solution in cpp to the following problem:

For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way:

  * Consider a graph on k nodes, with numbers from b_1 to b_k written on them.
  * For every i from 1 to k: find such j (1 ≤ j ≤ k, j≠ i), for which (b_i ⊕ b_j) is the smallest among all such j, where ⊕ denotes the operation of bitwise XOR (<https://en.wikipedia.org/wiki/Bitwise_operation#XOR>). Next, draw an undirected edge between vertices with numbers b_i and b_j in this graph.
  * We say that the sequence is good if and only if the resulting graph forms a tree (is connected and doesn't have any simple cycles).

It is possible that for some numbers b_i and b_j, you will try to add the edge between them twice. Nevertheless, you will add this edge only once.

You can find an example below (the picture corresponding to the first test case).

Sequence (0, 1, 5, 2, 6) is not good as we cannot reach 1 from 5.

However, sequence (0, 1, 5, 2) is good.

<image>

You are given a sequence (a_1, a_2, ..., a_n) of distinct non-negative integers. You would like to remove some of the elements (possibly none) to make the remaining sequence good. What is the minimum possible number of removals required to achieve this goal?

It can be shown that for any sequence, we can remove some number of elements, leaving at least 2, so that the remaining sequence is good.

Input

The first line contains a single integer n (2 ≤ n ≤ 200,000) — length of the sequence.

The second line contains n distinct non-negative integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the elements of the sequence.

Output

You should output exactly one integer — the minimum possible number of elements to remove in order to make the remaining sequence good.

Examples

Input

5
0 1 5 2 6

Output

1

Input

7
6 9 8 7 3 5 2

Output

2

Note

Note that numbers which you remove don't impact the procedure of telling whether the resulting sequence is good.

It is possible that for some numbers b_i and b_j, you will try to add the edge between them twice. Nevertheless, you will add this edge only once.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int D = 32;
int calc(int left, int right, vector<int> &vec) {
  if (right - left <= 1) {
    return 0;
  }
  int d = D;
  while (d > 0) {
    bool x = (vec[left] & (1LL << d));
    bool y = (vec[right - 1] & (1LL << d));
    if (x != y) {
      break;
    }
    d--;
  }
  int mid = left;
  while (mid < right) {
    if (vec[mid] & (1LL << d)) {
      break;
    }
    mid++;
  }
  return min(calc(left, mid, vec) + right - mid - 1,
             calc(mid, right, vec) + mid - left - 1);
}
void solve() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  cout << calc(0, N, vec) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  for (int i = 0; i < T; i++) {
    solve();
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

A process RAM is a sequence of bytes that are indexed from 1 to n. Polycarpus's program contains such instructions as "memset", that is, the operations of filling memory cells on a segment with some value. The details are: the code only contains m instructions that look like "set13 a_i l_i". Instruction i fills a continuous memory segment of length li, starting from cell number ai, (that it cells with numbers ai, ai + 1, ..., ai + li - 1) with values 13.

In Polycarpus's code, the optimizer's task is to remove the maximum number of instructions from his code in such a way that the remaining instructions set value 13 in all the memory bytes that got this value from the code before the optimization. Also, the value 13 should be set only in the memory bytes that got this value from the code before the optimization. Your task is to implement the optimizer for such program.

Input

The first line contains integers n and m (1 ≤ n ≤ 2·106, 1 ≤ m ≤ 2·105) — the number of bytes (memory cells) and the number of instructions in Polycarpus's code. Then m lines follow, each line contains a pair of integers ai, li (1 ≤ ai ≤ n, 1 ≤ li ≤ n - ai + 1).

Output

Print in the first line the sought maximum number of instructions that can be removed from the code. In the second line print the numbers of the instructions. The instructions are numbered from 1 to m in the order they appeared in the input. If there are multiple solutions, print any of them.

Examples

Input

10 4
3 3
3 1
4 1
9 2

Output

2
2 3

Input

1 1
1 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167177216")
using namespace std;
struct otr {
  int a, b, c;
};
bool cmp(otr &a, otr &b) {
  if (a.a != b.a) return a.a < b.a;
  if (a.b != b.b) return a.b > b.b;
  return a.c < b.c;
}
int main() {
  int n, m;
  scanf("%d%d", &m, &n);
  vector<otr> v(n);
  for (int i = 0; i < int(n); ++i) {
    scanf("%d%d", &v[i].a, &v[i].b);
    v[i].b += v[i].a - 1;
    v[i].c = i;
  }
  sort(v.begin(), v.end(), cmp);
  vector<int> ans;
  int maxr = -1, l = 0, r = 0;
  int pos = 0, last = 0;
  while (l < n) {
    if (v[l].a > maxr) {
      last = l;
      maxr = v[l].b;
    }
    int nmaxr = maxr;
    while (r < n && v[r].a <= maxr + 1) {
      if (v[r].b > nmaxr) {
        nmaxr = v[r].b;
        pos = r;
      }
      r++;
    }
    while (l < r) {
      if (pos != l && last != l) ans.push_back(v[l].c);
      l++;
    }
    maxr = nmaxr;
  }
  cout << ans.size() << endl;
  for (int i = 0; i < int(ans.size()); ++i) cout << ans[i] + 1 << ' ';
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high.

<image>

A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.

Mike is a curious to know for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.

Input

The first line of input contains integer n (1 ≤ n ≤ 2 × 105), the number of bears.

The second line contains n integers separated by space, a1, a2, ..., an (1 ≤ ai ≤ 109), heights of bears.

Output

Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.

Examples

Input

10
1 2 3 4 5 4 3 2 1 6

Output

6 4 4 3 3 2 2 1 1 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vp;
int vals[2000000];
int lefty[2000000];
int righty[2000000];
int taken[2000000];
int ans[2000000];
int main() {
  int i, j, k, n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &vals[i]);
    vp.push_back(make_pair(vals[i], i));
  }
  sort(vp.begin(), vp.end());
  reverse(vp.begin(), vp.end());
  int past = 0;
  for (i = 0; i < n; i++) {
    taken[vp[i].second] = 1;
    int l = vp[i].second, r = vp[i].second;
    if (taken[vp[i].second - 1]) {
      l = lefty[vp[i].second - 1];
    }
    if (taken[vp[i].second + 1]) {
      r = righty[vp[i].second + 1];
    }
    righty[l] = r;
    lefty[r] = l;
    for (j = past + 1; j <= (r - l + 1); j++) {
      ans[j] = vp[i].first;
    }
    past = max(past, (r - l + 1));
  }
  for (i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}

```