### Prompt

Develop a solution in Cpp to the problem described below:

Problem C: Seishun 18 Kippu

A student at R University, sirokurostone, was about to attend a training camp at Atsu University. Other members plan to use the Shinkansen, but sirokurostone was going to use the Seishun 18 Ticket. Similarly, a person who likes 2D with a youth 18 ticket was also trying to participate in the training camp.

Sirokurostone, who wanted to go with him anyway, decided to pick up him who likes 2D at the station on the way. sirokurostone wants to check the delay situation before leaving R University and take a route that takes less time to reach the station where Atsu University is located. sirokurostone intends to give that information to him who likes 2D after the route is confirmed. However, sirokurostone is in trouble because he does not know which route to take to reach the station where Atsu University is located sooner even if he sees the delay situation.

So your job is to find out how long it will take to get to the station where Atsu University is located on behalf of sirokurostone from the delay situation.

Between each station, there is a distance between stations and an estimated delay time. The train shall maintain 40km / h after it starts moving. The travel time between points a and b is

* Distance / 40+ estimated delay time

Can be obtained at. The stop time at each station can be ignored.

Input

A sequence of multiple datasets is given as input. The number of datasets is guaranteed to be 50 or less. Each dataset has the following format:

n m
s p g
a1 b1 d1 t1
...
ai bi di ti
...
am bm dm tm

The integers n (3 ≤ n ≤ 500) and m (2 ≤ m ≤ 5000) represent the total number of stations and the number of tracks between each station, respectively. s, p, and g are character strings that indicate the location of the station where sirokurostone rides, the station where a person who likes 2D rides, and the station where Atsu University is located, respectively. s, p, and g are different character strings.

The following m line represents the information between stations. ai and bi are character strings indicating stations connected by railroad tracks. ai and bi can go back and forth in both directions. ai and bi never match. The integer di (40 ≤ di ≤ 10000) represents the distance between ai and bi. di is guaranteed to be a multiple of 40. The integer ti (0 ≤ ti ≤ 20) indicates the estimated delay time between ai and bi.

The character string representing the station name is represented by a character string of 20 characters or less consisting of all lowercase and uppercase letters of the alphabet. There is at most one track between stations.

The end of the input is represented by a line containing two zeros.

Output

For each input dataset, output the arrival time (unit: time) to the station where Atsu University is located. It is guaranteed that there is a route from the station where sirokurostone rides to the station where 2D lovers ride, and a route from the station where 2D lovers ride to the station where Atsu University is located.

Sample Input

4 4
A B G
A B 40 3
B C 80 0
A G 40 0
B G 80 0
5 6
Kusatsu Tokyo Aizu
Tokyo Nagoya 120 3
Kusatsu Nagoya 40 0
Kusatsu Kanazawa 40 0
Kanazawa Aizu 40 0
Tokyo Kanazawa 40 0
Tokyo Aizu 80 4
0 0

Output for Sample Input

Five
Four

Example

Input

4 4
A B G
A B 40 3
B C 80 0
A G 40 0
B G 80 0
5 6
Kusatsu Tokyo Aizu
Tokyo Nagoya 120 3
Kusatsu Nagoya 40 0
Kusatsu Kanazawa 40 0
Kanazawa Aizu 40 0
Tokyo Kanazawa 40 0
Tokyo Aizu 80 4
0 0

Output

5
4

### Response

```cpp
//11
#include<iostream>
#include<set>
#include<map>

using namespace std;

int dik(map<string,map<string,int> > d,string s,string g){
  set<string> p;
  map<string,int> n;
  n[s]=0;
  for(int i=0;i<d.size();i++){
    int nm=1<<30;
    string ns;
    for(map<string,int>::iterator it=n.begin();it!=n.end();it++){
      if(!p.count(it->first)&&it->second<nm){
	nm=it->second;
	ns=it->first;
      }
    }
    p.insert(ns);
    for(map<string,int>::iterator it=d[ns].begin();it!=d[ns].end();it++){
      if(!n.count(it->first)||n[it->first]>n[ns]+d[ns][it->first]){
	n[it->first]=n[ns]+d[ns][it->first];
      }
    }
  }
  return n[g];
}

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    string s,p,g;
    cin>>s>>p>>g;
    map<string,map<string,int> > d;
    for(int i=0;i<m;i++){
      string a,b;
      int dd,t;
      cin>>a>>b>>dd>>t;
      d[a][b]=dd/40+t;
      d[b][a]=dd/40+t;
    }
    cout<<dik(d,s,p)+dik(d,p,g)<<endl;
  }
  return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.

Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.

Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds.

Your task is to help him solve this complicated task.

Input

The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.

Output

Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6.

Examples

Input

1 0.50 1

Output

0.5

Input

1 0.50 4

Output

0.9375

Input

4 0.20 2

Output

0.4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double dp[2004][2004];
int main() {
  int n, t;
  double p, ans = 0.0000000;
  cin >> n >> p >> t;
  dp[0][0] = 1.000000000;
  for (int i = 1; i <= t; ++i) dp[i][0] = dp[i - 1][0] * (1.0000000 - p);
  for (int i = 1; i <= max(n, t); ++i) dp[0][i] = 0.000000000;
  for (int i = 1; i <= t; ++i) {
    for (int j = 1; j <= t; ++j) {
      dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1.000000000 - p);
    }
  }
  for (int i = 1; i <= t; ++i) ans += min(i, n) * dp[t][i];
  printf("%.9lf\n", ans);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

The Quarkgo Empire Expeditionary Force is an evil organization that plans to invade the Earth. In keeping with the tradition of the invaders, they continued to send monsters at a pace of one every week, targeting the area around Tokyo in Japan. However, each time, five warriors calling themselves the Human Squadron Earth Five appeared, and the monster who was rampaging in the city was easily defeated.

Walzard Thru (Earth name: Genmasa) is a female executive of the Quarkgo Empire Expeditionary Force who is seriously worried about such a situation. She had a headache under a commander who wouldn't learn anything from her weekly defeat, or a genius scientist who repeated some misplaced inventions.

Meanwhile, the next operation was decided to send the blood-sucking monster Dracula to Japan. Dracula is a terrifying monster who turns a blood-sucking human into Dracula. Humans who have been sucked by Dracula also suck the blood of other humans to increase their fellow Dracula. In this way, the strategy is to fill the entire earth with Dracula.

Upon hearing this, Walzard soon realized. This strategy is different from the usual sequel strategy such as taking over a kindergarten bus. It's rare for that bad commander to have devised it, and it has the potential to really conquer the Earth.

The momentum of the game is terrifying. Dracula, who landed on the ground, quickly increased the number of friends. If we went on like this, the invasion of the earth seemed to be just a stone's throw away. However, at that moment, a strong and unpleasant premonition ran through Walzard's mind. No way, if this monster, the original is defeated, his friends will not be wiped out, right?

When I asked the scientist who designed and developed Dracula in a hurry, he was still worried about Walzard. It is designed so that when the original Dracula is destroyed, all humans who have sucked blood will return to their original state. Don't be foolish developer. Why did you add such an extra function!

Walzard jumped to the developer and decided to kick his knee, and immediately started the original recovery work. No matter how much the original and the fake look exactly the same, if nothing is done, it is visible that the rushed Earth Five will see through the original for some reason and be defeated.

According to the developers, all Draculaized humans weigh the same, but the original Dracula is a little heavier. Then you should be able to find the original by using only the balance. You must find and retrieve the original Dracula as soon as possible before the Earth Five appears.

Input

N

The integer N (2 ≤ N ≤ 2,000,000,000) is written on the first line of the input. This represents the total number of Draculas, both original and fake.

Output

In the worst case, how many times is it enough to use the balance to find one original from the N Draculas using the balance? Output the minimum value. However, comparing the weights of several Draculas placed on the left and right plates of the balance is counted as one time.

Examples

Input

8

Output

2

Input

30

Output

4

Input

2000000000

Output

20

### Response

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

int main(){
    int N;
    scanf("%d", &N);
    printf("%d\n", (int)ceil(log(N) / log(3)));
    return 0;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

Maria participates in a bicycle race.

The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.

Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).

Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.

Help Maria get ready for the competition — determine the number of dangerous turns on the track.

Input

The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track.

The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi, yi) and ends at the point (xi + 1, yi + 1).

It is guaranteed that:

  * the first straight section is directed to the north;
  * the southernmost (and if there are several, then the most western of among them) point of the track is the first point;
  * the last point coincides with the first one (i.e., the start position);
  * any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point);
  * no pair of points (except for the first and last one) is the same;
  * no two adjacent straight sections are directed in the same direction or in opposite directions.

Output

Print a single integer — the number of dangerous turns on the track.

Examples

Input

6
0 0
0 1
1 1
1 2
2 2
2 0
0 0

Output

1

Input

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

Output

6

Note

The first sample corresponds to the picture:

<image>

The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 3;
const int MAXABSXY = 1e4 + 4;
int n;
int x[MAXN], y[MAXN];
void solve() {
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int ldir, dir;
    if (x[i - 2 >= 0 ? i - 2 : n] == x[i - 1]) {
      if (y[i - 2 >= 0 ? i - 2 : n] < y[i - 1])
        ldir = 0;
      else
        ldir = 1;
    } else {
      if (x[i - 2 >= 0 ? i - 2 : n] < x[i - 1])
        ldir = 2;
      else
        ldir = 3;
    }
    if (x[i - 1] == x[i]) {
      if (y[i - 1] < y[i])
        dir = 0;
      else
        dir = 1;
    } else {
      if (x[i - 1] < x[i])
        dir = 2;
      else
        dir = 3;
    }
    if (ldir == 0 && dir == 3) ++ans;
    if (ldir == 1 && dir == 2) ++ans;
    if (ldir == 2 && dir == 0) ++ans;
    if (ldir == 3 && dir == 1) ++ans;
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n; ++i) scanf("%d%d", x + i, y + i);
  solve();
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

In "Takahashi-ya", a ramen restaurant, basically they have one menu: "ramen", but N kinds of toppings are also offered. When a customer orders a bowl of ramen, for each kind of topping, he/she can choose whether to put it on top of his/her ramen or not. There is no limit on the number of toppings, and it is allowed to have all kinds of toppings or no topping at all. That is, considering the combination of the toppings, 2^N types of ramen can be ordered.

Akaki entered Takahashi-ya. She is thinking of ordering some bowls of ramen that satisfy both of the following two conditions:

* Do not order multiple bowls of ramen with the exactly same set of toppings.
* Each of the N kinds of toppings is on two or more bowls of ramen ordered.

You are given N and a prime number M. Find the number of the sets of bowls of ramen that satisfy these conditions, disregarding order, modulo M. Since she is in extreme hunger, ordering any number of bowls of ramen is fine.

Constraints

* 2 \leq N \leq 3000
* 10^8 \leq M \leq 10^9 + 9
* N is an integer.
* M is a prime number.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of the sets of bowls of ramen that satisfy the conditions, disregarding order, modulo M.

Examples

Input

2 1000000007

Output

2

Input

3 1000000009

Output

118

Input

50 111111113

Output

1456748

Input

3000 123456791

Output

16369789

### Response

```cpp
#include <iostream>
using namespace std;
int N, M, fact[3009], inv[3009], factinv[3009], dp[3009][3009], pw[9000009], fermat[3009];
int main() {
	cin >> N >> M;
	fact[0] = 1;
	for (int i = 1; i <= N; i++) fact[i] = 1LL * fact[i - 1] * i % M;
	inv[1] = 1;
	for (int i = 2; i <= N; i++) inv[i] = 1LL * inv[M % i] * (M - M / i) % M;
	factinv[0] = 1;
	for (int i = 1; i <= N; i++) factinv[i] = 1LL * inv[i] * factinv[i - 1] % M;
	pw[0] = 1;
	for (int i = 1; i <= N * N; i++) pw[i] = 2 * pw[i - 1] % M;
	fermat[0] = 2;
	for (int i = 1; i <= N; i++) fermat[i] = 1LL * fermat[i - 1] * fermat[i - 1] % M;
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= i; j++) {
			dp[i][j] = (dp[i - 1][j - 1] + 1LL * j * dp[i - 1][j]) % M;
		}
	}
	int ret = 0;
	for (int i = 0; i <= N; i++) {
		int val = 1LL * fact[N] * factinv[i] % M * factinv[N - i] % M * fermat[N - i] % M;
		if (i & 1) val = (val == 0 ? 0 : M - val);
		for (int j = 0; j <= i; j++) {
			ret = (ret + 1LL * val % M * dp[i][j] % M * pw[(N - i) * j]) % M;
			ret = (ret + 1LL * (j + 1) * val % M * dp[i][j + 1] % M * pw[(N - i) * j]) % M;
		}
	}
	cout << ret << "\n";
	return 0;
}
```


### Prompt

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

You have successfully completed your studies and are preparing to move from near Komaba to near Hongo. As I was organizing my house, I found a lot of lottery tickets I bought last year. After confirming the exchange deadline, I have to cash in by tomorrow, but it is troublesome to go to the lottery counter for a small amount of money because I am not ready to move at all. So you decide to find out how much you can win.

The lottery consists of eight digits. The winning number is also composed of 8 digits and a number and'*', and if the lottery you have and the number part match, the winning money will be paid according to the winning number.

For example, if the lottery number you have is "12345678", you will win if the winning number is "******* 8" or "**** 5678", but the winning number is "**". If it is ** 4678 ", you will not win. There can be multiple winning numbers, and the winnings will be paid independently for each. However, the winning numbers are chosen so that one lottery does not win more than one winning number. For example, if there are two winning numbers, "******* 8" and "**** 5678", "12345678" will win both, so such a winning number will be selected. There is no one to be done.

Your job is to write a program that outputs how much winning money you will get for the lottery number you have and the lottery winning number given as input.

Notes on Test Cases

Multiple datasets are given in the above input format. Create a program that outputs each data set in the above output format.

When n is 0, it indicates the end of input.

<!-

Input

The input is given in the following format.

n m
N1 M1
...
Nn Mn
B1
...
Bm

In the first line, the number of winning numbers n (1 ≤ n ≤ 100) and the number of lottery tickets in possession m (1 ≤ m ≤ 1000) are given as integers.

In the next n lines, each line is given a winning number Ni and a winnings Mi (1 ≤ Mi ≤ 1000000). Winnings are integers. The format of the winning number is as described in the question text.

The next m lines will give you the number of the lottery you have.

Output

Output the total amount of winnings.

Examples

Input

3 3
*******1 100
******22 1000
11111112 1000000
01203291
02382022
11111111
10 10
****3228 149416
****3992 198635
****4286 77783
****4843 225244
***49835 231046
***59393 379996
*5763748 437345
*6726222 58054
*8117882 16375
*9244339 537727
77885716
96726222
26971031
66652868
89599648
37772338
64679621
65479161
92959393
57855682
0 0

Output

1200
438050

Input

3 3
*******1 100
******22 1000
11111112 1000000
01203291
02382022
11111111

Output

1200

Input

10 10
****3228 149416
****3992 198635
****4286 77783
****4843 225244
***49835 231046
***59393 379996
*5763748 437345
*6726222 58054
*8117882 16375
*9244339 537727
77885716
96726222
26971031
66652868
89599648
37772338
64679621
65479161
92959393
57855682

Output

438050

### Response

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

bool match(const string &number, const string &lottery) {
	for(unsigned i = 0; i < number.size(); ++i) {
		if(number[i] != '*' && number[i] != lottery[i]) {
			return false;
		}
	}
	return true;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int n, m; cin >> n >> m && n;) {
		vector<pair<int, string>> winning_numbers(n);
		for(auto &e : winning_numbers) cin >> e.second >> e.first;
		sort(winning_numbers.rbegin(), winning_numbers.rend());

		int ans = 0;
		while(m--) {
			string lottery;
			cin >> lottery;

			for(auto &e : winning_numbers) {
				if(match(e.second, lottery)) {
					ans += e.first;
					break;
				}
			}
		}
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}
```


### Prompt

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

Your task is to write a program of a simple dictionary which implements the following instructions:

* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'

Notes

Template in C

Constraints

* A string consists of 'A', 'C', 'G', or 'T'
* 1 ≤ length of a string ≤ 12
* n ≤ 1000000

Input

In the first line n, the number of instructions is given. In the following n lines, n instructions are given in the above mentioned format.

Output

Print yes or no for each find instruction in a line.

Examples

Input

5
insert A
insert T
insert C
find G
find A

Output

no
yes

Input

13
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
insert T
find TTT
find T

Output

yes
no
no
yes
yes
yes

### Response

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

int main(){
  int n;
  map<string, bool> mp;

  cin >> n;
  for(int i = 0; i < n; i++){
    string s1, s2;
    cin >> s1 >> s2;
    if(s1 == "insert") mp[(s2)] = true;
    else{
      if(mp[(s2)]) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
  return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

You are given strings s and t. Find one longest string that is a subsequence of both s and t.

Constraints

* s and t are strings consisting of lowercase English letters.
* 1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t. If there are multiple such strings, any of them will be accepted.

Examples

Input

axyb
abyxb

Output

axb

Input

aa
xayaz

Output

aa

Input

a
z

Output

Input

abracadabra
avadakedavra

Output

aaadara

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3+10;
char a[maxn],b[maxn];
int dp[maxn][maxn];

int main() {
	scanf("%s",a+1);
	scanf("%s",b+1);
	int lena = strlen(a+1);
	int lenb = strlen(b+1);

	for(int i = lena;i >= 1;i--) {
		for(int j = lenb;j >= 1;j--) {
			if(a[i] == b[j])
				dp[i][j] = dp[i+1][j+1] +1;
			else
				dp[i][j] = max(dp[i+1][j],dp[i][j+1]);
		}
	}

	int l = 1,r = 1;
	while(l <= lena && r <= lenb) {
		if(a[l] == b[r]) {
			cout<<a[l];
			l++;
			r++;
		}
		else if(dp[l][r] == dp[l+1][r]) l++;
		else r++;
	}
	return 0;
}
```


### Prompt

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

Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n).

Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will get an expression consisting of n summands. The value of the resulting expression is the sum of all its elements. The task is to add signs "+" and "-" before each number so that the value of expression s meets the limits 0 ≤ s ≤ a1. Print a sequence of signs "+" and "-", satisfying the given limits. It is guaranteed that the solution for the problem exists.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the original array.

It is guaranteed that the condition ai ≤ ai + 1 ≤ 2·ai fulfills for any positive integer i (i < n).

Output

In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 ≤ s ≤ a1. If there are multiple solutions, you are allowed to print any of them.

Examples

Input

4
1 2 3 5

Output

+++-

Input

3
3 3 5

Output

++-

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int i, b[n];
  int sum = 0;
  char out[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  for (i = n - 1; i >= 0; i--) {
    if (sum <= 0) {
      sum = sum + b[i];
      out[i] = '+';
    } else {
      sum -= b[i];
      out[i] = '-';
    }
  }
  for (i = 0; i < n; i++) {
    if (sum < 0) {
      if (out[i] == '+')
        out[i] = '-';
      else if (out[i] == '-')
        out[i] = '+';
    }
    printf("%c", out[i]);
  }
  printf("\n");
  return 0;
}

```


### Prompt

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

Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.

Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).

You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.

Input

The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).

The sum a1 + a2 + ... + an will be less than or equal to 10000.

Output

Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).

Examples

Input

4
1 1 1 1

Output

12

Note

The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, MAXN = 1000, MAXSUM = 10000;
int dp[MAXN][(2 * MAXSUM) + 1], a[MAXN], n, i, j, sol;
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  dp[0][MAXSUM + a[0]]++;
  dp[0][MAXSUM - a[0]]++;
  sol = ((sol + dp[0][MAXSUM]) % MOD);
  for (i = 1; i < n; i++) {
    for (j = (-MAXSUM); j <= MAXSUM; j++)
      dp[i][j + MAXSUM] =
          ((dp[i - 1][j + (MAXSUM - a[i])] + dp[i - 1][j + (MAXSUM + a[i])] +
            (a[i] == (abs(j)))) %
           MOD);
    sol = ((sol + dp[i][MAXSUM]) % MOD);
  }
  printf("%d\n", sol);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

We will consider the numbers a and b as adjacent if they differ by exactly one, that is, |a-b|=1.

We will consider cells of a square matrix n × n as adjacent if they have a common side, that is, for cell (r, c) cells (r, c-1), (r, c+1), (r-1, c) and (r+1, c) are adjacent to it.

For a given number n, construct a square matrix n × n such that:

  * Each integer from 1 to n^2 occurs in this matrix exactly once;
  * If (r_1, c_1) and (r_2, c_2) are adjacent cells, then the numbers written in them must not be adjacent.

Input

The first line contains one integer t (1 ≤ t ≤ 100). Then t test cases follow.

Each test case is characterized by one integer n (1 ≤ n ≤ 100).

Output

For each test case, output:

  * -1, if the required matrix does not exist;
  * the required matrix, otherwise (any such matrix if many of them exist).

The matrix should be outputted as n lines, where each line contains n integers.

Example

Input

3
1
2
3

Output

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

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define Sort(v)         sort(v.begin(),v.end())
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    Fast
    ll t,i,j,k;cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n==1)cout<<1<<endl;else if(n==2)cout<<-1<<endl;
        else{
        ll x=n*n;
        if(x%2!=0){
        for(i=1;i<=x;i+=2)cout<<i<<" ";
        for(i=2;i<x;i+=2)cout<<i<<" ";
        }
        else if(x%2==0){
        for(i=1;i<x;i+=2)cout<<i<<" ";
        for(i=2;i<=x;i+=2)cout<<i<<" ";

        }
        }

    }

}

```


### Prompt

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

problem

AOR Ika-chan, who loves feasts, defined "the number of feasts". A feast number is a natural number that includes "$ 51-3 $" in $ 10 $ decimal notation.
$? $ Can be any number from $ 0 $ to $ 9 $.

Find the number of feasts out of the natural numbers below $ N $.

input

$ N $

output

Output the number of feasts in one line. Also, output a line break at the end.

Example

Input

5124

Output

3

### Response

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

string s;
int64 dp[20][2][1000][2] = {};

int64 dfs(int32 k = 0, bool tight = 1, int32 lst = 0, int32 ok = 0){
	if(k == s.size()) return ok;
	int32 lim = (tight ? s[k]+1 : 10);
	int64 &res = dp[k][tight][lst][ok];
	if(~res) return res;
	res = 0;
	REP(i, lim){
		int32 nxt = (lst*10+i)%1000;
		if(!ok && 510 <= lst && lst < 520 && i == 3)
			res += dfs(k+1, tight && i == (lim-1), nxt, 1);
		else
			res += dfs(k+1, tight && i == (lim-1), nxt, ok);
	}
	return res;
}

int main(void){
	cin >> s;
	REP(i, s.size()) s[i] -= '0';
	memset(dp, -1, sizeof dp);
	cout << dfs() << endl;
}

```


### Prompt

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

Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.

Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.

Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.

Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.

Input

The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.

Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1 - num2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.

Output

Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.

Examples

Input

3 2
2 1
2 2

Output

0 0

Input

9 3
1 2 3
2 8
1 4 5

Output

2 3

Input

10 0

Output

5 9

Note

In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round.

The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solv();
int main() { solv(); }
int a[100000];
void solv() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int x;
    cin >> x;
    if (x == 1) {
      int a1, b;
      cin >> a1 >> b;
      a[a1] = 1;
      a[b] = 1;
    } else {
      int x1;
      cin >> x1;
      a[x1] = 1;
    }
  }
  int mx = 0;
  for (int i = 1; i < n; i++) {
    if (!a[i]) mx++;
  }
  int mn = 0;
  for (int i = 1; i < n; i++) {
    if (!a[i] && !a[i + 1]) {
      mn += 1;
      a[i + 1] = 1;
      continue;
    }
    if (!a[i] && a[i + 1]) {
      mn++;
    }
  }
  cout << mn << ' ' << mx;
}

```


### Prompt

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

Little girl Susie went shopping with her mom and she wondered how to improve service quality.

There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.

Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.

Input

The first line contains integer n (1 ≤ n ≤ 105).

The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.

Output

Print a single number — the maximum number of not disappointed people in the queue.

Examples

Input

5
15 2 1 5 3

Output

4

Note

Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int i, t[n];
  for (i = 0; i < n; i++) cin >> t[i];
  sort(t, t + n);
  int cnt = 1;
  int wait = t[0];
  i = 1;
  while (i < n) {
    if (wait <= t[i]) {
      cnt++;
      wait += t[i];
      i++;
    } else
      i++;
  }
  cout << cnt;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are given a problemset consisting of n problems. The difficulty of the i-th problem is a_i. It is guaranteed that all difficulties are distinct and are given in the increasing order.

You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to assemble should be a subset of problems (not necessary consecutive) of the given problemset. There is only one condition that should be satisfied: for each problem but the hardest one (the problem with the maximum difficulty) there should be a problem with the difficulty greater than the difficulty of this problem but not greater than twice the difficulty of this problem. In other words, let a_{i_1}, a_{i_2}, ..., a_{i_p} be the difficulties of the selected problems in increasing order. Then for each j from 1 to p-1 a_{i_{j + 1}} ≤ a_{i_j} ⋅ 2 should hold. It means that the contest consisting of only one problem is always valid.

Among all contests satisfying the condition above you have to assemble one with the maximum number of problems. Your task is to find this number of problems.

Input

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

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — difficulties of the problems. It is guaranteed that difficulties of the problems are distinct and are given in the increasing order.

Output

Print a single integer — maximum number of problems in the contest satisfying the condition in the problem statement.

Examples

Input

10
1 2 5 6 7 10 21 23 24 49

Output

4

Input

5
2 10 50 110 250

Output

1

Input

6
4 7 12 100 150 199

Output

3

Note

Description of the first example: there are 10 valid contests consisting of 1 problem, 10 valid contests consisting of 2 problems ([1, 2], [5, 6], [5, 7], [5, 10], [6, 7], [6, 10], [7, 10], [21, 23], [21, 24], [23, 24]), 5 valid contests consisting of 3 problems ([5, 6, 7], [5, 6, 10], [5, 7, 10], [6, 7, 10], [21, 23, 24]) and a single valid contest consisting of 4 problems ([5, 6, 7, 10]).

In the second example all the valid contests consist of 1 problem.

In the third example are two contests consisting of 3 problems: [4, 7, 12] and [100, 150, 199].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool isPrime[1000005] = {false};
vector<long long> prm;
vector<long long> SPF(1000005);
void sieve() {
  isPrime[1] = isPrime[0] = 0;
  long long i;
  for (i = 2; i < 1000005; ++i) isPrime[i] = 1;
  for (i = 2; i * i < 1000005; ++i) {
    if (isPrime[i]) {
      for (long long j = i * i; j < 1000005; j += i) isPrime[j] = 0;
    }
  }
  if (!prm.empty()) prm.clear();
  for (i = 2; i < 1000005; ++i) {
    if (isPrime[i]) prm.push_back(i);
  }
}
bool flip(bool f) {
  if (f) return 0;
  return 1;
}
long long fastPower(long long a, long long b) {
  if (b == 0) return 1;
  long long prod = 1;
  while (b > 0) {
    if (b & 1) prod = prod * a;
    b = b >> 1;
    a = a * a;
  }
  return prod;
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; i++) {
    res *= i;
  }
  return res;
}
long long nCr(long long n, long long r) {
  return (long double)fact(n) / (long double)(fact(r) * fact(n - r));
}
void printa(bool f) {
  if (f)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
}
long long bs(vector<long long> &a, long long l, long long r, long long x) {
  long long m;
  while (l <= r) {
    m = l - (r + l) / 2;
    if (x * 2 <= a[m])
      return m;
    else
      r = m - 1;
  }
  return -1;
}
void solve() {
  long long n, i;
  cin >> n;
  vector<long long> a(n);
  for (i = 0; i < n; ++i) cin >> a[i];
  long long ans = 0;
  for (i = 0; i < n; ++i) {
    long long j = i;
    while (j + 1 < n && a[j] * 2 >= a[j + 1]) ++j;
    ans = max(ans, j - i + 1);
    i = j;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.

Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.

A sequence a is a subsequence of a sequence b if a can be obtained from b by deletion of several (possibly, zero) elements. For example, [3,1] is a subsequence of [3,2,1] and [4,3,1], but not a subsequence of [1,3,3,7] and [3,10,4].

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 two integers n and m (1≤ n,m≤ 1000) — the lengths of the two arrays.

The second line of each test case contains n integers a_1,…,a_n (1≤ a_i≤ 1000) — the elements of the first array.

The third line of each test case contains m integers b_1,…,b_m (1≤ b_i≤ 1000) — the elements of the second array.

It is guaranteed that the sum of n and the sum of m across all test cases does not exceed 1000 (∑_{i=1}^t n_i, ∑_{i=1}^t m_i≤ 1000).

Output

For each test case, output "YES" if a solution exists, or "NO" otherwise.

If the answer is "YES", on the next line output an integer k (1≤ k≤ 1000) — the length of the array, followed by k integers c_1,…,c_k (1≤ c_i≤ 1000) — the elements of the array.

If there are multiple solutions with the smallest possible k, output any.

Example

Input

5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5

Output

YES
1 4
YES
1 3
NO
YES
1 3
YES
1 2

Note

In the first test case, [4] is a subsequence of [10, 8, 6, 4] and [1, 2, 3, 4, 5]. This array has length 1, it is the smallest possible length of a subsequence of both a and b.

In the third test case, no non-empty subsequences of both [3] and [2] exist, so the answer is "NO".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const int N = 55;
void solve() {
  long long int m, n, count = 0;
  cin >> m >> n;
  long long int mini = min(m, n);
  long long int arr[m], arr2[n], arr3[mini];
  for (int i = 0; i < m; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> arr2[i];
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[i] == arr2[j]) {
        arr3[count] = arr[i];
        count++;
        break;
      }
    }
    if (count > 0) break;
  }
  if (count > 0) {
    cout << "YES" << endl;
    cout << count << " ";
    for (int i = 0; i < count; i++) cout << arr3[i] << " ";
    cout << endl;
  } else
    cout << "NO" << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Given are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353.

* Let us repeat the following operation on the integer k. Operation: if the integer is currently odd, subtract 1 from it and divide it by 2; otherwise, divide it by 2 and add 2^{N-1} to it. How many operations need to be performed until k returns to its original value? (The answer is considered to be 0 if k never returns to its original value.)

Constraints

* 1 \leq N \leq 2\times 10^5
* 0 \leq X < 2^N
* X is given in binary and has exactly N digits. (In case X has less than N digits, it is given with leading zeroes.)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print the sum of the answers to the questions for the integers between 0 and X (inclusive), modulo 998244353.

Examples

Input

3
111

Output

40

Input

6
110101

Output

616

Input

30
001110011011011101010111011100

Output

549320998

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 400000, md = 998244353;
int dp[N + 1], n, n2, p2[N + 1];
bool ok[N + 1];
char s[N], z[N];

void ad(int &x, int y) { if ((x += y) >= md)x -= md; }
void sb(int &x, int y) { if ((x -= y) <  0 )x += md; }

bool fl(int x){
	f(i, x, n)z[i] = z[i - x] ^ 1;
	f(i, 0, n)if (z[i] < s[i])return true;
	else if (z[i] > s[i])return false;
	return true;
}

void go(int x){
	x >>= 1;
	f(i, 0, x){
		if (s[i] == '1')ad(dp[x << 1], p2[x - i - 1]);
		z[i] = s[i];
	}
	if (fl(x))ad(dp[x << 1], 1);
}

int main(){
	scanf("%d%s", &n, s);
	n2 = n << 1;
	p2[0] = 1;
	f(i, 1, n2 + 1)ad(p2[i] = p2[i - 1], p2[i - 1]);
	f(i, 1, n2 + 1)if (n % i && n2 % i == 0)ok[i] = true;
	f(i, 1, n2 + 1)if (ok[i])go(i);
	f(i, 1, n2 + 1)if (ok[i])for (int j = i << 1; j <= n2; j += i)sb(dp[j], dp[i]);
	int an = 0;
	f(i, 1, n2 + 1)if (ok[i])ad(an, (ll)i * dp[i] % md);
	printf("%d\n", an);
}
```


### Prompt

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

In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

Input

The first input line contains 4 integer numbers n, d, m, l (1 ≤ n, d, m, l ≤ 106, l < m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k - 1)m, (k - 1)m + l].

Output

Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.

Examples

Input

2 2 5 3

Output

4

Input

5 4 11 8

Output

20

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, m, l;
  long long int k;
  long long int g;
  fscanf(stdin, "%d%d%d%d", &n, &d, &m, &l);
  for (k = 1, g = 0; k <= n; k++) {
    if (g < ((k - 1) * m)) {
      cout << g;
      return 0;
    } else if (g <= (((k - 1) * m) + l)) {
      g += (((((k - 1) * m) + l) - g) / d) * d;
      while (g <= (((k - 1) * m) + l)) g += d;
    }
  }
  cout << g;
  return 0;
}

```


### Prompt

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

Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.

Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once.

One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.

Input

The first line contains two integers n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≤ di ≤ n) — the numbers of the dirty stairs (in an arbitrary order).

Output

Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO".

Examples

Input

10 5
2 4 8 3 6

Output

NO

Input

10 5
2 4 5 7 9

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int A[3010];
  for (int i = 0; i < m; i++) scanf("%d", &A[i]);
  sort(A, A + m);
  if (A[0] == 1 || A[m - 1] == n) {
    printf("NO\n");
    return 0;
  }
  bool valid = true;
  for (int i = 0; i + 2 < m; i++)
    if (A[i] + 1 == A[i + 1] && A[i + 1] + 1 == A[i + 2]) valid = false;
  if (valid)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

```


### Prompt

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

The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied:

  * ti < ti + 1 for each odd i < n;
  * ti > ti + 1 for each even i < n.

For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, 3) and (2, 5, 3, 2) are not.

Bear Limak has a sequence of positive integers t1, t2, ..., tn. This sequence is not nice now and Limak wants to fix it by a single swap. He is going to choose two indices i < j and swap elements ti and tj in order to get a nice sequence. Count the number of ways to do so. Two ways are considered different if indices of elements chosen for a swap are different.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 150 000) — the length of the sequence.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 150 000) — the initial sequence. It's guaranteed that the given sequence is not nice.

Output

Print the number of ways to swap two elements exactly once in order to get a nice sequence.

Examples

Input

5
2 8 4 7 7

Output

2

Input

4
200 150 100 50

Output

1

Input

10
3 2 1 4 1 4 1 4 1 4

Output

8

Input

9
1 2 3 4 5 6 7 8 9

Output

0

Note

In the first sample, there are two ways to get a nice sequence with one swap:

  1. Swap t2 = 8 with t4 = 7.
  2. Swap t1 = 2 with t5 = 7.

In the second sample, there is only one way — Limak should swap t1 = 200 with t4 = 50.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.1415926535897932384626433832795028841;
bool TST = 0;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
void Show(int *QQ, int N) {
  if (not TST) {
    return;
  }
  for (int x = 0; x < N; x++) {
    cout << QQ[x];
    if (x != N - 1) {
      cout << ',';
    }
  }
  cout << '\n';
}
void ShowLL(long long *QQ, int N) {
  if (not TST) {
    return;
  }
  for (int x = 0; x < N; x++) {
    cout << QQ[x];
    if (x != N - 1) {
      cout << ',';
    }
  }
  cout << '\n';
}
int n, T[150002];
int D[150002];
int EC[150002];
set<pair<int, int> > U;
int RR(int a, int b) {
  if (a >= b) {
    return 0;
  }
  return EC[((b - 1) + 1)] - EC[((a - 1) + 1)];
}
bool BackCheck(int i) {
  if (i == 0) {
    return 1;
  }
  if ((i - 1) % 2 == 1) {
    return D[i - 1] > D[i];
  }
  return D[i - 1] < D[i];
}
bool FrontCheck(int i) {
  if (i == n - 1) {
    return 1;
  }
  if (i % 2 == 1) {
    return D[i] > D[i + 1];
  }
  return D[i] < D[i + 1];
}
bool Errors(int i) { return (not BackCheck(i)) or (not FrontCheck(i)); }
void MARK(int x, int y) {
  int a = min(x, y);
  int b = max(x, y);
  U.insert(pair<int, int>(a, b));
}
bool USED(int x, int y) {
  int a = min(x, y);
  int b = max(x, y);
  if (U.find(pair<int, int>(a, b)) != U.end()) {
    return true;
  }
  return false;
}
int swapCheck(int i) {
  for (int x = 0; x < n; x++) {
    D[x] = T[x];
  }
  int ways = 0;
  for (int x = 0; x < n; x++) {
    if (x == i) {
      continue;
    }
    if (USED(x, i)) {
      continue;
    }
    MARK(x, i);
    swap(D[x], D[i]);
    if (Errors(i) or Errors(x)) {
      swap(D[x], D[i]);
      continue;
    }
    int t1 = min(x, i);
    int t2 = max(x, i);
    int b1 = RR(0, t1 - 1);
    int b2 = RR(t1 + 1, t2 - 1);
    int b3 = RR(t2 + 1, n - 1);
    if (b1 + b2 + b3 > 0) {
      swap(D[x], D[i]);
      continue;
    }
    ways++;
    swap(D[x], D[i]);
  }
  return ways;
}
int main() {
  scanf("%i", &n);
  for (int x = 0; x < n; x++) {
    scanf("%i", &T[x]);
  }
  EC[0] = 0;
  for (int x = 0; x < n; x++) {
    int errors = 0;
    if (x % 2 == 0 and T[x] >= T[x + 1]) {
      errors++;
    }
    if (x % 2 == 1 and T[x] <= T[x + 1]) {
      errors++;
    }
    EC[x + 1] = EC[x] + errors;
  }
  if (EC[n - 1] > 4) {
    printf("0\n");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0 and T[i] >= T[i + 1]) {
      ans += swapCheck(i);
      ans += swapCheck(i + 1);
      i++;
    }
    if (i % 2 == 1 and T[i] <= T[i + 1]) {
      ans += swapCheck(i);
      ans += swapCheck(i + 1);
      i++;
    }
  }
  printf("%i\n", ans);
}

```


### Prompt

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

Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.

Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.

Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".

Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...

In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.

Create a program that converts the integer n input in decimal to decimal and outputs it.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.

The number of datasets does not exceed 2000.

Output

The result of conversion to quaternary number for each input data set is output on one line.

Example

Input

7
4
0
12
10
10000
-1

Output

13
10
0
30
22
2130100

### Response

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

void convert(int x){
    if ( x == 0 ) return;
    convert(x/4); cout << x%4;
}

int main(){
    int n;
    while( cin >> n && n >= 0 ) {
	if ( n == 0 ) cout << 0 << endl;
	else {
	    convert(n); cout << endl;
	}
    }
}
```


### Prompt

Generate a Cpp solution to the following problem:

You are given an array of n integers: a_1, a_2, …, a_n. Your task is to find some non-zero integer d (-10^3 ≤ d ≤ 10^3) such that, after each number in the array is divided by d, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least ⌈n/2⌉). Note that those positive numbers do not need to be an integer (e.g., a 2.5 counts as a positive number). If there are multiple values of d that satisfy the condition, you may print any of them. In case that there is no such d, print a single integer 0.

Recall that ⌈ x ⌉ represents the smallest integer that is not less than x and that zero (0) is neither positive nor negative.

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in the array.

The second line contains n space-separated integers a_1, a_2, …, a_n (-10^3 ≤ a_i ≤ 10^3).

Output

Print one integer d (-10^3 ≤ d ≤ 10^3 and d ≠ 0) that satisfies the given condition. If there are multiple values of d that satisfy the condition, you may print any of them. In case that there is no such d, print a single integer 0.

Examples

Input

5
10 0 -7 2 6

Output

4

Input

7
0 0 1 -1 0 0 2

Output

0

Note

In the first sample, n = 5, so we need at least ⌈5/2⌉ = 3 positive numbers after division. If d = 4, the array after division is [2.5, 0, -1.75, 0.5, 1.5], in which there are 3 positive numbers (namely: 2.5, 0.5, and 1.5).

In the second sample, there is no valid d, so 0 should be printed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, key, pos = 0, negative = 0;
  cin >> t;
  n = t;
  while (t--) {
    cin >> key;
    if (key > 0)
      pos++;
    else if (key < 0)
      negative++;
  }
  if ((n + 1) / 2 <= pos)
    cout << 1 << endl;
  else if ((n + 1) / 2 <= negative)
    cout << -1 << endl;
  else
    cout << 0 << endl;
  return 0;
}

```


### Prompt

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

Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.

The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has a, b, c, a, b and c adjacent tiles, correspondingly.

To better visualize the situation, look at the picture showing a similar hexagon for a = 2, b = 3 and c = 4.

<image>

According to the legend, as the King of Berland obtained the values a, b and c, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?

Input

The first line contains three integers: a, b and c (2 ≤ a, b, c ≤ 1000).

Output

Print a single number — the total number of tiles on the hall floor.

Examples

Input

2 3 4

Output

18

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b, c;
  cin >> a >> b >> c;
  cout << (a * b + b * c + c * a) - (a + b + c) + 1;
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}

```


### Prompt

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

Brave Ponta and his best friend, Brave Gonta, have come to Luida's bar in search of friends to embark on an epic adventure. There are many warriors, monks and wizards in the tavern who are itching to go on an adventure.

Gonta, who is kind-hearted, cared for Ponta and said, "You can choose your friends first."

On the other hand, don't worry about Ponta and Gonta. "No, you can choose first."

We continued to give in to each other, and finally Luida proposed: "Then, I'll divide the n registrants here with this" party division machine "so that the total fighting power of each party is as even as possible."

The task given to you is to create a program that is built into the partying machine.

This program inputs n integers and outputs the minimum difference between the total value of the integers contained in A and the total value of the integers contained in B when they are divided into two groups A and B. Must be.

Thanks to this machine, Ponta and Gonta got along well and went on an epic adventure ...

Input

Multiple datasets are given as input. Each dataset is given in the following format:

n (number of registrants: integer)
a1 a2 ... an (combat power of each registrant: blank-separated integer)

n is 20 or less, and each registrant's combat power does not exceed 1 million.

When n is 0, it is the end of input.

Output

Print the minimum value on one line for each dataset.

Example

Input

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

Output

1
1

### Response

```cpp
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

int n;
int a[25];

int main() {
    while (cin >> n) {
        if (n == 0) break;
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            sum += a[i];
        }
        int res = 1<<29;
        for (int bit = 0; bit < (1<<n); ++bit) {
            int tmp = 0;
            for (int j = 0; j < n; ++j) if (bit & (1<<j)) tmp += a[j];
            chmin(res, abs(sum - tmp*2));
        }
        cout << res << endl;
    }
    return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Find the least common multiple (LCM) of given n integers.

Constraints

* 2 ≤ n ≤ 10
* 1 ≤ ai ≤ 1000
* Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1

Input

n
a1 a2 ... an

n is given in the first line. Then, n integers are given in the second line.

Output

Print the least common multiple of the given integers in a line.

Examples

Input

3
3 4 6

Output

12

Input

4
1 2 3 5

Output

30

### Response

```cpp
#include <iostream>
using namespace std;
long long gcd(long long a, long long b){
  int r = 0;
  while(true){
    /*a = abs(a);
    b = abs(b);*/
    r = a % b;
    a = b;
    b = r;
    if(r == 0){break;}
  }
  return a;
}
long long lcm(long long a, long long b){
  int L = 0;
  int G = gcd(a,b);
  L = a / G * b;
  return L;
}
int main(){
  long long N, Input;
  long long anslcm = 1;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> Input;
    anslcm = lcm(anslcm,Input);
  }
  cout << anslcm << endl;
  return 0;
}

```


### Prompt

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

This is an interactive problem. Refer to the Interaction section below for better understanding.

Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.

<image>

Initially, Ithea puts n clear sheets of paper in a line. They are numbered from 1 to n from left to right.

This game will go on for m rounds. In each round, Ithea will give Chtholly an integer between 1 and c, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one).

Chtholly wins if, at any time, all the sheets are filled with a number and the n numbers are in non-decreasing order looking from left to right from sheet 1 to sheet n, and if after m rounds she still doesn't win, she loses the game.

Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number.

Input

The first line contains 3 integers n, m and c (<image>, <image> means <image> rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.

Interaction

In each round, your program needs to read one line containing a single integer pi (1 ≤ pi ≤ c), indicating the number given to Chtholly.

Your program should then output a line containing an integer between 1 and n, indicating the number of sheet to write down this number in.

After outputting each line, don't forget to flush the output. For example:

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

If Chtholly wins at the end of a round, no more input will become available and your program should terminate normally. It can be shown that under the constraints, it's always possible for Chtholly to win the game.

Example

Input

2 4 4
2
1
3

Output

1
2
2

Note

In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets were filled with a number and they were non-decreasing, so she won the game.

Note that it is required that your program terminate immediately after Chtholly wins and do not read numbers from the input for the remaining rounds. If not, undefined behaviour may arise and it won't be sure whether your program will be accepted or rejected. Also because of this, please be careful when hacking others' codes. In the sample, Chtholly won the game after the 3rd round, so it is required that your program doesn't read the number of the remaining 4th round.

The input format for hacking:

  * The first line contains 3 integers n, m and c;
  * The following m lines each contains an integer between 1 and c, indicating the number given to Chtholly in each round.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c;
  cin >> n >> m >> c;
  int low = 0;
  int up = 0;
  int arr[n + 1];
  while ((low + up) != n) {
    int p;
    cin >> p;
    if (p > c / 2) {
      int t = n;
      while (n - t < up) {
        if (p > arr[t]) {
          cout << t << endl;
          arr[t] = p;
          break;
        }
        t--;
      }
      if (n - t == up) {
        cout << t << endl;
        arr[t] = p;
        up++;
      }
    } else {
      int t = 1;
      while (t < (low + 1)) {
        if (p < arr[t]) {
          cout << t << endl;
          arr[t] = p;
          break;
        }
        t++;
      }
      if (t == (low + 1)) {
        cout << t << endl;
        arr[t] = p;
        low++;
      }
    }
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Suppose you are given a string s of length n consisting of lowercase English letters. You need to compress it using the smallest possible number of coins.

To compress the string, you have to represent s as a concatenation of several non-empty strings: s = t_{1} t_{2} … t_{k}. The i-th of these strings should be encoded with one of the two ways:

  * if |t_{i}| = 1, meaning that the current string consists of a single character, you can encode it paying a coins;
  * if t_{i} is a substring of t_{1} t_{2} … t_{i - 1}, then you can encode it paying b coins.

A string x is a substring of a string y if x can be obtained from y by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

So your task is to calculate the minimum possible number of coins you need to spend in order to compress the given string s.

Input

The first line contains three positive integers, separated by spaces: n, a and b (1 ≤ n, a, b ≤ 5000) — the length of the string, the cost to compress a one-character string and the cost to compress a string that appeared before.

The second line contains a single string s, consisting of n lowercase English letters.

Output

Output a single integer — the smallest possible number of coins you need to spend to compress s.

Examples

Input

3 3 1
aba

Output

7

Input

4 1 1
abcd

Output

4

Input

4 10 1
aaaa

Output

12

Note

In the first sample case, you can set t_{1} = 'a', t_{2} = 'b', t_{3} = 'a' and pay 3 + 3 + 1 = 7 coins, since t_{3} is a substring of t_{1}t_{2}.

In the second sample, you just need to compress every character by itself.

In the third sample, you set t_{1} = t_{2} = 'a', t_{3} = 'aa' and pay 10 + 1 + 1 = 12 coins, since t_{2} is a substring of t_{1} and t_{3} is a substring of t_{1} t_{2}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MN = 5005, LOG = 15, inf = 1000000005, mod = 1000000007;
const long long INF = 1000000000000000005LL;
int dp[MN];
bitset<MN> fajny[MN];
pair<short int, short int> pie[MN][MN];
int kmr[LOG][2 * MN];
char S[MN];
int n;
void licz(int poz) {
  vector<pair<short int, short int> > P;
  for (int i = 1; i <= n; ++i)
    P.push_back({kmr[poz - 1][i], kmr[poz - 1][i + (1 << (poz - 1))]});
  sort((P).begin(), (P).end());
  for (int i = 1; i <= n; ++i) {
    pair<short int, short int> cur = {kmr[poz - 1][i],
                                      kmr[poz - 1][i + (1 << (poz - 1))]};
    kmr[poz][i] = (int)(lower_bound((P).begin(), (P).end(), cur) - P.begin());
  }
}
pair<short int, short int> hasz(int i, int j) {
  int len = j - i + 1;
  int wyk = 31 - __builtin_clz(len);
  int pot = (1 << wyk);
  return {kmr[wyk][i], kmr[wyk][j - pot + 1]};
}
int main() {
  int a, b;
  scanf("%d%d%d", &n, &a, &b);
  scanf("%s", S);
  for (int i = 1; i <= n; ++i) kmr[0][i] = S[i - 1] - 'a';
  for (int i = 1; i < LOG; ++i) licz(i);
  for (int l = 1; l <= n; ++l)
    for (int i = 1; i + l - 1 <= n; ++i) {
      pair<short int, short int> h = hasz(i, i + l - 1);
      if (pie[h.first][h.second].first == l) {
        if (pie[h.first][h.second].second + l - 1 < i) fajny[i][i + l - 1] = 1;
      } else {
        pie[h.first][h.second] = {l, i};
      }
    }
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1] + a;
    for (int j = i; j > 0; --j)
      if (fajny[j][i]) dp[i] = min(dp[i], dp[j - 1] + b);
  }
  printf("%d", dp[n]);
}

```


### Prompt

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

You are given a convex polygon. Count, please, the number of triangles that contain a given point in the plane and their vertices are the vertices of the polygon. It is guaranteed, that the point doesn't lie on the sides and the diagonals of the polygon.

Input

The first line contains integer n — the number of vertices of the polygon (3 ≤ n ≤ 100000). The polygon description is following: n lines containing coordinates of the vertices in clockwise order (integer x and y not greater than 109 by absolute value). It is guaranteed that the given polygon is nondegenerate and convex (no three points lie on the same line).

The next line contains integer t (1 ≤ t ≤ 20) — the number of points which you should count the answer for. It is followed by t lines with coordinates of the points (integer x and y not greater than 109 by absolute value).

Output

The output should contain t integer numbers, each on a separate line, where i-th number is the answer for the i-th point.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Examples

Input

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

Output

2

Input

3
0 0
0 5
5 0
2
1 1
10 10

Output

1
0

Input

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

Output

5
3
3
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long cross(pair<int, int> a, pair<int, int> b) {
  return 1LL * a.first * b.second - 1LL * a.second * b.first;
}
long long ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
  pair<int, int> p = pair<int, int>(b.first - a.first, b.second - a.second);
  pair<int, int> q = pair<int, int>(c.first - a.first, c.second - a.second);
  return cross(p, q);
}
int N, Q;
pair<int, int> P[100010];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &P[i].first, &P[i].second);
  }
  scanf("%d", &Q);
  for (int q = 0; q < Q; q++) {
    int x, y;
    scanf("%d %d", &x, &y);
    bool out = false;
    for (int i = 0; i < N; i++) {
      int j = (i + 1) % N;
      if (ccw(pair<int, int>(x, y), P[i], P[j]) >= 0) {
        out = true;
        break;
      }
    }
    if (out) {
      printf("0\n");
      continue;
    }
    long long ans = 1LL * N * (N - 1) * (N - 2) / 6;
    int pos = 0;
    for (int i = 0; i < N; i++) {
      while (ccw(P[i], P[pos], pair<int, int>(x, y)) <= 0) pos = (pos + 1) % N;
      int n = (pos - i + N) % N - 1;
      ans -= 1LL * n * (n - 1) / 2;
    }
    printf("%lld\n", ans);
  }
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.

Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.

The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.

Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?

Constraints

* 2≦N≦300
* 1≦M≦300

Input

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

N M

Output

Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).

Examples

Input

3 3

Output

2

Input

150 300

Output

734286322

Input

300 150

Output

0

### Response

```cpp
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int dp[2][333][333],ans,n,m;
int mod=1000000007;

signed main(){
  cin>>n>>m;
  dp[0][1][1]=1;
  for(int i=0;i<m;i++){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=n;k++){
        dp[(i+1)%2][j+1][k]+=dp[i%2][j][k]*(n-j);
        dp[(i+1)%2][j][j]+=dp[i%2][j][k]*k;
        dp[(i+1)%2][j][k]+=dp[i%2][j][k]*(j-k);

        dp[(i+1)%2][j+1][k]%=mod;
        dp[(i+1)%2][j][j]%=mod;
        dp[(i+1)%2][j][k]%=mod;
      }
    }
    r(k,333)r(j,333)dp[i%2][k][j]=0;
  }
  cout<<dp[m%2][n][n]<<endl;
}
```


### Prompt

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

You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).

Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≤ x1 ≤ x ≤ x2 ≤ n, 0 ≤ y1 ≤ y ≤ y2 ≤ m, <image>.

The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers.

<image>

If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one.

Input

The first line contains six integers n, m, x, y, a, b (1 ≤ n, m ≤ 109, 0 ≤ x ≤ n, 0 ≤ y ≤ m, 1 ≤ a ≤ n, 1 ≤ b ≤ m).

Output

Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2).

Examples

Input

9 9 5 5 2 1

Output

1 3 9 7

Input

100 100 52 50 46 56

Output

17 8 86 92

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a, b, k;
pair<int, int> ll, ur, o;
int gcd(int a, int b) {
  while (b != 0) {
    int tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}
int main() {
  cin >> n >> m >> x >> y >> a >> b;
  int g = gcd(a, b);
  a /= g;
  b /= g;
  k = min(n / a, m / b);
  ll.first = ll.second = 0;
  ur.first = a * k;
  ur.second = b * k;
  o.first = (ur.first + 1) / 2;
  o.second = (ur.second + 1) / 2;
  if (x >= o.first) {
    if (n - a * k + o.first < x) {
      ll.first = n - a * k;
      ur.first = n;
    } else {
      ll.first += x - o.first;
      ur.first += x - o.first;
    }
  }
  if (y >= o.second) {
    if (m - b * k + o.second < y) {
      ll.second = m - b * k;
      ur.second = m;
    } else {
      ll.second += y - o.second;
      ur.second += y - o.second;
    }
  }
  printf("%d %d %d %d\n", ll.first, ll.second, ur.first, ur.second);
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are given two positive integers a and b.

In one move, you can change a in the following way:

  * Choose any positive odd integer x (x > 0) and replace a with a+x;
  * choose any positive even integer y (y > 0) and replace a with a-y.

You can perform as many such operations as you want. You can choose the same numbers x and y in different moves.

Your task is to find the minimum number of moves required to obtain b from a. It is guaranteed that you can always obtain b from a.

You have to answer t independent test cases.

Input

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

Then t test cases follow. Each test case is given as two space-separated integers a and b (1 ≤ a, b ≤ 10^9).

Output

For each test case, print the answer — the minimum number of moves required to obtain b from a if you can perform any number of moves described in the problem statement. It is guaranteed that you can always obtain b from a.

Example

Input

5
2 3
10 10
2 4
7 4
9 3

Output

1
0
2
2
1

Note

In the first test case, you can just add 1.

In the second test case, you don't need to do anything.

In the third test case, you can add 1 two times.

In the fourth test case, you can subtract 4 and add 1.

In the fifth test case, you can just subtract 6.

### Response

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

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time independently). You can place tile in the grid at any position, the only condition is that tiles (and tile parts) should not overlap. Your goal is to proceed all given figures and avoid crossing at any time.

Input

The only line contains a string s consisting of zeroes and ones (1 ≤ |s| ≤ 1000). Zero describes vertical tile, one describes horizontal tile.

Output

Output |s| lines — for each tile you should output two positive integers r,c, not exceeding 4, representing numbers of smallest row and column intersecting with it.

If there exist multiple solutions, print any of them.

Example

Input

010

Output

1 1
1 2
1 4

Note

Following image illustrates the example after placing all three tiles:

<image> Then the first row is deleted:  <image>

### Response

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

```


### Prompt

Develop a solution in Cpp to the problem described below:

Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.

Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive.

Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.

You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages.

The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message.

The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message.

It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106.

Output

Print the maximum number of files the intercepted array could consist of.

Examples

Input

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

Output

3

Input

3 3
1 10 100
1 100 10

Output

2

Input

1 4
4
1 1 1 1

Output

1

Note

In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8.

In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100.

In the third example the only possibility is that the archive contains a single file of size 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ar[1000000], br[100000];
int main() {
  int cnt = 0, m, n, sum = 0, sum1 = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = 0; i < m; i++) cin >> br[i];
  int i = 0, j = 0;
  while (i < n && j < m) {
    if (sum == sum1) {
      cnt++;
      sum = ar[i++];
      sum1 = br[j++];
    } else if (sum > sum1) {
      sum1 += br[j++];
    } else
      sum += ar[i++];
  }
  cout << cnt << endl;
  return 0;
}

```


### Prompt

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

In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. Team BowWow has arrived at the station at the time s and it is trying to count how many trains have they missed; in other words, the number of trains that have departed strictly before time s. For example if s = 20, then they missed trains which have departed at 1, 4 and 16. As you are the only one who knows the time, help them!

Note that the number s will be given you in a [binary representation](https://en.wikipedia.org/wiki/Binary_number#Representation) without leading zeroes.

Input

The first line contains a single binary number s (0 ≤ s < 2^{100}) without leading zeroes.

Output

Output a single number — the number of trains which have departed strictly before the time s.

Examples

Input

100000000

Output

4

Input

101

Output

2

Input

10100

Output

3

Note

In the first example 100000000_2 = 256_{10}, missed trains have departed at 1, 4, 16 and 64.

In the second example 101_2 = 5_{10}, trains have departed at 1 and 4.

The third example is explained in the statements.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int M = 1e9 + 7;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int o = 0;
  if (s == "0") return cout << 0, 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') o++;
  }
  int k = int(s.size()) - 1;
  int ans = k / 2;
  if (o != 1 || k & 1) ans++;
  cout << ans;
}

```


### Prompt

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

You are given an array a of n integers, where n is odd. You can make the following operation with it:

  * Choose one of the elements of the array (for example a_i) and increase it by 1 (that is, replace it with a_i + 1).

You want to make the median of the array the largest possible using at most k operations.

The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array [1, 5, 2, 3, 5] is 3.

Input

The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n is odd, 1 ≤ k ≤ 10^9) — the number of elements in the array and the largest number of operations you can make.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9).

Output

Print a single integer — the maximum possible median after the operations.

Examples

Input

3 2
1 3 5

Output

5

Input

5 5
1 2 1 1 1

Output

3

Input

7 7
4 1 2 4 3 4 4

Output

5

Note

In the first example, you can increase the second element twice. Than array will be [1, 5, 5] and it's median is 5.

In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is 3.

In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be [5, 1, 2, 5, 3, 5, 5] and the median will be 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200003;
const long long INF = 1000000000000ll;
int n;
long long k, a[maxn];
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", a + i);
  sort(a + 1, a + n + 1);
  a[n + 1] = INF;
  int i = n / 2 + 1, j = i;
  long long cnt = 0, ans = a[i];
  while (1) {
    for (; j <= n && a[i] == a[j]; j++)
      ;
    if (cnt + (j - n / 2 - 1) * (a[j] - a[i]) > k) break;
    cnt += (j - n / 2 - 1) * (a[j] - a[i]);
    ans = a[j];
    i = j;
  }
  ans += (k - cnt) / (j - n / 2 - 1);
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.

Input

The first line contains two integers x1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot.

The second line contains two integers x2, y2 ( - 109 ≤ x2, y2 ≤ 109) — the finish position of the robot.

Output

Print the only integer d — the minimal number of steps to get the finish position.

Examples

Input

0 0
4 5

Output

5

Input

3 4
6 1

Output

3

Note

In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.

In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x1, y1, x2, y2, ans;
  cin >> x1 >> y1 >> x2 >> y2;
  long long int minm = min(abs(x2 - x1), abs(y2 - y1));
  if (minm == abs(x2 - x1))
    ans = max(y1, y2) - min(y1, y2);
  else
    ans = max(x1, x2) - min(x1, x2);
  cout << ans;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes.

Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clothes to wear on each of the days she will be absent. Arseniy's family is a bit weird so all the clothes is enumerated. For example, each of Arseniy's n socks is assigned a unique integer from 1 to n. Thus, the only thing his mother had to do was to write down two integers li and ri for each of the days — the indices of socks to wear on the day i (obviously, li stands for the left foot and ri for the right). Each sock is painted in one of k colors.

When mother already left Arseniy noticed that according to instruction he would wear the socks of different colors on some days. Of course, that is a terrible mistake cause by a rush. Arseniy is a smart boy, and, by some magical coincidence, he posses k jars with the paint — one for each of k colors.

Arseniy wants to repaint some of the socks in such a way, that for each of m days he can follow the mother's instructions and wear the socks of the same color. As he is going to be very busy these days he will have no time to change the colors of any socks so he has to finalize the colors now.

The new computer game Bota-3 was just realised and Arseniy can't wait to play it. What is the minimum number of socks that need their color to be changed in order to make it possible to follow mother's instructions and wear the socks of the same color during each of m days.

Input

The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively.

The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks.

Each of the following m lines contains two integers li and ri (1 ≤ li, ri ≤ n, li ≠ ri) — indices of socks which Arseniy should wear during the i-th day.

Output

Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors.

Examples

Input

3 2 3
1 2 3
1 2
2 3

Output

2

Input

3 2 2
1 1 2
1 2
2 1

Output

0

Note

In the first sample, Arseniy can repaint the first and the third socks to the second color.

In the second sample, there is no need to change any colors.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const long long oo = 9e18;
template <typename T>
bool umn(T &a, T b) {
  return (a > b ? (a = b, 1) : 0);
}
template <typename T>
bool umx(T &a, T b) {
  return (a < b ? (a = b, 1) : 0);
}
long long p[2 * N], sz[2 * N];
vector<long long> g[2 * N];
long long find_set(long long v) {
  if (p[v] == v)
    return v;
  else
    return p[v] = find_set(p[v]);
}
void unite_sets(long long a, long long b) {
  a = find_set(a);
  b = find_set(b);
  if (sz[a] < sz[b]) swap(a, b);
  sz[a] += sz[b];
  p[b] = a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < 2 * N; i++) {
    sz[i] = 1;
    p[i] = i;
  }
  vector<long long> a(n);
  for (auto &now : a) cin >> now;
  for (int i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    unite_sets(l, r);
  }
  set<long long> s;
  for (int i = 1; i <= n; i++) {
    g[find_set(i)].push_back(i);
    s.insert(find_set(i));
  }
  long long ans = 0;
  for (auto now : s) {
    map<long long, long long> mapa;
    for (auto now2 : g[now]) {
      mapa[a[now2 - 1]]++;
    }
    long long maxi = 0, sum = 0;
    for (auto now : mapa) {
      sum += now.second;
      umx(maxi, now.second);
    }
    ans += sum - maxi;
  }
  cout << ans;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You're given the centers of three equal sides of a strictly convex tetragon. Your task is to restore the initial tetragon.

Input

The first input line contains one number T — amount of tests (1 ≤ T ≤ 5·104). Each of the following T lines contains numbers x1, y1, x2, y2, x3, y3 — coordinates of different points that are the centers of three equal sides (non-negative integer numbers, not exceeding 10).

Output

For each test output two lines. If the required tetragon exists, output in the first line YES, in the second line — four pairs of numbers — coordinates of the polygon's vertices in clockwise or counter-clockwise order. Don't forget, please, that the tetragon should be strictly convex, i.e. no 3 of its points lie on one line. Output numbers with 9 characters after a decimal point.

If the required tetragon doen't exist, output NO in the first line, and leave the second line empty.

Examples

Input

3
1 1 2 2 3 3
0 1 1 0 2 2
9 3 7 9 9 8

Output

NO

YES
3.5 1.5 0.5 2.5 -0.5 -0.5 2.5 0.5
NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int Get() {
  char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  int X = c - 48;
  while (c = getchar(), c >= '0' && c <= '9') X = X * 10 + c - 48;
  return X;
}
double Cross(double Xa, double Ya, double Xb, double Yb, double Xc, double Yc) {
  return (Xa * Yb + Xb * Yc + Xc * Ya) - (Xb * Ya + Xc * Yb + Xa * Yc);
}
bool Check(int Xa, int Ya, int Xb, int Yb, int Xc, int Yc) {
  double A0 = 2 * (Xa - Xb), B0 = 2 * (Ya - Yb);
  double C0 = Xb * Xb - Xa * Xa + Yb * Yb - Ya * Ya;
  double A1 = 2 * (Xb - Xc), B1 = 2 * (Yb - Yc);
  double C1 =
      -3 * (Xb * Xb + Yb * Yb) - (Xc * Xc + Yc * Yc) + 4 * (Xb * Xc + Yb * Yc);
  double Xp = (C1 * B0 - C0 * B1) / (A0 * B1 - A1 * B0);
  double Yp = (A1 * C0 - A0 * C1) / (A0 * B1 - A1 * B0);
  double Xq = 2 * Xb - Xp, Yq = 2 * Yb - Yp;
  double _Xp = 2 * Xa - Xp, _Yp = 2 * Ya - Yp;
  double _Xq = 2 * Xc - Xq, _Yq = 2 * Yc - Yq;
  double a = Cross(_Xp, _Yp, Xp, Yp, Xq, Yq);
  double b = Cross(Xp, Yp, Xq, Yq, _Xq, _Yq);
  double c = Cross(Xq, Yq, _Xq, _Yq, _Xp, _Yp);
  double d = Cross(_Xq, _Yq, _Xp, _Yp, Xp, Yp);
  if ((a < 0 && b < 0 && c < 0 && d < 0) ||
      (a > 0 && b > 0 && c > 0 && d > 0)) {
    printf("YES\n");
    printf("%0.10lf %0.10lf ", Xp, Yp);
    printf("%0.10lf %0.10lf ", Xq, Yq);
    printf("%0.10lf %0.10lf ", _Xq, _Yq);
    printf("%0.10lf %0.10lf\n", _Xp, _Yp);
    return true;
  }
  return false;
}
void Work(int Xa, int Ya, int Xb, int Yb, int Xc, int Yc) {
  if (Cross(Xa, Ya, Xb, Yb, Xc, Yc)) {
    if (Check(Xa, Ya, Xb, Yb, Xc, Yc)) return;
    if (Check(Xb, Yb, Xc, Yc, Xa, Ya)) return;
    if (Check(Xc, Yc, Xa, Ya, Xb, Yb)) return;
  }
  printf("NO\n\n");
}
int main() {
  int Test = Get();
  while (Test--) {
    int Xa = Get(), Ya = Get();
    int Xb = Get(), Yb = Get();
    int Xc = Get(), Yc = Get();
    Work(Xa, Ya, Xb, Yb, Xc, Yc);
  }
  return 0;
}

```


### Prompt

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

Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set of words, and word is a sequence of lowercase Latin letters.

Peterson makes new language every morning. It is difficult task to store the whole language, so Peterson have invented new data structure for storing his languages which is called broom. Broom is rooted tree with edges marked with letters. Initially broom is represented by the only vertex — the root of the broom. When Peterson wants to add new word to the language he stands at the root and processes the letters of new word one by one. Consider that Peterson stands at the vertex u. If there is an edge from u marked with current letter, Peterson goes through this edge. Otherwise Peterson adds new edge from u to the new vertex v, marks it with the current letter and goes through the new edge. Size of broom is the number of vertices in it.

In the evening after working day Peterson can't understand the language he made this morning. It is too difficult for bored Peterson and he tries to make it simpler. Simplification of the language is the process of erasing some letters from some words of this language. Formally, Peterson takes some positive integer p and erases p-th letter from all the words of this language having length at least p. Letters in words are indexed starting by 1. Peterson considers that simplification should change at least one word, i.e. there has to be at least one word of length at least p. Peterson tries to make his language as simple as possible, so he wants to choose p such that the size of the broom for his simplified language is as small as possible.

Peterson is pretty annoyed with this task so he asks you for help. Write a program to find the smallest possible size of the broom and integer p.

Input

The first line of input contains integer n (2 ≤ n ≤ 3·105) — the size of the broom.

Next n - 1 lines describe the broom: i-th of them contains integers ui, vi and letter xi — describing the edge from ui to vi marked with letter xi.

Vertices are numbered from 1 to n. All xi are lowercase latin letters. Vertex 1 is the root of the broom.

Edges describe correct broom which is made from Peterson's language.

Output

The first line of output should contain the minimum possible size of the broom after its simplification. The second line of output should contain integer p to choose. If there are several suitable p values, print the smallest one.

Examples

Input

5
1 2 c
2 3 a
3 4 t
2 5 t

Output

3
2

Input

16
1 2 o
2 3 f
1 4 p
4 5 i
5 6 e
6 7 c
7 8 e
4 9 r
9 10 e
10 11 t
11 12 t
12 13 y
10 14 f
14 15 i
15 16 x

Output

12
2

Note

<image>

Broom from the second sample test can be built using language "piece", "of", "pie", "pretty", "prefix". Its simplification with p = 2 obtains the language of words "pece", "o", "pe", "petty", "pefix". This language gives us the broom with minimum possible size.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int md = 0;
int ans[maxn];
int g[maxn][26];
int merge(const vector<int>& a) {
  int res = (int)(a).size() - 1;
  vector<int> b;
  for (int i = 0; i < 26; i++) {
    b.clear();
    for (auto u : a) {
      if (g[u][i]) {
        b.emplace_back(g[u][i]);
      }
    }
    if ((int)(b).size() > 1) res += merge(b);
  }
  return res;
}
void dfs(int v, int d = 1) {
  vector<int> tmp;
  md = max(md, d);
  for (int i = 0; i < 26; i++) {
    if (g[v][i] == 0) continue;
    tmp.emplace_back(g[v][i]);
  }
  int res = merge(tmp) + 1;
  ans[d] += res;
  for (int i = 0; i < 26; i++) {
    if (g[v][i] == 0) continue;
    dfs(g[v][i], d + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    char ch;
    cin >> u >> v >> ch;
    g[u][ch - 'a'] = v;
  }
  dfs(1);
  int p = 1;
  for (int i = 1; i <= md; ++i) {
    if (ans[p] < ans[i]) {
      p = i;
    }
  }
  cout << n - ans[p] << "\n" << p << "\n";
  return 0;
}

```