### Prompt

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

We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c).

Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`.

The game consists of N steps. The i-th step proceeds as follows:

* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.

Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done.

Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.

Constraints

* 2 \leq H,W \leq 2 \times 10^5
* 2 \leq N \leq 2 \times 10^5
* 1 \leq s_r \leq H
* 1 \leq s_c \leq W
* |S|=|T|=N
* S and T consists of the four kinds of letters `L`, `R`, `U` and `D`.

Input

Input is given from Standard Input in the following format:

H W N
s_r s_c
S
T

Output

If the piece will remain on the grid at the end of the game, print `YES`; otherwise, print `NO`.

Examples

Input

2 3 3
2 2
RRL
LUD

Output

YES

Input

4 3 5
2 2
UDRRR
LLDUD

Output

NO

Input

5 6 11
2 1
RLDRRUDDLRL
URRDRLLDLRD

Output

NO

### Response

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

int h,w,n;
int sr,sc;
string s,t;

int lr,lc,mr,mc;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>h>>w>>n;
    cin>>sr>>sc;
    cin>>s;
    cin>>t;

    lr=mr=sr;
    lc=mc=sc;

    for(int i=0;i<n;i++){
        if(s[i]=='L')lc--;
        if(s[i]=='R')mc++;
        if(s[i]=='U')lr--;
        if(s[i]=='D')mr++;
        if(lc<1||mc>w||lr<1||mr>h){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t[i]=='L'&&mc>w/2)mc--;
        if(t[i]=='R'&&lc<w/2)lc++;
        if(t[i]=='U'&&mr>h/2)mr--;
        if(t[i]=='D'&&lr<h/2)lr++;
        //cout<<lc<<' '<<mc<<' '<<lr<<' '<<mr<<endl;
    }
    cout<<"YES"<<endl;

    return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.

Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time (in seconds).

Let's suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2a ≤ v holds.

As a result, Valera decided to set v seconds TL, that the following conditions are met:

  1. v is a positive integer;
  2. all correct solutions pass the system testing;
  3. at least one correct solution passes the system testing with some "extra" time;
  4. all wrong solutions do not pass the system testing;
  5. value v is minimum among all TLs, for which points 1, 2, 3, 4 hold.

Help Valera and find the most suitable TL or else state that such TL doesn't exist.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the running time of each of m wrong solutions in seconds.

Output

If there is a valid TL value, print it. Otherwise, print -1.

Examples

Input

3 6
4 5 2
8 9 6 10 7 11

Output

5

Input

3 1
3 4 5
6

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> correct;
  vector<int> notCorrect;
  int z;
  for (int i = 0; i < n; i++) {
    cin >> z;
    correct.push_back(z);
  }
  for (int i = 0; i < m; i++) {
    cin >> z;
    notCorrect.push_back(z);
  }
  sort(correct.begin(), correct.end());
  sort(notCorrect.begin(), notCorrect.end());
  int ans = 2 * correct[0];
  if (ans < correct[n - 1]) {
    ans = correct[n - 1];
  }
  if (ans >= notCorrect[0]) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Priests of the Quetzalcoatl cult want to build a tower to represent a power of their god. Tower is usually made of power-charged rocks. It is built with the help of rare magic by levitating the current top of tower and adding rocks at its bottom. If top, which is built from k - 1 rocks, possesses power p and we want to add the rock charged with power wk then value of power of a new tower will be {wk}p.

Rocks are added from the last to the first. That is for sequence w1, ..., wm value of power will be

<image>

After tower is built, its power may be extremely large. But still priests want to get some information about it, namely they want to know a number called cumulative power which is the true value of power taken modulo m. Priests have n rocks numbered from 1 to n. They ask you to calculate which value of cumulative power will the tower possess if they will build it from rocks numbered l, l + 1, ..., r.

Input

First line of input contains two integers n (1 ≤ n ≤ 105) and m (1 ≤ m ≤ 109).

Second line of input contains n integers wk (1 ≤ wk ≤ 109) which is the power of rocks that priests have.

Third line of input contains single integer q (1 ≤ q ≤ 105) which is amount of queries from priests to you.

kth of next q lines contains two integers lk and rk (1 ≤ lk ≤ rk ≤ n).

Output

Output q integers. k-th of them must be the amount of cumulative power the tower will have if is built from rocks lk, lk + 1, ..., rk.

Example

Input

6 1000000000
1 2 2 3 3 3
8
1 1
1 6
2 2
2 3
2 4
4 4
4 5
4 6

Output

1
1
2
4
256
3
27
597484987

Note

327 = 7625597484987

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-10;
int dcmp(double first) {
  if (fabs(first) < eps) return 0;
  return first < 0 ? -1 : 1;
}
long long mit;
long long a[N], b[N], ph[N];
int l, r, ot;
long long qpowt(long long a, long long n) {
  if (a > mit) return -1;
  long long ans = 1;
  int f = 1;
  while (n) {
    if (n & 1) {
      if (!f) return -1;
      ans *= a;
      if (ans > mit) return -1;
    }
    a *= a;
    if (a > mit) f = 0;
    n >>= 1;
  }
  return ans;
}
long long phe(long long n) {
  long long sum = n;
  long long m = sqrt(n + 0.5);
  for (long long i = 2; i <= m; i++) {
    if (!(n % i)) {
      sum = sum * (i - 1) / i;
      while (!(n % i)) n /= i;
    }
  }
  if (n > 1) sum = sum / n * (n - 1);
  return sum;
}
long long qpow(long long a, long long n, long long M) {
  a %= M;
  long long ans = 1;
  while (n) {
    if (n & 1) ans = (ans * a) % M;
    a = (a * a) % M;
    n >>= 1;
  }
  return ans;
}
long long f(long long pos) {
  long long pm = ph[pos - l + 1], ans;
  if (pm == 1 || pm == 0) {
    ans = 1;
  } else if (pos + 1 >= ot) {
    if (b[pos + 1] <= pm)
      ans = b[pos + 1];
    else
      ans = b[pos + 1] % pm + pm;
  } else
    ans = f(pos + 1) + pm;
  return qpow(a[pos], ans, ph[pos - l]);
}
int main() {
  int n, Q, cnt = 0;
  scanf("%d %lld", &n, &mit);
  vector<int> tt;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 1) tt.push_back(i);
  }
  ph[0] = mit;
  int n1 = 0;
  while (ph[n1] != 1) {
    n1++;
    ph[n1] = phe(ph[n1 - 1]);
  }
  scanf("%d", &Q);
  while (Q--) {
    cnt++;
    scanf("%d %d", &l, &r);
    l--;
    r--;
    int fq = lower_bound(tt.begin(), tt.end(), l) - tt.begin();
    if (fq != tt.size()) r = min(r, tt[fq]);
    ot = r;
    b[r] = a[r];
    for (int i = r - 1; i >= l; i--) {
      b[i] = qpowt(a[i], b[i + 1]);
      if (b[i] != -1)
        ot = i;
      else
        break;
    }
    if (l == r)
      printf("%lld\n", a[l] % mit);
    else
      printf("%lld\n", f(l));
  }
  return 0;
}

```


### Prompt

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

A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?

<image>

One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs Wr grams and each blue candy weighs Wb grams. Eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.

Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.

Input

The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).

Output

Print a single integer — the maximum number of joy units that Om Nom can get.

Examples

Input

10 3 5 2 3

Output

16

Note

In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.

### Response

```cpp
#include <bits/stdc++.h>
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1070000000LL;
const long long MOD = 1000000007LL;
using namespace std;
long long C, Hr, Hb, Wr, Wb;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  if (Wr < Wb) {
    swap(Hr, Hb);
    swap(Wr, Wb);
  }
  assert(Wr >= Wb);
  if (Wr > 1000) {
    long long ans = 0;
    for (long long r = (long long)(0); r < (long long)(1000010); r++) {
      long long rest = C - r * Wr;
      if (rest < 0) continue;
      ans = ((ans) > (r * Hr + rest / Wb * Hb) ? (ans)
                                               : (r * Hr + rest / Wb * Hb));
    }
    cout << ans << endl;
    return 0;
  } else {
    long long ans = 0;
    for (long long D = (long long)(((0) > (C - 1000) ? (0) : (C - 1000)));
         D < (long long)(C + 1); D++) {
      if (Hr * Wb > Hb * Wr) {
        long long mod = D % Wr;
        long long b = -1;
        for (long long i = (long long)(0); i < (long long)(1010); i++) {
          if (i * Wb % Wr == mod) {
            b = i;
            break;
          }
        }
        if (b == -1) continue;
        long long rest = D - b * Wb;
        if (rest < 0) continue;
        ans = ((ans) > (b * Hb + rest / Wr * Hr) ? (ans)
                                                 : (b * Hb + rest / Wr * Hr));
      } else {
        long long mod = D % Wb;
        long long r = -1;
        for (long long i = (long long)(0); i < (long long)(1010); i++) {
          if (i * Wr % Wb == mod) {
            r = i;
            break;
          }
        }
        if (r == -1) continue;
        long long rest = D - r * Wr;
        if (rest < 0) continue;
        ans = ((ans) > (r * Hr + rest / Wb * Hb) ? (ans)
                                                 : (r * Hr + rest / Wb * Hb));
      }
    }
    cout << ans << endl;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Let's play a game using a robot on a rectangular board covered with a square mesh (Figure D-1). The robot is initially set at the start square in the northwest corner facing the east direction. The goal of this game is to lead the robot to the goal square in the southeast corner.

<image>

Figure D-1: Example of a board

The robot can execute the following five types of commands.

"Straight":
Keep the current direction of the robot, and move forward to the next square.
"Right":
Turn right with 90 degrees from the current direction, and move forward to the next square.
"Back":
Turn to the reverse direction, and move forward to the next square.
"Left":
Turn left with 90 degrees from the current direction, and move forward to the next square.
"Halt":
Stop at the current square to finish the game.

Each square has one of these commands assigned as shown in Figure D-2. The robot executes the command assigned to the square where it resides, unless the player gives another command to be executed instead. Each time the player gives an explicit command, the player has to pay the cost that depends on the command type.

<image>

Figure D-2: Example of commands assigned to squares

The robot can visit the same square several times during a game. The player loses the game when the robot goes out of the board or it executes a "Halt" command before arriving at the goal square.

Your task is to write a program that calculates the minimum cost to lead the robot from the start square to the goal one.

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 is formatted as follows.

> w h
>  s(1,1) ... s(1,w)
>  s(2,1) ... s(2,w)
>  ...
>  s(h,1) ... s(h,w)
>  c0 c1 c2 c3

The integers h and w are the numbers of rows and columns of the board, respectively. You may assume 2 ≤ h ≤ 30 and 2 ≤ w ≤ 30. Each of the following h lines consists of w numbers delimited by a space. The number s(i, j) represents the command assigned to the square in the i-th row and the j-th column as follows.

* 0: "Straight"
* 1: "Right"
* 2: "Back"
* 3: "Left"
* 4: "Halt"

You can assume that a "Halt" command is assigned to the goal square. Note that "Halt" commands may be assigned to other squares, too.

The last line of a dataset contains four integers c0, c1, c2, and c3, delimited by a space, indicating the costs that the player has to pay when the player gives "Straight", "Right", "Back", and "Left" commands respectively. The player cannot give "Halt" commands. You can assume that all the values of c0, c1, c2, and c3 are between 1 and 9, inclusive.

Output

For each dataset, print a line only having a decimal integer indicating the minimum cost required to lead the robot to the goal. No other characters should be on the output line.

Sample Input

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

Output for the Sample Input

1
11
6

Example

Input

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

Output

1
11
6

### Response

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

struct State {
  int x, y, d, c;
  State(){}
  State(int x_, int y_, int d_, int c_) : x(x_), y(y_), d(d_), c(c_) {}
  bool operator>(const State& s) const {
    return c>s.c;
  }
};

const int S = 31;
const int INF = 1<<27;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

int H, W;
int G[S][S], C[4];

bool in(int x, int y) {
  return 0<=x && x<W && 0<=y & y<H;
}

int a() {
  int c[4][S][S];

  priority_queue<State, vector<State>, greater<State> > q;

  fill(c[0][0], c[4][0], INF);
  q.push(State(0,0,0,0));
  c[0][0][0] = 0;

  while(!q.empty()) {
    const State s = q.top(); q.pop();
    if(s.x == W-1 && s.y == H-1) return s.c;

    for(int i=0; i<4; i++) {
      State t = s;
      t.d = (s.d + i) % 4;
      t.x += dx[t.d], t.y += dy[t.d];
      t.c += i == G[s.y][s.x] ? 0 : C[i];
      if(in(t.x, t.y) && c[t.d][t.y][t.x] > t.c) {
	q.push(t);
	c[t.d][t.y][t.x] = t.c;
      }
    }
  }
  return -1;
}

int main() {
  while(cin >> W >>H, W+H ) {
    for(int i=0; i<H; i++) for(int j=0; j<W; j++) cin >> G[i][j];
    for(int i=0; i<4; i++) cin >> C[i];
    cout << a() << endl;
  }
  return 0;
}
```


### Prompt

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

It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.

Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.

Input

The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.

Output

Print a single integer — the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.

Examples

Input

1987

Output

2013

Input

2013

Output

2014

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int i, j, k, l, y, m, n;
  char s[101], t[101];
  scanf("%d", &y);
  for (i = y + 1;; i++) {
    n = i;
    j = n % 10;
    n = n / 10;
    k = n % 10;
    n = n / 10;
    l = n % 10;
    n = n / 10;
    if (n != l && n != k && n != j && l != k && l != j && k != j) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}

```


### Prompt

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

Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.

Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.

Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?

Input

The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.

Output

In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.

If there are multiple optimal ways to split the cubes into the heaps, print any of them.

Examples

Input

1
10 99

Output

1
2 1

Input

2
13 24 13 45

Output

4
1 2 2 1

Note

In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.

In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int o[200], v[200], p[200];
int cnt[2];
bool cmp(int a, int b) { return v[a] < v[b]; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 2 * n; ++i) {
    scanf("%d", v + i);
    o[i] = i;
  }
  sort(o, o + 2 * n, cmp);
  vector<int> u;
  for (int i = 0; i < 2 * n;) {
    int j = i;
    while (j < 2 * n && v[o[j]] == v[o[i]]) ++j;
    if (j - i == 1)
      u.push_back(o[i]);
    else {
      p[o[i]] = 1, ++cnt[0];
      p[o[i + 1]] = 2, ++cnt[1];
    }
    i = j;
  }
  for (int i = 0; i < u.size(); i += 2) {
    p[u[i]] = 1, ++cnt[0];
    if (i + 1 < u.size()) p[u[i + 1]] = 2, ++cnt[1];
  }
  printf("%d\n", cnt[0] * cnt[1]);
  for (int i = 0; i < 2 * n; ++i) {
    if (!p[i]) {
      if (cnt[0] < n) {
        p[i] = 1, ++cnt[0];
      } else {
        p[i] = 2, ++cnt[1];
      }
    }
  }
  for (int i = 0; i < 2 * n; ++i) printf("%d ", p[i]);
  puts("");
  return 0;
}

```


### Prompt

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

Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make:

  1. The house consists of some non-zero number of floors.
  2. Each floor consists of a non-zero number of rooms and the ceiling. A room is two cards that are leaned towards each other. The rooms are made in a row, each two adjoining rooms share a ceiling made by another card.
  3. Each floor besides for the lowest one should contain less rooms than the floor below.

Please note that the house may end by the floor with more than one room, and in this case they also must be covered by the ceiling. Also, the number of rooms on the adjoining floors doesn't have to differ by one, the difference may be more.

While bears are practicing to put cards, Horace tries to figure out how many floors their house should consist of. The height of the house is the number of floors in it. It is possible that you can make a lot of different houses of different heights out of n cards. It seems that the elephant cannot solve this problem and he asks you to count the number of the distinct heights of the houses that they can make using exactly n cards.

Input

The single line contains integer n (1 ≤ n ≤ 1012) — the number of cards.

Output

Print the number of distinct heights that the houses made of exactly n cards can have.

Examples

Input

13

Output

1

Input

6

Output

0

Note

In the first sample you can build only these two houses (remember, you must use all the cards):

<image>

Thus, 13 cards are enough only for two floor houses, so the answer is 1.

The six cards in the second sample are not enough to build any house.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long solve(long long n) {
  long long cnt = 0;
  for (long long i = 1; i <= 10000000; i++) {
    if ((i * (3 * i + 1)) / 2 > n)
      break;
    else {
      if ((n - (i * (3 * i + 1)) / 2) % 3 == 0) cnt++;
    }
  }
  return cnt;
}
int main() {
  long long n;
  cin >> n;
  cout << solve(n) << endl;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.

The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves.

One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0).

You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n).

Input

The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces.

The input limitations for getting 20 points are:

  * 1 ≤ n ≤ 300

The input limitations for getting 50 points are:

  * 1 ≤ n ≤ 2000

The input limitations for getting 100 points are:

  * 1 ≤ n ≤ 105

Output

Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero.

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

Examples

Input

4
1 0 1 2

Output

1
1
3

Input

8
1 2 3 4 5 6 7 8

Output

1
3
6
10
16
24
40

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long p[1000000];
vector<long long> v;
void f() {
  long long k = 1;
  while (k < 1000000) {
    for (long long i = k; i < k * 2 && i < 1000000; i++) p[i] = 1 + p[i - k];
    k *= 2;
  }
}
int main() {
  p[0] = 0;
  long long n;
  cin >> n;
  v.resize(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  f();
  for (long long i = 1; i < n; i++) {
    long long s = 0;
    for (long long j = 0; j < i; j++) {
      long long mi = p[i - j];
      for (long long k = i - j; k <= n - j - 1; k++)
        if (p[k] < mi) mi = p[k];
      s += mi * v[j];
    }
    cout << s << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You are a given a list of integers a_1, a_2, …, a_n and s of its segments [l_j; r_j] (where 1 ≤ l_j ≤ r_j ≤ n).

You need to select exactly m segments in such a way that the k-th order statistic of the multiset of a_i, where i is contained in at least one segment, is the smallest possible. If it's impossible to select a set of m segments in such a way that the multiset contains at least k elements, print -1.

The k-th order statistic of a multiset is the value of the k-th element after sorting the multiset in non-descending order.

Input

The first line contains four integers n, s, m and k (1 ≤ m ≤ s ≤ 1500, 1 ≤ k ≤ n ≤ 1500) — the size of the list, the number of segments, the number of segments to choose and the statistic number.

The second line contains n integers a_i (1 ≤ a_i ≤ 10^9) — the values of the numbers in the list.

Each of the next s lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the endpoints of the segments.

It is possible that some segments coincide.

Output

Print exactly one integer — the smallest possible k-th order statistic, or -1 if it's impossible to choose segments in a way that the multiset contains at least k elements.

Examples

Input

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

Output

2

Input

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

Output

1

Input

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

Output

-1

Note

In the first example, one possible solution is to choose the first and the third segment. Together they will cover three elements of the list (all, except for the third one). This way the 2-nd order statistic for the covered elements is 2.

<image>

### Response

```cpp
#include <bits/stdc++.h>
int M, a, b, c, i, j, K, p, q, h, s, m[1555], mind[1555], D[1555][1555],
    x[1555], y[1555], l[1555], r[1555];
int main() {
  scanf("%d%d%d%d", &a, &b, &c, &K);
  for (i = 1; i <= a; i++) {
    scanf("%d", &x[i]);
  }
  for (i = 1; i <= b; i++) {
    scanf("%d%d", &l[i], &r[i]);
  }
  p = 0;
  q = 1e9;
  q += 2;
  while (p != q - 1) {
    h = (p + q) / 2;
    for (i = 1; i <= a; i++) {
      if (x[i] <= h)
        y[i] = 1;
      else
        y[i] = 0;
    }
    for (i = 1; i <= a + 1; i++) {
      m[i] = -1;
      mind[i] = -1;
    }
    for (i = 0; i <= a + 1; i++)
      for (j = 0; j <= b + 1; j++) D[i][j] = -1;
    for (i = 1; i <= b; i++) {
      s = 0;
      for (j = r[i]; j >= l[i]; j--) {
        s += y[j];
        if (m[j] < s) {
          m[j] = s;
          mind[j] = r[i];
        }
      }
    }
    M = 0;
    D[0][0] = 0;
    for (i = 0; i <= a; i++) {
      for (j = 0; j <= c; j++) {
        D[i + 1][j] = std::max(D[i + 1][j], D[i][j]);
      }
      for (j = c; j >= 0; j--) {
        if (m[i + 1] != -1 && D[i][j] != -1 && j + 1 <= c &&
            D[mind[i + 1]][j + 1] < D[i][j] + m[i + 1]) {
          D[mind[i + 1]][j + 1] = D[i][j] + m[i + 1];
        }
      }
    }
    for (i = 0; i <= a; i++) {
      for (j = 0; j <= c; j++) {
        M = std::max(M, D[i][j]);
      }
    }
    if (M >= K)
      q = h;
    else
      p = h;
  }
  if (q == 1000000002) {
    puts("-1");
  } else
    printf("%d", q);
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).

Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.

The only line of the test case contains one integer n (1 ≤ n ≤ 10^9).

Output

For each test case, print the answer — the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.

Example

Input

7
1
2
3
12
12345
15116544
387420489

Output

0
-1
2
-1
-1
12
36

Note

Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:

  1. Divide by 6 and get 2519424;
  2. divide by 6 and get 419904;
  3. divide by 6 and get 69984;
  4. divide by 6 and get 11664;
  5. multiply by 2 and get 23328;
  6. divide by 6 and get 3888;
  7. divide by 6 and get 648;
  8. divide by 6 and get 108;
  9. multiply by 2 and get 216;
  10. divide by 6 and get 36;
  11. divide by 6 and get 6;
  12. divide by 6 and get 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long count = 0;
    int flag = 1;
    while (n != 1) {
      if (n % 3 != 0) {
        flag = 0;
        break;
      }
      if (n % 6 == 0) {
        n = n / 6;
        count++;
        continue;
      }
      n = n * 2;
      count++;
    }
    if (flag)
      cout << count << "\n";
    else
      cout << -1 << "\n";
  }
}

```


### Prompt

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

Petya sometimes has to water his field. To water the field, Petya needs a tank with exactly V ml of water.

Petya has got N tanks, i-th of them initially containing ai ml of water. The tanks are really large, any of them can contain any amount of water (no matter how large this amount is).

Also Petya has got a scoop that can contain up to K ml of water (initially the scoop is empty). This scoop can be used to get some water from some tank, and after that pour it all into some tank (it is impossible to get water from multiple tanks without pouring it, or leave some water in the scoop when pouring it). When Petya tries to get some water from a tank, he gets min(v, K) water, where v is the current volume of water in the tank.

Is it possible to obtain a tank with exactly V ml of water using these operations? If it is possible, print a sequence of operations that allows to do it. If there are multiple ways to obtain needed amount of water in some tank, print any of them.

Input

The first line contains 3 integers: N (2 ≤ N ≤ 5000), K (1 ≤ K ≤ 5000), and V (0 ≤ V ≤ 109) — the number of tanks, the maximum volume of water the scoop can contain, and the required amount of water in some tank, respectively.

The second line contains N integers ai (0 ≤ ai ≤ 105), where ai is initial volume of water in i-th tank.

Output

If it is impossible to obtain a tank with exactly V ml of water, print NO.

Otherwise print YES in the first line, and beginning from the second line, print the sequence of operations in the following format:

Each line has to contain 3 numbers denoting a compressed operation: "cnt x y" (1 ≤ cnt ≤ 109, 1 ≤ x, y ≤ N), where x is the index of the tank where we get water, y is the index of the tank where we pour water, and cnt is the number of times we transfer water from tank x to tank y.

The number of these lines must not exceed N + 5.

Examples

Input

2 3 5
2 3

Output

YES
1 2 1

Input

2 3 4
2 3

Output

NO

Input

5 2 0
1 3 5 7 9

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[5010], b[5010], dp[5010][5010];
bool flag[5010];
int main() {
  int n, k, v, sum = 0;
  scanf("%d%d%d", &n, &k, &v);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += (b[i] = a[i]), a[i] %= k;
  }
  if (sum < v) {
    puts("NO");
    return 0;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      if (dp[i - 1][j]) {
        dp[i][j] = 1;
        if (!dp[i][(j + a[i]) % k]) dp[i][(j + a[i]) % k] = 2;
      }
    }
  }
  int tar = v % k;
  if (!dp[n][tar]) {
    puts("NO");
    return 0;
  }
  puts("YES");
  int ans = 0, fnl1 = -1, fnl2 = -1;
  for (int i = n; i >= 1; --i) {
    if (dp[i][tar] == 2) {
      flag[i] = true, (tar += k - a[i]) %= k, ans += b[i];
      if (fnl1 == -1) fnl1 = i;
    } else if (fnl2 == -1)
      fnl2 = i;
  }
  if (fnl1 == -1) {
    for (int i = 1; i < n; ++i)
      if (b[i]) {
        printf("%d %d %d\n", (b[i] + k - 1) / k, i, n);
      }
    if (v / k) printf("%d %d %d\n", v / k, n, 1);
    return 0;
  }
  int rem = v - ans;
  int S1 = b[fnl1], S2 = b[fnl2];
  for (int i = 1; i <= n; ++i) {
    if (i == fnl1 || i == fnl2 || !b[i]) continue;
    if (!flag[i])
      printf("%d %d %d\n", (b[i] + k - 1) / k, i, fnl2), S2 += b[i];
    else
      printf("%d %d %d\n", (b[i] + k - 1) / k, i, fnl1), S1 += b[i];
  }
  int cnt = (v - S1) / k;
  if (cnt > 0)
    printf("%d %d %d\n", cnt, fnl2, fnl1);
  else if (cnt < 0)
    printf("%d %d %d\n", -cnt, fnl1, 1);
  return 0;
}

```


### Prompt

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

We have an integer sequence A, whose length is N.

Find the number of the non-empty contiguous subsequences of A whose sums are 0. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.

Constraints

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

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Find the number of the non-empty contiguous subsequences of A whose sum is 0.

Examples

Input

6
1 3 -4 2 2 -2

Output

3

Input

7
1 -1 1 -1 1 -1 1

Output

12

Input

5
1 -2 3 -4 5

Output

0

### Response

```cpp
#include<cstdio>
#include<map>
using namespace std;

typedef long long LL;

int N;
LL Ans;

map<LL,int> Cnt;

int main(){
	int i,x;
	LL s=0;
	scanf("%d",&N);
	Cnt[0]++;
	while(N--){
		scanf("%d",&x),s+=x;
		Ans+=Cnt[s];
		Cnt[s]++;
	}
	printf("%lld\n",Ans);
	return 0;
}
```


### Prompt

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

Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters.

The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces.

Input

A text is given in a line. You can assume the following conditions:

* The number of letters in the text is less than or equal to 1000.
* The number of letters in a word is less than or equal to 32.
* There is only one word which is arise most frequently in given text.
* There is only one word which has the maximum number of letters in given text.

Output

The two words separated by a space.

Example

Input

Thank you for your mail and your lectures

Output

your lectures

### Response

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int main(){
	map<string,int> mp;
	ios::sync_with_stdio(false);
	string s;
	string a,b;
	b="";
	while (cin>>s){
		mp[s]++;
		if (s.length()>b.length()){
			b=s;
		}
	}
	int ma=0;
	for (auto ite=mp.begin();ite!=mp.end();ite++){
		if (ite->second > ma){
			ma = ite->second;
			a = ite->first;
		}
	}
	cout << a << " "<<b<<endl;
	return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all.

After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains n space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.

Output

Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.

Examples

Input

5
1 2 3 4 5

Output

1 1 2 3 4

Input

5
2 3 4 5 6

Output

1 2 3 4 5

Input

3
2 2 2

Output

1 2 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
const long long MOD = 1000000009;
long long mypow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0)
    return mypow((a * a) % MOD, b / 2) % MOD;
  else
    return (a * (mypow(a, b - 1) % MOD)) % MOD;
}
int calc(int t) {
  long long ret = (mypow(2, t) - 1);
  ret %= MOD;
  ret *= k;
  ret %= MOD;
  ret *= 2;
  ret %= MOD;
  return ret;
}
int main() {
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  if (x.back() != 1) {
    cout << "1 ";
    x.pop_back();
    for (int xx : x) cout << xx << " ";
  } else {
    x.pop_back();
    for (int xx : x) cout << xx << " ";
    cout << "2";
  }
}

```


### Prompt

Please formulate a CPP solution to the following problem:

The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.

The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

  1. Only one disk can be moved at a time.
  2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
  3. No disk may be placed on top of a smaller disk.

With three disks, the puzzle can be solved in seven moves. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2n - 1, where n is the number of disks. (c) Wikipedia.

SmallY's puzzle is very similar to the famous Tower of Hanoi. In the Tower of Hanoi puzzle you need to solve a puzzle in minimum number of moves, in SmallY's puzzle each move costs some money and you need to solve the same puzzle but for minimal cost. At the beginning of SmallY's puzzle all n disks are on the first rod. Moving a disk from rod i to rod j (1 ≤ i, j ≤ 3) costs tij units of money. The goal of the puzzle is to move all the disks to the third rod.

In the problem you are given matrix t and an integer n. You need to count the minimal cost of solving SmallY's puzzle, consisting of n disks.

Input

Each of the first three lines contains three integers — matrix t. The j-th integer in the i-th line is tij (1 ≤ tij ≤ 10000; i ≠ j). The following line contains a single integer n (1 ≤ n ≤ 40) — the number of disks.

It is guaranteed that for all i (1 ≤ i ≤ 3), tii = 0.

Output

Print a single integer — the minimum cost of solving SmallY's puzzle.

Examples

Input

0 1 1
1 0 1
1 1 0
3

Output

7

Input

0 2 2
1 0 100
1 2 0
3

Output

19

Input

0 2 1
1 0 100
1 2 0
5

Output

87

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, cost[(int)(5)][(int)(5)];
long long int dp[(int)(50)][(int)(5)][(int)(5)];
int main() {
  for (int i = 1; i < 4; i++)
    for (int j = 1; j < 4; j++) scanf("%d", &cost[i][j]);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 3; j++) {
      for (int k = 1; k <= 3; k++) {
        if (j == k) continue;
        int t = 6 - j - k;
        dp[i][j][k] = min(dp[i - 1][j][t] + cost[j][k] + dp[i - 1][t][k],
                          dp[i - 1][j][k] + cost[j][t] + dp[i - 1][k][j] +
                              cost[t][k] + dp[i - 1][j][k]);
      }
    }
  }
  printf("%lld\n", dp[n][1][3]);
}

```


### Prompt

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

Phoenix is playing with a new puzzle, which consists of n identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.

<image> A puzzle piece

The goal of the puzzle is to create a square using the n pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all n pieces must be used (of course, the square shouldn't contain any holes as well). Can he do it?

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases.

The first line of each test case contains an integer n (1 ≤ n ≤ 10^9) — the number of puzzle pieces.

Output

For each test case, if Phoenix can create a square with the n puzzle pieces, print YES. Otherwise, print NO.

Example

Input

3
2
4
6

Output

YES
YES
NO

Note

For n=2, Phoenix can create a square like this:

<image>

For n=4, Phoenix can create a square like this:

<image>

For n=6, it is impossible for Phoenix to create a square.

### Response

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int rt = sqrt(n), rt2 = sqrt(n/2);
        if ((n%2 == 0 and rt*rt == n) or (2*rt2*rt2 == n)) cout << "YES\n";
        else cout << "NO\n";
    }
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

As Gerald, Alexander, Sergey and Gennady are already busy with the usual New Year chores, Edward hastily decorates the New Year Tree. And any decent New Year Tree must be decorated with a good garland. Edward has lamps of m colors and he wants to make a garland from them. That garland should represent a sequence whose length equals L. Edward's tree is n layers high and Edward plans to hang the garland so as to decorate the first layer with the first l1 lamps, the second layer — with the next l2 lamps and so on. The last n-th layer should be decorated with the last ln lamps, <image>

Edward adores all sorts of math puzzles, so he suddenly wondered: how many different ways to assemble the garland are there given that the both following two conditions are met:

  1. Any two lamps that follow consecutively in the same layer should have different colors.
  2. The sets of used colors in every two neighbouring layers must be different. We consider unordered sets (not multisets), where every color occurs no more than once. So the number of lamps of particular color does not matter.

Help Edward find the answer to this nagging problem or else he won't manage to decorate the Tree by New Year. You may consider that Edward has an unlimited number of lamps of each of m colors and it is not obligatory to use all m colors. The garlands are considered different if they differ in at least one position when represented as sequences. Calculate the answer modulo p.

Input

The first line contains three integers n, m and p (1 ≤ n, m ≤ 106, 2 ≤ p ≤ 109) which are the number of the tree's layers, the number of the lamps' colors and module correspondingly. The next line contains n integers li (1 ≤ li ≤ 5000, <image>).

Output

Print the only integer — the number of garlands modulo p.

Examples

Input

3 2 1000
3 1 2

Output

8

Input

2 3 1000
2 2

Output

24

Input

1 1 1000
5

Output

0

Note

In the first sample the following variants are possible: 121|1|12, 121|1|21, 121|2|12, 121|2|21, 212|1|12, 212|1|21, 212|2|12, 212|2|21. In the second sample the following variants are possible: 12|13, 12|23, 12|31, 12|32 and so on.

Figure for the first sample: <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T read_value(string s) {
  T result;
  istringstream sin(s);
  sin >> result;
  return result;
}
string read_line() {
  string ret_val;
  getline(std::cin, ret_val);
  return ret_val;
}
template <class T>
void init_array(T *arr, int size, T value) {
  for (int i = 0; i < size; i++) arr[i] = value;
}
template <class T>
inline T gcd(T a, T b) {
  return (!a) ? b : gcd(b % a, a);
}
template <class T>
inline T mod(T a, T p) {
  a %= p;
  return (a < 0) ? a + p : a;
}
template <class T>
inline int numbits(T n) {
  return (!n) ? 0 : 1 + numbits(n & (n - 1));
}
template <class T>
inline T inverse(T a, T m) {
  a = mod<T>(a, m);
  return (a == 1) ? 1 : mod((1 - m * inverse(m % a, a)) / a, m);
}
template <class T>
inline bool is_prime(T a) {
  T lim = (T)sqrt((double)a);
  for (T i = 2; i <= T(lim + 1E-9); i++)
    if (a % i == 0) return false;
  return true;
}
template <class T>
inline T power(T a, T p, T mod) {
  if (!p) return 1;
  T temp = power(a, p >> 1, mod);
  temp = (temp * temp) % mod;
  if (p & 1) temp = (temp * a) % mod;
  return temp;
}
void get_primes(int start, int end, vector<int> &vi) {
  bool *p = new bool[end + 1];
  init_array<bool>(p, end + 1, 0);
  p[1] = 1;
  for (int i = 2; i <= end; i++) {
    if (!p[i]) {
      if (i >= start) vi.push_back(i);
      for (int j = 2 * i; j <= end; j += i) p[j] = 1;
    }
  }
  delete[] p;
}
bool dfs(int current, int final, int total, vector<int> &visited,
         vector<vector<bool> > &edges, bool flow) {
  if (current == final) return true;
  if (visited[current]) return false;
  visited[current] = true;
  for (int i = 0; i < total; i++)
    if (edges[current][i] && dfs(i, final, total, visited, edges, flow)) {
      if (flow) {
        edges[current][i] = false;
        edges[i][current] = true;
      }
      return true;
    }
  return false;
}
int flow(int in, int out, int total, vector<vector<bool> > &edges) {
  int result = 0;
  for (vector<int> visited(total, 0); dfs(in, out, total, visited, edges, true);
       ++result)
    visited = vector<int>(total, 0);
  return result;
}
void create_set(int x, int *P, int *rank) {
  P[x] = x;
  rank[x] = 0;
}
int find_set(int x, int *P) {
  if (x != P[x]) P[x] = find_set(P[x], P);
  return P[x];
}
bool merge_sets(int x, int y, int *P, int *rank) {
  int Px = find_set(x, P);
  int Py = find_set(y, P);
  if (Px == Py) return false;
  if (rank[Px] > rank[Py])
    P[Py] = Px;
  else
    P[Px] = Py;
  if (rank[Px] == rank[Py]) rank[Py]++;
  return true;
}
template <typename T>
int read_cum_freq(int index, T *tree) {
  int sum = 0;
  while (index) {
    sum += tree[index];
    index -= (index & -index);
  }
  return sum;
}
template <typename T>
void upd_freq(int index, int mxIndex, int value, T *tree) {
  while (index <= mxIndex) {
    tree[index] += value;
    index += (index & -index);
  }
}
template <typename T>
int read_freq(int index, T *tree) {
  return read_cum_freq(index, tree) - read_cum_freq(index - 1, tree);
}
void build_failure_function(const string &str, int *temp_arr) {
  temp_arr[0] = temp_arr[1] = 0;
  for (int i = 2; i <= ((int)(str).size()); i++) {
    temp_arr[i] = -1;
    for (int ind = temp_arr[i - 1]; temp_arr[i] == -1; ind = temp_arr[ind]) {
      if (str[ind] == str[i - 1]) {
        temp_arr[i] = ind + 1;
      } else if (ind == 0) {
        temp_arr[i] = 0;
      }
    }
  }
}
void KMP(const string &text, const string &pattern, int *res) {
  int *temp_arr = new int[((int)(pattern).size()) + 1];
  build_failure_function(pattern, temp_arr);
  int i = 0;
  int ind = 0;
  while (i < ((int)(text).size())) {
    if (text[i] == pattern[ind]) {
      res[i] = ++ind;
      if (res[i] == ((int)(pattern).size())) {
        ind = temp_arr[ind];
      }
      i++;
    } else if (ind == 0) {
      res[i++] = 0;
    } else {
      ind = temp_arr[ind];
    }
  }
  delete[] temp_arr;
}
template <typename T, int N>
struct matrix {
  T m[N][N];
  T md;
  matrix(T md, bool unary = false) {
    this->md = md;
    memset(m, 0, sizeof(m));
    if (unary) {
      for (int i = 0; i < N; i++) {
        m[i][i] = 1;
      }
    }
  }
  matrix operator*(const matrix &that) const {
    matrix ret_val(md, false);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        for (int k = 0; k < N; k++) {
          ret_val.m[i][j] += this->m[i][k] * that.m[k][j];
          ret_val.m[i][j] %= md;
        }
      }
    }
    return ret_val;
  }
  vector<T> operator*(const vector<T> &vec) const {
    vector<T> ret_val(vec.size(), 0);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        ret_val[i] += m[i][j] * vec[j];
        ret_val[i] %= md;
      }
    }
    return ret_val;
  }
  matrix power(int pw) const {
    if (!pw) return matrix(md, true);
    if (pw == 1) return *this;
    matrix ret_val = power(pw >> 1);
    ret_val = ret_val * ret_val;
    if (pw & 1) ret_val = ret_val * (*this);
    return ret_val;
  }
};
void setup(int value, string name) {
  string name_in = name + ".in";
  string name_out = name + ".out";
  freopen(name_in.c_str(), "r", stdin);
  if (value) freopen(name_out.c_str(), "w", stdout);
}
int C[5001];
int dp[5001][5001];
void eval_c(long long m, long long p) {
  vector<long long> vi;
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (int i = 1; i <= min(5000, (int)m); ++i) {
    vi.push_back(m - i + 1);
    long long val = i;
    for (int j = 0; val != 1; ++j) {
      long long g = gcd(vi[j], val);
      vi[j] /= g;
      val /= g;
    }
    long long res = 1;
    for (int j = 0; j < vi.size(); ++j) {
      res *= vi[j];
      res %= p;
    }
    C[i] = (int)res;
  }
}
void eval_dp(long long p) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= 5000; ++i) {
    for (int j = 1; j <= i; ++j) {
      dp[j][i] = (int)(((long long)dp[j - 1][i - 1] * (long long)j +
                        (long long)dp[j][i - 1] * (long long)(j - 1)) %
                       p);
    }
  }
}
void run() {
  int n, m, p;
  std::cin >> n >> m >> p;
  eval_c(m, p);
  eval_dp(p);
  vector<long long> vi1, vi2;
  vi1.push_back(1);
  for (int i = 0; i < n; ++i) {
    int len;
    scanf("%d", &len);
    long long total = accumulate(vi1.begin(), vi1.end(), 0LL) % p;
    for (int j = 0; j <= len; ++j) {
      long long cc1 = C[j];
      long long cc2 = dp[j][len];
      long long prev = (j < vi1.size()) ? vi1[j] : 0;
      vi2.push_back((((cc1 * cc2) % p) * total) % p);
      vi2[j] = (p - ((cc2 * prev) % p) + vi2[j]) % p;
    }
    vi1.swap(vi2);
    vi2.resize(0);
  }
  std::cout << (accumulate(vi1.begin(), vi1.end(), 0LL) % p) << std::endl;
}
int main() {
  run();
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading.

Input

The input is given in the following format:

n
h1
h2
::
hn

The number of students n (1 ≤ n ≤ 40) is given to the first line, and the real number hi (150.0 ≤ hi ≤ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. ..

Output

Display the frequency distribution in the following format.

Line 1 Heading "1:" followed by * for people less than 165.0 cm *
2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm *
3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm *
4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm *
Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm *
Line 6 Heading "6:" followed by * for people over 185.0 cm *

Examples

Input

4
180.3
168.2
165.5
175.3

Output

1:
2:**
3:
4:*
5:*
6:

Input

21
179.4
171.5
156.6
173.0
169.4
181.2
172.4
170.0
163.6
165.9
173.5
168.2
162.5
172.0
175.1
172.3
167.5
175.9
186.2
168.0
178.6

Output

1:***
2:*****
3:*******
4:****
5:*
6:*

### Response

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

int main()
{
  int n;
  cin>>n;
  int c[6];
  memset(c,0,sizeof(c));
  for(;n--;)
    {
      double t;
      cin>>t;
      int i=0;
      for(double l=185.0;l>164.9;l-=5.0,i++)
	{
	  if(l<=t)
	    {
	      c[i]++;
	      i=-1;
	      break;
	    }
	}
      if(i!=-1)
	c[5]++;
    }
  for(int i=5;i>=0;i--)
    {
      cout<<6-i<<":";
      for(;c[i]--;)
	cout<<"*";
      cout<<endl;
    }

}
```


### Prompt

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

It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.

There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.

The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.

Input

The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.

The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.

The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.

Output

If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.

Examples

Input

5
2 4 5 4 10
40 30 20 10 40

Output

90

Input

3
100 101 100
2 4 5

Output

-1

Input

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

Output

33

Note

In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.

In the second example you can't select a valid triple of indices, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int compare(string S, string y) {
  if (S.size() != y.size())
    return 0;
  else {
    int i;
    for (i = 0; i < S.size(); i++) {
      if (S[i] != y[i]) return 0;
    }
  }
  return 1;
}
int main() {
  long int temp = INT_MAX;
  long int min = INT_MAX;
  long int n;
  cin >> n;
  long int A[n];
  long int B[n];
  int i, j, k;
  for (i = 0; i < n; i++) cin >> A[i];
  for (i = 0; i < n; i++) cin >> B[i];
  long long int ans[n];
  int flag = 0;
  for (i = 1; i < n; i++) {
    ans[i] = B[i];
    temp = INT_MAX;
    for (j = 0; j < i; j++) {
      if (B[j] < temp && A[j] < A[i]) {
        temp = B[j];
        flag = 1;
      }
    }
    ans[i] = ans[i] + temp;
  }
  if (flag == 0) {
    cout << "-1\n";
    return 0;
  }
  flag = 0;
  for (i = 1; i < n - 1; i++) {
    temp = INT_MAX;
    for (j = i + 1; j < n; j++) {
      if (B[j] < temp && A[j] > A[i]) {
        flag = 1;
        temp = B[j];
      }
    }
    ans[i] = ans[i] + temp;
    if (ans[i] < min) min = ans[i];
  }
  if (flag == 0) {
    cout << "-1\n";
    return 0;
  }
  cout << min << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has a Poke Balls and b Ultra Balls. There are n Pokemons. They are numbered 1 through n. Gosha knows that if he throws a Poke Ball at the i-th Pokemon he catches it with probability pi. If he throws an Ultra Ball at the i-th Pokemon he catches it with probability ui. He can throw at most one Ball of each type at any Pokemon.

The hunting proceeds as follows: at first, Gosha chooses no more than a Pokemons at which he will throw Poke Balls and no more than b Pokemons at which he will throw Ultra Balls. After that, he throws the chosen Balls at the chosen Pokemons. If he throws both Ultra Ball and Poke Ball at some Pokemon, he is caught if and only if he is caught by any of these Balls. The outcome of a throw doesn't depend on the other throws.

Gosha would like to know what is the expected number of the Pokemons he catches if he acts in an optimal way. In other words, he would like to know the maximum possible expected number of Pokemons can catch.

Input

The first line contains three integers n, a and b (2 ≤ n ≤ 2000, 0 ≤ a, b ≤ n) — the number of Pokemons, the number of Poke Balls and the number of Ultra Balls.

The second line contains n real values p1, p2, ..., pn (0 ≤ pi ≤ 1), where pi is the probability of catching the i-th Pokemon if Gosha throws a Poke Ball to it.

The third line contains n real values u1, u2, ..., un (0 ≤ ui ≤ 1), where ui is the probability of catching the i-th Pokemon if Gosha throws an Ultra Ball to it.

All the probabilities are given with exactly three digits after the decimal separator.

Output

Print the maximum possible expected number of Pokemons Gosha can catch. The answer is considered correct if it's absolute or relative error doesn't exceed 10 - 4.

Examples

Input

3 2 2
1.000 0.000 0.500
0.000 1.000 0.500

Output

2.75

Input

4 1 3
0.100 0.500 0.500 0.600
0.100 0.500 0.900 0.400

Output

2.16

Input

3 2 0
0.412 0.198 0.599
0.612 0.987 0.443

Output

1.011

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2048;
float d[N][N];
double A[N];
double B[N];
int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  for (int i = 0; (i) < (n); ++i) scanf("%lf", &A[i]);
  for (int i = 0; (i) < (n); ++i) scanf("%lf", &B[i]);
  for (int i = 0; (i) < (n); ++i) {
    float aa = A[i];
    float bb = B[i];
    float cc = A[i] + B[i] - A[i] * B[i];
    int mxa = min(a, i);
    int mxb = min(b, i);
    int mna = max(0, a - n + i);
    int mnb = max(0, b - n + i);
    for (int j = mxa; j >= mna; --j)
      for (int k = mxb; k >= mnb; --k) {
        d[j + 1][k] = max(d[j + 1][k], d[j][k] + aa);
        d[j][k + 1] = max(d[j][k + 1], d[j][k] + bb);
        d[j + 1][k + 1] = max(d[j + 1][k + 1], d[j][k] + cc);
      }
  }
  printf("%.10f\n", (double)d[a][b]);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Polycarp often uses his smartphone. He has already installed n applications on it. Application with number i takes up a_i units of memory.

Polycarp wants to free at least m units of memory (by removing some applications).

Of course, some applications are more important to Polycarp than others. He came up with the following scoring system — he assigned an integer b_i to each application:

  * b_i = 1 — regular application;
  * b_i = 2 — important application.

According to this rating system, his phone has b_1 + b_2 + … + b_n convenience points.

Polycarp believes that if he removes applications with numbers i_1, i_2, …, i_k, then he will free a_{i_1} + a_{i_2} + … + a_{i_k} units of memory and lose b_{i_1} + b_{i_2} + … + b_{i_k} convenience points.

For example, if n=5, m=7, a=[5, 3, 2, 1, 4], b=[2, 1, 1, 2, 1], then Polycarp can uninstall the following application sets (not all options are listed below):

  * applications with numbers 1, 4 and 5. In this case, it will free a_1+a_4+a_5=10 units of memory and lose b_1+b_4+b_5=5 convenience points;
  * applications with numbers 1 and 3. In this case, it will free a_1+a_3=7 units of memory and lose b_1+b_3=3 convenience points.
  * applications with numbers 2 and 5. In this case, it will free a_2+a_5=7 memory units and lose b_2+b_5=2 convenience points.

Help Polycarp, choose a set of applications, such that if removing them will free at least m units of memory and lose the minimum number of convenience points, or indicate that such a set does not exist.

Input

The first line contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow.

The first line of each test case contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 10^9) — the number of applications on Polycarp's phone and the number of memory units to be freed.

The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the number of memory units used by applications.

The third line of each test case contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 2) — the convenience points of each application.

It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case, output on a separate line:

  * -1, if there is no set of applications, removing which will free at least m units of memory;
  * the minimum number of convenience points that Polycarp will lose if such a set exists.

Example

Input

5
5 7
5 3 2 1 4
2 1 1 2 1
1 3
2
1
5 10
2 3 2 3 2
1 2 1 2 1
4 10
5 1 3 4
1 2 1 2
4 5
3 2 1 2
2 1 2 1

Output

2
-1
6
4
3

Note

In the first test case, it is optimal to remove applications with numbers 2 and 5, freeing 7 units of memory. b_2+b_5=2.

In the second test case, by removing the only application, Polycarp will be able to clear only 2 of memory units out of the 3 needed.

In the third test case, it is optimal to remove applications with numbers 1, 2, 3 and 4, freeing 10 units of memory. b_1+b_2+b_3+b_4=6.

In the fourth test case, it is optimal to remove applications with numbers 1, 3 and 4, freeing 12 units of memory. b_1+b_3+b_4=4.

In the fifth test case, it is optimal to remove applications with numbers 1 and 2, freeing 5 units of memory. b_1+b_2=3.

### Response

```cpp
//
//  main.cpp
//
//
//  Created by ji luyang on 2020/12/22.
//

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <time.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int t;
int n, m;
int a[200010], b[200010];
int main() {
    cin >> t;
    while (t--) {
        cin >> n >> m;
        vector<int> v1, v2;
        long long s1 = 0, s2 = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        for (int i = 0; i < n; i++) {
            scanf("%d", &b[i]);
        }
        for (int i = 0; i < n; i++) {
            if (b[i] == 1) v1.push_back(a[i]), s1 += a[i];
            else v2.push_back(a[i]), s2 += a[i];
        }
        sort(v1.begin(), v1.end(), greater<int>());
        sort(v2.begin(), v2.end(), greater<int>());
        int p2 = v2.size() - 1, p1 = -1, res = INT_MAX;
        if (s1 + s2 < m) {
            printf("-1\n");
            continue;
        }
        long long tmp = s2;
        while (p2 >= -1) {
            while (tmp < m) {
                p1++;
                if (p1 == v1.size()) break;
                tmp += v1[p1];
            }
            if (p1 == v1.size()) break;
            res = min(res, p1 + 1 + 2 * (p2 + 1));
            if (p2 == -1) break;
            tmp -= v2[p2];
            p2--;
        }
        printf("%d\n", res);
    }
    return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

There are n cities in Cyberland, numbered from 1 to n, connected by m bidirectional roads. The j-th road connects city aj and bj.

For tourists, souvenirs are sold in every city of Cyberland. In particular, city i sell it at a price of wi.

Now there are q queries for you to handle. There are two types of queries:

  * "C a w": The price in city a is changed to w.
  * "A a b": Now a tourist will travel from city a to b. He will choose a route, he also doesn't want to visit a city twice. He will buy souvenirs at the city where the souvenirs are the cheapest (possibly exactly at city a or b). You should output the minimum possible price that he can buy the souvenirs during his travel.

More formally, we can define routes as follow:

  * A route is a sequence of cities [x1, x2, ..., xk], where k is a certain positive integer.
  * For any 1 ≤ i < j ≤ k, xi ≠ xj.
  * For any 1 ≤ i < k, there is a road connecting xi and xi + 1.
  * The minimum price of the route is min(wx1, wx2, ..., wxk).
  * The required answer is the minimum value of the minimum prices of all valid routes from a to b.

Input

The first line of input contains three integers n, m, q (1 ≤ n, m, q ≤ 105), separated by a single space.

Next n lines contain integers wi (1 ≤ wi ≤ 109).

Next m lines contain pairs of space-separated integers aj and bj (1 ≤ aj, bj ≤ n, aj ≠ bj).

It is guaranteed that there is at most one road connecting the same pair of cities. There is always at least one valid route between any two cities.

Next q lines each describe a query. The format is "C a w" or "A a b" (1 ≤ a, b ≤ n, 1 ≤ w ≤ 109).

Output

For each query of type "A", output the corresponding answer.

Examples

Input

3 3 3
1
2
3
1 2
2 3
1 3
A 2 3
C 1 5
A 2 3

Output

1
2

Input

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

Output

2
1
5
3

Note

For the second sample, an optimal routes are:

From 2 to 3 it is [2, 3].

From 6 to 4 it is [6, 5, 1, 2, 4].

From 6 to 7 it is [6, 5, 7].

From 3 to 3 it is [3].

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005;
inline int read() {
  char c;
  int rec = 0;
  while ((c = getchar()) < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9') rec = rec * 10 + c - '0', c = getchar();
  return rec;
}
int n, m, Q, val[Maxn];
struct Graph {
  struct Branch {
    int next, to;
  } branch[Maxn << 1];
  int h[Maxn], cnt;
  inline void add(int x, int y) {
    branch[++cnt].to = y;
    branch[cnt].next = h[x];
    h[x] = cnt;
    return;
  }
} G, T;
int Bcc, dfn[Maxn], low[Maxn], idx, S[Maxn], Top;
void Tarjan(int v) {
  dfn[v] = low[v] = ++idx;
  S[++Top] = v;
  for (int i = G.h[v]; i; i = G.branch[i].next) {
    if (!dfn[G.branch[i].to]) {
      Tarjan(G.branch[i].to);
      low[v] = min(low[v], low[G.branch[i].to]);
      if (low[G.branch[i].to] >= dfn[v]) {
        int p = 0;
        ++Bcc;
        T.add(Bcc, v);
        T.add(v, Bcc);
        while (p != G.branch[i].to) {
          p = S[Top--];
          T.add(Bcc, p);
          T.add(p, Bcc);
        }
      }
    } else
      low[v] = min(low[v], dfn[G.branch[i].to]);
  }
  return;
}
multiset<int> U[Maxn];
int D, Minn[Maxn << 3];
int size[Maxn << 1], deep[Maxn << 1];
int top[Maxn << 1], fa[Maxn << 1], son[Maxn << 1];
int id[Maxn << 1], ind;
void Dfs1(int v) {
  size[v] = 1;
  deep[v] = deep[fa[v]] + 1;
  if (v <= n && fa[v]) U[fa[v] - n].insert(val[v]);
  for (int i = T.h[v]; i; i = T.branch[i].next) {
    if (T.branch[i].to == fa[v]) continue;
    fa[T.branch[i].to] = v;
    Dfs1(T.branch[i].to);
    size[v] += size[T.branch[i].to];
    if (size[son[v]] < size[T.branch[i].to]) son[v] = T.branch[i].to;
  }
  return;
}
void Dfs2(int v, int TOP) {
  top[v] = TOP;
  id[v] = ++ind;
  if (son[v]) Dfs2(son[v], TOP);
  for (int i = T.h[v]; i; i = T.branch[i].next)
    if (T.branch[i].to != fa[v] && T.branch[i].to != son[v])
      Dfs2(T.branch[i].to, T.branch[i].to);
  return;
}
inline int Ask(int L, int R) {
  int rec = 0x3f3f3f3f;
  for (int s = L + D - 1, t = R + D + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
    if (~s & 1) rec = min(rec, Minn[s ^ 1]);
    if (t & 1) rec = min(rec, Minn[t ^ 1]);
  }
  return rec;
}
int main() {
  n = read();
  m = read();
  Q = read();
  for (int i = 1; i <= n; ++i) val[i] = read();
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read();
    G.add(x, y);
    G.add(y, x);
  }
  char ch;
  Bcc = n;
  Tarjan(1);
  Dfs1(1);
  Dfs2(1, 1);
  D = 1;
  while (D <= Bcc) D <<= 1;
  memset(Minn, 0x3f, sizeof(Minn));
  for (int i = 1; i <= n; ++i) Minn[D + id[i]] = val[i];
  for (int i = n + 1; i <= Bcc; ++i) Minn[D + id[i]] = *U[i - n].begin();
  for (int i = D; i; --i) Minn[i] = min(Minn[i << 1], Minn[i << 1 | 1]);
  for (int i = 1; i <= Q; ++i) {
    while ((ch = getchar()) != 'A' && ch != 'C')
      ;
    int x = read(), y = read();
    if (ch == 'A') {
      int Ans = 0x3f3f3f3f;
      while (top[x] != top[y]) {
        if (deep[top[x]] < deep[top[y]]) swap(x, y);
        Ans = min(Ans, Ask(id[top[x]], id[x]));
        x = fa[top[x]];
      }
      if (deep[x] < deep[y]) swap(x, y);
      Ans = min(Ans, Ask(id[y], id[x]));
      if (y > n) Ans = min(Ans, val[fa[y]]);
      cout << Ans << '\n';
    } else {
      int p = fa[x];
      if (p) {
        U[p - n].erase(U[p - n].find(val[x]));
        U[p - n].insert(y);
        int v = id[p] + D;
        Minn[v] = *U[p - n].begin();
        v >>= 1;
        while (v) Minn[v] = min(Minn[v << 1], Minn[v << 1 | 1]), v >>= 1;
      }
      val[x] = y;
      int v = id[x] + D;
      Minn[v] = y;
      v >>= 1;
      while (v) Minn[v] = min(Minn[v << 1], Minn[v << 1 | 1]), v >>= 1;
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Alfred wants to buy a toy moose that costs c dollars. The store doesn’t give change, so he must give the store exactly c dollars, no more and no less. He has n coins. To make c dollars from his coins, he follows the following algorithm: let S be the set of coins being used. S is initially empty. Alfred repeatedly adds to S the highest-valued coin he has such that the total value of the coins in S after adding the coin doesn’t exceed c. If there is no such coin, and the value of the coins in S is still less than c, he gives up and goes home. Note that Alfred never removes a coin from S after adding it.

As a programmer, you might be aware that Alfred’s algorithm can fail even when there is a set of coins with value exactly c. For example, if Alfred has one coin worth $3, one coin worth $4, and two coins worth $5, and the moose costs $12, then Alfred will add both of the $5 coins to S and then give up, since adding any other coin would cause the value of the coins in S to exceed $12. Of course, Alfred could instead combine one $3 coin, one $4 coin, and one $5 coin to reach the total.

Bob tried to convince Alfred that his algorithm was flawed, but Alfred didn’t believe him. Now Bob wants to give Alfred some coins (in addition to those that Alfred already has) such that Alfred’s algorithm fails. Bob can give Alfred any number of coins of any denomination (subject to the constraint that each coin must be worth a positive integer number of dollars). There can be multiple coins of a single denomination. He would like to minimize the total value of the coins he gives Alfred. Please find this minimum value. If there is no solution, print "Greed is good". You can assume that the answer, if it exists, is positive. In other words, Alfred's algorithm will work if Bob doesn't give him any coins.

Input

The first line contains c (1 ≤ c ≤ 200 000) — the price Alfred wants to pay. The second line contains n (1 ≤ n ≤ 200 000) — the number of coins Alfred initially has. Then n lines follow, each containing a single integer x (1 ≤ x ≤ c) representing the value of one of Alfred's coins.

Output

If there is a solution, print the minimum possible total value of the coins in a solution. Otherwise, print "Greed is good" (without quotes).

Examples

Input

12
3
5
3
4

Output

5

Input

50
8
1
2
4
8
16
37
37
37

Output

Greed is good

Note

In the first sample, Bob should give Alfred a single coin worth $5. This creates the situation described in the problem statement.

In the second sample, there is no set of coins that will cause Alfred's algorithm to fail.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, arr[300100], c, big[300100];
int cnt[300100];
vector<pair<int, int> > vec;
bool check(int nw) {
  vector<pair<int, int> > used;
  int x = c, ind = (int)vec.size() - 1;
  while (x > 0) {
    ind = min(ind, big[x]);
    while (ind >= 0 && (vec[ind].first > x || vec[ind].second == 0)) {
      ind--;
    }
    if (nw > x) {
      if (ind < 0) return 1;
      int tmp = min(vec[ind].second, x / vec[ind].first);
      x -= tmp * vec[ind].first;
      used.push_back(make_pair(ind, tmp));
      vec[ind].second -= tmp;
    } else {
      if (ind == -1 || (nw >= vec[ind].first)) {
        x -= nw;
        nw = c + 1;
      } else {
        if (ind < 0) return 1;
        int tmp = min(vec[ind].second, x / vec[ind].first);
        x -= tmp * vec[ind].first;
        used.push_back(make_pair(ind, tmp));
        vec[ind].second -= tmp;
      }
    }
  }
  for (int i = 0; i < used.size(); i++) {
    vec[used[i].first].second += used[i].second;
  }
  return 0;
}
int main() {
  scanf("%d\n%d", &c, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    cnt[arr[i]]++;
  }
  for (int i = 0; i < c + 1; i++) {
    if (cnt[i]) vec.push_back(make_pair(i, cnt[i]));
    big[i] = (int)vec.size() - 1;
  }
  for (int i = 1; i < c; i++) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "Greed is good\n";
  return 0;
}

```


### Prompt

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

Takahashi received otoshidama (New Year's money gifts) from N of his relatives.

You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative.

For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins.

If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?

Constraints

* 2 \leq N \leq 10
* u_i = `JPY` or `BTC`.
* If u_i = `JPY`, x_i is an integer such that 1 \leq x_i \leq 10^8.
* If u_i = `BTC`, x_i is a decimal with 8 decimal digits, such that 0.00000001 \leq x_i \leq 100.00000000.

Input

Input is given from Standard Input in the following format:

N
x_1 u_1
x_2 u_2
:
x_N u_N

Output

If the gifts are worth Y yen in total, print the value Y (not necessarily an integer).

Output will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.

Examples

Input

2
10000 JPY
0.10000000 BTC

Output

48000.0

Input

3
100000000 JPY
100.00000000 BTC
0.00000001 BTC

Output

138000000.0038

### Response

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

int main(){
    int n;cin>>n;double ans=0;
    for(int i=0;i<n;i++){
        double x;string y;cin>>x>>y;
        if(y=="JPY") ans+=x;
        else ans+=x*380000.0;
    }
    cout<<ans<<endl;
}
```


### Prompt

Create a solution in Cpp for the following problem:

Input

The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space.

Output

Output "YES" or "NO".

Examples

Input

2 3

Output

YES

Input

3 2

Output

NO

Input

33 16

Output

YES

Input

26 5

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[25];
void f (int n, int k) {
	int p;
	if (n == 0) return;
	f(n / k, k);
	p = n % k;
	a[p]++;
//	cout << p << ' ';
}
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	f(n, k);
	for (int i = 0; i <= 16; i++) {
		if (a[i] >= 2) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
}
```


### Prompt

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

One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.

<image>

Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads S is regular if it can be represented as S = A + B + A + B + A + ... + A + B + A, where A and B are some bead sequences, " + " is the concatenation of sequences, there are exactly 2k + 1 summands in this sum, among which there are k + 1 "A" summands and k "B" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if A or B is an empty sequence.

Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order.

Input

The first line contains two integers n, k (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and number k from the definition of the regular sequence above.

The second line contains the sequence of n lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.

Output

Print a string consisting of n zeroes and ones. Position i (1 ≤ i ≤ n) must contain either number one if the first i beads on the thread form a regular sequence, or a zero otherwise.

Examples

Input

7 2
bcabcab

Output

0000011

Input

21 2
ababaababaababaababaa

Output

000110000111111000011

Note

In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take A = "", B = "bca"), and a sequence of the first 7 beads (we can take A = "b", B = "ca").

In the second sample test, for example, a sequence of the first 13 beads is regular, if we take A = "aba", B = "ba".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct fastIO {
  inline fastIO operator>>(int& num) {
    num = 0;
    char c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    bool foo = 0;
    if (c == '-') {
      foo = 1;
      c = getchar();
    }
    while (c >= '0' && c <= '9') {
      num = (num << 3) + (num << 1) + c - '0';
      c = getchar();
    }
    if (foo) num = -num;
    return *this;
  }
  inline fastIO operator>>(long long& num) {
    num = 0;
    char c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    bool foo = 0;
    if (c == '-') {
      foo = 1;
      c = getchar();
    }
    while (c >= '0' && c <= '9') {
      num = (num << 3) + (num << 1) + c - '0';
      c = getchar();
    }
    if (foo) num = -num;
    return *this;
  }
  inline fastIO operator>>(float& num) {
    scanf("%f", &num);
    return *this;
  }
  inline fastIO operator>>(double& num) {
    scanf("%lf", &num);
    return *this;
  }
  inline fastIO operator>>(long double& num) {
    scanf("%Lf", &num);
    return *this;
  }
  inline fastIO operator>>(char& num) {
    num = getchar();
    while (num == ' ' || num == '\n') num = getchar();
    return *this;
  }
  inline fastIO operator>>(char* num) {
    int cnt = 0;
    char c = getchar();
    while (c == ' ' || c == '\n') c = getchar();
    while (c != ' ' && c != '\n') {
      num[cnt++] = c;
      c = getchar();
    }
    num[cnt] = 0;
    return *this;
  }
  inline fastIO operator>>(string& num) {
    cin >> num;
    return *this;
  }
  inline void printInt(const int& num) {
    if (num < 10) {
      putchar(num + '0');
      return;
    }
    printInt(num / 10);
    putchar((num % 10) + '0');
  }
  inline void printINT(const long long& num) {
    if (num < 10) {
      putchar(num + '0');
      return;
    }
    printINT(num / 10);
    putchar((num % 10) + '0');
  }
  inline fastIO operator<<(const int& num) {
    if (num < 0)
      putchar('-'), printInt(-num);
    else
      printInt(num);
    return *this;
  }
  inline fastIO operator<<(const long long& num) {
    if (num < 0)
      putchar('-'), printINT(-num);
    else
      printINT(num);
    return *this;
  }
  inline fastIO operator<<(const float& num) {
    printf("%.10f", num);
    return *this;
  }
  inline fastIO operator<<(const double& num) {
    printf("%.16lf", num);
    return *this;
  }
  inline fastIO operator<<(const long double& num) {
    printf("%.20Lf", num);
    return *this;
  }
  inline fastIO operator<<(const char& num) {
    putchar(num);
    return *this;
  }
  inline fastIO operator<<(const char* num) {
    for (int i = 0; num[i]; i++) putchar(num[i]);
    return *this;
  }
  inline fastIO operator<<(const string& num) {
    cout << num;
    return *this;
  }
} fio;
int n, k;
char s[1000005];
int z[1000005];
char ans[1000005];
int qzh[1000005];
void calcz() {
  int l = 0, r = 0;
  for (int i = 1; i < n; i++) {
    if (i <= r) {
      z[i] = min(r - i, z[i - l]);
    }
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
      z[i]++;
    }
    if (i + z[i] > r) {
      l = i;
      r = i + z[i];
    }
  }
}
int main() {
  fio >> n >> k >> s;
  calcz();
  ans[n] = 0;
  if (k == 1) {
    memset((void*)ans, '1', sizeof(ans));
    ans[n] = 0;
    fio << ans << '\n';
    return 0;
  }
  for (int i = 1; i * k <= n; i++) {
    if (z[i] < i * (k - 1)) {
      continue;
    }
    qzh[i * k]++;
    qzh[min(i + z[i], i * (k + 1)) + 1]--;
  }
  int he = 0;
  for (int i = 1; i <= n; i++) {
    he += qzh[i];
    ans[i - 1] = '0' + (he > 0);
  }
  fio << ans << '\n';
  return 0;
}

```


### Prompt

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

Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.

More specifically, in one move, he can go from coordinate x to x + D or x - D.

He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.

Find the minimum possible absolute value of the coordinate of the destination.

Constraints

* -10^{15} \leq X \leq 10^{15}
* 1 \leq K \leq 10^{15}
* 1 \leq D \leq 10^{15}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

X K D

Output

Print the minimum possible absolute value of the coordinate of the destination.

Examples

Input

6 2 4

Output

2

Input

7 4 3

Output

1

Input

10 1 2

Output

8

Input

1000000000000000 1000000000000000 1000000000000000

Output

1000000000000000

### Response

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

int main()
{
	ll x,k,d;
	cin >> x >> k >> d;
	x = abs(x);
	ll t= 0;
	t = min(x/d,k);
	x -= t*d;
	k -= t;
	if(k==0)
	{
		cout<<x<<endl;
		return 0;
	}
	k%=2;
	if(k)cout<<abs(x-d)<<endl;
	else cout<<x<<endl;
}

```


### Prompt

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

There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step.

You're given the initial arrangement of the psychos in the line. Calculate how many steps are needed to the moment of time such, that nobody kills his neighbor after that moment. Look notes to understand the statement more precise.

Input

The first line of input contains integer n denoting the number of psychos, (1 ≤ n ≤ 105). In the second line there will be a list of n space separated distinct integers each in range 1 to n, inclusive — ids of the psychos in the line from left to right.

Output

Print the number of steps, so that the line remains the same afterward.

Examples

Input

10
10 9 7 8 6 5 3 4 2 1

Output

2

Input

6
1 2 3 4 5 6

Output

0

Note

In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1]  →  [10 8 4] →  [10]. So, there are two steps.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int inf = 0x3f3f3f3f;
int arr[maxn];
int ans[maxn];
stack<int> s;
int main() {
  int n;
  scanf("%d", &n);
  memset(ans, 0, sizeof ans);
  for (int i = 1; i <= n; ++i) scanf("%d", &arr[i]);
  for (int i = n; i >= 1; --i) {
    if (s.empty()) {
      s.push(i);
      ans[i] = 0;
      continue;
    }
    if (arr[s.top()] > arr[i]) {
      ans[i] = 0;
      s.push(i);
    } else {
      ans[i] = max(1, ans[s.top()]);
      s.pop();
      while (s.size() && arr[i] > arr[s.top()]) {
        ans[i] = max(ans[i] + 1, ans[s.top()]);
        s.pop();
      }
      s.push(i);
    }
  }
  int val = 0;
  for (int i = 1; i <= n; ++i) {
    val = max(val, ans[i]);
  }
  printf("%d\n", val);
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Friday is Polycarpus' favourite day of the week. Not because it is followed by the weekend, but because the lessons on Friday are 2 IT lessons, 2 math lessons and 2 literature lessons. Of course, Polycarpus has prepared to all of them, unlike his buddy Innocentius. Innocentius spent all evening playing his favourite game Fur2 and didn't have enough time to do the literature task. As Innocentius didn't want to get an F, he decided to do the task and read the book called "Storm and Calm" during the IT and Math lessons (he never used to have problems with these subjects). When the IT teacher Mr. Watkins saw this, he decided to give Innocentius another task so that the boy concentrated more on the lesson and less — on the staff that has nothing to do with IT.

Mr. Watkins said that a palindrome is a string that can be read the same way in either direction, from the left to the right and from the right to the left. A concatenation of strings a, b is a string ab that results from consecutive adding of string b to string a. Of course, Innocentius knew it all but the task was much harder than he could have imagined. Mr. Watkins asked change in the "Storm and Calm" the minimum number of characters so that the text of the book would also be a concatenation of no more than k palindromes. Innocentius can't complete the task and therefore asks you to help him.

Input

The first input line contains a non-empty string s which is the text of "Storm and Calm" (without spaces). The length of the string s does not exceed 500 characters. String s consists of uppercase and lowercase Latin letters. The second line contains a single number k (1 ≤ k ≤ |s|, where |s| represents the length of the string s).

Output

Print on the first line the minimum number of changes that Innocentius will have to make. Print on the second line the string consisting of no more than k palindromes. Each palindrome should be non-empty and consist of uppercase and lowercase Latin letters. Use the character "+" (ASCII-code 43) to separate consecutive palindromes. If there exist several solutions, print any of them.

The letters' case does matter, that is an uppercase letter is not considered equivalent to the corresponding lowercase letter.

Examples

Input

abacaba
1

Output

0
abacaba

Input

abdcaba
2

Output

1
abdcdba

Input

abdcaba
5

Output

0
a+b+d+c+aba

Input

abacababababbcbabcd
3

Output

1
abacaba+babab+bcbabcb

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char str[505];
int cnt, len;
int Pmat[505][505];
void relax(int l, int r) {
  int tmp = 0;
  while (l >= 0 && r < len) {
    if (str[l] != str[r]) {
      tmp++;
    }
    Pmat[l][r] = tmp;
    l--, r++;
  }
}
const int inf = 505;
int memo[inf][inf];
int solve(int st, int ed, int rem) {
  if (ed >= len - 1) return 0;
  if (rem <= 0) return inf;
  int &ret = memo[ed][rem];
  if (ret != -1) return ret;
  ret = inf;
  for (int i = ed + 1; i < len; i++) {
    ret = min(ret, solve(ed + 1, i, rem - 1) + Pmat[ed + 1][i]);
  }
  return ret;
}
string res = "";
void Build(int st, int ed, int rem) {
  string s = "";
  for (int k = st; k <= ed; k++) {
    s += str[k];
  }
  for (int i = 0; i < s.size(); i++)
    if (s[i] != s[s.size() - i - 1]) s[i] = s[s.size() - 1 - i];
  res += s + "+";
  for (int i = ed + 1; i < len; i++) {
    if (solve(ed + 1, i, rem - 1) + Pmat[ed + 1][i] == solve(st, ed, rem)) {
      Build(ed + 1, i, rem - 1);
      return;
    }
  }
}
int main() {
  scanf("%s", str);
  scanf("%d", &cnt);
  len = strlen(str);
  for (int pos = 0; pos < len; pos++) {
    relax(pos, pos);
    relax(pos - 1, pos);
    relax(pos, pos + 1);
  }
  memset(memo, -1, sizeof memo);
  int ans = inf;
  cnt--;
  for (int i = 0; i < len; i++) {
    ans = min(ans, solve(0, i, cnt) + Pmat[0][i]);
  }
  for (int i = 0; i < len; i++) {
    if (ans == solve(0, i, cnt) + Pmat[0][i]) {
      Build(0, i, cnt);
      break;
    }
  }
  cout << ans << endl;
  res.erase(res.begin() + res.size() - 1);
  cout << res << endl;
}

```


### Prompt

Create a solution in CPP for the following problem:

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task.

Input

The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number.

Output

Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1.

Examples

Input

11

Output

47

Input

10

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x = (2 * n) % 7, y = (n - 4 * x) / 7;
  if (y < 0) {
    cout << "-1";
    return 0;
  }
  while (1) {
    if (x > 0) {
      cout << "4";
      x--;
    } else if (y > 0) {
      cout << "7";
      y--;
    } else
      break;
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."

Could you pass the interview in the machine vision company in IT City?

Input

The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5.

Output

Output the last two digits of 5n without spaces between them.

Examples

Input

2

Output

25

### Response

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

```


### Prompt

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

Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that

  * s(a) ≥ n,
  * s(b) ≥ n,
  * s(a + b) ≤ m.

Input

The only line of input contain two integers n and m (1 ≤ n, m ≤ 1129).

Output

Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230.

Examples

Input

6 5

Output

6
7

Input

8 16

Output

35
53

Note

In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 ≥ n and s(b) = 7 ≥ n, and also s(a + b) = s(13) = 4 ≤ m.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
long long int power(long long int a, long long int b, long long int m) {
  if (b == 0) return 1;
  if (b == 1) return a % m;
  long long int t = power(a, b / 2, m) % m;
  t = (t * t) % m;
  if (b & 1) t = ((t % m) * (a % m)) % m;
  return t;
}
long long int modInverse(long long int a, long long int m) {
  return power(a, m - 2, m);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, l, n, m;
  cin >> n >> m;
  for (i = 1; i <= 200; i++) {
    cout << "8";
  }
  for (i = 1; i <= 200; i++) {
    cout << "0";
  }
  cout << "9"
       << "\n";
  for (i = 1; i <= 200; i++) {
    cout << "1";
  }
  for (i = 1; i <= 200; i++) {
    cout << "9";
  }
  cout << "1"
       << "\n";
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.

You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.

We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 ≤  p1 < p2 < ... < pk ≤  |s|) a subsequence of string s = s1s2... s|s|, where |s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".

String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| > |y| and x1 = y1, x2 = y2, ..., x|y| = y|y|, or there exists such number r (r < |x|, r < |y|) that x1 = y1, x2 = y2, ..., xr = yr and xr + 1 > yr + 1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".

String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s| - 1... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

Input

The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.

Output

Print the lexicographically largest palindromic subsequence of string s.

Examples

Input

radar

Output

rr

Input

bowwowwow

Output

wwwww

Input

codeforces

Output

s

Input

mississipp

Output

ssss

Note

Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".

### Response

```cpp
#include <bits/stdc++.h>
std::string str, ans, cur;
int len;
std::string mask(std::string str, int m) {
  std::string ret;
  for (int i = 0; i < str.length(); ++i) {
    if (m & (1 << i)) {
      ret += str[i];
    }
  }
  return ret;
}
bool poli(std::string cur) {
  int l = cur.length();
  for (int i = 0; i < l / 2; ++i) {
    if (cur[i] != cur[l - i - 1]) return false;
  }
  return true;
}
bool more(std::string first, std::string second) {
  std::string::iterator f_it = first.begin(), s_it = second.begin();
  for (; f_it != first.end() && s_it != second.end(); ++f_it, ++s_it) {
    if (*f_it != *s_it) return *f_it > *s_it;
  }
  return (f_it != first.end());
}
int main() {
  std::cin >> str;
  for (int m = 1; m < (1 << str.length()); ++m) {
    cur = mask(str, m);
    if (poli(cur) && more(cur, ans)) {
      ans = cur;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

```