### Prompt

Generate a cpp solution to the following problem:

Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:

a_{1} ≤ a_{2},

a_{n} ≤ a_{n-1} and

a_{i} ≤ max(a_{i-1},    a_{i+1}) for all i from 2 to n-1.

Ivan does not remember the array and asks to find the number of ways to restore it. Restored elements also should be integers from 1 to 200. Since the number of ways can be big, print it modulo 998244353.

Input

First line of input contains one integer n (2 ≤ n ≤ 10^{5}) — size of the array.

Second line of input contains n integers a_{i} — elements of array. Either a_{i} = -1 or 1 ≤ a_{i} ≤ 200. a_{i} = -1 means that i-th element can't be read.

Output

Print number of ways to restore the array modulo 998244353.

Examples

Input

3
1 -1 2

Output

1

Input

2
-1 -1

Output

200

Note

In the first example, only possible value of a_{2} is 2.

In the second example, a_{1} = a_{2} so there are 200 different values because all restored elements should be integers between 1 and 200.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
bool is_prime(long long n) {
  if (n <= 1) {
    return false;
  }
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
inline long long getPow(long long a, long long b) {
  long long res = 1ll, tp = a;
  while (b) {
    if (b & 1ll) {
      res *= tp;
    }
    tp *= tp;
    b >>= 1ll;
  }
  return res;
}
long long coso(long long x1, long long y1, long long x2, long long y2,
               long long x3, long long y3) {
  return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));
}
inline long long nxt() {
  long long x;
  cin >> x;
  return x;
}
void ok() {
  puts("YES");
  exit(0);
}
void no() {
  puts("NO");
  exit(0);
}
const long long N = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n = nxt();
  vector<long long> mas(n);
  for (int i = 0; i < n; i++) {
    mas[i] = nxt();
  }
  vector<vector<long long>> dp(200 + 5, vector<long long>(2, 0LL));
  if (mas[0] == -1) {
    for (int i = 1; i <= 200; i++) {
      dp[i][1] = 1;
    }
  } else
    dp[mas[0]][1] = 1;
  for (int i = 1; i < n; i++) {
    long long cur = 0;
    vector<vector<long long>> dp2(200 + 5, vector<long long>(2, 0LL));
    for (int j = 1; j <= 200; j++) {
      dp2[j][1] = cur;
      cur = (cur + dp[j][0] + dp[j][1]);
      while (cur > 998244353) {
        cur -= 998244353;
      }
    }
    cur = 0;
    for (int j = 200; j >= 1; j--) {
      dp2[j][0] =
          ((dp2[j][0] + dp[j][0] + dp[j][1]) % 998244353 + cur) % 998244353;
      while (dp2[j][0] > 998244353) {
        dp2[j][0] -= 998244353;
      }
      cur = (cur + dp[j][0]);
      while (cur > 998244353) {
        cur -= 998244353;
      }
    }
    for (int j = 1; j <= 200; j++) {
      if (mas[i] != -1 && mas[i] != j) {
        dp2[j][0] = dp2[j][1] = 0;
      }
    }
    dp = dp2;
  }
  long long ans = 0LL;
  for (int i = 1; i <= 200; i++) {
    ans += dp[i][0];
  }
  cout << ans % 998244353;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below carefully and follow it and not the similar rules in real programming languages.

There is a very powerful system of pointers on &K* — you can add an asterisk to the right of the existing type X — that will result in new type X * . That is called pointer-definition operation. Also, there is the operation that does the opposite — to any type of X, which is a pointer, you can add an ampersand — that will result in a type &X, to which refers X. That is called a dereference operation.

The &K* language has only two basic data types — void and errtype. Also, the language has operators typedef and typeof.

  * The operator "typedef A B" defines a new data type B, which is equivalent to A. A can have asterisks and ampersands, and B cannot have them. For example, the operator typedef void** ptptvoid will create a new type ptptvoid, that can be used as void**.
  * The operator "typeof A" returns type of A, brought to void, that is, returns the type void**...*, equivalent to it with the necessary number of asterisks (the number can possibly be zero). That is, having defined the ptptvoid type, as shown above, the typeof ptptvoid operator will return void**.

An attempt of dereferencing of the void type will lead to an error: to a special data type errtype. For errtype the following equation holds true: errtype* = &errtype = errtype. An attempt to use the data type that hasn't been defined before that will also lead to the errtype.

Using typedef, we can define one type several times. Of all the definitions only the last one is valid. However, all the types that have been defined earlier using this type do not change.

Let us also note that the dereference operation has the lower priority that the pointer operation, in other words &T *  is always equal to T.

Note, that the operators are executed consecutively one by one. If we have two operators "typedef &void a" and "typedef a* b", then at first a becomes errtype, and after that b becomes errtype* = errtype, but not &void* = void (see sample 2).

Vasya does not yet fully understand this powerful technology, that's why he asked you to help him. Write a program that analyzes these operators.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of operators. Then follow n lines with operators. Each operator is of one of two types: either "typedef A B", or "typeof A". In the first case the B type differs from void and errtype types, and besides, doesn't have any asterisks and ampersands.

All the data type names are non-empty lines of no more than 20 lowercase Latin letters. The number of asterisks and ampersands separately in one type in any operator does not exceed 10, however if we bring some types to void with several asterisks, their number may exceed 10.

Output

For every typeof operator print on the single line the answer to that operator — the type that the given operator returned.

Examples

Input

5
typedef void* ptv
typeof ptv
typedef &&ptv node
typeof node
typeof &ptv

Output

void*
errtype
void

Input

17
typedef void* b
typedef b* c
typeof b
typeof c
typedef &b b
typeof b
typeof c
typedef &&b* c
typeof c
typedef &b* c
typeof c
typedef &void b
typeof b
typedef b******* c
typeof c
typedef &&b* c
typeof c

Output

void*
void**
void
void**
errtype
void
errtype
errtype
errtype

Note

Let's look at the second sample.

After the first two queries typedef the b type is equivalent to void*, and с — to void**.

The next query typedef redefines b — it is now equal to &b = &void* = void. At that, the с type doesn't change.

After that the с type is defined as &&b* = &&void* = &void = errtype. It doesn't influence the b type, that's why the next typedef defines c as &void* = void.

Then the b type is again redefined as &void = errtype.

Please note that the c type in the next query is defined exactly as errtype******* = errtype, and not &void******* = void******. The same happens in the last typedef.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d\n", &n);
  string s;
  map<string, pair<int, int>> m;
  m["void"] = make_pair(1, 0);
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    if (s.substr(0, 6) == "typeof") {
      s = s.substr(7, s.size() - 7);
      int p = 0;
      while (s[s.size() - 1] == '*') {
        p++;
        s = s.substr(0, s.size() - 1);
      }
      while (s[0] == '&') {
        p--;
        s = s.substr(1, s.size() - 1);
      }
      if (m[s].first != 0 && m[s].second + p >= 0) {
        cout << "void";
        for (int j = 0; j < m[s].second + p; j++) cout << "*";
        cout << endl;
      } else
        cout << "errtype" << endl;
    } else {
      s = s.substr(8, s.size() - 8);
      string t, g;
      t = s.substr(0, s.find(' '));
      g = s.substr(t.size() + 1, s.size() - t.size() - 1);
      s = t;
      int p = 0;
      while (s[s.size() - 1] == '*') {
        p++;
        s = s.substr(0, s.size() - 1);
      }
      while (s[0] == '&') {
        p--;
        s = s.substr(1, s.size() - 1);
      }
      pair<int, int> h = m[s];
      if (h.first != 0 && p + h.second >= 0)
        m[g] = make_pair(1, p + h.second);
      else
        m[g] = make_pair(0, 0);
    }
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled:

  * 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer;
  * all numbers b1 - a1, b2 - a2, ..., bk - ak are distinct.

For the given number n find the number of beautiful sequences of length k. As the answer can be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Input

The first line contains integer t (1 ≤ t ≤ 2·105) — the number of the test data.

Each of the next t lines contains two integers n and k (1 ≤ k ≤ n ≤ 1000).

Output

For each test from the input print the answer to the problem modulo 1000000007 (109 + 7). Print the answers to the tests in the order in which the tests are given in the input.

Examples

Input

6
1 1
2 1
2 2
3 1
3 2
3 3

Output

1
3
0
6
2
0

Note

In the first test sample there is exactly one beautiful sequence: (1, 1).

In the second test sample, the following sequences are beautiful:

  * (1, 1);
  * (1, 2);
  * (2, 2).

In the fourth test sample, the following sequences are beautiful:

  * (1, 1);
  * (1, 2);
  * (1, 3);
  * (2, 2);
  * (2, 3);
  * (3, 3).

In the fifth test sample, the following sequences are beautiful:

  * (1, 1), (2, 3);
  * (1, 2), (3, 3).

In the third and sixth samples, there are no beautiful sequences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long s[1005][1005];
long long fact[1005];
long long invfact[1005];
long long choose[1005][1005];
long long s1(int x, int y) {
  if (y < 0) return 0;
  return s[x][y];
}
long long sum(int k, int n) {
  long long sum1 = 0;
  for (int i = 0; i <= n; ++i) {
    sum1 = (sum1 + choose[n - i][k] * s1(k, i));
    if (sum1 > 5E17) sum1 %= 1000000007;
  }
  return sum1;
}
int main() {
  fact[0] = 1;
  for (int i = 1; i <= 1000; ++i) fact[i] = (i * fact[i - 1]) % 1000000007;
  invfact[0] = 1;
  for (long long i = 1; i <= 1000; ++i) {
    long long l = 1;
    while (l % i != 0) l += 1000000007;
    l /= i;
    invfact[i] = (l * invfact[i - 1]) % 1000000007;
  }
  s[0][0] = 1;
  for (int i = 1; i <= 1000; ++i) s[0][i] = 0;
  for (int i = 1; i <= 1000; ++i) {
    for (int j = 0; j <= 1000; ++j) {
      s[i][j] = (i * s1(i - 1, j - i + 1) + s1(i, j - i)) % 1000000007;
    }
  }
  for (int i = 0; i <= 1000; ++i)
    for (int j = 0; j <= 1000; ++j) {
      if (i < j) {
        choose[i][j] = 0;
        continue;
      }
      choose[i][j] =
          ((fact[i] * invfact[i - j]) % 1000000007 * invfact[j]) % 1000000007;
    }
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int k, n;
    cin >> n >> k;
    printf("%d\n", sum(k, n) % 1000000007);
  }
}

```


### Prompt

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

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

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

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

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

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

<image>

Input

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

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

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

The horizontal line data is given as follows.

> h p q

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

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

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

Output

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

Sample Input

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

Output for the Sample Input

Four

Example

Input

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

Output

4

### Response

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

int main(){
		int n,m,a;
		while(cin >> n >> m >> a and !(n==0 && m==0 && a==0)){
				vector<vector<int> > ami(1005);

				for(int i=0;i<m;i++){
						int h,p,q;
						cin >> h >> p >> q;
						h--, p--, q--;
						ami[h].push_back(p);
				}
				int point = a-1;
				for(int i=1004;i>=0;i--){
						for(int j=0;j<ami[i].size();j++){
								if(point==ami[i][j]){
										point = point + 1;
								}else if(point-1==ami[i][j]){
										point = point - 1;
								}
						}
				}
				cout << point+1 << endl;
		}
}

```


### Prompt

Create a solution in Cpp for the following problem:

Given are two strings S and T.

Let us change some of the characters in S so that T will be a substring of S.

At least how many characters do we need to change?

Here, a substring is a consecutive subsequence. For example, `xxx` is a substring of `yxxxy`, but not a substring of `xxyxx`.

Constraints

* The lengths of S and T are each at least 1 and at most 1000.
* The length of T is at most that of S.
* S and T consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the minimum number of characters in S that need to be changed.

Examples

Input

cabacc
abc

Output

1

Input

codeforces
atcoder

Output

6

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int ans=1e9;
	for(int i=0;i<s.size()-t.size()+1;i++){
		int cnt=0;
		for(int j=0;j<t.size();j++)
			if(s[i+j]!=t[j])
				cnt++;
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability (p_i)/(100) for all 1 ≤ i ≤ n.

Some mirrors are called checkpoints. Initially, only the 1st mirror is a checkpoint. It remains a checkpoint all the time.

Creatnx asks the mirrors one by one, starting from the 1-st mirror. Every day, if he asks i-th mirror, there are two possibilities:

  * The i-th mirror tells Creatnx that he is beautiful. In this case, if i = n Creatnx will stop and become happy, otherwise he will continue asking the i+1-th mirror next day;
  * In the other case, Creatnx will feel upset. The next day, Creatnx will start asking from the checkpoint with a maximal number that is less or equal to i.

There are some changes occur over time: some mirrors become new checkpoints and some mirrors are no longer checkpoints. You are given q queries, each query is represented by an integer u: If the u-th mirror isn't a checkpoint then we set it as a checkpoint. Otherwise, the u-th mirror is no longer a checkpoint.

After each query, you need to calculate [the expected number](https://en.wikipedia.org/wiki/Expected_value) of days until Creatnx becomes happy.

Each of this numbers should be found by modulo 998244353. Formally, let M = 998244353. It can be shown that the answer can be expressed as an irreducible fraction p/q, where p and q are integers and q not ≡ 0 \pmod{M}. Output the integer equal to p ⋅ q^{-1} mod M. In other words, output such an integer x that 0 ≤ x < M and x ⋅ q ≡ p \pmod{M}.

Input

The first line contains two integers n, q (2 ≤ n, q ≤ 2 ⋅ 10^5) — the number of mirrors and queries.

The second line contains n integers: p_1, p_2, …, p_n (1 ≤ p_i ≤ 100).

Each of q following lines contains a single integer u (2 ≤ u ≤ n) — next query.

Output

Print q numbers – the answers after each query by modulo 998244353.

Examples

Input

2 2
50 50
2
2

Output

4
6

Input

5 5
10 20 30 40 50
2
3
4
5
3

Output

117
665496274
332748143
831870317
499122211

Note

In the first test after the first query, the first and the second mirrors are checkpoints. Creatnx will ask the first mirror until it will say that he is beautiful, after that he will ask the second mirror until it will say that he is beautiful because the second mirror is a checkpoint. After that, he will become happy. Probabilities that the mirrors will say, that he is beautiful are equal to 1/2. So, the expected number of days, until one mirror will say, that he is beautiful is equal to 2 and the answer will be equal to 4 = 2 + 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long fpow(long long base, long long exp) {
  long long result = 1;
  while (exp) {
    if (exp & 1) result = (result * base) % MOD;
    exp >>= 1;
    base = (base * base) % MOD;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    long long x;
    cin >> x;
    long long val = 100ll * fpow(x, MOD - 2) % MOD;
    ans = (ans + val + (val - 1 + MOD) * ans) % MOD;
  }
  cout << ans << "\n";
}

```


### Prompt

Create a solution in Cpp for the following problem:

Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.

The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

Input

The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Output

Print one integer — the number of times Kolya will have to empty the waste section.

Examples

Input

2 7 10
5 6

Output

1

Input

1 5 10
7

Output

0

Input

3 10 10
5 7 7

Output

1

Input

1 1 1
1

Output

0

Note

In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.

In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

### Response

```cpp
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
int n, b, d;
int a[100000];
void solve() {
  long long sum = 0;
  long long count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > b) continue;
    sum += a[i];
    if (sum > d) {
      count++;
      sum = 0;
    }
  }
  cout << count;
}
int main() {
  scanf("%d%d%d", &n, &b, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  solve();
  printf("\n");
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I.

* insert  $k$: Insert a node containing $k$ as key into $T$.
* find $k$: Report whether $T$ has a node containing $k$.
* print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively.

Constraints

* The number of operations $\leq 500,000$
* The number of print operations $\leq 10$.
* $-2,000,000,000 \leq key \leq 2,000,000,000$
* The height of the binary tree does not exceed 100 if you employ the above pseudo code.
* The keys in the binary search tree are all different.

Input

In the first line, the number of operations $m$ is given. In the following $m$ lines, operations represented by insert $k$, find $k$ or print are given.

Output

For each find $k$ operation, print "yes" if $T$ has a node containing $k$, "no" if not.

In addition, for each print operation, print a list of keys obtained by inorder tree walk and preorder tree walk in a line respectively. Put a space character before each key.

Example

Input

10
insert 30
insert 88
insert 12
insert 1
insert 20
find 12
insert 17
insert 25
find 16
print

Output

yes
no
 1 12 17 20 25 30 88
 30 12 1 20 17 25 88

### Response

```cpp
#include<cstdio>
#define N 500005
struct mzls
{
	int key;
	mzls *ch[2];
};
mzls tree[N];
bool f1=1;
mzls *root,*NIL,*ncnt;
inline void Init()
{
	NIL=&tree[0];
	NIL->ch[0]=NIL->ch[1]=NIL;
	ncnt=&tree[1];
	root=NIL;
}
inline mzls *newnode(int ml)
{
	mzls *p=++ncnt;
	p->key=ml;
	p->ch[0]=p->ch[1]=NIL;
	return p;
}
inline void Insert(mzls *&rt,int ml)
{
	if(rt==NIL)
	{
		rt=newnode(ml);
		return;
	}
	int d=(ml>=rt->key);
	Insert(rt->ch[d],ml);
}
inline void InOrder(mzls *rt)
{
	if(rt==NIL)
		return;
	InOrder(rt->ch[0]);
	printf(" %d",rt->key);
	InOrder(rt->ch[1]);
}
inline void Preorder(mzls *rt)
{
	if(rt==NIL)
		return;
	printf(" %d",rt->key);
	Preorder(rt->ch[0]);
	Preorder(rt->ch[1]);
}
inline mzls *Find(mzls *rt, int ml)
{
	if(rt==NIL) return NIL;
	if(rt->key==ml) return rt;
	int d=(ml>=rt->key);
	return Find(rt->ch[d],ml);
}
int main()
{
	int n,x;
	char op[100];
	Init();
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s",op);
		if(op[0]=='i')
		{
			scanf("%d",&x);
			Insert(root,x);
		}
		else if(op[0]=='f')
		{
			scanf("%d", &x);
			mzls *p=Find(root, x);
			if(p==NIL)
				puts("no");
			else
				puts("yes");
		}
		else
		{
			InOrder(root);
			puts("");
			Preorder(root);
			puts("");
		}
	}
	return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on n are less than in the hard version of the problem.

You are given an array a of n integers (there are no equals elements in the array). You can perform the following operations on array elements:

  1. choose any index i (1 ≤ i ≤ n) and move the element a[i] to the begin of the array;
  2. choose any index i (1 ≤ i ≤ n) and move the element a[i] to the end of the array.

For example, if n = 5, a = [4, 7, 2, 3, 9], then the following sequence of operations can be performed:

  * after performing the operation of the first type to the second element, the array a will become [7, 4, 2, 3, 9];
  * after performing the operation of the second type to the second element, the array a will become [7, 2, 3, 9, 4].

You can perform operations of any type any number of times in any order.

Find the minimum total number of operations of the first and second type that will make the a array sorted in non-decreasing order. In other words, what is the minimum number of operations that must be performed so the array satisfies the inequalities a[1] ≤ a[2] ≤ … ≤ a[n].

Input

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

Each test case starts with a line containing an integer n (1 ≤ n ≤ 3000) — length of the array a.

Then follow n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — an array that needs to be sorted by the given operations. All numbers in the given array are distinct.

The sum of n for all test cases in one test does not exceed 3000.

Output

For each test case output one integer — the minimum total number of operations of the first and second type, which will make the array sorted in non-decreasing order.

Example

Input

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

Output

2
2
0
2

Note

In the first test case, you first need to move 3, and then 2 to the beginning of the array. Therefore, the desired sequence of operations: [4, 7, 2, 3, 9] → [3, 4, 7, 2, 9] → [2, 3, 4, 7, 9].

In the second test case, you need to move the 1 to the beginning of the array, and the 8 — to the end. Therefore, the desired sequence of operations: [3, 5, 8, 1, 7] → [1, 3, 5, 8, 7] → [1, 3, 5, 7, 8].

In the third test case, the array is already sorted.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  int x, f = 1;
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') f = -1;
  x = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - 48;
  return x * f;
}
const int N = 200005;
pair<int, int> a[N];
set<int> s;
int sta[N], top;
int main() {
  int i, j, n, m, T, ans;
  T = read();
  while (T--) {
    s.clear();
    n = read();
    ans = 0;
    for (i = 1; i <= n; i++) a[i] = {read(), -i};
    sort(a + 1, a + i);
    j = 1;
    top = 0;
    for (i = 1; i <= n; i++) {
      if (a[i].first != a[i - top].first) {
        while (top) s.insert(sta[top--]);
        top = 0;
      }
      while (s.size() && *s.begin() < a[i].second) {
        s.erase(a[j].second);
        j++;
      }
      sta[++top] = a[i].second;
      ans = max(ans, top + int(s.size()));
    }
    printf("%d\n", n - ans);
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Rabbits and cats are competing. The rules are as follows.

First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number as the card is written on their paper. The winning condition is that the number of "a set of n numbers with a mark and is in a straight line" is equal to or greater than the number of playing cards drawn at the beginning.

Answer which of the rabbit and the cat wins up to the mth card given. However, the victory or defeat is when only one of the two cards meets the victory condition when a certain card is drawn and marked. In other cases, it is a draw. Cards may be drawn even after one of them meets the victory conditions, but this does not affect the victory or defeat.

Input

Line 1: “nuvm” (square size, number of rabbit playing cards, number of cat playing cards, number of cards drawn) 2- (N + 1) Line: n2 numbers that the rabbit writes on paper ( N + 2)-(2N + 1) Line: n2 numbers that the cat writes on paper (2N + 2)-(2N + M + 1) Line: m cards drawn
1 ≤ n ≤ 500
1 ≤ u, v ≤ 13
1 ≤ m ≤ 100 000
1 ≤ (number written) ≤ 1 000 000

The number of n2 rabbits write on paper, the number of n2 cats write on paper, and the number of m cards drawn are different.

Output

Output "USAGI" if the rabbit wins, "NEKO" if the cat wins, and "DRAW" if the tie, each in one line.

Examples

Input

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

Output

USAGI

Input

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

Output

DRAW

### Response

```cpp
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

int n, u, v, m;
vector<vector<int>> usa, neko;
vector<int> card;

void paint(vector<vector<int>>& tile, int lim) {
	set<int> cand;
	REP(i, lim) cand.insert(card[i]);
	REP(i, n)REP(j, n) {
		int num = tile[i][j];
		if (cand.find(num) == cand.end()) {
			tile[i][j] = 0;
		}
	}
}

int judge(vector<vector<int>> tile, int lim) {
	paint(tile, lim);

	int res = 0;
	// ud
	REP(i, n) {
		REP(j, n)if (tile[i][j] == 0)goto end;
		res++;
	end:;
	}
	// lr
	REP(j, n) {
		REP(i, n)if (tile[i][j] == 0)goto end2;
		res++;
	end2:;
	}
	// slash
	REP(i, n) if (tile[i][i] == 0)goto end3;
	res++;
end3:;
	REP(i, n)if (tile[i][n - 1 - i] == 0)goto end4;
	res++;
end4:;
	return res;
}

void single() {
	int uidx = find(card.begin(), card.end(), usa[0][0]) - card.begin();
	int nidx = find(card.begin(), card.end(), neko[0][0]) - card.begin();

	if (u == 1 && v == 1) {
		if (uidx == nidx)cout << "DRAW" << endl;
		else cout << (uidx < nidx ? "USAGI" : "NEKO") << endl;
	}
	else if (u == 1) {
		cout << (uidx < m ? "USAGI" : "DRAW") << endl;
	}
	else if (v == 1) {
		cout << (uidx < m ? "NEKO" : "DRAW") << endl;
	}
	else {
		cout << "DRAW" << endl;
	}

}

int main()
{
	cin >> n >> u >> v >> m;
	usa.resize(n, vector<int>(n));
	neko.resize(n, vector<int>(n));
	card.resize(m);
	REP(i, n) REP(j, n)cin >> usa[i][j];
	REP(i, n) REP(j, n)cin >> neko[i][j];
	REP(i, m)cin >> card[i];
	if (n == 1) {
		single();
		return 0;
	}
	int l = 0, r = m;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		bool res1 = judge(usa, mid) >= u;
		bool res2 = judge(neko, mid) >= v;
		if (res1 && res2)r = mid;
		else if (!res1 && !res2) l = mid;
		else {
			cout << (res1 ? "USAGI" : "NEKO") << endl;
			return 0;
		}
	}

	bool res1 = judge(usa, r) >= u;
	bool res2 = judge(neko, r) >= v;
	if (res1 == res2)cout << "DRAW" << endl;
	else cout << (res1 ? "USAGI" : "NEKO") << endl;
	return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the N days you would like to again own zero shares, but want to have as much money as possible.

Input

Input begins with an integer N (2 ≤ N ≤ 3·105), the number of days.

Following this is a line with exactly N integers p1, p2, ..., pN (1 ≤ pi ≤ 106). The price of one share of stock on the i-th day is given by pi.

Output

Print the maximum amount of money you can end up with at the end of N days.

Examples

Input

9
10 5 4 7 9 12 6 2 10

Output

20

Input

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

Output

41

Note

In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is  - 5 - 4 + 9 + 12 - 2 + 10 = 20.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
multiset<int> mst;
int main() {
  int n;
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int v;
    scanf("%d", &v);
    if (mst.empty() || *mst.begin() > v) {
      mst.insert(v);
    } else if (*mst.begin() <= v) {
      ans += 1ll * (v - *mst.begin());
      mst.erase(mst.begin());
      mst.insert(v);
      mst.insert(v);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

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

By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:

You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type:

  1. For given numbers xi and vi assign value vi to element axi.
  2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2.
  3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri).

Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type:

  * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105);
  * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n);
  * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105).

The input limits for scoring 30 points are (subproblem E1):

  * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type.

The input limits for scoring 70 points are (subproblems E1+E2):

  * It is guaranteed that there will be queries of the 1-st and 2-nd type only.

The input limits for scoring 100 points are (subproblems E1+E2+E3):

  * No extra limitations.

Output

For each query print the calculated sum modulo 1000000000 (109).

Examples

Input

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

Output

12
32
8
50

Input

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

Output

12
45

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 2e5 + 7, mod = 1e9;
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], f[df],
    sum[df], tag[df];
struct node {
  long long sum1, sum2, siz;
} ma[df << 2];
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
void pushdown(long long num, long long le, long long rig) {
  if (!tag[num]) return;
  ma[num].sum1 = ma[num].sum2 = 0;
  tag[(num << 1)] += tag[num] % mod, tag[(num << 1)] %= mod,
      tag[(num << 1 | 1)] += tag[num] % mod, tag[(num << 1 | 1)] %= mod;
  if (ma[(num << 1)].siz)
    ma[(num << 1)].sum1 =
        (ma[(num << 1)].sum1 + tag[num] * sum[ma[(num << 1)].siz - 1] % mod) %
        mod,
               ma[(num << 1)].sum2 =
                   (ma[(num << 1)].sum2 +
                    tag[num] * (sum[ma[(num << 1)].siz] - sum[0]) % mod) %
                   mod;
  if (ma[(num << 1 | 1)].siz)
    ma[(num << 1 | 1)].sum1 =
        (ma[(num << 1 | 1)].sum1 +
         tag[num] * sum[ma[(num << 1 | 1)].siz - 1] % mod) %
        mod,
                   ma[(num << 1 | 1)].sum2 =
                       (ma[(num << 1 | 1)].sum2 +
                        tag[num] * (sum[ma[(num << 1 | 1)].siz] - sum[0]) %
                            mod) %
                       mod;
  tag[num] = 0;
}
node operator+(node st, node ch) {
  node tr;
  tr.sum1 = (st.sum1 + f[st.siz - 1] * ch.sum2 % mod +
             (st.siz >= 2) * f[st.siz - 2] * ch.sum1 % mod) %
            mod;
  tr.sum2 =
      (st.sum2 + f[st.siz] * ch.sum2 % mod + f[st.siz - 1] * ch.sum1 % mod) %
      mod;
  tr.siz = st.siz + ch.siz;
  return tr;
}
void build(long long num, long long le, long long rig) {
  if (le == rig) {
    ma[num].sum1 = a[le] * f[0] % mod, ma[num].sum2 = a[le] * f[1] % mod,
    ma[num].siz = 1;
    return;
  }
  build((num << 1), le, ((le + rig) >> 1)),
      build((num << 1 | 1), ((le + rig) >> 1) + 1, rig),
      ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
  return;
}
void cov(long long num, long long le, long long rig, long long p, long long x) {
  if (le > p || rig < p) return;
  if (le == p && rig == p) {
    ma[num].sum1 = x * f[0] % mod, ma[num].sum2 = x * f[1] % mod,
    ma[num].siz = 1;
    return;
  }
  pushdown(num, le, rig), cov((num << 1), le, ((le + rig) >> 1), p, x),
      cov((num << 1 | 1), ((le + rig) >> 1) + 1, rig, p, x),
      ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
}
void upd(long long num, long long le, long long rig, long long l, long long r,
         long long x) {
  if (le > r || rig < l) return;
  if (le >= l && rig <= r)
    ma[num].sum1 = (ma[num].sum1 + x * sum[ma[num].siz - 1] % mod) % mod,
    ma[num].sum2 = (ma[num].sum2 + x * (sum[ma[num].siz] - sum[0]) % mod) % mod,
    tag[num] += x % mod, tag[num] %= mod;
  else
    pushdown(num, le, rig), upd((num << 1), le, ((le + rig) >> 1), l, r, x),
        upd((num << 1 | 1), ((le + rig) >> 1) + 1, rig, l, r, x),
        ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
}
node qry(long long num, long long le, long long rig, long long l, long long r) {
  if (le >= l && rig <= r)
    return ma[num];
  else {
    pushdown(num, le, rig);
    node ty;
    if (((le + rig) >> 1) >= l && r >= ((le + rig) >> 1) + 1)
      ty = qry((num << 1), le, ((le + rig) >> 1), l, r) +
           qry((num << 1 | 1), ((le + rig) >> 1) + 1, rig, l, r);
    else if (((le + rig) >> 1) >= l)
      ty = qry((num << 1), le, ((le + rig) >> 1), l, r);
    else if (r >= ((le + rig) >> 1) + 1)
      ty = qry((num << 1 | 1), ((le + rig) >> 1) + 1, rig, l, r);
    ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
    return ty;
  }
}
int main() {
  n = read(), m = read();
  f[0] = 1, sum[0] = 1;
  f[1] = 1, sum[1] = 2;
  for (long long i = (2); i <= (n * 2); ++i)
    f[i] = (f[i - 1] + f[i - 2]) % mod, sum[i] = (sum[i - 1] + f[i]) % mod;
  for (long long i = (1); i <= (n); ++i) a[i] = read() % mod;
  build(1, 1, n);
  for (long long i = (1); i <= (m); ++i) {
    long long op = read(), x = read(), y = read();
    if (op == 1) cov(1, 1, n, x, y);
    if (op == 2) printf("%lld\n", qry(1, 1, n, x, y).sum1 % mod);
    if (op == 3) {
      long long d = read();
      upd(1, 1, n, x, y, d % mod);
    }
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

This is an interactive problem.

The judge has a hidden rooted full binary tree with n leaves. A full binary tree is one where every node has either 0 or 2 children. The nodes with 0 children are called the leaves of the tree. Since this is a full binary tree, there are exactly 2n - 1 nodes in the tree. The leaves of the judge's tree has labels from 1 to n. You would like to reconstruct a tree that is isomorphic to the judge's tree. To do this, you can ask some questions.

A question consists of printing the label of three distinct leaves a1, a2, a3. Let the depth of a node be the shortest distance from the node to the root of the tree. Let LCA(a, b) denote the node with maximum depth that is a common ancestor of the nodes a and b.

Consider X = LCA(a1, a2), Y = LCA(a2, a3), Z = LCA(a3, a1). The judge will tell you which one of X, Y, Z has the maximum depth. Note, this pair is uniquely determined since the tree is a binary tree; there can't be any ties.

More specifically, if X (or Y, Z respectively) maximizes the depth, the judge will respond with the string "X" (or "Y", "Z" respectively).

You may only ask at most 10·n questions.

Input

The first line of input will contain a single integer n (3 ≤ n ≤ 1 000) — the number of leaves in the tree.

Output

To print the final answer, print out the string "-1" on its own line. Then, the next line should contain 2n - 1 integers. The i-th integer should be the parent of the i-th node, or -1, if it is the root.

Your answer will be judged correct if your output is isomorphic to the judge's tree. In particular, the labels of the leaves do not need to be labeled from 1 to n. Here, isomorphic means that there exists a permutation π such that node i is the parent of node j in the judge tree if and only node π(i) is the parent of node π(j) in your tree.

Interaction

To ask a question, print out three distinct integers a1, a2, a3. These integers should be between 1 and n, inclusive.

The judge will respond with a single character, either "X", "Y", "Z".

If the string is "X" (or "Y", "Z" respectively), that means the pair (a1, a2) (or (a2, a3), (a3, a1) respectively) has the deepest LCA among the three pairs.

You may only ask a question at most 10·n times, otherwise, you will get Wrong Answer.

When you are ready to answer, print out a single integer "-1" on its own line. The next line should contain 2n - 1 integers. The i-th integer should be the parent of the i-th node, or -1, if it is the root. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question.

You will get Wrong Answer verdict if

  * Your question or answers are not in the format described in this statement.
  * You ask strictly more than 10·n questions.
  * Your question contains duplicate indices.
  * Your final answer is not isomorphic to the judge tree.

You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below).

To flush you can use (just after printing an integer 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.

If at any moment your program reads -1 as an answer, it should immediately exit normally (for example, by calling exit(0)). You will get Wrong Answer in this case, it means that you made more queries than allowed, or made an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Hacking To hack someone, use the following format

    n
    p_1 p_2 ... p_{2n-1}

This denotes a tree where the parent of the i-th node is pi (pi = - 1 or n < pi ≤ 2n - 1). If pi is equal to -1, then node i is the root. This input must describe a valid full rooted binary tree.

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

Example

Input

5
X
Z
Y
Y
X

Output

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

Note

For the first sample, the judge has the hidden tree:

<image>

Here is a more readable format of the interaction:

<image> The last line can also be 8 6 9 8 9 7 -1 6 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef struct Querytype {
  int a, b, c;
  bool operator==(const Querytype &other) const {
    return a == other.a && b == other.b && c == other.c;
  }
} Query;
namespace std {
template <>
struct hash<Query> {
  std::size_t operator()(const Query &k) const {
    return (k.a * 1001 + k.b) * 1001 + k.c;
  }
};
}  // namespace std
int n, nn;
vector<int> edges[2 * 1001];
unordered_map<Query, char> q;
inline bool lsize(int x) { return x <= n; }
inline bool lnode(int x) { return x > n; }
struct CENT {
  typedef bool (*SZ_COUNTER)(int);
  typedef bool (*ND_COUNTER)(int);
  int *cmax, *csize, n;
  vector<int> nodes;
  bool *rem;
  SZ_COUNTER cntr;
  ND_COUNTER nntr;
  vector<pair<int, vector<int>>> cents;
  vector<map<int, int>> cents_orig;
  CENT(int n, SZ_COUNTER cntr, ND_COUNTER nntr) : n(n), cntr(cntr), nntr(nntr) {
    cmax = (int *)malloc((this->n + 1) * sizeof(int));
    csize = (int *)malloc((this->n + 1) * sizeof(int));
    rem = (bool *)malloc((this->n + 1) * sizeof(bool));
    memset(rem, false, (this->n + 1) * sizeof(bool));
  }
  ~CENT() {
    free(cmax);
    free(csize);
    free(rem);
  }
  void dfs(int x, int p) {
    nodes.push_back(x);
    csize[x] = cntr(x) ? 1 : 0;
    cmax[x] = 0;
    for (auto i : edges[x])
      if (i != -1 && i != p && !rem[i]) {
        dfs(i, x);
        csize[x] += csize[i];
        if (csize[i] > cmax[x]) cmax[x] = csize[i];
      }
  }
  void decompose() {
    cents.clear();
    vector<int> ztl;
    map<int, int> zml;
    cents.push_back(make_pair(0, ztl));
    cents_orig.push_back(zml);
    queue<pair<int, int>> q;
    q.push(make_pair(1, 0));
    while (!q.empty()) {
      auto t = q.front();
      q.pop();
      nodes.clear();
      dfs(t.first, -1);
      int ct = -1;
      for (auto i : nodes)
        if (csize[i] * 2 >= csize[t.first] && cmax[i] * 2 <= csize[t.first] &&
            nntr(i)) {
          ct = i;
          break;
        }
      if (ct == -1) ct = t.first;
      vector<int> ctl;
      cents.push_back(make_pair(ct, ctl));
      cents_orig.push_back(zml);
      int cti = cents.size() - 1, ki = 0;
      cents[t.second].second.push_back(cti);
      for (auto i : edges[ct])
        if (i != -1 && !rem[i]) {
          q.push(make_pair(i, cti));
          cents_orig[cti][i] = ki++;
        }
      rem[ct] = true;
    }
  }
};
int get_leaf(int x) {
  if (edges[x].size() <= 1)
    return x;
  else
    return get_leaf(edges[x][1]);
}
char query(int a, int b, int c) {
  bool bab = false;
  if (a > b) {
    swap(b, a);
    bab = true;
  }
  Query qq = {.a = a, .b = b, .c = c};
  if (q.find(qq) == q.end()) {
    cout << a << " " << b << " " << c << endl;
    cin >> q[qq];
  }
  return !bab || q[qq] == 'X' ? q[qq] : (q[qq] == 'Y' ? 'Z' : 'Y');
}
inline int vfind(const vector<int> &x, int v) {
  return find(x.begin(), x.end(), v) - x.begin();
}
void run(int x) {
  CENT cent(2 * n - 1, &lsize, &lnode);
  cent.decompose();
  int i = 1;
  while (true) {
    auto ct = cent.cents[i].first;
    auto cm = cent.cents_orig[i];
    const auto &cp = cent.cents[i].second;
    char q = query(get_leaf(edges[ct][1]), get_leaf(edges[ct][2]), x);
    if (q == 'X') {
      if (cm.find(edges[ct][0]) == cm.end()) {
        if (edges[ct][0] != -1) {
          int idx = vfind(edges[edges[ct][0]], ct);
          edges[edges[ct][0]][idx] = nn;
          edges[nn].push_back(edges[ct][0]);
        } else
          edges[nn].push_back(-1);
        edges[ct][0] = nn;
        edges[x].push_back(nn);
        edges[nn].push_back(ct);
        edges[nn].push_back(x);
        nn++;
        break;
      } else
        i = cp[cm[edges[ct][0]]];
    } else {
      int k = q == 'Y' ? 2 : 1;
      if (cm.find(edges[ct][k]) == cm.end() || !lnode(edges[ct][k])) {
        int ke = edges[ct][k];
        edges[ke][0] = nn;
        edges[ct][k] = nn;
        edges[x].push_back(nn);
        edges[nn].push_back(ct);
        edges[nn].push_back(ke);
        edges[nn].push_back(x);
        nn++;
        break;
      } else
        i = cp[cm[edges[ct][k]]];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  edges[1].push_back(n + 1);
  edges[2].push_back(n + 1);
  edges[n + 1].push_back(-1);
  edges[n + 1].push_back(1);
  edges[n + 1].push_back(2);
  nn = n + 2;
  for (int i = 3; i <= n; i++) run(i);
  cout << -1 << endl;
  for (int i = 1; i < 2 * n - 1; i++) cout << edges[i][0] << " ";
  cout << edges[2 * n - 1][0] << endl;
  return 0;
}

```


### Prompt

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

Mister B has a house in the middle of a giant plain field, which attracted aliens life. For convenience, aliens specified the Cartesian coordinate system on the field in such a way that Mister B's house has coordinates (0, 0). After that they sent three beacons to the field, but something went wrong. One beacon was completely destroyed, while the other two landed in positions with coordinates (m, 0) and (0, n), respectively, but shut down.

Mister B was interested in this devices, so he decided to take them home. He came to the first beacon, placed at (m, 0), lifted it up and carried the beacon home choosing the shortest path. After that he came to the other beacon, placed at (0, n), and also carried it home choosing the shortest path. When first beacon was lifted up, the navigation system of the beacons was activated.

Partially destroyed navigation system started to work in following way.

At time moments when both survived beacons are at points with integer coordinates the system tries to find a location for the third beacon. It succeeds if and only if there is a point with integer coordinates such that the area of the triangle formed by the two survived beacons and this point is equal to s. In this case the system sends a packet of information with beacon positions to aliens, otherwise it doesn't.

Compute how many packets of information system sent while Mister B was moving the beacons.

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. The next 3·t lines describe t test cases.

Every test case is described in three lines as follows. Note that each parameter is given as a product of three factors.

The first line of a test case contains three space-separated integers: n1, n2, n3 (1 ≤ ni ≤ 106) such that n = n1·n2·n3.

The second line contains three space-separated integers: m1, m2, m3 (1 ≤ mi ≤ 106) such that m = m1·m2·m3.

The third line contains three space-separated integers: s1, s2, s3 (1 ≤ si ≤ 106) such that s = s1·s2·s3.

Note that for hacks only tests with t = 1 allowed.

Output

Print t integers one per line — the answers for each test.

Example

Input

3
2 1 1
2 1 1
1 1 3
1 5 1
2 2 1
1 1 2
10 6 18
2 103 2
13 1 13

Output

4
7
171

Note

First test case contains the following beacon positions: (2, 0) and (0, 2), s = 3. The following packets could be sent: ((2, 0), (0, 2), ( - 1, 0)), ((1, 0), (0, 2), (4, 0)), ((0, 0), (0, 2), (3, 1)), ((0, 0), (0, 1), ( - 6, 0)), where (b1, b2, p) has next description: b1 — first beacon position, b2 — second beacon position, p — some generated point.

Second test case contains the following beacon initial positions: (4, 0) and (0, 5), s = 2. The following packets could be sent: ((4, 0), (0, 5), (0, 4)), ((3, 0), (0, 5), (2, 3)), ((2, 0), (0, 5), (2, 2)), ((1, 0), (0, 5), (1, 4)), ((0, 0), (0, 4), (0, - 1)), ((0, 0), (0, 2), (2, 0)), ((0, 0), (0, 1), (4, 0)).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
vector<string> s_p_l_i_t(const string &s, char c) {
  vector<string> v;
  int d = 0, f = 0;
  string t;
  for (char c : s) {
    if (!d && c == ',')
      v.push_back(t), t = "";
    else
      t += c;
    if (c == '\"' || c == '\'') f ^= 1;
    if (!f && c == '(') ++d;
    if (!f && c == ')') --d;
  }
  v.push_back(t);
  return move(v);
}
void e_r_r(vector<string>::iterator it) {}
template <typename T, typename... Args>
void e_r_r(vector<string>::iterator it, T a, Args... args) {
  if (*it == " 1" || *it == "1")
    cerr << endl;
  else
    cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  e_r_r(++it, args...);
}
const long long MOD = 1e9 + 7;
const int MAX_P = 1123456;
int prime[MAX_P];
void Fact(int n, map<long long, long long> &re) {
  while (prime[n]) {
    ++re[prime[n]];
    n /= prime[n];
  }
  if (n > 1) ++re[n];
}
void pre() {
  int i, j, k;
  for (i = 2; i < MAX_P; i++) {
    if (prime[i] == 0)
      for (long long j = 1ll * i * i; j < MAX_P; j += i) prime[j] = i;
  }
}
map<pair<pair<long long, long long>, long long>, long long> memo;
long long dfs(vector<pair<long long, long long>> &ps, int i, long long x) {
  if (ps.size() == i) return x >= 0;
  long long re = dfs(ps, i + 1, x);
  for (int(_) = 0; (_) < (ps[i].second); ++(_)) {
    x /= ps[i].first;
    if (!x) break;
    re += dfs(ps, i + 1, x);
  }
  return re;
}
long long dfs2(vector<pair<long long, long long>> &ps, int i, long long x) {
  if (ps.size() == i) {
    if (!x) return 0;
    long long re = 0;
    int n = ps.size();
    for (int(i) = 0; (i) < (1 << n); ++(i)) {
      long long t = x;
      for (int(j) = 0; (j) < (n); ++(j))
        if (i >> j & 1) t /= ps[j].first;
      re += (__builtin_popcount(i) % 2 ? -t : t);
    }
    return re;
  }
  long long re = dfs2(ps, i + 1, x);
  for (int(_) = 0; (_) < (ps[i].second); ++(_)) {
    x /= ps[i].first;
    if (!x) break;
    re += dfs2(ps, i + 1, x);
  }
  return re;
}
int main() {
  pre();
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  int T;
  cin >> T;
  while (T--) {
    map<long long, long long> xs, ys, ss;
    long long first = 1, second = 1, S = 1;
    for (int(i) = 0; (i) < (3); ++(i)) {
      long long t;
      cin >> t;
      first *= t;
      Fact(t, xs);
    }
    for (int(i) = 0; (i) < (3); ++(i)) {
      long long t;
      cin >> t;
      second *= t;
      Fact(t, ys);
    }
    for (int(i) = 0; (i) < (3); ++(i)) {
      long long t;
      cin >> t;
      S *= t;
      Fact(t, ss);
    }
    S *= 2;
    ++ss[2];
    if (memo.count(make_pair(pair<long long, long long>(first, second), S))) {
      cout << memo[make_pair(pair<long long, long long>(first, second), S)]
           << endl;
    }
    long long &re =
        memo[make_pair(pair<long long, long long>(first, second), S)];
    vector<pair<long long, long long>> ps((ss).begin(), (ss).end());
    reverse((ps).begin(), (ps).end());
    re += dfs(ps, 0, first);
    map<long long, long long> ts;
    for (pair<long long, long long> p : xs) {
      if (ss[p.first] < p.second) ts[p.first] = ss[p.first];
    }
    vector<pair<long long, long long>> tv((ts).begin(), (ts).end());
    re += dfs2(tv, 0, second);
    cout << re << endl;
  }
  return 0;
}

```


### Prompt

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

I’m planning to have a party on my birthday. Many of my friends will come to the party. Some of them will come with one or more pieces of cakes, but it is not certain if the number of the cakes is a multiple of the number of people coming.

I wish to enjoy the cakes equally among the partiers. So, I decided to apply the following rules. First, all the party attendants are given the same number of cakes. If some remainder occurs, a piece goes on a priority basis to the party host (that’s me!). How many pieces of cake can I enjoy?

Given the number of my friends and cake information, make a program to calculate how many pieces of cake I can enjoy. Note that I am not counted in the number of my friends.

Input

The input is given in the following format.

$N$ $C$
$p_1$ $p_2$ ... $p_C$

The first line provides the number of my friends $N$ ($1 \leq N \leq 100$) and the number of those among them who brought one or more pieces of cake with them $C$ ($1 \leq C \leq N$). The second line provides an array of integers $p_i$ ($1 \leq p_i \leq100$), each of which shows the number of cakes of the $i$-th friend of mine who was willing to come up with one or more pieces of cake.

Output

Output the number of cakes I can enjoy.

Examples

Input

5 4
5 5 6 5

Output

4

Input

7 5
8 8 8 8 8

Output

5

Input

100 3
3 3 3

Output

1

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c,x,sum=0,m;
  cin>>n>>c;
  for(int i=1;i<=c;++i){
    cin>>x;
    sum+=x;
  }
  m=sum/(n+1);
  if(sum%(n+1))++m;
  cout<<m<<endl;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

This is the easy version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved.

There are two binary strings a and b of length n (a binary string is a string consisting of symbols 0 and 1). In an operation, you select a prefix of a, and simultaneously invert the bits in the prefix (0 changes to 1 and 1 changes to 0) and reverse the order of the bits in the prefix.

For example, if a=001011 and you select the prefix of length 3, it becomes 011011. Then if you select the entire string, it becomes 001001.

Your task is to transform the string a into b in at most 3n operations. It can be proved that it is always possible.

Input

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

The first line of each test case contains a single integer n (1≤ n≤ 1000) — the length of the binary strings.

The next two lines contain two binary strings a and b of length n.

It is guaranteed that the sum of n across all test cases does not exceed 1000.

Output

For each test case, output an integer k (0≤ k≤ 3n), followed by k integers p_1,…,p_k (1≤ p_i≤ n). Here k is the number of operations you use and p_i is the length of the prefix you flip in the i-th operation.

Example

Input

5
2
01
10
5
01011
11100
2
01
01
10
0110011011
1000110100
1
0
1

Output

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

Note

In the first test case, we have 01→ 11→ 00→ 10.

In the second test case, we have 01011→ 00101→ 11101→ 01000→ 10100→ 00100→ 11100.

In the third test case, the strings are already the same. Another solution is to flip the prefix of length 2, which will leave a unchanged.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
inline int mul(int a, int b) { return (a * 1ll * b) % 1000000007; }
inline int power(int a, int b) {
  int rt = 1;
  while (b > 0) {
    if (b & 1) rt = mul(rt, a);
    a = mul(a, a);
    b >>= 1;
  }
  return rt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        if (i > 0) ans.push_back(i + 1);
        ans.push_back(1);
        if (i > 0) ans.push_back(i + 1);
      }
    }
    cout << ans.size() << " ";
    for (auto x : ans) cout << x << " ";
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: «eye», «pop», «level», «aba», «deed», «racecar», «rotor», «madam».

Nick started to look carefully for all palindromes in the text that they were reading in the class. For each occurrence of each palindrome in the text he wrote a pair — the position of the beginning and the position of the ending of this occurrence in the text. Nick called each occurrence of each palindrome he found in the text subpalindrome. When he found all the subpalindromes, he decided to find out how many different pairs among these subpalindromes cross. Two subpalindromes cross if they cover common positions in the text. No palindrome can cross itself.

Let's look at the actions, performed by Nick, by the example of text «babb». At first he wrote out all subpalindromes:

• «b» — 1..1 • «bab» — 1..3 • «a» — 2..2 • «b» — 3..3 • «bb» — 3..4 • «b» — 4..4

Then Nick counted the amount of different pairs among these subpalindromes that cross. These pairs were six:

1. 1..1 cross with 1..3 2. 1..3 cross with 2..2 3. 1..3 cross with 3..3 4. 1..3 cross with 3..4 5. 3..3 cross with 3..4 6. 3..4 cross with 4..4

Since it's very exhausting to perform all the described actions manually, Nick asked you to help him and write a program that can find out the amount of different subpalindrome pairs that cross. Two subpalindrome pairs are regarded as different if one of the pairs contains a subpalindrome that the other does not.

Input

The first input line contains integer n (1 ≤ n ≤ 2·106) — length of the text. The following line contains n lower-case Latin letters (from a to z).

Output

In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987.

Examples

Input

4
babb

Output

6

Input

2
aa

Output

2

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC target("sse4,avx")
const int p = 51123987;
struct string_view {
  const std::string& str;
  size_t left;
  size_t right;
  string_view(const std::string& str, size_t left, size_t right)
      : str(str), left(left), right(right) {}
  string_view(const string_view& view, size_t left, size_t right)
      : str(view.str), left(view.left + left), right(view.left + right) {}
  size_t size() const { return right - left; }
  char operator[](size_t idx) const { return str[left + idx]; }
};
struct Solution {
  std::vector<size_t> selfZ;
  std::vector<size_t> commonZ;
  void getSelfZ(const string_view& view) {
    size_t n = view.size();
    selfZ[0] = n;
    size_t right_bound = 1;
    size_t offset = 0;
    for (size_t i = 1; i < n; i++) {
      if (i >= right_bound || selfZ[i - offset] + i >= right_bound) {
        size_t start = std::max(i, right_bound);
        for (; start < n && view[start] == view[start - i]; start++) {
        }
        selfZ[i] = start - i;
        right_bound = start;
        offset = i;
      } else {
        selfZ[i] = selfZ[i - offset];
      }
    }
  }
  void getZ(const string_view& view, size_t maxn, const string_view& pattern) {
    size_t n = view.size();
    size_t m = pattern.size();
    size_t right_bound = 0;
    size_t offset = 0;
    for (size_t i = 0; i < maxn; i++) {
      if (i >= right_bound || selfZ[i - offset] + i >= right_bound) {
        size_t start = std::max(i, right_bound);
        for (; start < std::min(n, m + i) && view[start] == pattern[start - i];
             start++) {
        }
        commonZ[i] = start - i;
        right_bound = start;
        offset = i;
      } else {
        commonZ[i] = selfZ[i - offset];
      }
    }
  }
  void getPalindromes(const string_view& view, const string_view& rview,
                      std::vector<size_t>& maxLen) {
    if (view.size() <= 3) {
      for (size_t i = 0; i < view.size(); i++) {
        for (size_t j = i; j < view.size(); j++) {
          bool good = true;
          for (size_t k = i, l = j; k < l; k++, l--) {
            if (view[k] != view[l]) {
              good = false;
              break;
            }
          }
          if (good) {
            maxLen[i + j + view.left * 2] =
                std::max(maxLen[i + j + view.left * 2], j - i + 1);
          }
        }
      }
      return;
    }
    size_t middle = view.size() / 2;
    size_t revMiddle = view.size() - middle;
    string_view viewHalf(view, middle, view.size());
    getSelfZ(viewHalf);
    getZ(rview, revMiddle, viewHalf);
    for (size_t i = 0; i < revMiddle; i++) {
      size_t rightPos = i + commonZ[i];
      if (rightPos > revMiddle) {
        size_t left = view.right - rightPos;
        size_t right = view.left + middle + commonZ[i] - 1;
        maxLen[left + right] = std::max(maxLen[left + right], right - left + 1);
      }
    }
    string_view viewHalf2(rview, revMiddle, rview.size());
    getSelfZ(viewHalf2);
    getZ(view, middle + 1, viewHalf2);
    for (size_t i = 0; i <= middle; i++) {
      size_t rightPos = i + commonZ[i];
      if (rightPos > middle) {
        size_t left = view.left + middle - commonZ[i];
        size_t right = view.left + rightPos - 1;
        maxLen[left + right] = std::max(maxLen[left + right], right - left + 1);
      }
    }
    getPalindromes(string_view(view, 0, middle),
                   string_view(rview, revMiddle, rview.size()), maxLen);
    getPalindromes(string_view(view, middle, view.size()),
                   string_view(rview, 0, revMiddle), maxLen);
  }
  static int mul32(int x, int y, int p) { return int(int64_t(x) * y % p); }
  void run(std::istream& in, std::ostream& out) {
    size_t n;
    in >> n;
    std::string s;
    in >> s;
    std::string r = s;
    std::reverse(r.begin(), r.end());
    std::vector<size_t> maxLen(2 * n - 1);
    selfZ.resize(n);
    commonZ.resize(n);
    getPalindromes(string_view(s, 0, n), string_view(r, 0, n), maxLen);
    std::vector<int> leftBounds(n);
    std::vector<int> allPalindromes(n);
    for (size_t i = 0; i < maxLen.size(); i++) {
      if (maxLen[i] == 0) continue;
      size_t left = (i + 1 - maxLen[i]) / 2;
      size_t middle = left + (maxLen[i] + 1) / 2;
      leftBounds[left]++;
      if (middle < n) leftBounds[middle]--;
    }
    for (size_t i = 1; i < leftBounds.size(); i++) {
      leftBounds[i] += leftBounds[i - 1];
    }
    for (size_t i = 0; i < maxLen.size(); i++) {
      if (maxLen[i] == 0) continue;
      size_t left = (i + 1 - maxLen[i]) / 2;
      size_t middle1 = left + (maxLen[i] + 1) / 2;
      size_t middle2 = left + (maxLen[i] + 2) / 2;
      size_t right = left + maxLen[i] + 1;
      allPalindromes[left]++;
      if (middle1 < n) allPalindromes[middle1]--;
      if (middle2 < n) allPalindromes[middle2]--;
      if (right < n) allPalindromes[right]++;
    }
    for (size_t i = 1; i < allPalindromes.size(); i++) {
      allPalindromes[i] = (allPalindromes[i] + allPalindromes[i - 1]) % p;
    }
    for (size_t i = 1; i < allPalindromes.size(); i++) {
      allPalindromes[i] = (allPalindromes[i] + allPalindromes[i - 1]) % p;
    }
    int res = 0;
    for (size_t i = 0; i < allPalindromes.size(); i++) {
      res += mul32(allPalindromes[i] - leftBounds[i], leftBounds[i], p);
      if (leftBounds[i] & 1) {
        res += mul32((leftBounds[i] - 1) / 2, leftBounds[i], p);
      } else {
        res += mul32(leftBounds[i] - 1, leftBounds[i] / 2, p);
      }
      res = res % p;
    }
    if (res < 0) res += p;
    out << res << std::endl;
  }
};
int main() {
  std::cin.sync_with_stdio(false);
  std::cin.tie(nullptr);
  Solution().run(std::cin, std::cout);
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.

Note, that during capitalization all the letters except the first one remains unchanged.

Input

A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.

Output

Output the given word after capitalization.

Examples

Input

ApPLe

Output

ApPLe

Input

konjac

Output

Konjac

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string word;
  cin >> word;
  if (word[0] >= 97 && word[0] <= 122) word[0] = word[0] - 32;
  cout << word << endl;
  return 0;
}

```


### Prompt

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

The city Valera lives in is going to hold elections to the city Parliament.

The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to n, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired.

There are n candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to n, inclusive. If the candidate number i will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the i-th district to the district 1, where the city Parliament is located.

Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates.

Input

The first line contains a single integer n (2 ≤ n ≤ 105) — the number of districts in the city.

Then n - 1 lines follow. Each line contains the description of a city road as three positive integers xi, yi, ti (1 ≤ xi, yi ≤ n, 1 ≤ ti ≤ 2) — the districts connected by the i-th bidirectional road and the road type. If ti equals to one, then the i-th road isn't the problem road; if ti equals to two, then the i-th road is the problem road.

It's guaranteed that the graph structure of the city is a tree.

Output

In the first line print a single non-negative number k — the minimum size of the required subset of candidates. Then on the second line print k space-separated integers a1, a2, ... ak — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them.

Examples

Input

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

Output

1
5

Input

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

Output

1
3

Input

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

Output

4
5 4 3 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 2;
const long long MOD = 1e9 + 7;
const long long Inf = MOD * MOD;
const long double eps = 1e-7;
const long long dx[] = {1, 0, 0, 0};
const long long dy[] = {0, 1, 1, -1};
long long n, u, v, w, timer = 0, t = 1;
vector<int> adj[N];
vector<int> Ans;
map<pair<int, int>, bool> M;
bool vis[N];
bool dfs(int u, int par) {
  int Res = false;
  for (auto x : adj[u]) {
    if (x != par) {
      Res |= dfs(x, u);
    }
  }
  if (M[{u, par}] && !Res) {
    Ans.push_back(u);
    Res = true;
  }
  return Res;
}
void Solve() {
  scanf("%lld", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%lld%lld%lld", &u, &v, &w);
    M[{u, v}] = w - 1;
    M[{v, u}] = w - 1;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  printf("%d\n", (int)Ans.size());
  for (auto x : Ans) {
    cout << x << " ";
  }
}
int main() {
  while (t--) {
    ++timer;
    Solve();
    puts("");
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels.

Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that:

  * there are exactly n pixels on the display;
  * the number of rows does not exceed the number of columns, it means a ≤ b;
  * the difference b - a is as small as possible.

Input

The first line contains the positive integer n (1 ≤ n ≤ 106) — the number of pixels display should have.

Output

Print two integers — the number of rows and columns on the display.

Examples

Input

8

Output

2 4

Input

64

Output

8 8

Input

5

Output

1 5

Input

999999

Output

999 1001

Note

In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.

In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.

In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.

### Response

```cpp
#include <bits/stdc++.h>
int n, k;
int main() {
  scanf("%d", &n);
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) k = i;
  }
  printf("%d %d", k, n / k);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Consider a conveyor belt represented using a grid consisting of n rows and m columns. The cell in the i-th row from the top and the j-th column from the left is labelled (i,j).

Every cell, except (n,m), has a direction R (Right) or D (Down) assigned to it. If the cell (i,j) is assigned direction R, any luggage kept on that will move to the cell (i,j+1). Similarly, if the cell (i,j) is assigned direction D, any luggage kept on that will move to the cell (i+1,j). If at any moment, the luggage moves out of the grid, it is considered to be lost.

There is a counter at the cell (n,m) from where all luggage is picked. A conveyor belt is called functional if and only if any luggage reaches the counter regardless of which cell it is placed in initially. More formally, for every cell (i,j), any luggage placed in this cell should eventually end up in the cell (n,m).

This may not hold initially; you are, however, allowed to change the directions of some cells to make the conveyor belt functional. Please determine the minimum amount of cells you have to change.

Please note that it is always possible to make any conveyor belt functional by changing the directions of some set of cells.

Input

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

The first line of each test case contains two integers n, m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of rows and columns, respectively.

The following n lines each contain m characters. The j-th character in the i-th line, a_{i,j} is the initial direction of the cell (i, j). Please note that a_{n,m}= C.

Output

For each case, output in a new line the minimum number of cells that you have to change to make the conveyor belt functional.

Example

Input

4
3 3
RRD
DDR
RRC
1 4
DDDC
6 9
RDDDDDRRR
RRDDRRDDD
RRDRDRRDR
DDDDRDDRR
DRRDRDDDR
DDRDRRDDC
1 1
C

Output

1
3
9
0

Note

In the first case, just changing the direction of (2,3) to D is enough.

You can verify that the resulting belt is functional. For example, if we place any luggage at (2,2), it first moves to (3,2) and then to (3,3).

In the second case, we have no option but to change the first 3 cells from D to R making the grid equal to RRRC.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, ans = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (i == n - 1) {
        for (int j = 0; j < s.size() - 1; j++) {
          if (s[j] == 'D') ans++;
        }
      } else {
        if (s[s.size() - 1] == 'R') ans++;
      }
    }
    cout << ans << endl;
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the song name, Peter immediately plays the following song in order, and so on.

The i-th song of AC/PE has its recognizability pi. This means that if the song has not yet been recognized by you, you listen to it for exactly one more second and with probability of pi percent you recognize it and tell it's name. Otherwise you continue listening it. Note that you can only try to guess it only when it is integer number of seconds after the moment the song starts playing.

In all AC/PE songs the first words of chorus are the same as the title, so when you've heard the first ti seconds of i-th song and its chorus starts, you immediately guess its name for sure.

For example, in the song Highway To Red the chorus sounds pretty late, but the song has high recognizability. In the song Back In Blue, on the other hand, the words from the title sound close to the beginning of the song, but it's hard to name it before hearing those words. You can name both of these songs during a few more first seconds.

Determine the expected number songs of you will recognize if the game lasts for exactly T seconds (i. e. you can make the last guess on the second T, after that the game stops).

If all songs are recognized faster than in T seconds, the game stops after the last song is recognized.

Input

The first line of the input contains numbers n and T (1 ≤ n ≤ 5000, 1 ≤ T ≤ 5000), separated by a space. Next n lines contain pairs of numbers pi and ti (0 ≤ pi ≤ 100, 1 ≤ ti ≤ T). The songs are given in the same order as in Petya's list.

Output

Output a single number — the expected number of the number of songs you will recognize in T seconds. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Examples

Input

2 2
50 2
10 1

Output

1.500000000

Input

2 2
0 2
100 2

Output

1.000000000

Input

3 3
50 3
50 2
25 2

Output

1.687500000

Input

2 2
0 2
0 2

Output

1.000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 10;
int p[MAXN], c[MAXN];
double dp[MAXN][MAXN];
inline double qpow(double x, int y) {
  double ret = 1;
  while (y) {
    if (y & 1) ret *= x;
    x *= x, y >>= 1;
  }
  return ret;
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 0; i != n; ++i) {
    scanf("%d%d", p + i, c + i);
  }
  dp[0][0] = 1;
  double ans = 0;
  for (int i = 0; i != n; ++i) {
    double pp = p[i] / 100.0;
    double now = 0;
    double r = qpow(1 - pp, c[i] - 1) * pp;
    double r2 = qpow(1 - pp, c[i] - 1);
    for (int j = 0; j != t; ++j) {
      now *= 1 - pp;
      now += dp[i][j] * pp;
      if (j + 1 >= c[i]) {
        now -= dp[i][j - c[i] + 1] * r;
        dp[i + 1][j + 1] = now + dp[i][j - c[i] + 1] * r2;
      } else
        dp[i + 1][j + 1] = now;
    }
    for (int j = 0; j != t + 1; ++j) {
      ans += dp[i + 1][j];
    }
  }
  printf("%.8lf", ans);
  return 0;
}

```


### Prompt

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

Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.

<image>

Initially, each hole has a_i stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.

Note that the counter-clockwise order means if the player takes the stones from hole i, he will put one stone in the (i+1)-th hole, then in the (i+2)-th, etc. If he puts a stone in the 14-th hole, the next one will be put in the first hole.

After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.

Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

Input

The only line contains 14 integers a_1, a_2, …, a_{14} (0 ≤ a_i ≤ 10^9) — the number of stones in each hole.

It is guaranteed that for any i (1≤ i ≤ 14) a_i is either zero or odd, and there is at least one stone in the board.

Output

Output one integer, the maximum possible score after one move.

Examples

Input

0 1 1 0 0 0 0 0 0 7 0 0 0 0

Output

4

Input

5 1 1 1 1 0 0 0 0 0 0 0 0 0

Output

8

Note

In the first test case the board after the move from the hole with 7 stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n = 14;
  vector<long long int> holes(n);
  for (int i = 0; i < n; i++) cin >> holes[i];
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    vector<long long int> aux = holes;
    long long int cant = holes[i];
    if (cant == 0) continue;
    long long int cuno = cant / 14ll, sobra = cant % 14ll;
    aux[i] = 0;
    for (int j = 0; j < n; j++) {
      aux[j] += cuno;
    }
    int idx = i + 1;
    while (sobra--) {
      if (idx == 14) idx = 0;
      aux[idx]++;
      idx++;
    }
    long long int res = 0;
    for (int j = 0; j < n; j++) {
      if (aux[j] % 2 == 0) res += aux[j];
    }
    ans = max(res, ans);
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". This time I will make a box with sticks, but I would like to see if I can make a rectangular parallelepiped using the 12 sticks I prepared. However, the stick must not be cut or broken.

Given the lengths of the twelve bars, write a program to determine if you can create a rectangular parallelepiped with all of them as sides.

Input

The input is given in the following format.

e1 e2 ... e12

The input consists of one line and is given the integer ei (1 ≤ ei ≤ 100) representing the length of each bar.

Output

If a rectangular parallelepiped can be created, "yes" is output, and if it cannot be created, "no" is output. However, since a cube is a kind of rectangular parallelepiped, "yes" is output even if it is a cube.

Examples

Input

1 1 3 4 8 9 7 3 4 5 5 5

Output

no

Input

1 1 2 2 3 1 2 3 3 3 1 2

Output

yes

### Response

```cpp
#include <stdio.h>
int size[3],a[12],s[3];
bool dfs(int now){
    if(now>=12)return true;
    else{
        for(int i=0;i<3;i++)if(s[i]==-1){
            size[i]=1;
            s[i]=a[now];
            if(dfs(now+1))return true;
            s[i]=-1;
            size[i]=0;
        }
        else if(s[i]==a[now]&&size[i]<5){
            size[i]++;
            if(dfs(now+1))return true;
            size[i]--;
        }
        return false;
    }
}
int main(){
    for(int i=0;i<3;i++)s[i]=-1;
    for(int i=0;i<12;i++)scanf("%d",&a[i]);
    if(dfs(0))printf("yes\n");
    else printf("no\n");
}

```


### Prompt

Create a solution in Cpp for the following problem:

Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).

Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.

Dima considers two assembled sequences (p1, q1), (p2, q2), ..., (p2·n, q2·n) and (x1, y1), (x2, y2), ..., (x2·n, y2·n) distinct, if there is such i (1 ≤ i ≤ 2·n), that (pi, qi) ≠ (xi, yi).

As the answer can be rather large, print the remainder from dividing the answer by number m.

Input

The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 109). The numbers in the lines are separated by spaces.

The last line contains integer m (2 ≤ m ≤ 109 + 7).

Output

In the single line print the remainder after dividing the answer to the problem by number m.

Examples

Input

1
1
2
7

Output

1

Input

2
1 2
2 3
11

Output

2

Note

In the first sample you can get only one sequence: (1, 1), (2, 1).

In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cnt;
long long a[200001], n, m, res, same;
int main() {
  cin >> n;
  for (int i = 0; i < n * 2; i++) {
    cin >> a[i], cnt[a[i]]++;
    if (i >= n)
      if (a[i - n] == a[i]) same++;
  }
  cin >> m;
  res = 1;
  for (int i = 0; i < 2 * n; i++) {
    for (int j = 1; j <= cnt[a[i]]; j++) {
      res *= j;
      while (res % 2 == 0 && same) res /= 2, same--;
      res %= m;
    }
    cnt[a[i]] = 0;
  }
  cout << res << endl;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

The best night ever in the world has come! It's 8 p.m. of December 24th, yes, the night of Cristmas Eve. Santa Clause comes to a silent city with ringing bells. Overtaking north wind, from a sleigh a reindeer pulls she shoot presents to soxes hanged near windows for children.

The sleigh she is on departs from a big christmas tree on the fringe of the city. Miracle power that the christmas tree spread over the sky like a web and form a paths that the sleigh can go on. Since the paths with thicker miracle power is easier to go, these paths can be expressed as undirected weighted graph.

Derivering the present is very strict about time. When it begins dawning the miracle power rapidly weakens and Santa Clause can not continue derivering any more. Her pride as a Santa Clause never excuses such a thing, so she have to finish derivering before dawning.

The sleigh a reindeer pulls departs from christmas tree (which corresponds to 0th node), and go across the city to the opposite fringe (n-1 th node) along the shortest path. Santa Clause create presents from the miracle power and shoot them from the sleigh the reindeer pulls at his full power. If there are two or more shortest paths, the reindeer selects one of all shortest paths with equal probability and go along it.

By the way, in this city there are p children that wish to see Santa Clause and are looking up the starlit sky from their home. Above the i-th child's home there is a cross point of the miracle power that corresponds to c[i]-th node of the graph. The child can see Santa Clause if (and only if) Santa Clause go through the node.

Please find the probability that each child can see Santa Clause.

Constraints

* 3 ≤ n ≤ 100
* There are no parallel edges and a edge whose end points are identical.
* 0 < weight of the edge < 10000

Input

Input consists of several datasets.

The first line of each dataset contains three integers n, m, p, which means the number of nodes and edges of the graph, and the number of the children. Each node are numbered 0 to n-1.

Following m lines contains information about edges. Each line has three integers. The first two integers means nodes on two endpoints of the edge. The third one is weight of the edge.

Next p lines represent c[i] respectively.

Input terminates when n = m = p = 0.

Output

For each dataset, output p decimal values in same order as input. Write a blank line after that.

You may output any number of digit and may contain an error less than 1.0e-6.

Example

Input

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

Output

1.00000000

0.50000000
0.50000000

### Response

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;

void chmin(int& a,int b)
{
	a=min(a,b);
}

int main()
{
	for(int n,m,s;cin>>n>>m>>s && n|m|s;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w;
			g[u].emplace_back(u,v,w);
			g[v].emplace_back(v,u,w);
		}
		vi cs(s);
		rep(i,s) cin>>cs[i];

		vvi dp(n,vi(n,INF));
		rep(i,n) dp[i][i]=0;
		rep(i,n) for(auto e:g[i]) chmin(dp[e.src][e.dst],e.weight);
		rep(k,n) rep(i,n) rep(j,n) chmin(dp[i][j],dp[i][k]+dp[k][j]);

		vd cnt1(n,0); cnt1[0]=1;
		{
			Graph gg(n);
			rep(i,n) for(auto e:g[i]) if(dp[0][e.src]+e.weight+dp[e.dst][n-1]==dp[0][n-1])
				gg[e.src].push_back(e);
			vi is(n); iota(all(is),0);
			sort(all(is),[&](int i,int j){return dp[0][i]<dp[0][j];});
			for(auto u:is) for(auto e:gg[u]) cnt1[e.dst]+=cnt1[u];
		}
		vd cnt2(n,0); cnt2[n-1]=1;
		{
			Graph gg(n);
			rep(i,n) for(auto e:g[i]) if(dp[0][e.src]+e.weight+dp[e.dst][n-1]==dp[0][n-1])
				gg[e.dst].emplace_back(e.dst,e.src,e.weight);
			vi is(n); iota(all(is),0);
			sort(all(is),[&](int i,int j){return dp[n-1][i]<dp[n-1][j];});
			for(auto u:is) for(auto e:gg[u]) cnt2[e.dst]+=cnt2[u];
		}

		for(auto i:cs) printf("%.9f\n",cnt1[i]*cnt2[i]/cnt1[n-1]); puts("");
	}
}
```


### Prompt

Create a solution in Cpp for the following problem:

One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.

Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.

Input

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

Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality).

All ai are distinct. All bi are distinct.

Output

If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).

Examples

Input

2
1 2
2 1

Output

Happy Alex

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, a, b;
  vector<pair<long, long> > v;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  long i = 0;
  bool find = false;
  while (i < n - 1 && !find) {
    if (v[i].second > v[i + 1].second)
      find = true;
    else
      i++;
  }
  if (find)
    cout << "Happy Alex";
  else
    cout << "Poor Alex";
  cout << endl;
  return 0;
}

```


### Prompt

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

The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.

Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits.

Input

The only line of input contains one integer n (1 ≤ n ≤ 55) — the maximum length of a number that a door-plate can hold.

Output

Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than n digits.

Examples

Input

2

Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char _;
const int maxN = 80 + 5;
const int maxM = 5000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 500;
const int maxL = 20;
long double x = 1.000000011;
long double power(long double n, int k) {
  if (k == 0) return 1.0;
  long double ans = power(n, k / 2);
  ans = ans * ans;
  if (k & 1) ans = ans * n;
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cout << (1LL << (n + 1)) - 2 << endl;
  return 0;
}

```


### Prompt

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

A maze is composed of a grid of H \times W squares - H vertical, W horizontal.

The square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is `#` and a road if S_{ij} is `.`.

There is a magician in (C_h,C_w). He can do the following two kinds of moves:

* Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.
* Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in.

In either case, he cannot go out of the maze.

At least how many times does he need to use the magic to reach (D_h, D_w)?

Constraints

* 1 \leq H,W \leq 10^3
* 1 \leq C_h,D_h \leq H
* 1 \leq C_w,D_w \leq W
* S_{ij} is `#` or `.`.
* S_{C_h C_w} and S_{D_h D_w} are `.`.
* (C_h,C_w) \neq (D_h,D_w)

Input

Input is given from Standard Input in the following format:

H W
C_h C_w
D_h D_w
S_{11}\ldots S_{1W}
\vdots
S_{H1}\ldots S_{HW}

Output

Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print `-1` instead.

Examples

Input

4 4
1 1
4 4
..#.
..#.
.#..
.#..

Output

1

Input

4 4
1 4
4 1
.##.

.##.

Output

-1

Input

4 4
2 2
3 3
....
....
....
....

Output

0

Input

4 5
1 2
2 5
.###
.
..##
..##

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int H,W,sx,sy,gx,gy,d[1000][1000];
string s[1000];
int INF=1<<30;
int main()
{
    cin>>H>>W;
    cin>>sx>>sy;
    cin>>gx>>gy;
    --sx;--sy;--gx;--gy;
    for(int i=0;i<H;++i)cin>>s[i];
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=INF;
    d[sx][sy]=0;
    deque<pair<int,int>>q;
    q.push_back({sx,sy});
    while(!q.empty())
    {
        int x=q.front().first;
        int y=q.front().second;
        q.pop_front();
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
        {
            int nx=x+i;
            int ny=y+j;
            if(nx<0||ny<0||nx>=H||ny>=W||s[nx][ny]=='#')continue;
            if(abs(i)+abs(j)<=1&&d[nx][ny]>d[x][y])
            {
                d[nx][ny]=d[x][y];
                q.push_front({nx,ny});
            }else if(d[nx][ny]>d[x][y]+1)
            {
                d[nx][ny]=d[x][y]+1;
                q.push_back({nx,ny});
            }
        }
    }
    cout<<(d[gx][gy]==INF?-1:d[gx][gy])<<endl;
}
```


### Prompt

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

In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).

Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.

Input

The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.

Output

The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.

Examples

Input

2
5 7

Output

2 5

Input

3
10 2 8

Output

1 8

Input

6
3 8 2 9 4 14

Output

6 9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, t;
  cin >> n;
  long long int p[n], m[n];
  for (long long int i = 0; i < n; i++) {
    cin >> p[i];
    m[i] = p[i];
  }
  sort(m, m + n, greater<int>());
  for (long long int i = 0; i < n; i++) {
    if (m[0] == p[i]) {
      t = i + 1;
      break;
    }
  }
  cout << t << " " << m[1];
  return 0;
}

```