### Prompt

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

People like to be fit. That's why many of them are ready to wake up at dawn, go to the stadium and run. In this problem your task is to help a company design a new stadium.

The city of N has a shabby old stadium. Many people like it and every morning thousands of people come out to this stadium to run. The stadium can be represented as a circle, its length is exactly l meters with a marked start line. However, there can't be simultaneous start in the morning, so exactly at 7, each runner goes to his favorite spot on the stadium and starts running from there. Note that not everybody runs in the same manner as everybody else. Some people run in the clockwise direction, some of them run in the counter-clockwise direction. It mostly depends on the runner's mood in the morning, so you can assume that each running direction is equiprobable for each runner in any fixed morning.

The stadium is tiny and is in need of major repair, for right now there only is one running track! You can't get too playful on a single track, that's why all runners keep the same running speed — exactly 1 meter per a time unit. Nevertheless, the runners that choose different directions bump into each other as they meet.

The company wants to design a new stadium, but they first need to know how bad the old one is. For that they need the expectation of the number of bumpings by t time units after the running has begun. Help the company count the required expectation. Note that each runner chooses a direction equiprobably, independently from the others and then all runners start running simultaneously at 7 a.m. Assume that each runner runs for t time units without stopping. Consider the runners to bump at a certain moment if at that moment they found themselves at the same point in the stadium. A pair of runners can bump more than once.

Input

The first line of the input contains three integers n, l, t (1 ≤ n ≤ 106, 1 ≤ l ≤ 109, 1 ≤ t ≤ 109). The next line contains n distinct integers a1, a2, ..., an (0 ≤ a1 < a2 < ... < an < l), here ai is the clockwise distance from the start line to the i-th runner's starting position.

Output

Print a single real number — the answer to the problem with absolute or relative error of at most 10 - 6.

Examples

Input

2 5 1
0 2

Output

0.2500000000

Input

3 7 3
0 1 6

Output

1.5000000000

Note

There are two runners in the first example. If the first runner run clockwise direction, then in 1 time unit he will be 1m away from the start line. If the second runner run counter-clockwise direction then in 1 time unit he will be also 1m away from the start line. And it is the only possible way to meet. We assume that each running direction is equiprobable, so the answer for the example is equal to 0.5·0.5 = 0.25.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;
const long long LINF = 1e15;
const int N_ = 2500005;
long long N, L, B;
long long P, Q;
long long D[N_];
double res;
int main() {
  int i, j, k;
  scanf("%I64d%I64d%I64d", &N, &L, &B);
  P = (B * 2) / L;
  Q = (B * 2) % L;
  res += (double)P * (double)N * (double)(N - 1) * 2;
  for (i = 1; i <= N; i++) {
    scanf("%I64d", &D[i]);
  }
  for (i = 1; i <= N; i++) D[i + N] = D[i] + L;
  for (i = 1, k = 2; i <= N; i++) {
    while (k <= 2 * N && D[k] <= D[i] + Q) ++k;
    res += (double)(k - i - 1);
  }
  for (i = 2 * N, k = 2 * N - 1; i > N; i--) {
    while (k > 0 && D[k] >= D[i] - Q) --k;
    res += (double)(i - k - 1);
  }
  if (res >= (1ll << 30)) res += 1;
  printf("%.10lf\n", res / 8.);
  return 0;
}

```


### Prompt

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

A fraction whose numerator is 1 and whose denominator is a positive integer is called a unit fraction. A representation of a positive rational number p/q as the sum of finitely many unit fractions is called a partition of p/q into unit fractions. For example, 1/2 + 1/6 is a partition of 2/3 into unit fractions. The difference in the order of addition is disregarded. For example, we do not distinguish 1/6 + 1/2 from 1/2 + 1/6.

For given four positive integers p, q, a, and n, count the number of partitions of p/q into unit fractions satisfying the following two conditions.

* The partition is the sum of at most n many unit fractions.
* The product of the denominators of the unit fractions in the partition is less than or equal to a.

For example, if (p,q,a,n) = (2,3,120,3), you should report 4 since

2/3 = 1/3 + 1/3 = 1/2 + 1/6 = 1/4 + 1/4 + 1/6 = 1/3 + 1/6 + 1/6

enumerates all of the valid partitions.

Input

The input is a sequence of at most 1000 data sets followed by a terminator.

A data set is a line containing four positive integers p, q, a, and n satisfying p,q <= 800, a <= 12000 and n <= 7. The integers are separated by a space.

The terminator is composed of just one line which contains four zeros separated by a space. It is not a part of the input data but a mark for the end of the input.

Output

The output should be composed of lines each of which contains a single integer. No other characters should appear in the output.

The output integer corresponding to a data set p, q, a, n should be the number of all partitions of p/q into at most n many unit fractions such that the product of the denominators of the unit fractions is less than or equal to a.

Example

Input

2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 3
2 3 12000 7
54 795 12000 7
2 3 300 1
2 1 200 5
2 4 54 2
0 0 0 0

Output

4
7
6
2
42
1
0
9
3

### Response

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

int P,Q,A,N;

int accum(int p,int q,int depth,int dono,int prd){
  if(p==0)return 1;
  int res=0;
  for(int i=dono;prd*i<=A;i++){
    if((N-depth)*q<i*p)break;
    if(p*i<q)continue;
    res+=accum(p*i-q,q*i,depth+1,i,prd*i);
    //cout<<depth<<" "<<res<<endl;
  }
  return res;
}

int main(){
  while(cin>>P>>Q>>A>>N,A) cout<<accum(P,Q,0,1,1)<<endl;
  return 0;
}
```


### Prompt

Generate a cpp solution to the following problem:

Takahashi loves takoyaki - a ball-shaped snack.

With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.

How long does it take to make N takoyaki?

Constraints

* 1 \leq N,X,T \leq 1000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X T

Output

Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.

Examples

Input

20 12 6

Output

12

Input

1000 1 1000

Output

1000000

### Response

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

int main() {
	int n,x,t;
	cin>>n>>x>>t;
	int a=(n+x-1)/x;
	cout<<a*t;
	return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.

The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed 3. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.

Your character has also found an artifact that boosts the damage of some of your actions: every 10-th card you play deals double damage.

What is the maximum possible damage you can deal during n turns?

Input

The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of turns.

Then n blocks of input follow, the i-th block representing the cards you get during the i-th turn.

Each block begins with a line containing one integer k_i (1 ≤ k_i ≤ 2 ⋅ 10^5) — the number of cards you get during i-th turn. Then k_i lines follow, each containing two integers c_j and d_j (1 ≤ c_j ≤ 3, 1 ≤ d_j ≤ 10^9) — the parameters of the corresponding card.

It is guaranteed that ∑ _{i = 1}^{n} k_i ≤ 2 ⋅ 10^5.

Output

Print one integer — the maximum damage you may deal.

Example

Input

5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100

Output

263

Note

In the example test the best course of action is as follows:

During the first turn, play all three cards in any order and deal 18 damage.

During the second turn, play both cards and deal 7 damage.

During the third turn, play the first and the third card and deal 13 damage.

During the fourth turn, play the first and the third card and deal 25 damage.

During the fifth turn, play the only card, which will deal double damage (200).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
mt19937 rng(steady_clock::now().time_since_epoch().count());
const long long mod = 998244353;
long long madd(long long a, long long b) { return (a + b) % mod; }
long long msub(long long a, long long b) {
  return (((a - b) % mod) + mod) % mod;
}
long long mmul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long mpow(long long base, long long exp) {
  long long res = 1;
  while (exp) {
    if (exp % 2 == 1) {
      res = (res * base) % mod;
    }
    exp >>= 1;
    base = (base * base) % mod;
  }
  return res;
}
long long minv(long long base) { return mpow(base, mod - 1); }
long long mdiv(long long a, long long b) { return mmul(a, minv(b)); }
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
bool prime[10000006];
void sieve(int n) {
  for (long long i = 0; i < n + 1; i++) prime[i] = 1;
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  prime[1] = prime[0] = 0;
}
long long n, q, Q, T, m, k, l, r, x, y, z, g;
vector<long long> turns[200002][3];
long long dp[200001][11];
long long a[11];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> k;
    for (long long j = 0; j < k; j++) {
      cin >> x >> y;
      turns[i + 1][--x].push_back(y);
    }
    for (long long j = 0; j < 3; j++) {
      sort(turns[i + 1][j].begin(), turns[i + 1][j].end());
      reverse(turns[i + 1][j].begin(), turns[i + 1][j].end());
    }
  }
  for (long long i = 0; i < n + 1; i++)
    for (long long j = 0; j < 10; j++) dp[i][j] = -1;
  for (long long j = 0; j < 10; j++) dp[0][j] = -1;
  dp[0][0] = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < 10; j++) a[j] = -1;
    for (long long j = 0; j < 10; j++) {
      if (dp[i - 1][j] != -1) {
        a[j] = max(a[j], dp[i - 1][j]);
        if (j + 1 > 9) {
          if (turns[i][0].size())
            a[(j + 1) % 10] =
                max(a[(j + 1) % 10], dp[i - 1][j] + 2 * turns[i][0][0]);
          if (turns[i][1].size())
            a[(j + 1) % 10] =
                max(a[(j + 1) % 10], dp[i - 1][j] + 2 * turns[i][1][0]);
          if (turns[i][2].size())
            a[(j + 1) % 10] =
                max(a[(j + 1) % 10], dp[i - 1][j] + 2 * turns[i][2][0]);
        } else {
          if (turns[i][0].size())
            a[(j + 1) % 10] =
                max(a[(j + 1) % 10], dp[i - 1][j] + turns[i][0][0]);
          if (turns[i][1].size())
            a[(j + 1) % 10] =
                max(a[(j + 1) % 10], dp[i - 1][j] + turns[i][1][0]);
          if (turns[i][2].size())
            a[(j + 1) % 10] =
                max(a[(j + 1) % 10], dp[i - 1][j] + turns[i][2][0]);
        }
        if (j + 2 > 9) {
          if (turns[i][0].size() > 1)
            a[(j + 2) % 10] =
                max(a[(j + 2) % 10],
                    dp[i - 1][j] + 2 * turns[i][0][0] + turns[i][0][1]);
          if (turns[i][0].size() && turns[i][1].size())
            a[(j + 2) % 10] =
                max(a[(j + 2) % 10],
                    dp[i - 1][j] + 2 * max(turns[i][0][0], turns[i][1][0]) +
                        min(turns[i][0][0], turns[i][1][0]));
        } else {
          if (turns[i][0].size() > 1)
            a[(j + 2) % 10] =
                max(a[(j + 2) % 10],
                    dp[i - 1][j] + turns[i][0][0] + turns[i][0][1]);
          if (turns[i][0].size() && turns[i][1].size())
            a[(j + 2) % 10] =
                max(a[(j + 2) % 10],
                    dp[i - 1][j] + turns[i][0][0] + turns[i][1][0]);
        }
        if (j + 3 > 9) {
          if (turns[i][0].size() > 2)
            a[(j + 3) % 10] =
                max(a[(j + 3) % 10], dp[i - 1][j] + 2 * turns[i][0][0] +
                                         turns[i][0][1] + turns[i][0][2]);
        } else {
          if (turns[i][0].size() > 2)
            a[(j + 3) % 10] =
                max(a[(j + 3) % 10], dp[i - 1][j] + turns[i][0][0] +
                                         turns[i][0][1] + turns[i][0][2]);
        }
      }
    }
    for (long long j = 0; j < 10; j++) dp[i][j] = a[j];
  }
  long long ans = 0;
  for (long long i = 0; i < 10; i++) ans = max(dp[n][i], ans);
  cout << ans << endl;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Sonya was unable to think of a story for this problem, so here comes the formal description.

You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array.

Next line contains n integer ai (1 ≤ ai ≤ 109).

Output

Print the minimum number of operation required to make the array strictly increasing.

Examples

Input

7
2 1 5 11 5 9 11

Output

9

Input

5
5 4 3 2 1

Output

12

Note

In the first sample, the array is going to look as follows:

2 3 5 6 7 9 11

|2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9

And for the second sample:

1 2 3 4 5

|5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long d[3333][3333], a[3333], b[3333];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    a[i] -= i;
    b[i] = a[i];
  }
  sort(b + 1, b + 1 + n);
  int bn = unique(b + 1, b + 1 + n) - b - 1;
  memset(d, 127, sizeof(d));
  for (int i = 1; i <= bn; ++i) {
    d[1][i] = min(d[1][i - 1], abs(a[1] - b[i]));
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= bn; ++j) {
      d[i][j] = min(d[i][j - 1], d[i - 1][j] + abs(a[i] - b[j]));
    }
  }
  printf("%I64d", d[n][bn]);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

problem

President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.

Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.

* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.

Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.

input

The input consists of 1 + N lines.

On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.

The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.

output

Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.

Input / output example

Input example 1

4 5
WRWRW
BWRWB
WRWRW
RWBWR

Output example 1

11

Input example 2

6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW

Output example 2

44

In I / O example 1, the old flag is colored as shown in the figure below.

fig01

In the figure below, repaint the 11 squares with an'X'.

fig02

This makes it possible to make the Russian flag as shown in the figure below.

fig03

Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.

In I / O example 2, the old flag is colored as shown in the figure below.

fig04

Creative Commons License

Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"

Example

Input

4 5
WRWRW
BWRWB
WRWRW
RWBWR

Output

11

### Response

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

int count(int sy, int ey, int W, vector< string >& f, char c) {
	int ret = 0;
	for (int y=sy; y<ey; ++y) for (int x=0; x<W; ++x) if (f[y][x] != c) ++ret;
	return ret;
}

int main() {
	int N, M;
	cin >> N >> M;

	vector< string > f(N);
	for (int i=0; i<N; ++i) cin >> f[i];

	int ans = N * M;
	for (int s=1; s<N-1; ++s) for (int t=s+1; t<N; ++t) {
		int w = count(0, s, M, f, 'W');
		int b = count(s, t, M, f, 'B');
		int r = count(t, N, M, f, 'R');
		ans = min(ans, w + b + r);
	}
	cout << ans << endl;
}

```


### Prompt

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

Taro is a member of a programming contest circle. In this circle, the members manage their schedules in the system called Great Web Calender.

Taro has just added some of his friends to his calendar so that he can browse their schedule on his calendar. Then he noticed that the system currently displays all the schedules in only one color, mixing the schedules for all his friends. This is difficult to manage because it's hard to tell whose schedule each entry is.

But actually this calender system has the feature to change the color of schedule entries, based on the person who has the entries. So Taro wants to use that feature to distinguish their plans by color.

Given the colors Taro can use and the number of members, your task is to calculate the subset of colors to color all schedule entries. The colors are given by "Lab color space".

In Lab color space, the distance between two colors is defined by the square sum of the difference of each element. Taro has to pick up the subset of colors that maximizes the sum of distances of all color pairs in the set.

Input

The input is like the following style.

N M
L_{0} a_{0} b_{0}
L_{1} a_{1} b_{1}
...
L_{N-1} a_{N-1} b_{N-1}

The first line contains two integers N and M (0 \leq M \leq N \leq 20), where N is the number of colors in the input, and M is the number of friends Taro wants to select the colors for. Each of the following N lines contains three decimal integers L(0.0 \leq L \leq 100.0), a(-134.0 \leq a \leq 220.0) and b(-140.0 \leq b \leq 122.0) which represents a single color in Lab color space.

Output

Output the maximal of the total distance. The output should not contain an error greater than 10^{-5}.

Examples

Input

3 2
0 0 0
10 10 10
100 100 100

Output

30000.00000000000000000000

Input

5 3
12.0 15.0 9.0
10.0 -3.0 2.2
3.5 6.8 9.0
2.1 4.4 5.9
1.2 4.0 -5.4

Output

1003.44000000000005456968

Input

2 1
1.0 1.0 1.0
0.0 0.0 0.0

Output

0.00000000000000000000

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int n, m;
double l[20], a[20], b[20];

vector<int> use;

// idx以降でk個選ぶときの最大値
double dfs(int idx, int k){
    double res = 0;
    if (k == 0){
        for (int i = 0; i < use.size(); i++)
        {
            for (int j = 0; j < i; j++)
            {
                double dl = l[use[i]] - l[use[j]];
                double da = a[use[i]] - a[use[j]];
                double db = b[use[i]] - b[use[j]];
                res += dl*dl + da*da + db*db;
            }
        }
    }
    else
    {
        for (int i = idx; i < n - k + 1; i++)
        {
            use.push_back(i);
            res = max(res, dfs(i+1, k - 1));
            use.pop_back();
        }
    }
    return res;
}

int main(){
    while (cin >> n >> m && n | m)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> l[i] >> a[i] >> b[i];
        }
        cout << fixed << setprecision(20) << dfs(0, m) << endl;
    }
}
```


### Prompt

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

At Akabe High School, which is a programmer training school, the roles of competition programmers in team battles are divided into the following three types.
C: | Coder | I am familiar with the language and code.
--- | --- | ---
A: | Algorithm | I am good at logical thinking and think about algorithms.
N: | Navigator | Good at reading comprehension, analyze and debug problems.

At this high school, a team of three people is formed in one of the following formations.

CCA: | Well-balanced and stable
--- | ---
CCC: | Fast-paced type with high risk but expected speed
CAN: | Careful solving of problems accurately

As a coach of the Competitive Programming Department, you take care every year to combine these members and form as many teams as possible. Therefore, create a program that outputs the maximum number of teams that can be created when the number of coders, the number of algorithms, and the number of navigators are given as inputs.

input

The input consists of one dataset. Input data is given in the following format.

Q
c1 a1 n1
c2 a2 n2
::
cQ aQ nQ

Q (0 ≤ Q ≤ 100) on the first line is the number of years for which you want to find the number of teams. The number of people by role in each year is given to the following Q line. Each row is given the number of coders ci (0 ≤ ci ≤ 1000), the number of algorithms ai (0 ≤ ai ≤ 1000), and the number of navigators ni (0 ≤ ni ≤ 1000).

output

Output the maximum number of teams that can be created on one line for each year.

Example

Input

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

Output

1
1
4
0

### Response

```cpp
#include <stdio.h>

int min(int a, int b) {
  return a < b ? a : b;
}

int main(void) {
  int i, j, k, q, c, a, n;
  scanf("%d", &q);
  for(i = 0; i < q; ++i) {
    int ans = 0, t;
    scanf("%d%d%d", &c, &a, &n);
    ans = min(c, min(a, n));
    c -= ans, a -= ans, n -= ans;
    ans += min(c / 2, a);
    t = min(c / 2, a);
    c -= 2 * t, a -= t;
    ans += c / 3;
    printf("%d\n", ans);
  }
  return 0;
}

```


### Prompt

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

Taro is planning a long trip by train during the summer vacation. However, in order for Taro, who is a high school student, to travel as far as possible during the summer vacation, which has only one month, he cannot make a good plan unless he finds the cheapest and the fastest way. Let's create a program to help Taro's plan so that he can enjoy a wonderful trip.

<image>

Create a program that outputs the minimum amount or the shortest time in response to inquiries by inputting track information and the number of stations.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:

n m
a1 b1 cost1 time1
a2 b2 cost2 time2
::
an bn costn timen
k
p1 q1 r1
p2 q2 r2
::
pk qk rk

The first line gives the number of track information n (1 ≤ n ≤ 3000) and the number of stations m (1 ≤ m ≤ 100).

The following n lines give information on the i-th line. As information on each line, the numbers ai, bi (1 ≤ ai, bi ≤ m) of the two stations connecting the lines, the toll costi (1 ≤ costi ≤ 1000), and the travel time timei (1 ≤ timei ≤ 1000) are given. I will. However, each station shall be numbered in order from 1 to m. If ai and bi are connected by railroad tracks, both ai to bi and bi to ai can be moved at the same rate and time.

The following line is given the number of queries k (1 ≤ k ≤ 200). The next k line is given the i-th query. For each query, the departure station pi, the arrival station qi, and the type of value to output ri (0 or 1) are given. Inquiries must have a route.

The number of datasets does not exceed 50.

Output

Outputs the minimum amount or minimum time on one line for each data set. When ri is 0, the minimum amount is output, and when ri is 1, the minimum time is output.

Example

Input

6 5
1 2 200 10
1 4 400 15
1 3 250 25
2 4 100 10
4 5 150 20
3 5 300 20
2
1 5 0
1 5 1
0 0

Output

450
35

### Response

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

const int inf = 1<<20;
int Cost[100][100];
int Time[100][100];

int main()
{
	int n,m,k,a,b,c,t;
	while(cin >> n >> m, (n||m))
	{
		for(int i=0; i<m; i++)
		for(int j=0; j<m; j++)
		{
			Cost[i][j] = Time[i][j] = (i==j?0:inf);
		}

		while(n--)
		{
			cin >> a >> b >> c >> t;
			a--; b--;
			Cost[a][b] = Cost[b][a] = c;
			Time[a][b] = Time[b][a] = t;
		}

		for(int l=0; l<m; l++)
		for(int i=0; i<m; i++)
		for(int j=0; j<m; j++)
		{
			if(Time[i][j]>Time[i][l]+Time[l][j]) Time[i][j] = Time[i][l]+Time[l][j];
			if(Cost[i][j]>Cost[i][l]+Cost[l][j]) Cost[i][j] = Cost[i][l]+Cost[l][j];
		}

		cin >> k;
		while(k--)
		{
			cin >> a >> b >> t;
			a--; b--;
			if(t==0){ cout << Cost[a][b] << endl; }
			if(t==1){ cout << Time[a][b] << endl; }
		}
	}
}
```


### Prompt

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

Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.

Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

Input

The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.

Output

Print the maximum possible even sum that can be obtained if we use some of the given integers.

Examples

Input

3
1 2 3

Output

6

Input

5
999999999 999999999 999999999 999999999 999999999

Output

3999999996

Note

In the first sample, we can simply take all three integers for a total sum of 6.

In the second sample Wet Shark should take any four out of five integers 999 999 999.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int senar_petit = 1e9 + 1;
  long long suma = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    suma += x;
    if (x % 2 and x < senar_petit) senar_petit = x;
  }
  if (suma % 2)
    cout << suma - senar_petit << endl;
  else
    cout << suma << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Alice and Bob play ping-pong with simplified rules.

During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternately make a return until one of them doesn't make a return.

The one who doesn't make a return loses this play. The winner of the play commences the next play. Alice starts the first play.

Alice has x stamina and Bob has y. To hit the ball (while serving or returning) each player spends 1 stamina, so if they don't have any stamina, they can't return the ball (and lose the play) or can't serve the ball (in this case, the other player serves the ball instead). If both players run out of stamina, the game is over.

Sometimes, it's strategically optimal not to return the ball, lose the current play, but save the stamina. On the contrary, when the server commences a play, they have to hit the ball, if they have some stamina left.

Both Alice and Bob play optimally and want to, firstly, maximize their number of wins and, secondly, minimize the number of wins of their opponent.

Calculate the resulting number of Alice's and Bob's wins.

Input

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

The first and only line of each test case contains two integers x and y (1 ≤ x, y ≤ 10^6) — Alice's and Bob's initial stamina.

Output

For each test case, print two integers — the resulting number of Alice's and Bob's wins, if both of them play optimally.

Example

Input

3
1 1
2 1
1 7

Output

0 1
1 1
0 7

Note

In the first test case, Alice serves the ball and spends 1 stamina. Then Bob returns the ball and also spends 1 stamina. Alice can't return the ball since she has no stamina left and loses the play. Both of them ran out of stamina, so the game is over with 0 Alice's wins and 1 Bob's wins.

In the second test case, Alice serves the ball and spends 1 stamina. Bob decides not to return the ball — he loses the play but saves stamina. Alice, as the winner of the last play, serves the ball in the next play and spends 1 more stamina. This time, Bob returns the ball and spends 1 stamina. Alice doesn't have any stamina left, so she can't return the ball and loses the play. Both of them ran out of stamina, so the game is over with 1 Alice's and 1 Bob's win.

In the third test case, Alice serves the ball and spends 1 stamina. Bob returns the ball and spends 1 stamina. Alice ran out of stamina, so she can't return the ball and loses the play. Bob, as a winner, serves the ball in the next 6 plays. Each time Alice can't return the ball and loses each play. The game is over with 0 Alice's and 7 Bob's wins.

### Response

```cpp
/*
 *   Author: glaucoacassioc
 *   Created on 2020-11-30, 11:48:30
 */
#include <bits/stdc++.h>
using namespace std;

#define _CRT_SECURE_NO_DEPRECATE
#define INF 0X7f7f7f7
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define endl "\n"

typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

int32_t main() {
      #ifndef ONLINE_JUDGE
            freopen("in.txt","r",stdin);
            freopen("out.txt","w",stdout);
      #endif
      ios_base::sync_with_stdio(false);
      cin.tie(NULL); cout.tie(NULL);
      int n, a , b;
      cin >> n;
      while(n--) {
            cin >> a >> b;
            cout << --a <<" "<< b << endl;
      }
}

```


### Prompt

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

Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown in the front screen.

There are eight types of direction arrows in the Step Step Evolution: UP, UPPER RIGHT, RIGHT, LOWER RIGHT, DOWN, LOWER LEFT, LEFT, and UPPER LEFT. These direction arrows will scroll upward from the bottom of the screen. When the direction arrow overlaps the stationary arrow nearby the top, then the player must step on the corresponding arrow panel on the dance platform. The figure below shows how the dance platform looks like.

<image>

Figure 1: the dance platform for Step Step Evolution

In the game, you have to obey the following rule:

* Except for the beginning of the play, you must not press the arrow panel which is not correspond to the edit data.
* The foot must stay upon the panel where it presses last time, and will not be moved until it’s going to press the next arrow panel.
* The left foot must not step on the panel which locates at right to the panel on which the right foot rests. Conversely, the right foot must not step on the panel which locates at left to the panel on which the left foot rests.

As for the third condition, the following figure shows the examples of the valid and invalid footsteps.

<image>

Figure 2: the examples of valid and invalid footsteps

The first one (left foot for LEFT, right foot for DOWN) and the second one (left foot for LOWER LEFT, right foot for UPPER LEFT) are valid footstep. The last one (left foot for RIGHT, right foot for DOWN) is invalid footstep.

Note that, at the beginning of the play, the left foot and right foot can be placed anywhere at the arrow panel. Also, you can start first step with left foot or right foot, whichever you want.

To play this game in a beautiful way, the play style called “ Natural footstep style” is commonly known among talented players. “Natural footstep style” is the style in which players make steps by the left foot and the right foot in turn. However, when a sequence of arrows is difficult, players are sometimes forced to violate this style.

Now, your friend has created an edit data (the original sequence of direction arrows to be pushed) for you. You are interested in how many times you have to violate “Natural footstep style” when you optimally played with this edit data. In other words, what is the minimum number of times you have to step on two consecutive arrows using the same foot?

Input

The input consists of several detasets. Each dataset is specified by one line containing a sequence of direction arrows. Directions are described by numbers from 1 to 9, except for 5. The figure below shows the correspondence between numbers and directions.

You may assume that the length of the sequence is between 1 and 100000, inclusive. Also, arrows of the same direction won’t appear consecutively in the line. The end of the input is indicated by a single “#”.

<image>

Figure 3: the correspondence of the numbers to the direction arrows

Output

For each dataset, output how many times you have to violate “Natural footstep style” when you play optimally in one line.

Examples

Input

1
12
123
369
6748
4247219123
1232123212321232
#

Output

0
0
1
0
1
2
7

Input

1
12
123
369
6748
4247219123
1232123212321232

Output

0
0
1
0
1
2
7

### Response

```cpp
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		if (r%l) {
			return gcd(l, r%l);

		}
		else {
			return l;
		}
	}
}

map<int, int>mp;

int main() {
	mp['1'] = 0;
	mp['2'] = 1;
	mp['3'] = 2;
	mp['4'] = 0;
	mp['6'] = 2;
	mp['7'] = 0;
	mp['8'] = 1;
	mp['9'] = 2;
	while (1) {
		string st; cin >> st;
		if (st == "#")break;
		int ans = 99999999;
		{
			int l = 0;
			int r = 2;
			bool isleft = true;
			int tired = 0;
			for (int i = 0; i < st.size(); ++i) {
				if (isleft) {
					if (r < mp[st[i]]) {
						r = mp[st[i]];
						tired++;
					}
					else {
						l = mp[st[i]];
						isleft =!isleft;
					}
				}
				else {
					if (l > mp[st[i]]) {
						l = mp[st[i]];
						tired++;
					}
					else {
						r = mp[st[i]];
						isleft = !isleft;
					}
				}

			}
			ans = min(ans, tired);
		}
		{
			int l = 0;
			int r = 2;
			bool isleft = false;
			int tired = 0;
			for (int i = 0; i < st.size(); ++i) {
				if (isleft) {
					if (r < mp[st[i]]) {
						r = mp[st[i]];
						tired++;
					}
					else {
						l = mp[st[i]];
						isleft = !isleft;
					}
				}
				else {
					if (l > mp[st[i]]) {
						l = mp[st[i]];
						tired++;
					}
					else {
						r = mp[st[i]];
						isleft = !isleft;
					}
				}

			}
			ans = min(ans, tired);
		}
		cout << ans << endl;
	}
	return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed).

Let's consider empty cells are denoted by '.', then the following figures are stars:

<image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3.

You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.

In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars.

Input

The first line of the input contains two integers n and m (3 ≤ n, m ≤ 100) — the sizes of the given grid.

The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.

Output

If it is impossible to draw the given grid using stars only, print "-1".

Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid.

Examples

Input

6 8
....*...
...**...
..*****.
...**...
....*...
........

Output

3
3 4 1
3 5 2
3 5 1

Input

5 5
.*...
****.
.****
..**.
.....

Output

3
2 2 1
3 3 1
3 4 1

Input

5 5
.*...
***..
.*...
.*...
.....

Output

-1

Input

3 3
*.*
.*.
*.*

Output

-1

Note

In the first example the output

    2
    3 4 1
    3 5 2

is also correct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, h, g, c[268456], d[317456], l, r, s, t, k, a[1121][1136],
    b1[1213456], b2[1345678], b3[1123456], m, x, y, z;
string p[12345], q;
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (i = 1; i < n - 1; i++) {
    for (j = 1; j < m - 1; j++) {
      t = 0;
      if (p[i][j] == '*' && p[i][j + 1] == '*' && p[i][j - 1] == '*' &&
          p[i + 1][j] == '*' && p[i - 1][j] == '*') {
        l = 1;
        a[i][j] = 1;
        a[i][j + l] = 1;
        a[i][j - l] = 1;
        a[i + 1][j] = 1;
        a[i - 1][j] = 1;
        while (t == 0) {
          l++;
          t = 1;
          if (i < l || j < l || n - i <= l || m - j <= l) break;
          if (p[i][j + l] == '*' && p[i][j - l] == '*' && p[i + l][j] == '*' &&
              p[i - l][j] == '*')
            t = 0;
          if (t == 0) {
            a[i][j + l] = 1;
            a[i][j - l] = 1;
            a[i + l][j] = 1;
            a[i - l][j] = 1;
          }
        }
        b1[s] = i + 1;
        b2[s] = j + 1;
        b3[s] = l - 1;
        s++;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (p[i][j] == '*' && a[i][j] == 0) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << s << endl;
  for (i = 0; i < s; i++) {
    cout << b1[i] << ' ' << b2[i] << ' ' << b3[i] << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.

Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?

Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.

Help Inna maximize the total joy the hares radiate. :)

Input

The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 105.

Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.

Output

In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.

Examples

Input

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

Output

13

Input

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

Output

44

Input

3
1 1 1
1 2 1
1 1 1

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100100], b[100100], c[100100];
int dp[100100][5];
int main() {
  int n, i, j, k, l, m, q, w, e, r, t;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (i = 1; i <= n; i++) scanf("%d", &c[i]);
  memset(dp, 0, sizeof(dp));
  dp[1][0] = b[1];
  dp[1][1] = a[1];
  for (i = 2; i <= n - 1; i++) {
    dp[i][0] = max(dp[i - 1][0] + b[i], dp[i - 1][1] + c[i]);
    dp[i][1] = max(dp[i - 1][0] + a[i], dp[i - 1][1] + b[i]);
  }
  if (n == 1)
    printf("%d\n", a[1]);
  else
    printf("%d\n", max(dp[n - 1][0] + a[n], dp[n - 1][1] + b[n]));
  return 0;
}

```


### Prompt

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

This problem has nothing to do with Little Chris. It is about hill climbers instead (and Chris definitely isn't one).

There are n hills arranged on a line, each in the form of a vertical line segment with one endpoint on the ground. The hills are numbered with numbers from 1 to n from left to right. The i-th hill stands at position xi with its top at height yi. For every two hills a and b, if the top of hill a can be seen from the top of hill b, their tops are connected by a rope. Formally, the tops of two hills are connected if the segment connecting their top points does not intersect or touch any of the other hill segments. Using these ropes, the hill climbers can move from hill to hill.

There are m teams of climbers, each composed of exactly two members. The first and the second climbers of the i-th team are located at the top of the ai-th and bi-th hills, respectively. They want to meet together at the top of some hill. Now, each of two climbers move according to the following process:

  1. if a climber is at the top of the hill where the other climber is already located or will come eventually, the former climber stays at this hill;
  2. otherwise, the climber picks a hill to the right of his current hill that is reachable by a rope and is the rightmost possible, climbs this hill and continues the process (the climber can also climb a hill whose top is lower than the top of his current hill).

<image>

For each team of climbers, determine the number of the meeting hill for this pair!

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105), the number of hills. The next n lines describe the hills. The i-th of them contains two space-separated integers xi, yi (1 ≤ xi ≤ 107; 1 ≤ yi ≤ 1011), the position and the height of the i-th hill. The hills are given in the ascending order of xi, i.e., xi < xj for i < j.

The next line of input contains a single integer m (1 ≤ m ≤ 105), the number of teams. The next m lines describe the teams. The i-th of them contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n), the numbers of the hills where the climbers of the i-th team are located. It is possible that ai = bi.

Output

In a single line output m space-separated integers, where the i-th integer is the number of the meeting hill for the members of the i-th team.

Examples

Input

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

Output

5 6 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
long long X[maxn], Y[maxn];
vector<int> G[maxn];
int fa[maxn], anc[maxn][25], dep[maxn], q[maxn];
bool vis[maxn];
void init(int n) {
  for (int i = 0; i <= n; i++) G[i].clear();
}
void dfs(int u, int d) {
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!vis[v]) {
      vis[v] = 1;
      dep[v] = d;
      fa[v] = u;
      dfs(v, d + 1);
    }
  }
}
void RMQ(int n) {
  memset(anc, 0, sizeof(anc));
  for (int i = 1; i <= n; i++) anc[i][0] = fa[i];
  for (int k = 1; k <= 20; k++)
    for (int v = 1; v <= n; v++) anc[v][k] = anc[anc[v][k - 1]][k - 1];
}
int swim(int x, int H) {
  for (int i = 0; H > 0; i++) {
    if (H & 1) x = anc[x][i];
    H /= 2;
  }
  return x;
}
int LCA(int u, int v) {
  int k;
  if (dep[u] > dep[v]) swap(u, v);
  v = swim(v, dep[v] - dep[u]);
  if (u == v) return v;
  while (1) {
    for (k = 0; anc[u][k] != anc[v][k]; k++)
      ;
    if (k == 0) return anc[u][0];
    u = anc[u][k - 1];
    v = anc[v][k - 1];
  }
}
int main() {
  int n, m, x, y;
  while (scanf("%d", &n) != EOF) {
    init(n);
    for (int i = 1; i <= n; i++) scanf("%I64d%I64d", &X[i], &Y[i]);
    q[0] = n;
    int s = 0;
    for (int i = n - 1; i >= 1; i--) {
      while (s && (Y[i] - Y[q[s]]) * (X[q[s - 1]] - X[q[s]]) >
                      (X[q[s]] - X[i]) * (Y[q[s]] - Y[q[s - 1]]))
        s--;
      s++;
      q[s] = i;
      G[q[s - 1]].push_back(i);
    }
    memset(vis, 0, sizeof(vis));
    vis[n] = 1;
    fa[n] = 0;
    dep[n] = 1;
    dfs(n, 2);
    RMQ(n);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &x, &y);
      int ans = LCA(x, y);
      if (i != m)
        printf("%d ", ans);
      else
        printf("%d", ans);
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.

The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.

Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Examples

Input

3 1

Output

3
1 2
2 3
3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 100;
long long n, k, m, x, y;
vector<int> g[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  x = n * (n - 1) / 2;
  y = n * k;
  if (x < y) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      g[j].push_back((j + m) % n + 1);
    }
    m++;
  }
  cout << y << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      cout << i << " " << g[i][j] << endl;
    }
  }
  return 0;
}

```


### Prompt

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

We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}.

You need to rearrange these numbers as follows:

1. First, for each of the N rows, rearrange the numbers written in it as you like.
2. Second, for each of the M columns, rearrange the numbers written in it as you like.
3. Finally, for each of the N rows, rearrange the numbers written in it as you like.

After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.

Constraints

* 1 \leq N,M \leq 100
* 1 \leq A_{ij} \leq NM
* A_{ij} are distinct.

Input

Input is given from Standard Input in the following format:

N M
A_{11} A_{12} ... A_{1M}
:
A_{N1} A_{N2} ... A_{NM}

Output

Print one way to rearrange the numbers in the following format:

B_{11} B_{12} ... B_{1M}
:
B_{N1} B_{N2} ... B_{NM}
C_{11} C_{12} ... C_{1M}
:
C_{N1} C_{N2} ... C_{NM}

Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2.

Examples

Input

3 2
2 6
4 3
1 5

Output

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

Input

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

Output

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

### Response

```cpp
#include<bits/stdc++.h>
#define pb emplace_back
#define INF 1e9
#define N 210
using namespace std;
struct Info{int nu,ne,qu;}a[N*N];
int m,n,x,y,s,t,num=1,b[N],cur[N],an[N][N],li[N],di[N];
vector<int> c[N][N];
void jb(int x,int y){
	a[++num].nu=y;a[num].ne=b[x];b[x]=num;a[num].qu=1;
	a[++num].nu=x;a[num].ne=b[y];b[y]=num;a[num].qu=0;
}
int dinic(int x,int sh){
	if (x==t) return sh;
	int n1=0,n2;
	for (int y=cur[x];y;y=a[y].ne){
		cur[x]=y;
		if (di[a[y].nu]==di[x]+1&&a[y].qu){
			n2=dinic(a[y].nu,min(a[y].qu,sh-n1));
			n1+=n2;a[y].qu-=n2;a[y^1].qu+=n2;
			if (n1==sh) return n1;
		}
	}
	return n1;
}
bool bfs(){
	for (int i=1;i<=t;i++)di[i]=INF;
	int l=1,r=1;li[l]=s;di[s]=0;
	while (l<=r){
		for (int y=b[li[l]];y;y=a[y].ne)
			if (a[y].qu&&di[a[y].nu]==INF){di[a[y].nu]=di[li[l]]+1;li[++r]=a[y].nu;}
		l++;
	}
	return (di[t]!=INF);
}
int main(){
	cin>>n>>m;
	s=n+n+1,t=n+n+2;
	for (int i=1;i<=n;i++){jb(s,i);jb(i+n,t);}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){cin>>x;c[i][(x-1)/m+1].pb(x);jb(i,n+(x-1)/m+1);}
	for (int j=1;j<=m;j++){
		while (bfs()){for (int i=1;i<=t;i++)cur[i]=b[i];dinic(s,INF);}
		for (int i=1;i<=n;i++){
			a[i*2].qu=1;a[i*2+1].qu=0;
			a[(i+n)*2].qu=1;a[(i+n)*2+1].qu=0;
		}
		for (int i=3;i<=num;i+=2){
			if (a[i].qu){
				a[i].qu=0;y=a[i^1].nu-n;
				an[a[i].nu][j]=c[a[i].nu][y][c[a[i].nu][y].size()-1];
				c[a[i].nu][y].pop_back();
			}
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<m;j++)cout<<an[i][j]<<' ';
		cout<<an[i][m]<<endl;
	}
	for (int i=1;i<=m;i++){
		vector<int> no;no.clear();
		for (int j=1;j<=n;j++)no.pb(an[j][i]);
		sort(no.begin(),no.end());
		for (int j=1;j<=n;j++)an[j][i]=no[j-1];
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<m;j++)cout<<an[i][j]<<' ';
		cout<<an[i][m]<<endl;
	}
	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is a_i. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least x.

Each programmer should belong to at most one team. Some programmers may be left without a team.

Calculate the maximum number of teams that you can assemble.

Input

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

The first line of each test case contains two integers n and x (1 ≤ n ≤ 10^5; 1 ≤ x ≤ 10^9) — the number of programmers and the restriction of team skill respectively.

The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ 10^9), where a_i is the skill of the i-th programmer.

The sum of n over all inputs does not exceed 10^5.

Output

For each test case print one integer — the maximum number of teams that you can assemble.

Example

Input

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

Output

2
1
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int c = 0, num = 0;
    for (int i = n - 1; i >= 0; i--) {
      num++;
      if (a[i] * num >= x) {
        c++;
        num = 0;
      }
    }
    cout << c << "\n";
  }
  return 0;
}

```


### Prompt

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

You are given a tree with N vertices.
Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices.
The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i.

You are also given Q queries and an integer K. In the j-th query (1≤j≤Q):

* find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.

Constraints

* 3≤N≤10^5
* 1≤a_i,b_i≤N (1≤i≤N-1)
* 1≤c_i≤10^9 (1≤i≤N-1)
* The given graph is a tree.
* 1≤Q≤10^5
* 1≤K≤N
* 1≤x_j,y_j≤N (1≤j≤Q)
* x_j≠y_j (1≤j≤Q)
* x_j≠K,y_j≠K (1≤j≤Q)

Input

Input is given from Standard Input in the following format:

N
a_1 b_1 c_1
:
a_{N-1} b_{N-1} c_{N-1}
Q K
x_1 y_1
:
x_{Q} y_{Q}

Output

Print the responses to the queries in Q lines.
In the j-th line j(1≤j≤Q), print the response to the j-th query.

Examples

Input

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

Output

3
2
4

Input

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

Output

5
14
22

Input

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

Output

17000000000

### Response

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

vector<pair<int , int> > v[100005];
long long dp[100005];
void dfs(int n , int p , long long dis)
{
    dp[n] = dp[p]+1ll*dis;

    for(auto it : v[n])
    {
        if(it.first!=p)
        {
            dfs(it.first , n , it.second);
        }
    }
}
int main()
{
    int n;

    cin >> n;

    for(int i = 1 ; i<n ; i++)
    {
        int x , y , z;

        cin >> x >> y >> z;

        v[x].push_back(make_pair(y , z));
        v[y].push_back(make_pair(x , z));
    }

    int q , k;

    cin >> q >> k;

    dfs(k , 0 , 0);

    while(q--)
    {
        int l , r;

        cin >> l >> r;

        cout << dp[r]+dp[l] << "\n";
    }
    return 0;
}

```


### Prompt

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

You are given an undirected graph with n vertices and m edges. You have to write a number on each vertex of this graph, each number should be either 0 or 1. After that, you write a number on each edge equal to the sum of numbers on vertices incident to that edge.

You have to choose the numbers you will write on the vertices so that there is at least one edge with 0 written on it, at least one edge with 1 and at least one edge with 2. How many ways are there to do it? Two ways to choose numbers are different if there exists at least one vertex which has different numbers written on it in these two ways.

Input

The first line contains two integers n and m (1 ≤ n ≤ 40, 0 ≤ m ≤ (n(n - 1))/(2)) — the number of vertices and the number of edges, respectively.

Then m lines follow, each line contains two numbers x_i and y_i (1 ≤ x_i, y_i ≤ n, x_i ≠ y_i) — the endpoints of the i-th edge. It is guaranteed that each pair of vertices is connected by at most one edge.

Output

Print one integer — the number of ways to write numbers on all vertices so that there exists at least one edge with 0 written on it, at least one edge with 1 and at least one edge with 2.

Examples

Input

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

Output

20

Input

4 4
1 2
2 3
3 4
4 1

Output

4

Input

35 29
1 2
2 3
3 1
4 1
4 2
3 4
7 8
8 9
9 10
10 7
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30

Output

34201047040

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 40;
int n, m;
vector<int> e[maxn];
inline long long f012() { return (1LL << n); }
inline long long fz() { return (m == 0 ? (1LL << n) : 0); }
inline long long f0() {
  long long res = 1;
  for (int i = 0; i < n; i++) {
    if (e[i].empty()) res <<= 1;
  }
  return res;
}
inline long long f2() { return f0(); }
bool used[maxn];
void dfs(int v) {
  used[v] = true;
  for (int u : e[v]) {
    if (!used[u]) {
      dfs(u);
    }
  }
}
inline long long f02() {
  long long res = 1;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      dfs(i);
      res <<= 1;
    }
  }
  return res;
}
int kt[maxn];
bool is2ch = true;
void dfs1(int v) {
  for (int u : e[v]) {
    if (!kt[u]) {
      kt[u] = 3 - kt[v];
      dfs1(u);
    } else if (kt[u] == kt[v]) {
      is2ch = false;
    }
  }
}
inline long long f1() {
  long long res = 1;
  for (int i = 0; i < n; i++) {
    if (!kt[i]) {
      kt[i] = 1;
      dfs1(i);
      res <<= 1;
    }
  }
  res = (is2ch ? res : 0);
  return res;
}
const int maxmsk = (1 << 20);
long long e2[maxn];
bool nz1[maxmsk], nz2[maxmsk];
int pmsk[maxmsk];
inline long long f01() {
  for (int i = 0; i < n; i++) {
    for (int j : e[i]) {
      e2[i] |= (1LL << j);
    }
  }
  int c1 = n / 2;
  nz1[0] = true;
  for (int i = 0; i < c1; i++) {
    for (int j = 0; j < (1 << i); j++) {
      if ((j & e2[i]) == 0) {
        nz1[j | (1 << i)] |= nz1[j];
      }
    }
  }
  nz2[0] = true;
  for (int i = 0; i < n - c1; i++) {
    for (int j = 0; j < (1 << i); j++) {
      if ((((long long)j << c1) & e2[c1 + i]) == 0) {
        nz2[j | (1 << i)] |= nz2[j];
      }
    }
  }
  for (int i = 0; i < (1 << (n - c1)); i++) {
    pmsk[i] = nz2[i];
  }
  for (int i = 0; i < (n - c1); i++) {
    for (int j = 0; j < (1 << (n - c1)); j++) {
      if ((j & (1 << i)) == 0) {
        pmsk[j | (1 << i)] += pmsk[j];
      }
    }
  }
  long long res = 0;
  for (int i = 0; i < (1 << c1); i++) {
    if (nz1[i]) {
      long long cmsk = 0;
      for (int j = 0; j < c1; j++) {
        if ((1 << j) & i) cmsk |= e2[j];
      }
      res += pmsk[(1 << (n - c1)) - 1 - (cmsk >> c1)];
    }
  }
  return res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    e[v].push_back(u);
    e[u].push_back(v);
  }
  cout << f012() - 2 * f01() - f02() + f0() + f1() + f2() - fz();
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).

Now, he will perform the following operation exactly once:

* Choose K consecutive elements in P and sort them in ascending order.

Find the number of permutations that can be produced as P after the operation.

Constraints

* 2 \leq N \leq 200000
* 2 \leq K \leq N
* 0 \leq P_i \leq N-1
* P_0,P_1,\cdots,P_{N-1} are all different.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_0 P_1 \cdots P_{N-1}

Output

Print the number of permutations that can be produced as P after the operation.

Examples

Input

5 3
0 2 1 4 3

Output

2

Input

4 4
0 1 2 3

Output

1

Input

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

Output

6

### Response

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

using namespace std;

#define ll long long

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

  vector<int> p(n);
  for(int i = 0; i < n; i++) cin >> p[i];
  priority_queue<int> q0, q1;
  vector<int> fin(n, false);
  vector<int> seq(n, 1);
  for(int i = 0; i < k; i++){
    q0.push(p[i]);
    q1.push(-p[i]);
  }
  for(int i = n - 2; i >= 0; i--){
    if(p[i] < p[i + 1]) seq[i] = seq[i + 1] + 1;
  }
  ll s = 0;
  for(int i = 0; i < n; i++){
    if(seq[i] == k) s++;
  }
  ll count = 1;
  for(int i = 0; i + k < n; i++){
    while(fin[-q1.top()]){
      q1.pop();
    }
    ll c = 0;
    if(-q1.top() != p[i]) c = 1;
    fin[p[i]] = true;
    while(fin[q0.top()]){
      q0.pop();
    }
    q0.push(p[i + k]);
    q1.push(-p[i + k]);
    if(q0.top() != p[i + k]) c = 1;
    count += c;
  }

  cout << (count - max(s - (ll)1, (ll)0)) << endl;

  return 0;
}
```


### Prompt

Please formulate a CPP solution to the following problem:

A linguist, Nodvic Natharus Damenhof (commonly called Dr. Usoperant), invented an artificial language Usoperant in 2007. The word usoperant means ‘one which tires’. Damenhof’s goal was to create a complex and pedantic language that would remind many difficulties in universal communications. Talking in Usoperant, you should remember the importance of choosing your words in many conversations.

For example of the complexity, you may be confused by the way to say large numbers. Usoperant has some words that indicate exponential numbers in decimal, described as 10p where p is a positive integer. In terms of English, those words might include thousand for 103 (1,000), million for 106 (1,000,000), and undecillion for 1036 (1,000,000,000,000,000,000,000,000,000,000,000,000).

You can concatinate those words to express larger numbers. When two words w1 and w2 mean numbers 10p1 and 10p2 respectively, a concatinated word w1w2 means 10p1+p2. Using the above examples in English (actually the following examples are incorrect in English), you can say 109 by millionthousand, 1012 by millionmillion and 1039 by undecillionthousand. Note that there can be multiple different expressions for a certain number. For example, 109 can also be expressed by thousandthousandthousand. It is also possible to insert separators between the adjacent components like million-thousand and thousand-thousand-thousand.

In this problem, you are given a few of such words, their representing digits and an expression of a certain number in Usoperant. Your task is to write a program to calculate the length of the shortest expression which represents the same number as the given expression.

The expressions in the input do not contain any separators like millionthousand. In case of ambiguity, the expressions should be interpreted as the largest number among possibles. The resultant expressions should always contain separators like million-thousand, so we can distinguish, for example, x-x (a concatinated word of two x's) and xx (just a single word). The separators should not be counted in the length.

Note:

In the fourth case, the word abcdefgh can be separated as abcd-efgh (representing 103 ) and abcde-fgh (representing 1010 ), and by the rule described in the problem statement, this word should be interpreted as 1010. As this number can be expressed by yy, the length of the shortest expression is two (as in the sample output). The existence of y-y (representing 1016 ) is not a problem here, because we can distinguish yy and y-y as long as we always use separators.

Input

The input consists of multiple test cases. Each test case begins with a line including an integer N (1 ≤ N ≤ 100). The integer N indicates the number of words in the dictionary of exponential numbers.

The following N lines give the words in the dictionary. Each line contains a word wi and an integer pi (1 ≤ i ≤ N, 1 ≤ pi ≤ 10), specifying that the word wi expresses an exponential number 10pi in Usoperant. Each wi consists of at most 100 alphabetical letters.

Then a line which contains an expression of a number in Usoperant follows. The expression consists of at most 200 alphabetical letters.

The end of the input is indicated by a line which contains only a single 0.

Output

For each test case, print a line which contains the case number and the length of the shortest expression which represents the same number as the given expression in the input.

Example

Input

3
billion 9
million 6
thousand 3
billionmillionthousand
3
oku 8
sen 3
man 4
okusenman
2
nico 2
video 4
niconicovideo
6
abcd 1
efgh 2
abcde 4
fgh 6
y 8
yy 10
abcdefgh
0

Output

Case 1: 14
Case 2: 9
Case 3: 10
Case 4: 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 10101010;

int main(){
    int cc = 0;
    int n;
    while(cin >>n,n){
        vector<string> s(n);
        vector<int> p(n),l(n);
        rep(i,n){
            cin >>s[i] >>p[i];
            l[i] = s[i].size();
        }

        string t;
        cin >>t;
        int T = t.size();

        vector<int> dp(T+1,-INF);
        dp[0] = 0;
        rep(i,T){
            rep(j,n){
                if(i+l[j] > T) continue;
                if(s[j] == t.substr(i,l[j])){
                    dp[i+l[j]] = max(dp[i+l[j]], dp[i]+p[j]);
                }
            }
        }

        int V = dp[T];
        dp = vector<int>(V+1, INF);
        dp[0] = 0;
        rep(i,V){
            rep(j,n){
                int ni = i+p[j];
                if(ni > V) continue;
                dp[ni] = min(dp[ni], dp[i]+l[j]);
            }
        }

        cout << "Case " << cc+1 << ": " << dp[V] << "\n";
        ++cc;
    }
    return 0;
}

```


### Prompt

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

You are given two integers a and b. Print a+b.

Input

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

Each test case is given as a line of two integers a and b (-1000 ≤ a, b ≤ 1000).

Output

Print t integers — the required numbers a+b.

Example

Input

4
1 5
314 15
-99 99
123 987

Output

6
329
0
1110

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> m;
    cout << n + m << '\n';
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Kurohashi has never participated in AtCoder Beginner Contest (ABC).

The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.

What is the earliest ABC where Kurohashi can make his debut?

Constraints

* 100 \leq N \leq 999
* N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If the earliest ABC where Kurohashi can make his debut is ABC n, print n.

Examples

Input

111

Output

111

Input

112

Output

222

Input

750

Output

777

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int K;
int main(){
 cin>>K;
 int res=((K+110)/111)*111;
 cout<<res;
}
```


### Prompt

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

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>
using namespace std;
template <typename T, typename L>
bool smax(T& x, L y) {
  return x < y ? x = y, true : false;
}
long long c, wa, wb, ha, hb;
long long mx = -1;
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cerr << "HELLO WORLD :)\n";
  cin >> c >> ha >> hb >> wa >> wb;
  for (long long i = 0; i <= 1e7 && i * wa <= c; i++)
    smax(mx, i * ha + (c - wa * i) / wb * hb);
  for (long long i = 0; i <= 1e7 && i * wb <= c; i++)
    smax(mx, i * hb + (c - wb * i) / wa * ha);
  return cout << (mx == -1 ? 0 : mx) << '\n', false;
}

```


### Prompt

Create a solution in cpp for the following problem:

Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.

Input

The first line contains integer n (3 ≤ n ≤ 100) — amount of worm's forms. The second line contains n space-separated integers ai (1 ≤ ai ≤ 1000) — lengths of worms of each form.

Output

Output 3 distinct integers i j k (1 ≤ i, j, k ≤ n) — such indexes of worm's forms that ai = aj + ak. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that aj = ak.

Examples

Input

5
1 2 3 5 7

Output

3 2 1

Input

5
1 8 1 5 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0, x;
  vector<int> v;
  cin >> n;
  bool f = true;
  map<int, int> mpp;
  map<int, int> mp;
  map<int, string> m;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    mp[x] = i;
    if (m[x] != "ase") {
      m[x] = "ase";
      mpp[x] = i;
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      x = v[i] + v[j];
      if ((m[x] == "ase") &&
          (i != j && mp[v[j]] != mp[x] && mp[v[i]] != mp[x])) {
        f = false;
        cout << mp[x] + 1;
        if (mp[v[j]] == mp[v[i]]) {
          cout << " " << mp[v[j]] + 1 << " " << mpp[v[j]] + 1 << "\n";
        } else {
          cout << " " << mp[v[j]] + 1 << " " << mp[v[i]] + 1 << "\n";
        }
        break;
      }
    }
    if (f == false) {
      break;
    }
  }
  if (f == true) {
    cout << -1 << "\n";
  }
}

```


### Prompt

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

One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.

These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.

Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.

Input

The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.

We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.

Output

Print a single integer — the maximum length of a repost chain.

Examples

Input

5
tourist reposted Polycarp
Petr reposted Tourist
WJMZBMR reposted Petr
sdya reposted wjmzbmr
vepifanov reposted sdya

Output

6

Input

6
Mike reposted Polycarp
Max reposted Polycarp
EveryOne reposted Polycarp
111 reposted Polycarp
VkCup reposted Polycarp
Codeforces reposted Polycarp

Output

2

Input

1
SoMeStRaNgEgUe reposted PoLyCaRp

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void FastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long pow(long long B, long long P) {
  long long S = 1;
  for (long long i = 1; i <= P; i++) S = S * B;
  return S;
}
int fx4[] = {1, -1, 0, 0};
int fy4[] = {0, 0, 1, -1};
map<string, vector<string> > graph;
map<string, int> visited;
map<string, int> level;
string same(string S) {
  int len = S.length();
  for (int i = 0; i < len; i++) {
    S[i] = toupper(S[i]);
  }
  return S;
}
int BFS(string source) {
  visited[source] = 1;
  queue<string> Q;
  Q.push(source);
  level[source] = 1;
  int MAX = 1;
  while (!Q.empty()) {
    string u = Q.front();
    Q.pop();
    for (int i = 0; i < graph[u].size(); i++) {
      string v = graph[u][i];
      if (visited[v] == 0) {
        visited[v] = 1;
        Q.push(v);
        level[v] = level[u] + 1;
        if (level[v] > MAX) MAX = level[v];
      }
    }
  }
  return MAX;
}
set<string> nodes;
int main() {
  FastIO();
  int N;
  cin >> N;
  string S, X, Y;
  for (int i = 0; i < N; i++) {
    cin >> X >> S >> Y;
    X = same(X);
    Y = same(Y);
    graph[Y].push_back(X);
    nodes.insert(X);
    nodes.insert(Y);
  }
  int ans = BFS("POLYCARP");
  cout << ans << endl;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Alice and Bob are decorating a Christmas Tree.

Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have y yellow ornaments, b blue ornaments and r red ornaments.

In Bob's opinion, a Christmas Tree will be beautiful if:

  * the number of blue ornaments used is greater by exactly 1 than the number of yellow ornaments, and
  * the number of red ornaments used is greater by exactly 1 than the number of blue ornaments.

That is, if they have 8 yellow ornaments, 13 blue ornaments and 9 red ornaments, we can choose 4 yellow, 5 blue and 6 red ornaments (5=4+1 and 6=5+1).

Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.

In the example two paragraphs above, we would choose 7 yellow, 8 blue and 9 red ornaments. If we do it, we will use 7+8+9=24 ornaments. That is the maximum number.

Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree!

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Input

The only line contains three integers y, b, r (1 ≤ y ≤ 100, 2 ≤ b ≤ 100, 3 ≤ r ≤ 100) — the number of yellow, blue and red ornaments.

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Output

Print one number — the maximum number of ornaments that can be used.

Examples

Input

8 13 9

Output

24

Input

13 3 6

Output

9

Note

In the first example, the answer is 7+8+9=24.

In the second example, the answer is 2+3+4=9.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int y, b, r;
  scanf("%d%d%d", &y, &b, &r);
  if (y < b && y < r) {
    while (1) {
      if (b >= (y + 1) && r >= (y + 2)) {
        b = y + 1;
        r = y + 2;
        break;
      } else
        y--;
    }
  } else if (b < y && b < r) {
    while (1) {
      if (y >= (b - 1) && r >= (b + 1)) {
        y = b - 1;
        r = b + 1;
        break;
      } else
        b--;
    }
  } else {
    while (1) {
      if (y >= (r - 2) && b >= (r - 1)) {
        b = r - 1;
        y = r - 2;
        break;
      } else
        r--;
    }
  }
  printf("%d\n", y + b + r);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Nura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing.

Nura can buy gadgets for n days. For each day you know the exchange rates of dollar and pound, so you know the cost of conversion burles to dollars or to pounds.

Each day (from 1 to n) Nura can buy some gadgets by current exchange rate. Each day she can buy any gadgets she wants, but each gadget can be bought no more than once during n days.

Help Nura to find the minimum day index when she will have k gadgets. Nura always pays with burles, which are converted according to the exchange rate of the purchase day. Nura can't buy dollars or pounds, she always stores only burles. Gadgets are numbered with integers from 1 to m in order of their appearing in input.

Input

First line contains four integers n, m, k, s (1 ≤ n ≤ 2·105, 1 ≤ k ≤ m ≤ 2·105, 1 ≤ s ≤ 109) — number of days, total number and required number of gadgets, number of burles Nura has.

Second line contains n integers ai (1 ≤ ai ≤ 106) — the cost of one dollar in burles on i-th day.

Third line contains n integers bi (1 ≤ bi ≤ 106) — the cost of one pound in burles on i-th day.

Each of the next m lines contains two integers ti, ci (1 ≤ ti ≤ 2, 1 ≤ ci ≤ 106) — type of the gadget and it's cost. For the gadgets of the first type cost is specified in dollars. For the gadgets of the second type cost is specified in pounds.

Output

If Nura can't buy k gadgets print the only line with the number -1.

Otherwise the first line should contain integer d — the minimum day index, when Nura will have k gadgets. On each of the next k lines print two integers qi, di — the number of gadget and the day gadget should be bought. All values qi should be different, but the values di can coincide (so Nura can buy several gadgets at one day). The days are numbered from 1 to n.

In case there are multiple possible solutions, print any of them.

Examples

Input

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

Output

3
1 1
2 3

Input

4 3 2 200
69 70 71 72
104 105 106 107
1 1
2 2
1 2

Output

-1

Input

4 3 1 1000000000
900000 910000 940000 990000
990000 999000 999900 999990
1 87654
2 76543
1 65432

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
const int MAXN = 2e5 + 10, INF = 0x3f3f3f3f;
int n, m, k, s;
long long a[MAXN], b[MAXN], c[MAXN];
int t[MAXN], daya[MAXN], dayb[MAXN];
int ans = -1, ansad, ansbd, ansp[MAXN];
void input() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  a[0] = INF;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
    if (a[i] > a[i - 1]) {
      a[i] = a[i - 1];
      daya[i] = daya[i - 1];
    } else {
      daya[i] = i;
    }
  }
  b[0] = INF;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", b + i);
    if (b[i] > b[i - 1]) {
      b[i] = b[i - 1];
      dayb[i] = dayb[i - 1];
    } else {
      dayb[i] = i;
    }
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%lld", t + i, c + i);
  }
}
bool check(int mid) {
  std::multiset<std::pair<long long, int> > st;
  for (int i = 1; i <= m; i++) {
    st.insert(std::make_pair(c[i] * (t[i] == 1 ? a[mid] : b[mid]), i));
  }
  long long rst = 0;
  auto it = st.begin();
  for (int i = 0; i < k; i++) {
    rst += (it++)->first;
  }
  if (rst <= s) {
    ans = mid;
    ansad = daya[mid];
    ansbd = dayb[mid];
    for (int i = 0; i < k; i++) {
      ansp[i] = (--it)->second;
    }
    return true;
  } else
    return false;
}
void query() {
  int left = 1, right = n;
  while (left <= right) {
    int mid = (left + right) >> 1;
    if (check(mid)) {
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
}
int main() {
  input();
  query();
  printf("%d\n", ans);
  if (ans != -1) {
    for (int i = 0; i < k; i++) {
      printf("%d %d\n", ansp[i], t[ansp[i]] == 1 ? ansad : ansbd);
    }
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened.

You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

Input

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

Examples

Input

fixprefixsuffix

Output

fix

Input

abcdabc

Output

Just a legend

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
char s[1000006];
int z[1000006];
void calc_z() {
  int n = (int)strlen(s);
  int l = 0, r = 0;
  for (int i = 1; i <= int(n); i++) {
    if (i < r) {
      z[i] = min(z[i - l], r - i);
    }
    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() {
  gets(s);
  calc_z();
  int n = (int)strlen(s);
  int len = 0;
  for (int i = 1; i <= int(n - 1); i++) {
    if (i + z[i] < n) {
      len = max(len, z[i]);
    } else {
      len = max(len, z[i] - 1);
    }
  }
  for (int i = 1; i <= int(n - 1); i++) {
    if (i + z[i] == n) {
      if (len >= z[i]) {
        s[z[i]] = 0;
        puts(s);
        return 0;
      }
    }
  }
  cout << "Just a legend\n";
  return 0;
}

```


### Prompt

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

You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:

  * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.

Note that you can put very large positive integers (like 10^{(10^{10})}).

It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.

<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).

<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.

What are the minimum and the maximum possible values of f for the given tree? Find and print both.

Input

The first line contains integer n (3 ≤ n ≤ 10^{5}) — the number of vertices in given tree.

The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 ≤ a_{i} < b_{i} ≤ n) — it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.

Output

Print two integers — the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.

Examples

Input

6
1 3
2 3
3 4
4 5
5 6

Output

1 4

Input

6
1 3
2 3
3 4
4 5
4 6

Output

3 3

Input

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

Output

1 6

Note

In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.

<image>

In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.

<image>

In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const long long p = 998244353;
int maxans = 0;
vector<int> v[101000];
int vis[101000];
int dp[101000][2];
int minans;
void dfs(int x, int fa) {
  int f = 0;
  for (auto i : v[x]) {
    if (i == fa) continue;
    if (vis[i] != 1) {
      dfs(i, x);
      if (dp[i][1]) dp[x][0] = 1;
      if (dp[i][0]) dp[x][1] = 1;
    } else {
      if (f)
        maxans--;
      else
        f = 1;
      dp[x][1] = 1;
    }
  }
  if (dp[x][0] && dp[x][1]) minans = 3;
}
int main() {
  int n;
  scanf("%d", &n);
  maxans = n - 1;
  minans = 1;
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y), v[y].push_back(x);
    vis[x]++, vis[y]++;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] > 1) {
      dfs(i, 0);
      break;
    }
  }
  cout << minans << " " << maxans << endl;
}

```


### Prompt

Generate a CPP solution to the following problem:

Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.

Help Petya find the length of each string obtained by Vasya.

Input

The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.

The second line contains one string s — the song, consisting of n lowercase letters of English letters.

Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.

Output

Print q lines: for each question print the length of the string obtained by Vasya.

Examples

Input

7 3
abacaba
1 3
2 5
1 7

Output

4
7
11

Input

7 4
abbabaa
1 3
5 7
6 6
2 4

Output

5
4
1
5

Input

13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9

Output

82
125
9
191
62
63
97

Note

In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.

### Response

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

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

    ll n, q;
    cin>>n>>q;
    string s;
    cin>>s;
    ll ar[n];
    for(ll i = 0; i < n; i++){
        ll num = s[i]-97+1;
        ar[i] = num;
        if(i > 0)
            ar[i] += ar[i-1];
    }
    for(ll i = 1; i <= q; i++){
        ll a, b;
        cin>>a>>b;
        if(a>1)
            cout<<(ar[b-1]-ar[a-2])<<'\n';
        else
            cout<<ar[b-1]<<'\n';
    }

    return 0;
}

```


### Prompt

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

We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this:

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

Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime.

Input

Input contains several test cases. Each test case consists of an integer N in one line.

Output

For each line of input, output P .

Example

Input

1
4
7
51

Output

0
2
2
6

### Response

```cpp
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;

int is_prime[11000];

int main(){
	REP(i, 11000)is_prime[i] = 1;
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i <= 10000; i++){
		if (is_prime[i]){
			for (int j = i * 2; j <= 10000; j += i)is_prime[j] = 0;
		}
	}

	while (cin >> n){
		int ans = 0;
		FOR(i, 1, n + 1){
			if (is_prime[i] && is_prime[n + 1 - i])ans++;
		}
		cout << ans << endl;
	}
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

You are given an array a_1, a_2, ..., a_n and an array b_1, b_2, ..., b_n.

For one operation you can sort in non-decreasing order any subarray a[l ... r] of the array a.

For example, if a = [4, 2, 2, 1, 3, 1] and you choose subbarray a[2 ... 5], then the array turns into [4, 1, 2, 2, 3, 1].

You are asked to determine whether it is possible to obtain the array b by applying this operation any number of times (possibly zero) to the array a.

Input

The first line contains one integer t (1 ≤ t ≤ 3 ⋅ 10^5) — the number of queries.

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

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

The third line of each query contains n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ n).

It is guaranteed that ∑ n ≤ 3 ⋅ 10^5 over all queries in a test.

Output

For each query print YES (in any letter case) if it is possible to obtain an array b and NO (in any letter case) otherwise.

Example

Input

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

Output

YES
YES
NO
NO

Note

In first test case the can sort subarray a_1 ... a_5, then a will turn into [1, 1, 4, 4, 7, 5, 6], and then sort subarray a_5 ... a_6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int fen[(ll)(3e5 + 3)];
void add(int ind, int val) {
  for (int i = ind; i < (ll)(3e5 + 3); i += i & (-i)) {
    fen[i] = max(fen[i], val);
  }
}
int su(int ind) {
  int ans = (ll)(-5e5);
  for (int i = ind; i > 0; i -= i & (-i)) {
    ans = max(fen[i], ans);
  }
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    fill(fen, fen + n + 10, (ll)(-5e5));
    int ar[n], br[n], cc = 0;
    vector<int> av[n + 1], bv[n + 1];
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
      av[ar[i]].push_back(i);
    }
    for (int i = 0; i < n; i++) {
      cin >> br[i];
      bv[br[i]].push_back(i);
    }
    bool fl = 1;
    for (int i = 1; i <= n; i++) {
      if (av[i].size() != bv[i].size()) {
        fl = 0;
        break;
      }
    }
    if (!fl) {
      cout << "NO\n";
      continue;
    }
    sort(br, br + n);
    int la = -1;
    for (int i = 0; i < n; i++) {
      if (br[i] != la) {
        cc = 0;
        la = br[i];
      } else {
        cc++;
      }
      if (su(av[br[i]][cc] + 1) >= bv[br[i]][cc]) {
        fl = 0;
        break;
      }
      add(av[br[i]][cc] + 1, bv[br[i]][cc]);
    }
    if (fl) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

For the New Year, Polycarp decided to send postcards to all his n friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size w × h, which can be cut into pieces.

Polycarp can cut any sheet of paper w × h that he has in only two cases:

  * If w is even, then he can cut the sheet in half and get two sheets of size w/2 × h;
  * If h is even, then he can cut the sheet in half and get two sheets of size w × h/2;

If w and h are even at the same time, then Polycarp can cut the sheet according to any of the rules above.

After cutting a sheet of paper, the total number of sheets of paper is increased by 1.

Help Polycarp to find out if he can cut his sheet of size w × h at into n or more pieces, using only the rules described above.

Input

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

Each test case consists of one line containing three integers w, h, n (1 ≤ w, h ≤ 10^4, 1 ≤ n ≤ 10^9) — the width and height of the sheet Polycarp has and the number of friends he needs to send a postcard to.

Output

For each test case, output on a separate line:

  * "YES", if it is possible to cut a sheet of size w × h into at least n pieces;
  * "NO" otherwise.

You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

Example

Input

5
2 2 3
3 3 2
5 10 2
11 13 1
1 4 4

Output

YES
NO
YES
YES
YES

Note

In the first test case, you can first cut the 2 × 2 sheet into two 2 × 1 sheets, and then cut each of them into two more sheets. As a result, we get four sheets 1 × 1. We can choose any three of them and send them to our friends.

In the second test case, a 3 × 3 sheet cannot be cut, so it is impossible to get two sheets.

In the third test case, you can cut a 5 × 10 sheet into two 5 × 5 sheets.

In the fourth test case, there is no need to cut the sheet, since we only need one sheet.

In the fifth test case, you can first cut the 1 × 4 sheet into two 1 × 2 sheets, and then cut each of them into two more sheets. As a result, we get four sheets 1 × 1.

### Response

```cpp
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
void solve() {
	long long w,h,n;
	cin >> w >> h >> n;
	int cnt = 0;
	while (w % 2 == 0) {
		cnt++;
		w /= 2;
	}
	while (h % 2 == 0) {
		cnt++;
		h /= 2;
	}
	if (pow(2, cnt) >= n)cout << "YES" << endl;
	else cout << "NO" << endl;
}

int main()
{
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

```