### Prompt

Please formulate a Cpp solution to the following problem:

Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.

You are given n operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.

Input

The first line contains one positive integer n — the number of operations, that have been made by Vasya (1 ≤ n ≤ 100).

The next line contains the string s, consisting of n symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on i-th operation, s_i is equal to "-" (without quotes), if added, s_i is equal to "+" (without quotes).

Output

Print one integer — the minimal possible number of stones that can be in the pile after these n operations.

Examples

Input

3
---

Output

0

Input

4
++++

Output

4

Input

2
-+

Output

1

Input

5
++-++

Output

3

Note

In the first test, if Vasya had 3 stones in the pile at the beginning, after making operations the number of stones will be equal to 0. It is impossible to have less number of piles, so the answer is 0. Please notice, that the number of stones at the beginning can't be less, than 3, because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty).

In the second test, if Vasya had 0 stones in the pile at the beginning, after making operations the number of stones will be equal to 4. It is impossible to have less number of piles because after making 4 operations the number of stones in the pile increases on 4 stones. So, the answer is 4.

In the third test, if Vasya had 1 stone in the pile at the beginning, after making operations the number of stones will be equal to 1. It can be proved, that it is impossible to have less number of stones after making the operations.

In the fourth test, if Vasya had 0 stones in the pile at the beginning, after making operations the number of stones will be equal to 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  int n;
  char s[105];
  cin >> n >> s;
  int ans = 0, cnt;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '-')
      cnt = -1;
    else
      cnt = 1;
    ans += cnt;
    if (ans < 0) ans = 0;
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

Anton goes to school, his favorite lessons are arraystudying. He usually solves all the tasks pretty fast, but this time the teacher gave him a complicated one: given two arrays b and c of length n, find array a, such that:

<image>

where a and b means bitwise AND, while a or b means bitwise OR.

Usually Anton is good in arraystudying, but this problem is too hard, so Anton asks you to help.

Input

The first line of the input contains a single integers n (1 ≤ n ≤ 200 000) — the size of arrays b and c.

The second line contains n integers bi (0 ≤ bi ≤ 109) — elements of the array b.

Third line contains n integers ci (0 ≤ ci ≤ 109) — elements of the array c.

Output

If there is no solution, print  - 1.

Otherwise, the only line of the output should contain n non-negative integers ai — elements of the array a. If there are multiple possible solutions, you may print any of them.

Examples

Input

4
6 8 4 4
16 22 10 10

Output

3 5 1 1

Input

5
8 25 14 7 16
19 6 9 4 25

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int nmax = 200009;
int a[nmax], b[nmax], c[nmax], sum, i, n, used[nmax], bp[nmax], cp[nmax], j,
    flag;
long long st;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    st += b[i];
  }
  for (i = 1; i <= n; ++i) {
    scanf("%d", &c[i]);
    st += c[i];
  }
  if (st % (n + n) == 0)
    sum = st / (n + n);
  else {
    printf("-1\n");
    return 0;
  }
  for (i = 1; i <= n; ++i) {
    if ((b[i] + c[i] - sum) % n) {
      printf("-1\n");
      return 0;
    }
    a[i] = (b[i] + c[i] - sum) / n;
  }
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= 30; ++j)
      if (a[i] & (1 << j)) used[j]++;
  }
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= 30; ++j)
      if (a[i] & (1 << j)) {
        bp[i] += (1 << j) * used[j];
        cp[i] += n * (1 << j);
      } else
        cp[i] += (1 << j) * used[j];
  }
  flag = 1;
  for (i = 1; i <= n; ++i) flag &= (bp[i] == b[i] && cp[i] == c[i]);
  if (flag) {
    for (i = 1; i <= n; ++i) printf("%d\n", a[i]);
  } else
    printf("-1\n");
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:

<image>

In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.

Input

The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.

Output

Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).

Examples

Input

AB
XC
XB
AC

Output

YES

Input

AB
XC
AC
BX

Output

NO

Note

The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.

In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 9;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 8;
char s[5][5], t[5][5];
long long n, m;
void solve() {
  long long i, j;
  cin >> s[1] + 1 >> s[2] + 1 >> t[1] + 1 >> t[2] + 1;
  if (s[2][2] == 'X') swap(s[2][1], s[2][2]);
  if (s[1][2] == 'X') swap(s[1][1], s[1][2]);
  if (s[1][1] == 'X') swap(s[1][1], s[2][1]);
  if (t[2][2] == 'X') swap(t[2][1], t[2][2]);
  if (t[1][2] == 'X') swap(t[1][1], t[1][2]);
  if (t[1][1] == 'X') swap(t[1][1], t[2][1]);
  if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&
      s[2][2] == t[2][2])
    return (void)(cout << "YES" << endl);
  swap(s[1][1], s[2][1]);
  swap(s[1][1], s[1][2]);
  swap(s[1][2], s[2][2]);
  swap(s[2][1], s[2][2]);
  if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&
      s[2][2] == t[2][2])
    return (void)(cout << "YES" << endl);
  swap(s[1][1], s[2][1]);
  swap(s[1][1], s[1][2]);
  swap(s[1][2], s[2][2]);
  swap(s[2][1], s[2][2]);
  if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&
      s[2][2] == t[2][2])
    return (void)(cout << "YES" << endl);
  swap(s[1][1], s[2][1]);
  swap(s[1][1], s[1][2]);
  swap(s[1][2], s[2][2]);
  swap(s[2][1], s[2][2]);
  if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&
      s[2][2] == t[2][2])
    return (void)(cout << "YES" << endl);
  cout << "NO" << endl;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings.

More formally, for each invited person the following conditions should be fulfilled:

  * all his friends should also be invited to the party;
  * the party shouldn't have any people he dislikes;
  * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≤ i < p) are friends.

Help the Beaver find the maximum number of acquaintances he can invite.

Input

The first line of input contains an integer n — the number of the Beaver's acquaintances.

The second line contains an integer k <image> — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> — indices of people who form the i-th pair of friends.

The next line contains an integer m <image> — the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described.

Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time.

The input limitations for getting 30 points are:

  * 2 ≤ n ≤ 14

The input limitations for getting 100 points are:

  * 2 ≤ n ≤ 2000

Output

Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.

Examples

Input

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

Output

3

Note

Let's have a look at the example.

<image>

Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 7;
vector<int> adj[MAX];
bool mark[MAX], group[MAX];
int gr[MAX], fr[MAX];
void dfs(int u, int groupID);
int n, k, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int groupID = 1;
  for (int i = 1; i <= n; ++i) {
    if (!mark[i]) {
      dfs(i, groupID);
      group[groupID] = true;
      ++groupID;
    }
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    if (gr[u] == gr[v]) {
      group[gr[u]] = false;
    }
  }
  memset(fr, 0, sizeof(fr));
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    fr[gr[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    if (group[i]) {
      res = max(res, fr[i]);
    }
  }
  cout << res << "\n";
  return 0;
}
void dfs(int u, int groupID) {
  gr[u] = groupID;
  mark[u] = true;
  int size = adj[u].size();
  for (int i = 0; i < size; ++i) {
    if (!mark[adj[u][i]]) {
      dfs(adj[u][i], groupID);
    }
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.

Constraints

* $1 \leq n \leq 18$
* $0 \leq k \leq n$
* $0 \leq b_i < n$

Input

The input is given in the following format.

$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$

$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.

Output

Print the subsets ordered by their decimal integers. Print a subset in the following format.

$d$: $e_0$ $e_1$ ...

Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.

Example

Input

4
2 0 2

Output

5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3

### Response

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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

void dump(int n) {
		out(n, ':');
		for (int j = 0, t; (t = n >> j); j++)
			if (t & 1)
				out(' ', j);
		outl();
}

typedef vector<int> v;
void enumeration(int t, int i, int n, v &r) {
	if (i >= n) {
		r.push_back(t);
		return;
	}

	if ((t >> i) & 1)
		enumeration(t, i + 1, n, r);
	else {
		enumeration(t, i + 1, n, r);
		enumeration((1 << i) | t, i + 1, n, r);
	}
}

int main() {
	int n = in(), u = 0;
	v r;
	for (int i = in(); i; i--)
		u |= 1 << in();
	enumeration(u, 0, n, r);
	sort(r.begin(), r.end());
	for (int x: r)
		dump(x);
}

```


### Prompt

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

An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated manner, so that any invader would become lost. Each room has at least two doors.

The Ninja House can be modeled by a graph, as shown in Figure l. A circle represents a room. Each line connecting two circles represents a door between two rooms.

<image> Figure l. Graph Model of Ninja House.  |  Figure 2. Ninja House exploration.
---|---

I decided to draw a map, since no map was available. Your mission is to help me draw a map from the record of my exploration.

I started exploring by entering a single entrance that was open to the outside. The path I walked is schematically shown in Figure 2, by a line with arrows. The rules for moving between rooms are described below.

After entering a room, I first open the rightmost door and move to the next room. However, if the next room has already been visited, I close the door without entering, and open the next rightmost door, and so on. When I have inspected all the doors of a room, I go back through the door I used to enter the room.

I have a counter with me to memorize the distance from the first room. The counter is incremented when I enter a new room, and decremented when I go back from a room. In Figure 2, each number in parentheses is the value of the counter when I have entered the room, i.e., the distance from the first room. In contrast, the numbers not in parentheses represent the order of my visit.

I take a record of my exploration. Every time I open a door, I record a single number, according to the following rules.

1. If the opposite side of the door is a new room, I record the number of doors in that room, which is a positive number.
2. If it is an already visited room, say R, I record ``the distance of R from the first room'' minus ``the distance of the current room from the first room'', which is a negative number.

In the example shown in Figure 2, as the first room has three doors connecting other rooms, I initially record ``3''. Then when I move to the second, third, and fourth rooms, which all have three doors, I append ``3 3 3'' to the record. When I skip the entry from the fourth room to the first room, the distance difference ``-3'' (minus three) will be appended, and so on. So, when I finish this exploration, its record is a sequence of numbers ``3 3 3 3 -3 3 2 -5 3 2 -5 -3''.

There are several dozens of Ninja Houses in the city. Given a sequence of numbers for each of these houses, you should produce a graph for each house.

Input

The first line of the input is a single integer n, indicating the number of records of Ninja Houses I have visited. You can assume that n is less than 100. Each of the following n records consists of numbers recorded on one exploration and a zero as a terminator. Each record consists of one or more lines whose lengths are less than 1000 characters. Each number is delimited by a space or a newline. You can assume that the number of rooms for each Ninja House is less than 100, and the number of doors in each room is less than 40.

Output

For each Ninja House of m rooms, the output should consist of m lines. The j-th line of each such m lines should look as follows:

i r1 r2  ... rki

where r1, ... , rki should be rooms adjoining room i, and ki should be the number of doors in room i. Numbers should be separated by exactly one space character. The rooms should be numbered from 1 in visited order. r1, r2, ... , rki should be in ascending order. Note that the room i may be connected to another room through more than one door. In this case, that room number should appear in r1, ... , rki as many times as it is connected by different doors.

Example

Input

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

Output

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

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>
#include <ctime>
#include <list>
#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int num[110];
int vacant[110];

vector<vector<int>> G;

void add_edge(int a, int b){
	G[a].push_back(b);
	G[b].push_back(a);
}

vector<int> rec;

void dfs(int &id, int d, int prv, int &i){
	if (rec.size() == i) return;
	int cur = id;
	int x = rec[i];

	if (x < 0){
		--id;
		add_edge(prv, vacant[d - 1 + x]);
		return;
	}

	if (prv > 0) add_edge(prv, cur);

	num[cur] = x;
	if (G[cur].size() < num[cur]) vacant[d] = cur;
	while (G[cur].size() < num[cur]){
		++id, ++i;
		dfs(id, d + 1, cur, i);
	}
}

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

	int t;
	cin >> t;
	while (t--){
		rec.clear();
		int a;
		while (cin >> a, a) rec.push_back(a);

		G.assign(110, vector<int>());

		int id = 1, i = 0;
		dfs(id, 0, -1, i);
		for (int i = 1; i <= id; ++i){
			sort(ALL(G[i]));
			cout << i;
			for (auto v : G[i]) cout << ' ' << v;
			cout << endl;
		}
	}

	return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

Takahashi and Snuke came up with a game that uses a number sequence, as follows:

* Prepare a sequence of length M consisting of integers between 0 and 2^N-1 (inclusive): a = a_1, a_2, \ldots, a_M.

* Snuke first does the operation below as many times as he likes:

* Choose a positive integer d, and for each i (1 \leq i \leq M), in binary, set the d-th least significant bit of a_i to 0. (Here the least significant bit is considered the 1-st least significant bit.)
* After Snuke finishes doing operations, Takahashi tries to sort a in ascending order by doing the operation below some number of times. Here a is said to be in ascending order when a_i \leq a_{i + 1} for all i (1 \leq i \leq M - 1).

* Choose two adjacent elements of a: a_i and a_{i + 1}. If, in binary, these numbers differ in exactly one bit, swap a_i and a_{i + 1}.

There are 2^{NM} different sequences of length M consisting of integers between 0 and 2^N-1 that can be used in the game.

How many among them have the following property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations? Find the count modulo (10^9 + 7).

Constraints

* All values in input are integers.
* 1 \leq N \leq 5000
* 2 \leq M \leq 5000

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number, modulo (10^9 + 7), of sequences with the property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations.

Examples

Input

2 5

Output

352

Input

2020 530

Output

823277409

### Response

```cpp
//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 5005 /*rem*/
#define mod 1000000007
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
ll pw[maxn];
ll dp[maxn][maxn];
int main() {
	pw[0] = 1;
	for (int i = 1; i < maxn; i++)
		pw[i] = pw[i - 1] * 2 % mod;
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		ll pl = 0;
		for (int j = 1; j <= m; j++) {
			if (i == 1) dp[i][j] = pw[j];
			else {
				dp[i][j] = (j + 1) * dp[i - 1][j] % mod;
				pl *= 2;
				pl += dp[i - 1][j - 1] * (j - 1);
				pl %= mod;
				dp[i][j] = (dp[i][j] + pl) % mod;
			//	}
				/*
					dp[i][j] += dp[i - 1][j - d] * pw[d - 1] % mod * (j - d),
					dp[i][j] %= mod;
				*/
			}
		}
	}
	cout << dp[n][m] << endl;
	return 0;
}

```


### Prompt

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

An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.

To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.

When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.

You are suggested to solve an African crossword and print the word encrypted there.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Output

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

Examples

Input

3 3
cba
bcd
cbc

Output

abcd

Input

5 5
fcofd
ooedo
afaoa
rdcdf
eofsf

Output

codeforces

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  char a[105][105], b[105][105], c[105][105];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
    strcpy(b[i], a[i]);
    strcpy(c[i], a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int flag = 0;
      int k;
      for (k = j + 1; k < m; k++) {
        if (a[i][j] == a[i][k]) {
          a[i][k] = '0';
          flag = 1;
        }
      }
      if (flag == 1) a[i][j] = '0';
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      int flag = 0;
      int k;
      for (k = j + 1; k < n; k++) {
        if (b[j][i] == b[k][i]) {
          b[k][i] = '0';
          flag = 1;
        }
      }
      if (flag == 1) b[j][i] = '0';
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '0' || b[i][j] == '0') c[i][j] = '0';
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] != '0') printf("%c", c[i][j]);
    }
  }
  printf("\n");
  return 0;
}

```


### Prompt

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

Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is a non-empty string of length not more than 10, consisting of lowercase English letters, and pricei (the price of the i-th purchase) is a non-empty string, consisting of digits and dots (decimal points). It is possible that purchases with equal names have different prices.

The price of each purchase is written in the following format. If the price is an integer number of dollars then cents are not written.

Otherwise, after the number of dollars a dot (decimal point) is written followed by cents in a two-digit format (if number of cents is between 1 and 9 inclusively, there is a leading zero).

Also, every three digits (from less significant to the most) in dollars are separated by dot (decimal point). No extra leading zeroes are allowed. The price always starts with a digit and ends with a digit.

For example:

  * "234", "1.544", "149.431.10", "0.99" and "123.05" are valid prices,
  * ".333", "3.33.11", "12.00", ".33", "0.1234" and "1.2" are not valid.

Write a program that will find the total price of all purchases in the given bill.

Input

The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill.

It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.

Output

Print the total price exactly in the same format as prices given in the input.

Examples

Input

chipsy48.32televizor12.390

Output

12.438.32

Input

a1b2c3.38

Output

6.38

Input

aa0.01t0.03

Output

0.04

### Response

```cpp
#include <bits/stdc++.h>
char a[1010];
int tot, cent;
int len;
int getnext(int pos) {
  for (int i = pos + 1; i <= len; i++) {
    if (a[i] == '.') return i;
    if (!('0' <= a[i] && a[i] <= '9')) return 0;
  }
  return 0;
}
int main() {
  scanf("%s", a + 1);
  int i = 0, tmp = 0, next;
  len = strlen(a + 1);
  while (i <= len) {
    if ('0' <= a[i + 1] && a[i + 1] <= '9') {
      i++;
      tmp = 0;
      next = getnext(i);
      if (next == 0) {
        while ('0' <= a[i] && a[i] <= '9') {
          tmp = tmp * 10 + a[i] - '0';
          i++;
        }
        tot += tmp;
      } else {
        tmp = 0;
        while (i < next) tmp = tmp * 10 + a[i] - '0', i++;
        i++;
        while (next && '0' <= a[next + 3] && a[next + 3] <= '9') {
          i = next + 1;
          while (i <= next + 3) {
            tmp = tmp * 10 + a[i] - '0';
            i++;
          }
          next = getnext(next);
        }
        if (!next)
          tot += tmp;
        else {
          tot += tmp;
          tmp = (a[next + 1] - '0') * 10 + a[next + 2] - '0';
          cent += tmp;
          i = next + 3;
        }
      }
    } else
      i++;
  }
  tot += (cent / 100);
  cent %= 100;
  bool st = 0;
  if (tot / 1000 != 0) {
    if (tot / 1000000 != 0) {
      if (tot / 1000000000 != 0) {
        printf("%d", tot / 1000000000);
        tot %= 1000000000;
        st = 1;
      }
      if (st)
        printf(".%03d", tot / 1000000);
      else
        st = 1, printf("%d", tot / 1000000);
      tot %= 1000000;
    }
    if (st)
      printf(".%03d", tot / 1000);
    else
      st = 1, printf("%d", tot / 1000);
    tot %= 1000;
  }
  if (st)
    printf(".%03d", tot);
  else
    st = 1, printf("%d", tot);
  if (cent != 0) printf(".%02d", cent);
}

```


### Prompt

Please create a solution in CPP to the following problem:

You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

Input

The first line contains a single positive integer n (2 ≤ n ≤ 105).

The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.

Output

Print "Yes" if there is such a point, "No" — otherwise.

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

Examples

Input

3
1 1
-1 -1
2 -1

Output

Yes

Input

4
1 1
2 2
-1 1
-2 2

Output

No

Input

3
1 2
2 1
4 60

Output

Yes

Note

In the first example the second point can be removed.

In the second example there is no suitable for the condition point.

In the third example any point can be removed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
void _F(const char *name, T arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename T, typename... Args>
void _F(const char *names, T arg1, Args... args) {
  const char *name = strchr(names, ',');
  cerr.write(names, name - names) << " = " << arg1 << '\n';
  _F(name + 2, args...);
}
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &q) {
  in >> q.first >> q.second;
  return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> &q) {
  out << q.first << " " << q.second;
  return out;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2) {
  return {p1.first + p2.first, p1.second + p2.second};
}
template <typename T1, typename T2>
pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2) {
  return {p1.first - p2.first, p1.second - p2.second};
}
void solve() {
  long long n;
  cin >> n;
  long long x, y, ne = 0, p = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x >> y;
    if (x < 0)
      ne++;
    else
      p++;
  }
  if (ne <= 1 || p <= 1) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  start = clock();
  cout << fixed << setprecision(12);
  for (long long i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.

You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.

Constraints

* 1 ≦ x ≦ 3{,}000
* x is an integer.

Input

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

x

Output

Print the answer.

Examples

Input

1000

Output

ABC

Input

2000

Output

ARC

### Response

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

int main(){
	int x;
  	cin>>x;
	x<1200?cout<<"ABC"<<endl:cout<<"ARC"<<endl;
  	return 0;
}
```


### Prompt

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

For given two sequneces $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$, determine whether all elements of $B$ are included in $A$. Note that, elements of $A$ and $B$ are sorted by ascending order respectively.

Constraints

* $1 \leq n, m \leq 200,000$
* $-1,000,000,000 \leq a_0 < a_1 < ... < a_{n-1} \leq 1,000,000,000$
* $-1,000,000,000 \leq b_0 < b_1 < ... < b_{m-1} \leq 1,000,000,000$

Input

The input is given in the following format.

$n$
$a_0 \; a_1 \; ,..., \; a_{n-1}$
$m$
$b_0 \; b_1 \; ,..., \; b_{m-1}$

The number of elements in $A$ and its elements $a_i$ are given in the first and second lines respectively. The number of elements in $B$ and its elements $b_i$ are given in the third and fourth lines respectively.

Output

Print 1, if $A$ contains all elements of $B$, otherwise 0.

Examples

Input

4
1 2 3 4
2
2 4

Output

1

Input

4
1 2 3 4
3
1 2 5

Output

0

### Response

```cpp
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 1000000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    //ll begin_time=clock();
    //-------------------------------
    int n;cin>>n;
    V<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int m;cin>>m;
    V<ll>b(m);
    for(int i=0;i<m;i++)cin>>b[i];
    map<ll,int>mm;
    for(int i=0;i<n;i++){
        mm[a[i]]++;
    }
    bool abc=1;
    for(int i=0;i<m;i++){
        if(mm[b[i]]==0){
            abc=0;
            break;
        }
    }
    if(abc==0)cout<<0<<endl;
    else cout<<1<<Endl;
    //-------------------------------
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

```


### Prompt

Please formulate a cpp solution to the following problem:

The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that there must be at least 6 square meters per student in a room (that is, the room for n students must have the area of at least 6n square meters). The caretaker can enlarge any (possibly both) side of the room by an arbitrary positive integer of meters. Help him change the room so as all n students could live in it and the total area of the room was as small as possible.

Input

The first line contains three space-separated integers n, a and b (1 ≤ n, a, b ≤ 109) — the number of students and the sizes of the room.

Output

Print three integers s, a1 and b1 (a ≤ a1; b ≤ b1) — the final area of the room and its sizes. If there are multiple optimal solutions, print any of them.

Examples

Input

3 3 5

Output

18
3 6

Input

2 4 4

Output

16
4 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  n *= 6;
  long long a2 = max(a, (n + b - 1) / b), b2 = b;
  long long n2 = a2 * b2;
  for (long long i = a; i <= n;) {
    long long k = (n + i - 1) / i;
    long long r = (k == 1 ? n : (n - 1) / (k - 1));
    long long x = i * max(b, k);
    if (x < n2) {
      n2 = x;
      a2 = i;
      b2 = max(b, k);
    }
    i = r + 1;
  }
  cout << n2 << '\n' << a2 << ' ' << b2 << '\n';
  return 0;
}

```


### Prompt

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

Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.

This time Miroslav laid out n skewers parallel to each other, and enumerated them with consecutive integers from 1 to n in order from left to right. For better cooking, he puts them quite close to each other, so when he turns skewer number i, it leads to turning k closest skewers from each side of the skewer i, that is, skewers number i - k, i - k + 1, ..., i - 1, i + 1, ..., i + k - 1, i + k (if they exist).

For example, let n = 6 and k = 1. When Miroslav turns skewer number 3, then skewers with numbers 2, 3, and 4 will come up turned over. If after that he turns skewer number 1, then skewers number 1, 3, and 4 will be turned over, while skewer number 2 will be in the initial position (because it is turned again).

As we said before, the art of cooking requires perfect timing, so Miroslav wants to turn over all n skewers with the minimal possible number of actions. For example, for the above example n = 6 and k = 1, two turnings are sufficient: he can turn over skewers number 2 and 5.

Help Miroslav turn over all n skewers.

Input

The first line contains two integers n and k (1 ≤ n ≤ 1000, 0 ≤ k ≤ 1000) — the number of skewers and the number of skewers from each side that are turned in one step.

Output

The first line should contain integer l — the minimum number of actions needed by Miroslav to turn over all n skewers. After than print l integers from 1 to n denoting the number of the skewer that is to be turned over at the corresponding step.

Examples

Input

7 2

Output

2
1 6

Input

5 1

Output

2
1 4

Note

In the first example the first operation turns over skewers 1, 2 and 3, the second operation turns over skewers 4, 5, 6 and 7.

In the second example it is also correct to turn over skewers 2 and 5, but turning skewers 2 and 4, or 1 and 5 are incorrect solutions because the skewer 3 is in the initial state after these operations.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int nax = 1000 * 1007;
int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0, curr = 0, index = 0;
  for (int i = 0; i < k + 1; i++) {
    curr = 0;
    int j = i;
    while (j < n) {
      curr++;
      j += (2 * k) + 1;
    }
    if (curr >= ans) {
      ans = curr;
      index = i;
    }
  }
  cout << ans << endl;
  for (int i = index + 1; i <= n; i += (2 * k) + 1) cout << i << " ";
  return 0;
}

```


### Prompt

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

Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by <image>. A Modular Equation, as Hamed's teacher described, is an equation of the form <image> in which a and b are two non-negative integers and x is a variable. We call a positive integer x for which <image> a solution of our equation.

Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.

Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers a and b determines how many answers the Modular Equation <image> has.

Input

In the only line of the input two space-separated integers a and b (0 ≤ a, b ≤ 109) are given.

Output

If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation <image>.

Examples

Input

21 5

Output

2

Input

9435152 272

Output

282

Input

10 10

Output

infinity

Note

In the first sample the answers of the Modular Equation are 8 and 16 since <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, i;
  cin >> a >> b;
  if (a == b) {
    cout << "infinity";
    return 0;
  } else if (b > a) {
    cout << 0;
    return 0;
  }
  long long c = a - b;
  long long sq = sqrt(c);
  long long ans = 0;
  for (i = 1; i <= sq; i++) {
    if (c % i == 0) {
      if (i == (c / i)) {
        if (i > b) ans++;
      } else {
        if (i > b) ans++;
        if ((c / i) > b) ans++;
      }
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Skyscraper "MinatoHarukas"

Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show advertisement on as many vertically adjacent windows as possible. The rent for one floor is proportional to the floor number, that is, the rent per month for the n-th floor is n times that of the first floor. Here, the ground floor is called the first floor in the American style, and basement floors are out of consideration for the renting. In order to help Mr. Port, you should write a program that computes the vertically adjacent floors satisfying his requirement and whose total rental cost per month is exactly equal to his budget.

For example, when his budget is 15 units, with one unit being the rent of the first floor, there are four possible rent plans, 1+2+3+4+5, 4+5+6, 7+8, and 15. For all of them, the sums are equal to 15. Of course in this example the rent of maximal number of the floors is that of 1+2+3+4+5, that is, the rent from the first floor to the fifth floor.

Input

The input consists of multiple datasets, each in the following format.

> b
>

A dataset consists of one line, the budget of Mr. Port b as multiples of the rent of the first floor. b  is a positive integer satisfying 1 < b < 109.

The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 1000.

Output

For each dataset, output a single line containing two positive integers representing the plan with the maximal number of vertically adjacent floors with its rent price exactly equal to the budget of Mr. Port. The first should be the lowest floor number and the second should be the number of floors.

Sample Input

15
16
2
3
9699690
223092870
847288609
900660121
987698769
999999999
0

Output for the Sample Input

1 5
16 1
2 1
1 2
16 4389
129 20995
4112949 206
15006 30011
46887 17718
163837 5994

Example

Input

15
16
2
3
9699690
223092870
847288609
900660121
987698769
999999999
0

Output

1 5
16 1
2 1
1 2
16 4389
129 20995
4112949 206
15006 30011
46887 17718
163837 5994

### Response

```cpp
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

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

    while(1) {
        int b;
        cin >> b;
        if (b == 0) break;
        for (long long w = 100000; w >= 1; --w) {
            long long lh = b - (w * w - w) / 2;
            if (lh > 0 && lh % w == 0) {
                cout << lh / w << " " << w << endl;
                break;
            }
        }
    }
}

```


### Prompt

Generate a cpp solution to the following problem:

Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming.

Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds).

Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent.

After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E — the expected number of crosswords he will be able to solve completely. Can you calculate it?

Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values — in this problem it means that the expected value of the number of solved crosswords can be calculated as E = ∑ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords.

We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P ⋅ Q^{-1} mod (10^9 + 7).

Input

The first line contains two integers n and T (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ T ≤ 2 ⋅ 10^{14}) — the number of crosswords and the time Adilbek has to spend, respectively.

The second line contains n integers t_1, t_2, ..., t_n (1 ≤ t_i ≤ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword.

Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them.

Output

Print one integer — the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P ⋅ Q^{-1} mod (10^9 + 7).

Examples

Input

3 5
2 2 2

Output

750000007

Input

3 5
2 1 2

Output

125000003

Note

The answer for the first sample is equal to 14/8.

The answer for the second sample is equal to 17/8.

### Response

```cpp
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int n, x = 0, y = 0, w = 1, fac[200010], ifac[200010], inv[200010], a[200010];
long long m, sum[200010];
int& qmo(int& x) { return x += (x >> 31) & mod; }
void init(int N) {
  fac[0] = inv[1] = ifac[0] = 1;
  for (int i = 1; i <= N; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 2; i <= N; i++)
    inv[i] = mod - 1ll * inv[mod % i] * (mod / i) % mod;
  for (int i = 1; i <= N; i++) ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
}
int C(int n, int m) {
  if (n < m || m < 0) return 0;
  return 1ll * fac[n] * ifac[n - m] % mod * ifac[m] % mod;
}
int S(int n, long long m) {
  if (n < 0 || m < 0) return 0;
  m = min(1ll * n, m);
  while (x < n) {
    qmo(qmo(w = w + w - mod) -= C(x, y));
    x++;
  }
  while (x > n) {
    w = 1ll * (w - C(x - 1, y) + mod) * inv[2] % mod;
    x--;
  }
  while (y < m) {
    qmo(w += C(x, y + 1) - mod);
    y++;
  }
  while (y > m) {
    qmo(w -= C(x, y));
    y--;
  }
  return w;
}
int main() {
  scanf("%d%lld", &n, &m);
  init(max(n, 2));
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i];
  int res = 0;
  for (int i = 1, nw = inv[2]; i <= n; i++, nw = 1ll * nw * inv[2] % mod) {
    res = (res + 1ll * nw * S(i, m - sum[i])) % mod;
  }
  printf("%d\n", res);
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Andrew plays a game called "Civilization". Dima helps him.

The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a road between any contiguous cities vi and vi + 1 (1 ≤ i < k). The length of the described path equals to (k - 1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.

During the game events of two types take place:

  1. Andrew asks Dima about the length of the longest path in the region where city x lies.
  2. Andrew asks Dima to merge the region where city x lies with the region where city y lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them.

Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.

Input

The first line contains three integers n, m, q (1 ≤ n ≤ 3·105; 0 ≤ m < n; 1 ≤ q ≤ 3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly.

Each of the following m lines contains two integers, ai and bi (ai ≠ bi; 1 ≤ ai, bi ≤ n). These numbers represent the road between cities ai and bi. There can be at most one road between two cities.

Each of the following q lines contains one of the two events in the following format:

  * 1 xi. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city xi (1 ≤ xi ≤ n).
  * 2 xi yi. It is the request Andrew gives to Dima to merge the region that contains city xi and the region that contains city yi (1 ≤ xi, yi ≤ n). Note, that xi can be equal to yi.

Output

For each event of the first type print the answer on a separate line.

Examples

Input

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

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
vector<int> roads[300001];
bool is_in[300001];
int tags[300001];
int dists[300001];
vector<int> tagged[300001];
pair<int, int> tag(int t, int n) {
  tags[n] = t;
  tagged[t].push_back(n);
  is_in[n] = true;
  int max1 = 0;
  vector<int> vs;
  for (auto m : roads[n]) {
    if (is_in[m]) continue;
    pair<int, int> p = tag(t, m);
    max1 = max(max1, p.first);
    vs.push_back(p.second);
  }
  int max2 = 0;
  sort(vs.begin(), vs.end(), greater<int>());
  if (vs.size()) {
    max2 = 1 + vs[0];
    max1 = max(max1, max2);
  }
  if (vs.size() > 1) {
    max1 = max(max1, max2 + 1 + vs[1]);
  }
  return make_pair(max1, max2);
}
int main(int argc, char* argv[]) {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    roads[a].push_back(b);
    roads[b].push_back(a);
  }
  for (int i = 0; i <= 300000; ++i) {
    is_in[i] = false;
    dists[i] = 0;
  }
  for (int i = 0; i <= 300000; ++i)
    if (not is_in[i]) dists[i] = tag(i, i).first;
  for (int i = 0; i < q; ++i) {
    int req;
    scanf("%d", &req);
    if (1 == req) {
      int x;
      scanf("%d", &x);
      printf("%d\n", dists[tags[x]]);
    } else if (2 == req) {
      int x, y;
      scanf("%d %d", &x, &y);
      int tag_x = tags[x], tag_y = tags[y];
      if (tag_x == tag_y) continue;
      int d = max(dists[tag_x], dists[tag_y]);
      d = max(d, 1 + (dists[tag_x] + 1) / 2 + (dists[tag_y] + 1) / 2);
      if (tagged[tag_x].size() < tagged[tag_y].size()) {
        for (int n : tagged[tag_x]) {
          tagged[tag_y].push_back(n);
          tags[n] = tag_y;
        }
        tagged[tag_x].clear();
        dists[tag_y] = d;
      } else {
        for (int n : tagged[tag_y]) {
          tagged[tag_x].push_back(n);
          tags[n] = tag_x;
        }
        tagged[tag_y].clear();
        dists[tag_x] = d;
      }
    }
  }
  return 0;
}

```


### Prompt

Your challenge is to write 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 <iostream>
#include <vector>
using namespace std;

long long n, a[100009], b[100009], c[100009], s[100009], dist[100009], dp[100009]; vector<int>x[100009]; bool used[100009];
vector<pair<long long, long long>>X[200009];

long long dfs(int pos, int depth) {
	used[pos] = true;
	dist[pos] = depth;
	dp[pos] = 1;
	for (int i = 0; i < x[pos].size(); i++) {
		if (used[x[pos][i]] == true) continue;
		dp[pos] += dfs(x[pos][i], depth + 1);
	}
	return dp[pos];
}
void dfs2(int pos, long long depth) {
	if (used[pos] == true) return;
	dist[pos] = depth; used[pos] = true;
	for (int i = 0; i < X[pos].size(); i++) {
		dfs2(X[pos][i].first, depth + X[pos][i].second);
	}
}

int main() {
	cin >> n;
	for (int i = 1; i <= n - 1; i++) {
		cin >> a[i] >> b[i];
		x[a[i]].push_back(b[i]);
		x[b[i]].push_back(a[i]);
	}
	for (int i = 1; i <= n; i++) cin >> s[i];
	dfs(1, 0);
	for (int i = 1; i <= n - 1; i++) {
		if (dist[a[i]] > dist[b[i]]) swap(a[i], b[i]);
		if (s[b[i]] - s[a[i]] == 0) continue;
		else  c[i] = (s[b[i]] - s[a[i]]) / (n - dp[b[i]] * 2);
	}
	for (int i = 1; i <= n - 1; i++) {
		X[a[i]].push_back(make_pair(b[i], c[i]));
		X[b[i]].push_back(make_pair(a[i], c[i]));
	}
	for (int i = 1; i <= n; i++) used[i] = false;
	dfs2(1, 0);
	long long sum = 0; for (int i = 1; i <= n; i++) sum += dist[i];
	for (int i = 1; i <= n - 1; i++) {
		if (c[i] == 0) c[i] = (s[1] - sum) / (n / 2);
	}
	for (int i = 1; i <= n - 1; i++) {
		cout << c[i] << endl;
	}
	return 0;
}
```


### Prompt

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

In some other world, today is the day before Christmas Eve.

Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \leq i \leq N) is p_i yen (the currency of Japan).

He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay?

Constraints

* 2 \leq N \leq 10
* 100 \leq p_i \leq 10000
* p_i is an even number.

Input

Input is given from Standard Input in the following format:

N
p_1
p_2
:
p_N

Output

Print the total amount Mr. Takaha will pay.

Examples

Input

3
4980
7980
6980

Output

15950

Input

4
4320
4320
4320
4320

Output

15120

### Response

```cpp
#include<iostream>
int main(){int n,i,A=0,M=0,p;std::cin>>n;for(i=n;i--;){std::cin>>p;M=M>p?M:p;A+=p;}std::cout<<A-M/2;}
```


### Prompt

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

There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (n + 1) meters, he draws a cross (see picture for clarifications).

John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?

<image> The figure shows the order in which John draws crosses for a square with side 4. The lower left square has two crosses. Overall John paints 17 crosses.

Input

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

The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample.

Output

For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.

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

Examples

Input

3
4 8 100

Output

17
33
401

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool visited[100000];
bool check[100000];
long long int dis[100000];
int gcd(long long int x, long long int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main() {
  long long int t;
  cin >> t;
  long long int a[t];
  for (int j = 0; j < t; j++) {
    long long int n;
    cin >> n;
    long long int d, f, g, ans, m;
    d = (n + 1) + (2 * n) + n - 1;
    f = n + 1;
    g = gcd(d, f);
    m = (f / g);
    ans = ((m * d) / f) + 1;
    a[j] = ans;
  }
  for (int i = 0; i < t; i++) {
    cout << a[i] << endl;
  }
}

```


### Prompt

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

There are N slimes standing on a number line. The i-th slime from the left is at position x_i.

It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.

Niwango will perform N-1 operations. The i-th operation consists of the following procedures:

* Choose an integer k between 1 and N-i (inclusive) with equal probability.
* Move the k-th slime from the left, to the position of the neighboring slime to the right.
* Fuse the two slimes at the same position into one slime.

Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.

Constraints

* 2 \leq N \leq 10^{5}
* 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}
* x_i is an integer.

Input

Input is given from Standard Input in the following format:

N
x_1 x_2 \ldots x_N

Output

Print the answer.

Examples

Input

3
1 2 3

Output

5

Input

12
161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932

Output

750927044

### Response

```cpp
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 100010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;

void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

ll x[100010],ans = 0,sum = 0;
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	inverse();
	for(i=1;i<n;i++){
		sum += inv[i];
		(ans += sum*(x[i] - x[i - 1])%mod) %= mod;
	}
	(ans *= fact[n - 1]) %= mod;
	cout << ans << endl;
}
```


### Prompt

Generate a cpp solution to the following problem:

Alice and Bob have decided to play the game "Rock, Paper, Scissors".

The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a draw. Otherwise, the following rules applied:

  * if one player showed rock and the other one showed scissors, then the player who showed rock is considered the winner and the other one is considered the loser;
  * if one player showed scissors and the other one showed paper, then the player who showed scissors is considered the winner and the other one is considered the loser;
  * if one player showed paper and the other one showed rock, then the player who showed paper is considered the winner and the other one is considered the loser.

Alice and Bob decided to play exactly n rounds of the game described above. Alice decided to show rock a_1 times, show scissors a_2 times and show paper a_3 times. Bob decided to show rock b_1 times, show scissors b_2 times and show paper b_3 times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that a_1 + a_2 + a_3 = n and b_1 + b_2 + b_3 = n.

Your task is to find two numbers:

  1. the minimum number of round Alice can win;
  2. the maximum number of rounds Alice can win.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 10^{9}) — the number of rounds.

The second line of the input contains three integers a_1, a_2, a_3 (0 ≤ a_i ≤ n) — the number of times Alice will show rock, scissors and paper, respectively. It is guaranteed that a_1 + a_2 + a_3 = n.

The third line of the input contains three integers b_1, b_2, b_3 (0 ≤ b_j ≤ n) — the number of times Bob will show rock, scissors and paper, respectively. It is guaranteed that b_1 + b_2 + b_3 = n.

Output

Print two integers: the minimum and the maximum number of rounds Alice can win.

Examples

Input

2
0 1 1
1 1 0

Output

0 1

Input

15
5 5 5
5 5 5

Output

0 15

Input

3
0 0 3
3 0 0

Output

3 3

Input

686
479 178 29
11 145 530

Output

22 334

Input

319
10 53 256
182 103 34

Output

119 226

Note

In the first example, Alice will not win any rounds if she shows scissors and then paper and Bob shows rock and then scissors. In the best outcome, Alice will win one round if she shows paper and then scissors, and Bob shows rock and then scissors.

In the second example, Alice will not win any rounds if Bob shows the same things as Alice each round.

In the third example, Alice always shows paper and Bob always shows rock so Alice will win all three rounds anyway.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  int a1, a2, a3, b1, b2, b3;
  cin >> a1 >> a2 >> a3;
  cin >> b1 >> b2 >> b3;
  int ansm = 0;
  ansm += min(b2, a1) + min(a2, b3) + min(a3, b1);
  int ansmi = 0;
  ansmi = max((b1 - (a1 + a2)), b2 - (a3 + a2));
  ansmi = max(ansmi, b3 - (a1 + a3));
  if (ansmi < 0) ansmi = 0;
  cout << ansmi << " " << ansm;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.

First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.

Input

In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.

In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.

Output

Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.

Examples

Input

5
1 3 2 1 2

Output

3

Input

6
2 1 2 2 4 1

Output

2

Note

In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.

In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<pair<int, bool>> a(n, {0, false});
  set<int> v;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    v.insert(a[i].first);
  }
  for (int i = n - 1; i >= 0; --i) {
    if (v.size() == 1) {
      break;
    }
    if (!a[i].second) {
      a[i].second = true;
      v.erase(a[i].first);
    }
  }
  for (auto i : v) {
    cout << i;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once.

A contiguous substring of string s is a string that can be obtained from s by removing some (possibly zero) characters from the beginning of s and some (possibly zero) characters from the end of s.

Input

The first line contains one integer t (1 ≤ t ≤ 20000) — the number of test cases.

Each test case consists of one line containing the string s (1 ≤ |s| ≤ 200000). It is guaranteed that each character of s is either 1, 2, or 3.

The sum of lengths of all strings in all test cases does not exceed 200000.

Output

For each test case, print one integer — the length of the shortest contiguous substring of s containing all three types of characters at least once. If there is no such substring, print 0 instead.

Example

Input

7
123
12222133333332
112233
332211
12121212
333333
31121

Output

3
3
4
4
0
0
4

Note

Consider the example test:

In the first test case, the substring 123 can be used.

In the second test case, the substring 213 can be used.

In the third test case, the substring 1223 can be used.

In the fourth test case, the substring 3221 can be used.

In the fifth test case, there is no character 3 in s.

In the sixth test case, there is no character 1 in s.

In the seventh test case, the substring 3112 can be used.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int len = 1000000;
int arr[len] = {0};
int siv() {
  for (long long int i = 2; i < len; i++) {
    for (long long int j = i * i; j < len; j += i) {
      arr[j - 1] = 1;
    }
  }
}
long long divis(long long int n) {
  if (n % 2 == 0) {
    return 2;
  } else {
    for (int i = 3; i <= sqrt(n); i++) {
      if (n % i == 0) {
        return i;
      }
    }
  }
  return n;
}
bool chec(string s) {
  int i;
  for (i = 0; i < s.size() - 2; i++) {
    if (s[i] != s[i + 1] && s[i] != s[i + 2] && s[i + 1] != s[i + 2]) {
      return true;
      break;
    }
  }
  return false;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i, j, k, l, x, y, z, sum = 0, o = 0, mind = LLONG_MAX,
                                          maxd, multii;
    vector<long long int> v, vv;
    string s;
    cin >> s;
    set<char> tem(s.begin(), s.end());
    if (tem.size() == 1 || tem.size() == 2) {
      cout << 0 << endl;
    } else if (chec(s) == true) {
      cout << 3 << endl;
    } else {
      y = 0;
      for (i = 0; i < s.size() - 2; i++) {
        if (s[i] != s[i + 1]) {
          j = i + 1;
          x = j;
          j++;
          while (s[x] == s[j]) {
            j++;
            y++;
          }
          y++;
          if (s[i] != s[x] && s[i] != s[j] && j < s.size()) {
            mind = min(mind, 1 + y + 1);
            y = 0;
          }
        }
        y = 0;
      }
      cout << mind << endl;
    }
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c.

You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order.

Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c).

Input

The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≤ x_i ≤ 10^9) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4.

Output

Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

Examples

Input

3 6 5 4

Output

2 1 3

Input

40 40 40 60

Output

20 20 20

Input

201 101 101 200

Output

1 100 100

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, x2, x3, x4;
  cin >> x1 >> x2 >> x3 >> x4;
  int maxi = INT_MIN;
  maxi = max(x1, max(max(x2, x3), x4));
  if (maxi == x1) {
    cout << maxi - x2 << " " << maxi - x3 << " " << maxi - x4;
  } else if (maxi == x2) {
    cout << maxi - x1 << " " << maxi - x3 << " " << maxi - x4;
  } else if (maxi == x3) {
    cout << maxi - x1 << " " << maxi - x2 << " " << maxi - x4;
  } else {
    cout << maxi - x1 << " " << maxi - x2 << " " << maxi - x3;
  }
  return 0;
}

```


### Prompt

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

One day in the IT lesson Anna and Maria learned about the lexicographic order.

String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages.

The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework.

Input

The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).

Output

Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).

Examples

Input

aa
2

Output

a

Input

abc
5

Output

bc

Input

abab
7

Output

b

Note

In the second sample before string "bc" follow strings "a", "ab", "abc", "b".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
set<pair<string, long long> > Set;
string s;
long long k, len;
void work() {
  for (long long i = 0; i < len; i++) {
    string tmp;
    tmp += s[i];
    Set.insert(make_pair(tmp, i));
  }
  pair<string, long long> p;
  while (k--) {
    p = *Set.begin();
    Set.erase(Set.begin());
    if (p.second == len - 1) continue;
    pair<string, long long> t;
    t.first = p.first + s[++p.second];
    t.second = p.second;
    Set.insert(t);
  }
  cout << p.first << endl;
}
int main() {
  while (cin >> s >> k) {
    Set.clear();
    len = s.size();
    if (k > len * (len + 1) / 2) {
      puts("No such line.");
      continue;
    }
    work();
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given a huge integer a consisting of n digits (n is between 1 and 3 ⋅ 10^5, inclusive). It may contain leading zeros.

You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 2).

For example, if a = 032867235 you can get the following integers in a single operation:

  * 302867235 if you swap the first and the second digits;
  * 023867235 if you swap the second and the third digits;
  * 032876235 if you swap the fifth and the sixth digits;
  * 032862735 if you swap the sixth and the seventh digits;
  * 032867325 if you swap the seventh and the eighth digits.

Note, that you can't swap digits on positions 2 and 4 because the positions are not adjacent. Also, you can't swap digits on positions 3 and 4 because the digits have the same parity.

You can perform any number (possibly, zero) of such operations.

Find the minimum integer you can obtain.

Note that the resulting integer also may contain leading zeros.

Input

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

The only line of each test case contains the integer a, its length n is between 1 and 3 ⋅ 10^5, inclusive.

It is guaranteed that the sum of all values n does not exceed 3 ⋅ 10^5.

Output

For each test case print line — the minimum integer you can obtain.

Example

Input

3
0709
1337
246432

Output

0079
1337
234642

Note

In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): 0 \underline{70} 9 → 0079.

In the second test case, the initial integer is optimal.

In the third test case you can perform the following sequence of operations: 246 \underline{43} 2 → 24 \underline{63}42 → 2 \underline{43} 642 → 234642.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long n = s.size();
    queue<char> q1, q2;
    for (long i = 0; i < n; i++) {
      if ((s[i] - '0') % 2)
        q1.push(s[i]);
      else
        q2.push(s[i]);
    }
    string s1 = "";
    while (!q1.empty() && !q2.empty()) {
      s1 += min(q1.front(), q2.front());
      if (q1.front() < q2.front())
        q1.pop();
      else
        q2.pop();
    }
    while (!q1.empty()) {
      s1 += q1.front();
      q1.pop();
    }
    while (!q2.empty()) {
      s1 += q2.front();
      q2.pop();
    }
    cout << s1 << "\n";
  }
}

```


### Prompt

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

You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest.

The track's map is represented by a rectangle n × m in size divided into squares. Each square is marked with a lowercase Latin letter (which means the type of the plot), with the exception of the starting square (it is marked with a capital Latin letters S) and the terminating square (it is marked with a capital Latin letter T). The time of movement from one square to another is equal to 1 minute. The time of movement within the cell can be neglected. We can move from the cell only to side-adjacent ones, but it is forbidden to go beyond the map edges. Also the following restriction is imposed on the path: it is not allowed to visit more than k different types of squares (squares of one type can be visited an infinite number of times). Squares marked with S and T have no type, so they are not counted. But S must be visited exactly once — at the very beginning, and T must be visited exactly once — at the very end.

Your task is to find the path from the square S to the square T that takes minimum time. Among all shortest paths you should choose the lexicographically minimal one. When comparing paths you should lexicographically represent them as a sequence of characters, that is, of plot types.

Input

The first input line contains three integers n, m and k (1 ≤ n, m ≤ 50, n·m ≥ 2, 1 ≤ k ≤ 4). Then n lines contain the map. Each line has the length of exactly m characters and consists of lowercase Latin letters and characters S and T. It is guaranteed that the map contains exactly one character S and exactly one character T.

Pretest 12 is one of the maximal tests for this problem.

Output

If there is a path that satisfies the condition, print it as a sequence of letters — the plot types. Otherwise, print "-1" (without quotes). You shouldn't print the character S in the beginning and T in the end.

Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.

Examples

Input

5 3 2
Sba
ccc
aac
ccc
abT

Output

bcccc

Input

3 4 1
Sxyy
yxxx
yyyT

Output

xxxx

Input

1 3 3
TyS

Output

y

Input

1 4 1
SxyT

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int R, C, KK;
char ssG[N][N];
int stx, sty;
struct nodexx {
  string str;
  int x, y, val;
  nodexx(string str00, int x00, int y00, int val00) {
    str = str00, x = x00, y = y00, val = val00;
  }
  bool operator<(const nodexx t) const {
    int lenaa = str.size(), lenbb = t.str.size();
    if (lenaa - lenbb) return lenaa > lenbb;
    return str > t.str;
  }
};
priority_queue<nodexx> QQ;
set<pair<pair<int, int>, int> > SET;
int has[N][N];
int dirc[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
bool Judge(int x) {
  int cnt = 0;
  while (x > 0) {
    cnt += x % 2;
    x >>= 1;
  }
  return cnt <= KK;
}
string BFS() {
  SET.clear();
  memset(has, 0, sizeof has);
  while (QQ.size()) QQ.pop();
  QQ.push(nodexx("", stx, sty, 0));
  SET.insert(make_pair(make_pair(stx, sty), 0));
  int e, r, c, t;
  while (QQ.size()) {
    nodexx XA = QQ.top();
    QQ.pop();
    for (e = 0; e < 4; e++) {
      r = XA.x + dirc[e][0], c = XA.y + dirc[e][1];
      if (r >= 0 && r < R && c >= 0 && c < C && ssG[r][c] != 'S') {
        if (ssG[r][c] == 'T') return XA.str;
        t = XA.val | (1 << (ssG[r][c] - 'a'));
        if (Judge(t) && SET.count(make_pair(make_pair(r, c), t)) == 0) {
          if (has[r][c] && (has[r][c] & t) == has[r][c]) continue;
          has[r][c] = t;
          SET.insert(make_pair(make_pair(r, c), t));
          QQ.push(nodexx(XA.str + ssG[r][c], r, c, t));
        }
      }
    }
  }
  return "-1";
}
void cyh() { cout << BFS() << endl; }
int main() {
  int e, f;
  while (cin >> R >> C >> KK) {
    for (e = 0; e < R; e++) {
      scanf("%s", ssG[e]);
      for (f = 0; f < C; f++)
        if (ssG[e][f] == 'S') stx = e, sty = f;
    }
    cyh();
  }
  return 0;
}

```


### Prompt

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

We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i.

There is one cursor. The cursor's location ℓ is denoted by an integer in \{0, …, |s|\}, with the following meaning:

  * If ℓ = 0, then the cursor is located before the first character of s.
  * If ℓ = |s|, then the cursor is located right after the last character of s.
  * If 0 < ℓ < |s|, then the cursor is located between s_ℓ and s_{ℓ+1}.

We denote by s_left the string to the left of the cursor and s_right the string to the right of the cursor.

We also have a string c, which we call our clipboard, which starts out as empty. There are three types of actions:

  * The Move action. Move the cursor one step to the right. This increments ℓ once.
  * The Cut action. Set c ← s_right, then set s ← s_left.
  * The Paste action. Append the value of c to the end of the string s. Note that this doesn't modify c.

The cursor initially starts at ℓ = 0. Then, we perform the following procedure:

  1. Perform the Move action once.
  2. Perform the Cut action once.
  3. Perform the Paste action s_ℓ times.
  4. If ℓ = x, stop. Otherwise, return to step 1.

You're given the initial string s and the integer x. What is the length of s when the procedure stops? Since this value may be very large, only find it modulo 10^9 + 7.

It is guaranteed that ℓ ≤ |s| at any time.

Input

The first line of input contains a single integer t (1 ≤ t ≤ 1000) denoting the number of test cases. The next lines contain descriptions of the test cases.

The first line of each test case contains a single integer x (1 ≤ x ≤ 10^6). The second line of each test case consists of the initial string s (1 ≤ |s| ≤ 500). It is guaranteed, that s consists of the characters "1", "2", "3".

It is guaranteed that the sum of x in a single file is at most 10^6. It is guaranteed that in each test case before the procedure will stop it will be true that ℓ ≤ |s| at any time.

Output

For each test case, output a single line containing a single integer denoting the answer for that test case modulo 10^9 + 7.

Example

Input

4
5
231
7
2323
6
333
24
133321333

Output

25
1438
1101
686531475

Note

Let's illustrate what happens with the first test case. Initially, we have s =  231. Initially, ℓ = 0 and c = \varepsilon (the empty string). The following things happen if we follow the procedure above:

  * Step 1, Move once: we get ℓ = 1.
  * Step 2, Cut once: we get s =  2 and c =  31.
  * Step 3, Paste s_ℓ =  2 times: we get s =  23131.
  * Step 4: ℓ = 1 not= x = 5, so we return to step 1.

  * Step 1, Move once: we get ℓ = 2.
  * Step 2, Cut once: we get s =  23 and c =  131.
  * Step 3, Paste s_ℓ =  3 times: we get s =  23131131131.
  * Step 4: ℓ = 2 not= x = 5, so we return to step 1.

  * Step 1, Move once: we get ℓ = 3.
  * Step 2, Cut once: we get s =  231 and c =  31131131.
  * Step 3, Paste s_ℓ =  1 time: we get s =  23131131131.
  * Step 4: ℓ = 3 not= x = 5, so we return to step 1.

  * Step 1, Move once: we get ℓ = 4.
  * Step 2, Cut once: we get s =  2313 and c =  1131131.
  * Step 3, Paste s_ℓ =  3 times: we get s =  2313113113111311311131131.
  * Step 4: ℓ = 4 not= x = 5, so we return to step 1.

  * Step 1, Move once: we get ℓ = 5.
  * Step 2, Cut once: we get s =  23131 and c =  13113111311311131131.
  * Step 3, Paste s_ℓ =  1 times: we get s =  2313113113111311311131131.
  * Step 4: ℓ = 5 = x, so we stop.

At the end of the procedure, s has length 25.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int DIV = 1000000007;
int main(int argc, char* argv[]) {
  FILE* f = stdin;
  int t;
  fscanf(f, "%d", &t);
  vector<char> s(1000000);
  for (int test = 0; test < t; test++) {
    int x;
    fscanf(f, "%d", &x);
    long long len = 0;
    char c = 0;
    while (c < '0' || c > '9') c = fgetc(f);
    while (c >= '0' && c <= '9') {
      s[len] = c;
      len++;
      if (feof(f)) break;
      c = fgetc(f);
    }
    int slenOld = len;
    for (int l = 1; l <= x; l++) {
      long long add = len - l;
      if (add < 0) add += DIV;
      add *= (s[l - 1] - '1');
      len = (len + add) % DIV;
      if (slenOld < x) {
        int slen = std::min((long long)x, add + slenOld);
        for (int i = slenOld; i < slen; i++) s[i] = s[l + (i - slenOld)];
        slenOld = slen;
      }
    }
    printf("%I64d\n", len);
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input

The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Output

Print a single integer — the number of problems the friends will implement on the contest.

Examples

Input

3
1 1 0
1 1 1
1 0 0

Output

2

Input

2
1 0 0
0 1 1

Output

1

Note

In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.

In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int count = 0;
  while (n--) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 2) count++;
  }
  cout << count << endl;
  return 0;
}

```


### Prompt

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

Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.

However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.

Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.

Input

The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).

The following line contains a binary string of length n representing Kevin's results on the USAICO.

Output

Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.

Examples

Input

8
10000011

Output

5

Input

2
01

Output

2

Note

In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.

In the second sample, Kevin can flip the entire string and still have the same score.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  int N, sol = 1;
  std::string S;
  std::cin >> N >> S;
  for (int i = 0; i < N - 1; i++) sol += (S[i] != S[i + 1]);
  std::cout << std::min(N, sol + 2);
  return 0;
}

```


### Prompt

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

You are given a tree consisting of n vertices. A tree is a connected undirected graph with n-1 edges. Each vertex v of this tree has a color assigned to it (a_v = 1 if the vertex v is white and 0 if the vertex v is black).

You have to solve the following problem for each vertex v: what is the maximum difference between the number of white and the number of black vertices you can obtain if you choose some subtree of the given tree that contains the vertex v? The subtree of the tree is the connected subgraph of the given tree. More formally, if you choose the subtree that contains cnt_w white vertices and cnt_b black vertices, you have to maximize cnt_w - cnt_b.

Input

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

The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 1), where a_i is the color of the i-th vertex.

Each of the next n-1 lines describes an edge of the tree. Edge i is denoted by two integers u_i and v_i, the labels of vertices it connects (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i).

It is guaranteed that the given edges form a tree.

Output

Print n integers res_1, res_2, ..., res_n, where res_i is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex i.

Examples

Input

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

Output

2 2 2 2 2 1 1 0 2

Input

4
0 0 1 0
1 2
1 3
1 4

Output

0 -1 1 -1

Note

The first example is shown below:

<image>

The black vertices have bold borders.

In the second example, the best subtree for vertices 2, 3 and 4 are vertices 2, 3 and 4 correspondingly. And the best subtree for the vertex 1 is the subtree consisting of vertices 1 and 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200005];
int col[200005];
int dp1[200005];
int dp2[200005];
void dfs1(int node, int pn) {
  dp1[node] = -1;
  if (col[node]) dp1[node] = 1;
  for (int i = 0; i < adj[node].size(); i++)
    if (adj[node][i] != pn) {
      dfs1(adj[node][i], node);
      if (dp1[adj[node][i]] > 0) dp1[node] += dp1[adj[node][i]];
    }
  return;
}
void dfs2(int node, int pn, int up) {
  dp2[node] = dp1[node] + up;
  for (int i = 0; i < adj[node].size(); i++)
    if (adj[node][i] != pn) {
      int top = dp1[node] - max(0, dp1[adj[node][i]]) + up;
      dfs2(adj[node][i], node, max(top, 0));
    }
  return;
}
int main() {
  int n, x, y;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> col[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(1, -1);
  dfs2(1, -1, 0);
  for (int i = 1; i <= n; i++) cout << dp2[i] << " ";
  cout << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length n, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the corresponding square exists and is empty. The game ends as soon as the sheep are lined up, that is, there should be no empty cells between any sheep.

For example, if n=6 and the level is described by the string "**.*..", then the following game scenario is possible:

  * the sheep at the 4 position moves to the right, the state of the level: "**..*.";
  * the sheep at the 2 position moves to the right, the state of the level: "*.*.*.";
  * the sheep at the 1 position moves to the right, the state of the level: ".**.*.";
  * the sheep at the 3 position moves to the right, the state of the level: ".*.**.";
  * the sheep at the 2 position moves to the right, the state of the level: "..***.";
  * the sheep are lined up and the game ends.

For a given level, determine the minimum number of moves you need to make to complete the level.

Input

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

The first line of each test case contains one integer n (1 ≤ n ≤ 10^6).

The second line of each test case contains a string of length n, consisting of the characters '.' (empty space) and '*' (sheep) — the description of the level.

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

Output

For each test case output the minimum number of moves you need to make to complete the level.

Example

Input

5
6
**.*..
5
*****
3
.*.
3
...
10
*.*...*.**

Output

1
0
0
0
9

### Response

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

int main(){
  long long int t; cin>>t;
  for(long int x=0;x<t;x++){
    long long int n; cin>>n;
    long long int sheep=0;
    char arr[n];
    for(long long int i=0;i<n;i++){
      cin>>arr[i];
      if(arr[i]=='*')sheep++;
    }
    long long int middle=(sheep-1)/2;
    long long int pos_sheep[sheep];
    long long int y=0;
    for(long long int i=0;i<n;i++){
      if(arr[i]=='*'){
        pos_sheep[y]=i;
        y++;
      }
    }
    long long int moves=0;
    for(long long int i=0;i<sheep;i++){
      moves+=abs(pos_sheep[i]-pos_sheep[middle]+(middle-i));
    }
    cout<<moves<<endl;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.

Let's try to make a new task. Firstly we will use the following task. There are n people, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There are n people, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutation p?

More formally, if we denote the handle of the i-th person as hi, then the following condition must hold: <image>.

Input

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

The next n lines each contains two strings. The i-th line contains strings fi and si (1 ≤ |fi|, |si| ≤ 50) — the first name and last name of the i-th person. Each string consists only of lowercase English letters. All of the given 2n strings will be distinct.

The next line contains n distinct integers: p1, p2, ..., pn (1 ≤ pi ≤ n).

Output

If it is possible, output "YES", otherwise output "NO".

Examples

Input

3
gennady korotkevich
petr mitrichev
gaoyuan chen
1 2 3

Output

NO

Input

3
gennady korotkevich
petr mitrichev
gaoyuan chen
3 1 2

Output

YES

Input

2
galileo galilei
nicolaus copernicus
2 1

Output

YES

Input

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
1 2 3 4 5 6 7 8 9 10

Output

NO

Input

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
2 4 9 6 5 7 1 3 8 10

Output

YES

Note

In example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last.

In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n;
  cin >> n;
  string a, b;
  vector<pair<string, string> > name;
  vector<int> pos;
  pos.resize(n);
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    name.push_back(make_pair(a, b));
  }
  for (i = 0; i < n; i++) cin >> pos[i];
  bool dp[100005][2];
  dp[0][0] = true;
  dp[0][1] = true;
  for (i = 1; i < n; i++) {
    j = pos[i] - 1;
    k = pos[i - 1] - 1;
    dp[i][0] = false;
    dp[i][1] = false;
    if (dp[i - 1][0] == true && name[j].first > name[k].first) {
      dp[i][0] = true;
    }
    if (dp[i - 1][1] == true && name[j].first > name[k].second) {
      dp[i][0] = true;
    }
    if (dp[i - 1][0] == true && name[j].second > name[k].first) {
      dp[i][1] = true;
    }
    if (dp[i - 1][1] == true && name[j].second > name[k].second) {
      dp[i][1] = true;
    }
  }
  if (dp[n - 1][0] || dp[n - 1][1])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```