### Prompt

Please formulate a Cpp solution to the following problem:

You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building.

Submitted designs will look like a screenshot of a well known game as shown below.

<image>

This is because the center specifies that the building should be constructed by stacking regular units called pieces, each of which consists of four cubic blocks. In addition, the center requires the competitors to submit designs that satisfy the following restrictions.

* All the pieces are aligned. When two pieces touch each other, the faces of the touching blocks must be placed exactly at the same position.
* All the pieces are stable. Since pieces are merely stacked, their centers of masses must be carefully positioned so as not to collapse.
* The pieces are stacked in a tree-like form in order to symbolize boundless potentiality of young artists. In other words, one and only one piece touches the ground, and each of other pieces touches one and only one piece on its bottom faces.
* The building has a flat shape. This is because the construction site is a narrow area located between a straight moat and an expressway where no more than one block can be placed between the moat and the expressway as illustrated below.

<image>

It will take many days to fully check stability of designs as it requires complicated structural calculation. Therefore, you are asked to quickly check obviously unstable designs by focusing on centers of masses. The rules of your quick check are as follows.

Assume the center of mass of a block is located at the center of the block, and all blocks have the same weight. We denote a location of a block by xy-coordinates of its left-bottom corner. The unit length is the edge length of a block.

Among the blocks of the piece that touch another piece or the ground on their bottom faces, let xL be the leftmost x-coordinate of the leftmost block, and let xR be the rightmost x-coordinate of the rightmost block. Let the x-coordinate of its accumulated center of mass of the piece be M, where the accumulated center of mass of a piece P is the center of the mass of the pieces that are directly and indirectly supported by P, in addition to P itself. Then the piece is stable, if and only if xL < M < xR. Otherwise, it is unstable. A design of a building is unstable if any of its pieces is unstable.

Note that the above rules could judge some designs to be unstable even if it would not collapse in reality. For example, the left one of the following designs shall be judged to be unstable.

<image> |  | <image>
---|---|---

Also note that the rules judge boundary cases to be unstable. For example, the top piece in the above right design has its center of mass exactly above the right end of the bottom piece. This shall be judged to be unstable.

Write a program that judges stability of each design based on the above quick check rules.

Input

The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset, which represents a front view of a building, is formatted as follows.

> w h
>  p0(h-1)p1(h-1)...p(w-1)(h-1)
>  ...
>  p01p11...p(w-1)1
>  p00p10...p(w-1)0
>

The integers w and h separated by a space are the numbers of columns and rows of the layout, respectively. You may assume 1 ≤ w ≤ 10 and 1 ≤ h ≤ 60. The next h lines specify the placement of the pieces. The character pxy indicates the status of a block at (x,y), either ``.`', meaning empty, or one digit character between ``1`' and ``9`', inclusive, meaning a block of a piece. (As mentioned earlier, we denote a location of a block by xy-coordinates of its left-bottom corner.)

When two blocks with the same number touch each other by any of their top, bottom, left or right face, those blocks are of the same piece. (Note that there might be two different pieces that are denoted by the same number.) The bottom of a block at (x,0) touches the ground.

You may assume that the pieces in each dataset are stacked in a tree-like form.

Output

For each dataset, output a line containing a word `STABLE` when the design is stable with respect to the above quick check rules. Otherwise, output `UNSTABLE`. The output should be written with uppercase letters, and should not contain any other extra characters.

Sample Input

4 5
..33
..33
2222
..1.
.111
5 7
....1
.1..1
.1..1
11..1
.2222
..111
...1.
3 6
.3.
233
23.
22.
.11
.11
4 3
2222
..11
..11
4 5
.3..
33..
322.
2211
.11.
3 3
222
2.1
111
3 4
11.
11.
.2.
222
3 4
.11
.11
.2.
222
2 7
11
.1
21
22
23
.3
33
2 3
1.
11
.1
0 0

Output for the Sample Input

STABLE
STABLE
STABLE
UNSTABLE
STABLE
STABLE
UNSTABLE
UNSTABLE
UNSTABLE
UNSTABLE

Example

Input

4 5
..33
..33
2222
..1.
.111
5 7
....1
.1..1
.1..1
11..1
.2222
..111
...1.
3 6
.3.
233
23.
22.
.11
.11
4 3
2222
..11
..11
4 5
.3..
33..
322.
2211
.11.
3 3
222
2.1
111
3 4
11.
11.
.2.
222
3 4
.11
.11
.2.
222
2 7
11
.1
21
22
23
.3
33
2 3
1.
11
.1
0 0

Output

STABLE
STABLE
STABLE
UNSTABLE
STABLE
STABLE
UNSTABLE
UNSTABLE
UNSTABLE
UNSTABLE

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

bool used[100][100];
bool v[100][100];
int xl,xr;
int h,w;

P rec(int x,int y,bool f,vector<string> s){
    used[y][x]=true;
    if(f){
        v[y][x]=true;
    }
    int r=2*x+1;
    int t=1;
    for (int i = 0; i < 4; i++) {
        int nx=x+dx[i],ny=y+dy[i];
        if(f){
            if(i==1){
                if(s[ny][nx]!=s[y][x]&&s[ny][nx]!='.'){
                    xl=min(xl,x);
                    xr=max(xr,x+1);
                }
            }
        }
        if(0<=nx&&nx<w&&0<=ny&&ny<h){
            if(s[ny][nx]=='.'||used[ny][nx]) continue;
            if(s[y][x]!=s[ny][nx]){
                if(i==3){
                    P p = rec(nx,ny,false,s);
                    r += p.fs;
                    t += p.sc;
                }
            }
            else{
                P p = rec(nx,ny,f,s);
                r += p.fs;
                t += p.sc;
            }
        }
    }
    return mp(r,t);
}

int main(){
    while(1){
        cin >> w >> h;
        if(!h&&!w) return 0;
        vector<string> s(h);
        memset(v,false,sizeof(v));
        for (int i = 0; i < h; i++) {
            cin >> s[i];
        }
        string k="";
        for (int i = 0; i < w; i++) {
            k.pb('#');
        }
        s.pb(k);
        bool flag=false;
        for (int i = h-1; i >= 0; i--) {
            for (int j = 0; j < w; j++) {
                memset(used,false,sizeof(used));
                if(s[i][j]=='.'||v[i][j]) continue;
                xl=100,xr=0;
                P p = rec(j,i,true,s);
                if(p.fs<=2*xl*p.sc||2*xr*p.sc<=p.fs) flag=true;
            }
        }
        if(flag) puts("UNSTABLE");
        else puts("STABLE");
    }
    return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

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;
const int maxn = 123456;
int f[maxn];
int main(){
  iota(f, f + maxn, 0);
  for(int p : {6, 9}){
  	long long now = p;
   	while(now < maxn){
		for(int i = 0; i < maxn - now; i++) f[i + now] = min(f[i + now], f[i] + 1);
      now *= p;
    }
  }
  int n; cin >> n;
  cout << f[n] << endl;
  return 0;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

BCPC stands for Byteforces Collegiate Programming Contest, and is the most famous competition in Byteforces.

BCPC is a team competition. Each team is composed by a coach and three contestants. Blenda is the coach of the Bit State University(BSU), and she is very strict selecting the members of her team.

<image>

In BSU there are n students numbered from 1 to n. Since all BSU students are infinitely smart, the only important parameters for Blenda are their reading and writing speed. After a careful measuring, Blenda have found that the i-th student have a reading speed equal to ri (words per minute), and a writing speed of wi (symbols per minute). Since BSU students are very smart, the measured speeds are sometimes very big and Blenda have decided to subtract some constant value c from all the values of reading speed and some value d from all the values of writing speed. Therefore she considers ri' = ri - c and wi' = wi - d.

The student i is said to overwhelm the student j if and only if ri'·wj' > rj'·wi'. Blenda doesn’t like fights in teams, so she thinks that a team consisting of three distinct students i, j and k is good if i overwhelms j, j overwhelms k, and k overwhelms i. Yes, the relation of overwhelming is not transitive as it often happens in real life.

Since Blenda is busy preparing a training camp in Codeforces, you are given a task to calculate the number of different good teams in BSU. Two teams are considered to be different if there is at least one student that is present in one team but is not present in the other. In other words, two teams are different if the sets of students that form these teams are different.

Input

In the first line of the input three integers n, c and d (3 ≤ n ≤ 345678, 1 ≤ c, d ≤ 109) are written. They denote the number of students Blenda can use to form teams, the value subtracted from all reading speeds and the value subtracted from all writing speeds respectively.

Each of the next n lines contains two integers ri and wi (0 < ri, wi ≤ 109, |ri - c| + |wi - d| > 0). There are no two students, such that both their reading and writing speeds coincide, i.e. for every i ≠ j condition |ri - rj| + |wi - wj| > 0 holds.

Output

Print the number of different teams in BSU, that are good according to Blenda's definition.

Examples

Input

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

Output

4

Input

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

Output

11

Note

In the first sample the following teams are good: (i = 1, j = 2, k = 3), (i = 2, j = 5, k = 1), (i = 1, j = 4, k = 3), (i = 5, j = 1, k = 4).

Note, that for example the team (i = 3, j = 1, k = 2) is also good, but is considered to be the same as the team (i = 1, j = 2, k = 3).

### Response

```cpp
#include <bits/stdc++.h>
int MOD = int(1e9) + 7;
inline int add(int a, int b) {
  return (a + b >= MOD) ? (a + b - MOD) : (a + b);
}
inline void inc(int &a, int b) { a = add(a, b); }
inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); }
inline void dec(int &a, int b) { a = sub(a, b); }
inline int mul(int a, int b) { return (a * 1ll * b) % MOD; }
using namespace std;
const int N = 345678;
const long double PI = acosl(-1), EPS = 1e-18;
long double ang[2 * N];
long long f(int from, int to) {
  return 1LL * (to - from) * (to - from - 1) / 2;
}
int main() {
  int n, c, d;
  scanf("%d %d %d", &n, &c, &d);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    ang[i] = atan2l(y - d, x - c);
  }
  sort(ang, ang + n);
  for (int i = n; i < 2 * n; i++) ang[i] = ang[i - n] + 2 * PI;
  long long ans = 1LL * n * (n - 1) * (n - 2) / 6;
  int from = 0, to = 0;
  for (int i = 0; i < n; i++) {
    while (ang[from] - ang[i] < PI - EPS) from++;
    while (ang[to + 1] - ang[i] < PI + EPS) to++;
    ans += f(from, to + 1) - f(i, to);
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

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

You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.

Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.

For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.

The game "flood fill" is played on the given line as follows:

  * At the start of the game you pick any starting square (this is not counted as a turn).
  * Then, in each game turn, change the color of the connected component containing the starting square to any other color.

Find the minimum number of turns needed for the entire line to be changed into a single color.

Input

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

The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.

Output

Print a single integer — the minimum number of the turns needed.

Examples

Input

4
5 2 2 1

Output

2

Input

8
4 5 2 2 1 3 5 5

Output

4

Input

1
4

Output

0

Note

In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:

  * [5, 2, 2, 1]
  * [5, 5, 5, 1]
  * [1, 1, 1, 1]

In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.

In the third example, the line already consists of one color only.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  int c = -1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<int> b(0);
  b.push_back(v[0]);
  for (int i = 1; i < n; i++) {
    if (v[i] != v[i - 1]) b.push_back(v[i]);
  }
  int dp[n][n][2];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < 2; k++) {
        if (i == j)
          dp[i][j][k] = 0;
        else
          dp[i][j][k] = 1000000;
      }
    }
  }
  for (int r = 0; r < n; r++) {
    for (int l = r + 1 - 1; l >= 0; l--) {
      for (int k = 0; k < 2; k++) {
        if (k)
          c = v[r];
        else
          c = v[l];
        if (l - 1 >= 0) {
          dp[l - 1][r][0] =
              min(dp[l - 1][r][0], dp[l][r][k] + int(v[l - 1] != c));
        }
        if (r + 1 <= n - 1) {
          dp[l][r + 1][1] =
              min(dp[l][r + 1][1], dp[l][r][k] + int(v[r + 1] != c));
        }
      }
    }
  }
  cout << min(dp[0][n - 1][1], dp[0][n - 1][0]);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: «eye», «pop», «level», «aba», «deed», «racecar», «rotor», «madam».

Nick started to look carefully for all palindromes in the text that they were reading in the class. For each occurrence of each palindrome in the text he wrote a pair — the position of the beginning and the position of the ending of this occurrence in the text. Nick called each occurrence of each palindrome he found in the text subpalindrome. When he found all the subpalindromes, he decided to find out how many different pairs among these subpalindromes cross. Two subpalindromes cross if they cover common positions in the text. No palindrome can cross itself.

Let's look at the actions, performed by Nick, by the example of text «babb». At first he wrote out all subpalindromes:

• «b» — 1..1 • «bab» — 1..3 • «a» — 2..2 • «b» — 3..3 • «bb» — 3..4 • «b» — 4..4

Then Nick counted the amount of different pairs among these subpalindromes that cross. These pairs were six:

1. 1..1 cross with 1..3 2. 1..3 cross with 2..2 3. 1..3 cross with 3..3 4. 1..3 cross with 3..4 5. 3..3 cross with 3..4 6. 3..4 cross with 4..4

Since it's very exhausting to perform all the described actions manually, Nick asked you to help him and write a program that can find out the amount of different subpalindrome pairs that cross. Two subpalindrome pairs are regarded as different if one of the pairs contains a subpalindrome that the other does not.

Input

The first input line contains integer n (1 ≤ n ≤ 2·106) — length of the text. The following line contains n lower-case Latin letters (from a to z).

Output

In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987.

Examples

Input

4
babb

Output

6

Input

2
aa

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[2 * 1000000 + 5];
struct st {
  vector<pair<char, int> > nxt;
  int len, link;
};
st node[2 * 1000000 + 5];
int cnt[2 * 1000000 + 5];
int sz;
int last;
inline void init() {
  for (int i = 1; i <= sz; i++) {
    cnt[i] = 0;
    node[i].nxt.clear();
  }
  sz = last = 2;
  node[1].len = -1;
  node[1].link = 1;
  node[2].len = 0;
  node[2].link = 1;
}
inline int Insert(int pos, char c) {
  int cur = last, curlen = node[cur].len;
  while (true) {
    curlen = node[cur].len;
    if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) break;
    cur = node[cur].link;
  }
  for (pair<char, int> x : node[cur].nxt) {
    if (x.first == c) {
      last = x.second;
      cnt[last] = cnt[node[last].link] + 1;
      return cnt[last];
    }
  }
  sz++;
  last = sz;
  node[sz].len = node[cur].len + 2;
  node[cur].nxt.push_back(make_pair(c, sz));
  if (node[sz].len == 1) {
    node[sz].link = 2;
    cnt[sz] = cnt[node[sz].link] + 1;
    return cnt[sz];
  }
  while (true) {
    cur = node[cur].link;
    curlen = node[cur].len;
    if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) {
      int t;
      for (pair<char, int> x : node[cur].nxt) {
        if (x.first == c) {
          t = x.second;
          break;
        }
      }
      node[sz].link = t;
      break;
    }
  }
  cnt[sz] = cnt[node[sz].link] + 1;
  return cnt[sz];
}
inline long long koto(int i) { return cnt[i]; }
int l[2 * 1000000 + 5];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n / 2; i++) swap(s[i], s[n - i - 1]);
  init();
  long long tot = 0ll;
  for (int i = 0; i < n; i++) {
    l[n - i - 1] = Insert(i, s[i]);
    tot += l[n - i - 1];
    tot %= 51123987;
  }
  long long ans = (tot * (tot - 1ll) / 2ll) % 51123987;
  long long mn = 0ll;
  long long sum = 0ll;
  for (int i = 0; i < n / 2; i++) swap(s[i], s[n - i - 1]);
  init();
  for (int i = 0; i < n; i++) {
    mn += (l[i] * sum) % 51123987;
    mn %= 51123987;
    long long x = 1ll * Insert(i, s[i]);
    sum += x;
  }
  ans = (ans - mn + 51123987) % 51123987;
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.

Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.

Input

The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).

Output

Print n integers forming the permutation. If there are multiple answers, print any of them.

Examples

Input

3 2

Output

1 3 2

Input

3 1

Output

1 2 3

Input

5 2

Output

1 3 2 4 5

Note

By |x| we denote the absolute value of number x.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], l = 1, r, n, p = 0, cur = 1;
void preencher(int d) {
  if (d == 0) return;
  a[p] = cur;
  a[p + 1] = n - cur + 1;
  l++;
  r--;
  p += 2;
  cur++;
  d--;
  while (d) {
    a[p] = cur;
    l++;
    p++;
    d--;
    if (d == 0) return;
    a[p] = n - cur + 1;
    r--;
    p++;
    d--;
    cur++;
  }
}
int main() {
  int k;
  scanf("%d %d", &n, &k);
  r = n;
  preencher(k - 1);
  for (int i = p; i < (int)n; i++) {
    if (((k - 1) & 1) == 1)
      a[i] = r--;
    else
      a[i] = l++;
  }
  for (int i = 0; i < (int)n; i++) {
    printf("%d ", a[i]);
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.

The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

Input

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Output

Print a single integer, denoting the minimum possible height of the tallest tower.

Examples

Input

1 3

Output

9

Input

3 2

Output

8

Input

5 0

Output

10

Note

In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.

In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int n, m;
bool check(int x) {
  int a2 = x / 2, a3 = x / 3, a6 = x / 6;
  a2 -= a6;
  a3 -= a6;
  if (max(n - a2, 0) + max(m - a3, 0) <= a6)
    return true;
  else
    return false;
}
int main() {
  cin >> n >> m;
  int l = 1, r = 1e7;
  int ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}

```


### Prompt

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

Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play t matches of a digit game...

In each of t matches of the digit game, a positive integer is generated. It consists of n digits. The digits of this integer are numerated from 1 to n from the highest-order digit to the lowest-order digit. After this integer is announced, the match starts.

Agents play in turns. Raze starts. In one turn an agent can choose any unmarked digit and mark it. Raze can choose digits on odd positions, but can not choose digits on even positions. Breach can choose digits on even positions, but can not choose digits on odd positions. The match ends, when there is only one unmarked digit left. If the single last digit is odd, then Raze wins, else Breach wins.

It can be proved, that before the end of the match (for every initial integer with n digits) each agent has an ability to make a turn, i.e. there is at least one unmarked digit, that stands on a position of required parity.

For each of t matches find out, which agent wins, if both of them want to win and play optimally.

Input

First line of input contains an integer t (1 ≤ t ≤ 100) — the number of matches.

The first line of each match description contains an integer n (1 ≤ n ≤ 10^3) — the number of digits of the generated number.

The second line of each match description contains an n-digit positive integer without leading zeros.

Output

For each match print 1, if Raze wins, and 2, if Breach wins.

Example

Input

4
1
2
1
3
3
102
4
2069

Output

2
1
1
2

Note

In the first match no one can make a turn, the only digit left is 2, it's even, so Breach wins.

In the second match the only digit left is 3, it's odd, so Raze wins.

In the third match Raze can mark the last digit, after that Breach can only mark 0. 1 will be the last digit left, it's odd, so Raze wins.

In the fourth match no matter how Raze plays, Breach can mark 9, and in the end there will be digit 0. It's even, so Breach wins.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string arr;
    cin >> arr;
    int re = 0, bo = 0, e = 0, o = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (((int)arr[i] - 48) % 2)
        o++;
      else
        e++;
    }
    for (int i = 0; i < n; i += 2) {
      if (((int)arr[i] - 48) % 2 == 0) re++;
    }
    for (int i = 1; i < n; i += 2) {
      if (((int)arr[i] - 48) % 2) bo++;
    }
    if (n % 2 == 0) {
      if (e > re)
        ans = 2;
      else
        ans = 1;
    } else {
      if (o > bo)
        ans = 1;
      else
        ans = 2;
    }
    cout << ans << endl;
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions:

  * There is no vertex that has more than two incident edges painted the same color.
  * For any two vertexes that have incident edges painted the same color (say, c), the path between them consists of the edges of the color c.

Not all tree paintings are equally good for Adam. Let's consider the path from some vertex to the root. Let's call the number of distinct colors on this path the cost of the vertex. The cost of the tree's coloring will be the maximum cost among all the vertexes. Help Adam determine the minimum possible cost of painting the tree.

Initially, Adam's tree consists of a single vertex that has number one and is the root. In one move Adam adds a new vertex to the already existing one, the new vertex gets the number equal to the minimum positive available integer. After each operation you need to calculate the minimum cost of coloring the resulting tree.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of times a new vertex is added. The second line contains n numbers pi (1 ≤ pi ≤ i) — the numbers of the vertexes to which we add another vertex.

Output

Print n integers — the minimum costs of the tree painting after each addition.

Examples

Input

11
1 1 1 3 4 4 7 3 7 6 6

Output

1 1 1 1 1 2 2 2 2 2 3

Note

The figure below shows one of the possible variants to paint a tree from the sample at the last moment. The cost of the vertexes with numbers 11 and 12 equals 3.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
const int MAXN = 1e6 + 7;
int par[MAXN];
int max1[MAXN];
int max2[MAXN];
vector<int> g[MAXN];
int get(int x) {
  if (max1[x] == 0) return 1;
  return max(max1[x], max2[x] + 1);
}
void upd(int v, int x) {
  if (v == -1) return;
  int old = get(v);
  int &m1 = max1[v];
  int &m2 = max2[v];
  if (m1 < x) {
    m2 = m1;
    m1 = x;
  } else if (m2 < x) {
    m2 = x;
  }
  if (old != get(v)) upd(par[v], get(v));
}
int solve() {
  if (!(cin >> n)) return 1;
  n++;
  par[0] = -1;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    par[i] = x - 1;
    upd(par[i], 1);
    cout << max1[0] << " \n"[i + 1 == n];
  }
  return 0;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tests = 1e9;
  for (int i = 1; i <= tests; i++) {
    if (solve()) break;
  }
}

```


### Prompt

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

A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.

<image>

It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.

Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.

Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.

Input

The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.

Output

Print one integer — the number of seconds Vasya has to wait until he gets his lunch.

Examples

Input

1f

Output

1

Input

2d

Output

10

Input

4a

Output

11

Input

5e

Output

18

Note

In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.

In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a;
  char b;
  long long int sum = 0;
  cin >> a;
  cin >> b;
  if (a % 4 == 1 || a % 4 == 3) {
    if (a % 4 == 1)
      sum = sum + 6 * ((a - 1) / 2);
    else
      sum = sum + 6 * ((a - 3) / 2);
    if (a % 4 == 1)
      sum = sum + (a - 1);
    else
      sum += a - 3;
  } else {
    if (a % 4 == 0)
      sum += 6 * ((a - 2) / 2);
    else
      sum += 6 * (a / 2);
    if (a % 4 == 2)
      sum += a - 1;
    else
      sum += a - 3;
  }
  if (b == 'f')
    sum += 1;
  else if (b == 'e')
    sum += 2;
  else if (b == 'd')
    sum += 3;
  else if (b == 'a')
    sum += 4;
  else if (b == 'b')
    sum += 5;
  else
    sum += 6;
  cout << sum;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and ai < aj. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3).

You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2].

After each query you have to determine whether the number of inversions is odd or even.

Input

The first line contains one integer n (1 ≤ n ≤ 1500) — the size of the permutation.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — the elements of the permutation. These integers are pairwise distinct.

The third line contains one integer m (1 ≤ m ≤ 2·105) — the number of queries to process.

Then m lines follow, i-th line containing two integers li, ri (1 ≤ li ≤ ri ≤ n) denoting that i-th query is to reverse a segment [li, ri] of the permutation. All queries are performed one after another.

Output

Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise.

Examples

Input

3
1 2 3
2
1 2
2 3

Output

odd
even

Input

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

Output

odd
odd
odd
even

Note

The first example:

  1. after the first query a = [2, 1, 3], inversion: (2, 1);
  2. after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2).

The second example:

  1. a = [1, 2, 4, 3], inversion: (4, 3);
  2. a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3);
  3. a = [1, 2, 4, 3], inversion: (4, 3);
  4. a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).

### Response

```cpp
#include <bits/stdc++.h>
int n, i, j, a[1505], m, l, r, x;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", a + i);
  for (i = 1; i < n; ++i)
    for (j = i + 1; j <= n; ++j) x ^= a[i] > a[j];
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &l, &r);
    i = r - l + 1;
    x ^= (i * (i - 1) >> 1) & 1;
    puts(x ? "odd" : "even");
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.

Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.

Input

The first line contains three integers n, m, and k (1 ≤ n, m, k ≤ 100) — the number of participants, the number of pens, and the number of notebooks respectively.

Output

Print "Yes" if it possible to reward all the participants. Otherwise, print "No".

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

Examples

Input

5 8 6

Output

Yes

Input

3 9 3

Output

Yes

Input

8 5 20

Output

No

Note

In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.

In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.

In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  if (m < n || k < n) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.

At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the height of the i-th castle is equal to hi. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition hi ≤ hi + 1 holds for all i from 1 to n - 1.

Squidward suggested the following process of sorting castles:

  * Castles are split into blocks — groups of consecutive castles. Therefore the block from i to j will include castles i, i + 1, ..., j. A block may consist of a single castle.
  * The partitioning is chosen in such a way that every castle is a part of exactly one block.
  * Each block is sorted independently from other blocks, that is the sequence hi, hi + 1, ..., hj becomes sorted.
  * The partitioning should satisfy the condition that after each block is sorted, the sequence hi becomes sorted too. This may always be achieved by saying that the whole sequence is a single block.

Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day.

The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.

Output

Print the maximum possible number of blocks in a valid partitioning.

Examples

Input

3
1 2 3

Output

3

Input

4
2 1 3 2

Output

2

Note

In the first sample the partitioning looks like that: [1][2][3].

<image>

In the second sample the partitioning is: [2, 1][3, 2]

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool compa(pair<long long, long long> p, pair<long long, long long> o) {
  if (o.first == p.first) {
    return o.second > p.second;
  }
  return o.first > p.first;
}
void fun() {
  long long r, i, sum = 0, j, k, flag = 0, x = 0, y, z, ans = 0;
  cin >> n;
  long long l[n];
  pair<long long, long long> p[n];
  pair<long long, long long> o;
  for (i = 0; i < n; i++) {
    cin >> l[i];
    o.first = l[i];
    o.second = i;
    p[i] = o;
  }
  sort(p, p + n, compa);
  map<long long, long long> mp;
  for (i = 0; i < n; i++) {
    mp[p[i].second] = i;
  }
  long long max = 0;
  for (i = 0; i < n; i++) {
    if (mp[i] > max) {
      max = mp[i];
    }
    if (i == max) {
      ans++;
    }
  }
  cout << ans << endl;
}
int main() {
  long long t, n, k;
  t = 1;
  for (long long i = 0; i < t; i++) fun();
}

```


### Prompt

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

Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.

A common divisor for two positive numbers is a number which both numbers are divisible by.

But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.

You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.

Input

The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).

Output

Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.

Examples

Input

9 27
3
1 5
10 11
9 11

Output

3
-1
9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n;
  scanf("%d%d%d", &a, &b, &n);
  set<int> div;
  for (int i = 1; i * i <= b; i++) {
    if (b % i == 0) {
      if (a % i == 0) div.insert(i);
      if (a % (b / i) == 0) div.insert(b / i);
    }
  }
  while (n--) {
    int l, r;
    scanf("%d%d", &l, &r);
    set<int>::iterator it = div.upper_bound(r);
    it--;
    if (*it < l) {
      cout << -1 << endl;
      continue;
    }
    cout << *it << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.

Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:

  * If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great.
  * If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).

You are given a multiple-choice questions, can you predict child's choose?

Input

The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.

Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".

Output

Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).

Examples

Input

A.VFleaKing_is_the_author_of_this_problem
B.Picks_is_the_author_of_this_problem
C.Picking_is_the_author_of_this_problem
D.Ftiasch_is_cute

Output

D

Input

A.ab
B.abcde
C.ab
D.abc

Output

C

Input

A.c
B.cc
C.c
D.c

Output

B

Note

In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.

In the second sample, no choice is great, so the child will choose the luckiest choice C.

In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.

### Response

```cpp
#include <bits/stdc++.h>
char s[5][200], ans;
int l[5], a[5], b[5], anss;
int main() {
  for (int i = 1; i <= 4; i++) scanf("%s", s[i]), l[i] = strlen(s[i]) - 2;
  for (int i = 1; i <= 4; i++) {
    int a = 1, b = 1;
    for (int j = 1; j <= 4; j++)
      if (j != i) a &= (l[j] >= l[i] * 2), b &= (l[i] >= l[j] * 2);
    if (a || b) anss++, ans = 'A' + i - 1;
  }
  if (anss != 1) ans = 'C';
  printf("%c\n", ans);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

The Galaxy contains n planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All you need to do is call for them.

Now the space rescuers plan to build the largest in the history of the Galaxy rescue station; however, the rescue station's location is yet to be determined. As some cases are real emergencies, the rescuers want to find such a point in the Galaxy from which it would be possible to get to the remotest planet in the minimum possible time. In other words, the rescuers need such point in the space that the distance between it and the planet remotest from it was minimal (if we compare this point with all other possible points in the space). Unfortunately, the rescuers can't sole this problem.

As the planets are quite remote from each other, they can be considered as points in Euclidean three-dimensional space. The distance between points (xi, yi, zi) and (xj, yj, zj) can be calculated by the formula <image>. The rescue station can be positioned in any point in the space. It can also coincide with some planet.

Galaxy is in danger! Save the space rescuers and find the required point for them.

Input

The first line of the input file contains integer n — the number of planets (1 ≤ N ≤ 100). Each of the following n lines contains information about the planets. The i-th line contains three integers xi, yi, zi — the coordinates of the i-th planet ( - 104 ≤ xi, yi, zi ≤ 104, 1 ≤ i ≤ n). No two planets coincide.

Output

Print on the first line of the output file three space-separated real numbers x0, y0, z0 — the coordinates for the future base. If there are several solutions, you are allowed to print any of them. The answer will be accepted if the distance from this point to the remotest planet will differ from the juries' variant in no more than 10 - 6 in absolute or relative value.

Examples

Input

5
5 0 0
-5 0 0
0 3 4
4 -3 0
2 2 -2

Output

0.000 0.000 0.000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 105;
long long n;
double x[N], y[N], z[N];
double sqr(double x1, double x2) { return (x1 - x2) * (x1 - x2); }
double get(double cX, double cY, double cZ) {
  double r = 0;
  for (long long i = 1; i <= n; i++) {
    double d = sqr(x[i], cX) + sqr(y[i], cY) + sqr(z[i], cZ);
    r = max(r, d);
  }
  return r;
}
double X, Y, Z;
double ternaryZ(double x, double y, double lo, double hi) {
  for (long long i = 1; i <= 100; i++) {
    double z1 = (lo * 2 + hi) / 3;
    double z2 = (lo + hi * 2) / 3;
    double val1 = get(x, y, z1);
    double val2 = get(x, y, z2);
    if (val1 <= val2)
      hi = z2;
    else
      lo = z1;
  }
  Z = lo;
  return get(x, y, lo);
}
double ternaryY(double x, double lo, double hi) {
  for (long long i = 1; i <= 70; i++) {
    double y1 = (lo * 2 + hi) / 3;
    double y2 = (lo + hi * 2) / 3;
    double val1 = ternaryZ(x, y1, -1e4, 1e4);
    double val2 = ternaryZ(x, y2, -1e4, 1e4);
    if (val1 <= val2)
      hi = y2;
    else
      lo = y1;
  }
  Y = lo;
  return ternaryZ(x, lo, -1e4, 1e4);
}
double ternaryX(double lo, double hi) {
  for (long long i = 1; i <= 60; i++) {
    double x1 = (lo * 2 + hi) / 3;
    double x2 = (lo + hi * 2) / 3;
    double val1 = ternaryY(x1, -1e4, 1e4);
    double val2 = ternaryY(x2, -1e4, 1e4);
    if (val1 <= val2)
      hi = x2;
    else
      lo = x1;
  }
  X = lo;
  return lo;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];
  ternaryX(-1e4, 1e4);
  cout << fixed << setprecision(6) << X << " " << Y << " " << Z;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

There are n students studying in the 6th grade, in group "B" of a berland secondary school. Every one of them has exactly one friend whom he calls when he has some news. Let us denote the friend of the person number i by g(i). Note that the friendships are not mutual, i.e. g(g(i)) is not necessarily equal to i.

On day i the person numbered as ai learns the news with the rating of bi (bi ≥ 1). He phones the friend immediately and tells it. While he is doing it, the news becomes old and its rating falls a little and becomes equal to bi - 1. The friend does the same thing — he also calls his friend and also tells the news. The friend of the friend gets the news already rated as bi - 2. It all continues until the rating of the news reaches zero as nobody wants to tell the news with zero rating.

More formally, everybody acts like this: if a person x learns the news with a non-zero rating y, he calls his friend g(i) and his friend learns the news with the rating of y - 1 and, if it is possible, continues the process.

Let us note that during a day one and the same person may call his friend and tell him one and the same news with different ratings. Thus, the news with the rating of bi will lead to as much as bi calls.

Your task is to count the values of resi — how many students learned their first news on day i.

The values of bi are known initially, whereas ai is determined from the following formula:

<image> where mod stands for the operation of taking the excess from the cleavage, res0 is considered equal to zero and vi — some given integers.

Input

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 105) — the number of students and the number of days. The second line contains n space-separated integers g(i) (1 ≤ g(i) ≤ n, g(i) ≠ i) — the number of a friend of the i-th student. The third line contains m space-separated integers vi (1 ≤ vi ≤ 107). The fourth line contains m space-separated integers bi (1 ≤ bi ≤ 107).

Output

Print m lines containing one number each. The i-th line should contain resi — for what number of students the first news they've learned over the m days in question, was the news number i. The number of the news is the number of the day on which it can be learned. The days are numbered starting from one in the order in which they are given in the input file. Don't output res0.

Examples

Input

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

Output

1
1
1
0

Input

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

Output

1
1
1
2
1
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int g[100001], v[100001], b[100001], bl[100001];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &g[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &v[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    int ans = 0;
    for (int j = (v[i] + cnt - 1) % n + 1; bl[j] < b[i]; j = g[j]) {
      if (bl[j] == 0) ans++;
      bl[j] = b[i];
      b[i]--;
    }
    cnt = ans;
    printf("%d\n", ans);
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Let's say you are standing on the XY-plane at point (0, 0) and you want to reach point (n, n).

You can move only in two directions:

  * to the right, i. e. horizontally and in the direction that increase your x coordinate,
  * or up, i. e. vertically and in the direction that increase your y coordinate.

In other words, your path will have the following structure:

  * initially, you choose to go to the right or up;
  * then you go some positive integer distance in the chosen direction (distances can be chosen independently);
  * after that you change your direction (from right to up, or from up to right) and repeat the process.

You don't like to change your direction too much, so you will make no more than n - 1 direction changes.

As a result, your path will be a polygonal chain from (0, 0) to (n, n), consisting of at most n line segments where each segment has positive integer length and vertical and horizontal segments alternate.

Not all paths are equal. You have n integers c_1, c_2, ..., c_n where c_i is the cost of the i-th segment.

Using these costs we can define the cost of the path as the sum of lengths of the segments of this path multiplied by their cost, i. e. if the path consists of k segments (k ≤ n), then the cost of the path is equal to ∑_{i=1}^{k}{c_i ⋅ length_i} (segments are numbered from 1 to k in the order they are in the path).

Find the path of the minimum cost and print its cost.

Input

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

The first line of each test case contains the single integer n (2 ≤ n ≤ 10^5).

The second line of each test case contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^9) — the costs of each segment.

It's guaranteed that the total sum of n doesn't exceed 10^5.

Output

For each test case, print the minimum possible cost of the path from (0, 0) to (n, n) consisting of at most n alternating segments.

Example

Input

3
2
13 88
3
2 3 1
5
4 3 2 1 4

Output

202
13
19

Note

In the first test case, to reach (2, 2) you need to make at least one turn, so your path will consist of exactly 2 segments: one horizontal of length 2 and one vertical of length 2. The cost of the path will be equal to 2 ⋅ c_1 + 2 ⋅ c_2 = 26 + 176 = 202.

In the second test case, one of the optimal paths consists of 3 segments: the first segment of length 1, the second segment of length 3 and the third segment of length 2.

The cost of the path is 1 ⋅ 2 + 3 ⋅ 3 + 2 ⋅ 1 = 13.

In the third test case, one of the optimal paths consists of 4 segments: the first segment of length 1, the second one — 1, the third one — 4, the fourth one — 4. The cost of the path is 1 ⋅ 4 + 1 ⋅ 3 + 4 ⋅ 2 + 4 ⋅ 1 = 19.

### Response

```cpp
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) (void)0
#define debug_if(...) (void)0
#endif

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a, b;
		for (int i = 0; i < n; ++i) {
			int x;
			cin >> x;
			if (i & 1) {
				a.push_back(x);
			} else {
				b.push_back(x);
			}
		}
		auto calc = [&](const vector<int>& c) {
			int m = c.size();
			vector<long long> res(m + 1);
			long long sum = 0;
			int minv = INT_MAX;
			for (int i = 0; i < m; ++i) {
				minv = min(minv, c[i]);
				sum += c[i];
				res[i + 1] = (long long)(n - i) * minv + sum - minv;
			}
			return res;
		};
		auto f = calc(a);
		auto g = calc(b);
		debug(f);
		debug(g);
		long long ans = LONG_LONG_MAX;
		for (int i = 1; i < min(f.size(), g.size()); ++i) {
			ans = min(ans, f[i] + g[i]);
			if (i + 1 < g.size()) {
				ans = min(ans, g[i + 1] + f[i]);
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
```


### Prompt

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

Misha didn't do his math homework for today's lesson once again. As a punishment, his teacher Dr. Andrew decided to give him a hard, but very useless task.

Dr. Andrew has written two strings s and t of lowercase English letters at the blackboard. He reminded Misha that prefix of a string is a string formed by removing several (possibly none) of its last characters, and a concatenation of two strings is a string formed by appending the second string to the right of the first string.

The teacher asked Misha to write down on the blackboard all strings that are the concatenations of some non-empty prefix of s and some non-empty prefix of t. When Misha did it, Dr. Andrew asked him how many distinct strings are there. Misha spent almost the entire lesson doing that and completed the task.

Now he asks you to write a program that would do this task automatically.

Input

The first line contains the string s consisting of lowercase English letters. The second line contains the string t consisting of lowercase English letters.

The lengths of both string do not exceed 105.

Output

Output a single integer — the number of distinct strings that are concatenations of some non-empty prefix of s with some non-empty prefix of t.

Examples

Input

aba
aa

Output

5

Input

aaaaa
aaaa

Output

8

Note

In the first example, the string s has three non-empty prefixes: {a, ab, aba}. The string t has two non-empty prefixes: {a, aa}. In total, Misha has written five distinct strings: {aa, aaa, aba, abaa, abaaa}. The string abaa has been written twice.

In the second example, Misha has written eight distinct strings: {aa, aaa, aaaa, aaaaa, aaaaaa, aaaaaaa, aaaaaaaa, aaaaaaaaa}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string& s) {
  int l = 0, r = 0, n = s.size();
  vector<int> z(s.size(), 0);
  for (int i = 1, ThxDem = n; i < ThxDem; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
vector<int> kmppre(string& t) {
  vector<int> r(t.size() + 1);
  r[0] = -1;
  int j = -1;
  for (int i = 0, ThxDem = t.size(); i < ThxDem; ++i) {
    while (j >= 0 && t[i] != t[j]) j = r[j];
    r[i + 1] = ++j;
  }
  return r;
}
string s, t, w;
int c[100005];
int main() {
  cin >> s >> t;
  w = t + '#' + s;
  auto z = z_function(w);
  for (int i = 1, ThxDem = ((int)(s).size()); i < ThxDem; ++i)
    c[z[((int)(t).size()) + 1 + i]]++;
  for (int i = 100003; i >= 0; --i) c[i] += c[i + 1];
  auto b = kmppre(t);
  long long r = 1LL * ((int)(s).size()) * ((int)(t).size());
  for (int i = 2, ThxDem = ((int)(t).size()) + 1; i < ThxDem; ++i)
    if (b[i]) r -= c[i - b[i]];
  cout << r << endl;
  return 0;
}

```


### Prompt

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

You are given three integers A, B and C.

Determine if there exists an equilateral triangle whose sides have lengths A, B and C.

Constraints

* All values in input are integers.
* 1 \leq A,B,C \leq 100

Input

Input is given from Standard Input in the following format:

A B C

Output

If there exists an equilateral triangle whose sides have lengths A, B and C, print `Yes`; otherwise, print `No`.

Examples

Input

2 2 2

Output

Yes

Input

3 4 5

Output

No

### Response

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  string s = (a==b && b==c) ? "Yes" : "No";
  cout << s;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.

You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.

For examples, each of these pictures contain crosses:

<image>

The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).

Following images don't contain crosses:

<image>

You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.

What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?

You are also asked to answer multiple independent queries.

Input

The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.

The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.

Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.

It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.

Output

Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.

Example

Input

9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**

Output

0
0
0
0
0
4
1
1
2

Note

The example contains all the pictures from above in the same order.

The first 5 pictures already contain a cross, thus you don't have to paint anything.

You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.

You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).

You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.

There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || '9' < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f * x;
}
string S;
int hang[50000 + 5], lie[50000 + 5];
vector<string> G;
int main() {
  int T = read();
  while (T--) {
    int n = read(), m = read();
    for (int i = 0; i < n; i++) {
      cin >> S;
      for (int j = 0; j < m; j++)
        hang[i] += (S[j] == '.'), lie[j] += (S[j] == '.');
      G.push_back(S);
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (G[i][j] == '.')
          ans = min(ans, hang[i] + lie[j] - 1);
        else
          ans = min(ans, hang[i] + lie[j]);
      }
    printf("%d\n", ans);
    for (int i = 0; i < n; i++) hang[i] = 0;
    for (int i = 0; i < m; i++) lie[i] = 0;
    G.clear();
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.

Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.

Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.

Input

In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now.

The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now).

The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week).

Output

Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.

Examples

Input

3 1
5 4 6
3 1 5

Output

10

Input

5 3
3 4 7 10 3
4 5 5 12 5

Output

25

Note

In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.

In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int total_items, min_items, ans = 0;
  cin >> total_items >> min_items;
  int starting[total_items];
  int ending[total_items];
  for (int i = 0; i < total_items; i++) {
    cin >> starting[i];
  }
  for (int i = 0; i < total_items; i++) {
    cin >> ending[i];
  }
  int total_negative = 0;
  pair<int, int> differences[total_items];
  for (int i = 0; i < total_items; i++) {
    if (starting[i] - ending[i] < 0) total_negative++;
    differences[i] = make_pair(starting[i] - ending[i], i);
  }
  sort(differences, differences + total_items);
  int items_to_buy_week_1 = max(min_items, total_negative);
  for (int i = 0; i < items_to_buy_week_1; i++) {
    ans += starting[differences[i].second];
  }
  for (int i = items_to_buy_week_1; i < total_items; i++) {
    ans += ending[differences[i].second];
  }
  cout << ans << "\n";
}

```


### Prompt

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

We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i.

In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y).

We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.

Constraints

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

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the minimum total weight of the edges in such a cycle.

Examples

Input

3
1 5
4 2
6 3

Output

7

Input

4
1 5
2 6
3 7
4 8

Output

10

Input

6
19 92
64 64
78 48
57 33
73 6
95 73

Output

227

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a[N],b[N],p[N],q[N],i,mn;
pair<int,int*>c[N*2];
long long s[N*2],ans=1ll<<60,t,sa;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d%d",a+i,b+i),c[i*2-1]=make_pair(a[i],p+i),c[i*2]=make_pair(b[i],q+i),sa+=a[i];
	sort(c+1,c+n*2+1);for(i=1;i<=n*2;++i)*c[i].second=i,s[i]=s[i-1]+c[i].first;
	ans=min(ans,min(sa,s[n*2]-sa));
	for(i=1;i<=n;++i){
		int x=p[i],y=q[i];if(x>y)swap(x,y);
		if(y<=n)ans=min(ans,s[n]);else if(x<=n-1)ans=min(ans,s[n-1]+c[y].first);
			else ans=min(ans,s[n-2]+a[i]+b[i]);
	}
	printf("%lld\n",ans);
}

```


### Prompt

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

Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".

The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.

Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.

  1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
  2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
  3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.

If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.

Please determine the total cost for each of the m customers.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 10^5), representing the number of different kinds of food and the number of customers, respectively.

The second line contains n positive integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.

The third line contains n positive integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^6), where c_i denotes the cost of one dish of the i-th kind.

The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 ≤ t_j ≤ n, 1 ≤ d_j ≤ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.

Output

Print m lines. In the j-th line print the cost for the j-th customer.

Examples

Input

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

Output

22
24
14
10
39

Input

6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66

Output

36
396
3996
39996
399996
0

Input

6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6

Output

36
11058
99996
4333326
0
0

Note

In the first sample, 5 customers will be served as follows.

  1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 ⋅ 3 + 1 ⋅ 2 + 1 ⋅ 2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
  2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 ⋅ 6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
  3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 ⋅ 2 + 3 ⋅ 2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
  4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 ⋅ 3 + 2 ⋅ 2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
  5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 ⋅ 3 + 3 ⋅ 6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.

In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 ⋅ 6 = 396.

In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 ⋅ 6 + 666 ⋅ 6 + 6666 ⋅ 1 = 11058.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 + 100000;
int n, m, rem[MAXN];
long long c[MAXN];
bool ok[MAXN];
set<pair<int, int>> s;
long long solve(int k, int num) {
  if (num >= rem[k]) {
    long long cost = 0LL;
    if (ok[k]) {
      cost = 1LL * rem[k] * c[k];
      num -= rem[k];
      rem[k] = 0;
      ok[k] = false;
      assert(s.find({c[k], k}) != s.end());
      s.erase(s.find({c[k], k}));
    }
    if (num > 0) return cost + solve(s.begin()->second, num);
    return cost;
  } else {
    long long cost = 1LL * num * c[k];
    rem[k] -= num;
    return cost;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  long long totrem = 0LL;
  for (int i = (int)0; i < (int)n; ++i) cin >> rem[i], totrem += rem[i];
  for (int i = (int)0; i < (int)n; ++i) cin >> c[i];
  for (int i = (int)0; i < (int)n; ++i) {
    s.insert({c[i], i});
    ok[i] = true;
  }
  bool can = true;
  while (m--) {
    int kf, num;
    cin >> kf >> num;
    if (num > totrem || !can) {
      cout << 0 << '\n';
      can = false;
    } else {
      cout << solve(kf - 1, num) << '\n';
      totrem -= num;
    }
  }
  return 0;
}

```


### Prompt

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

There are n players sitting at the card table. Each player has a favorite number. The favorite number of the j-th player is f_j.

There are k ⋅ n cards on the table. Each card contains a single integer: the i-th card contains number c_i. Also, you are given a sequence h_1, h_2, ..., h_k. Its meaning will be explained below.

The players have to distribute all the cards in such a way that each of them will hold exactly k cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals h_t if the player holds t cards containing his favorite number. If a player gets no cards with his favorite number (i.e., t=0), his joy level is 0.

Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence h_1, ..., h_k is the same for all the players.

Input

The first line of input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ 10) — the number of players and the number of cards each player will get.

The second line contains k ⋅ n integers c_1, c_2, ..., c_{k ⋅ n} (1 ≤ c_i ≤ 10^5) — the numbers written on the cards.

The third line contains n integers f_1, f_2, ..., f_n (1 ≤ f_j ≤ 10^5) — the favorite numbers of the players.

The fourth line contains k integers h_1, h_2, ..., h_k (1 ≤ h_t ≤ 10^5), where h_t is the joy level of a player if he gets exactly t cards with his favorite number written on them. It is guaranteed that the condition h_{t - 1} < h_t holds for each t ∈ [2..k].

Output

Print one integer — the maximum possible total joy levels of the players among all possible card distributions.

Examples

Input

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

Output

21

Input

3 3
9 9 9 9 9 9 9 9 9
1 2 3
1 2 3

Output

0

Note

In the first example, one possible optimal card distribution is the following:

  * Player 1 gets cards with numbers [1, 3, 8];
  * Player 2 gets cards with numbers [2, 2, 8];
  * Player 3 gets cards with numbers [2, 2, 8];
  * Player 4 gets cards with numbers [5, 5, 5].

Thus, the answer is 2 + 6 + 6 + 7 = 21.

In the second example, no player can get a card with his favorite number. Thus, the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int freqC[100001];
long long int freqF[100001];
long long int h[11];
long long int DP[5000][501];
int main() {
  long long int i, j, k, l, m, n, p, q, x, y, z, a, b, c, d, e, f, r;
  scanf("%lld", &n);
  scanf("%lld", &k);
  for (i = 0; i < k * n; i++) {
    scanf("%lld", &c);
    freqC[c]++;
  }
  for (i = 0; i < n; i++) {
    scanf("%lld", &f);
    freqF[f]++;
  }
  for (i = 1; i <= k; i++) {
    scanf("%lld", &h[i]);
  }
  for (j = 1; j <= n; j++) {
    for (i = 1; i < k * n; i++) {
      if (i >= j * k) {
        DP[i][j] = h[k] * j;
      } else {
        for (p = 0; p <= min(k, i); p++) {
          DP[i][j] = max(DP[i][j], h[p] + DP[i - p][j - 1]);
        }
      }
    }
  }
  a = 0;
  for (i = 0; i <= 100000; i++) {
    if (freqC[i] >= freqF[i] * k) {
      a += h[k] * freqF[i];
    } else {
      a += DP[freqC[i]][freqF[i]];
    }
  }
  printf("%lld\n", a);
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.

Below there was also written that a string is called beautiful if for each i (1 ≤ i ≤ |s|) there are no more ')' characters than '(' characters among the first i characters of s and also the total number of '(' characters is equal to the total number of ')' characters.

Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.

Input

The first line of the input contains a string s (1 ≤ |s| ≤ 105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that s contains at least one '#' character.

Output

If there is no way of replacing '#' characters which leads to a beautiful string print  - 1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.

If there are several possible answers, you may output any of them.

Examples

Input

(((#)((#)

Output

1
2

Input

()((#((#(#()

Output

2
2
1

Input

#

Output

-1

Input

(#)

Output

-1

Note

|s| denotes the length of the string s.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[1000010];
int brr[1000010];
stack<int> st;
int main() {
  int prev;
  int cnt = 0;
  string s;
  cin >> s;
  int lst = -1;
  int l = s.length();
  bool b = true;
  for (int i = 0; i < l; i++) {
    if (s[i] == '(') {
      st.push(i);
      cnt++;
    }
    if (s[i] == ')') {
      cnt--;
      if (cnt < 0) {
        b = false;
        break;
      } else
        st.pop();
    }
    if (s[i] == '#') {
      cnt--;
      if (cnt < 0) {
        b = false;
        break;
      } else {
        st.pop();
        arr[i] = 1;
        brr[i] = 1;
      }
      lst = max(lst, i);
    }
  }
  while (!st.empty() and b) {
    int tp = st.top();
    if (tp > lst) {
      b = false;
      break;
    } else {
      cnt--;
      st.pop();
      brr[lst]++;
    }
  }
  if (!b || (cnt != 0)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < l; i++) {
    if (arr[i] == 1) {
      cout << brr[i] << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Professor Matsuzaki is a scientist studying the truth of the universe. Life, the universe, all the answers are said to be 42, but Professor Matsuzaki thinks that this alone is not enough to elucidate the truth of the universe. Professor Matsuzaki believes that the truth of the universe is represented by a function consisting of two parameters, and 42 is just one of them.

The function M (N, P) defined by Professor Matsuzaki selects two prime numbers larger than N (the same number can be two) and sums them, in order from the smallest number. Represents the number that appears in the Pth position when arranged. Here, there are numbers that can be represented by two or more sums, but such numbers are arranged in the same number as the number of combinations of sums.

As an example, consider the case of N = 0. In this case, two are selected from all the prime numbers and summed. Considering the smallest number among such sums, it is permissible to select the same number twice, which shows that 2 + 2 = 4. That is, M (0, 1) = 4. The next smallest number is 2 + 3 = 5, so M (0, 2) = 5. Considering in the same way, it can be seen that the sums are arranged as 4, 5, 6, 7, 8, 9, 10, 10, 12, 13, 14, 14, 16, .... That is, for example, M (0, 9) = 12.

Considering the case of N = 10 in the same way, in this case, two prime numbers greater than 10 {11, 13, 17, 19, ...} are selected, and the sums obtained are arranged in ascending order. And 22, 24, 26, 28, 30, 30, 32, ...

Your job is to write a program that calculates M (N, P) given N and P.

Input

The input consists of multiple datasets. The dataset is one line, given two integers N (0 ≤ N ≤ 100,000) and P (1 ≤ P ≤ 100) separated by a single space.

The end of the input is indicated by a single line containing two blank-separated -1s.

Output

For each dataset, output the value of M (N, P) on one line. The output must not contain extra blanks or line breaks.

Sample Input

0 55
0 1
0 2
0 3
10 1
10 2
10 3
10 4
10 5
10 6
11 1
11 2
11 3
100000 100
-1 -1

Output for the Sample Input

42
Four
Five
6
twenty two
twenty four
26
28
30
30
26
30
32
200274

Example

Input

0 55
0 1
0 2
0 3
10 1
10 2
10 3
10 4
10 5
10 6
11 1
11 2
11 3
100000 100
-1 -1

Output

42
4
5
6
22
24
26
28
30
30
26
30
32
200274

### Response

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

const int N=200000;

int main(void){
	vector<bool> isprime(N+1);
	for(int i=0;i<isprime.size();i++) isprime[i]=true;
	int upto = (int)sqrt(isprime.size());
	isprime[0]=isprime[1]=false;
	for(int i=2;i<=upto;++i){
		if(isprime[i]){//消されてなければその倍数を消す
			for(int j=2;i*j<isprime.size();++j) isprime[i*j] = false;
		}
	}

	int n,p;
	while(cin>>n>>p,!(n==-1&&p==-1)){
    vector<int> tmp,ans;
    for(int i=n+1,count=0;count<100;++i){
      if(isprime[i]){
     	 tmp.push_back(i);
     	 ++count;
      }
    }
    for(int i=0;i<100;++i){
      for(int j=i;j<100;++j){
        ans.push_back(tmp[i]+tmp[j]);
      }
    }
    sort(ans.begin(),ans.end());
		cout<<ans[p-1]<<endl;
	}
  return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element and the digit of the sum at that position are the same. If that holds for every position, then the multiset is balanced. Otherwise it's unbalanced.

For example, multiset \{20, 300, 10001\} is balanced and multiset \{20, 310, 10001\} is unbalanced:

<image>

The red digits mark the elements and the positions for which these elements have the same digit as the sum. The sum of the first multiset is 10321, every position has the digit required. The sum of the second multiset is 10331 and the second-to-last digit doesn't appear in any number, thus making the multiset unbalanced.

You are given an array a_1, a_2, ..., a_n, consisting of n integers.

You are asked to perform some queries on it. The queries can be of two types:

  * 1~i~x — replace a_i with the value x;
  * 2~l~r — find the unbalanced subset of the multiset of the numbers a_l, a_{l + 1}, ..., a_r with the minimum sum, or report that no unbalanced subset exists.

Note that the empty multiset is balanced.

For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of elements in the array and the number of queries, respectively.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i < 10^9).

Each of the following m lines contains a query of one of two types:

  * 1~i~x (1 ≤ i ≤ n, 1 ≤ x < 10^9) — replace a_i with the value x;
  * 2~l~r (1 ≤ l ≤ r ≤ n) — find the unbalanced subset of the multiset of the numbers a_l, a_{l + 1}, ..., a_r with the lowest sum, or report that no unbalanced subset exists.

It is guaranteed that there is at least one query of the second type.

Output

For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.

Example

Input

4 5
300 10001 20 20
2 1 3
1 1 310
2 1 3
2 3 3
2 3 4

Output

-1
330
-1
40

Note

All the subsets of multiset \{20, 300, 10001\} are balanced, thus the answer is -1.

The possible unbalanced subsets in the third query are \{20, 310\} and \{20, 310, 10001\}. The lowest sum one is \{20, 310\}. Note that you are asked to choose a subset, not a subsegment, thus the chosen elements might not be adjancent in the array.

The fourth query includes only the empty subset and subset \{20\}. Both of them are balanced.

The last query includes the empty subset and the subsets \{20\}, \{20\} and \{20, 20\}. Only \{20, 20\} is unbalanced, its sum is 40. Note that you are asked to choose a multiset, thus it might include equal elements.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T>
using matrix = vector<vector<T>>;
constexpr int INF = (int)2e9 + 7;
constexpr int MAXN = (int)2e5 + 1;
constexpr int MOD = (int)2e9 + 7;
constexpr double EPS = 1e-9;
struct st_t_ {
  pii a[10];
};
using st_t = st_t_;
using st_val_t = int;
st_val_t a[MAXN];
st_t st[MAXN * 4];
void st_put(int v, st_val_t val) {
  int t = val;
  for (int i = 0; i < 10; ++i) {
    st[v].a[i] = {INF, INF};
    if (t % 10 != 0) st[v].a[i].first = val;
    t /= 10;
  }
}
void st_push(int v) {}
st_t st_combine(st_t a, st_t b) {
  st_t res;
  for (int i = 0; i < 10; ++i) {
    int t[] = {a.a[i].first, a.a[i].second, b.a[i].first, b.a[i].second};
    sort(t, t + 4);
    res.a[i] = {t[0], t[1]};
  }
  return res;
}
void st_build(int v, int tl, int tr) {
  if (tl == tr) {
    st_put(v, a[tl]);
  } else {
    int tm = (tl + tr) / 2;
    st_build(2 * v, tl, tm);
    st_build(2 * v + 1, tm + 1, tr);
    st[v] = st_combine(st[2 * v], st[2 * v + 1]);
  }
}
void st_update(int v, int tl, int tr, int x, st_val_t val) {
  if (tl == tr) {
    st_put(v, val);
  } else {
    st_push(v);
    int tm = (tl + tr) / 2;
    if (x <= tm)
      st_update(2 * v, tl, tm, x, val);
    else
      st_update(2 * v + 1, tm + 1, tr, x, val);
    st[v] = st_combine(st[2 * v], st[2 * v + 1]);
  }
}
st_t st_query(int v, int tl, int tr, int l, int r) {
  if (l <= tl && tr <= r) return st[v];
  st_push(v);
  int tm = (tl + tr) / 2;
  if (r <= tm) return st_query(v * 2, tl, tm, l, r);
  if (l > tm) return st_query(v * 2 + 1, tm + 1, tr, l, r);
  return st_combine(st_query(v * 2, tl, tm, l, tm),
                    st_query(v * 2 + 1, tm + 1, tr, tm + 1, r));
}
class EZaprosiSummi {
 public:
  void solve(std::istream &in, std::ostream &out) {
    int n, m;
    in >> n >> m;
    for (int i = 1; i <= n; ++i) {
      in >> a[i];
    }
    st_build(1, 1, n);
    for (int i = 0; i < m; ++i) {
      int t, l, r;
      in >> t >> l >> r;
      if (t == 1) {
        st_update(1, 1, n, l, r);
      } else {
        auto t = st_query(1, 1, n, l, r);
        int res = INF;
        for (int j = 0; j < 10; ++j) {
          if (t.a[j].first < INF && t.a[j].second < INF)
            res = min(res, t.a[j].first + t.a[j].second);
        }
        out << (res == INF ? -1 : res) << endl;
      }
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(9);
  EZaprosiSummi solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Tattah's youngest brother, Tuftuf, is new to programming.

Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.

Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.

Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.

Your task is to determine Tuftuf's destiny.

Input

The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.

Output

Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.

Examples

Input

3
64 16 32

Output

NO

Input

4
4 2 1 3

Output

YES

Note

In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 0, x = 0;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  sort(a.begin(), a.end());
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i] < a[i + 1] && 2ll * a[i] > a[i + 1]) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
}

```


### Prompt

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

There are many caves deep in mountains found in the countryside. In legend, each cave has a treasure hidden within the farthest room from the cave's entrance. The Shogun has ordered his Samurais to explore these caves with Karakuri dolls (robots) and to find all treasures. These robots move in the caves and log relative distances and directions between rooms.

Each room in a cave is mapped to a point on an integer grid (x, y >= 0). For each cave, the robot always starts from its entrance, runs along the grid and returns to the entrance (which also serves as the exit). The treasure in each cave is hidden in the farthest room from the entrance, using Euclid distance for measurement, i.e. the distance of the room at point (x, y) from the entrance (0, 0) is defined as the square root of (x*x+y*y). If more than one room has the same farthest distance from the entrance, the treasure is hidden in the room having the greatest value of x. While the robot explores a cave, it records how it has moved. Each time it takes a new direction at a room, it notes the difference (dx, dy) from the last time it changed its direction. For example, suppose the robot is currently in the room at point (2, 4). If it moves to room (6, 4), the robot records (4, 0), i.e. dx=6-2 and dy=4-4. The first data is defined as the difference from the entrance. The following figure shows rooms in the first cave of the Sample Input. In the figure, the farthest room is the square root of 61 distant from the entrance.
<image>

Based on the records that the robots bring back, your job is to determine the rooms where treasures are hidden.

Input

In the first line of the input, an integer N showing the number of caves in the input is given. Integers dxi and dyi are i-th data showing the differences between rooms. Note that since the robot moves along the grid, either dxi or dyi is zero. An integer pair dxi = dyi = 0 signals the end of one cave's data which means the robot finished the exploration for the cave and returned back to the entrance. The coordinates are limited to (0,0)-(1000,1000).

Output

Print the position (x, y) of the treasure room on a line for each cave.

Example

Input

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

Output

6 5
1 0
2 1

### Response

```cpp
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int calcDist(int x,int y){
	return x*x + y*y;
}

void func(){

	int ans_x = 0,ans_y = 0,tmp_x=0,tmp_y=0,dx,dy,maximum = 0,maximum_x,tmp_dist;

	while(true){
		scanf("%d %d",&dx,&dy);
		if(dx == 0 && dy == 0)break;

		tmp_x += dx;
		tmp_y += dy;

		tmp_dist = calcDist(tmp_x,tmp_y);
		if(tmp_dist > maximum){
			maximum = tmp_dist;
			maximum_x = tmp_x;
			ans_x = tmp_x;
			ans_y = tmp_y;

		}else if(tmp_dist == maximum && maximum_x < tmp_x){
			maximum_x = tmp_x;
			ans_x = tmp_x;
			ans_y = tmp_y;
		}
	}

	printf("%d %d\n",ans_x,ans_y);
}

int main(){

	int N;
	scanf("%d",&N);

	for(int i = 0; i < N; i++)func();

	return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Filled with optimism, Hyunuk will host a conference about how great this new year will be!

The conference will have n lectures. Hyunuk has two candidate venues a and b. For each of the n lectures, the speaker specified two time intervals [sa_i, ea_i] (sa_i ≤ ea_i) and [sb_i, eb_i] (sb_i ≤ eb_i). If the conference is situated in venue a, the lecture will be held from sa_i to ea_i, and if the conference is situated in venue b, the lecture will be held from sb_i to eb_i. Hyunuk will choose one of these venues and all lectures will be held at that venue.

Two lectures are said to overlap if they share any point in time in common. Formally, a lecture held in interval [x, y] overlaps with a lecture held in interval [u, v] if and only if max(x, u) ≤ min(y, v).

We say that a participant can attend a subset s of the lectures if the lectures in s do not pairwise overlap (i.e. no two lectures overlap). Note that the possibility of attending may depend on whether Hyunuk selected venue a or venue b to hold the conference.

A subset of lectures s is said to be venue-sensitive if, for one of the venues, the participant can attend s, but for the other venue, the participant cannot attend s.

A venue-sensitive set is problematic for a participant who is interested in attending the lectures in s because the participant cannot be sure whether the lecture times will overlap. Hyunuk will be happy if and only if there are no venue-sensitive sets. Determine whether Hyunuk will be happy.

Input

The first line contains an integer n (1 ≤ n ≤ 100 000), the number of lectures held in the conference.

Each of the next n lines contains four integers sa_i, ea_i, sb_i, eb_i (1 ≤ sa_i, ea_i, sb_i, eb_i ≤ 10^9, sa_i ≤ ea_i, sb_i ≤ eb_i).

Output

Print "YES" if Hyunuk will be happy. Print "NO" otherwise.

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

Examples

Input

2
1 2 3 6
3 4 7 8

Output

YES

Input

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

Output

NO

Input

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

Output

YES

Note

In second example, lecture set \{1, 3\} is venue-sensitive. Because participant can't attend this lectures in venue a, but can attend in venue b.

In first and third example, venue-sensitive set does not exist.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct info {
  int l1, r1, l2, r2;
  info(int _l1, int _r1, int _l2, int _r2) {
    l1 = _l1;
    r1 = _r1;
    l2 = _l2;
    r2 = _r2;
  }
};
const int maxn = 5e5 + 10;
int tree[4 * maxn], lazy[4 * maxn];
vector<pair<int, int> > agrega[maxn], quita[maxn];
vector<pair<int, int> > agrega2[maxn], quita2[maxn];
vector<info> A;
int N;
void build() {
  for (int i = 0; i < 4 * maxn; i++) {
    tree[i] = lazy[i] = 0;
  }
}
void update(int node, int start, int end, int l, int r, int val) {
  if (lazy[node] != 0) {
    tree[node] += lazy[node];
    if (start != end) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
  if (start > end || start > r || end < l) return;
  if (start >= l && end <= r) {
    tree[node] += val;
    if (start != end) {
      lazy[node * 2] += val;
      lazy[node * 2 + 1] += val;
    }
    return;
  }
  int mid = (start + end) / 2;
  update(node * 2, start, mid, l, r, val);
  update(node * 2 + 1, mid + 1, end, l, r, val);
  tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
int query(int node, int start, int end, int l, int r) {
  if (start > end || start > r || end < l) return 0;
  if (lazy[node] != 0) {
    tree[node] += lazy[node];
    if (start != end) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
  if (start >= l && end <= r) return tree[node];
  int mid = (start + end) / 2;
  int p1 = query(node * 2, start, mid, l, r);
  int p2 = query(node * 2 + 1, mid + 1, end, l, r);
  return max(p1, p2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  vector<int> unicos, diffs;
  ;
  for (int i = 0; i < N; i++) {
    int l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    unicos.push_back(l1);
    unicos.push_back(r1);
    unicos.push_back(l2);
    unicos.push_back(r2);
    A.push_back(info(l1, r1, l2, r2));
  }
  sort((unicos).begin(), (unicos).end());
  unicos.erase(unique((unicos).begin(), (unicos).end()), unicos.end());
  for (int i = 0; i < N; i++) {
    A[i].l1 =
        lower_bound((unicos).begin(), (unicos).end(), A[i].l1) - unicos.begin();
    A[i].r1 =
        lower_bound((unicos).begin(), (unicos).end(), A[i].r1) - unicos.begin();
    A[i].l2 =
        lower_bound((unicos).begin(), (unicos).end(), A[i].l2) - unicos.begin();
    A[i].r2 =
        lower_bound((unicos).begin(), (unicos).end(), A[i].r2) - unicos.begin();
    diffs.push_back(A[i].l1);
    diffs.push_back(A[i].r1);
    diffs.push_back(A[i].l2);
    diffs.push_back(A[i].r2);
    agrega[A[i].l1].push_back({A[i].l2, A[i].r2});
    quita[A[i].r1 + 1].push_back({A[i].l2, A[i].r2});
    agrega2[A[i].l2].push_back({A[i].l1, A[i].r1});
    quita2[A[i].r2 + 1].push_back({A[i].l1, A[i].r1});
  }
  sort((diffs).begin(), (diffs).end());
  diffs.erase(unique((diffs).begin(), (diffs).end()), diffs.end());
  build();
  int cnt = 0;
  int fin = diffs.back() + 1;
  for (int i = 0; i < fin + 1; i++) {
    for (auto &x : quita[i]) {
      cnt--;
      update(1, 0, fin, x.first, x.second, -1);
    }
    for (auto &x : agrega[i]) {
      if (cnt) {
        int cntAnt = query(1, 0, fin, x.first, x.second);
        if (cntAnt != cnt) {
          cout << "NO\n";
          ;
          return 0;
        }
      }
      cnt++;
      update(1, 0, fin, x.first, x.second, 1);
    }
  }
  build();
  cnt = 0;
  for (int i = 0; i < fin + 1; i++) {
    for (auto &x : quita2[i]) {
      cnt--;
      update(1, 0, fin, x.first, x.second, -1);
    }
    for (auto &x : agrega2[i]) {
      if (cnt) {
        int cntAnt = query(1, 0, fin, x.first, x.second);
        if (cntAnt != cnt) {
          cout << "NO\n";
          ;
          return 0;
        }
      }
      cnt++;
      update(1, 0, fin, x.first, x.second, 1);
    }
  }
  cout << "YES\n";
  ;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}.

You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}).

Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible.

Input

The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively.

Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9).

Output

Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them.

Example

Input

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

Output

1 5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e5;
int n, m;
long long val[(1 << 8) + 5], koji[(1 << 8) + 5];
long long sol = -1;
pair<int, int> res = make_pair(1, 1);
vector<int> v;
const long long inf = (long long)1e9 + 5;
void solve(long long mask, long long first, long long sad, int idx) {
  if (first == m) {
    sad = min(sad, val[mask]);
    if (koji[mask] && sad > sol) {
      sol = sad;
      res = make_pair(idx, koji[mask]);
    }
    return;
  }
  solve(mask, first + 1, min(sad, (long long)v[first]), idx);
  solve(mask | (1 << first), first + 1, sad, idx);
}
void procesiraj(long long mask, long long first, long long sad, int idx) {
  if (first == m) {
    if (sad >= val[mask]) {
      val[mask] = sad;
      koji[mask] = idx;
    }
    return;
  }
  procesiraj(mask, first + 1, sad, idx);
  procesiraj(mask | (1 << first), first + 1, min(sad, (long long)v[first]),
             idx);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    v.clear();
    for (int j = 0; j < m; ++j) {
      int first;
      scanf("%d", &first);
      v.push_back(first);
    }
    solve(0, 0, inf, i);
    procesiraj(0, 0, inf, i);
  }
  printf("%d %d", res.first, res.second);
  return 0;
}

```