### Prompt

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

The mayor of Amida, the City of Miracle, is not elected like any other city. Once exhausted by long political struggles and catastrophes, the city has decided to leave the fate of all candidates to the lottery in order to choose all candidates fairly and to make those born under the lucky star the mayor. I did. It is a lottery later called Amidakuji.

The election is held as follows. The same number of long vertical lines as the number of candidates will be drawn, and some horizontal lines will be drawn there. Horizontal lines are drawn so as to connect the middle of adjacent vertical lines. Below one of the vertical lines is written "Winning". Which vertical line is the winner is hidden from the candidates. Each candidate selects one vertical line. Once all candidates have been selected, each candidate follows the line from top to bottom. However, if a horizontal line is found during the movement, it moves to the vertical line on the opposite side to which the horizontal line is connected, and then traces downward. When you reach the bottom of the vertical line, the person who says "winning" will be elected and become the next mayor.

This method worked. Under the lucky mayor, a peaceful era with few conflicts and disasters continued. However, in recent years, due to population growth, the limits of this method have become apparent. As the number of candidates increased, the Amidakuji became large-scale, and manual tabulation took a lot of time. Therefore, the city asked you, the programmer of the city hall, to computerize the Midakuji.

Your job is to write a program that finds the structure of the Amidakuji and which vertical line you will eventually reach given the position of the selected vertical line.

The figure below shows the contents of the input and output given as a sample.

<image>

Input

The input consists of multiple datasets. One dataset is given as follows.

> n m a
> Horizontal line 1
> Horizontal line 2
> Horizontal line 3
> ...
> Horizontal line m
>

n, m, and a are integers that satisfy 2 <= n <= 100, 0 <= m <= 1000, 1 <= a <= n, respectively. Represents a number.

The horizontal line data is given as follows.

> h p q

h, p, and q are integers that satisfy 1 <= h <= 1000, 1 <= p <q <= n, respectively, h is the height of the horizontal line, and p and q are connected to the horizontal line 2 Represents the number of the vertical line of the book.

No two or more different horizontal lines are attached to the same height of one vertical line.

At the end of the input, there is a line consisting of only three zeros separated by blanks.

Output

Output one line for each dataset, the number of the vertical line at the bottom of the vertical line a when traced from the top.

Sample Input

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

Output for the Sample Input

Four

Example

Input

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

Output

4

### Response

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

class Line{
public:
	int h,p,q;
	friend istream& operator>>(istream &in,Line &a){
		in>>a.h>>a.p>>a.q;
		return in;
	}
};
bool cmp(Line a,Line b){
	return b.h<a.h;
}
int main(){
	int n,m,a;
	Line line[1000];
	while(cin>>n>>m>>a,n|m|a){
		for(int i=0;i<m;i++)cin>>line[i];
		sort(line,line+m,cmp);
		for(int i=0;i<m;i++){
			if(line[i].p==a)a=line[i].q;
			else if(line[i].q==a)a=line[i].p;
		}
		cout<<a<<endl;
	}
}
```


### Prompt

Develop a solution in cpp to the problem described below:

There are n athletes in front of you. Athletes are numbered from 1 to n from left to right. You know the strength of each athlete — the athlete number i has the strength s_i.

You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team.

You want the strongest athlete from the first team to differ as little as possible from the weakest athlete from the second team. Formally, you want to split the athletes into two teams A and B so that the value |max(A) - min(B)| is as small as possible, where max(A) is the maximum strength of an athlete from team A, and min(B) is the minimum strength of an athlete from team B.

For example, if n=5 and the strength of the athletes is s=[3, 1, 2, 6, 4], then one of the possible split into teams is:

  * first team: A = [1, 2, 4],
  * second team: B = [3, 6].

In this case, the value |max(A) - min(B)| will be equal to |4-3|=1. This example illustrates one of the ways of optimal split into two teams.

Print the minimum value |max(A) - min(B)|.

Input

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

Each test case consists of two lines.

The first line contains positive integer n (2 ≤ n ≤ 50) — number of athletes.

The second line contains n positive integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 1000), where s_i — is the strength of the i-th athlete. Please note that s values may not be distinct.

Output

For each test case print one integer — the minimum value of |max(A) - min(B)| with the optimal split of all athletes into two teams. Each of the athletes must be a member of exactly one of the two teams.

Example

Input

5
5
3 1 2 6 4
6
2 1 3 2 4 3
4
7 9 3 1
2
1 1000
3
100 150 200

Output

1
0
2
999
50

Note

The first test case was explained in the statement. In the second test case, one of the optimal splits is A=[2, 1], B=[3, 2, 4, 3], so the answer is |2-2|=0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e15;
using Graph = vector<vector<long long>>;
signed main() {
  long long T;
  cin >> T;
  for (long long t = 0; t < T; t++) {
    long long N;
    cin >> N;
    vector<long long> A(N);
    for (long long i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    long long ans = 1000000;
    for (long long i = 1; i < N; i++) {
      ans = min(ans, A[i] - A[i - 1]);
    }
    cout << ans << endl;
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mechanism contains string t that consists of the same number of characters as s and differs from s in exactly one position".

Watto has already compiled the mechanism, all that's left is to write a program for it and check it on the data consisting of n initial lines and m queries. He decided to entrust this job to you.

Input

The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively.

Next follow n non-empty strings that are uploaded to the memory of the mechanism.

Next follow m non-empty strings that are the queries to the mechanism.

The total length of lines in the input doesn't exceed 6·105. Each line consists only of letters 'a', 'b', 'c'.

Output

For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).

Examples

Input

2 3
aaaaa
acacaca
aabaa
ccacacc
caaac

Output

YES
NO
NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
const long long MAX = 1e7 + 20;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
long long BM(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P & 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return (long long)R;
}
long long MI(long long x, long long m) { return BM(x, m - 2, m); }
struct data {
  bool endmark;
  int next[5];
  data() {
    endmark = false;
    memset(next, -1, sizeof(next));
  }
} trie[600005];
int tot = 0, sz;
string s;
void add(string s) {
  int cur = 0;
  for (int i = 0; i < s.size(); i++) {
    int ch = s[i] - 'a';
    if (trie[cur].next[ch] == -1) {
      trie[++tot] = data();
      trie[cur].next[ch] = tot;
    }
    cur = trie[cur].next[ch];
  }
  trie[cur].endmark = true;
}
bool findmatch(int pos, int cur, bool change) {
  if (pos == sz) {
    return (change and trie[cur].endmark);
  }
  bool ret = false;
  int now = s[pos] - 'a';
  if (change) {
    if (trie[cur].next[now] == -1) return false;
    return findmatch(pos + 1, trie[cur].next[now], change);
  } else {
    for (int i = 0; i < 3; i++) {
      if (trie[cur].next[i] == -1) continue;
      ret |= findmatch(pos + 1, trie[cur].next[i], (i == now) ? 0 : 1);
    }
  }
  return ret;
}
int main() {
  trie[0] = data();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    add(s);
  }
  while (m--) {
    cin >> s;
    sz = s.size();
    if (findmatch(0, 0, 0))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

We have a tree with N vertices. The vertices are numbered 0 through N - 1, and the i-th edge (0 ≤ i < N - 1) comnnects Vertex a_i and b_i. For each pair of vertices u and v (0 ≤ u, v < N), we define the distance d(u, v) as the number of edges in the path u-v.

It is expected that one of the vertices will be invaded by aliens from outer space. Snuke wants to immediately identify that vertex when the invasion happens. To do so, he has decided to install an antenna on some vertices.

First, he decides the number of antennas, K (1 ≤ K ≤ N). Then, he chooses K different vertices, x_0, x_1, ..., x_{K - 1}, on which he installs Antenna 0, 1, ..., K - 1, respectively. If Vertex v is invaded by aliens, Antenna k (0 ≤ k < K) will output the distance d(x_k, v). Based on these K outputs, Snuke will identify the vertex that is invaded. Thus, in order to identify the invaded vertex no matter which one is invaded, the following condition must hold:

* For each vertex u (0 ≤ u < N), consider the vector (d(x_0, u), ..., d(x_{K - 1}, u)). These N vectors are distinct.

Find the minumum value of K, the number of antennas, when the condition is satisfied.

Constraints

* 2 ≤ N ≤ 10^5
* 0 ≤ a_i, b_i < N
* The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_0 b_0
a_1 b_1
:
a_{N - 2} b_{N - 2}

Output

Print the minumum value of K, the number of antennas, when the condition is satisfied.

Examples

Input

5
0 1
0 2
0 3
3 4

Output

2

Input

2
0 1

Output

1

Input

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

Output

3

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int n,doe,root;
int pre[202020],son[202020],now[101010],du[101010];
int g[101010],size[101010];
bool br[101010];
void add(int x,int y)
{
	++x; ++y;
	++doe;
	pre[doe]=now[x];
	now[x]=doe;
	son[doe]=y;
}
void dfs(int x,int fa)
{
	int p=now[x];
	br[x]=1;
	if (du[x]==1)
	{
		g[x]=1;
		return;
	}
	int dog=0;
	while (p)
	{
		int y=son[p];
		if (y!=fa)
		{
			dfs(y,x);
			g[x]+=g[y];
			if (br[y]) dog=max(dog,g[y]);
			br[x]&=br[y];
		}
		p=pre[p];
	}
	if (du[x]>2) br[x]=0,g[x]-=dog;
}
int main()
{
	scanf("%d",&n);
	int x,y;
	for (int i=1;i<n;++i)
		scanf("%d%d",&x,&y),add(x,y),add(y,x),++du[x+1],++du[y+1];
	for (int i=1;i<=n;++i) if (du[i]>2) root=i;
	if (!root)
	{
		printf("1\n");
		return 0;
	}
	int p=now[root];
	int dog=0;
//	printf("%d\n",root);
	while (p)
	{
		y=son[p];
		dfs(y,root);
		g[root]+=g[y];
		if (br[y]) dog=max(dog,g[y]);
		p=pre[p];
	}
//	for (int i=1;i<=n;++i) printf("%d ",g[i]);
//	printf("\n");
	printf("%d\n",g[root]-dog);
	return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Pushok the dog has been chasing Imp for a few hours already.

<image>

Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner.

While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (i, j), that i < j and <image> and <image>.

The robot is off at the moment. Imp knows that it has a sequence of strings ti in its memory, and he can arbitrary change their order. When the robot is started, it generates the string t as a concatenation of these strings in the given order. The noise of the resulting string equals the noise of this concatenation.

Help Imp to find the maximum noise he can achieve by changing the order of the strings.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of strings in robot's memory.

Next n lines contain the strings t1, t2, ..., tn, one per line. It is guaranteed that the strings are non-empty, contain only English letters 's' and 'h' and their total length does not exceed 105.

Output

Print a single integer — the maxumum possible noise Imp can achieve by changing the order of the strings.

Examples

Input

4
ssh
hs
s
hhhs

Output

18

Input

2
h
s

Output

1

Note

The optimal concatenation in the first sample is ssshhshhhs.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool compare1(pair<long long int, int> p1,
              pair<long long int, long long int> p2) {
  if ((p1.first * p2.second) == (p2.first * p1.second)) {
    return (p1.first > p2.first);
  }
  return (p1.first * p2.second) > (p2.first * p1.second);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  string str;
  vector<pair<long long int, long long int>> vec;
  long long int ctrs, ctrh;
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> str;
    ctrs = 0;
    ctrh = 0;
    for (long long int j = 0; j < str.size(); j++) {
      if (str[j] == 's') {
        ctrs++;
      } else {
        ctrh++;
        sum += ctrs;
      }
    }
    vec.push_back(make_pair(ctrs, ctrh));
  }
  sort(vec.begin(), vec.end(), compare1);
  long long int s_sum = vec[0].first;
  for (int long long i = 1; i < n; i++) {
    sum = sum + s_sum * vec[i].second;
    s_sum += vec[i].first;
  }
  cout << sum << '\n';
  return 0;
}

```


### Prompt

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

You are given an array a consisting of n integer numbers.

You have to color this array in k colors in such a way that:

  * Each element of the array should be colored in some color;
  * For each i from 1 to k there should be at least one element colored in the i-th color in the array;
  * For each i from 1 to k all elements colored in the i-th color should be distinct.

Obviously, such coloring might be impossible. In this case, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c_1, c_2, ... c_n, where 1 ≤ c_i ≤ k and c_i is the color of the i-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 5000) — the length of the array a and the number of colors, respectively.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 5000) — elements of the array a.

Output

If there is no answer, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c_1, c_2, ... c_n, where 1 ≤ c_i ≤ k and c_i is the color of the i-th element of the given array) satisfying the conditions described in the problem statement. If there are multiple answers, you can print any.

Examples

Input

4 2
1 2 2 3

Output

YES
1 1 2 2

Input

5 2
3 2 1 2 3

Output

YES
2 1 1 2 1

Input

5 2
2 1 1 2 1

Output

NO

Note

In the first example the answer 2~ 1~ 2~ 1 is also acceptable.

In the second example the answer 1~ 1~ 1~ 2~ 2 is also acceptable.

There exist other acceptable answers for both examples.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  int n, k;
  while (cin >> n >> k) {
    vector<int> V[5005];
    for (int i = 1; i <= n; i++) {
      int tmp;
      cin >> tmp;
      V[tmp].push_back(i);
    }
    int mx = 0;
    for (int i = 1; i <= 5000; i++) {
      mx = mx > V[i].size() ? mx : V[i].size();
    }
    if (mx > k || n < k) {
      cout << "NO" << endl;
      continue;
    } else {
      queue<int> Q;
      int tmp = 1;
      while (Q.size() < n) {
        for (int i = 0; i < V[tmp].size(); i++) {
          Q.push(V[tmp][i]);
        }
        tmp++;
      }
      int ans[5005];
      int f = 0;
      while (Q.empty() == 0) {
        int t = Q.front();
        Q.pop();
        ans[t] = ++f;
        if (f == k) f = 0;
      }
      for (int i = tmp; i <= 5000; i++) {
        for (int j = 0; j < V[i].size(); j++) {
          ans[V[i][j]] = j + 1;
        }
      }
      cout << "YES" << endl;
      for (int i = 1; i <= n; i++) {
        cout << ans[i] << " ";
      }
      cout << endl;
    }
  }
}

```


### Prompt

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

Let's call an integer array a_1, a_2, ..., a_n good if a_i ≠ i for each i.

Let F(a) be the number of pairs (i, j) (1 ≤ i < j ≤ n) such that a_i + a_j = i + j.

Let's say that an array a_1, a_2, ..., a_n is excellent if:

  * a is good;
  * l ≤ a_i ≤ r for each i;
  * F(a) is the maximum possible among all good arrays of size n.

Given n, l and r, calculate the number of excellent arrays modulo 10^9 + 7.

Input

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

The first and only line of each test case contains three integers n, l, and r (2 ≤ n ≤ 2 ⋅ 10^5; -10^9 ≤ l ≤ 1; n ≤ r ≤ 10^9).

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

Output

For each test case, print the number of excellent arrays modulo 10^9 + 7.

Example

Input

4
3 0 3
4 -3 5
42 -33 55
69 -42 146

Output

4
10
143922563
698570404

Note

In the first test case, it can be proven that the maximum F(a) among all good arrays a is equal to 2. The excellent arrays are:

  1. [2, 1, 2];
  2. [0, 3, 2];
  3. [2, 3, 2];
  4. [3, 0, 1].

### Response

```cpp
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>

using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

#define mp    make_pair
#define pb    push_back
#define F     first
#define S     second
#define ab(x) (((x)<0)?-(x):(x))

#define MOD 1000000007

class nCrModular {
public:
    ll mod;
    vector<ll> fac;

    nCrModular(int n, ll _mod) {
        mod = _mod;
        fac.resize(n + 1);

        fac[0] = 1;
        for (int i = 1; i <= n; i++)
            fac[i] = (fac[i - 1] * i) % mod;
    }

    ll pow(ll x, ll y) {
        ll r = 1;
        for (x = x % mod; y; y >>= 1, x = (x * x) % mod)
            if (y & 1) r = (r * x) % mod;
        return r;
    }

    ll inv(ll x) {
        return pow(x, mod - 2);
    }

    ll nCr(ll n, ll r) {
        if (n < r) return 0;
        if (r == 0) return 1;
        return ((fac[n] * inv(fac[r]) % mod) * inv(fac[n - r])) % mod;
    }
} ncr(200000, MOD);

void solve() {
    int n, s, e;
    cin >> n >> s >> e;

    int k = min(min(ab(s - 1), ab(e - 1)), min(ab(s - n), ab(e - n)));
    int L = 1, R = n, m1 = n / 2, m2 = (n + 1) / 2;
    ll r = 0;
    for (int i = 0; i <= m2 - m1; i++) {
        int need = m1 + i;
        r = (r + ncr.nCr(n, need) * k) % MOD;
    }

    for (k = k + 1;; k++) {
        if (!(s - L <= -k && k <= e - L)) L++;
        if (!(s - R <= -k && k <= e - R)) R--;
        if (R - L + 1 < 0) break;
        int plus = L - 1;
        int minus = n - R;
        if (plus > m2 || minus > m2) break;

        for (int i = 0; i <= m2 - m1; i++) {
            int need = m1 + i - plus;
            r = (r + ncr.nCr(R - L + 1, need)) % MOD;
        }
    }

    cout << r << endl;
}

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

    int test_case;
    cin >> test_case;
    while (test_case--)
        solve();
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.

For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1, 2, 4, 5, 7, 8, 10, 11, 13 .... The 7-th number among them is 10.

Input

The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases in the input. Next, t test cases are given, one per line.

Each test case is two positive integers n (2 ≤ n ≤ 10^9) and k (1 ≤ k ≤ 10^9).

Output

For each test case print the k-th positive integer that is not divisible by n.

Example

Input

6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1

Output

10
15
1999999999
113
1000000001
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long f(long long x, long long n) { return x - (x / n); }
long long solve(long long n, long long k) {
  long long L = 1;
  long long R = 1e10;
  while (L < R) {
    long long M = L + (R - L) / 2;
    if (f(M, n) < k)
      L = M + 1;
    else
      R = M;
  }
  return L;
}
int main() {
  long long k, n, t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cout << solve(n, k) << "\n";
  }
  return 0;
}

```


### Prompt

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

Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:

  * After the cutting each ribbon piece should have length a, b or c.
  * After the cutting the number of ribbon pieces should be maximum.

Help Polycarpus and find the number of ribbon pieces after the required cutting.

Input

The first line contains four space-separated integers n, a, b and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.

Output

Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.

Examples

Input

5 5 3 2

Output

2

Input

7 5 5 2

Output

2

Note

In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.

In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  int a, b, c, n, dp[4001];
  cin >> n >> a >> b >> c;
  for (int i = 1; i <= n; i++) {
    dp[i] = 0;
    if (a == i || b == i || c == i) dp[i] = 1;
    for (int j = 1; j <= i / 2; j++) {
      if (dp[j] != 0 && dp[i - j] != 0) dp[i] = max(dp[i], (dp[j] + dp[i - j]));
    }
  }
  cout << dp[n];
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Description

THE BY DOLM @ STER is a training simulation game scheduled to be released on EXIDNA by 1rem on April 1, 2010. For the time being, it probably has nothing to do with an arcade game where the network connection service stopped earlier this month.
This game is a game in which members of the unit (formation) to be produced are selected from the bidders, and through lessons and communication with the members, they (they) are raised to the top of the bidders, the top biddles.
Each bidle has three parameters, vocal, dance, and looks, and the unit's ability score is the sum of all the parameters of the biddles that belong to the unit. The highest of the three stats of a unit is the rank of the unit.
There is no limit to the number of people in a unit, and you can work as a unit with one, three, or 100 members. Of course, you can hire more than one of the same bidle, but hiring a bidle is expensive and must be taken into account.
As a producer, you decided to write and calculate a program to make the best unit.

Input

The input consists of multiple test cases.
The first line of each test case is given the number N of bid dollars and the available cost M. (1 <= N, M <= 300) The next 2 * N lines contain information about each bidle.
The name of the bidle is on the first line of the bidle information. Biddle names consist of alphabets and spaces, with 30 characters or less. Also, there is no bidle with the same name.
The second line is given the integers C, V, D, L. C is the cost of hiring one Biddle, V is the vocal, D is the dance, and L is the stat of the looks. (1 <= C, V, D, L <= 300)
Input ends with EOF.

Output

Answer the maximum rank of units that can be made within the given cost.
If you cannot make a unit, output 0.

Example

Input

3 10
Dobkeradops
7 5 23 10
PataPata
1 1 2 1
dop
5 3 11 14
2 300
Bydo System Alpha
7 11 4 7
Green Inferno
300 300 300 300

Output

29
462

### Response

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

int n,m;
int c[301],v[301],d[301],l[301];
int dp[301][301];

int solve(int idx,int rem,int *t){
	if(idx == n) return 0;
	if(dp[idx][rem] != -1) return dp[idx][rem];
	int res = 0;
	for(int i=0;i*c[idx]<=rem;i++){
		res = max(res,i*t[idx]+solve(idx+1,rem-i*c[idx],t));
	}
	return dp[idx][rem]=res;
}

int main(void){
	while(cin>>n>>m){
		for(int i=0;i<n;i++){
			char ch = getchar();
			while((ch=getchar()) != '\n');
			cin>>c[i]>>v[i]>>d[i]>>l[i];
		}

		int ans = 0;
		memset(dp,-1,sizeof(dp));
		ans = max(ans,solve(0,m,v));
		memset(dp,-1,sizeof(dp));
		ans = max(ans,solve(0,m,d));
		memset(dp,-1,sizeof(dp));
		ans = max(ans,solve(0,m,l));
		cout<<ans<<endl;
	}

	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.

Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.

Input

In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.

Output

If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≤ k ≤ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≤ li ≤ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.

Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.

Examples

Input

0010100

Output

3
3 1 3 4
3 2 5 6
1 7

Input

111

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, tms, st[200005], st_[200005], lst[200005], t, tt, k, i;
char S[200005];
bool vis[200005];
int main() {
  scanf("%s", S + 1);
  n = strlen(S + 1);
  for (i = 1; i <= n; i++)
    if (S[i] == '1') {
      if (!t) return puts("-1"), 0;
      lst[i] = st[--t];
      st_[tt++] = i;
    } else {
      if (tt) lst[i] = st_[--tt];
      st[t++] = i;
    }
  if (tt) return puts("-1"), 0;
  printf("%d\n", t);
  while (t--) {
    for (i = st[t], k = 0; i; k++, i = lst[i])
      ;
    printf("%d", k);
    tt = 0;
    for (int i = st[t]; i; i = lst[i]) {
      st_[tt++] = i;
    }
    for (int i = tt - 1; i >= 0; i--) printf(" %d", st_[i]);
    puts("");
  }
}

```


### Prompt

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

We get more and more news about DDoS-attacks of popular websites.

Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds 100 ⋅ t, where t — the number of seconds in this time segment.

Arseny knows statistics on the number of requests per second since the server is booted. He knows the sequence r_1, r_2, ..., r_n, where r_i — the number of requests in the i-th second after boot.

Determine the length of the longest continuous period of time, which Arseny considers to be a DDoS-attack. A seeking time period should not go beyond the boundaries of the segment [1, n].

Input

The first line contains n (1 ≤ n ≤ 5000) — number of seconds since server has been booted. The second line contains sequence of integers r_1, r_2, ..., r_n (0 ≤ r_i ≤ 5000), r_i — number of requests in the i-th second.

Output

Print the only integer number — the length of the longest time period which is considered to be a DDoS-attack by Arseny. If it doesn't exist print 0.

Examples

Input

5
100 200 1 1 1

Output

3

Input

5
1 2 3 4 5

Output

0

Input

2
101 99

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
int a[1 << 20];
int p[1 << 20];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = (0); i < (n); ++i) cin >> a[i];
  p[0] = a[0];
  for (int i = (1); i < (n); ++i) p[i] = p[i - 1] + a[i];
  int ans = 0;
  for (int l = (0); l < (n); ++l)
    for (int len = (1); len < (n - l + 1); ++len) {
      int tut = p[len + l - 1];
      if (l) tut -= p[l - 1];
      if (tut > 100 * len) ans = max(ans, len);
    }
  cout << ans << endl;
  cerr << "Time elapsed : " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula:

\begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n - 1) + fib(n - 2) & \\\ \end{array} \right. \end{equation*}

Constraints

* $0 \leq n \leq 44$

Input

An integer $n$ is given.

Example

Input

3

Output

3

### Response

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

int main(){
    int f[45],n;
    cin>>n;
    f[0]=1;f[1]=1;
    for(int i=2;i<45;i++){
        f[i]=f[i-1]+f[i-2];
    }
    cout<<f[n]<<endl;
    return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges.
The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i.
Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).
A connected graph is a graph where there is a path between every pair of different vertices.
Find the number of the edges that are not contained in any shortest path between any pair of different vertices.

Constraints

* 2≤N≤100
* N-1≤M≤min(N(N-1)/2,1000)
* 1≤a_i,b_i≤N
* 1≤c_i≤1000
* c_i is an integer.
* The given graph contains neither self-loops nor double edges.
* The given graph is connected.

Input

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

N M
a_1 b_1 c_1
a_2 b_2 c_2
:
a_M b_M c_M

Output

Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.

Examples

Input

3 3
1 2 1
1 3 1
2 3 3

Output

1

Input

3 2
1 2 1
2 3 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll e[1005][1005];
ll d[1005][1005];
ll n,m;
ll a[1005],b[1005],c;
ll ans;
int main(void){
	cin>>n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      d[i][j]=1000000000;
    }
  }
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i]>>c;
		e[a[i]-1][b[i]-1]=c; e[b[i]-1][a[i]-1]=c;
		d[a[i]-1][b[i]-1]=c; d[b[i]-1][a[i]-1]=c;
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	for(int i=0;i<m;i++){
		if(d[a[i]-1][b[i]-1]<e[a[i]-1][b[i]-1]){
			ans++;
		}
	}
	cout<<ans<<endl;

}

```


### Prompt

Please formulate a cpp solution to the following problem:

For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for example, 5/2=2.5.

Input

The first line contains a single integer t — the number of test cases (1 ≤ t ≤ 100). The test cases follow, each in two lines.

The first line of a test case contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 10^6). The second line contains integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^6) — the elements of the array.

Output

For each test case print "YES", if it is possible to reorder the elements of the array in such a way that the given formula gives the given value, and "NO" otherwise.

Example

Input

2
3 8
2 5 1
4 4
0 1 2 3

Output

YES
NO

Note

In the first test case one of the reorders could be [1, 2, 5]. The sum is equal to (1/1 + 2/2 + 5/3) + (2/2 + 5/3) + (5/3) = 8. The brackets denote the inner sum ∑_{j=i}^{n}{(a_j)/(j)}, while the summation of brackets corresponds to the sum over i.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
template <class T>
inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  res *= flag;
}
const int maxn = 2e5 + 7;
int n, t, m;
int main() {
  read(t);
  while (t--) {
    read(n);
    read(m);
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
      int x;
      read(x);
      sum += x;
    }
    printf("%s\n", m == sum ? "YES" : "NO");
  }
  return 0;
}

```


### Prompt

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

Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:

Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types of spells in stock:

  1. Doubles health of the creature (hpi := hpi·2);
  2. Assigns value of health of the creature to its damage (dmgi := hpi).

Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.

Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.

Input

The first line contains three integers n, a, b (1 ≤ n ≤ 2·105, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively.

The i-th of the next n lines contain two number hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.

Output

Print single integer — maximum total damage creatures can deal.

Examples

Input

2 1 1
10 15
6 1

Output

27

Input

3 0 3
10 8
7 11
5 2

Output

26

Note

In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27.

In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 26.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 2e5 + 5;
long long hp[N], dmg[N], c[N];
int a, b, n, p[N];
bool cmp(int x, int y) { return hp[x] - dmg[x] > hp[y] - dmg[y]; }
int main() {
  scanf("%d%d%d", &n, &a, &b);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) scanf("%lld%lld", hp + i, dmg + i), p[i] = i;
  long long now = 1LL << a;
  std::sort(p + 1, p + 1 + n, cmp);
  for (int i = 1; i <= n; i++)
    if (i <= b)
      ans += std::max(hp[p[i]], dmg[p[i]]);
    else
      ans += dmg[p[i]];
  long long sum = ans;
  for (int i = 1; i <= n; i++) {
    long long res = sum;
    int j = p[i];
    if (i <= b) {
      res -= std::max(hp[j], dmg[j]);
      res += std::max(hp[j] * now, dmg[j]);
      ans = std::max(ans, res);
    } else {
      res -= std::max(hp[p[b]], dmg[p[b]]) - dmg[p[b]] + dmg[j];
      res += std::max(dmg[j], hp[j] * now);
      ans = std::max(ans, res);
    }
  }
  if (!b) ans = sum;
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

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

A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable.

Constraints

* 1 ≤ |V| ≤ 10,000
* 0 ≤ |E| ≤ 30,000
* 1 ≤ Q ≤ 100,000

Input

A directed graph G(V, E) and a sequence of queries where each query contains a pair of nodes u and v.

|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1
Q
u0 v0
u1 v1
:
uQ-1 vQ-1

|V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V|-1 respectively.

si and ti represent source and target nodes of i-th edge (directed).

ui and vi represent a pair of nodes given as the i-th query.

Output

For each query, pinrt "1" if the given nodes belong to the same strongly connected component, "0" otherwise.

Example

Input

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

Output

1
0
1
1

### Response

```cpp
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int n,m,used[101010],cmp[101010];
vector<int> v[101010],rv[101010],vs;

void dfs(int x){
   used[x]=true;
   for(auto to:v[x])if(!used[to])dfs(to);
   vs.push_back(x);
}

void rdfs(int x,int k){
   used[x]=true;
   cmp[x]=k;
   for(auto to:rv[x])if(!used[to])rdfs(to,k);
}

int scc(){
   rep(i,n)if(!used[i])dfs(i);
   rep(i,n)used[i]=0;
   reverse(vs.begin(),vs.end());
   int k=0;
   for(auto x:vs)if(!used[x])rdfs(x,k++);
   return k;
}
int main(){
    cin>>n>>m;
    rep(i,m){
        int s,t;
        cin>>s>>t;
        v[s].push_back(t);
        rv[t].push_back(s);
    }
    scc();
    int q;
    cin>>q;
    rep(i,q){
        int s,t;
        cin>>s>>t;
        cout<<(cmp[s]==cmp[t])<<endl;
    }
    return 0;
}

```


### Prompt

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

Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that yi is equal to the sum of first i elements of array x (0 ≤ i ≤ m).

You have an infinite sequence of arrays A0, A1, A2..., where A0 is given in the input, and for each i ≥ 1 Ai = p(Ai - 1). Also you have a positive integer k. You have to find minimum possible i such that Ai contains a number which is larger or equal than k.

Input

The first line contains two integers n and k (2 ≤ n ≤ 200000, 1 ≤ k ≤ 1018). n is the size of array A0.

The second line contains n integers A00, A01... A0n - 1 — the elements of A0 (0 ≤ A0i ≤ 109). At least two elements of A0 are positive.

Output

Print the minimum i such that Ai contains a number which is larger or equal than k.

Examples

Input

2 2
1 1

Output

1

Input

3 6
1 1 1

Output

2

Input

3 1
1 0 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 2e5 + 10;
const long long inf = 1e18;
int n;
long long k, a[maxN];
bool check(long long d) {
  long long c = 1, x = d - 1, y = 0, sum = 0;
  bool ovf = 0;
  for (int i = n; i; i--) {
    if (a[i] > 0 && (ovf || (long double)sum + (long double)c * a[i] > inf)) {
      return 1;
    }
    if (a[i] > 0) {
      sum += c * a[i];
    }
    if (sum >= k) {
      return 1;
    }
    x++;
    y++;
    if ((long double)c * x / y > inf) {
      ovf = 1;
    } else {
      __int128 tmp = c;
      tmp *= x;
      tmp /= y;
      c = tmp;
    }
  }
  return sum >= k;
}
void solve() {
  cin >> n >> k;
  for (int i = 1; i <= (int)(n); ++i) {
    cin >> a[i];
  }
  if (*max_element(a + 1, a + n + 1) >= k) {
    cout << 0;
    return;
  }
  long long l = 0, r = inf;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You have two variables a and b. Consider the following sequence of actions performed with these variables:

  1. If a = 0 or b = 0, end the process. Otherwise, go to step 2;
  2. If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
  3. If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.

Initially the values of a and b are positive integers, and so the process will be finite.

You have to determine the values of a and b after the process ends.

Input

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.

Output

Print two integers — the values of a and b after the end of the process.

Examples

Input

12 5

Output

0 1

Input

31 12

Output

7 12

Note

Explanations to the samples:

  1. a = 12, b = 5 <image> a = 2, b = 5 <image> a = 2, b = 1 <image> a = 0, b = 1;
  2. a = 31, b = 12 <image> a = 7, b = 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int guga[101][101];
int saba = 101;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b;
  cin >> a >> b;
  while (a > 0 && b > 0) {
    if (a >= 2 * b) {
      a = a % (2 * b);
      continue;
    }
    if (b >= 2 * a) {
      b = b % (2 * a);
      continue;
    } else
      break;
  }
  cout << a << ' ' << b;
  return 0;
}

```


### Prompt

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

Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.

A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.

The deck of cards is represented by a string as follows.

abcdeefab

The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.

For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:

eefababcd

You can repeat such shuffle operations.

Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).

Constraints

* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10

Input

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

A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm

The input ends with a single character '-' for the string.

Output

For each dataset, print a string which represents the final state in a line.

Example

Input

aabc
3
1
2
1
vwxyz
2
3
4
-

Output

aabc
xyzvw

### Response

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

using namespace std;

int main(){
	string str;
	cin>>str;
	int m,b;
	while(str!="-"){
		cin>>m;
		int sum=0;
		for(int i=0;i<m;i++){
			cin>>b;
			sum+=b;
		}
		sum%=str.size();
		str=str.substr(sum,str.size()-sum)+str.substr(0,sum);
		cout<<str<<endl;
		cin>>str;
	}
	return 0;
}

```


### Prompt

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

In Omkar's last class of math, he learned about the least common multiple, or LCM. LCM(a, b) is the smallest positive integer x which is divisible by both a and b.

Omkar, having a laudably curious mind, immediately thought of a problem involving the LCM operation: given an integer n, find positive integers a and b such that a + b = n and LCM(a, b) is the minimum value possible.

Can you help Omkar solve his ludicrously challenging math problem?

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10). Description of the test cases follows.

Each test case consists of a single integer n (2 ≤ n ≤ 10^{9}).

Output

For each test case, output two positive integers a and b, such that a + b = n and LCM(a, b) is the minimum possible.

Example

Input

3
4
6
9

Output

2 2
3 3
3 6

Note

For the first test case, the numbers we can choose are 1, 3 or 2, 2. LCM(1, 3) = 3 and LCM(2, 2) = 2, so we output 2 \ 2.

For the second test case, the numbers we can choose are 1, 5, 2, 4, or 3, 3. LCM(1, 5) = 5, LCM(2, 4) = 4, and LCM(3, 3) = 3, so we output 3 \ 3.

For the third test case, LCM(3, 6) = 6. It can be shown that there are no other pairs of numbers which sum to 9 that have a lower LCM.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
bool PALIN(string s) {
  long long int i = 0;
  long long int j = s.length() - 1;
  while (i <= j) {
    if (s[i] != s[j]) return false;
    j--;
    i++;
  }
  return true;
}
int main(void) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n, x = 0;
    cin >> n;
    for (long long int i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        x = i;
        break;
      }
    }
    if (x == 0) {
      x = n;
    }
    cout << n / x << " " << n - (n / x) << "\n";
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m.

Public transport is not free. There are 4 types of tickets:

  1. A ticket for one ride on some bus or trolley. It costs c1 burles;
  2. A ticket for an unlimited number of rides on some bus or on some trolley. It costs c2 burles;
  3. A ticket for an unlimited number of rides on all buses or all trolleys. It costs c3 burles;
  4. A ticket for an unlimited number of rides on all buses and trolleys. It costs c4 burles.

Vasya knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of burles he will have to spend on the tickets.

Input

The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets.

The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use.

The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is going to use the bus number i.

The fourth line contains m integers bi (0 ≤ bi ≤ 1000) — the number of times Vasya is going to use the trolley number i.

Output

Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.

Examples

Input

1 3 7 19
2 3
2 5
4 4 4

Output

12

Input

4 3 2 1
1 3
798
1 2 3

Output

1

Input

100 100 8 100
3 5
7 94 12
100 1 47 0 42

Output

16

Note

In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles.

In the second sample the profitable strategy is to buy one ticket of the fourth type.

In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int c1, c2, c3, c4, n, m, i, x, y;
  scanf("%d", &c1);
  scanf("%d", &c2);
  scanf("%d", &c3);
  scanf("%d", &c4);
  scanf("%d", &n);
  scanf("%d", &m);
  int b1[n + 1];
  int s1[m + 1];
  for (i = 1; i <= n; i++) scanf("%d", &b1[i]);
  for (i = 1; i <= m; i++) scanf("%d", &s1[i]);
  int sum1 = 0, sum2 = 0, sum = 0;
  for (i = 1; i <= n; i++) {
    x = b1[i] * c1;
    y = c2;
    if (x >= y)
      sum1 += y;
    else
      sum1 += x;
  }
  if (sum1 >= c3) sum1 = c3;
  for (i = 1; i <= m; i++) {
    x = s1[i] * c1;
    y = c2;
    if (x >= y)
      sum2 += y;
    else
      sum2 += x;
  }
  if (sum2 >= c3) sum2 = c3;
  sum = sum1 + sum2;
  if (sum >= c4) sum = c4;
  printf("%d\n", sum);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest.

The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A.M.) on January 1. There are n problems for the contest. The penalty time for each solved problem is set as the distance from the moment of solution submission to the New Year in minutes. For example, the problem submitted at 21:00 (9.00 P.M.) gets penalty time 180, as well as the problem submitted at 3:00 (3.00 A.M.). The total penalty time is calculated as the sum of penalty time for all solved problems. It is allowed to submit a problem exactly at the end of the contest, at 6:00 (6.00 A.M.).

Gennady opened the problems exactly at 18:00 (6.00 P.M.) and managed to estimate their complexity during the first 10 minutes of the contest. He believes that writing a solution for the i-th problem will take ai minutes. Gennady can submit a solution for evaluation at any time after he completes writing it. Probably he will have to distract from writing some solution to send the solutions of other problems for evaluation. The time needed to send the solutions can be neglected, i.e. this time can be considered to equal zero. Gennady can simultaneously submit multiple solutions. Besides, he can move at any time from writing one problem to another, and then return to the first problem from the very same place, where he has left it. Thus the total solution writing time of the i-th problem always equals ai minutes. Of course, Gennady does not commit wrong attempts, and his solutions are always correct and are accepted from the first attempt. He can begin to write the solutions starting from 18:10 (6.10 P.M.).

Help Gennady choose from the strategies that help him solve the maximum possible number of problems, the one with which his total penalty time will be minimum.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of the problems. The next line contains n space-separated integers ai (1 ≤ ai ≤ 720) — each number shows how much time in minutes Gennady will spend writing a solution to the problem.

Output

Print two integers — the number of problems Gennady will solve and the total penalty time considering that he chooses the optimal strategy.

Examples

Input

3
30 330 720

Output

2 10

Note

In the sample, one of Gennady's possible optimal strategies is as follows. At 18:10 (6:10 PM) he begins to write the first problem and solves it in 30 minutes (18:40 or 6.40 P.M.). At 18:40 (6.40 P.M.) he begins to write the second problem. There are 320 minutes left before the New Year, so Gennady does not have the time to finish writing the second problem before the New Year. At 0:00 (12.00 A.M.) he distracts from the second problem, submits the first one, and returns immediately to writing the second problem. At 0:10 (0.10 A.M.), he completes the solution for the second problem, submits it and gets 10 minute penalty time. Note that as the total duration of the contest is 720 minutes and Gennady has already spent 10 minutes on reading the problems, he will not have time to solve the third problem during the contest. Yes, such problems happen to exist.

Competitions by the given rules are held annually on the site http://b23.ru/3wvc

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[111];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &arr[i]);
  sort(arr, arr + n);
  int t = 10;
  int ans = 0;
  int qts = 0;
  for (int i = (0); i < (n); ++i) {
    t += arr[i];
    if (t > 720) break;
    qts++;
    if (t > 360) ans += (t - 360);
  }
  printf("%d %d\n", qts, ans);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

I decided to create a program that displays a "round and round pattern". The "round and round pattern" is as follows.

* If the length of one side is n, it is displayed as a character string with n rows and n columns.
* A spiral pattern that rotates clockwise with the lower left corner as the base point.
* The part with a line is represented by # (half-width sharp), and the blank part is represented by "" (half-width blank).
* Leave a space between the lines.

Create a program that takes an integer n as an input and outputs a "round and round pattern" with a side length of n.

Input

The input is given in the following format:

d
n1
n2
::
nd

The number of datasets d (d ≤ 20) is given to the first line, and the side length ni (1 ≤ ni ≤ 100) of the i-th round pattern is given to each of the following d lines.

Output

Please output a round and round pattern for each data set. Insert a blank line between the datasets.

Example

Input

2
5
6

Output

#####
#   #
# # #
# # #
# ###

######
#    #
# ## #
# #  #
# #  #
# ####

### Response

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

char A[100][100];

int main() {
    int D; cin >> D;
    while(D--) {
        int N; cin >> N;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                A[i][j] = ' ';
            }
        }
        int x = 0, y = N;
        const int dx[] = { 0, 1, 0, -1 };
        const int dy[] = { -1, 0, 1, 0 };
        int dir = 0;
        for(int i = 0; i < N; i++) {
            int k;
            if(i == 0) k = N;
            else k = N + 1 - (i + 1) / 2 * 2;

            for(int j = 0; j < k; j++) {
                x += dx[dir]; y += dy[dir];
                A[y][x] = '#';
            }
            (dir += 1) %= 4;
        }
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                cout << A[i][j];
            }
            cout << endl;
        }
        if(D != 0) cout << endl;
    }
}
```


### Prompt

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

Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city he wants by following roads.

<image>

Some girl has stolen Barney's heart, and Barney wants to find her. He starts looking for in the root of the tree and (since he is Barney Stinson not a random guy), he uses a random DFS to search in the cities. A pseudo code of this algorithm is as follows:

    let starting_time be an array of length n
    current_time = 0
    dfs(v):
    	current_time = current_time + 1
    	starting_time[v] = current_time
    	shuffle children[v] randomly (each permutation with equal possibility)
    	// children[v] is vector of children cities of city v
    	for u in children[v]:
    		dfs(u)

As told before, Barney will start his journey in the root of the tree (equivalent to call dfs(1)).

Now Barney needs to pack a backpack and so he wants to know more about his upcoming journey: for every city i, Barney wants to know the expected value of starting_time[i]. He's a friend of Jon Snow and knows nothing, that's why he asked for your help.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105) — the number of cities in USC.

The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi < i), where pi is the number of the parent city of city number i in the tree, meaning there is a road between cities numbered pi and i in USC.

Output

In the first and only line of output print n numbers, where i-th number is the expected value of starting_time[i].

Your answer for each city will be considered correct if its absolute or relative error does not exceed 10 - 6.

Examples

Input

7
1 2 1 1 4 4

Output

1.0 4.0 5.0 3.5 4.5 5.0 5.0

Input

12
1 1 2 2 4 4 3 3 1 10 8

Output

1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
double PI = 4 * atan(1);
double val[100005];
int numc[100005], par[100005];
vector<int> child[100005];
int dfs(int node) {
  for (int i : child[node]) numc[node] += dfs(i);
  numc[node]++;
  return numc[node];
}
void dfs2(int node) {
  val[node] = val[par[node]];
  val[node] += double(numc[par[node]] - numc[node] + 1) / 2.0;
  for (int i : child[node]) dfs2(i);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i < n + 1; i++) {
    int x;
    cin >> x;
    child[x].push_back(i);
    par[i] = x;
  }
  dfs(1);
  val[1] = 1.0;
  for (int i : child[1]) dfs2(i);
  cout << fixed << setprecision(1);
  for (int i = 1; i < n + 1; i++) cout << val[i] << " ";
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive):

* Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.

Constraints

* 1 \leq |S| \leq 300
* 0 \leq K \leq 10^9
* S consists of `0` and `1`.

Input

Input is given from Standard Input in the following format:

S K

Output

Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive).

Examples

Input

0101 1

Output

4

Input

01100110 2

Output

14

Input

1101010010101101110111100011011111011000111101110101010010101010101 20

Output

113434815

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod = 998244353;
int f[305][305][305], n, m, a[305];
char s[305];
inline int abs(const int &x){return x<0?-x:x;}
inline int add(const int &x, const int &y){return x+y>=mod?x+y-mod:x+y;}
int main() {
	scanf("%s%d",s+1,&m);
	for(int i=1, L=strlen(s+1), pre=0;i<=L;i++) {
		if(s[i]=='0') {
			a[++n]=i-pre-1;
			pre=i;
		} else if(i==L) {
			a[++n]=i-pre;
		}
	}
	m=min(m,int(strlen(s+1)));
	f[n+1][0][0]=1;
	for(int i=n+1;i>1;i--) {
		for(int p=0;p<=m;p++) {
			for(int j=0;j<=m;j++) if(f[i][p][j]){
				for(int k=0;k<=m;k++) {
					if(k<=p) {
						f[i-1][p-k][j]=add(f[i][p][j],f[i-1][p-k][j]);
					}
					if(k<=a[i-1]&&k) {
						f[i-1][p+k][j+k]=add(f[i][p][j],f[i-1][p+k][j+k]);
					}
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<=m;i++) ans=add(ans,f[1][0][i]);
	printf("%d\n",ans);
	return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Two beavers, Timur and Marsel, play the following game.

There are n logs, each of exactly m meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than k meters. Each resulting part is also a log which can be gnawed in future by any beaver. The beaver that can't make a move loses. Thus, the other beaver wins.

Timur makes the first move. The players play in the optimal way. Determine the winner.

Input

The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 109).

Output

Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes.

Examples

Input

1 15 4

Output

Timur

Input

4 9 5

Output

Marsel

Note

In the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as k = 4. Thus, the winner is Timur.

In the second example the beavers have 4 logs 9 meters in length. Timur can't split any of them, so that the resulting parts possessed the length of not less than 5 meters, that's why he loses instantly.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const double EPS = 1e-9;
const long long INF = 1000000000 + 5;
int n, m, k;
map<pair<int, int>, int> list;
int main() {
  cin >> n >> m >> k;
  int ans = 0;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      if (i >= k && m / i > 1) ans = 1;
      if (i > 1 && m / i >= k) ans = 1;
    }
  }
  if (n % 2 == 0) ans = 0;
  if (ans)
    printf("Timur");
  else
    printf("Marsel");
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i.

Snuke will perform the following operation zero or more times:

* Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.

Find the number of possible final sequences of colors of the stones, modulo 10^9+7.

Constraints

* 1 \leq N \leq 2\times 10^5
* 1 \leq C_i \leq 2\times 10^5(1\leq i\leq N)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
C_1
:
C_N

Output

Print the number of possible final sequences of colors of the stones, modulo 10^9+7.

Examples

Input

5
1
2
1
2
2

Output

3

Input

6
4
2
5
4
2
4

Output

5

Input

7
1
3
1
2
3
3
2

Output

5

### Response

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

int main() {
    int n;
    cin >> n;
    long ans = 1;
    int prev = -1;
    unordered_map<int, int> counter;
    for (int i = 0; i < n; i++) {
        int c;
        cin >> c;
        if (c != prev) {
            ans += counter[c];
            ans %= MOD;
        }
        prev = c;
        counter[c] = ans;
    }
    cout << ans << endl;
    return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of:

  * Operation AND ('&', ASCII code 38)
  * Operation OR ('|', ASCII code 124)
  * Operation NOT ('!', ASCII code 33)
  * Variables x, y and z (ASCII codes 120-122)
  * Parentheses ('(', ASCII code 40, and ')', ASCII code 41)

If more than one expression of minimum length exists, you should find the lexicographically smallest one.

Operations have standard priority. NOT has the highest priority, then AND goes, and OR has the lowest priority. The expression should satisfy the following grammar:

E ::= E '|' T | T

T ::= T '&' F | F

F ::= '!' F | '(' E ')' | 'x' | 'y' | 'z'

Input

The first line contains one integer n — the number of functions in the input (1 ≤ n ≤ 10 000).

The following n lines contain descriptions of functions, the i-th of them contains a string of length 8 that consists of digits 0 and 1 — the truth table of the i-th function. The digit on position j (0 ≤ j < 8) equals to the value of the function in case of <image>, <image> and <image>.

Output

You should output n lines, the i-th line should contain the expression of minimum length which equals to the i-th function. If there is more than one such expression, output the lexicographically smallest of them. Expressions should satisfy the given grammar and shouldn't contain white spaces.

Example

Input

4
00110011
00000111
11110000
00011111

Output

y
(y|z)&x
!x
x|y&z

Note

The truth table for the second function:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, U;
char s[20];
struct table {
  int f, tp;
  string s;
  table(void) {}
  table(int _f, int t, string a) : f(_f), tp(t), s(a) {}
  inline bool operator<(const table &b) const {
    if (s.size() == b.s.size()) return s < b.s;
    return s.size() < b.s.size();
  }
};
table ans[N][4];
int vis[N][4];
set<table> S;
set<table>::iterator it;
vector<table> don;
inline void Push(int f, int tp, string s) {
  table u = table(f, tp, s);
  if (!vis[f][tp]) {
    vis[f][tp] = 1;
    ans[f][tp] = u;
    S.insert(u);
  } else if (u < ans[f][tp]) {
    S.erase(ans[f][tp]);
    ans[f][tp] = u;
    S.insert(u);
  }
}
int main(void) {
  Push(240, 0, "x");
  Push(204, 0, "y");
  Push(170, 0, "z");
  U = (1 << 8) - 1;
  while (!S.empty()) {
    it = S.begin();
    table cur = *it;
    S.erase(it);
    Push(cur.f, 0, '(' + cur.s + ')');
    if (cur.tp == 0) Push(cur.f ^ U, 0, '!' + cur.s);
    don.push_back(cur);
    for (table x : don) {
      if (cur.tp < 2 && x.tp < 2)
        Push(cur.f & x.f, 1, min(cur.s, x.s) + '&' + max(cur.s, x.s));
      Push(cur.f | x.f, 2, min(cur.s, x.s) + '|' + max(cur.s, x.s));
    }
  }
  for (int i = 0; i <= U; i++)
    ans[i][0] = min(ans[i][0], min(ans[i][1], ans[i][2]));
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    int f = 0;
    for (int i = 7; ~i; i--) f = f << 1 | (s[i] - '0');
    cout << ans[f][0].s << endl;
  }
  return 0;
}

```


### Prompt

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

Input

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

Output

Output "YES" or "NO".

Examples

Input

2 3

Output

YES

Input

3 2

Output

NO

Input

33 16

Output

YES

Input

26 5

Output

NO

### Response

```cpp

/*
    بسم الله الرحمن الرحيم

     الجامعة الإسلامية العالمية شيتاغونغ

    لا تحزن ان الله معنا
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i, a, b) for (ll i=a; i<b; i++)

ll gcd(ll a, ll b)
{
    if (b==0) return a;
    return gcd(b, a%b);
}

void solve()
{
    ll n, m, arr[1001] ={0};
    cin >> n >> m;
    while(n)
    {
        arr[n % m] ++;
        n /= m;
    }

    ll f = 0;
    fr(i, 0, m)
    {
        if (arr[i] > 1)
        {
            f = 1;
            cout << "NO\n";
            break;
        }
    }
    if (!f) cout << "YES\n";
}

int main()
{
    solve();
    return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

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

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

Input

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

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

Output

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

Examples

Input

7
2 1 5 11 5 9 11

Output

9

Input

5
5 4 3 2 1

Output

12

Note

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

2 3 5 6 7 9 11

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

And for the second sample:

1 2 3 4 5

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
const int nMax = 3000 + 1 + 9;
int midian[nMax][nMax];
long long cost[nMax][nMax];
int A[nMax], B[nMax];
int n;
long long dp[nMax], last[nMax];
void prepro() {
  for (int start = 1; start <= n; start++) {
    priority_queue<int> P;
    priority_queue<int, vector<int>, greater<int> > Q;
    long long sumP = 0, sumQ = 0;
    for (int i = start; i <= n; i++) {
      int minQ = Q.empty() ? -(2000000000) : Q.top();
      if (B[i] >= minQ) {
        Q.push(B[i]);
        sumQ += B[i];
        if (Q.size() == P.size() + 2) {
          int minQ = Q.top();
          Q.pop();
          sumQ -= minQ;
          P.push(minQ);
          sumP += minQ;
        }
      } else {
        P.push(B[i]);
        sumP += B[i];
        if (P.size() == Q.size() + 1) {
          int maxP = P.top();
          P.pop();
          sumP -= maxP;
          Q.push(maxP);
          sumQ += maxP;
        }
      }
      int mid;
      mid = Q.top();
      mid = Q.size() == P.size() + 1 ? mid : P.top();
      midian[start][i] = mid;
      long long costP = 1LL * P.size() * mid - sumP;
      long long costQ = sumQ - 1LL * Q.size() * mid;
      cost[start][i] = costP + costQ;
    }
  }
}
void build_dp() {
  dp[0] = 0, last[0] = -(2000000000);
  for (int j = 1; j <= n; j++) {
    dp[j] = LLONG_MAX;
    for (int i = 0; i < j; i++) {
      if (last[i] >= midian[i + 1][j] + i + 1) continue;
      long long nw = dp[i] + cost[i + 1][j];
      long long nwl = 0LL + midian[i + 1][j] + j;
      if (dp[j] > nw) {
        dp[j] = nw;
        last[j] = nwl;
      } else if (dp[j] == nw) {
        last[j] = min(last[j], nwl);
      }
    }
  }
}
int main() {
  read_file();
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &A[i]), B[i] = A[i] - i;
    prepro();
    build_dp();
    long long ans = dp[n];
    printf("%lld\n", ans);
  }
}

```


### Prompt

Generate a CPP solution to the following problem:

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

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

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

Input

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

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

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

It is possible that some segments coincide.

Output

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

Examples

Input

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

Output

2

Input

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

Output

1

Input

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

Output

-1

Note

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

<image>

### Response

```cpp
#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }
void M() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
int n, s, m, k, mem[1509][1509], arr1[1509], arr2[1509], nxt[1509];
vector<int> v1, org;
vector<pair<int, int> > v2;
int solve(int i, int rem) {
  if (rem <= 0) return 0;
  if (i == n) return m + 1;
  int &ret = mem[i][rem];
  if (ret != -1) return ret;
  int ans;
  ans = solve(i + 1, rem);
  if (nxt[i] != -1) ans = min(ans, 1 + solve(nxt[i], rem - arr2[i]));
  return ret = ans;
}
bool check(int L) {
  memset(arr1, 0, sizeof(arr1));
  for (int i = 0; i < n; i++) {
    if (org[i] <= L) arr1[i]++;
    if (i) arr1[i] += arr1[i - 1];
  }
  for (int i = 0; i < n; i++) {
    if (nxt[i] == -1) continue;
    arr2[i] = arr1[nxt[i] - 1];
    if (i) arr2[i] -= arr1[i - 1];
  }
  memset(mem, -1, sizeof(mem));
  return solve(0, k) <= m;
}
int main() {
  M();
  cin >> n >> s >> m >> k;
  int no;
  for (int i = 0; i < n; i++) {
    cin >> no;
    org.push_back(no);
    v1.push_back(no);
  }
  sort(((v1).begin()), ((v1).end()));
  int l, r;
  for (int i = 0; i < s; i++) {
    cin >> l >> r;
    l--;
    r--;
    v2.push_back(make_pair(l, r));
  }
  sort(((v2).begin()), ((v2).end()));
  memset(nxt, -1, sizeof(nxt));
  for (int i = 0; i < s; i++) {
    for (int j = v2[i].first; j <= v2[i].second; j++)
      nxt[j] = max(nxt[j], v2[i].second + 1);
  }
  l = 0;
  r = n - 1;
  int mid, res = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(v1[mid])) {
      r = mid - 1;
      res = v1[mid];
    } else
      l = mid + 1;
  }
  cout << res << endl;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.

Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).

In one move Koa:

  1. selects some subset of positions p_1, p_2, …, p_k (k ≥ 1; 1 ≤ p_i ≤ n; p_i ≠ p_j if i ≠ j) of A such that A_{p_1} = A_{p_2} = … = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).

  2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).

  3. sets each letter in positions p_1, p_2, …, p_k to letter y. More formally: for each i (1 ≤ i ≤ k) Koa sets A_{p_i} = y.

Note that you can only modify letters in string A.

Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!

Input

Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10) — the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer n (1 ≤ n ≤ 10^5) — the length of strings A and B.

The second line of each test case contains string A (|A|=n).

The third line of each test case contains string B (|B|=n).

Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).

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

Output

For each test case:

Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.

Example

Input

5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda

Output

2
-1
3
2
-1

Note

  * In the 1-st test case Koa:
    1. selects positions 1 and 2 and sets A_1 = A_2 =  b (\color{red}{aa}b → \color{blue}{bb}b).
    2. selects positions 2 and 3 and sets A_2 = A_3 =  c (b\color{red}{bb} → b\color{blue}{cc}).

  * In the 2-nd test case Koa has no way to make string A equal B.

  * In the 3-rd test case Koa:
    1. selects position 1 and sets A_1 =  t (\color{red}{a}bc → \color{blue}{t}bc).
    2. selects position 2 and sets A_2 =  s (t\color{red}{b}c → t\color{blue}{s}c).
    3. selects position 3 and sets A_3 =  r (ts\color{red}{c} → ts\color{blue}{r}).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, k, l, t, x, y;
  string str = "abcdefghijklmnopqrst";
  cin >> t;
  while (t--) {
    cin >> n;
    string a, b;
    cin >> a >> b;
    long long int f = 0;
    for (i = 0; i < n; i++) {
      if (a[i] > b[i]) {
        f = 1;
        break;
      }
    }
    if (f) {
      cout << -1 << endl;
      continue;
    }
    long long int sum = 0;
    for (j = 0; j < 20; j++) {
      char ch = str[j];
      char c = 'z';
      long long int qq = 0;
      for (i = 0; i < n; i++) {
        if (a[i] == ch && a[i] != b[i]) {
          qq = 1;
          if (b[i] < c) {
            c = b[i];
          }
        }
      }
      sum += qq;
      for (l = 0; l < n; l++) {
        if (a[l] == ch && a[l] != b[l]) {
          a[l] = c;
        }
      }
      if (a == b) break;
    }
    cout << sum << endl;
  }
}

```


### Prompt

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

Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.

A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe.

<image> The figure shows a 4-output splitter

Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.

Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.

Input

The first line contains two space-separated integers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 109).

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

Output

Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.

Examples

Input

4 3

Output

2

Input

5 5

Output

1

Input

8 4

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k;
bool ok(long long x) {
  long long ans = (k * (k + 1)) / 2;
  ans -= ((k - x) * (k - x + 1)) / 2;
  ans -= x - 1;
  if (ans >= n) return true;
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  long long low = 0, high = k - 1;
  long long ans = -1;
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (ok(mid)) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Karen is getting ready for a new school day!

<image>

It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.

What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?

Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.

Input

The first and only line of input contains a single string in the format hh:mm (00 ≤  hh ≤ 23, 00 ≤  mm ≤ 59).

Output

Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.

Examples

Input

05:39

Output

11

Input

13:31

Output

0

Input

23:59

Output

1

Note

In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.

In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.

In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s, s1;
int ans, h, hh, m, mm;
int main() {
  cin >> s;
  while (1) {
    h = s[0] - 48;
    hh = s[1] - 48;
    m = s[3] - 48;
    mm = s[4] - 48;
    if (h == mm && hh == m) {
      break;
    }
    mm++;
    if (mm == 10) {
      mm = 0;
      m++;
      if (m == 6) {
        m = 0;
        hh++;
        if (hh == 10) {
          hh = 0;
          h++;
        }
        if (hh == 4 && h == 2) {
          hh = 0;
          h = 0;
        }
      }
    }
    s[0] = h + 48;
    s[1] = hh + 48;
    s[3] = m + 48;
    s[4] = mm + 48;
    ans++;
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!

It is well-known that there are n cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of cities is connected by no more than one road. It is not guaranteed that the road network is connected, i.e. it is possible that you can't reach some city from some other.

The tour will contain several episodes. In each of the episodes:

  * the wizard will disembark at some city x from the Helicopter;
  * he will give a performance and show a movie for free at the city x;
  * he will drive to some neighboring city y using a road;
  * he will give a performance and show a movie for free at the city y;
  * he will drive to some neighboring to y city z;
  * he will give a performance and show a movie for free at the city z;
  * he will embark the Helicopter and fly away from the city z.

It is known that the wizard doesn't like to use roads, so he agrees to use each road at most once (regardless of direction). In other words, for road between a and b he only can drive once from a to b, or drive once from b to a, or do not use this road at all.

The wizards wants to plan as many episodes as possible without violation the above rules. Help the wizard!

Please note that the wizard can visit the same city multiple times, the restriction is on roads only.

Input

The first line contains two integers n, m (1 ≤ n ≤ 2·105, 0 ≤ m ≤ 2·105) — the number of cities and the number of roads in Berland, respectively.

The roads description follow, one in each line. Each description is a pair of two integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), where ai and bi are the ids of the cities connected by the i-th road. It is guaranteed that there are no two roads connecting the same pair of cities. Every road is bidirectional. The cities are numbered from 1 to n.

It is possible that the road network in Berland is not connected.

Output

In the first line print w — the maximum possible number of episodes. The next w lines should contain the episodes in format x, y, z — the three integers denoting the ids of the cities in the order of the wizard's visits.

Examples

Input

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

Output

2
1 4 2
4 3 2

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
const int MAXN = 2e5 + 5;
vector<pair<int, pair<int, int>>> ans;
vector<vector<int>> adj(MAXN);
vector<bool> vis(MAXN, 0);
vector<int> tin(MAXN, 0);
int timer = 0;
bool dfs(int v, int u) {
  vis[v] = 1;
  tin[v] = ++timer;
  vector<int> can;
  for (int x : adj[v]) {
    if (x == u) continue;
    if (!vis[x]) {
      if (dfs(x, v)) can.push_back(x);
    } else if (tin[x] < tin[v]) {
      can.push_back(x);
    }
  }
  for (int i = 1; i < (int)(can.size()); i += 2) {
    ans.push_back({can[i], {v, can[i - 1]}});
  }
  if ((int)(can.size()) % 2 == 0) return 1;
  if (u != -1) {
    int s = (int)(can.size()) - 1;
    ans.push_back({can[s], {v, u}});
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i, -1);
    }
  }
  cout << (int)(ans.size()) << '\n';
  for (auto x : ans) {
    cout << x.first << " " << x.second.first << " " << x.second.second << '\n';
  }
}

```


### Prompt

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

An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.

Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:

  1. initially the atom is in the state i,
  2. we spend Ek - Ei energy to put the atom in the state k,
  3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
  4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
  5. the process repeats from step 1.

Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.

Due to some limitations, Arkady can only choose such three states that Ek - Ei ≤ U.

Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.

Input

The first line contains two integers n and U (3 ≤ n ≤ 105, 1 ≤ U ≤ 109) — the number of states and the maximum possible difference between Ek and Ei.

The second line contains a sequence of integers E1, E2, ..., En (1 ≤ E1 < E2... < En ≤ 109). It is guaranteed that all Ei are given in increasing order.

Output

If it is not possible to choose three states that satisfy all constraints, print -1.

Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.

Examples

Input

4 4
1 3 5 7

Output

0.5

Input

10 8
10 13 15 16 17 19 20 22 24 25

Output

0.875

Input

3 1
2 5 10

Output

-1

Note

In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.

In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int Set(int n, int pos) { return n = n | (1 << pos); }
int reset(int n, int pos) { return n = n & ~(1 << pos); }
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
};
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); };
int ara[100005];
int ans = 0;
int bs(int i, int n, int u) {
  int lo = i + 2, hi = n, mid;
  ans = 0;
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (ara[mid] - ara[i] <= u) {
      lo = mid + 1;
      ans = mid;
    } else
      hi = mid - 1;
  }
  return ans;
}
int main() {
  int n, u;
  scanf("%d%d", &n, &u);
  for (int i = 1; i <= n; i++) scanf("%d", &ara[i]);
  int lo = 1, hi = n;
  double ans = 0.0;
  for (int i = 1; i <= n; i++) {
    int k = bs(i, n, u);
    if (k == 0) continue;
    int tmp = ara[k] - ara[i + 1], tmp2 = ara[k] - ara[i];
    double tmp3 = (1.0 * tmp) / (1.0 * tmp2);
    if (tmp3 > ans) {
      ans = tmp3;
    }
  }
  if (ans == 0.0) {
    printf("-1\n");
    return 0;
  }
  printf("%.15lf", ans);
}

```


### Prompt

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

Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if

  1. the sequence consists of at least two elements
  2. f0 and f1 are arbitrary
  3. fn + 2 = fn + 1 + fn for all n ≥ 0.

You are given some sequence of integers a1, a2, ..., an. Your task is rearrange elements of this sequence in such a way that its longest possible prefix is Fibonacci-ish sequence.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 1000) — the length of the sequence ai.

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

Output

Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement.

Examples

Input

3
1 2 -1

Output

3

Input

5
28 35 7 14 21

Output

4

Note

In the first sample, if we rearrange elements of the sequence as  - 1, 2, 1, the whole sequence ai would be Fibonacci-ish.

In the second sample, the optimal way to rearrange elements is <image>, <image>, <image>, <image>, 28.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 5;
int a[1005], b[1005], sum[1005], pos[1005];
int main() {
  int res = 0, mx = -1, n, l = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    mx = max(a[i], mx);
    if (a[i] == 0) ++res;
  }
  sort(a + 1, a + 1 + n);
  b[++l] = a[1];
  for (int i = 2; i <= n; ++i)
    if (a[i] != a[i - 1]) b[++l] = a[i];
  for (int i = 1; i <= n; ++i) {
    pos[i] = lower_bound(b + 1, b + 1 + l, a[i]) - b;
    ++sum[pos[i]];
  }
  int ans = 2;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (j == i) continue;
      if (a[i] == 0 && a[j] == 0) continue;
      int x = a[i], y = a[j], cnt = 2;
      vector<int> t;
      t.clear();
      sum[pos[i]]--;
      sum[pos[j]]--;
      t.push_back(pos[i]);
      t.push_back(pos[j]);
      while (x + y <= mx) {
        int z = lower_bound(b + 1, b + 1 + l, x + y) - b;
        if (z == l + 1 || b[z] != x + y || !sum[z]) break;
        sum[z]--;
        t.push_back(z);
        int tmp = x + y;
        x = y;
        y = tmp;
        ++cnt;
      }
      for (int k = 0; k < t.size(); k++) sum[t[k]]++;
      ans = max(ans, cnt);
    }
  }
  printf("%d\n", max(ans, res));
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are running for a governor in a small city in Russia. You ran some polls and did some research, and for every person in the city you know whom he will vote for, and how much it will cost to bribe that person to vote for you instead of whomever he wants to vote for right now. You are curious, what is the smallest amount of money you need to spend on bribing to win the elections. To win elections you need to have strictly more votes than any other candidate.

Input

First line contains one integer n (1 ≤ n ≤ 105) — number of voters in the city. Each of the next n lines describes one voter and contains two integers ai and bi (0 ≤ ai ≤ 105; 0 ≤ bi ≤ 104) — number of the candidate that voter is going to vote for and amount of money you need to pay him to change his mind. You are the candidate 0 (so if a voter wants to vote for you, ai is equal to zero, in which case bi will also be equal to zero).

Output

Print one integer — smallest amount of money you need to spend to win the elections.

Examples

Input

5
1 2
1 2
1 2
2 1
0 0

Output

3

Input

4
1 2
1 2
2 1
0 0

Output

2

Input

1
100000 0

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int my = 0;
int n;
int check(int m) {
  int mx = 0;
  vector<int> nv;
  int ans = 0;
  int have = my;
  for (int i = 1; i <= 100000; ++i) {
    mx = max(mx, (int)v[i].size());
    for (int j = 0, s = v[i].size(); j < s; ++j) {
      if (s - j <= m)
        nv.push_back(v[i][j]);
      else {
        ans += v[i][j];
        have++;
      }
    }
  }
  int t = m - have;
  sort(nv.begin(), nv.end());
  for (int i = 0; i < t + (mx >= m) && i < nv.size(); ++i) ans += nv[i];
  return ans;
}
int main() {
  int a, b;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a, &b);
    if (a != 0)
      v[a].push_back(b);
    else
      my++;
  }
  for (int i = 1; i <= 100000; ++i) sort(v[i].begin(), v[i].end());
  int l = 0, r = n;
  while (r - l > 2) {
    int m1 = l + (r - l) / 3;
    int m2 = r - (r - l) / 3;
    if (check(m1) < check(m2)) {
      r = m2;
    } else {
      l = m1;
    }
  }
  int ans = 0x3f3f3f3f;
  for (int i = l; i <= r; ++i) {
    ans = min(ans, check(i));
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

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 <iostream>

using namespace std;

int main() {
    unsigned long long n,a,b;
    cin>>n>>a>>b;
    cout<<(n/(a+b))*a+min(n%(a+b),a);
    return 0;
}
```


### Prompt

Please create a solution in cpp to the following problem:

wHAT DO WE NEED cAPS LOCK FOR?

Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.

Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:

  * either it only contains uppercase letters;
  * or all letters except for the first one are uppercase.

In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.

Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.

Input

The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.

Output

Print the result of the given word's processing.

Examples

Input

cAPS

Output

Caps

Input

Lock

Output

Lock

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int i;
  int j, flag = 1;
  char Str[100];
  scanf("%s", Str);
  for (i = 1; Str[i] != '\0'; i++) {
    if (Str[i] >= 97 && Str[i] <= 122) {
      flag = 0;
      break;
    }
  }
  if (flag == 1) {
    if (Str[0] >= 65 && Str[0] <= 90)
      Str[0] = Str[0] + 32;
    else
      Str[0] = Str[0] - 32;
    for (j = 1; Str[j] != '\0'; j++) {
      Str[j] = Str[j] + 32;
    }
  }
  printf("%s\n", Str);
  return 0;
}

```