### Prompt

Generate a CPP solution to the following problem:

problem

There are the following games.

N characters are lined up in a vertical row. The color of these characters is red, blue, or yellow, and in the initial state, four or more characters of the same color are not lined up in a row. The player can select a character at a certain position and change it to another color. By this operation, if four or more characters of the same color are lined up in a row, those characters will disappear. When four or more characters of the same color are lined up in a row due to the disappearance of the characters, those characters also disappear, and this chain continues until there are no more places where four or more characters of the same color are lined up in a row. .. The purpose of this game is to reduce the number of characters remaining without disappearing.

For example, if the color of the sixth character from the top is changed from yellow to blue in the state at the left end of the figure below, five blue characters will disappear in a row, and finally three characters will remain without disappearing.

<image>

Given the color sequence of N characters in the initial state, create a program that finds the minimum value M of the number of characters that remain without disappearing when the color of the character is changed in only one place.

input

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

The first line consists of only the number of characters N (1 ≤ N ≤ 10000). The following N lines contain one of 1, 2, and 3 integers, and the i + 1st line (1 ≤ i ≤ N) represents the color of the i-th character from the top in the initial state (1). Is red, 2 is blue, and 3 is yellow).

When N is 0, it indicates the end of input. The number of datasets does not exceed 5.

output

For each dataset, output the minimum value M of the number of characters remaining without disappearing on one line.

Examples

Input

12
3
2
1
1
2
3
2
2
2
1
1
3
12
3
2
1
1
2
3
2
1
3
2
1
3
0

Output

3
12

Input

None

Output

None

### Response

```cpp
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,chr[10000];
int go(int p,int dir){
    int cr=chr[p];
    while(chr[p]==cr){
        if(dir==-1&&p<0)break;
        if(dir==1&&p>=n)break;
        p+=dir;
    }
    return p;
}
int del(int sp){
    int u=sp,d=sp;
    while(chr[u]==chr[d]){
        int _u=go(u,-1),_d=go(d,1);
        int dif=u-_u+(_d-d);
        if(u==d)dif--;
        if(dif<4)break;
        u=_u;d=_d;
        if(u<0||d>=n)break;
    }
    int ans=u+1+(n-d);
    if(d==u)ans--;
    return ans;

}
int main(){
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>chr[i];
        int Min=10000;

        for(int i=0;i<n;i++){
            for(int j=1;j<=3;j++){
                if(chr[i]==j)continue;
                int k=chr[i];
                chr[i]=j;
                Min=min(Min,del(i));
                chr[i]=k;
            }
        }
        cout<<Min<<endl;
    }
}
```


### Prompt

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

Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.

Constraints

* 1 ≤ a,b,c ≤ 100
* 1 ≤ d ≤ 100
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

a b c d

Output

If A and C can communicate, print `Yes`; if they cannot, print `No`.

Examples

Input

4 7 9 3

Output

Yes

Input

100 10 1 2

Output

No

Input

10 10 10 1

Output

Yes

Input

1 100 2 10

Output

Yes

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((fabs(a-b)<=d && fabs(b-c)<=d)||fabs(a-c)<=d)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}
```


### Prompt

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

Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.

A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.

When a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.

At the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.

In the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i. For Kizahashi, write a program that determines whether each of the N players survived this game.

Constraints

* All values in input are integers.
* 2 \leq N \leq 10^5
* 1 \leq K \leq 10^9
* 1 \leq Q \leq 10^5
* 1 \leq A_i \leq N\ (1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:

N K Q
A_1
A_2
.
.
.
A_Q

Output

Print N lines. The i-th line should contain `Yes` if Player i survived the game, and `No` otherwise.

Examples

Input

6 3 4
3
1
3
2

Output

No
No
Yes
No
No
No

Input

6 5 4
3
1
3
2

Output

Yes
Yes
Yes
Yes
Yes
Yes

Input

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

Output

No
No
No
No
Yes
No
No
No
Yes
No

### Response

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

int main()
{
	int N,K,Q;
	cin >> N >> K >> Q;
	vector<int> v(N);
	rep(i,Q){
		int n;
		cin >> n;
		v[n-1]++;
	}
	rep(i,N){
		if(Q-v[i]>=K)cout <<"No"<<endl;
		else cout << "Yes" <<endl;
	}
}
```


### Prompt

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

The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any direction takes the same time.

All residents of Berland are very lazy people, and so when they want to get from city v to city u, they always choose one of the shortest paths (no matter which one).

The Berland government wants to make this country's road network safer. For that, it is going to put a police station in one city. The police station has a rather strange property: when a citizen of Berland is driving along the road with a police station at one end of it, the citizen drives more carefully, so all such roads are considered safe. The roads, both ends of which differ from the city with the police station, are dangerous.

Now the government wonders where to put the police station so that the average number of safe roads for all the shortest paths from the cultural capital to the main capital would take the maximum value.

Input

The first input line contains two integers n and m (2 ≤ n ≤ 100, <image>) — the number of cities and the number of roads in Berland, correspondingly. Next m lines contain pairs of integers vi, ui (1 ≤ vi, ui ≤ n, vi ≠ ui) — the numbers of cities that are connected by the i-th road. The numbers on a line are separated by a space.

It is guaranteed that each pair of cities is connected with no more than one road and that it is possible to get from any city to any other one along Berland roads.

Output

Print the maximum possible value of the average number of safe roads among all shortest paths from the culture capital to the main one. The answer will be considered valid if its absolute or relative inaccuracy does not exceed 10 - 6.

Examples

Input

4 4
1 2
2 4
1 3
3 4

Output

1.000000000000

Input

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

Output

1.714285714286

Note

In the first sample you can put a police station in one of the capitals, then each path will have exactly one safe road. If we place the station not in the capital, then the average number of safe roads will also make <image>.

In the second sample we can obtain the maximum sought value if we put the station in city 4, then 6 paths will have 2 safe roads each, and one path will have 0 safe roads, so the answer will equal <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> g[110];
long long disfrom1[110], disfromn[110];
long long totpath[110], totpathn[110];
bool used[110];
void bfs1() {
  queue<long long> q;
  used[1] = 1;
  q.push(1);
  totpath[1] = 1;
  while (!q.empty()) {
    long long k = q.front();
    q.pop();
    for (int i = 0; i < g[k].size(); i++) {
      long long to = g[k][i];
      if (!used[to]) {
        used[to] = 1;
        q.push(to);
        disfrom1[to] = disfrom1[k] + 1;
      }
      if (disfrom1[to] == disfrom1[k] + 1) {
        totpath[to] += totpath[k];
      }
    }
  }
}
void bfsn() {
  queue<long long> q;
  q.push(n);
  used[n] = 1;
  totpathn[n] = 1;
  while (!q.empty()) {
    long long k = q.front();
    q.pop();
    for (int i = 0; i < g[k].size(); i++) {
      long long to = g[k][i];
      if (!used[to]) {
        used[to] = 1;
        q.push(to);
        disfromn[to] = disfromn[k] + 1;
      }
      if (disfromn[to] == disfromn[k] + 1) {
        totpathn[to] += totpathn[k];
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  bfs1();
  memset(used, 0, sizeof used);
  bfsn();
  long long tt = totpath[n];
  double sol = 1;
  for (int i = 1; i <= n; i++) {
    long long tn1 = 0;
    long long tnn = 0;
    long long mm1 = disfrom1[n] + 10;
    long long mmn = disfromn[1] + 10;
    for (int j = 0; j < g[i].size(); j++) {
      long long to = g[i][j];
      mm1 = min(mm1, disfrom1[to]);
      mmn = min(mmn, disfromn[to]);
    }
    if (mm1 + mmn + 2 == disfrom1[n]) {
      for (int j = 0; j < g[i].size(); j++) {
        long long to = g[i][j];
        if (disfrom1[to] == mm1) {
          tn1 += totpath[to];
        } else if (disfromn[to] == mmn) {
          tnn += totpathn[to];
        }
      }
      long long tp = tn1 * tnn;
      sol = max(sol, (tp * 2.0) / tt);
    }
  }
  cout << setprecision(8) << fixed;
  cout << sol << endl;
  return 0;
}

```


### Prompt

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

Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.

If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:

  1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
  2. Right after that he starts to type it.
  3. Exactly t milliseconds after he ends typing all the text, the site receives information about it.

The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.

Given the length of the text and the information about participants, determine the result of the game.

Input

The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.

Output

If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".

Examples

Input

5 1 2 1 2

Output

First

Input

3 3 1 1 1

Output

Second

Input

4 5 3 1 5

Output

Friendship

Note

In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.

In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.

In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int Maxn3 = 1e3 + 10;
const long long int Maxn4 = 1e4 + 10;
const long long int Maxn5 = 1e5 + 10;
const long long int Maxn6 = 1e6 + 10;
const long long int Maxn7 = 1e7 + 10;
const long long int Maxn8 = 1e8 + 10;
const long long int Maxn9 = 1e9 + 10;
const long long int Maxn18 = 1e18 + 10;
const long long int Mod1 = 1e7 + 7;
const long long int Mod2 = 1e9 + 7;
const long long int LLMax = LLONG_MAX;
const long long int LLMin = LLONG_MIN;
const long long int INTMax = INT_MAX;
const long long int INTMin = INT_MIN;
long long int mn = LLMax, mx = LLMin;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int s, v1, v2, t1, t2;
  cin >> s >> v1 >> v2 >> t1 >> t2;
  int a = s * v1 + 2 * t1;
  int b = s * v2 + 2 * t2;
  if (a < b)
    cout << "First\n";
  else if (a > b)
    cout << "Second\n";
  else
    cout << "Friendship\n";
}

```


### Prompt

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

Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.

Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).

Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?

Please help Kolya answer this question.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 109) — Kolya's initial game-coin score.

Output

Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).

Examples

Input

1359257

Output

YES

Input

17851817

Output

NO

Note

In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int GCDFast(int a, int b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
int dx[8] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int GCD(int b, int a) {
  if (a == 0) return b;
  return GCD(a, b % a);
}
long long getLcm(long long a, long long b) {
  long long c = a / gcd(a, b);
  return b * c;
}
bool mysort(int a, int b) {
  if (a > b) return true;
  return false;
}
long long data[100005], length;
void binary(int index, string str) {
  if (length == index) {
    cout << str << "\n";
    for (int i = 0; i < length; i++) {
      if (str[i] == '1') cout << data[i];
    }
    cout << "\n";
    return;
  }
  binary(index + 1, str + '0');
  binary(index + 1, str + '1');
}
int main() {
  long long n, i, j, k, result = 0, temp, m;
  long long x, y, z, sum, test_case, ans, len;
  string name;
  bool check;
  while (cin >> n) {
    check = false;
    for (i = 0; i <= n && !check; i += 1234567) {
      for (j = 0; j <= n; j += 123456) {
        x = n - i - j;
        if (x >= 0 && x % 1234 == 0)
          check = true;
        else if (x < 0)
          break;
      }
    }
    if (check)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Polycarpus got hold of a family tree. The found tree describes the family relations of n people, numbered from 1 to n. Every person in this tree has at most one direct ancestor. Also, each person in the tree has a name, the names are not necessarily unique.

We call the man with a number a a 1-ancestor of the man with a number b, if the man with a number a is a direct ancestor of the man with a number b.

We call the man with a number a a k-ancestor (k > 1) of the man with a number b, if the man with a number b has a 1-ancestor, and the man with a number a is a (k - 1)-ancestor of the 1-ancestor of the man with a number b.

In the tree the family ties do not form cycles. In other words there isn't a person who is his own direct or indirect ancestor (that is, who is an x-ancestor of himself, for some x, x > 0).

We call a man with a number a the k-son of the man with a number b, if the man with a number b is a k-ancestor of the man with a number a.

Polycarpus is very much interested in how many sons and which sons each person has. He took a piece of paper and wrote m pairs of numbers vi, ki. Help him to learn for each pair vi, ki the number of distinct names among all names of the ki-sons of the man with number vi.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 105) — the number of people in the tree. Next n lines contain the description of people in the tree. The i-th line contains space-separated string si and integer ri (0 ≤ ri ≤ n), where si is the name of the man with a number i, and ri is either the number of the direct ancestor of the man with a number i or 0, if the man with a number i has no direct ancestor.

The next line contains a single integer m (1 ≤ m ≤ 105) — the number of Polycarpus's records. Next m lines contain space-separated pairs of integers. The i-th line contains integers vi, ki (1 ≤ vi, ki ≤ n).

It is guaranteed that the family relationships do not form cycles. The names of all people are non-empty strings, consisting of no more than 20 lowercase English letters.

Output

Print m whitespace-separated integers — the answers to Polycarpus's records. Print the answers to the records in the order, in which the records occur in the input.

Examples

Input

6
pasha 0
gerald 1
gerald 1
valera 2
igor 3
olesya 1
5
1 1
1 2
1 3
3 1
6 1

Output

2
2
0
1
0

Input

6
valera 0
valera 1
valera 1
gerald 0
valera 4
kolya 4
7
1 1
1 2
2 1
2 2
4 1
5 1
6 1

Output

1
0
0
0
2
0
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010];
vector<pair<int, int> > point[100010];
map<pair<int, int>, int> vis;
int n, v, k, depth[100010], pos[100010][2], tot;
char s[100010][23];
void Dfs(int k, int d) {
  pos[k][0] = ++tot;
  point[d].push_back(make_pair(tot, k));
  depth[k] = d;
  for (vector<int>::iterator p = adj[k].begin(); p != adj[k].end(); ++p) {
    Dfs(*p, d + 1);
  }
  pos[k][1] = ++tot;
}
int solve() {
  if (vis[make_pair(v, k)]) return vis[make_pair(v, k)] - 1;
  vector<pair<int, int> >::iterator l, r;
  set<string> str;
  l = lower_bound(point[depth[v] + k].begin(), point[depth[v] + k].end(),
                  make_pair(pos[v][0], 100010));
  r = lower_bound(point[depth[v] + k].begin(), point[depth[v] + k].end(),
                  make_pair(pos[v][1], 0));
  for (vector<pair<int, int> >::iterator p = l; p != r; ++p) {
    str.insert(s[(*p).second]);
  }
  return (vis[make_pair(v, k)] = str.size() + 1) - 1;
}
int main() {
  int p, m, i;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%s%d", &s[i], &p);
    adj[p].push_back(i);
  }
  Dfs(0, 0);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &v, &k);
    printf("%d\n", solve());
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations:

  * multiply the current number by 2 (that is, replace the number x by 2·x);
  * append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1).

You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.

Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.

Input

The first line contains two positive integers a and b (1 ≤ a < b ≤ 109) — the number which Vasily has and the number he wants to have.

Output

If there is no way to get b from a, print "NO" (without quotes).

Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer k — the length of the transformation sequence. On the third line print the sequence of transformations x1, x2, ..., xk, where:

  * x1 should be equal to a,
  * xk should be equal to b,
  * xi should be obtained from xi - 1 using any of two described operations (1 < i ≤ k).

If there are multiple answers, print any of them.

Examples

Input

2 162

Output

YES
5
2 4 8 81 162

Input

4 42

Output

NO

Input

100 40021

Output

YES
5
100 200 2001 4002 40021

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long finnal, arr[100000], prof = 0;
bool done = false;
void expandir(long long a) {
  if (done == true) return;
  arr[prof] = a;
  prof++;
  long long opc1 = 2 * a;
  long long opc2 = a * 10 + 1;
  if (a > finnal) {
    prof--;
    return;
  }
  if (a == finnal) {
    cout << "YES" << endl;
    cout << prof << endl;
    for (int i = 0; i < prof; i++) cout << arr[i] << " ";
    done = true;
  } else {
    expandir(opc1);
    expandir(opc2);
  }
  prof--;
}
int main() {
  long long a;
  cin >> a >> finnal;
  expandir(a);
  if (done == false) {
    cout << "NO" << endl;
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

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

<image>

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

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

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

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

Input

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

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

Output

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

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

Examples

Input

7
1 2 1 1 4 4

Output

1.0 4.0 5.0 3.5 4.5 5.0 5.0

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cmax(T& a, T b) {
  a = max(a, b);
}
template <typename T>
void cmin(T& a, T b) {
  a = min(a, b);
}
bool RD(void) { return true; }
bool RD(int& a) { return scanf("%d", &a) == 1; }
bool RD(long long& a) { return scanf("%lld", &a) == 1; }
bool RD(double& a) { return scanf("%lf", &a) == 1; }
bool RD(char& a) { return scanf(" %c", &a) == 1; }
bool RD(char* a) { return scanf("%s", a) == 1; }
template <typename T, typename... TT>
bool RD(T& a, TT&... b) {
  return RD(a) && RD(b...);
}
const int maxn = 1.12e5;
vector<int> g[maxn];
int sz[maxn];
double e[maxn];
void getsz(int p, int u) {
  sz[u] = 1;
  for (int v : g[u])
    if (v != p) {
      getsz(u, v);
      sz[u] += sz[v];
    }
}
void calc(int p, int u) {
  for (int v : g[u])
    if (v != p) {
      e[v] = e[u] + (sz[u] - 1 - sz[v]) / 2.0 + 1.0;
      calc(u, v);
    }
}
int main() {
  int n;
  RD(n);
  for (int i = (2), __e = (n + 1); i < __e; ++i) {
    int p;
    RD(p);
    g[i].push_back(p);
    g[p].push_back(i);
  }
  getsz(0, 1);
  e[1] = 1.0;
  calc(0, 1);
  for (int i = (1), __e = (n + 1); i < __e; ++i)
    printf("%.15lf%c", e[i], " \n"[i == n]);
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj.

Input

On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000.

Output

On a single line output the coordinates of Mj, space separated.

Examples

Input

3 4
0 0
1 1
2 3
-5 3

Output

14 0

Input

3 1
5 5
1000 1000
-1000 1000
3 100

Output

1995 1995

### Response

```cpp
#include <bits/stdc++.h>
struct point {
  int x, y;
} a[100010];
int main() {
  int n, x, y;
  long long t;
  scanf("%d%I64d", &n, &t);
  scanf("%d%d", &x, &y);
  for (int i = 0; i < n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  int r = t % (2 * n);
  for (int i = 0; i < r; i++) x = 2 * a[i % n].x - x, y = 2 * a[i % n].y - y;
  printf("%d %d", x, y);
}

```


### Prompt

Generate a CPP solution to the following problem:

Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows:

* The vertices of the tree were numbered 1,2,...,N, and the edges were numbered 1,2,...,N-1.
* Edge i connected Vertex a_i and b_i.
* The length of each edge was an integer between 1 and 10^{18} (inclusive).
* The sum of the shortest distances from Vertex i to Vertex 1,...,N was s_i.

From the information above, restore the length of each edge. The input guarantees that it is possible to determine the lengths of the edges consistently with the record. Furthermore, it can be proved that the length of each edge is uniquely determined in such a case.

Constraints

* 2 \leq N \leq 10^{5}
* 1 \leq a_i,b_i \leq N
* 1 \leq s_i \leq 10^{18}
* The given graph is a tree.
* All input values are integers.
* It is possible to consistently restore the lengths of the edges.
* In the restored graph, the length of each edge is an integer between 1 and 10^{18} (inclusive).

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}
s_1 s_2 ... s_{N}

Output

Print N-1 lines. The i-th line must contain the length of Edge i.

Examples

Input

4
1 2
2 3
3 4
8 6 6 8

Output

1
2
1

Input

5
1 2
1 3
1 4
1 5
10 13 16 19 22

Output

1
2
3
4

Input

15
9 10
9 15
15 4
4 13
13 2
13 11
2 14
13 6
11 1
1 12
12 3
12 7
2 5
14 8
1154 890 2240 883 2047 2076 1590 1104 1726 1791 1091 1226 841 1000 901

Output

5
75
2
6
7
50
10
95
9
8
78
28
89
8

### Response

```cpp
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, C[101000], ck, cc;
long long S[101000], R[101000], SS;
vector<int>E[101000], Num[101000];
void DFS(int a, int pp, int num) {
	int i;
	C[a] = 1;
	for (i = 0; i < E[a].size(); i++) {
		if (E[a][i] == pp)continue;
		DFS(E[a][i], a, Num[a][i]);
		C[a] += C[E[a][i]];
	}
	if (pp) {
		if (C[a] * 2 == n)ck = num, cc = C[a];
		else {
			R[num] = (S[a] - S[pp]) / (n - C[a] * 2);
			SS -= C[a] * R[num];
		}
	}
}
int main() {
	int i, a, b;
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
		Num[a].push_back(i);
		Num[b].push_back(i);
	}
	for (i = 1; i <= n; i++)scanf("%lld", &S[i]);
	SS = S[1];
	DFS(1, 0, -1);
	if (ck)R[ck] = SS / cc;
	for (i = 1; i < n; i++)printf("%lld\n", R[i]);
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.

Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has).

The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints.

A color hint goes like that: a player names some color and points at all the cards of this color.

Similarly goes the value hint. A player names some value and points at all the cards that contain the value.

Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in.

Output

Print a single integer — the minimum number of hints that the other players should make.

Examples

Input

2
G3 G3

Output

0

Input

4
G4 R4 R3 B3

Output

2

Input

5
B1 Y1 W1 G1 R1

Output

4

Note

In the first sample Borya already knows for each card that it is a green three.

In the second sample we can show all fours and all red cards.

In the third sample you need to make hints about any four colors.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
bool ok[6][6];
set<char> s1[6];
set<char> s2[6];
vector<int> v1[6], v2[6];
char col[105];
char num[105];
int hint[105];
int ans;
int main() {
  cin >> n;
  ans = n;
  for (int i = 1; i <= n; i++) {
    cin >> col[i] >> num[i];
    if (col[i] == 'R') {
      col[i] = 'A';
    } else if (col[i] == 'G') {
      col[i] = 'B';
    } else if (col[i] == 'B') {
      col[i] = 'C';
    } else if (col[i] == 'Y') {
      col[i] = 'D';
    } else {
      col[i] = 'E';
    }
    v1[col[i] - 'A' + 1].push_back(i);
    v2[num[i] - '0'].push_back(i);
  }
  for (int msk = 0; msk < (1 << 10); msk++) {
    int t = msk;
    int pl = 0;
    int cnt = 0;
    for (int i = 1; i <= 5; i++) {
      s1[i].clear();
      s2[i].clear();
    }
    memset(hint, 0, sizeof(hint));
    while (t) {
      pl++;
      if (t % 2) {
        cnt++;
        if (pl <= 5) {
          for (int i = 0; i < v1[pl].size(); i++) {
            hint[v1[pl][i]]++;
            s1[pl].insert(num[v1[pl][i]]);
          }
        } else {
          for (int i = 0; i < v2[pl - 5].size(); i++) {
            hint[v2[pl - 5][i]]++;
            s2[pl - 5].insert(col[v2[pl - 5][i]]);
          }
        }
      }
      t /= 2;
    }
    set<pair<char, char> > S;
    for (int i = 1; i <= n; i++) {
      if (hint[i] == 2) {
        s1[col[i] - 'A' + 1].erase(num[i]);
        s2[num[i] - '0'].erase(col[i]);
      } else if (hint[i] == 0) {
        S.insert(make_pair(col[i], num[i]));
      }
    }
    bool flag = true;
    for (int i = 1; i <= 5; i++) {
      if (s1[i].size() > 1 || s2[i].size() > 1) {
        flag = false;
        break;
      }
    }
    if (S.size() > 1) {
      flag = false;
    }
    if (flag) {
      ans = min(ans, cnt);
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

In the town of Aalam-Aara (meaning the Light of the Earth), previously there was no crime, no criminals but as the time progressed, sins started creeping into the hearts of once righteous people. Seeking solution to the problem, some of the elders found that as long as the corrupted part of population was kept away from the uncorrupted part, the crimes could be stopped. So, they are trying to set up a compound where they can keep the corrupted people. To ensure that the criminals don't escape the compound, a watchtower needs to be set up, so that they can be watched.

Since the people of Aalam-Aara aren't very rich, they met up with a merchant from some rich town who agreed to sell them a land-plot which has already a straight line fence AB along which a few points are set up where they can put up a watchtower. Your task is to help them find out the number of points on that fence where the tower can be put up, so that all the criminals can be watched from there. Only one watchtower can be set up. A criminal is watchable from the watchtower if the line of visibility from the watchtower to him doesn't cross the plot-edges at any point between him and the tower i.e. as shown in figure 1 below, points X, Y, C and A are visible from point B but the points E and D are not.

<image> Figure 1  <image> Figure 2

Assume that the land plot is in the shape of a polygon and coordinate axes have been setup such that the fence AB is parallel to x-axis and the points where the watchtower can be set up are the integer points on the line. For example, in given figure 2, watchtower can be setup on any of five integer points on AB i.e. (4, 8), (5, 8), (6, 8), (7, 8) or (8, 8). You can assume that no three consecutive points are collinear and all the corner points other than A and B, lie towards same side of fence AB. The given polygon doesn't contain self-intersections.

Input

The first line of the test case will consist of the number of vertices n (3 ≤ n ≤ 1000).

Next n lines will contain the coordinates of the vertices in the clockwise order of the polygon. On the i-th line are integers xi and yi (0 ≤ xi, yi ≤ 106) separated by a space.

The endpoints of the fence AB are the first two points, (x1, y1) and (x2, y2).

Output

Output consists of a single line containing the number of points where the watchtower can be set up.

Examples

Input

5
4 8
8 8
9 4
4 0
0 4

Output

5

Input

5
4 8
5 8
5 4
7 4
2 2

Output

0

Note

Figure 2 shows the first test case. All the points in the figure are watchable from any point on fence AB. Since, AB has 5 integer coordinates, so answer is 5.

For case two, fence CD and DE are not completely visible, thus answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int turn2(std::complex<double> a, std::complex<double> b,
          std::complex<double> c) {
  double x = imag((a - b) * conj(c - b));
  return x < 0 ? -1 : x > 0;
}
std::complex<double> omega(std::complex<double> x, std::complex<double> y) {
  return conj(x - y) / (x - y);
}
std::complex<double> rho(std::complex<double> x, std::complex<double> y) {
  return (conj(x) * y - x * conj(y)) / (x - y);
}
std::complex<double> intersection(std::complex<double> a,
                                  std::complex<double> b,
                                  std::complex<double> c,
                                  std::complex<double> d) {
  return (rho(a, b) - rho(c, d)) / (omega(a, b) - omega(c, d));
}
bool parallel(std::complex<double> a, std::complex<double> b,
              std::complex<double> c, std::complex<double> d) {
  return imag((a - b) * conj(c - d)) == 0;
}
double EPS = 1e-8;
double l = -1e20;
double r = 1e20;
vector<std::complex<double> > x;
int n;
int turn;
std::complex<double> I = std::complex<double>(0, 1);
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    x.push_back(std::complex<double>(a, b));
  }
  if (real(x[0]) > real(x[1])) {
    for (int i = 0; i < n; i++) x[i] *= -1;
  }
  turn = turn2(x[0], x[1], x[2]);
  for (int i = 2; i + 1 < n; i++) {
    if (parallel(x[0], x[1], x[i], x[i + 1])) {
      if (turn2(x[i], x[i + 1], x[i + 1] + I) != turn) {
        r = -1e20;
        l = 1e20;
      }
    } else {
      std::complex<double> s = intersection(x[0], x[1], x[i], x[i + 1]);
      if (turn2(x[i], x[i + 1], s + 1.0) == turn) {
        l = max(l, real(s));
      } else {
        r = min(r, real(s));
      }
    }
  }
  l = max(l, real(x[0]));
  r = min(r, real(x[1]));
  if (r - l >= -EPS) {
    printf("%d\n", (int)(floor(r + EPS) - ceil(l - EPS)) + 1);
  } else {
    printf("0\n");
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of the vertices, except the root, has a directed edge coming from its parent. Note that the root may not be Vertex 1.

Takahashi has added M new directed edges to this graph. Each of these M edges, u \rightarrow v, extends from some vertex u to its descendant v.

You are given the directed graph with N vertices and N-1+M edges after Takahashi added edges. More specifically, you are given N-1+M pairs of integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the i-th edge extends from Vertex A_i to Vertex B_i.

Restore the original rooted tree.

Constraints

* 3 \leq N
* 1 \leq M
* N + M \leq 10^5
* 1 \leq A_i, B_i \leq N
* A_i \neq B_i
* If i \neq j, (A_i, B_i) \neq (A_j, B_j).
* The graph in input can be obtained by adding M edges satisfying the condition in the problem statement to a rooted tree with N vertices.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_{N-1+M} B_{N-1+M}

Output

Print N lines. In the i-th line, print `0` if Vertex i is the root of the original tree, and otherwise print the integer representing the parent of Vertex i in the original tree.

Note that it can be shown that the original tree is uniquely determined.

Examples

Input

3 1
1 2
1 3
2 3

Output

0
1
2

Input

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

Output

6
4
2
0
6
2

### Response

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

int N,M;
int root;
vector<int> G[100010];
vector<bool> rootf(100010,true);
vector<int> tt(100010,0);
vector<int> ans(100010,-1);
queue<int> que;

int main(){
	cin >> N >> M;
	for(int i=0;i<N+M-1;i++){
		int s,t;
		scanf("%d%d",&s,&t);
		G[s].push_back(t);
		rootf.at(t)=false;
		tt.at(t)++;
	}

	for(int i=1;i<=N;i++)if(rootf.at(i))root=i;
	ans.at(root)=0;
	que.push(root);

	while(que.empty()==0){
		int s=que.front();
		que.pop();
		for(auto t:G[s]){
			ans.at(t)=s;
			tt.at(t)--;
			if(tt.at(t)==0)que.push(t);
		}
	}

	for(int i=1;i<=N;i++)printf("%d\n",ans.at(i));
	return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.

Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits.

Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket.

If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally.

Input

The first line contains one even integer n (2 ≤ n ≤ 2 ⋅ 10^{5}) — the number of digits in the ticket.

The second line contains a string of n digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.

Output

If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).

Examples

Input

4
0523

Output

Bicarp

Input

2
??

Output

Bicarp

Input

8
?054??0?

Output

Bicarp

Input

6
???00?

Output

Monocarp

Note

Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp.

In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int x = 0, sum = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] == '?')
      x++;
    else
      sum += s[i] - '0';
  }
  for (int i = n / 2; i < n; i++) {
    if (s[i] == '?')
      x--;
    else
      sum -= s[i] - '0';
  }
  if (2 * sum == -1 * 9 * x) {
    cout << "Bicarp";
    return 0;
  }
  cout << "Monocarp";
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Chief Judge's log, stardate 48642.5. We have decided to make a problem from elementary number theory. The problem looks like finding all prime factors of a positive integer, but it is not.

A positive integer whose remainder divided by 7 is either 1 or 6 is called a 7N+{1,6} number. But as it is hard to pronounce, we shall call it a Monday-Saturday number.

For Monday-Saturday numbers a and b, we say a is a Monday-Saturday divisor of b if there exists a Monday-Saturday number x such that ax = b. It is easy to show that for any Monday-Saturday numbers a and b, it holds that a is a Monday-Saturday divisor of b if and only if a is a divisor of b in the usual sense.

We call a Monday-Saturday number a Monday-Saturday prime if it is greater than 1 and has no Monday-Saturday divisors other than itself and 1. A Monday-Saturday number which is a prime in the usual sense is a Monday-Saturday prime but the converse does not always hold. For example, 27 is a Monday-Saturday prime although it is not a prime in the usual sense. We call a Monday-Saturday prime which is a Monday-Saturday divisor of a Monday-Saturday number a a Monday-Saturday prime factor of a. For example, 27 is one of the Monday-Saturday prime factors of 216, since 27 is a Monday-Saturday prime and 216 = 27 × 8 holds.

Any Monday-Saturday number greater than 1 can be expressed as a product of one or more Monday-Saturday primes. The expression is not always unique even if differences in order are ignored. For example,  216 = 6 × 6 × 6 = 8 × 27  holds.

Our contestants should write a program that outputs all Monday-Saturday prime factors of each input Monday-Saturday number.

Input

The input is a sequence of lines each of which contains a single Monday-Saturday number. Each Monday-Saturday number is greater than 1 and less than 300000 (three hundred thousand). The end of the input is indicated by a line containing a single digit 1.

Output

For each input Monday-Saturday number, it should be printed, followed by a colon `:' and the list of its Monday-Saturday prime factors on a single line. Monday-Saturday prime factors should be listed in ascending order and each should be preceded by a space. All the Monday-Saturday prime factors should be printed only once even if they divide the input Monday-Saturday number more than once.

Sample Input

205920
262144
262200
279936
299998
1

Output for the Sample Input

205920: 6 8 13 15 20 22 55 99
262144: 8
262200: 6 8 15 20 50 57 69 76 92 190 230 475 575 874 2185
279936: 6 8 27
299998: 299998

Example

Input

205920
262144
262200
279936
299998
1

Output

205920: 6 8 13 15 20 22 55 99
262144: 8
262200: 6 8 15 20 50 57 69 76 92 190 230 475 575 874 2185
279936: 6 8 27
299998: 299998

### Response

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

#define LIM 300020
using namespace std;

int main(){

	int n;
	bool isprime[LIM]={0};
	vector<int> primes;

	for(int i=2; i<LIM; ++i)
		isprime[i]=true;

	for(int i=2; i*i<LIM; ++i){

		if(isprime[i] && (i%7==1 || i%7==6)){
			for(int j=i; i*j<LIM; j++){
				if(j%7==1 || j%7==6){
					isprime[i*j]=false;
				}
			}
		}
	}

	for(int i=0; i<LIM; ++i){

		if(isprime[i] && (i%7==1 || i%7==6))
			primes.push_back(i);
	}

	while(cin>>n, n>1){

		cout << n << ":";

		for(int i=0; i<primes.size(); ++i){

			if(n%primes[i]==0)
				cout << " " << primes[i];
		}

		cout << endl;
	}

	return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise.

Vova thinks that people in the i-th flats are disturbed and cannot sleep if and only if 1 < i < n and a_{i - 1} = a_{i + 1} = 1 and a_i = 0.

Vova is concerned by the following question: what is the minimum number k such that if people from exactly k pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number k.

Input

The first line of the input contains one integer n (3 ≤ n ≤ 100) — the number of flats in the house.

The second line of the input contains n integers a_1, a_2, ..., a_n (a_i ∈ \{0, 1\}), where a_i is the state of light in the i-th flat.

Output

Print only one integer — the minimum number k such that if people from exactly k pairwise distinct flats will turn off the light then nobody will be disturbed.

Examples

Input

10
1 1 0 1 1 0 1 0 1 0

Output

2

Input

5
1 1 0 0 0

Output

0

Input

4
1 1 1 1

Output

0

Note

In the first example people from flats 2 and 7 or 4 and 7 can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.

There are no disturbed people in second and third examples.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, n, m, t, sum = 0, ans = 0;
  bool f = 0, flag = 0;
  string s;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 1; i < n - 1; i++) {
    if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) {
      a[i + 1] = 0;
      sum++;
      i++;
    }
  }
  cout << sum << endl;
  return 0;
}

```


### Prompt

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

We call two numbers x and y similar if they have the same parity (the same remainder when divided by 2), or if |x-y|=1. For example, in each of the pairs (2, 6), (4, 3), (11, 7), the numbers are similar to each other, and in the pairs (1, 4), (3, 12), they are not.

You are given an array a of n (n is even) positive integers. Check if there is such a partition of the array into pairs that each element of the array belongs to exactly one pair and the numbers in each pair are similar to each other.

For example, for the array a = [11, 14, 16, 12], there is a partition into pairs (11, 12) and (14, 16). The numbers in the first pair are similar because they differ by one, and in the second pair because they are both even.

Input

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

Each test case consists of two lines.

The first line contains an even positive integer n (2 ≤ n ≤ 50) — length of array a.

The second line contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).

Output

For each test case print:

  * YES if the such a partition exists,
  * NO otherwise.

The letters in the words YES and NO can be displayed in any case.

Example

Input

7
4
11 14 16 12
2
1 8
4
1 1 1 1
4
1 2 5 6
2
12 13
6
1 6 3 10 5 8
6
1 12 3 10 5 8

Output

YES
NO
YES
YES
YES
YES
NO

Note

The first test case was explained in the statement.

In the second test case, the two given numbers are not similar.

In the third test case, any partition is suitable.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void test() {
  int i, n, a, cnt = 0, c = 0;
  vector<int> v;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end(), greater<int>());
  for (i = 0; i < n; ++i) {
    if (v[i] % 2) cnt++;
  }
  if (cnt % 2 == 0) {
    cout << "YES" << endl;
    return;
  }
  for (i = 0; i < n - 1; ++i) {
    if (v[i] - v[i + 1] == 1) c++;
  }
  if (c >= 1)
    cout << "YES\n";
  else
    cout << "NO" << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) test();
}

```


### Prompt

Please create a solution in cpp to the following problem:

There is a sequence of length N: a = (a_1, a_2, ..., a_N). Here, each a_i is a non-negative integer.

Snuke can repeatedly perform the following operation:

* Let the XOR of all the elements in a be x. Select an integer i (1 ≤ i ≤ N) and replace a_i with x.

Snuke's objective is to match a with another sequence b = (b_1, b_2, ..., b_N). Here, each b_i is a non-negative integer.

Determine whether the objective is achievable, and find the minimum necessary number of operations if the answer is positive.

Constraints

* 2 ≤ N ≤ 10^5
* a_i and b_i are integers.
* 0 ≤ a_i, b_i < 2^{30}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N
b_1 b_2 ... b_N

Output

If the objective is achievable, print the minimum necessary number of operations. Otherwise, print `-1` instead.

Examples

Input

3
0 1 2
3 1 0

Output

2

Input

3
0 1 2
0 1 2

Output

0

Input

2
1 1
0 0

Output

-1

Input

4
0 1 2 3
1 0 3 2

Output

5

### Response

```cpp
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+50;
int n,a[N],b[N],c[N],c2[N],m,ans;bool vis[N];
vector<int>v[N];
void dfs(int x){
	vis[x]=1;
	for(int i=0,y;i<v[x].size();i++)
		if(!vis[y=v[x][i]])dfs(y);
}
int main(){
	scanf("%d",&n);n++;
	for(int i=1;i<n;i++)scanf("%d",&a[i]),a[n]^=a[i];
	for(int i=1;i<n;i++)scanf("%d",&b[i]),b[n]^=b[i];
	for(int i=1;i<=n;i++)c[i]=a[i],c2[i]=b[i];
	sort(c+1,c+n+1);sort(c2+1,c2+n+1);
	for(int i=1;i<=n;i++)if(c[i]!=c2[i])puts("-1"),exit(0);
	m=unique(c+1,c+n+1)-c-1;
	for(int i=1;i<=n;i++)a[i]=lower_bound(c+1,c+m+1,a[i])-c,b[i]=lower_bound(c+1,c+m+1,b[i])-c;
	for(int i=1;i<=n;i++)if(a[i]!=b[i])v[a[i]].pb(b[i]),ans++;
	for(int i=1;i<=m;i++)if(!vis[i]&&v[i].size())dfs(i),ans++;ans-=2;
	if(a[n]==b[n]){
		if(!v[a[n]].size())ans+=2;
		else ans++;
	}
	cout<<ans;
	return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of the maximum size such that any two of them are connected by an edge in graph G. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph.

Consider n distinct points on a line. Let the i-th point have the coordinate xi and weight wi. Let's form graph G, whose vertices are these points and edges connect exactly the pairs of points (i, j), such that the distance between them is not less than the sum of their weights, or more formally: |xi - xj| ≥ wi + wj.

Find the size of the maximum clique in such graph.

Input

The first line contains the integer n (1 ≤ n ≤ 200 000) — the number of points.

Each of the next n lines contains two numbers xi, wi (0 ≤ xi ≤ 109, 1 ≤ wi ≤ 109) — the coordinate and the weight of a point. All xi are different.

Output

Print a single number — the number of vertexes in the maximum clique of the given graph.

Examples

Input

4
2 3
3 1
6 1
0 2

Output

3

Note

If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars!

The picture for the sample test.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int x, w;
pair<int, int> m[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x >> w;
    m[i].first = x + w;
    m[i].second = x - w;
  }
  sort(m, m + n);
  int ans = 0;
  int cnt = 0;
  for (int i = 1; i < n; ++i) {
    if (m[i].second >= m[ans].first) {
      ans = i;
      ++cnt;
    }
  }
  cout << cnt + 1;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

This problem consists of two subproblems: for solving subproblem E1 you will receive 11 points, and for solving subproblem E2 you will receive 13 points.

A tree is an undirected connected graph containing no cycles. The distance between two nodes in an unweighted tree is the minimum number of edges that have to be traversed to get from one node to another.

You are given 3 trees that have to be united into a single tree by adding two edges between these trees. Each of these edges can connect any pair of nodes from two trees. After the trees are connected, the distances between all unordered pairs of nodes in the united tree should be computed. What is the maximum possible value of the sum of these distances?

Input

The first line contains three space-separated integers n1, n2, n3 — the number of vertices in the first, second, and third trees, respectively. The following n1 - 1 lines describe the first tree. Each of these lines describes an edge in the first tree and contains a pair of integers separated by a single space — the numeric labels of vertices connected by the edge. The following n2 - 1 lines describe the second tree in the same fashion, and the n3 - 1 lines after that similarly describe the third tree. The vertices in each tree are numbered with consecutive integers starting with 1.

The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.

  * In subproblem E1 (11 points), the number of vertices in each tree will be between 1 and 1000, inclusive.
  * In subproblem E2 (13 points), the number of vertices in each tree will be between 1 and 100000, inclusive.

Output

Print a single integer number — the maximum possible sum of distances between all pairs of nodes in the united tree.

Examples

Input

2 2 3
1 2
1 2
1 2
2 3

Output

56

Input

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

Output

151

Note

Consider the first test case. There are two trees composed of two nodes, and one tree with three nodes. The maximum possible answer is obtained if the trees are connected in a single chain of 7 vertices.

In the second test case, a possible choice of new edges to obtain the maximum answer is the following:

  * Connect node 3 from the first tree to node 1 from the second tree;
  * Connect node 2 from the third tree to node 1 from the second tree.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
const int INF = 5e8;
struct Tree {
  int e[200005], nxt[200005], begin[100005], cnt;
  int n;
  long long int totdist[100005];
  int size[100005];
  long long int sum_dist;
  void getdist(int v, int p) {
    size[v] = 1;
    for (int it = begin[v]; ~it; it = nxt[it]) {
      int to = e[it];
      if (to == p) continue;
      getdist(to, v);
      size[v] += size[to];
      totdist[v] += totdist[to];
    }
    totdist[v] += size[v] - 1;
  }
  void getdist2(int v, int p, long long int sum) {
    for (int it = begin[v]; ~it; it = nxt[it]) {
      int to = e[it];
      if (to == p) continue;
      getdist2(to, v,
               sum + totdist[v] - (totdist[to] + size[to]) + n - size[to]);
    }
    totdist[v] += sum;
  }
  long long int maxdist;
  void init(int n_) {
    n = n_;
    memset(begin, -1, sizeof(begin));
    cnt = 0;
    for (int i = 0; i < (n - 1); ++i) {
      int a, b;
      scanf("%d%d", &a, &b);
      --a;
      --b;
      e[cnt] = b;
      nxt[cnt] = begin[a];
      begin[a] = cnt++;
      e[cnt] = a;
      nxt[cnt] = begin[b];
      begin[b] = cnt++;
    }
    maxdist = sum_dist = 0;
    getdist(0, -1);
    getdist2(0, -1, 0);
    for (int i = 0; i < (n); ++i) {
      chmax(maxdist, totdist[i]);
      sum_dist += totdist[i];
    }
    debug(totdist, totdist + n);
    sum_dist /= 2;
  }
  long long int dis1, dis3;
  int n1, n3;
  int cut[100005];
  long long int res;
  pair<long long int, long long int> dfs(int v, int p, int d) {
    pair<long long int, long long int> nxtt =
        make_pair(totdist[v] * n1 + d * (long long int)n1 * n3,
                  totdist[v] * n3 + d * (long long int)n1 * n3);
    chmax(res, nxtt.first + nxtt.second - 2LL * d * n1 * n3);
    for (int it = begin[v]; ~it; it = nxt[it]) {
      int to = e[it];
      if (to == p) continue;
      pair<long long int, long long int> nxt2 = dfs(to, v, d + 1);
      chmax(res, nxtt.first + nxt2.second - 2LL * d * (long long int)n1 * n3);
      chmax(res, nxtt.second + nxt2.first - 2LL * d * (long long int)n1 * n3);
      chmax(nxtt.first, nxt2.first);
      chmax(nxtt.second, nxt2.second);
    }
    return nxtt;
  }
  long long int query(long long int A, long long int B, int n1_, int n3_) {
    ;
    ;
    dis1 = A;
    dis3 = B;
    n1 = n1_;
    n3 = n3_;
    memset((cut), 0, sizeof(cut));
    res = 0;
    dfs(0, -1, 0);
    res += (dis1 + dis3) * n;
    res += n1 * dis3;
    res += n3 * dis1;
    res += 2ll * n1 * n3;
    res += 1ll * n1 * n;
    res += 1ll * n * n3;
    return res;
  }
};
Tree T[3];
int n[3];
int main() {
  cin >> n[0] >> n[1] >> n[2];
  for (int i = 0; i < (3); ++i) {
    T[i].init(n[i]);
  }
  int perm[3] = {0, 1, 2};
  long long int res = 0, base = T[0].sum_dist + T[1].sum_dist + T[2].sum_dist;
  do {
    if (perm[0] > perm[2]) {
      chmax(res, T[perm[1]].query(T[perm[0]].maxdist, T[perm[2]].maxdist,
                                  n[perm[0]], n[perm[2]]));
    }
  } while (next_permutation(perm, perm + 3));
  res += base;
  cout << res << endl;
  return 0;
}

```


### Prompt

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

Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the i-th section of this wall. You know that archer who stands at section i can shoot orcs that attack section located at distance not exceeding r, that is all such sections j that |i - j| ≤ r. In particular, r = 0 means that archers are only capable of shooting at orcs who attack section i.

Denote as defense level of section i the total number of archers who can shoot at the orcs attacking this section. Reliability of the defense plan is the minimum value of defense level of individual wall section.

There is a little time left till the attack so you can't redistribute archers that are already located at the wall. However, there is a reserve of k archers that you can distribute among wall sections in arbitrary way. You would like to achieve maximum possible reliability of the defence plan.

Input

The first line of the input contains three integers n, r and k (1 ≤ n ≤ 500 000, 0 ≤ r ≤ n, 0 ≤ k ≤ 1018) — the number of sections of the wall, the maximum distance to other section archers can still shoot and the number of archers yet to be distributed along the wall. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the current number of archers at each section.

Output

Print one integer — the maximum possible value of defense plan reliability, i.e. the maximum possible value of minimum defense level if we distribute k additional archers optimally.

Examples

Input

5 0 6
5 4 3 4 9

Output

5

Input

4 2 0
1 2 3 4

Output

6

Input

5 1 1
2 1 2 1 2

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const long long mod = 1e9 + 7;
const long double eps = 1e-10;
const int inf = 1e6;
int n, d;
long long k;
long long a[maxn];
long long ac[maxn];
long long bc[maxn];
long long b[maxn];
bool check(long long t) {
  memset(b, 0, sizeof(b));
  long long used = 0;
  long long cur = 0;
  for (int i = 0; i < n; ++i) {
    cur += ac[i];
    long long need = max(0ll, t - cur);
    int addPos = i + d * 2;
    cur += need;
    used += need;
    if (used > k) return false;
    if (addPos < n) b[addPos] += need;
    cur -= b[i];
    cur -= bc[i];
  }
  return used <= k;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> d >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    int lp = max(0, i - d);
    int rp = min(n - 1, i + d);
    ac[lp] += a[i];
    bc[rp] += a[i];
  }
  long long l = *min_element(a, a + n);
  long long r = k + accumulate(a, a + n, 0ll);
  while (l + 1 < r) {
    long long m = l + (r - l) / 2;
    if (check(m))
      l = m;
    else
      r = m - 1;
  }
  if (check(r))
    cout << r << "\n";
  else
    cout << l << "\n";
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given n strings ti. Each string has cost ci.

Let's define the function of string <image>, where ps, i is the number of occurrences of s in ti, |s| is the length of the string s. Find the maximal value of function f(s) over all strings.

Note that the string s is not necessarily some string from t.

Input

The first line contains the only integer n (1 ≤ n ≤ 105) — the number of strings in t.

Each of the next n lines contains contains a non-empty string ti. ti contains only lowercase English letters.

It is guaranteed that the sum of lengths of all strings in t is not greater than 5·105.

The last line contains n integers ci ( - 107 ≤ ci ≤ 107) — the cost of the i-th string.

Output

Print the only integer a — the maximal value of the function f(s) over all strings s. Note one more time that the string s is not necessarily from t.

Examples

Input

2
aa
bb
2 1

Output

4

Input

2
aa
ab
2 1

Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, len;
char t[600013];
int id[600013];
int e[100013], c[100013];
pair<pair<int, int>, int> cur[600013];
int last[600013], where[600013];
int suffix[600013], lcp[600013];
void makeSA() {
  for (int i = 0; i < len; i++) {
    last[i] = t[i];
    cur[i].second = where[i] = i;
  }
  for (int k = 1; k < len; k *= 2) {
    for (int i = 0; i < len; i++) {
      cur[i].first = make_pair(last[i], 0);
      if (cur[i].second + k < len)
        cur[i].first.second = last[where[cur[i].second + k]];
    }
    sort(cur, cur + len);
    for (int i = 0; i < len; i++) where[cur[i].second] = i;
    last[0] = 0;
    for (int i = 1; i < len; i++)
      last[i] = last[i - 1] + (cur[i].first != cur[i - 1].first);
  }
  for (int i = 0; i < len; i++) suffix[i] = cur[i].second;
  int prev = 0;
  for (int i = 0; i < len; i++) {
    int& l = lcp[where[i]];
    l = max(0, prev - 1);
    while (t[i + l] == t[suffix[where[i] + 1] + l] && t[i + l] != '$') l += 1;
    lcp[where[i]] = l;
    prev = l;
  }
  lcp[len - 1] = 0;
}
long long sums[600013];
int l[600013], r[600013];
stack<int> has;
long long sum(int a, int b) { return sums[b] - (a ? sums[a - 1] : 0); }
void solve() {
  sums[0] = c[id[suffix[0]]];
  for (int i = 1; i < len; i++) sums[i] = sums[i - 1] + c[id[suffix[i]]];
  fill(l, l + len, -1);
  for (int i = 0; i < len - 1; i++) {
    while (has.size() && lcp[has.top()] >= lcp[i]) has.pop();
    if (has.size()) l[i] = has.top();
    has.push(i);
  }
  while (has.size()) has.pop();
  fill(r, r + len, len - 1);
  for (int i = len - 2; i >= 0; i--) {
    while (has.size() && lcp[has.top()] >= lcp[i]) has.pop();
    if (has.size()) r[i] = has.top();
    has.push(i);
  }
  long long ans = 0;
  for (int i = 0; i < len; i++) {
    if (t[suffix[i]] == '$') continue;
    if (i < len - 1)
      ans = max(ans, lcp[i] * (sums[r[i]] - (l[i] + 1 ? sums[l[i]] : 0)));
    long long dist = e[id[suffix[i]]] - suffix[i];
    if (i && dist == lcp[i - 1]) continue;
    if (dist == lcp[i]) continue;
    ans = max(ans, dist * c[id[suffix[i]]]);
  }
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &n);
  char* head = t;
  for (int i = 0; i < n; i++) {
    scanf(" %s", head);
    while (*head) {
      id[head - t] = i;
      head++;
    }
    e[i] = head - t;
    *head = '$';
    id[head - t] = n;
    head++;
  }
  len = head - t;
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  makeSA();
  solve();
  return 0;
}

```


### Prompt

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

The term of this problem is the same as the previous one, the only exception — increased restrictions.

Input

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie.

The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

Output

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

Examples

Input

1 1000000000
1
1000000000

Output

2000000000

Input

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1

Output

0

Input

3 1
2 1 4
11 3 16

Output

4

Input

4 3
4 3 5 6
11 12 14 20

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int a[100000 + 12], b[100000 + 12];
int n, k;
bool ok(long long int mid, int k) {
  int i, j;
  long long int need = 0;
  for (i = 0; i < n; i++) {
    need = mid * a[i];
    if (need < b[i]) continue;
    if (need - b[i] > k) return false;
    k -= need - b[i];
  }
  return true;
}
int main() {
  int i;
  cin >> n >> k;
  long long int low = 0, high = 1e10, mid;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  while (low != high) {
    mid = low + (high - low + 1) / 2;
    if (ok(mid, k))
      low = mid;
    else
      high = mid - 1;
  }
  cout << low << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.

An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.

At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?

Constraints

* All values in input are integers.
* 1 \leq A, B \leq 1000
* 0 \leq H \leq 11
* 0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.

Examples

Input

3 4 9 0

Output

5.00000000000000000000

Input

3 4 10 40

Output

4.56425719433005567605

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
double a,b;
int h,m;
int main(){
    scanf("%lf%lf%d%d",&a,&b,&h,&m);
    printf("%.9f",sqrt(a*a+b*b-2*a*b*cos((abs(30*h-5.5*m)*(acos(-1)/180)))));
    return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Write a program which reads a list of student test scores and evaluates the performance for each student.

The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.

The final performance of a student is evaluated by the following procedure:

* If the student does not take the midterm or final examination, the student's grade shall be F.
* If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
* If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
* If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
* If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
* If the total score of the midterm and final examination is less than 30, the student's grade shall be F.

Input

The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.

The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.

The number of datasets (the number of students) does not exceed 50.

Output

For each dataset, print the grade (A, B, C, D or F) in a line.

Example

Input

40 42 -1
20 30 -1
0 2 -1
-1 -1 -1

Output

A
C
F

### Response

```cpp
#include<iostream>
int main(){
	for (int m,f,r,s;std::cin>>m>>f>>r,s=m+f,m+1||f+1||r+1;std::cout<<((m+1&&f+1)?(s>=80?"A":(s>=65?"B":(s>=50?"C":(s>=30?(r>=50?"C":"D"):"F")))):"F")<<std::endl);
}
```


### Prompt

Please formulate a cpp solution to the following problem:

One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.

<image>

Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads S is regular if it can be represented as S = A + B + A + B + A + ... + A + B + A, where A and B are some bead sequences, " + " is the concatenation of sequences, there are exactly 2k + 1 summands in this sum, among which there are k + 1 "A" summands and k "B" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if A or B is an empty sequence.

Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order.

Input

The first line contains two integers n, k (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and number k from the definition of the regular sequence above.

The second line contains the sequence of n lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.

Output

Print a string consisting of n zeroes and ones. Position i (1 ≤ i ≤ n) must contain either number one if the first i beads on the thread form a regular sequence, or a zero otherwise.

Examples

Input

7 2
bcabcab

Output

0000011

Input

21 2
ababaababaababaababaa

Output

000110000111111000011

Note

In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take A = "", B = "bca"), and a sequence of the first 7 beads (we can take A = "b", B = "ca").

In the second sample test, for example, a sequence of the first 13 beads is regular, if we take A = "aba", B = "ba".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int l, k, kmp[1000010], p = 0, cur, d, t, la, lb;
char s[1000010];
int main() {
  scanf("%d%d", &l, &k);
  scanf("%s", s + 1);
  for (int i = 2; i <= l; i++) {
    while (p && s[i] != s[p + 1]) p = kmp[p];
    if (s[i] == s[p + 1]) p++;
    kmp[i] = p;
  }
  for (int i = 1; i <= l; i++) {
    cur = i - kmp[i], d = i / cur, t = d / k, la = i - k * t * cur,
    lb = d / k * cur - la;
    if (i % cur)
      printf("%d", (lb > 0));
    else
      printf("%d", (lb >= 0));
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Christmas was knocking on the door, and our protagonist, Bob, was preparing a spectacular present for his long-time second best friend Charlie. As chocolate boxes are lame, he decided to decorate a tree instead. Bob's tree can be represented as an undirected connected graph with n nodes (numbered 1 to n) and n-1 edges. Initially, Bob placed a decoration with label i on node i, for each 1 ≤ i ≤ n. However, as such a simple arrangement is lame, he decided to shuffle the decorations a bit. Formally, Bob did the following steps:

  * First, he listed the n-1 edges in some order.
  * Then, he considered the edges one by one in that order. For each edge (u, v), he swapped the decorations of node u with the one of node v.

After finishing, Bob seemed satisfied with the arrangement, so he went to sleep.

The next morning, Bob wakes up only to find out that his beautiful arrangement has been ruined! Last night, Bob's younger brother Bobo dropped some of the decorations on the floor while he was playing with the tree. Fortunately, no decorations were lost, so Bob can repair the tree in no time. However, he completely forgets how the tree looked like yesterday. Therefore, given the labels of the decorations still on the tree, Bob wants to know the number of possible configurations of the tree. As the result can be quite large, Bob will be happy if you can output the result modulo 1000000007 (10^9+7). Note that, it is possible that there exists no possible configurations.

Input

The first line contains a single integer n (2 ≤ n ≤ 500 000) — the number of nodes.

Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n), denoting that there is an edge connecting two nodes u and v. It is guaranteed that the given edges form a tree.

The last line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ n). For each i, a_i = 0 means that the decoration of node i has been dropped on the floor. Otherwise, a_i is the label of the decoration of node i. It is guaranteed that no label appears more than once.

Output

Output the number of possible configurations modulo 1000000007 (10^9+7).

Examples

Input

4
3 4
2 4
4 1
0 4 0 0

Output

2

Input

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

Output

12

Input

3
1 2
1 3
1 0 0

Output

0

Note

In the first example, the possible configurations of the tree are [2, 4, 1, 3] and [3, 4, 2, 1].

In the second example, note that while there are 4! = 24 possible permutations of the edges, each of them results in a possible configuration, there are only 12 different configurations.

In the third example, it is easy to see that the decoration 1 cannot stay at node 1 after the swaps.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 500010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b;
int A[MAXN], deg[MAXN];
int par[MAXN], h[MAXN], parid[MAXN];
long long F[MAXN], ans = 1;
int f[MAXN][2], nex2[MAXN], bad[MAXN];
bool mark[MAXN];
vector<pair<int, int> > G[MAXN];
map<pair<int, int>, int> mp;
map<int, int> nex[MAXN];
set<pair<int, int> > st;
void dfs(int node) {
  h[node] = h[par[node]] + 1;
  for (pair<int, int> p : G[node])
    if (p.first != par[node]) {
      par[p.first] = node;
      parid[p.first] = p.second;
      dfs(p.first);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  F[0] = 1;
  for (int i = 1; i < MAXN; i++) F[i] = F[i - 1] * i % mod;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    mp[{u, v}] = mp[{v, u}] = i;
    G[u].push_back({v, i});
    G[v].push_back({u, i});
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    if (!A[i]) continue;
    int v = i, u = A[i];
    if (u == v) return cout << 0 << '\n', 0;
    vector<int> v1, v2;
    while (u != v) {
      if (h[u] < h[v]) {
        v1.push_back(v);
        v = par[v];
      } else {
        v2.push_back(u);
        u = par[u];
      }
    }
    v1.push_back(u);
    reverse(v2.begin(), v2.end());
    for (int x : v2) v1.push_back(x);
    for (int i = 1; i < v1.size(); i++) {
      pair<int, int> p = {v1[i - 1], v1[i]};
      if (st.count(p)) return cout << 0 << '\n', 0;
      st.insert(p);
      int id = mp[{v1[i - 1], v1[i]}];
      if (i == 1) f[v1[i - 1]][0] = id;
      if (i == v1.size() - 1) f[v1[i]][1] = id;
      if (1 < i && i < v1.size() - 1) {
        if (f[v1[i]][1] == id) return cout << 0 << '\n', 0;
        if (f[v1[i - 1]][0] == id) return cout << 0 << '\n', 0;
      }
    }
    for (int i = 1; i + 1 < v1.size(); i++) {
      int x = mp[{v1[i - 1], v1[i]}];
      int y = mp[{v1[i + 1], v1[i]}];
      if (nex[v1[i]][x]) return cout << 0 << '\n', 0;
      nex[v1[i]][x] = y;
    }
  }
  for (int i = 1; i <= n; i++) {
    int ted = G[i].size() - (f[i][0] > 0) - (f[i][1] > 0) - nex[i].size();
    for (pair<int, int> p : nex[i]) nex2[p.first] = p.second, bad[p.second] = 1;
    if (f[i][0] && f[i][1]) {
      int v = f[i][0], l = 0;
      while (nex2[v]) v = nex2[v], l++;
      if (v == f[i][1] && l < G[i].size() - 1) return cout << 0 << '\n', 0;
    }
    for (pair<int, int> p : G[i]) {
      int v = p.second;
      if (bad[v]) continue;
      while (1) {
        if (mark[v]) return cout << 0 << '\n', 0;
        mark[v] = 1;
        if (!nex2[v]) break;
        v = nex2[v];
      }
    }
    for (pair<int, int> p : G[i])
      if (!mark[p.second]) return cout << 0 << '\n', 0;
    ans = ans * F[max(ted, 0)] % mod;
    for (pair<int, int> p : G[i])
      nex2[p.second] = mark[p.second] = bad[p.second] = 0;
  }
  cout << ans << "\n";
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.

A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1, and also exists an edge between vertices v1 and vt.

A simple path in a undirected graph is a sequence of not necessarily distinct vertices v1, v2, ..., vt (t > 0), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1 and furthermore each edge occurs no more than once. We'll say that a simple path v1, v2, ..., vt starts at vertex v1 and ends at vertex vt.

You've got a graph consisting of n vertices and m edges, that is a vertex cactus. Also, you've got a list of k pairs of interesting vertices xi, yi, for which you want to know the following information — the number of distinct simple paths that start at vertex xi and end at vertex yi. We will consider two simple paths distinct if the sets of edges of the paths are distinct.

For each pair of interesting vertices count the number of distinct simple paths between them. As this number can be rather large, you should calculate it modulo 1000000007 (109 + 7).

Input

The first line contains two space-separated integers n, m (2 ≤ n ≤ 105; 1 ≤ m ≤ 105) — the number of vertices and edges in the graph, correspondingly. Next m lines contain the description of the edges: the i-th line contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n) — the indexes of the vertices connected by the i-th edge.

The next line contains a single integer k (1 ≤ k ≤ 105) — the number of pairs of interesting vertices. Next k lines contain the list of pairs of interesting vertices: the i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ n; xi ≠ yi) — the indexes of interesting vertices in the i-th pair.

It is guaranteed that the given graph is a vertex cactus. It is guaranteed that the graph contains no loops or multiple edges. Consider the graph vertices are numbered from 1 to n.

Output

Print k lines: in the i-th line print a single integer — the number of distinct simple ways, starting at xi and ending at yi, modulo 1000000007 (109 + 7).

Examples

Input

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

Output

2
2
2
4
4
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f ? x : -x;
}
const long long N = 1e5 + 5, M = 2e5 + 5, mod = 1e9 + 7;
long long tot = 1, ver[M], nxt[M], head[N];
void add(long long u, long long v) {
  ver[++tot] = v;
  nxt[tot] = head[u];
  head[u] = tot;
}
long long tot2, ver2[M], nxt2[M], head2[N];
void Add(long long u, long long v) {
  ver2[++tot2] = v;
  nxt2[tot2] = head2[u];
  head2[u] = tot2;
}
long long dfn[N], low[N], num, bridge[M];
void tarjan(long long u, long long lst) {
  dfn[u] = low[u] = ++num;
  for (long long i = head[u]; i; i = nxt[i]) {
    long long v = ver[i];
    if (!dfn[v]) {
      tarjan(v, i);
      low[u] = min(low[u], low[v]);
      if (low[v] > dfn[u]) bridge[i] = bridge[i ^ 1] = 1;
    } else if (i != (lst ^ 1))
      low[u] = min(low[u], dfn[v]);
  }
}
long long col[N], cnt[N], dcc;
void dfs1(long long u) {
  col[u] = dcc;
  cnt[dcc]++;
  for (long long i = head[u]; i; i = nxt[i]) {
    long long v = ver[i];
    if (bridge[i] || col[v]) continue;
    dfs1(v);
  }
}
long long dis[N];
void dfs2(long long u, long long fa) {
  dis[u] += (cnt[u] > 1);
  for (long long i = head2[u]; i; i = nxt2[i]) {
    long long v = ver2[i];
    if (v == fa) continue;
    dis[v] = dis[u];
    dfs2(v, u);
  }
}
long long dep[N], f[N][30], t = 20;
queue<long long> q;
void bfs(long long st) {
  q.push(st);
  dep[st] = 1;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long i = head2[u]; i; i = nxt2[i]) {
      long long v = ver2[i];
      if (dep[v]) continue;
      dep[v] = dep[u] + 1;
      f[v][0] = u;
      for (long long j = 1; j <= t; j++) f[v][j] = f[f[v][j - 1]][j - 1];
      q.push(v);
    }
  }
}
long long lca(long long u, long long v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (long long i = t; i >= 0; i--)
    if (dep[f[v][i]] >= dep[u]) v = f[v][i];
  if (u == v) return u;
  for (long long i = t; i >= 0; i--)
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  return f[u][0];
}
long long qpow(long long a, long long x) {
  long long res = 1;
  while (x) {
    if (x & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    x >>= 1;
  }
  return res;
}
long long n, m, T;
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= m; i++) {
    long long u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  tarjan(1, -1);
  for (long long i = 1; i <= n; i++) {
    if (!col[i]) {
      dcc++;
      dfs1(i);
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = head[i]; j; j = nxt[j]) {
      long long v = ver[j];
      if (col[i] != col[v]) Add(col[i], col[v]);
    }
  }
  dfs2(1, -1);
  bfs(1);
  T = read();
  while (T--) {
    long long u = col[read()], v = col[read()];
    long long l = lca(u, v);
    printf("%lld\n", qpow(2, dis[u] + dis[v] - dis[l] * 2 + (cnt[l] > 1)));
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).

You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).

You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.

To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

Input

The first line contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of chocolate bars in the shop.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the cost of i-th chocolate bar.

The third line contains one integer m (1 ≤ m ≤ n - 1) — the number of coupons you have.

The fourth line contains m integers q_1, q_2, ..., q_m (2 ≤ q_i ≤ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.

Output

Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.

Example

Input

7
7 1 3 1 4 10 8
2
3 4

Output

27
30

Note

Consider the first example.

If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.

If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  long long int n, s = 0;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  sort(a, a + n, greater<long long int>());
  long long int m, q, s1;
  cin >> m;
  for (int i = 0; i < m; i++) {
    s1 = s;
    cin >> q;
    s1 -= a[q - 1];
    cout << s1 << endl;
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given an array a of n integers.

You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.

Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR).

Input

The first line of input contains the integer n (3 ≤ n ≤ 10^{6}), the size of the array a.

Next line contains n space separated integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 2 ⋅ 10^{6}), representing the elements of the array a.

Output

Output a single integer, the maximum value of the expression given in the statement.

Examples

Input

3
2 4 6

Output

6

Input

4
2 8 4 7

Output

12

Note

In the first example, the only possible triplet is (1, 2, 3). Hence, the answer is 2 | (4 \& 6) = 6.

In the second example, there are 4 possible triplets:

  1. (1, 2, 3), value of which is 2|(8\&4) = 2.
  2. (1, 2, 4), value of which is 2|(8\&7) = 2.
  3. (1, 3, 4), value of which is 2|(4\&7) = 6.
  4. (2, 3, 4), value of which is 8|(4\&7) = 12.

The maximum value hence is 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  int res = 0;
  char ch = ' ';
  while (ch > '9' || ch < '0') ch = getchar();
  while (ch >= '0' && ch <= '9') res *= 10, res += ch - '0', ch = getchar();
  return res;
}
int cnt[2097156];
void insert(int x, int y) {
  if (cnt[x | y] >= 2) return;
  if (x == 0) {
    ++cnt[y];
    return;
  }
  insert(x & x - 1, y | (x & -x)), insert(x & x - 1, y);
}
int n, ans = 0;
int A[2097156];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) A[i] = read();
  for (int i = n, cur; i >= 1; --i) {
    if (i <= n - 2) {
      cur = 0;
      for (int j = 21; j >= 0; --j)
        if ((~A[i] >> j & 1) && cnt[cur | (1 << j)] == 2) cur |= (1 << j);
      ans = max(ans, A[i] | cur);
    }
    insert(A[i], 0);
  }
  cout << ans << endl;
}

```


### Prompt

Generate a cpp solution to the following problem:

It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.

Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.

Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.

Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.

The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.

The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Output

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

Examples

Input

5
2 7 3 4 9
3
1 25 11

Output

1
5
3

Note

For the sample input:

  * The worms with labels from [1, 2] are in the first pile.
  * The worms with labels from [3, 9] are in the second pile.
  * The worms with labels from [10, 12] are in the third pile.
  * The worms with labels from [13, 16] are in the fourth pile.
  * The worms with labels from [17, 25] are in the fifth pile.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long ara[100010];
vector<long long> v;
vector<long long> v1;
long long val, sum, val1;
long long f, l, mid, mid1, res1, res2, s;
long long n, m;
void bs(long long s) {
  f = 0;
  l = n - 1;
  while (f <= l) {
    mid = (f + l) / 2;
    mid1 = mid - 1;
    res1 = ara[mid];
    res2 = ara[mid1];
    if (s < res1 && mid1 < 0) {
      cout << "1";
      break;
    } else if (s < res1 && s < res2)
      l = mid - 1;
    else if (s > res1 && s > res2)
      f = mid + 1;
    else if ((s >= res1 && s >= res2) || (s < res1 && s > res2)) {
      cout << mid + 1;
      break;
    } else {
      l = mid - 1;
    }
  }
}
int main() {
  sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> val;
    sum += val;
    ara[i] = sum;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> val1;
    v1.push_back(val1);
  }
  for (int i = 0; i < m; i++) {
    s = v1.at(i);
    bs(s);
    cout << endl;
  }
}

```


### Prompt

Generate a cpp solution to the following problem:

You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.

You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:

  * (i - 1, j + 1) — only if i > 1,
  * (i, j + 1), or
  * (i + 1, j + 1) — only if i < 3.

However, there are n obstacles blocking your path. k-th obstacle is denoted by three integers ak, lk and rk, and it forbids entering any cell (ak, j) such that lk ≤ j ≤ rk.

You have to calculate the number of different paths from (2, 1) to (2, m), and print it modulo 109 + 7.

Input

The first line contains two integers n and m (1 ≤ n ≤ 104, 3 ≤ m ≤ 1018) — the number of obstacles and the number of columns in the matrix, respectively.

Then n lines follow, each containing three integers ak, lk and rk (1 ≤ ak ≤ 3, 2 ≤ lk ≤ rk ≤ m - 1) denoting an obstacle blocking every cell (ak, j) such that lk ≤ j ≤ rk. Some cells may be blocked by multiple obstacles.

Output

Print the number of different paths from (2, 1) to (2, m), taken modulo 109 + 7. If it is impossible to get from (2, 1) to (2, m), then the number of paths is 0.

Example

Input

2 5
1 3 4
2 2 3

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long s[3];
long long n, m;
struct Data {
  long long a, l, r;
  Data() {}
  Data(long long a, long long l, long long r) : a(a), l(l), r(r) {}
} p[10000 + 10];
bool cmp(const Data& data1, const Data& data2) { return data1.l < data2.l; }
vector<vector<long long> > mul(vector<vector<long long> > A,
                               vector<vector<long long> > B) {
  vector<vector<long long> > C(3, vector<long long>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
      }
    }
  }
  return C;
}
vector<vector<long long> > pow(vector<vector<long long> > A, long long n) {
  vector<vector<long long> > B(3, vector<long long>(3));
  for (int i = 0; i < 3; i++) B[i][i] = 1;
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
inline bool empty() { return (s[0] == -1 && s[1] == -1 && s[2] == -1); }
inline pair<long long, long long> getmin() {
  pair<long long, long long> p = make_pair(-1, -1);
  for (int i = 0; i < 3; i++) {
    if (s[i] > 0 && (p.first == -1 || s[i] < p.first))
      p = make_pair(s[i], i + 3);
  }
  return p;
}
long long solve() {
  sort(p, p + n, cmp);
  s[0] = s[1] = s[2] = -1;
  vector<pair<long long, long long> > v;
  vector<vector<long long> > A(3, vector<long long>(3, 1)),
      res(3, vector<long long>(3, 0));
  A[0][2] = A[2][0] = 0;
  res[0][0] = res[1][1] = res[2][2] = 1;
  for (int i = 0; i < n || !empty(); i++) {
    while (!empty()) {
      pair<long long, long long> pr = getmin();
      if (i >= n || pr.first < p[i].l) {
        v.push_back(pr);
        s[pr.second - 3] = -1;
      } else {
        break;
      }
    }
    if (i < n) {
      if (s[p[i].a] == -1) v.push_back(make_pair(p[i].l, p[i].a));
      s[p[i].a] = max(s[p[i].a], p[i].r);
    }
  }
  long long k = 1;
  for (int i = 0; i <= v.size(); i++) {
    long long nxt = i < v.size() ? v[i].first : m;
    res = mul(pow(A, nxt - k), res);
    k = nxt;
    if (i < v.size()) {
      if (v[i].second >= 3) {
        v[i].second -= 3;
        for (int j = 0; j < 3; j++) A[v[i].second][j] = 1;
        if (v[i].second % 2 == 0) A[v[i].second][2 - v[i].second] = 0;
      } else {
        for (int j = 0; j < 3; j++) A[v[i].second][j] = 0;
      }
    }
  }
  return res[1][1];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> p[i].a >> p[i].l >> p[i].r;
    p[i].a--;
    p[i].l--;
  }
  cout << solve() << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

Output

Output the single number — the number of Alyona's leaves.

Examples

Input

5
birch yellow
maple red
birch yellow
maple yellow
maple green

Output

4

Input

3
oak yellow
oak yellow
oak yellow

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = ~(1 << 31);
int gcd(int a, int b) {
  if (b > a) {
    b += a;
    a = b - a;
    b = b - a;
  }
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  int m;
  cin >> m;
  string s1, s2;
  set<pair<string, string> > a;
  for (int i = 0; i < m; i++) {
    cin >> s1 >> s2;
    a.insert(make_pair(s1, s2));
  }
  cout << a.size() << endl;
  return 0;
}

```