### Prompt

Please formulate a Cpp solution to the following problem:

For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.

Input

The entire input looks like:

q (the number of queries)
1st query
2nd query
...
qth query

Each query consists of integer coordinates of end points of s1 and s2 in the following format:

xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3

Output

For each query, print "1" or "0".

Example

Input

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

Output

1
1
0

### Response

```cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
const double PI = acos(-1);
inline bool equals(double a, double b) { return abs(b - a) < EPS; }
using Point = complex<double>;
namespace std { bool operator < (const Point &a, const Point &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } }
struct Line
{
    Point a, b;
    Line(Point a, Point b) : a(a), b(b) {}
};
inline double dot(const Point &a, const Point &b) { return real(a) * real(b) + imag(a) * imag(b); }
inline double cross(const Point &a, const Point &b) { return real(a) * imag(b) - imag(a) * real(b); }
inline bool isParallel(const Line &a, const Line &b) { return equals(cross(a.b - a.a, b.b - b.a), 0.0); }
inline bool isOrthogonal(const Line &a, const Line &b) { return equals(dot(a.a - a.b, b.a - b.b), 0.0); }
inline Point projection(const Line &l, const Point &p)
{
    double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
    return l.a + (l.a - l.b) * t;
}
inline Point reflection(const Line &l, const Point &p) { return p + (projection(l, p) - p) * 2.0; }
inline int ccw(const Point &a, Point b, Point c)
{
    b = b - a, c = c - a;
    if(cross(b, c) > EPS) return 1;
    if(cross(b, c) < -EPS) return -1;
    if(dot(b, c) < 0) return 2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}
inline bool isIntersect(const Point &a, const Point &b, const Point &c, const Point &d) { return (ccw(a, b, c) * ccw(a, b, d) <= 0) and (ccw(c, d, a) * ccw(c, d, b) <= 0); }
inline bool isIntersect(const Line &l, const Line &m) { return isIntersect(l.a, l.b, m.a, m.b); }
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(8);
    int n; cin >> n;
    while(n--)
    {
        double x0, y0, x1, y1, x2, y2, x3, y3; cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        Point a = Point(x0, y0), b = Point(x1, y1), c = Point(x2, y2), d = Point(x3, y3);
        int res = isIntersect(Line(a, b), Line(c, d));
        cout << res << endl;
    }
    return 0;
}

```


### Prompt

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

Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s.

String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".

Dr. Moriarty plans to take string s and cut out some substring from it, let's call it t. Then he needs to change the substring t zero or more times. As a result, he should obtain a fixed string u (which is the string that should be sent to Sherlock Holmes). One change is defined as making one of the following actions:

  * Insert one letter to any end of the string.
  * Delete one letter from any end of the string.
  * Change one letter into any other one.

Moriarty is very smart and after he chooses some substring t, he always makes the minimal number of changes to obtain u.

Help Moriarty choose the best substring t from all substrings of the string s. The substring t should minimize the number of changes Moriarty should make to obtain the string u from it.

Input

The first line contains a non-empty string s, consisting of lowercase Latin letters. The second line contains a non-empty string u, consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000, inclusive.

Output

Print the only integer — the minimum number of changes that Dr. Moriarty has to make with the string that you choose.

Examples

Input

aaaaa
aaa

Output

0

Input

abcabc
bcd

Output

1

Input

abcdef
klmnopq

Output

7

Note

In the first sample Moriarty can take any substring of length 3, and it will be equal to the required message u, so Moriarty won't have to make any changes.

In the second sample you should take a substring consisting of characters from second to fourth ("bca") or from fifth to sixth ("bc"). Then you will only have to make one change: to change or to add the last character.

In the third sample the initial string s doesn't contain any character that the message should contain, so, whatever string you choose, you will have to make at least 7 changes to obtain the required message.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[2222], u[2222];
int l, ll, ans;
int main() {
  gets(s);
  gets(u);
  l = strlen(s);
  ll = strlen(u);
  ans = ll;
  for (int j = -ll; j <= l; j++) {
    int cnt = 0;
    for (int i = 0; i < ll; i++) {
      if (i + j < 0 || i + j >= l)
        cnt++;
      else
        cnt += (s[i + j] != u[i]);
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest patissiers in the world. Those who are invited to his birthday party are gourmets from around the world. They are eager to see and eat his extremely creative cakes. Now a large box-shaped cake is being carried into the party. It is not beautifully decorated and looks rather simple, but it must be delicious beyond anyone's imagination. Let us cut it into pieces with a knife and serve them to the guests attending the party.

The cake looks rectangular, viewing from above (Figure C-1). As exemplified in Figure C-2, the cake will iteratively be cut into pieces, where on each cut exactly a single piece is cut into two smaller pieces. Each cut surface must be orthogonal to the bottom face and must be orthogonal or parallel to a side face. So, every piece shall be rectangular looking from above and every side face vertical.

<image>

Figure C-1: The top view of the cake
<image>

Figure C-2: Cutting the cake into pieces

Piece sizes in Figure C-2 vary significantly and it may look unfair, but you don't have to worry. Those guests who would like to eat as many sorts of cakes as possible often prefer smaller pieces. Of course, some prefer larger ones.

Your mission of this problem is to write a computer program that simulates the cutting process of the cake and reports the size of each piece.

Input

The input is a sequence of datasets, each of which is of the following format.

> n  w  d
>  p1  s1
>  ...
>  pn  sn
>

The first line starts with an integer n that is between 0 and 100 inclusive. It is the number of cuts to be performed. The following w and d in the same line are integers between 1 and 100 inclusive. They denote the width and depth of the cake, respectively. Assume in the sequel that the cake is placed so that w and d are the lengths in the east-west and north-south directions, respectively.

Each of the following n lines specifies a single cut, cutting one and only one piece into two. pi is an integer between 1 and i inclusive and is the identification number of the piece that is the target of the i-th cut. Note that, just before the i-th cut, there exist exactly i pieces. Each piece in this stage has a unique identification number that is one of 1, 2, ..., i and is defined as follows:

* The earlier a piece was born, the smaller its identification number is.
* Of the two pieces born at a time by the same cut, the piece with the smaller area (looking from above) has the smaller identification number. If their areas are the same, you may define as you like the order between them, since your choice in this case has no influence on the final answer.

Note that identification numbers are adjusted after each cut.

si is an integer between 1 and 1000 inclusive and specifies the starting point of the i-th cut. From the northwest corner of the piece whose identification number is pi, you can reach the starting point by traveling si in the clockwise direction around the piece. You may assume that the starting point determined in this way cannot be any one of the four corners of the piece. The i-th cut surface is orthogonal to the side face on which the starting point exists.

The end of the input is indicated by a line with three zeros.

Output

For each dataset, print in a line the areas looking from above of all the pieces that exist upon completion of the n cuts specified in the dataset. They should be in ascending order and separated by a space. When multiple pieces have the same area, print it as many times as the number of the pieces.

Example

Input

3 5 6
1 18
2 19
1 2
3 4 1
1 1
2 1
3 1
0 2 5
0 0 0

Output

4 4 6 16
1 1 1 1
10

### Response

```cpp
// Undone
#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N, W, D;
  while (cin>>N>>W>>D, N+W+D) {
    vector<pair<int, int>> v;
    v.push_back(make_pair(W, D));
    for (int i = 0; i < N; i++) {
      int p, s;
      cin>>p>>s;
      p--;
      int w = v[p].first, d = v[p].second;
      while (s > w*2+d*2) s -= w*2+d*2;
      pair<int,int> p1, p2;
      if (s < w) {
        p1 = make_pair(s, d);
        p2 = make_pair(w-s, d);
      } else if (s < w + d) {
        s -= w;
        p1 = make_pair(w, s);
        p2 = make_pair(w, d-s);
      } else if (s < 2*w+d) {
        s -= w+d;
        p1 = make_pair(s, d);
        p2 = make_pair(w-s, d);
      } else if (s < 2*w+2*d) {
        s -= 2*w+d;
        p1 = make_pair(w, s);
        p2 = make_pair(w, d-s);
      }
      v.erase(v.begin() + p);
      if (p1.first*p1.second > p2.first*p2.second) swap(p1, p2);
      v.push_back(p1);
      v.push_back(p2);
    }

    vector<int> ans(v.size());
    for (int i = 0; i < v.size(); i++) {
      ans[i] = v[i].first*v[i].second;
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < v.size(); i++) {
      if (i) cout<<" ";
      cout << ans[i];
    }
    cout << endl;
  }
}

```


### Prompt

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

Let’s play a stone removing game.

Initially, n stones are arranged on a circle and numbered 1, ... , n clockwise (Figure 1). You are also given two numbers k and m. From this state, remove stones one by one following the rules explained below, until only one remains. In step 1, remove stone m. In step 2, locate the k-th next stone clockwise from m and remove it. In subsequent steps, start from the slot of the stone removed in the last step, make k hops clockwise on the remaining stones and remove the one you reach. In other words, skip (k - 1) remaining stones clockwise and remove the next one. Repeat this until only one stone is left and answer its number.

For example, the answer for the case n = 8, k = 5, m = 3 is 1, as shown in Figure 1.

<image>

Figure 1: An example game

Initial state: Eight stones are arranged on a circle.

Step 1: Stone 3 is removed since m = 3.

Step 2: You start from the slot that was occupied by stone 3. You skip four stones 4, 5, 6 and 7 (since k = 5), and remove the next one, which is 8.

Step 3: You skip stones 1, 2, 4 and 5, and thus remove 6. Note that you only count stones that are still on the circle and ignore those already removed. Stone 3 is ignored in this case.

Steps 4-7: You continue until only one stone is left. Notice that in later steps when only a few stones remain, the same stone may be skipped multiple times. For example, stones 1 and 4 are skipped twice in step 7.

Final State: Finally, only one stone, 1, is on the circle. This is the final state, so the answer is 1.

Input

The input consists of multiple datasets each of which is formatted as follows.

n k m

The last dataset is followed by a line containing three zeros. Numbers in a line are separated by a single space. A dataset satisfies the following conditions.

2 ≤ n ≤ 10000, 1 ≤ k ≤ 10000, 1 ≤ m ≤ n

The number of datasets is less than 100.

Output

For each dataset, output a line containing the stone number left in the final state. No extra characters such as spaces should appear in the output.

Example

Input

8 5 3
100 9999 98
10000 10000 10000
0 0 0

Output

1
93
2019

### Response

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

int main()
{
  int n,k,m;
  while(cin >> n >> k >> m, (n || k || m))
    {
      vector<int> stone;
      for(int i=1;i<=n;i++)
	stone.push_back(i);

      m--;
      for(;stone.size() > 1;)
	stone.erase(stone.begin()+m),m = (m+k-1)%stone.size();
      cout << stone[0] << endl;
    }
  return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here, it is abbreviated as JOI.

JOI is conducting research to confine many microorganisms in one petri dish alive. There are N microorganisms to be investigated, and they are numbered 1, 2, ..., N. When each microorganism is trapped in a petri dish, it instantly releases a harmful substance called foo (fatally odd object) into the petri dish. The amount of foo released by each microorganism is known. The foo released by all the microorganisms trapped in the petri dish is evenly ingested by each microorganism in the petri dish. The foo tolerance of each microorganism is known, and if foo is ingested in excess of this amount, the microorganism will die.

The foo release amount of the microorganism i is ai milligrams, and the foo tolerance is bi milligrams. That is, when the microorganisms i1, i2, ..., ik are trapped in the petri dish, each microorganism in the petri dish ingests (ai1 + ai2 + ... + aik) / k milligrams of foo, and the microorganisms in the petri dish ingest. i will die if this intake is greater than bi.

On behalf of JOI, you must keep as many microorganisms alive in the petri dish as possible. However, no microbes in the petri dish should die from ingestion of foo, as carcasses of microorganisms adversely affect the environment in the petri dish.

It is still a mystery how JOI profits from making "just a strange invention", and no one in JOI knows except the president.

input

Read the following input from standard input.

* The integer N is written on the first line, which indicates that there are N microorganisms to be investigated.
* The following N lines contain information on each microorganism. On the first line of i + (1 ≤ i ≤ N), the positive integers ai and bi are written separated by blanks, and the foo emission amount of the microorganism i is ai milligrams and the foo tolerance is bi milligrams. Represent.

output

Output the maximum number of microorganisms that can be confined in one petri dish to the standard output in one line.

Example

Input

6
12 8
5 9
2 4
10 12
6 7
13 9

Output

3

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

typedef pair<int,int> P;

int bit[100001][2] = {},n;

int sum(int i,int num){
	int s = 0;
	while(i > 0){
		s += bit[i][num];
		i -= i & -i;
	}
	return s;
}

void add(int i,int x,int num){
	while(i <= 100000){
		bit[i][num] += x;
		i += i & -i;
	}
}

bool C(int x,int ok){
	return sum(x,0) * ok >= sum(x,1);
}

signed main(){
	int ma = 0;
	vector<P> bug;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		bug.push_back(P(b,a));
	}
	sort(bug.begin(),bug.end(),greater<P>());
	for(int i = 0;i < n;i++){
		int ok = bug[i].first,foo = bug[i].second,low = 0,up = 100001;
		add(foo,1,0);
		add(foo,foo,1);
		while(up - low > 1){
			int mid = (up + low) / 2;
			if(C(mid,ok)) low = mid;
			else up = mid;
		}
		int s = sum(low,0);
		if(low < 100000 && sum(low + 1,0) - sum(low,0) >= 2){
			int ss = sum(low,1);
			int j = 1;
			for(;j <= sum(low + 1,0) - sum(low,0);j++){
				if(ss + (low + 1) * j > ok * (sum(low,0) + j)) break;
			}
			s += j - 1;
		}
		ma = max(ma,s);
	}
	cout << ma << endl;
	return 0;
}
```


### Prompt

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

Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:

There are two arrays of integers a and b of length n. It turned out that array a contains only elements from the set \{-1, 0, 1\}.

Anton can perform the following sequence of operations any number of times:

  1. Choose any pair of indexes (i, j) such that 1 ≤ i < j ≤ n. It is possible to choose the same pair (i, j) more than once.
  2. Add a_i to a_j. In other words, j-th element of the array becomes equal to a_i + a_j.

For example, if you are given array [1, -1, 0], you can transform it only to [1, -1, -1], [1, 0, 0] and [1, -1, 1] by one operation.

Anton wants to predict if it is possible to apply some number (zero or more) of these operations to the array a so that it becomes equal to array b. Can you help him?

Input

Each test contains multiple test cases.

The first line contains the number of test cases t (1 ≤ t ≤ 10000). The description of the test cases follows.

The first line of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the length of arrays.

The second line of each test case contains n integers a_1, a_2, ..., a_n (-1 ≤ a_i ≤ 1) — elements of array a. There can be duplicates among elements.

The third line of each test case contains n integers b_1, b_2, ..., b_n (-10^9 ≤ b_i ≤ 10^9) — elements of array b. There can be duplicates among elements.

It is guaranteed that the sum of n over all test cases doesn't exceed 10^5.

Output

For each test case, output one line containing "YES" if it's possible to make arrays a and b equal by performing the described operations, or "NO" if it's impossible.

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

Example

Input

5
3
1 -1 0
1 1 -2
3
0 1 1
0 2 2
2
1 0
1 41
2
-1 0
-1 -41
5
0 1 -1 1 -1
1 1 -1 1 -1

Output

YES
NO
YES
YES
NO

Note

In the first test-case we can choose (i, j)=(2, 3) twice and after that choose (i, j)=(1, 2) twice too. These operations will transform [1, -1, 0] → [1, -1, -2] → [1, 1, -2]

In the second test case we can't make equal numbers on the second position.

In the third test case we can choose (i, j)=(1, 2) 41 times. The same about the fourth test case.

In the last lest case, it is impossible to make array a equal to the array b.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    int flag = 0;
    if (a[0] != b[0])
      flag++;
    else {
      int cn1 = 0, c1 = 0;
      for (int i = 0; i < n; i++) {
        if (a[i] < b[i] && c1 == 0)
          flag++;
        else if (a[i] > b[i] && cn1 == 0)
          flag++;
        else {
        }
        if (a[i] == 1) c1++;
        if (a[i] == -1) cn1++;
      }
    }
    if (flag == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.

Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.

She has ordered a very big round pizza, in order to serve her many friends. Exactly n of Shiro's friends are here. That's why she has to divide the pizza into n + 1 slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.

Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.

As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?

Input

A single line contains one non-negative integer n (0 ≤ n ≤ 10^{18}) — the number of Shiro's friends. The circular pizza has to be sliced into n + 1 pieces.

Output

A single integer — the number of straight cuts Shiro needs.

Examples

Input

3

Output

2

Input

4

Output

5

Note

To cut the round pizza into quarters one has to make two cuts through the center with angle 90^{\circ} between them.

To cut the round pizza into five equal parts one has to make five cuts.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  if (n == 0) {
    cout << "0" << endl;
  } else {
    if ((n + 1) % 2 == 0) {
      cout << (n + 1) / 2 << endl;
    } else {
      cout << n + 1 << endl;
    }
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Do you know a story about the three musketeers? Anyway, you will learn about its origins now.

Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.

There are n warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.

Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.

Input

The first line contains two space-separated integers, n and m (3 ≤ n ≤ 4000, 0 ≤ m ≤ 4000) — respectively number of warriors and number of pairs of warriors knowing each other.

i-th of the following m lines contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Warriors ai and bi know each other. Each pair of warriors will be listed at most once.

Output

If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).

Examples

Input

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

Output

2

Input

7 4
2 1
3 6
5 1
1 7

Output

-1

Note

In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.

The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.

In the second sample there is no triple of warriors knowing each other.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) res = (res % 1000000007 * a % 1000000007) % 1000000007;
    b = b >> 1;
    a = (a * a) % 1000000007;
  }
  return res;
}
bool Visit[5000][5000];
long long Degree[5000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, k, n, m;
  cin >> n >> m;
  long long res = 10000000000000;
  for (i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    Visit[a][b] = true;
    Visit[b][a] = true;
    Degree[a]++;
    Degree[b]++;
  }
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++) {
      if (Visit[i][j]) {
        for (k = j + 1; k <= n; k++) {
          if (Visit[i][k] && Visit[j][k])
            res = min(res, Degree[i] + Degree[j] + Degree[k]);
        }
      }
    }
  }
  if (res == 10000000000000)
    cout << "-1";
  else
    cout << res - 6;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

This is an interactive problem.

In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.

The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.

To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).

Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.

After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.

Can you find the station with the train using no more than 4500 applications of the gadgets?

Input

The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.

Interaction

You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.

Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:

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

Hacks

In order to hack, you should present a test in the following format.

The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.

Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.

For example, the following lines are the first lines of the sample test.

    10 2 5
    5
    3
    5
    7
    7
    ...

Example

Input

10 2

Yes

No

Yes

Yes

Output

3 5

3 3

3 4

5 5

Note

In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k, mv;
string query(long long l, long long r) {
  assert(mv < 4400);
  ++mv;
  string res;
  cout << l << ' ' << r << '\n';
  fflush(stdout);
  cin >> res;
  return res;
}
void f(long long l, long long r) {
  if ((r - l + 1) < 100) {
    long long x = (rand() % (r - l + 1)) + l;
    if (query(x, x) == "Yes") exit(0);
    f(max(1ll, l - k), min(n, r + k));
  }
  long long mid = l + r >> 1;
  if (query(l, mid) == "Yes")
    f(max(1ll, l - k), min(n, mid + k));
  else
    f(max(1ll, mid - k), min(n, r + k));
}
signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  srand(time(NULL));
  f(1, n);
  return 0;
}

```


### Prompt

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

Natasha's favourite numbers are n and 1, and Sasha's favourite numbers are m and -1. One day Natasha and Sasha met and wrote down every possible array of length n+m such that some n of its elements are equal to 1 and another m elements are equal to -1. For each such array they counted its maximal prefix sum, probably an empty one which is equal to 0 (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as f(a) the maximal prefix sum of an array a_{1, … ,l} of length l ≥ 0. Then:

$$$f(a) = max (0, \smash{\displaystylemax_{1 ≤ i ≤ l}} ∑_{j=1}^{i} a_j )$$$

Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo 998\: 244\: 853.

Input

The only line contains two integers n and m (0 ≤ n,m ≤ 2 000).

Output

Output the answer to the problem modulo 998\: 244\: 853.

Examples

Input

0 2

Output

0

Input

2 0

Output

2

Input

2 2

Output

5

Input

2000 2000

Output

674532367

Note

In the first example the only possible array is [-1,-1], its maximal prefix sum is equal to 0.

In the second example the only possible array is [1,1], its maximal prefix sum is equal to 2.

There are 6 possible arrays in the third example:

[1,1,-1,-1], f([1,1,-1,-1]) = 2

[1,-1,1,-1], f([1,-1,1,-1]) = 1

[1,-1,-1,1], f([1,-1,-1,1]) = 1

[-1,1,1,-1], f([-1,1,1,-1]) = 1

[-1,1,-1,1], f([-1,1,-1,1]) = 0

[-1,-1,1,1], f([-1,-1,1,1]) = 0

So the answer for the third example is 2+1+1+1+0+0 = 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244853;
int n, m;
long long dp[2005][2005], k[2005][2005], C[4005][4005];
void init() {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0)
        k[i][j] = 1;
      else if (j == 0)
        k[i][j] = 0;
      else if (i > j)
        k[i][j] = 0;
      else
        k[i][j] = (k[i - 1][j] + k[i][j - 1]) % mod;
    }
  }
  C[0][0] = C[1][0] = C[1][1] = 1;
  for (int i = 2; i <= n + m; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
  }
}
int main() {
  cin >> n >> m;
  init();
  for (int i = 0; i <= n; i++) dp[i][0] = i, dp[0][i] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      dp[i][j] =
          ((dp[i - 1][j] + C[i + j - 1][i - 1]) % mod +
           (dp[i][j - 1] - C[i + j - 1][j - 1] + k[i][j - 1] + mod) % mod) %
          mod;
  cout << dp[n][m] << endl;
  return 0;
}

```


### Prompt

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

Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.

If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift.

Now Petya wants to know for each friend i the number of a friend who has given him a gift.

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.

Output

Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i.

Examples

Input

4
2 3 4 1

Output

4 1 2 3

Input

3
1 3 2

Output

1 3 2

Input

2
1 2

Output

1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int p[n];
  int s[n];
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == p[j]) {
        s[i] = j;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << s[i] << " ";
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

This is the hard version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.

You are given an array [a_1, a_2, ..., a_n].

Your goal is to find the length of the longest subarray of this array such that the most frequent value in it is not unique. In other words, you are looking for a subarray such that if the most frequent value occurs f times in this subarray, then at least 2 different values should occur exactly f times.

An array c is a subarray of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input

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

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

Output

You should output exactly one integer — the length of the longest subarray of the array whose most frequent value is not unique. If there is no such subarray, output 0.

Examples

Input

7
1 1 2 2 3 3 3

Output

6

Input

10
1 1 1 5 4 1 3 1 2 2

Output

7

Input

1
1

Output

0

Note

In the first sample, the subarray [1, 1, 2, 2, 3, 3] is good, but [1, 1, 2, 2, 3, 3, 3] isn't: in the latter there are 3 occurrences of number 3, and no other element appears 3 times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int e = 5e5 + 100;
int n, m, a[e], ton1[e], cnt[e], cnx[e], b[e], s[e], mm[e * 2];
int main() {
  cin >> n;
  int maxn = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    ton1[a[i]]++;
    maxn = ((maxn) > (ton1[a[i]]) ? (maxn) : (ton1[a[i]]));
  }
  int pd = 0;
  for (int i = 1; i <= n; i++) {
    if (pd != 0 and ton1[i] == maxn) {
      cout << n;
      return 0;
    }
    if (ton1[i] == maxn) {
      pd = i;
    }
  }
  int k = sqrt(n), ans = 0;
  for (int i = 1, lim = ((k) < (ton1[pd]) ? (k) : (ton1[pd])); i <= lim; i++) {
    int l = 0, r = 0, mxcn = 0;
    memset(cnx, 0, sizeof(cnx));
    memset(cnt, 0, sizeof(cnt));
    cnx[0] = n;
    while (r <= n) {
      for (; cnt[pd] <= i and r <= n;) {
        if (cnx[mxcn] > 1) ans = ((ans) > (r - l) ? (ans) : (r - l));
        r++;
        cnx[cnt[a[r]]]--;
        cnt[a[r]]++;
        mxcn = ((mxcn) > (cnt[a[r]]) ? (mxcn) : (cnt[a[r]]));
        cnx[cnt[a[r]]]++;
      }
      for (; cnt[pd] > i and l <= r;) {
        ++l;
        cnx[cnt[a[l]]]--;
        if (cnt[a[l]] == mxcn and cnx[cnt[a[l]]] == 0) mxcn--;
        cnt[a[l]]--;
        cnx[cnt[a[l]]]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == pd) continue;
    if (ton1[i] > k) {
      memset(mm, 0x3f, sizeof(mm));
      mm[e] = 0;
      for (int j = 1; j <= n; j++) {
        if (a[j] == i) {
          b[j] = -1;
        } else if (a[j] == pd) {
          b[j] = 1;
        } else
          b[j] = 0;
        s[j] = s[j - 1] + b[j];
        mm[s[j] + e] = ((mm[s[j] + e]) < (j) ? (mm[s[j] + e]) : (j));
        ans = ((ans) > (j - mm[s[j] + e]) ? (ans) : (j - mm[s[j] + e]));
      }
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

A tree is an undirected graph with exactly one simple path between each pair of vertices. We call a set of simple paths k-valid if each vertex of the tree belongs to no more than one of these paths (including endpoints) and each path consists of exactly k vertices.

You are given a tree with n vertices. For each k from 1 to n inclusive find what is the maximum possible size of a k-valid set of simple paths.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vertices in the tree.

Then following n - 1 lines describe the tree, each of them contains two integers v, u (1 ≤ v, u ≤ n) — endpoints of the corresponding edge.

It is guaranteed, that the given graph is a tree.

Output

Output n numbers, the i-th of which is the maximum possible number of paths in an i-valid set of paths.

Examples

Input

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

Output

7
3
2
1
1
1
1

Input

6
1 2
2 3
2 4
1 5
5 6

Output

6
2
2
1
1
0

Note

One way to achieve the optimal number of paths for the second sample is illustrated in the following picture:

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
int a, b, c, d, e, f, p = 1000000007, base = 157, mi = 1e9, id = 0, q, pos;
int ind[300000], ans[300000], si[300000], si2[300000];
pair<int, int> reb_price[300000];
string s, s2;
vector<int> vec[300000];
vector<pair<int, int>> rebra[300000];
vector<int> order;
void dfs() {
  for (auto v : order) {
    int ma = 0, ma2 = 0;
    si[v] = 1;
    for (auto i : rebra[v]) {
      if (i.second == 0) {
        continue;
      }
      b += (si[i.first] + i.second - 1) / id;
      si[i.first] = (si[i.first] + i.second - 1) % id;
      if (si[i.first] > ma) {
        ma2 = ma;
        ma = si[i.first];
      } else if (si[i.first] > ma2) {
        ma2 = si[i.first];
      }
    }
    si[v] = ma + 1;
    if (si[v] + ma2 >= id) {
      si[v] = 0;
      b++;
    }
  }
}
pair<int, int> dfs2(int v, int pred, int pred2) {
  if (rebra[v].size() == 1 && v != 1) {
    rebra[v][0] = {pred2, 0};
    order.push_back(v);
    return {v, 1};
  }
  if (rebra[v].size() == 2 && v != 1) {
    if (rebra[v][0].first == pred) {
      auto pa = dfs2(rebra[v][1].first, v, pred2);
      return {pa.first, pa.second + 1};
    } else {
      auto pa = dfs2(rebra[v][0].first, v, pred2);
      return {pa.first, pa.second + 1};
    }
  }
  int j = 0;
  for (auto i : rebra[v]) {
    if (i.first == pred) {
      rebra[v][j] = {pred2, 0};
      j++;
      continue;
    }
    rebra[v][j] = dfs2(i.first, v, v);
    j++;
  }
  order.push_back(v);
  return {v, 1};
}
int readint() {
  int n = 0;
  char c;
  do {
    c = fgetc(stdin);
  } while (!(c == '-' || '0' <= c && c <= '9'));
  int sign = 1;
  if (c == '-') {
    sign = -1;
    c = fgetc(stdin);
  }
  do {
    n = n * 10 + (c - '0');
    c = fgetc(stdin);
  } while ('0' <= c && c <= '9');
  return n * sign;
}
signed main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
  a = readint();
  for (int i = 0; i < a - 1; i++) {
    b = readint();
    c = readint();
    rebra[b].push_back({c, 1});
    rebra[c].push_back({b, 1});
  }
  dfs2(1, -1, -1);
  for (int i = 0; i < a; i = i) {
    if (i == 0 || i < 2000) {
      b = 0;
      id = i + 1;
      dfs();
      cout << b << '\n';
      ;
      i++;
    } else {
      b = 0;
      id = i + 1;
      dfs();
      c = b;
      int l = i + 1, r = a / max(b, 1) + 1;
      b = 0;
      while (r - l > 1) {
        int res = (r + l) / 2;
        b = 0;
        id = res;
        dfs();
        if (b == c) {
          l = res;
        } else {
          r = res;
        }
      }
      for (int j = i; j < l; j++) {
        cout << c << '\n';
        ;
      }
      i = l;
    }
  }
  cin >> a;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document.

In the Pindows operating system a strings are the lexemes of the command line — the first of them is understood as the name of the program to run and the following lexemes are its arguments. For example, as we execute the command " run.exe one, two . ", we give four lexemes to the Pindows command line: "run.exe", "one,", "two", ".". More formally, if we run a command that can be represented as string s (that has no quotes), then the command line lexemes are maximal by inclusion substrings of string s that contain no spaces.

To send a string with spaces or an empty string as a command line lexeme, we can use double quotes. The block of characters that should be considered as one lexeme goes inside the quotes. Embedded quotes are prohibited — that is, for each occurrence of character """ we should be able to say clearly that the quotes are opening or closing. For example, as we run the command ""run.exe o" "" " ne, " two . " " ", we give six lexemes to the Pindows command line: "run.exe o", "" (an empty string), " ne, ", "two", ".", " " (a single space).

It is guaranteed that each lexeme of the command line is either surrounded by spaces on both sides or touches the corresponding command border. One of its consequences is: the opening brackets are either the first character of the string or there is a space to the left of them.

You have a string that consists of uppercase and lowercase English letters, digits, characters ".,?!"" and spaces. It is guaranteed that this string is a correct OS Pindows command line string. Print all lexemes of this command line string. Consider the character """ to be used only in order to denote a single block of characters into one command line lexeme. In particular, the consequence is that the given string has got an even number of such characters.

Input

The single line contains a non-empty string s. String s consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space.

It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaranteed that the given command line string contains at least one lexeme.

Output

In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "<" (less) character to the left of your lexemes and the ">" (more) character to the right. Print the lexemes in the order in which they occur in the command.

Please, follow the given output format strictly. For more clarifications on the output format see the test samples.

Examples

Input

"RUn.exe O" "" "   2ne, " two! . " "

Output

<RUn.exe O>
<>
<   2ne, >
<two!>
<.>
< >

Input

   firstarg   second   ""

Output

<firstarg>
<second>
<>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  getline(cin, s);
  int n = s.size(), i = 0;
  while (s[i] != '\0') {
    while (s[i] == ' ') {
      i++;
    }
    if (s[i] == '"') {
      i++;
      cout << "<";
      while (s[i] != '"' && s[i] != '\0') {
        cout << s[i];
        i++;
      }
      i++;
      cout << ">\n";
    } else if (s[i] != '\0') {
      cout << "<";
      while (s[i] != ' ' && s[i] != '\0') {
        cout << s[i];
        i++;
      }
      cout << ">\n";
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

for i = 1 to A.length-1
key = A[i]
/* insert A[i] into the sorted sequence A[0,...,j-1] */
j = i - 1
while j >= 0 and A[j] > key
A[j+1] = A[j]
j--
A[j+1] = key

Note that, indices for array elements are based on 0-origin.

To illustrate the algorithms, your program should trace intermediate result for each step.

Hint

Template in C

Constraints

1 ≤ N ≤ 100

Input

The first line of the input includes an integer N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by a single space.

Output

The output consists of N lines. Please output the intermediate sequence in a line for each step. Elements of the sequence should be separated by single space.

Examples

Input

6
5 2 4 6 1 3

Output

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

Input

3
1 2 3

Output

1 2 3
1 2 3
1 2 3

### Response

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

void outlist(int A[],int n){
	for(int i=0;i<n;i++){
		if (i>0){
			cout<<" ";
		}
    	cout<<A[i];
	}
  	cout<<endl;
}

int main(){
	int n;
	int A[1000];
	cin>>n;
	for(int i=0;i<n;i++){
			cin>>A[i];
	}
	outlist(A,n);
	for(int j=1;j<n;j++){
		int v=A[j];
		int k=j-1;
		while(k>=0&&A[k]>v){
			A[k+1]=A[k];
			k--;
		}
		A[k+1]=v;
		outlist(A,n);
	}
	return 0;

}

```


### Prompt

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

Berland annual chess tournament is coming!

Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.

Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins.

Every chess player has its rating ri. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.

After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.

Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?

Input

The first line contains one integer n (1 ≤ n ≤ 100).

The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000).

Output

If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".

Examples

Input

2
1 3 2 4

Output

YES

Input

1
3 3

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int c[MAXN];
int v[1005];
int main() {
  int no;
  scanf("%d", &no);
  no <<= 1;
  for (int i = 0; i < no; ++i) {
    scanf("%d", &c[i]);
  }
  sort(c, c + no);
  int stp = no >> 1;
  for (int i = 0; i < stp; ++i) {
    v[c[i]] = 1;
  }
  int ok = 1;
  for (int i = stp; i < no; ++i) {
    if (v[c[i]]) {
      ok = 0;
      break;
    }
  }
  puts(ok ? "YES" : "NO");
  return 0;
}

```


### Prompt

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

A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.

In the festival m fireworks will be launched. The i-th (1 ≤ i ≤ m) launching is on time ti at section ai. If you are at section x (1 ≤ x ≤ n) at the time of i-th launching, you'll gain happiness value bi - |ai - x| (note that the happiness value might be a negative value).

You can move up to d length units in a unit time interval, but it's prohibited to go out of the main street. Also you can be in an arbitrary section at initial time moment (time equals to 1), and want to maximize the sum of happiness that can be gained from watching fireworks. Find the maximum total happiness.

Note that two or more fireworks can be launched at the same time.

Input

The first line contains three integers n, m, d (1 ≤ n ≤ 150000; 1 ≤ m ≤ 300; 1 ≤ d ≤ n).

Each of the next m lines contains integers ai, bi, ti (1 ≤ ai ≤ n; 1 ≤ bi ≤ 109; 1 ≤ ti ≤ 109). The i-th line contains description of the i-th launching.

It is guaranteed that the condition ti ≤ ti + 1 (1 ≤ i < m) will be satisfied.

Output

Print a single integer — the maximum sum of happiness that you can gain from watching all the fireworks.

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

Examples

Input

50 3 1
49 1 1
26 1 4
6 1 10

Output

-31

Input

10 2 1
1 1000 4
9 1000 4

Output

1992

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, d;
long long dp[150005][5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> d;
  long long pt;
  long long prev, curr;
  for (long long i = 0; i < m; i++) {
    long long a, b, t;
    cin >> a >> b >> t;
    if (i == 0) {
      prev = 0;
      curr = 1;
      for (long long j = 1; j <= n; j++) dp[j][i] = b - abs(a - j);
      pt = t;
    } else {
      for (long long j = 1; j <= n; j++) dp[j][curr] = b - abs(a - j);
      long long s = (t - pt) * d;
      pt = t;
      deque<long long> mq;
      for (long long j = 1; j <= s + 1 && j <= n; j++) {
        while (!mq.empty() && dp[mq.back()][prev] < dp[j][prev]) mq.pop_back();
        mq.push_back(j);
      }
      for (long long j = 1; j <= n; j++) {
        while (!mq.empty() && mq.front() < j - s) mq.pop_front();
        dp[j][curr] += dp[mq.front()][prev];
        if (j + s + 1 <= n) {
          while (!mq.empty() && j + s + 1 <= n &&
                 dp[mq.back()][prev] < dp[j + 1 + s][prev])
            mq.pop_back();
          mq.push_back(j + s + 1);
        }
      }
      swap(prev, curr);
    }
  }
  long long sol = dp[1][prev];
  for (int i = 2; i <= n; i++)
    if (sol < dp[i][prev]) sol = dp[i][prev];
  cout << sol << endl;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n.

He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace 'a' with 'b' or replace 'b' with 'a'). Nikolay can use no letters except 'a' and 'b'.

The prefix of string s of length l (1 ≤ l ≤ n) is a string s[1..l].

For example, for the string s="abba" there are two prefixes of the even length. The first is s[1...2]="ab" and the second s[1...4]="abba". Both of them have the same number of 'a' and 'b'.

Your task is to calculate the minimum number of operations Nikolay has to perform with the string s to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.

Input

The first line of the input contains one even integer n (2 ≤ n ≤ 2⋅10^{5}) — the length of string s.

The second line of the input contains the string s of length n, which consists only of lowercase Latin letters 'a' and 'b'.

Output

In the first line print the minimum number of operations Nikolay has to perform with the string s to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.

In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, you can print any of them.

Examples

Input

4
bbbb

Output

2
abba

Input

6
ababab

Output

0
ababab

Input

2
aa

Output

1
ba

Note

In the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'.

In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < n; i += 2) {
    if (s[i] == s[i + 1]) {
      cnt++;
      if (s[i] == 'a')
        s[i] = 'b';
      else
        s[i] = 'a';
    }
  }
  cout << cnt << endl << s;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.

Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.

To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.

Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.

Print the minimum cost Vladik has to pay to get to the olympiad.

Input

The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.

The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.

Output

Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

Examples

Input

4 1 4
1010

Output

1

Input

5 5 2
10110

Output

0

Note

In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.

In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, n, b;
string s;
int main() {
  cin >> n >> a >> b >> s;
  if (s[a - 1] == s[b - 1])
    cout << 0;
  else
    cout << 1;
}

```


### Prompt

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

Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.

Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.

After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.

Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.

Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.

Input

The first line of the input contains an only integer n (1 ≤ n ≤ 100 000), the number of points in Pavel's records.

The second line contains 2 ⋅ n integers a_1, a_2, ..., a_{2 ⋅ n} (1 ≤ a_i ≤ 10^9), coordinates, written by Pavel in some order.

Output

Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.

Examples

Input

4
4 1 3 2 3 2 1 3

Output

1

Input

3
5 8 5 5 7 5

Output

0

Note

In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[1000005];
long long ans;
int main() {
  while (cin >> n) {
    for (int i = 0; i < 2 * n; i++) cin >> a[i];
    sort(a, a + 2 * n);
    ans = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]);
    for (int i = 1; i < n; i++) {
      ans = min(ans, ((a[2 * n - 1] - a[0]) * (a[n + i - 1] - a[i])));
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.

Let's index all the leaf nodes from the left to the right from 1 to 2h. The exit is located at some node n where 1 ≤ n ≤ 2h, the player doesn't know where the exit is so he has to guess his way out!

Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules:

  * Character 'L' means "go to the left child of the current node";
  * Character 'R' means "go to the right child of the current node";
  * If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node;
  * If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command;
  * If he reached a leaf node that is not the exit, he returns to the parent of the current node;
  * If he reaches an exit, the game is finished.

Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?

Input

Input consists of two integers h, n (1 ≤ h ≤ 50, 1 ≤ n ≤ 2h).

Output

Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.

Examples

Input

1 2

Output

2

Input

2 3

Output

5

Input

3 6

Output

10

Input

10 1024

Output

2046

Note

A perfect binary tree of height h is a binary tree consisting of h + 1 levels. Level 0 consists of a single node called root, level h consists of 2h nodes called leaves. Each node that is not a leaf has exactly two children, left and right one.

Following picture illustrates the sample test number 3. Nodes are labeled according to the order of visit.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
static double m1[400400];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long h, n, cu = 0, pw, lr = 0, res = 0;
  cin >> h >> n;
  --n;
  pw = 1ll << (h);
  for (int i = 0; i < h; ++i) {
    pw /= 2;
    res += (2 * pw - 1) * (lr == (cu + pw > n)) + 1;
    if (cu + pw <= n) {
      lr = 0;
      cu += pw;
    } else {
      lr = 1;
    }
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Drazil is playing a math game with Varda.

Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.

First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:

1. x doesn't contain neither digit 0 nor digit 1.

2. <image> = <image>.

Help friends find such number.

Input

The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.

The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.

Output

Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.

Examples

Input

4
1234

Output

33222

Input

3
555

Output

555

Note

In the first case, <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1E18;
const long double EPS = 1E-10;
const int N = 1e5 + 1;
const long long MOD = 1E9 + 7;
int n;
vector<char> v;
int main() {
  cin >> n;
  char a;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a == '4') {
      v.push_back('3');
      v.push_back('2');
      v.push_back('2');
    } else if (a == '6') {
      v.push_back('5');
      v.push_back('3');
    } else if (a == '8') {
      v.push_back('2');
      v.push_back('2');
      v.push_back('2');
      v.push_back('7');
    } else if (a == '9') {
      v.push_back('3');
      v.push_back('3');
      v.push_back('2');
      v.push_back('7');
    } else if (a != '0' && a != '1')
      v.push_back(a);
  }
  sort(v.begin(), v.end());
  for (int i = v.size() - 1; i >= 0; i--) cout << v[i];
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.

Input

The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).

Output

If it's impossible to find the representation of n as a product of k numbers, print -1.

Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.

Examples

Input

100000 2

Output

2 50000

Input

100000 20

Output

-1

Input

1024 5

Output

2 64 2 2 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k, counter = 1, dv[50];
bool is_prime(long long x) {
  for (int i = 2; i <= sqrt(x); i += ((i == 2) ? 1 : 2)) {
    if (x % i == 0) return 0;
  }
  return 1;
}
int main() {
  cin >> n >> k;
  dv[0] = 1;
  while (!is_prime(n)) {
    for (int i = 2; i <= sqrt(n); i++) {
      if (is_prime(i) && n % i == 0) {
        n /= i;
        dv[counter++] = i;
      }
    }
  }
  dv[counter++] = n;
  int anything = 1;
  if (counter - 1 < k) {
    cout << -1;
    return 0;
  } else {
    for (int i = 1; i < counter; i++) {
      if (i >= k) anything *= dv[i];
      if (i < k)
        cout << dv[i] << " ";
      else if (i == counter - 1)
        cout << anything << " ";
    }
  }
  return 0;
}

```


### Prompt

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

Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.

Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substring of n (a substring of n is a sequence of consecutive digits of the number n).

Vasya knows that there may be more than one way to restore the number n. Your task is to find the smallest possible initial integer n. Note that decimal representation of number n contained no leading zeroes, except the case the integer n was equal to zero itself (in this case a single digit 0 was used).

Input

The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000.

The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes.

It is guaranteed that the input data is correct, and the answer always exists.

Output

Print the smalles integer n which Vasya could pass to Kate.

Examples

Input

003512
021

Output

30021

Input

199966633300
63

Output

3036366999

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string S, P;
int ns, np;
vector<char> res1, res2;
int dd[15], F[15];
bool inc;
bool check(int x) {
  for (int i = 0; i <= 9; i++) F[i] = dd[i];
  int cnt = 0;
  int m = x;
  while (x) {
    if (!F[x % 10]) return 0;
    F[x % 10]--;
    x /= 10;
    cnt++;
  }
  if (ns - cnt != m) return 0;
  return 1;
}
bool compare() {
  for (int i = 0; i <= res1.size(); i++)
    if (res1[i] < res2[i])
      return 1;
    else if (res2[i] < res1[i])
      return 0;
  return 1;
}
int main() {
  cin >> S;
  cin >> P;
  ns = S.size();
  np = P.size();
  for (int i = 0; i < ns; i++) dd[S[i] - '0']++;
  for (int i = 0; i < np; i++) dd[P[i] - '0']--;
  inc = 0;
  for (int i = 1; i < np; i++)
    if (P[i] < P[i - 1])
      break;
    else if (P[i] > P[i - 1]) {
      inc = 1;
      break;
    }
  for (int k = np; k <= ns; k++) {
    if (!check(k)) continue;
    int x = k;
    while (x) {
      dd[x % 10]--;
      x /= 10;
    }
    int pos = 0;
    for (int i = 1; i <= 9; i++)
      if (dd[i]) {
        pos = i;
        break;
      }
    if (!pos) {
      cout << P;
      for (int i = 1; i <= F[0]; i++) cout << '0';
      return 0;
    }
    if (P[0] != '0' && P[0] - '0' < pos) {
      cout << P;
      for (int i = 0; i <= 9; i++)
        for (int j = 1; j <= F[i]; j++) cout << i;
      return 0;
    }
    res1.clear();
    res1.push_back((char)pos + '0');
    F[pos]--;
    for (int i = 0; i <= 9; i++) {
      if (P[0] - '0' == i && !inc) {
        for (int j = 0; j < np; j++) res1.push_back(P[j]);
      }
      for (int j = 1; j <= F[i]; j++) res1.push_back((char)i + '0');
      if (P[0] - '0' == i && inc) {
        for (int j = 0; j < np; j++) res1.push_back(P[j]);
      }
    }
    if (P[0] - '0' > pos || P[0] == '0') {
      for (int i = 0; i < res1.size(); i++) cout << res1[i];
      return 0;
    }
    res2.clear();
    F[pos]++;
    for (int i = 0; i < np; i++) res2.push_back(P[i]);
    for (int i = 0; i <= 9; i++)
      for (int j = 1; j <= F[i]; j++) res2.push_back((char)i + '0');
    if (compare()) {
      for (int i = 0; i < res1.size(); i++) cout << res1[i];
    } else {
      for (int i = 0; i < res2.size(); i++) cout << res2[i];
    }
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.

<image>

The park consists of 2n + 1 - 1 squares connected by roads so that the scheme of the park is a full binary tree of depth n. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2n, 2n + 1, ..., 2n + 1 - 1 and these exits lead straight to the Om Nom friends' houses. From each square i (2 ≤ i < 2n + 1) there is a road to the square <image>. Thus, it is possible to go from the park entrance to each of the exits by walking along exactly n roads.

<image> To light the path roads in the evening, the park keeper installed street lights along each road. The road that leads from square i to square <image> has ai lights.

Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.

He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.

Input

The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.

The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and <image>. All numbers ai are positive integers, not exceeding 100.

Output

Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.

Examples

Input

2
1 2 3 4 5 6

Output

5

Note

Picture for the sample test. Green color denotes the additional street lights.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[(1 << 12)];
int dist[(1 << 12) >> 1];
int intervals[(1 << 12) << 1], lazy[(1 << 12) << 1];
int lst;
void relax(int p, int val) {
  intervals[p] += val;
  lazy[p] += val;
}
void update(int s, int e, int p, int us, int ue, int val, int laz) {
  relax(p, laz);
  if (us <= s && e <= ue) {
    intervals[p] += val;
    lazy[p] += val;
    return;
  }
  if (s > ue || e < us) return;
  int mid = (s + e) >> 1;
  update(s, mid, p << 1, us, ue, val, lazy[p]);
  update(mid + 1, e, (p << 1) + 1, us, ue, val, lazy[p]);
  lazy[p] = 0;
  intervals[p] = max(intervals[p << 1], intervals[(p << 1) + 1]);
}
void build(int s, int e, int p) {
  if (s == e) {
    intervals[p] = dist[s - 1];
    return;
  }
  int mid = (s + e) >> 1;
  build(s, mid, p << 1);
  build(mid + 1, e, (p << 1) + 1);
  intervals[p] = max(intervals[p << 1], intervals[(p << 1) + 1]);
}
int query(int s, int e, int p, int qs, int qe, int laz) {
  relax(p, laz);
  if (qs <= s && e <= qe) return intervals[p];
  if (s > qe || e < qs) return 0;
  int mid = (s + e) >> 1;
  int ret = max(query(s, mid, p << 1, qs, qe, lazy[p]),
                query(mid + 1, e, (p << 1) + 1, qs, qe, lazy[p]));
  lazy[p] = 0;
  return ret;
}
int rec(int src, int sum) {
  int mx = sum;
  if (adj[src].empty()) dist[lst++] = sum;
  for (int i = 0; i < adj[src].size(); i++) {
    int t = adj[src][i].first;
    int cost = adj[src][i].second;
    mx = max(mx, rec(t, sum + cost));
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int mx_e = (1 << (n + 1));
  for (int i = 2; i < mx_e; i++) {
    int x;
    cin >> x;
    adj[i / 2].push_back(make_pair((i), (x)));
  }
  int must = rec(1, 0);
  int s = 1, e = (1 << n);
  build(s, e, 1);
  int ans = 0;
  for (int i = 1 << (n - 1); i; i >>= 1) {
    for (int beg = 1; beg <= (1 << n); beg += i) {
      int mx = 0;
      mx = query(s, e, 1, beg, beg + i - 1, 0);
      int inc = must - mx;
      ans += inc;
      update(s, e, 1, beg, beg + i - 1, inc, 0);
    }
  }
  cout << ans << "\n";
  return 0;
}

```


### Prompt

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

Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.

Overall the galaxy has n planets, indexed with numbers from 1 to n. Jack is on the planet with index 1, and Apophis will land on the planet with index n. Jack can move between some pairs of planets through stargates (he can move in both directions); the transfer takes a positive, and, perhaps, for different pairs of planets unequal number of seconds. Jack begins his journey at time 0.

It can be that other travellers are arriving to the planet where Jack is currently located. In this case, Jack has to wait for exactly 1 second before he can use the stargate. That is, if at time t another traveller arrives to the planet, Jack can only pass through the stargate at time t + 1, unless there are more travellers arriving at time t + 1 to the same planet.

Knowing the information about travel times between the planets, and the times when Jack would not be able to use the stargate on particular planets, determine the minimum time in which he can get to the planet with index n.

Input

The first line contains two space-separated integers: n (2 ≤ n ≤ 105), the number of planets in the galaxy, and m (0 ≤ m ≤ 105) — the number of pairs of planets between which Jack can travel using stargates. Then m lines follow, containing three integers each: the i-th line contains numbers of planets ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which are connected through stargates, and the integer transfer time (in seconds) ci (1 ≤ ci ≤ 104) between these planets. It is guaranteed that between any pair of planets there is at most one stargate connection.

Then n lines follow: the i-th line contains an integer ki (0 ≤ ki ≤ 105) that denotes the number of moments of time when other travellers arrive to the planet with index i. Then ki distinct space-separated integers tij (0 ≤ tij < 109) follow, sorted in ascending order. An integer tij means that at time tij (in seconds) another traveller arrives to the planet i. It is guaranteed that the sum of all ki does not exceed 105.

Output

Print a single number — the least amount of time Jack needs to get from planet 1 to planet n. If Jack can't get to planet n in any amount of time, print number -1.

Examples

Input

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

Output

7

Input

3 1
1 2 3
0
1 3
0

Output

-1

Note

In the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves to planet 2, and then — to planet 4, then he spends a total of only 2 + 5 = 7 seconds.

In the second sample one can't get from planet 1 to planet 3 by moving through stargates.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n, m;
set<pair<int, int> > s;
int best[maxn];
vector<pair<int, int> > v[maxn];
vector<int> t[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int fi, se, c;
    cin >> fi >> se >> c;
    v[fi].push_back(pair<int, int>(se, c));
    v[se].push_back(pair<int, int>(fi, c));
  }
  for (int i = 1; i <= n; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int mask;
      cin >> mask;
      t[i].push_back(mask);
    }
  }
  for (int i = 1; i <= n; ++i) best[i] = 1000000000 + 1000000000;
  best[1] = 0;
  for (int i = 1; i <= n; ++i) s.insert(pair<int, int>(best[i], i));
  while (s.size()) {
    pair<int, int> Min = *s.begin();
    s.erase(s.begin());
    int ind = Min.second;
    int w = Min.first;
    for (int i = 0; i < t[ind].size(); ++i)
      if (t[ind][i] == w) {
        while (i < t[ind].size() && t[ind][i] == w) {
          w++;
          i++;
        }
        break;
      }
    for (int i = 0; i < v[ind].size(); ++i) {
      int i1 = v[ind][i].first;
      int c = v[ind][i].second;
      if (best[i1] > w + c) {
        s.erase(pair<int, int>(best[i1], i1));
        best[i1] = w + c;
        s.insert(pair<int, int>(best[i1], i1));
      }
    }
  }
  if (best[n] == 1000000000 + 1000000000)
    cout << -1 << endl;
  else
    cout << best[n] << endl;
  return 0;
}

```


### Prompt

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

A: Hokkaido University Easy

Note

Please note that the problem settings are the same as problem B, except for the constraints.

story

Homura-chan, who passed Hokkaido University and is excited about the beginning of a new life. But in front of her, a huge campus awaits ...

"Eh ... I'm not in time for the next class ..."

problem

Hokkaido University Sapporo Campus is famous for being unusually large. The Sapporo campus is represented by rectangular squares with H squares vertically and W squares horizontally. We will use (i, j) to represent the cells that are i-mass from the north and j-mass from the west. There are several buildings on campus, with a'B'if there is a building in the location represented by the square (i, j) and a'.' If not, in c_ {i, j}.

Homura, a freshman at Hokkaido University, was surprised at the size of the campus and was worried about moving between buildings. So I was wondering how far the farthest of the two squares with the building were. Here we define the distance between two pairs of squares (i, j), (i', j') as | i-i'| + | j-j'|.

Homura found this problem difficult for him and asked his classmates for help. Please ask for an answer instead of Homura-chan.

Input format

H W
c_ {11} c_ {12} ... c_ {1W}
::
c_ {H1} c_ {H2} ... c_ {HW}

Constraint

* 2 \ leq H, W \ leq 30
* H and W are integers
* c_ {i, j} is either'B'or'.'.
* At least two of c_ {i, j} are'B'.

Output format

Print the integer that represents the answer on one line.

Input example 1

3 3
B.B
..B
.BB

Output example 1

Four

* The longest is between the two points (1,1) and (3,3).

Input example 2

4 3
B ..
B ..
...
...

Output example 2

1

* Adjacent positions may be the longest.

Input example 3

6 6
... B ..
B.B.B.
.B.B.B
... B.B
.B..B.
..B ...

Output example 3

7

Example

Input

3 3
B.B
..B
.BB

Output

4

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>

using namespace std;

int main(){
  int H,W,n=0;
  int ans=0;
  cin>>H>>W;
  char c[40][40];
  int xa[30*30],ya[30*30];

  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      cin>>c[y][x];
      if(c[y][x] == 'B'){
        xa[n]=x;
        ya[n]=y;
        n++;
      }
    }
  }

  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      ans = max(ans,abs(xa[i]-xa[j])+abs(ya[i]-ya[j]));
    }
  }

  cout<<ans<<endl;

  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

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

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

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

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

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

enumerates all of the valid partitions.

Input

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

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

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

Output

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

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

Example

Input

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

Output

4
7
6
2
42
1
0
9
3

### Response

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

ll p,q,a;
int n;

inline bool same(ll num, ll den)
{
    return num*q==den*p;
}

ll dfs(ll num, ll den, int dep, ll b)
{
    if(same(num,den)) return 1;

    if(dep==n) return 0;

    // printf(" now: %lld %lld %d %lld\n", num,den,dep,b);
    ll x=q*den,y=p*den-q*num;
    // printf("x=%lld y=%lld\n", x,y);

    ll l=x/y;
    if(x%y!=0) ++l;
    l=max(l,b);
    ll r=a/den;

    ll ret=0;
    for(ll i=l; i<=r; ++i) ret+=dfs(num*i+den, i*den, dep+1, i);
    return ret;
}

int main()
{
    while(cin >>p >>q >>a >>n,p) printf("%lld\n", dfs(0,1,0,1));
    return 0;
}
```


### Prompt

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

You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

Input

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output

Output one number — length of the longest substring that can be met in the string at least twice.

Examples

Input

abcd

Output

0

Input

ababa

Output

3

Input

zzz

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int res;
set<string> st[100];
int main() {
  string s;
  cin >> s;
  for (int i = 1; i < s.size(); i++) {
    for (int j = 0; j <= s.size() - i; j++) st[i].insert(s.substr(j, i));
    if (st[i].size() < s.size() - i + 1) res = i;
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

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

This is an interactive problem. In the interaction section below you will find the information about flushing the output.

The New Year tree of height h is a perfect binary tree with vertices numbered 1 through 2h - 1 in some order. In this problem we assume that h is at least 2. The drawing below shows one example New Year tree of height 3:

<image>

Polar bears love decorating the New Year tree and Limak is no exception. To decorate the tree, he must first find its root, i.e. a vertex with exactly two neighbours (assuming that h ≥ 2). It won't be easy because Limak is a little bear and he doesn't even see the whole tree. Can you help him?

There are t testcases. In each testcase, you should first read h from the input. Then you can ask at most 16 questions of format "? x" (without quotes), where x is an integer between 1 and 2h - 1, inclusive. As a reply you will get the list of neighbours of vertex x (more details in the "Interaction" section below). For example, for a tree on the drawing above after asking "? 1" you would get a response with 3 neighbours: 4, 5 and 7. Your goal is to find the index of the root y and print it in the format "! y". You will be able to read h for a next testcase only after printing the answer in a previous testcase and flushing the output.

Each tree is fixed from the beginning and it doesn't change during your questions.

Input

The first line of the input contains a single integer t (1 ≤ t ≤ 500) — the number of testcases.

At the beginning of each testcase you should read from the input a single integer h (2 ≤ h ≤ 7) — the height of the tree. You can't read the value of h in a next testcase until you answer a previous testcase.

Interaction

To ask a question about neighbours of vertex x, print "? x" (without quotes) on a separate line. Note, you must print an end-of-line character after the last character of the line and flush your output to get a response.

The response will consist of two lines. The first line will contain a single integer k (1 ≤ k ≤ 3) — the number of neighbours of vertex x. The second line will contain k distinct integers t1, ..., tk (1 ≤ t1 < ... < tk ≤ 2h - 1) — indices of neighbours of vertex x, gives in the increasing order.

After asking at most 16 questions you have to say y — the index of the root. Print "! y" (without quotes) and an end-of-line character, and flush the output.

Each tree is fixed from the beginning and it doesn't change during your questions.

You can get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output.

To flush you can use (just printing a query/answer and end-of-line):

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

In any moment if the program reads h = 0 or k = 0 it should immediately terminate normally (for example, calling exit(0)). It means that the system detected incorrect request/output from your program and printed 0 because if can't process your requests anymore. In this case you'll receive verdict "Wrong Answer", but if you ignore case h = 0 or k = 0 it could lead to "Runtime Error", "Time/Memory limit exceeded" or any other verdict because your program could read a trash from the closed input stream.

Hacking. To hack someone, use the following format:

The first line should contain a single integer t equal to 1 (only one testcase is allowed in hacks). The second line should contain a single integer h. Each of next 2h - 2 lines should contain two distinct integers ai and bi (1 ≤ ai, bi ≤ 2h - 1), denoting two nodes connected with an edge. The printed edges must form a perfect binary tree of height h.

Of course, contestant programs will not be able to see this input.

Examples

Input

1
3
3
4 5 7
2
1 2
1
2

Output

? 1
? 5
? 6
! 5

Input

2
2
1
3
2
1 2
2
1 2
4
3
3 12 13

Output

? 1
? 3
? 3
! 3
? 6
! 1

Note

In the first sample, a tree corresponds to the drawing from the statement.

In the second sample, there are two two testcases. A tree in the first testcase has height 2 and thus 3 vertices. A tree in the second testcase has height 4 and thus 15 vertices. You can see both trees on the drawing below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int t, n, dep[200], que[200], pre[200], necc[200], ans, edge[200][5], tail,
    head, fir[200];
void build(int now) {
  scanf("%d", &edge[now][0]);
  for (int i = 1; i <= edge[now][0]; i++) {
    scanf("%d", &edge[now][i]);
    if (!necc[edge[now][i]]) {
      fir[edge[now][i]] = fir[now] + 1;
      que[++tail] = edge[now][i];
      pre[edge[now][i]] = now;
    }
  }
}
void ask(int now) {
  necc[now] = 1;
  printf("? %d\n", now);
  ans--;
  fflush(stdout);
}
void anss(int now) {
  printf("! %d\n", now);
  fflush(stdout);
}
void nclear(int x, int y) {
  necc[x] = 1;
  for (int i = 1; i <= edge[x][0]; i++)
    if (edge[x][i] != y) nclear(edge[x][i], x);
}
void check(int x) {
  int h = 0;
  for (int i = 1; i <= edge[x][0]; i++)
    if (dep[edge[x][i]]) h++;
  if (h == 2)
    for (int i = 1; i <= edge[x][0]; i++)
      if (!dep[edge[x][i]]) dep[edge[x][i]] = dep[x] - 1;
}
int dfs(int x, int y, int z) {
  if (z == 0) return 0;
  ask(x);
  build(x);
  if (edge[x][0] == 2) {
    anss(x);
    return 2;
  }
  if (edge[x][0] == 1) return 1;
  for (int i = 1; i <= edge[x][0]; i++)
    if (edge[x][i] != y) {
      return dfs(edge[x][i], x, z - 1);
    }
}
void solve() {
  memset(dep, 0, sizeof(dep));
  memset(necc, 0, sizeof(necc));
  memset(pre, 0, sizeof(pre));
  memset(fir, 0, sizeof(fir));
  memset(edge, 0, sizeof(edge));
  que[1] = 1;
  fir[1] = 1;
  tail = 1;
  head = 0;
  while (head != tail) {
    head++;
    int now = que[head];
    if (!necc[now]) {
      if (ans == 0) {
        int tmp = now;
        for (int i = head + 1; i <= tail; i++)
          if (!necc[que[i]] && fir[que[i]] < fir[tmp]) tmp = que[i];
        anss(tmp);
        return;
      } else if (n == 7 && dep[pre[pre[now]]] == 4) {
        int o = dfs(now, pre[now], 2);
        if (o == 1)
          nclear(pre[now], pre[pre[now]]);
        else if (o == 2)
          return;
      } else {
        ask(now);
        build(now);
        if (edge[now][0] == 2) {
          anss(now);
          return;
        }
        if (edge[now][0] == 1) {
          dep[now] = n;
          while (pre[now] &&
                 (!dep[pre[now]] || dep[pre[now]] == dep[now] - 1)) {
            dep[pre[now]] = dep[now] - 1;
            check(pre[now]);
            nclear(now, pre[now]);
            now = pre[now];
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    ans = 16;
    scanf("%d", &n);
    solve();
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:

  * Query number i is given as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).
  * The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum ali + ali + 1 + ... + ari = 0, otherwise the response to the query will be integer 0.

Help Eugeny, answer all his queries.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n integers a1, a2, ..., an (ai = -1, 1). Next m lines contain Eugene's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n).

Output

Print m integers — the responses to Eugene's queries in the order they occur in the input.

Examples

Input

2 3
1 -1
1 1
1 2
2 2

Output

0
1
0

Input

5 5
-1 1 1 1 -1
1 1
2 3
3 5
2 5
1 5

Output

0
1
0
1
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1111111];
int m, n;
int main() {
  cin >> n;
  cin >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int num1 = 0, num2 = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1)
      num1++;
    else
      num2++;
  }
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l;
    cin >> r;
    if ((r - l + 1) % 2 == 1)
      cout << "0" << endl;
    else if ((r - l + 1) / 2 <= num1 && (r - l + 1) / 2 <= num2)
      cout << "1" << endl;
    else
      cout << "0" << endl;
  }
  return 0;
}

```


### Prompt

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

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

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

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

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

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

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

Input

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

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

Output

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

Examples

Input

0 1 1
1 0 1
1 1 0
3

Output

7

Input

0 2 2
1 0 100
1 2 0
3

Output

19

Input

0 2 1
1 0 100
1 2 0
5

Output

87

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long t[3][3];
long long mat[41][3][3][3];
long long compute(int n, int i, int j, int k) {
  if (mat[n][i][j][k] != -1) return mat[n][i][j][k];
  if (n == 1) {
    mat[n][i][j][k] =
        ((t[i][j]) < (t[i][k] + t[k][j]) ? (t[i][j]) : (t[i][k] + t[k][j]));
    return mat[n][i][j][k];
  }
  long long a = ((compute(n - 1, i, k, j)) <
                         (compute(n - 1, i, j, k) + compute(n - 1, j, k, i))
                     ? (compute(n - 1, i, k, j))
                     : (compute(n - 1, i, j, k) + compute(n - 1, j, k, i)));
  a += t[i][j];
  a += ((compute(n - 1, k, j, i)) <
                (compute(n - 1, k, i, j) + compute(n - 1, i, j, k))
            ? (compute(n - 1, k, j, i))
            : (compute(n - 1, k, i, j) + compute(n - 1, i, j, k)));
  long long b = ((compute(n - 1, i, j, k)) <
                         (compute(n - 1, i, k, j) + compute(n - 1, k, j, i))
                     ? (compute(n - 1, i, j, k))
                     : (compute(n - 1, i, k, j) + compute(n - 1, k, j, i)));
  b += t[i][k] + t[k][j];
  b += compute(n - 1, j, i, k) +
       ((compute(n - 1, i, j, k)) <
                (compute(n - 1, i, k, j) + compute(n - 1, k, j, i))
            ? (compute(n - 1, i, j, k))
            : (compute(n - 1, i, k, j) + compute(n - 1, k, j, i)));
  mat[n][i][j][k] = ((a) < (b) ? (a) : (b));
  return mat[n][i][j][k];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  for (int i = 0; i < 41; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          mat[i][j][k][l] = -1;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> t[i][j];
    }
  }
  int n;
  cin >> n;
  cout << compute(n, 0, 2, 1) << "\n";
  return 0;
}

```


### Prompt

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

Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.

They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai.

A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.

Input

The first line contains an integer n (1 ≤ n ≤ 105) — the number of cards Conan has.

The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number on the i-th card.

Output

If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes).

Examples

Input

3
4 5 7

Output

Conan

Input

2
1 1

Output

Agasa

Note

In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.

In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[100005][2], n, counter = 0;
vector<int> v;
int dfs(int i, int turn) {
  if (i == n) {
    if ((turn + counter) % 2) return 1;
    return 0;
  }
  if (dp[i][turn] != -1) return dp[i][turn];
  return dp[i][turn] = max(dfs(i + 1, (turn + 1) % 2), dfs(i + 1, turn));
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> n;
  int x;
  map<int, int> maap;
  for (int i = 0; i < n; i++) {
    cin >> x;
    maap[x * -1]++;
  }
  for (map<int, int>::iterator it = maap.begin(); it != maap.end(); it++) {
    if (it->second % 2) {
      cout << "Conan" << endl;
      return 0;
    }
  }
  cout << "Agasa" << endl;
  return 0;
}

```