### Prompt

Develop a solution in cpp to the problem described below:

You are given an array a with n elements. Each element of a is either 0 or 1.

Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).

Input

The first line contains two integers n and k (1 ≤ n ≤ 3·105, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.

The second line contains n integers ai (0 ≤ ai ≤ 1) — the elements of a.

Output

On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.

On the second line print n integers aj — the elements of the array a after the changes.

If there are multiple answers, you can print any one of them.

Examples

Input

7 1
1 0 0 1 1 0 1

Output

4
1 0 0 1 1 1 1

Input

10 2
1 0 0 1 0 1 0 1 0 1

Output

5
1 0 0 1 1 1 1 1 0 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> numbers(n);
  for (int i = 0; i < n; ++i) {
    cin >> numbers[i];
  }
  int l = 0;
  int r = -1;
  int count = 0;
  while (count <= k && r < n) {
    ++r;
    if (numbers[r] == 0) ++count;
  }
  pair<int, int> max_len = make_pair(l, r);
  while (r < n && l < n) {
    if (numbers[l] == 0) --count;
    ++l;
    while (count <= k && r < n) {
      ++r;
      if (r == n) continue;
      if (numbers[r] == 0) ++count;
    }
    if (r - l > max_len.second - max_len.first) max_len = make_pair(l, r);
  }
  for (int i = max_len.first; i < max_len.second; ++i) {
    numbers[i] = 1;
  }
  cout << max_len.second - max_len.first << endl;
  for (int i = 0; i < n; ++i) {
    cout << numbers[i] << " ";
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors or singers. It is a revolutionary theory in astronomy.

According to this theory, stars we are observing are not independent objects, but only small portions of larger objects called super stars. A super star is filled with invisible (or transparent) material, and only a number of points inside or on its surface shine. These points are observed as stars by us.

In order to verify this theory, Dr. Extreme wants to build motion equations of super stars and to compare the solutions of these equations with observed movements of stars. As the first step, he assumes that a super star is sphere-shaped, and has the smallest possible radius such that the sphere contains all given stars in or on it. This assumption makes it possible to estimate the volume of a super star, and thus its mass (the density of the invisible material is known).

You are asked to help Dr. Extreme by writing a program which, given the locations of a number of stars, finds the smallest sphere containing all of them in or on it. In this computation, you should ignore the sizes of stars. In other words, a star should be regarded as a point. You may assume the universe is a Euclidean space.

Input

The input consists of multiple data sets. Each data set is given in the following format.

n
x1 y1 z1
x2 y2 z2
...
xn yn zn

The first line of a data set contains an integer n, which is the number of points. It satisfies the condition 4 ≤ n ≤ 30.

The locations of n points are given by three-dimensional orthogonal coordinates: (xi, yi, zi) (i = 1,..., n). Three coordinates of a point appear in a line, separated by a space character.

Each value is given by a decimal fraction, and is between 0.0 and 100.0 (both ends inclusive). Points are at least 0.01 distant from each other.

The end of the input is indicated by a line containing a zero.

Output

For each data set, the radius ofthe smallest sphere containing all given points should be printed, each in a separate line. The printed values should have 5 digits after the decimal point. They may not have an error greater than 0.00001.

Example

Input

4
10.00000 10.00000 10.00000
20.00000 10.00000 10.00000
20.00000 20.00000 10.00000
10.00000 20.00000 10.00000
4
10.00000 10.00000 10.00000
10.00000 50.00000 50.00000
50.00000 10.00000 50.00000
50.00000 50.00000 10.00000
0

Output

7.07107
34.64102

### Response

```cpp
#include<iostream>
#include<valarray>
#include<cmath>

using namespace std;

double dist(valarray<double> a,valarray<double> b){
  double s=0;
  for(int i=0;i<3;i++){
    s+=(a[i]-b[i])*(a[i]-b[i]);
  }
  return sqrt(s);
}

int main(){
  for(int n;cin>>n,n;){
    valarray<double> p[30];
    for(int i=0;i<n;i++){
      p[i].resize(3);
      cin>>p[i][0]>>p[i][1]>>p[i][2];
    }
    valarray<double> c(50,3);
    double w=1;
    double ld;
    for(int i=0;i<100000;i++,w*=.999){
      double m=-1;
      int x;
      for(int j=0;j<n;j++){
	auto d=dist(p[j],c);
	if(d>m){
	  m=d;
	  x=j;
	}
      }
      ld=m;
      valarray<double> v=p[x]-c;
      c+=v*w;
    }
    cout.precision(5);
    cout<<fixed<<ld<<endl;
  }
}
```


### Prompt

Generate a CPP solution to the following problem:

Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.

Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.

Jzzhu wonders how to get the maximum possible number of groups. Can you help him?

Input

A single integer n (1 ≤ n ≤ 105), the number of the apples.

Output

The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.

If there are several optimal answers you can print any of them.

Examples

Input

6

Output

2
6 3
2 4

Input

9

Output

3
9 3
2 4
6 8

Input

2

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200002;
int n, used[N];
vector<int> ds[N], ans;
int gcd(int l, int r) { return !l ? r : gcd(r % l, l); }
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++)
    if (i % 2 && !used[i])
      for (int j = i; j <= n; j += i) {
        if (!used[j]) ds[i].push_back(j);
        used[j] = 1;
      }
  for (int i = 2; i + i <= n; i++)
    if (ds[i].size()) {
      if (ds[i].size() % 2) {
        used[ds[i][1]] = 0;
        ds[i][1] = ds[i].back();
        ds[i].pop_back();
      }
      while (ds[i].size()) {
        ans.push_back(ds[i].back());
        ds[i].pop_back();
      }
    }
  for (int i = 2; i <= n; i += 2)
    if (!used[i]) ds[2].push_back(i);
  for (int i = 2; i <= ds[2].size(); i += 2) {
    ans.push_back(ds[2][i - 1]);
    ans.push_back(ds[2][i - 2]);
  }
  cout << ans.size() / 2 << endl;
  while (ans.size()) {
    cout << ans.back();
    ans.pop_back();
    cout << " " << ans.back() << endl;
    ans.pop_back();
  }
  cin >> n;
}

```


### Prompt

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

Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.

Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.

Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.

Input

The first line of input will be a single string s (1 ≤ |s| ≤ 50), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z').

Output

Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.

Examples

Input

abcd

Output

4

Input

bbb

Output

1

Input

yzyz

Output

2

Note

For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".

For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".

For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string in;
set<string> s;
int main(int argc, char const *argv[]) {
  while (cin >> in) {
    int len = in.length();
    for (int i = 0; i < len; i++) {
      in += in[i];
    }
    for (int i = 0; i < len; i++) {
      string tmp;
      for (int j = 0; j < len; j++) {
        tmp += in[i + j];
      }
      s.insert(tmp);
    }
    cout << s.size() << endl;
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There are n parrots standing in a circle. Each parrot has a certain level of respect among other parrots, namely r_i. When a parrot with respect level x starts chattering, x neighbours to the right and to the left of it start repeating the same words in 1 second. Their neighbours then start repeating as well, and so on, until all the birds begin to chatter.

You are given the respect levels of all parrots. For each parrot answer a question: if this certain parrot starts chattering, how many seconds will pass until all other birds will start repeating it?

Input

In the first line of input there is a single integer n, the number of parrots (1 ≤ n ≤ 10^5).

In the next line of input there are n integers r_1, ..., r_n, the respect levels of parrots in order they stand in the circle (1 ≤ r_i ≤ n).

Output

Print n integers. i-th of them should equal the number of seconds that is needed for all parrots to start chattering if the i-th parrot is the first to start.

Examples

Input

4
1 1 4 1

Output

2 2 1 2

Input

8
1 2 2 1 5 1 3 1

Output

3 3 2 2 1 2 2 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[100007 * 3];
pair<int, int> seg[17][100007 * 3], Seg[17][100007 * 12];
void Build(int i, int k, int l, int r) {
  if (l == r) {
    Seg[i][k] = seg[i][l];
    return;
  }
  int mid = (l + r) >> 1;
  Build(i, k * 2, l, mid);
  Build(i, k * 2 + 1, mid + 1, r);
  Seg[i][k].first = min(Seg[i][k * 2].first, Seg[i][k * 2 + 1].first);
  Seg[i][k].second = max(Seg[i][k * 2].second, Seg[i][k * 2 + 1].second);
}
int fst, sec;
void Get(int i, int k, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    fst = min(fst, Seg[i][k].first);
    sec = max(sec, Seg[i][k].second);
    return;
  }
  int res = 1, mid = (l + r) >> 1;
  if (L <= mid) Get(i, k * 2, l, mid, L, R);
  if (R > mid) Get(i, k * 2 + 1, mid + 1, r, L, R);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[n + i] = a[n * 2 + i] = a[i];
  }
  if (n == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n * 3; ++i) {
    seg[0][i].first = max(i - a[i], 1);
    seg[0][i].second = min(i + a[i], n * 3);
  }
  Build(0, 1, 1, n * 3);
  for (int i = 1; i < 17; ++i) {
    for (int j = 1; j <= n * 3; ++j) {
      fst = seg[i - 1][j].first, sec = seg[i - 1][j].second;
      Get(i - 1, 1, 1, n * 3, fst, sec);
      seg[i][j].first = fst, seg[i][j].second = sec;
    }
    Build(i, 1, 1, n * 3);
  }
  for (int i = 1; i <= n; ++i) {
    int ans = n, cur = 0, l = n + i, r = n + i;
    for (int j = 16; j >= 0; --j) {
      fst = l, sec = r;
      Get(j, 1, 1, n * 3, l, r);
      if (sec - fst + 1 >= n)
        ans = min(ans, cur + (1 << j));
      else
        l = fst, r = sec, cur += 1 << j;
    }
    printf("%d%c", ans, " \n"[i == n]);
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.

There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

Input

The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the maximum final height of the smallest flower.

Examples

Input

6 2 3
2 2 2 2 1 1

Output

2

Input

2 5 1
5 8

Output

9

Note

In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, w, i, step, Max;
int a[100000 + 5], sum[100000 + 5];
bool ok(int l) {
  int crt, m2;
  m2 = m;
  for (int j = 1; j <= n; ++j) sum[j] = 0;
  for (int j = 1; j <= n; ++j) {
    sum[j] += sum[j - 1];
    if (sum[j] + a[j] >= l) continue;
    crt = sum[j] + a[j];
    if (l - crt > m2) return false;
    m2 -= (l - crt);
    sum[j] += (l - crt);
    sum[min(n + 1, j + w)] -= (l - crt);
  }
  return true;
}
int main() {
  scanf("%d%d%d", &n, &m, &w);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    Max = max(Max, a[i] + m);
  }
  for (step = 1; step < Max; step <<= 1)
    ;
  for (i = 0; step; step >>= 1)
    if (i + step <= Max)
      if (ok(i + step)) i += step;
  printf("%d\n", i);
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

"Search" is an operation to obtain the desired information from a large amount of information. Familiar examples include "finding your own exam number from a large number of exam numbers" when announcing your success, or "finding Taro Aizu's phone number" from your phone book. This search operation is also widely used in the computer field.

<image>

There are many ways to search. Consider a search method that can be used when the data to be searched is arranged in ascending (or largest) order.

Using the magnitude relationship between the value located in the center of the data string arranged in ascending order (or in descending order) and the target value, the first half is set as the search range or the second half is searched from the value located in the center. There is a way to narrow down the search range by deciding whether to make it a range. The procedure is as follows.

1. The entire column of data is the scope of the search.
2. Examine the value located in the center of the search range.
3. If the desired value matches the centered value, the search ends.
4. If it is smaller than the target value and the value located in the center, the first half is the search range, and if it is larger, the second half is the search range and returns to 2.

The following is an example of the search method described above. The desired value in this example is 51. Each piece of data is numbered (index), which starts at 0.

Step 1: Initially, the search range is the entire number 0-6.

Step 2: Find the value in the center of the search range. However, the "centered value" is the value at the position of the number obtained by dividing (the number on the left side + the number on the right side) by 2. In other words, in this case, (0 + 6) ÷ 2 is calculated, and the value (36) at number 3 is the value located in the center.

Step 3: Compare the desired value (51) with the centrally located value (36).

Step 4: From the result of step 3, the target value is larger than the value located in the center, so the search range is from number 4 (next to the value located in the center) in the latter half. Use the same procedure to check the value located in the center of the search range, and if the target value is smaller than the value located in the center, the first half is the search range, and if it is larger, the second half is the search range. I will make it smaller. (Repeat of steps 2 to 4) The search ends when the target value matches the value located in the center or the search range is reached.

| <image>
--- | ---

Create a program that takes an array of n numbers as input and outputs the number of times the target value is compared with the value located in the center. However, if the number of the value located in the center is not divisible, the value rounded down to the nearest whole number will be used as the number. It is assumed that the given data columns are sorted in ascending order.

Input

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

n
a1
a2
::
an
k

The number of numbers n (1 ≤ n ≤ 100) is given on the first line, and the i-th number ai (1 ≤ ai ≤ 100000, integer) is given on the following n lines.

The following line is given the value k (1 ≤ k ≤ 100000) to search for.

Output

The number of comparisons until the search is completed for each data set is output on one line.

Example

Input

7
11
15
23
36
51
61
86
51
4
1
2
3
5
4
0

Output

3
3

### Response

```cpp
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int n,s;
	int a[101];
	while(cin >> n){
		if(n == 0)break;
		for(int i = 0; i < n; i++) cin >> a[i];
		cin >> s;

		int left = 0,right = n-1;
		int cnt = 0;
		while(1){
			if(left > right)break;
			int mid = (left + right) / 2;
			cnt++;
			if(a[mid] == s){
				break;
			}
			else if(a[mid] < s){
				left = mid + 1;
			}
			else
				right = mid - 1;
		}
		printf("%d\n",cnt);
	}
	return 0;
}
```


### Prompt

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

Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.

Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.

Input

The first line contains the positive integer a (1 ≤ a ≤ 1000) — the number of lemons Nikolay has.

The second line contains the positive integer b (1 ≤ b ≤ 1000) — the number of apples Nikolay has.

The third line contains the positive integer c (1 ≤ c ≤ 1000) — the number of pears Nikolay has.

Output

Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.

Examples

Input

2
5
7

Output

7

Input

4
7
13

Output

21

Input

2
3
2

Output

0

Note

In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.

In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.

In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 500 + 100, INF = 1e9;
bool vis[MAX];
vector<int> adj[MAX];
int main() {
  int a, b, c, x = 0;
  cin >> a >> b >> c;
  for (int i = 1;; i++) {
    if (a >= i && (b >= 2 * i && c >= 4 * i))
      x = i;
    else
      break;
  }
  cout << 7 * x;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given a permutation p. Calculate the total number of inversions in all permutations that lexicographically do not exceed the given one.

As this number can be very large, print it modulo 1000000007 (109 + 7).

Input

The first line contains a single integer n (1 ≤ n ≤ 106) — the length of the permutation. The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n).

Output

Print a single number — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

2
2 1

Output

1

Input

3
2 1 3

Output

2

Note

Permutation p of length n is the sequence that consists of n distinct integers, each of them is from 1 to n.

An inversion of permutation p1, p2, ..., pn is a pair of indexes (i, j), such that i < j and pi > pj.

Permutation a do not exceed permutation b lexicographically, if either a = b or there exists such number i, for which the following logical condition fulfills: <image> AND (ai < bi).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 20;
const long long mod = 1e9 + 7;
struct node {
  int lazy, t;
  long long sum;
  node() { lazy = t = sum = 0; }
};
node seg[maxn * 4];
int a[maxn];
long long fac[maxn];
node merge(node a, node b) {
  node c;
  c.sum = a.sum + b.sum;
  c.t = a.t + b.t;
  return c;
}
void build(int s, int e, int v) {
  if (e - s < 2) {
    seg[v].sum = s;
    return;
  }
  int m = (s + e) / 2;
  build(s, m, 2 * v);
  build(m, e, 2 * v + 1);
  seg[v] = merge(seg[2 * v], seg[2 * v + 1]);
}
void rem(int p, int s, int e, int v) {
  if (e - s < 2) {
    seg[v].sum = 0;
    seg[v].t = 1;
    return;
  }
  int m = (s + e) / 2;
  if (p < m)
    rem(p, s, m, 2 * v);
  else
    rem(p, m, e, 2 * v + 1);
  seg[v] = merge(seg[2 * v], seg[2 * v + 1]);
}
void ok(long long s, long long e, int v, long long val) {
  seg[v].sum += (e - s - seg[v].t) * val;
  seg[v].lazy += val;
}
void shift(int s, int e, int v) {
  if (e - s >= 2 && seg[v].lazy != 0) {
    int m = (s + e) / 2;
    ok(s, m, 2 * v, seg[v].lazy);
    ok(m, e, 2 * v + 1, seg[v].lazy);
  }
  seg[v].lazy = 0;
}
void add(int l, int r, int val, int s, int e, int v) {
  if (l <= s && e <= r) {
    ok(s, e, v, val);
    return;
  }
  if (r <= s || e <= l) return;
  shift(s, e, v);
  int m = (s + e) / 2;
  add(l, r, val, s, m, 2 * v);
  add(l, r, val, m, e, 2 * v + 1);
  seg[v] = merge(seg[2 * v], seg[2 * v + 1]);
}
long long get(int l, int r, int s, int e, int v) {
  if (l <= s && e <= r) return seg[v].sum % mod;
  if (r <= s || e <= l) return 0;
  shift(s, e, v);
  int m = (s + e) / 2;
  return (get(l, r, s, m, 2 * v) + get(l, r, m, e, 2 * v + 1)) % mod;
}
int get_r(int l, int r, int s, int e, int v) {
  if (l <= s && e <= r) return seg[v].t;
  if (r <= s || e <= l) return 0;
  int m = (s + e) / 2;
  return get_r(l, r, s, m, 2 * v) + get_r(l, r, m, e, 2 * v + 1);
}
long long f(long long x) { return (x * (x - 1) / 2) % mod; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  fac[2] = 1;
  for (long long i = 3; i < maxn; i++) fac[i] = (fac[i - 1] * i) % mod;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
  build(0, n, 1);
  long long res = 0, tmp = 0;
  for (int i = 0; i < n; i++) {
    long long k = a[i] - get_r(0, a[i], 0, n, 1);
    long long w = ((n - i - 1 < 2) ? 1 : fac[n - i - 1] * 2) % mod;
    res += (((fac[n - i - 1] * f(n - i - 1)) % mod) * k) % mod;
    res += (w * get(0, a[i], 0, n, 1)) % mod;
    res += (((tmp * w) % mod) * k) % mod;
    res %= mod;
    tmp += get(a[i], a[i] + 1, 0, n, 1);
    rem(a[i], 0, n, 1);
    tmp %= mod;
    add(a[i], n, -1, 0, n, 1);
  }
  res += tmp;
  cout << res % mod << endl;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Constraints

* 1≦A,B,C≦10

Input

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

A B C

Output

If it is possible to construct a Haiku by using each of the phrases once, print `YES` (case-sensitive). Otherwise, print `NO`.

Examples

Input

5 5 7

Output

YES

Input

7 7 5

Output

NO

### Response

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

int main(){
int a,b,c;
cin>>a>>b>>c;
if(a+b+c==17&&(a==5||b==5||c==5)&&(a==7||b==7||c==7))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.

A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.

Input

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

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print the maximum length of an increasing subarray of the given array.

Examples

Input

5
1 7 2 11 15

Output

3

Input

6
100 100 100 100 100 100

Output

1

Input

3
1 2 3

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int a[100009] = {0};
int main() {
  int i, j, k;
  int n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  int pre = 1;
  int c = 0;
  for (i = 0; i < n; i++) {
    if (a[i] > pre) {
      c++;
      pre = a[i];
    } else {
      ans = max(ans, c);
      c = 1;
      pre = a[i];
    }
  }
  ans = max(ans, c);
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

Peter is a person with erratic sleep habits. He goes to sleep at twelve o'lock every midnight. He gets up just after one hour of sleep on some days; he may even sleep for twenty-three hours on other days. His sleeping duration changes in a cycle, where he always sleeps for only one hour on the first day of the cycle.

Unfortunately, he has some job interviews this month. No doubt he wants to be in time for them. He can take anhydrous caffeine to reset his sleeping cycle to the beginning of the cycle anytime. Then he will wake up after one hour of sleep when he takes caffeine. But of course he wants to avoid taking caffeine as possible, since it may affect his health and accordingly his very important job interviews.

Your task is to write a program that reports the minimum amount of caffeine required for Peter to attend all his interviews without being late, where the information about the cycle and the schedule of his interviews are given. The time for move to the place of each interview should be considered negligible.

Input

The input consists of multiple datasets. Each dataset is given in the following format:

T
t1 t2 ... tT
N
D1 M1
D2 M2
...
DN MN

T is the length of the cycle (1 ≤ T ≤ 30); ti (for 1 ≤ i ≤ T ) is the amount of sleep on the i-th day of the cycle, given in hours (1 ≤ ti ≤ 23); N is the number of interviews (1 ≤ N ≤ 100); Dj (for 1 ≤ j ≤ N) is the day of the j-th interview (1 ≤ Dj ≤ 100); Mj (for 1 ≤ j ≤ N) is the hour when the j-th interview starts (1 ≤ Mj ≤ 23).

The numbers in the input are all integers. t1 is always 1 as stated above. The day indicated by 1 is the first day in the cycle of Peter's sleep.

The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed.

Output

For each dataset, print the minimum number of times Peter needs to take anhydrous caffeine.

Example

Input

2
1 23
3
1 1
2 1
3 1
0

Output

2

### Response

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

using namespace std;

static const int INF = (1<<20);

int T, t[30], N, D, M, dp[101][30], m[101];

int main(){
  while(cin >> T && T){
    for(int i=0;i<T;i++) cin >> t[i];
    cin >> N;
    fill(m, m+101, INF);
    for(int i=0;i<N;i++){
      cin >> D >> M;
      m[D-1] = min(m[D-1], M);
    }
    fill(dp[0], dp[101], INF);
    dp[0][0] = 0;
    for(int i=0;i<100;i++){
      for(int j=0;j<T;j++){
        if(t[j] <= m[i]){
          dp[i+1][(j+1)%T] = min(dp[i+1][(j+1)%T], dp[i][j]);
          dp[i+1][0] = min(dp[i+1][0], dp[i][j]+1);
        }
      }
    }
    int ans = INF;
    for(int i=0;i<T;i++) ans = min(ans, dp[100][i]);
    cout << ans << endl;
  }
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality:

a + b + c + d = n

For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).

Input

The input consists of several datasets. Each dataset consists of n (1 ≤ n ≤ 50) in a line. The number of datasets is less than or equal to 50.

Output

Print the number of combination in a line.

Example

Input

35
1

Output

4
4

### Response

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

int res;
int n;

void dfs(int u, int all)
{
	if(u == 4)
	{
		if(all == n) res ++;
		return;
	}

	for(int i = 0; i < 10; i ++ )
		dfs(u + 1, all + i);
}

int main()
{
	while(cin >> n)
	{
		res = 0;

		dfs(0, 0);

		cout << res << endl;
	}
}

```


### Prompt

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

Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he has m queries:

  * Query number i is represented as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).
  * The answer to the query li, ri is the number of pairs of integers q, w (li ≤ q, w ≤ ri) such that pq is the divisor of pw.

Help Yaroslav, answer all his queries.

Input

The first line contains the integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). The following m lines contain Yaroslav's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n).

Output

Print m integers — the answers to Yaroslav's queries in the order they appear in the input.

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

Examples

Input

1 1
1
1 1

Output

1

Input

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

Output

27
14
8
4
2
1
2
7
9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 2e5 + 5;
int tree[SIZE], n, m, N, p[SIZE], indx[SIZE], res[SIZE];
pair<int, int> divP[18 * SIZE];
struct data {
  int u, v, p;
} queries[SIZE];
bool compare(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
bool compareD(const data &a, const data &b) { return a.v < b.v; }
void Input() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    indx[p[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    queries[i] = {x, y, i};
  }
}
void make_Div_pair() {
  for (int i = 1; i <= n; i++) {
    for (int pj = p[i]; pj <= n; pj += p[i]) {
      int j = indx[pj];
      divP[++N] = (i < j) ? make_pair(i, j) : make_pair(j, i);
    }
  }
}
int sum(int u) {
  int temp = 0;
  for (; u > 0; u -= (u & -u)) temp += tree[u];
  return temp;
}
int get_sum(int u, int v) { return sum(v) - sum(u - 1); }
void update(int u, int val) {
  for (; u <= n; u += (u & -u)) tree[u] += val;
}
void Solve() {
  make_Div_pair();
  sort(divP + 1, divP + N + 1, compare);
  sort(queries + 1, queries + m + 1, compareD);
  int now = 1;
  for (int i = 1; i <= m; i++) {
    int u = queries[i].u;
    int v = queries[i].v;
    int p = queries[i].p;
    while (now <= N && divP[now].second <= v) {
      update(divP[now].first, 1);
      now++;
    }
    res[p] = get_sum(u, v);
  }
}
void Print() {
  for (int i = 1; i <= m; i++) cout << res[i] << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Input();
  Solve();
  Print();
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to n in order.

The stones always fall to the center of Liss's interval. When Liss occupies the interval [k - d, k + d] and a stone falls to k, she will escape to the left or to the right. If she escapes to the left, her new interval will be [k - d, k]. If she escapes to the right, her new interval will be [k, k + d].

You are given a string s of length n. If the i-th character of s is "l" or "r", when the i-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the n stones falls.

Input

The input consists of only one line. The only line contains the string s (1 ≤ |s| ≤ 106). Each character in s will be either "l" or "r".

Output

Output n lines — on the i-th line you should print the i-th stone's number from the left.

Examples

Input

llrlr

Output

3
5
4
2
1

Input

rrlll

Output

1
2
5
4
3

Input

lrlrr

Output

2
4
5
3
1

Note

In the first example, the positions of stones 1, 2, 3, 4, 5 will be <image>, respectively. So you should print the sequence: 3, 5, 4, 2, 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1000001];
int main() {
  int i, l;
  string s;
  cin >> s;
  l = s.size();
  int rt = l - 1, lt = 0, st = 1;
  for (i = 0; i < l; i++) {
    if (s[i] == 'r') {
      a[lt] = st;
      st++;
      lt++;
    } else {
      a[rt] = st;
      st++;
      rt--;
    }
  }
  for (i = 0; i < l; i++) printf("%d\n", a[i]);
  return 0;
}

```


### Prompt

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

For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows:

* f(b,n) = n, when n < b
* f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b

Here, {\rm floor}(n / b) denotes the largest integer not exceeding n / b, and n \ {\rm mod} \ b denotes the remainder of n divided by b.

Less formally, f(b,n) is equal to the sum of the digits of n written in base b. For example, the following hold:

* f(10,\,87654)=8+7+6+5+4=30
* f(100,\,87654)=8+76+54=138

You are given integers n and s. Determine if there exists an integer b (b \geq 2) such that f(b,n)=s. If the answer is positive, also find the smallest such b.

Constraints

* 1 \leq n \leq 10^{11}
* 1 \leq s \leq 10^{11}
* n,\,s are integers.

Input

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

n
s

Output

If there exists an integer b (b \geq 2) such that f(b,n)=s, print the smallest such b. If such b does not exist, print `-1` instead.

Examples

Input

87654
30

Output

10

Input

87654
138

Output

100

Input

87654
45678

Output

-1

Input

31415926535
1

Output

31415926535

Input

1
31415926535

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,s;
ll f( ll b,ll n)
{
  return n<b?n:f(b,n/b)+n%b;
}
int main()
{
  scanf("%lld%lld",&n,&s);
  if(s>n)return puts("-1"),0;
  if(s==n)return printf("%lld\n",n+1),0;
  ll m=sqrt(n)+1;
  for(ll i=2; i<=m; ++i)
    if(f(i,n)==s)return printf( "%lld",i),0;
  ll ans=1e11;
  n-=s;
  for( ll i=1; i*i<=n; ++i)
    if(n%i==0)
    {
      ll b=n/i+1;
      if(f(b,n+s)==s)ans=min(ans,b);
    }
  return printf("%lld\n",ans!=1e11?ans:-1),0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

Takahashi has many red balls and blue balls. Now, he will place them in a row.

Initially, there is no ball placed.

Takahashi, who is very patient, will do the following operation 10^{100} times:

* Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.

How many blue balls will be there among the first N balls in the row of balls made this way?

Constraints

* 1 \leq N \leq 10^{18}
* A, B \geq 0
* 0 < A + B \leq 10^{18}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of blue balls that will be there among the first N balls in the row of balls.

Examples

Input

8 3 4

Output

4

Input

8 0 4

Output

0

Input

6 2 4

Output

2

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
	cin>>n>>a>>b;
	long long ans=n/(a+b)*a+(n%(a+b)>a?a:(n%(a+b)));
	cout<<ans;
	return 0;
}

```


### Prompt

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

Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to learn those letters. That's why he decided to lose some part of the string (not necessarily a connected part). The lost part can consist of any number of segments of any length, at any distance from each other. However, Gerald knows that if he loses more than k characters, it will be very suspicious.

Find the least number of distinct characters that can remain in the string after no more than k characters are deleted. You also have to find any possible way to delete the characters.

Input

The first input data line contains a string whose length is equal to n (1 ≤ n ≤ 105). The string consists of lowercase Latin letters. The second line contains the number k (0 ≤ k ≤ 105).

Output

Print on the first line the only number m — the least possible number of different characters that could remain in the given string after it loses no more than k characters.

Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly m distinct characters. The final string should be the subsequence of the initial string. If Gerald can get several different strings with exactly m distinct characters, print any of them.

Examples

Input

aaaaa
4

Output

1
aaaaa

Input

abacaba
4

Output

1
aaaa

Input

abcdefgh
10

Output

0

Note

In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.

In the second sample you are allowed to delete 4 characters. You cannot delete all the characters, because the string has length equal to 7. However, you can delete all characters apart from "a" (as they are no more than four), which will result in the "aaaa" string.

In the third sample you are given a line whose length is equal to 8, and k = 10, so that the whole line can be deleted. The correct answer is 0 and an empty string.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[500];
bool mark[1000];
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int k;
  cin >> k;
  int ans = 0;
  int MAX = 0;
  for (int i = 0; i < n; i++) {
    if (a[s[i]] == 0) ans++;
    a[s[i]]++;
    if (a[s[i]] > a[MAX]) MAX = s[i];
  }
  for (int i = 0; i < n; i++) {
    int minin = MAX;
    for (int j = 0; j < n; j++) {
      if (a[s[j]] < a[minin] && a[s[j]] > 0) minin = s[j];
    }
    if (k >= a[minin]) {
      mark[minin] = true;
      k -= a[minin];
      ans--;
      a[minin] = 10000000;
    } else
      break;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++)
    if (!mark[s[i]]) cout << s[i];
  cout << endl;
  return 0;
}

```


### Prompt

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

The only difference between easy and hard versions is constraints.

There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers from 1 to n (i.e. p is a permutation). The sequence p doesn't change from day to day, it is fixed.

For example, if n=6 and p=[4, 6, 1, 3, 5, 2] then at the end of the first day the book of the 1-st kid will belong to the 4-th kid, the 2-nd kid will belong to the 6-th kid and so on. At the end of the second day the book of the 1-st kid will belong to the 3-th kid, the 2-nd kid will belong to the 2-th kid and so on.

Your task is to determine the number of the day the book of the i-th child is returned back to him for the first time for every i from 1 to n.

Consider the following example: p = [5, 1, 2, 4, 3]. The book of the 1-st kid will be passed to the following kids:

  * after the 1-st day it will belong to the 5-th kid,
  * after the 2-nd day it will belong to the 3-rd kid,
  * after the 3-rd day it will belong to the 2-nd kid,
  * after the 4-th day it will belong to the 1-st kid.

So after the fourth day, the book of the first kid will return to its owner. The book of the fourth kid will return to him for the first time after exactly one day.

You have to answer q independent queries.

Input

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

The first line of the query contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of kids in the query. The second line of the query contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, all p_i are distinct, i.e. p is a permutation), where p_i is the kid which will get the book of the i-th kid.

It is guaranteed that ∑ n ≤ 2 ⋅ 10^5 (sum of n over all queries does not exceed 2 ⋅ 10^5).

Output

For each query, print the answer on it: n integers a_1, a_2, ..., a_n, where a_i is the number of the day the book of the i-th child is returned back to him for the first time in this query.

Example

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr int MOD = 998244353;
struct UnionFind {
  vector<int> par, weight;
  UnionFind(int n) : par(n, -1), weight(n) {}
  void unite(int x, int y, int w = 0) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (par[x] > par[y]) swap(x, y), w = -w;
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) {
    if (par[x] < 0) return x;
    int r = find(par[x]);
    return par[x] = r;
  }
  int sizeOf(int x) { return -par[find(x)]; }
};
int q, n, a[200020], b[200020];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    UnionFind uf(n + 1);
    for (int i = 1; i <= n; ++i) uf.unite(i, a[i]);
    for (int i = 1; i <= n; ++i) cout << uf.sizeOf(i) << " \n"[n == i];
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Polycarp has 26 tasks. Each task is designated by a capital letter of the Latin alphabet.

The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.

Polycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.

For example, if Polycarp solved tasks in the following order: "DDBBCCCBBEZ", then the teacher will see that on the third day Polycarp began to solve the task 'B', then on the fifth day he got distracted and began to solve the task 'C', on the eighth day Polycarp returned to the task 'B'. Other examples of when the teacher is suspicious: "BAB", "AABBCCDDEEBZZ" and "AAAAZAAAAA".

If Polycarp solved the tasks as follows: "FFGZZZY", then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn't have any suspicious: "BA", "AFFFCC" and "YYYYY".

Help Polycarp find out if his teacher might be suspicious.

Input

The first line contains an integer t (1 ≤ t ≤ 1000). Then t test cases follow.

The first line of each test case contains one integer n (1 ≤ n ≤ 50) — the number of days during which Polycarp solved tasks.

The second line contains a string of length n, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.

Output

For each test case output:

  * "YES", if the teacher cannot be suspicious;
  * "NO", otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

Example

Input

5
3
ABA
11
DDBBCCCBBEZ
7
FFGZZZY
1
Z
2
AB

Output

NO
NO
YES
YES
YES

### Response

```cpp
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD  998244353//1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef  long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef ll ValType;
template<typename  T> void maxtt(T& t1, T t2) {
    t1=max(t1,t2);
}
template<typename  T> void mintt(T& t1, T t2) {
    t1=min(t1,t2);
}
#define MAX (135)

bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
const ll MOD2 = (ll)MOD * (ll)MOD;
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD){
    x+=y; if (x>=mod) x-=mod;
    if(x<0) x+=mod;
    assert(x>=0 && x<mod);
}
void et(int x=-1) {
    printf("%d\n", x); exit(0);
}
ll fastPow(ll x, ll y, int mod=MOD) {
    ll ans = 1;
    while(y>0) {
        if(y&1) ans = (x * ans)%mod;
        x = x*x%mod;
        y>>=1;
    }
    return ans;
}
ll gcd1(ll x, ll y) {
    return y?gcd1(y,x%y):x;
}

//#include <atcoder/all>
//using mint = atcoder::modint1000000007;

char s[MAX];
void fmain(int tid) {
    scanf("%d", &n);
    scanf("%s", s+1);
    vector<char> vp;
    REQ(i,n) {
        if(vp.empty() || vp.back()!=s[i]) {
            vp.push_back(s[i]);
        }
    }
    sort(vp.begin(), vp.end());
    int N=unique(vp.begin(),vp.end())-vp.begin();
    if(N==vp.size()) {
        puts("YES");
    } else puts("NO");
}
int main() {
//    freopen("smallrand2.in","r",stdin);
//    freopen("output.txt","w",stdout);
    int t=1;
//    init();
    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at the integer points of the plane. At each integer point which belongs to the table perimeter there is a chair in which a general sits.

Some points on the plane contain radiators for the generals not to freeze in winter. Each radiator is characterized by the number ri — the radius of the area this radiator can heat. That is, if the distance between some general and the given radiator is less than or equal to ri, than the general feels comfortable and warm. Here distance is defined as Euclidean distance, so the distance between points (x1, y1) and (x2, y2) is <image>

Each general who is located outside the radiators' heating area can get sick. Thus, you should bring him a warm blanket. Your task is to count the number of warm blankets you should bring to the Super Duper Secret Place.

The generals who are already comfortable do not need a blanket. Also the generals never overheat, ever if they are located in the heating area of several radiators. The radiators can be located at any integer points on the plane, even inside the rectangle (under the table) or on the perimeter (directly under some general). Even in this case their radius does not change.

Input

The first input line contains coordinates of two opposite table corners xa, ya, xb, yb (xa ≠ xb, ya ≠ yb). The second line contains integer n — the number of radiators (1 ≤ n ≤ 103). Then n lines contain the heaters' coordinates as "xi yi ri", the numbers are separated by spaces. All input data numbers are integers. The absolute value of all coordinates does not exceed 1000, 1 ≤ ri ≤ 1000. Several radiators can be located at the same point.

Output

Print the only number — the number of blankets you should bring.

Examples

Input

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

Output

4

Input

5 2 6 3
2
6 2 2
6 5 3

Output

0

Note

In the first sample the generals are sitting at points: (2, 2), (2, 3), (2, 4), (2, 5), (3, 2), (3, 5), (4, 2), (4, 3), (4, 4), (4, 5). Among them, 4 generals are located outside the heating range. They are the generals at points: (2, 5), (3, 5), (4, 4), (4, 5).

In the second sample the generals are sitting at points: (5, 2), (5, 3), (6, 2), (6, 3). All of them are located inside the heating range.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 1;
struct Point {
  int x, y;
  double r;
} P[MAXN];
int xa, ya, xb, yb;
int n;
bool DIS(int x, int y) {
  for (int i = 0; i < n; i++) {
    double dis =
        ((x - P[i].x) * (x - P[i].x) + (y - P[i].y) * (y - P[i].y)) * 1.0;
    if (dis <= P[i].r * P[i].r) return false;
  }
  return true;
}
bool run() {
  if (scanf("%d%d%d%d", &xa, &ya, &xb, &yb) == EOF) return false;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%lf", &P[i].x, &P[i].y, &P[i].r);
  }
  int ans = 0;
  int MinX = min(xa, xb);
  int MaxX = max(xa, xb);
  int MinY = min(ya, yb);
  int MaxY = max(ya, yb);
  for (int i = MinX; i <= MaxX; i++) {
    if (DIS(i, MinY)) ans++;
  }
  for (int i = MinX; i <= MaxX; i++) {
    if (DIS(i, MaxY)) ans++;
  }
  for (int i = MinY + 1; i < MaxY; i++) {
    if (DIS(MinX, i)) ans++;
  }
  for (int i = MinY + 1; i < MaxY; i++) {
    if (DIS(MaxX, i)) ans++;
  }
  printf("%d\n", ans);
  return true;
}
int main() {
  while (run())
    ;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Let N be a positive odd number.

There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.

Taro has tossed all the N coins. Find the probability of having more heads than tails.

Constraints

* N is an odd number.
* 1 \leq N \leq 2999
* p_i is a real number and has two decimal places.
* 0 < p_i < 1

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 \ldots p_N

Output

Print the probability of having more heads than tails. The output is considered correct when the absolute error is not greater than 10^{-9}.

Examples

Input

3
0.30 0.60 0.80

Output

0.612

Input

1
0.50

Output

0.5

Input

5
0.42 0.01 0.42 0.99 0.42

Output

0.3821815872

### Response

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

int main(void){
	int n;
	cin>>n;
	double *DP=new double[n+1];
	DP[0]=1;
	for(int i=1;i<=n;i++) DP[i]=0;

	for(int i=0;i<n;i++){
		double p;
		cin>>p;
		for(int j=i+1;j>0;j--){
			DP[j]=DP[j]*(1-p)+DP[j-1]*p;
		}
		DP[0]*=(1-p);
	}

	double ans=0;
	for(int i=n;i>n/2;i--){
		ans+=DP[i];
	}

	printf("%.10f\n",ans);

	return 0;
}

```


### Prompt

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

In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any city you can get to any other one by moving along the roads.

You want to destroy the largest possible number of roads in the country so that the remaining roads would allow you to get from city s1 to city t1 in at most l1 hours and get from city s2 to city t2 in at most l2 hours.

Determine what maximum number of roads you need to destroy in order to meet the condition of your plan. If it is impossible to reach the desired result, print -1.

Input

The first line contains two integers n, m (1 ≤ n ≤ 3000, <image>) — the number of cities and roads in the country, respectively.

Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are given in the description can transport you from any city to any other one. It is guaranteed that each pair of cities has at most one road between them.

The last two lines contains three integers each, s1, t1, l1 and s2, t2, l2, respectively (1 ≤ si, ti ≤ n, 0 ≤ li ≤ n).

Output

Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.

Examples

Input

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

Output

0

Input

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

Output

1

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<vector<int>> d(n, vector<int>(n, -1));
  for (int i = 0; i < n; i++) {
    queue<int> q;
    q.push(i);
    d[i][i] = 0;
    while (!q.empty()) {
      auto v = q.front();
      q.pop();
      for (int j = 0; j < g[v].size(); j++) {
        auto v2 = g[v][j];
        if (d[i][v2] == -1) {
          d[i][v2] = d[i][v] + 1;
          q.push(v2);
        }
      }
    }
  }
  int s[2], t[2], l[2];
  for (int i = 0; i < 2; i++) {
    cin >> s[i] >> t[i] >> l[i];
    s[i]--;
    t[i]--;
  }
  int minEdges = m + 1;
  for (int k = 0; k < 2; k++) {
    swap(s[0], t[0]);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        auto route0 = d[s[0]][i] + d[i][j] + d[j][t[0]];
        auto route1 = d[s[1]][i] + d[i][j] + d[j][t[1]];
        if (route0 <= l[0] && route1 <= l[1]) {
          minEdges = min(minEdges, route0 + route1 - d[i][j]);
        }
      }
    }
  }
  auto route0 = d[s[0]][t[0]];
  auto route1 = d[s[1]][t[1]];
  if (route0 <= l[0] && route1 <= l[1]) {
    minEdges = min(minEdges, route0 + route1);
  }
  int result = 0;
  if (minEdges > m) {
    result = -1;
  } else {
    result = m - minEdges;
  }
  cout << result << endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Takahashi is meeting up with Aoki.

They have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.

Takahashi will leave his house now and go straight to the place at a speed of S meters per minute.

Will he arrive in time?

Constraints

* 1 \leq D \leq 10000
* 1 \leq T \leq 10000
* 1 \leq S \leq 10000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

D T S

Output

If Takahashi will reach the place in time, print `Yes`; otherwise, print `No`.

Examples

Input

1000 15 80

Output

Yes

Input

2000 20 100

Output

Yes

Input

10000 1 1

Output

No

### Response

```cpp
#include<stdio.h>
int main()
{
	int d,t,s;
	scanf("%d %d %d",&d,&t,&s);
	if(d<=t*s)printf("Yes");
	else printf("No");
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number <image>, in particular that q2 = q + 1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a0a1...an equals to <image>.

Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help.

Given two numbers written in golden system notation, determine which of them has larger decimal value.

Input

Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000.

Output

Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal.

Examples

Input

1000
111

Output

<

Input

00100
11

Output

=

Input

110
101

Output

>

Note

In the first example first number equals to <image>, while second number is approximately 1.6180339882 + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number.

In the second example numbers are equal. Each of them is  ≈ 2.618.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 1000;
int a1[MAX], a2[MAX];
int main() {
  string a, b;
  cin >> a >> b;
  for (int i = a.length() - 1; i >= 0; i--) a1[a.length() - i - 1] = a[i] - '0';
  for (int i = b.length() - 1; i >= 0; i--) a2[b.length() - i - 1] = b[i] - '0';
  for (int i = MAX - 10; i >= 0; i--) {
    for (int j = i; a1[j] && a1[j + 1]; j += 2)
      a1[j] = a1[j + 1] = 0, a1[j + 2] = 1;
    for (int j = i; a2[j] && a2[j + 1]; j += 2)
      a2[j] = a2[j + 1] = 0, a2[j + 2] = 1;
  }
  for (int i = MAX - 1; i >= 0; i--)
    if (a1[i] > a2[i])
      return cout << '>', 0;
    else if (a1[i] < a2[i])
      return cout << '<', 0;
  cout << '=';
}

```


### Prompt

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

You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the first characters of these strings are distinct.

Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist.

Input

The first line contains a positive integer k (1 ≤ k ≤ 26) — the number of strings that should be in a beautiful sequence.

The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive.

Output

If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next k lines print the beautiful sequence of strings s1, s2, ..., sk.

If there are multiple possible answers, print any of them.

Examples

Input

1
abca

Output

YES
abca

Input

2
aaacas

Output

YES
aaa
cas

Input

4
abc

Output

NO

Note

In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<char> arr;
  string str;
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    arr.insert(str[i]);
  }
  if (arr.size() < n) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
    set<char> temp;
    cout << str[0];
    int ctr = 1;
    temp.insert(str[0]);
    int i;
    for (i = 1; i < str.size(); i++) {
      if (temp.count(str[i]))
        cout << str[i];
      else {
        ctr++;
        temp.insert(str[i]);
        if (ctr > n) {
          break;
        }
        cout << "\n";
        cout << str[i];
      }
    }
    for (int j = i; j < str.size(); j++) cout << str[j];
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.

Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.

Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!

Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!

Input

The first line contains a single integer T (1 ≤ T ≤ 100): the number of bags for which you need to solve the problem.

The first line of each bag description contains a single integer n (2 ≤ n ≤ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.

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

Output

For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.

Example

Input

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

Output

3
2
0
4

Note

For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).

For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
int a[maxn], vis[maxn], num[maxn];
map<int, int> mp;
int cmp(int x, int y) { return x > y; }
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    mp.clear();
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      vis[i] = 0;
      num[i] = 0;
      if (!mp[a[i]]) mp[a[i]] = ++cnt;
      a[i] = mp[a[i]];
    }
    for (int i = 1; i <= n; i++) vis[a[i]]++;
    sort(vis + 1, vis + 1 + cnt, cmp);
    int len = vis[1];
    if (cnt == 1) {
      printf("0\n");
      continue;
    }
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      if (vis[i] == len) vis[i]--;
    }
    len--;
    int now = 1;
    for (int i = 1; i <= cnt; i++) {
      int tmp = vis[i];
      while (tmp) {
        tmp--;
        num[now]++;
        now = now + 1;
        if (now == len + 1) now = 1;
      }
    }
    printf("%d\n", num[len] - 1);
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.

Let us define a function f(r, c) as follows:

* f(r,c) :=  (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)

Given are integers r_1, r_2, c_1, and c_2. Find the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).

Constraints

* 1 ≤ r_1 ≤ r_2 ≤ 10^6
* 1 ≤ c_1 ≤ c_2 ≤ 10^6
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

r_1 c_1 r_2 c_2

Output

Print the sum of f(i, j) modulo (10^9+7).

Examples

Input

1 1 2 2

Output

14

Input

314 159 2653 589

Output

602215194

### Response

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

//  a^b % m
long long powmod(long long a, long long b, long long m)
{
    long long r = 1;
    for (; b>0; b>>=1, a=a*a%m)
        if (b&1)
            r = r*a%m;
    return r;
}

int main()
{
    long long r1, c1, r2, c2;
    cin>>r1>>c1>>r2>>c2;

    long long M = 1000000007;
    vector<long long> F(2000002);
    F[0] = 1;
    for (int i=1; i<=2000001; i++)
        F[i] = F[i-1]*i%M;

    auto C = [&](long long x, long long y)
    {
        return F[x]*powmod(F[y], M-2, M)%M*powmod(F[x-y], M-2, M)%M;
    };

    long long ans = 0;
    for (long long r=r1; r<=r2; r++)
    {
        ans += C(r+c2+1, c2) - C(r+c1, c1-1);
        ans = (ans%M+M)%M;
    }
    cout<<ans<<endl;
}

```


### Prompt

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

Let’s take a prime P = 200\,003. You are given N integers A_1, A_2, \ldots, A_N. Find the sum of ((A_i \cdot A_j) \bmod P) over all N \cdot (N-1) / 2 unordered pairs of elements (i < j).

Please note that the sum isn't computed modulo P.

Constraints

* 2 \leq N \leq 200\,000
* 0 \leq A_i < P = 200\,003
* All values in input are integers.

Input

Input is given from Standard Input in the following format.

N
A_1 A_2 \cdots A_N

Output

Print one integer — the sum over ((A_i \cdot A_j) \bmod P).

Examples

Input

4
2019 0 2020 200002

Output

474287

Input

5
1 1 2 2 100000

Output

600013

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define int long long
const double Pi=acos(-1.0);
const int mod=200003,G=2,N=4000010;
struct CP{
	CP (double xx=0,double yy=0){x=xx,y=yy;}
	double x,y;
	CP operator + (CP const &B) const
	{return CP(x+B.x,y+B.y);}
	CP operator - (CP const &B) const
	{return CP(x-B.x,y-B.y);}
	CP operator * (CP const &B) const
	{return CP(x*B.x-y*B.y,x*B.y+y*B.x);}
};
int tr[N];
void fft(CP *f,int n,int flag){
	for(int i=0;i<n;++i)
		if(i<tr[i]) swap(f[i],f[tr[i]]);
	for(int p=2;p<=n;p<<=1){
		int len=p>>1;
		CP tg(cos(2*Pi/p),sin(2*Pi/p));
		if(flag==-1) tg.y*=-1;
		for(int k=0;k<n;k+=p){
			CP buf(1,0),tt;
			for(int l=k;l<k+len;++l)
				tt=buf*f[l+len],
				f[l+len]=f[l]-tt,
				f[l]=f[l]+tt,
				buf=buf*tg;
		}
	}
	if(flag==-1){
		for(int i=0;i<n;++i)
			f[i].x/=n;
	}
}
CP f[N];
int Lg[N],a[N],g[N];
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1;
	}
	return res;
}
void init(){
	int x=1;
	for(int i=0;i<mod-1;++i)
		g[i]=x,Lg[x]=i,x=x*G%mod;
	//for(int i=0;i<mod-1;++i)
	//	cout<<g[i]<<" ";cout<<endl;
	//cout<<"egerdf\n";
}
signed main(){
//	freopen("2.out","w",stdout);
	init();
	int n,x;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i])f[Lg[a[i]]].x++;
	}
	int limit=1;
	while(limit<=((mod-1)<<1)) limit<<=1;
	//cout<<limit<<endl;
	for(int i=0;i<limit;++i)
		tr[i]=(tr[i>>1]>>1)|(i&1?limit>>1:0);
	//cout<<"segrtryhaw\n";
	fft(f,limit,1);
	for(int i=0;i<limit;++i)
		f[i]=f[i]*f[i];
	fft(f,limit,-1);
	//for(int i=0;i<limit;++i)cout<<f[i].x<<" ";cout<<endl;
	//cout<<"wegrtjrtsfh\n";
	for(int i=1;i<=n;++i)
		if(a[i])f[Lg[a[i]]+Lg[a[i]]].x--;
	int ans=0;
	//cout<<"fgrerttdfbdfgb\n";
	for(int i=0;i<limit;++i)
		ans+=(long long)(f[i].x/2+1e-1)*g[i%(mod-1)];
	cout<<ans;
	return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

You've got an n × m table (n rows and m columns), each cell of the table contains a "0" or a "1".

Your task is to calculate the number of rectangles with the sides that are parallel to the sides of the table and go along the cell borders, such that the number one occurs exactly k times in the rectangle.

Input

The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 2500, 0 ≤ k ≤ 6) — the sizes of the table and the required number of numbers one.

Next n lines each contains m characters "0" or "1". The i-th character of the j-th line corresponds to the character that is in the j-th row and the i-th column of the table.

Output

Print a single number — the number of rectangles that contain exactly k numbers one.

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

Examples

Input

3 3 2
101
000
101

Output

8

Input

5 5 1
00000
00000
00100
00000
00000

Output

81

Input

5 5 6
01010
10101
01010
10101
01010

Output

12

Input

3 3 0
001
010
000

Output

15

Input

4 4 0
0000
0101
0000
0000

Output

52

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int K;
int grid[2][2505][2505];
int up[2505][8], up_sum[2505][8];
int down[2505][8], down_sum[2505][8];
long long compute(int x1, int y1, int x2, int y2, int d) {
  if (x1 == x2 && y1 == y2) {
    return grid[d][x1][y1] - grid[d][x1 - 1][y1] == K;
  }
  if (x2 - x1 < y2 - y1) {
    swap(x1, y1);
    swap(x2, y2);
    d ^= 1;
  }
  int mid = (x1 + x2) >> 1;
  long long ret = 0;
  for (int i = (y1); i < int(y2 + 1); i++) {
    for (int k = 0; k < int(K + 1); k++) {
      up_sum[i][k] = 0;
      down_sum[i][k] = 0;
      up[i][k] = x1;
      down[i][k] = x2;
    }
    for (int j = (i); j < int(y2 + 1); j++) {
      for (int k = 0; k < int(K + 1); k++) {
        up_sum[i][k] += grid[d][mid][j] - grid[d][up[i][k] - 1][j];
        while (up_sum[i][k] > k) {
          up_sum[i][k] -=
              grid[d ^ 1][j][up[i][k]] - grid[d ^ 1][i - 1][up[i][k]];
          up[i][k]++;
        }
        down_sum[i][k] += grid[d][down[i][k]][j] - grid[d][mid][j];
        while (down_sum[i][k] > k) {
          down_sum[i][k] -=
              grid[d ^ 1][j][down[i][k]] - grid[d ^ 1][i - 1][down[i][k]];
          down[i][k]--;
        }
      }
      for (int k = 0; k < int(K + 1); k++) {
        if (up_sum[i][k] != k || down_sum[i][K - k] != K - k) {
          continue;
        }
        int l, r;
        if (k == 0) {
          l = mid - up[i][k] + 1;
        } else {
          l = up[i][k - 1] - up[i][k];
        }
        if (k == K) {
          r = down[i][K - k] - mid;
        } else {
          r = down[i][K - k] - down[i][K - k - 1];
        }
        ret += l * r;
      }
    }
  }
  ret += compute(x1, y1, mid, y2, d);
  ret += compute(mid + 1, y1, x2, y2, d);
  return ret;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int m, n;
  cin >> m >> n >> K;
  for (int i = 0; i < int(m); i++) {
    for (int j = 0; j < int(n); j++) {
      char c;
      cin >> c;
      grid[0][i + 1][j + 1] = c - '0';
      grid[1][j + 1][i + 1] = c - '0';
    }
  }
  for (int i = 0; i < int(m); i++) {
    for (int j = 0; j < int(n); j++) {
      grid[0][i + 1][j + 1] += grid[0][i][j + 1];
      grid[1][j + 1][i + 1] += grid[1][j][i + 1];
    }
  }
  cout << compute(1, 1, m, n, 0);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Petya and Vasya got employed as couriers. During the working day they are to deliver packages to n different points on the line. According to the company's internal rules, the delivery of packages must be carried out strictly in a certain order. Initially, Petya is at the point with the coordinate s1, Vasya is at the point with the coordinate s2, and the clients are at the points x1, x2, ..., xn in the order of the required visit.

The guys agree in advance who of them will deliver the package to which of the customers, and then they act as follows. When the package for the i-th client is delivered, the one who delivers the package to the (i + 1)-st client is sent to the path (it can be the same person who went to the point xi, or the other). The friend who is not busy in delivering the current package, is standing still.

To communicate with each other, the guys have got walkie-talkies. The walkie-talkies work rather poorly at great distances, so Petya and Vasya want to distribute the orders so that the maximum distance between them during the day is as low as possible. Help Petya and Vasya to minimize the maximum distance between them, observing all delivery rules.

Input

The first line contains three integers n, s1, s2 (1 ≤ n ≤ 100 000, 0 ≤ s1, s2 ≤ 109) — number of points of delivery and starting positions of Petya and Vasya.

The second line contains n integers x1, x2, ..., xn — customers coordinates (0 ≤ xi ≤ 109), in the order to make a delivery.

It is guaranteed, that among the numbers s1, s2, x1, ..., xn there are no two equal.

Output

Output the only integer, minimum possible maximal distance between couriers during delivery.

Examples

Input

2 0 10
5 6

Output

10

Input

3 2 1
3 4 5

Output

1

Input

1 4 5
2

Output

2

Note

In the first test case the initial distance between the couriers is 10. This value will be the answer, for example, Petya can perform both deliveries, and Vasya will remain at the starting point.

In the second test case you can optimally act, for example, like this: Vasya delivers the package to the first customer, Petya to the second and, finally, Vasya delivers the package to the third client. With this order of delivery, the distance between the couriers will never exceed 1.

In the third test case only two variants are possible: if the delivery of a single package is carried out by Petya, the maximum distance between them will be 5 - 2 = 3. If Vasya will deliver the package, the maximum distance is 4 - 2 = 2. The latter method is optimal.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, s1, s2;
int a[100005];
inline int read() {
  int s = 0, w = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') w = -1;
  for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
  return s * w;
}
inline bool check(int x) {
  int l = -0x3f3f3f3f, r = 0x3f3f3f3f;
  for (register int i = n; i >= 1; i--) {
    if (l <= a[i] && a[i] <= r)
      l = a[i] - x, r = a[i] + x;
    else
      l = max(l, a[i] - x), r = min(r, a[i] + x);
  }
  return (l <= s1 && s1 <= r) || (l <= s2 && s2 <= r);
}
int main() {
  n = read(), s1 = read(), s2 = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  int l = abs(s1 - s2), r = 0x3f3f3f3f;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.

You are given the integers written in the following three squares in a magic square:

* The integer A at the upper row and left column
* The integer B at the upper row and middle column
* The integer C at the middle row and middle column

Determine the integers written in the remaining squares in the magic square.

It can be shown that there exists a unique magic square consistent with the given information.

Constraints

* 0 \leq A, B, C \leq 100

Input

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

A
B
C

Output

Output the integers written in the magic square, in the following format:

X_{1,1} X_{1,2} X_{1,3}
X_{2,1} X_{2,2} X_{2,3}
X_{3,1} X_{3,2} X_{3,3}

where X_{i,j} is the integer written in the square at the i-th row and j-th column.

Examples

Input

8
3
5

Output

8 3 4
1 5 9
6 7 2

Input

1
1
1

Output

1 1 1
1 1 1
1 1 1

### Response

```cpp
#include <stdio.h>

int main()
{
	int a,b,c;

	scanf ("%d %d %d",&a,&b,&c);
	for (int s=-1000;s<=1000;s++){
		int p[3][3];
		p[0][0] = a;
		p[0][1] = b;
		p[1][1] = c;
		p[0][2] = s - a - b;
		p[2][0] = s - c - p[0][2];
		p[1][0] = s - a - p[2][0];
		p[1][2] = s - c - p[1][0];
		p[2][1] = s - b - c;
		p[2][2] = s - a - c;

		bool good = 1;
		for (int i=0;i<3;i++) if (p[i][0] + p[i][1] + p[i][2] != s) good = 0;
		for (int i=0;i<3;i++) if (p[0][i] + p[1][i] + p[2][i] != s) good = 0;
		if (p[0][0] + p[1][1] + p[2][2] != s) good = 0;
		if (p[2][0] + p[1][1] + p[0][2] != s) good = 0;
		if (good){
			for (int i=0;i<3;i++) for (int j=0;j<3;j++) printf ("%d%c",p[i][j],j+1<3?' ':'\n');
			return 0;
		}
	}

	return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Min Element

Given the sequence a_1, a_2, .., a_N.

Find the minimum number in this sequence.

If the minimum value is in more than one place, answer the one with the lowest number.

input

N
a_1 a_2 ... a_N

output

Output the smallest i such that a_i is the minimum value in the sequence.

Constraint

* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9

Input example

6
8 6 9 1 2 1

Output example

Four

Example

Input

6
8 6 9 1 2 1

Output

4

### Response

```cpp
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  int mn = 1000000000;
  int mnp = -1;
  for(int i = 0; n > i; i++){
    int t;cin>>t;
    if(mn > t){
      mnp = i;
      mn = t;
    }
  }
  cout << mnp+1 << endl;
}

```


### Prompt

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

This is an interactive problem.

You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.

More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the integer value in this element, and nexti that is the index of the next element of the singly linked list (or -1, if the current element is the last). The list is sorted, i.e. if nexti ≠ - 1, then valuenexti > valuei.

You are given the number of elements in the list n, the index of the first element start, and the integer x.

You can make up to 2000 queries of the following two types:

  * ? i (1 ≤ i ≤ n) — ask the values valuei and nexti,
  * ! ans — give the answer for the problem: the minimum integer, greater than or equal to x, or ! -1, if there are no such integers. Your program should terminate after this query.

Write a program that solves this problem.

Input

The first line contains three integers n, start, x (1 ≤ n ≤ 50000, 1 ≤ start ≤ n, 0 ≤ x ≤ 109) — the number of elements in the list, the index of the first element and the integer x.

Output

To print the answer for the problem, print ! ans, where ans is the minimum integer in the list greater than or equal to x, or -1, if there is no such integer.

Interaction

To make a query of the first type, print ? i (1 ≤ i ≤ n), where i is the index of element you want to know information about.

After each query of type ? read two integers valuei and nexti (0 ≤ valuei ≤ 109,  - 1 ≤ nexti ≤ n, nexti ≠ 0).

It is guaranteed that if nexti ≠ - 1, then valuenexti > valuei, and that the array values give a valid singly linked list with start being the first element.

Note that you can't ask more than 1999 queries of the type ?.

If nexti = - 1 and valuei = - 1, then it means that you asked more queries than allowed, or asked an invalid query. Your program should immediately terminate (for example, by calling exit(0)). You will receive "Wrong Answer", it means that you asked more queries than allowed, or asked an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including the final answer.

To flush you can use (just after printing a query and line end):

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

Hacks format

For hacks, use the following format:

In the first line print three integers n, start, x (1 ≤ n ≤ 50000, 1 ≤ start ≤ n, 0 ≤ x ≤ 109).

In the next n lines print the description of the elements of the list: in the i-th line print two integers valuei and nexti (0 ≤ valuei ≤ 109,  - 1 ≤ nexti ≤ n, nexti ≠ 0).

The printed structure should be a valid singly linked list. In particular, it should be possible to reach all elements from start by following links nexti, and the last element end should have -1 in the nextend.

Example

Input

5 3 80
97 -1
58 5
16 2
81 1
79 4

Output

? 1
? 2
? 3
? 4
? 5
! 81

Note

You can read more about singly linked list by the following link: <https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list>

The illustration for the first sample case. Start and finish elements are marked dark. <image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int M = 1e6 + 5, INF = 0x3f3f3f3f, mod = 1000007;
int A[M], val[M], nxt[M];
int Rand() { return (rand() << 15) | rand(); }
int main() {
  srand(time(NULL));
  int n, st, x;
  scanf("%d%d%d", &n, &st, &x);
  for (int j = 1; j <= n; j++) {
    A[j] = j;
  }
  for (int j = 1; j <= M; j++) {
    int a = Rand() % n + 1, b = Rand() % n + 1;
    swap(A[a], A[b]);
  }
  printf("? %d", st);
  cout << endl;
  scanf("%d%d", &val[st], &nxt[st]);
  int up = INF, down = val[st];
  int uppos, downpos = st;
  for (int j = 1; j <= min(n, 999); j++) {
    printf("? %d", A[j]);
    cout << endl;
    int a, b;
    scanf("%d%d", &a, &b);
    val[A[j]] = a;
    nxt[A[j]] = b;
    if (a >= x && a <= up) {
      up = a;
      uppos = A[j];
    }
    if (a <= x && a >= down) {
      down = a;
      downpos = A[j];
    }
  }
  if (up == x) {
    printf("! %d", x);
    cout << endl;
    return 0;
  }
  if (down >= x) {
    printf("! %d", down);
    cout << endl;
    return 0;
  }
  int left = 999;
  while (left--) {
    if (nxt[downpos] == -1) break;
    printf("? %d", nxt[downpos]);
    cout << endl;
    downpos = nxt[downpos];
    int a, b;
    scanf("%d%d", &a, &b);
    if (a >= x) {
      printf("! %d", a);
      cout << endl;
      return 0;
    }
    val[downpos] = a;
    nxt[downpos] = b;
  }
  printf("! %d", up == INF ? -1 : up);
  cout << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

In a magical land there are n cities conveniently numbered 1, 2, ..., n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may appear between two cities.

Vicky the witch has been tasked with performing deliveries between some pairs of cities. However, Vicky is a beginner, so she can only complete a delivery if she can move from her starting city to her destination city through a double rainbow. A double rainbow is a sequence of cities c_1, c_2, ..., c_k satisfying the following properties:

  * For each i with 1 ≤ i ≤ k - 1, the cities c_i and c_{i + 1} are connected by a road.
  * For each i with 1 ≤ i ≤ (k - 1)/(2), the roads connecting c_{2i} with c_{2i - 1} and c_{2i + 1} have the same color.

For example if k = 5, the road between c_1 and c_2 must be the same color as the road between c_2 and c_3, and the road between c_3 and c_4 must be the same color as the road between c_4 and c_5.

Vicky has a list of events in chronological order, where each event is either a delivery she must perform, or appearance of a new road. Help her determine which of her deliveries she will be able to complete.

Input

The first line contains four integers n, m, c, and q (2 ≤ n ≤ 10^5, 1 ≤ m, c, q ≤ 10^5), denoting respectively the number of cities, the number of roads initially present, the number of different colors the roads can take, and the number of events.

Each of the following m lines contains three integers x, y, and z (1 ≤ x, y ≤ n, 1 ≤ z ≤ c), describing that there initially exists a bidirectional road with color z between cities x and y.

Then q lines follow, describing the events. Each event is one of the following two types:

  1. + x y z (1 ≤ x, y ≤ n, 1 ≤ z ≤ c), meaning a road with color z appears between cities x and y;
  2. ? x y (1 ≤ x, y ≤ n), meaning you should determine whether Vicky can make a delivery starting at city x and ending at city y. It is guaranteed that x ≠ y.

It is guaranteed that at any moment, there is at most one road connecting any pair of cities, and that no road connects a city to itself. It is guaranteed that the input contains at least one event of the second type.

Output

For each event of the second type, print a single line containing "Yes" (without quotes) if the delivery can be made, or a single line containing "No" (without quotes) otherwise.

Example

Input

4 3 2 4
1 2 1
2 3 1
3 4 2
? 1 4
? 4 1
+ 3 1 2
? 4 1

Output

Yes
No
Yes

Note

The following picture corresponds to the sample.

<image>

For her first delivery, Vicky can use the sequence 1, 2, 3, 4 which is a double rainbow. However, she cannot complete the second delivery, as she can only reach city 3. After adding the road between cities 1 and 3, she can now complete a delivery from city 4 to city 1 by using the double rainbow 4, 3, 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct bian {
  int to, nxt, va;
} bi[400040];
int n, m, c, q, siz, head[100010], num, tot, f[100010], id[100010], idnum,
    d[100010];
int query[100010][4];
bitset<700> lt[100010];
map<int, int> mp[100010];
void add(int from, int to, int va) {
  bi[++num].nxt = head[from];
  head[from] = num;
  bi[num].to = to;
  bi[num].va = va;
}
int find(int x) {
  if (x != f[x]) return f[x] = find(f[x]);
  return x;
}
int main() {
  scanf("%d %d %d %d", &n, &m, &c, &q);
  int x, y, z;
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", &x, &y, &z);
    add(x, y, z);
    ++d[x];
    add(y, x, z);
    ++d[y];
  }
  tot = 2 * m;
  char op;
  for (int i = 1; i <= q; ++i) {
    scanf(" %c", &op);
    if (op == '+') {
      scanf("%d %d %d", &x, &y, &z);
      query[i][1] = x, query[i][2] = y, query[i][3] = z;
      ++d[x], ++d[y];
      tot += 2;
    } else {
      scanf("%d %d", &x, &y);
      query[i][0] = 1, query[i][1] = x, query[i][2] = y;
    }
  }
  siz = sqrt(tot);
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= n; ++i)
    if (d[i] >= siz) {
      id[i] = ++idnum;
      for (int j = head[i]; j; j = bi[j].nxt) lt[bi[j].to].set(idnum);
    }
  for (int i = 1; i <= n; ++i)
    for (int j = head[i]; j; j = bi[j].nxt) {
      if (mp[i].count(bi[j].va)) {
        x = find(bi[j].to), y = find(mp[i][bi[j].va]);
        if (x != y) lt[y] |= lt[x], f[x] = y;
      } else
        mp[i][bi[j].va] = bi[j].to;
    }
  for (int i = 1; i <= q; ++i) {
    if (query[i][0]) {
      x = query[i][1], y = query[i][2];
      if (find(x) == find(y)) {
        printf("Yes\n");
        continue;
      }
      bool flag = 0;
      if (d[y] < siz) {
        for (int j = head[y]; j; j = bi[j].nxt)
          if (find(x) == find(bi[j].to)) {
            flag = 1;
            break;
          }
      } else
        flag = lt[find(x)][id[y]];
      if (flag)
        printf("Yes\n");
      else
        printf("No\n");
    } else {
      x = query[i][1], y = query[i][2], z = query[i][3];
      add(x, y, z), add(y, x, z);
      if (id[y]) lt[find(x)].set(id[y]);
      if (id[x]) lt[find(y)].set(id[x]);
      if (mp[x][z]) {
        if (find(mp[x][z]) != find(y)) {
          lt[find(y)] |= lt[find(mp[x][z])];
          f[find(mp[x][z])] = find(y);
        }
      } else
        mp[x][z] = y;
      swap(x, y);
      if (mp[x][z]) {
        if (find(mp[x][z]) != find(y)) {
          lt[find(y)] |= lt[find(mp[x][z])];
          f[find(mp[x][z])] = find(y);
        }
      } else
        mp[x][z] = y;
    }
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

The government of Berland decided to improve network coverage in his country. Berland has a unique structure: the capital in the center and n cities in a circle around the capital. The capital already has a good network coverage (so the government ignores it), but the i-th city contains a_i households that require a connection.

The government designed a plan to build n network stations between all pairs of neighboring cities which will maintain connections only for these cities. In other words, the i-th network station will provide service only for the i-th and the (i + 1)-th city (the n-th station is connected to the n-th and the 1-st city).

All network stations have capacities: the i-th station can provide the connection to at most b_i households.

Now the government asks you to check can the designed stations meet the needs of all cities or not — that is, is it possible to assign each household a network station so that each network station i provides the connection to at most b_i households.

Input

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

The first line of each test case contains the single integer n (2 ≤ n ≤ 10^6) — the number of cities and stations.

The second line of each test case contains n integers (1 ≤ a_i ≤ 10^9) — the number of households in the i-th city.

The third line of each test case contains n integers (1 ≤ b_i ≤ 10^9) — the capacities of the designed stations.

It's guaranteed that the sum of n over test cases doesn't exceed 10^6.

Output

For each test case, print YES, if the designed stations can meet the needs of all cities, or NO otherwise (case insensitive).

Example

Input

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

Output

YES
YES
NO
YES
YES

Note

In the first test case:

  * the first network station can provide 2 connections to the first city and 1 connection to the second city;
  * the second station can provide 2 connections to the second city and 1 connection to the third city;
  * the third station can provide 3 connections to the third city.

In the second test case:

  * the 1-st station can provide 2 connections to the 1-st city;
  * the 2-nd station can provide 3 connections to the 2-nd city;
  * the 3-rd station can provide 3 connections to the 3-rd city and 1 connection to the 1-st station.

In the third test case, the fourth city needs 5 connections, but the third and the fourth station has 4 connections in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int q;
int n;
long long ar[N], mx[N], pre[N];
long long tot, cur;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    bool ok = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> ar[i];
      pre[i + i] = -ar[i];
    }
    for (int i = 1; i <= n; i++) {
      cin >> mx[i];
      int id = (i + i) % (n + n) + 1;
      pre[id] = mx[i];
    }
    n = n + n;
    for (int i = 1; i <= n; i++) {
      pre[n + i] = pre[i];
    }
    for (int i = 1; i <= n + n; i++) {
      pre[i] = pre[i] + pre[i - 1];
    }
    if (pre[n] < 0) {
      cout << "NO" << '\n';
      continue;
    }
    long long mx = 0;
    for (int i = 0; i <= n + n; i++) {
      if (i & 1) {
        if (pre[i] - mx < 0) {
          ok = 0;
          break;
        }
      } else {
        mx = max(mx, pre[i]);
      }
    }
    if (ok)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}

```


### Prompt

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

Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x.

<image>

Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.

Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.

Input

The first and only line of input contains one integer, n (1 ≤ n ≤ 1012).

Output

Print the answer in one line.

Examples

Input

10

Output

10

Input

12

Output

6

Note

In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.

In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 22, so 12 is not lovely, while 6 is indeed lovely.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i;
  cin >> n;
  long long int ans = n;
  for (i = 2; i <= sqrt(n); i++) {
    long long int x = i * i;
    while (ans % x == 0) ans /= i;
  }
  cout << ans << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Alex enjoys performing magic tricks. He has a trick that requires a deck of n cards. He has m identical decks of n different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs n cards at random and performs the trick with those. The resulting deck looks like a normal deck, but may have duplicates of some cards.

The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful.

You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case.

Input

First line of the input consists of two integers n and m (1 ≤ n, m ≤ 1000), separated by space — number of cards in each deck, and number of decks.

Output

On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10 - 6.

Examples

Input

2 2

Output

0.6666666666666666

Input

4 4

Output

0.4000000000000000

Input

1 2

Output

1.0000000000000000

Note

In the first sample, with probability <image> Alex will perform the trick with two cards with the same value from two different decks. In this case the trick is guaranteed to succeed.

With the remaining <image> probability he took two different cards, and the probability of pulling off the trick is <image>.

The resulting probability is <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int n, m, k;
int a[1005];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    double ans = 0, p = 1.0, b = n * m - m - n + 1;
    for (int i = 1; i < n; i++) p = p * (b + i) / (b + i + m - 1);
    ans += p * 1 * 1;
    for (int i = 2; i <= min(n, m); i++) {
      p = p * (m - i + 1) / i * (n - i + 1) / ((n - 1) * (m - 1) + i - 1);
      ans += p * i * i;
    }
    ans /= n;
    printf("%.8f\n", ans);
  }
  return 0;
}

```


### Prompt

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

The only difference between easy and hard versions is constraints.

Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.

There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins. The second way is to make m_i other voters vote for you, and the i-th voter will vote for free.

Moreover, the process of such voting takes place in several steps. For example, if there are five voters with m_1 = 1, m_2 = 2, m_3 = 2, m_4 = 4, m_5 = 5, then you can buy the vote of the fifth voter, and eventually everyone will vote for you. Set of people voting for you will change as follows: {5} → {1, 5} → {1, 2, 3, 5} → {1, 2, 3, 4, 5}.

Calculate the minimum number of coins you have to spend so that everyone votes for you.

Input

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

The first line of each test case contains one integer n (1 ≤ n ≤ 5000) — the number of voters.

The next n lines contains the description of voters. i-th line contains two integers m_i and p_i (1 ≤ p_i ≤ 10^9, 0 ≤ m_i < n).

It is guaranteed that the sum of all n over all test cases does not exceed 5000.

Output

For each test case print one integer — the minimum number of coins you have to spend so that everyone votes for you.

Example

Input

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

Output

8
0
7

Note

In the first test case you have to buy vote of the third voter. Then the set of people voting for you will change as follows: {3} → {1, 3} → {1, 2, 3}.

In the second example you don't need to buy votes. The set of people voting for you will change as follows: {1} → {1, 3, 5} → {1, 2, 3, 5} → {1, 2, 3, 5, 6, 7} → {1, 2, 3, 4, 5, 6, 7}.

In the third test case you have to buy votes of the second and the fifth voters. Then the set of people voting for you will change as follows: {2, 5} → {1, 2, 3, 4, 5} → {1, 2, 3, 4, 5, 6}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1;
pair<long long, long long> mp[N];
void solve() {
  long long n;
  cin >> n;
  long long x, y;
  for (long long i = 1; i <= n; i++) {
    cin >> x >> y;
    mp[i] = {x, y};
  }
  sort(mp + 1, mp + n + 1);
  long long ans = 0;
  priority_queue<long long, vector<long long>, greater<long long> > price;
  long long extra = 0;
  for (long long i = n; i > 0; i--) {
    long long m = mp[i].first;
    while (i > 0 && mp[i].first == m) {
      price.push(mp[i].second);
      i--;
    }
    i++;
    long long need = m - (i - 1 + extra);
    if (need <= 0) continue;
    while (need--) {
      extra++;
      ans += price.top();
      price.pop();
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}

```