### Prompt

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

After hard work Igor decided to have some rest.

He decided to have a snail. He bought an aquarium with a slippery tree trunk in the center, and put a snail named Julia into the aquarium.

Igor noticed that sometimes Julia wants to climb onto the trunk, but can't do it because the trunk is too slippery. To help the snail Igor put some ropes on the tree, fixing the lower end of the i-th rope on the trunk on the height li above the ground, and the higher end on the height ri above the ground.

For some reason no two ropes share the same position of the higher end, i.e. all ri are distinct. Now Julia can move down at any place of the trunk, and also move up from the lower end of some rope to its higher end. Igor is proud of his work, and sometimes think about possible movements of the snail. Namely, he is interested in the following questions: «Suppose the snail is on the trunk at height x now. What is the highest position on the trunk the snail can get on if it would never be lower than x or higher than y?» Please note that Julia can't move from a rope to the trunk before it reaches the higher end of the rope, and Igor is interested in the highest position on the tree trunk.

Igor is interested in many questions, and not always can answer them. Help him, write a program that answers these questions.

Input

The first line contains single integer n (1 ≤ n ≤ 100000) — the height of the trunk.

The second line contains single integer m (1 ≤ m ≤ 100000) — the number of ropes.

The next m lines contain information about the ropes.

The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the heights on which the lower and the higher ends of the i-th rope are fixed, respectively. It is guaranteed that all ri are distinct.

The next line contains single integer q (1 ≤ q ≤ 100000) — the number of questions.

The next q lines contain information about the questions.

Each of these lines contain two integers x and y (1 ≤ x ≤ y ≤ n), where x is the height where Julia starts (and the height Julia can't get lower than), and y is the height Julia can't get higher than.

Output

For each question print the maximum reachable for Julia height.

Examples

Input

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

Output

2
2
5
5
7

Input

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

Output

2
7
3
3
2
2
5
3
7
10

Note

The picture of the first sample is on the left, the picture of the second sample is on the right. Ropes' colors are just for clarity, they don't mean anything.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using std::max;
using std::min;
using std::sort;
using std::swap;
using std::vector;
const int maxn = 100017;
int val[maxn << 2], tag[maxn << 2];
int N, M, Q;
int rp[maxn];
struct Query {
  int id, x;
};
vector<Query> q[maxn];
int ans[maxn];
struct node {
  int mx, sc, tag;
} tree[maxn << 2];
void pushdown(int i) {
  if (tree[i].tag == 0) return;
  if (tree[(i << 1)].mx > tree[i].sc)
    tree[(i << 1)].mx = tree[(i << 1)].tag = tree[i].tag;
  if (tree[(i << 1 | 1)].mx > tree[i].sc)
    tree[(i << 1 | 1)].mx = tree[(i << 1 | 1)].tag = tree[i].tag;
  tree[i].tag = 0;
  return;
}
void pushup(int i) {
  tree[i].mx = max(tree[(i << 1)].mx, tree[(i << 1 | 1)].mx);
  tree[i].sc = max(tree[(i << 1)].sc, tree[(i << 1 | 1)].sc);
  if (tree[(i << 1)].mx != tree[(i << 1 | 1)].mx)
    tree[i].sc = max(tree[i].sc, min(tree[(i << 1)].mx, tree[(i << 1 | 1)].mx));
  return;
}
void update(int L, int R, int l, int r, int li, int ri, int i) {
  if (li > tree[i].mx) return;
  if (l <= L && R <= r) {
    if (li > tree[i].sc)
      tree[i].mx = tree[i].tag = ri;
    else {
      int mid = L + R >> 1;
      pushdown(i);
      update(L, mid, l, r, li, ri, (i << 1));
      update(mid + 1, R, l, r, li, ri, (i << 1 | 1));
      pushup(i);
    }
  } else {
    int mid = L + R >> 1;
    pushdown(i);
    if (l <= mid) update(L, mid, l, r, li, ri, (i << 1));
    if (r > mid) update(mid + 1, R, l, r, li, ri, (i << 1 | 1));
    pushup(i);
  }
  return;
}
void update(int L, int R, int x, int i) {
  if (L == R) {
    tree[i].mx = x;
    return;
  }
  pushdown(i);
  int mid = L + R >> 1;
  if (x <= mid)
    update(L, mid, x, (i << 1));
  else
    update(mid + 1, R, x, (i << 1 | 1));
  return pushup(i);
}
int query(int L, int R, int x, int i) {
  if (L == R) return tree[i].mx;
  pushdown(i);
  int mid = L + R >> 1;
  if (x <= mid)
    return query(L, mid, x, (i << 1));
  else
    return query(mid + 1, R, x, (i << 1 | 1));
}
int main() {
  scanf("%d%d", &N, &M);
  int x, y;
  for (int i = 1; i <= M; i++) scanf("%d%d", &x, &y), rp[y] = x;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++)
    scanf("%d%d", &x, &y), q[y].push_back((Query){i, x});
  for (int i = 1; i <= N; i++) {
    update(1, N, i, 1);
    if (rp[i]) update(1, N, 1, rp[i], rp[i], i, 1);
    for (int k = 0; k < q[i].size(); k++)
      ans[q[i][k].id] = query(1, N, q[i][k].x, 1);
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).

You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is nice.

A garland is called nice if any two lamps of the same color have distance divisible by three between them. I.e. if the obtained garland is t, then for each i, j such that t_i = t_j should be satisfied |i-j|~ mod~ 3 = 0. The value |x| means absolute value of x, the operation x~ mod~ y means remainder of x when divided by y.

For example, the following garlands are nice: "RGBRGBRG", "GB", "R", "GRBGRBG", "BRGBRGB". The following garlands are not nice: "RR", "RGBG".

Among all ways to recolor the initial garland to make it nice you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

Input

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

The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.

Output

In the first line of the output print one integer r — the minimum number of recolors needed to obtain a nice garland from the given one.

In the second line of the output print one string t of length n — a nice garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

Examples

Input

3
BRB

Output

1
GRB

Input

7
RGBGRBB

Output

3
RGBRGBR

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5;
const int INF = 1e9 + 1e5 + 2;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  map<int, string> mp;
  mp[1] = "RGB";
  mp[2] = "RBG";
  mp[3] = "BRG";
  mp[4] = "BGR";
  mp[5] = "GBR";
  mp[6] = "GRB";
  string second;
  cin >> second;
  int ans = 1e6;
  string anss;
  for (int i = 1; i <= 6; i++) {
    string x = mp[i];
    int sum = 0;
    for (int j = 0; j < n; j += 3) {
      if (x[0] != second[j]) ++sum;
      if (x[1] != second[j + 1] && j + 1 < n) ++sum;
      if (x[2] != second[j + 2] && j + 2 < n) ++sum;
    }
    if (sum < ans) {
      ans = sum;
      anss = x;
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < n / 3; i++) cout << anss;
  int y = n % 3;
  for (int i = 0; i < y; i++) cout << anss[i];
}

```


### Prompt

Create a solution in Cpp for the following problem:

Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants sum of all elements at the odd positions and sum of all elements at the even positions to become equal. The elements that you remove don't have to be consecutive.

For example, if she has a = [1, 0, 1, 0, 0, 0] and she removes 2nd and 4th elements, a will become equal [1, 1, 0, 0] and its alternating sum is 1 - 1 + 0 - 0 = 0.

Help her!

Input

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

The first line of each test case contains a single integer n (2 ≤ n ≤ 10^3, n is even) — length of the array.

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

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

Output

For each test case, firstly, print k (n/2 ≤ k ≤ n) — number of elements that will remain after removing in the order they appear in a. Then, print this k numbers. Note that you should print the numbers themselves, not their indices.

We can show that an answer always exists. If there are several answers, you can output any of them.

Example

Input

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

Output

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

Note

In the first and second cases, alternating sum of the array, obviously, equals 0.

In the third case, alternating sum of the array equals 1 - 1 = 0.

In the fourth case, alternating sum already equals 1 - 1 + 0 - 0 = 0, so we don't have to remove anything.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> ones;
    vector<int> zeros;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 1) {
        ones.push_back(i);
      } else {
        zeros.push_back(i);
      }
    }
    if (ones.size() <= n / 2) {
      cout << n - ones.size() << endl;
      for (int i = 0; i < zeros.size(); i++) {
        cout << 0 << " ";
      }
      cout << endl;
    } else {
      cout << n - (zeros.size() + (ones.size() % 2 == 1)) << endl;
      for (int i = 0; i < ones.size() - (ones.size() % 2 == 1); i++) {
        cout << 1 << " ";
      }
      cout << endl;
    }
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

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

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

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

Input

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

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

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

Output

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

Examples

Input

003512
021

Output

30021

Input

199966633300
63

Output

3036366999

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
int n, m, c[10], d[10], k, b, x, p, a;
char s[N], t[N];
int d1(int k) {
  int c = 0;
  while (k) k /= 10, c++;
  return c;
}
bool d2(int k) {
  memset(d, 0, sizeof d);
  while (k) d[k % 10]++, k /= 10;
  for (int i = 0; i < 10; ++i)
    if (d[i] > c[i]) return 0;
  return true;
}
int main() {
  scanf("%s %s", s, t);
  n = strlen(s), m = strlen(t);
  for (int i = 0; i < n; ++i) c[s[i] - '0']++;
  for (k = N; k > 0; --k)
    if (k + d1(k) == n and d2(k)) break;
  for (int i = 0; i < m; ++i) c[t[i] - '0']--;
  while (k) c[k % 10]--, k /= 10;
  x = t[0] - '0';
  a = (x != 0);
  for (int i = 0; i < 10; ++i) d[i] = c[i];
  for (int i = 0; i < m; ++i) {
    for (int j = 0 + (i == 0); j < t[i] - '0'; ++j)
      if (d[j]) a = 0;
    if (d[t[i] - '0'] == 0 or !a) break;
    d[t[i] - '0']--;
  }
  for (int i = 0; i < m; ++i) {
    if (t[i] > t[0]) {
      b = 0;
      break;
    } else if (t[i] < t[0]) {
      b = 1;
      break;
    }
  }
  for (int i = 1; i < 10; ++i) {
    if (a) {
      printf("%s", t);
      p = 1;
      break;
    }
    if (c[i]) {
      printf("%c", i + '0');
      --c[i];
      break;
    }
    if (!a and i == x and !b) {
      printf("%s", t);
      p = 1;
      break;
    }
  }
  for (int i = 0; i < 10; ++i) {
    if (i == x and b and !p) printf("%s", t), p = 1;
    while (c[i]) printf("%c", i + '0'), --c[i];
    if (i == x and !b and !p) printf("%s", t), p = 1;
  }
  printf("\n");
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a connected undirected simple graph, which has N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects vertices A_i and B_i. Your task is to find a path that satisfies the following conditions:

* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.

It can be proved that such a path always exists. Also, if there are more than one solution, any of them will be accepted.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq A_i < B_i \leq N
* The given graph is connected and simple (that is, for every pair of vertices, there is at most one edge that directly connects them).

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Find one path that satisfies the conditions, and print it in the following format. In the first line, print the count of the vertices contained in the path. In the second line, print a space-separated list of the indices of the vertices, in order of appearance in the path.

Examples

Input

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

Output

4
2 3 1 4

Input

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

Output

7
1 2 3 4 5 6 7

### Response

```cpp
#include<bits/stdc++.h>

int n,m,s,t;

int to[200005],nxt[200005],fst[100005],tot;
void add(int u,int v)
{
    to[++tot]=v;
    nxt[tot]=fst[u];
    fst[u]=tot;
}

bool vis[100005];
int q[200005],l,r;

void extend(int u,int &p,int d)
{
    vis[q[p+=d]=u]=1;
    for(int e=fst[u],v;e;e=nxt[e])
	if(!vis[v=to[e]]){extend(v,p,d);return;}
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int e=1;e<=m;++e)
    {
	scanf("%d%d",&s,&t);
	add(s,t),add(t,s);
    }

    vis[s]=vis[t]=1;
    extend(s,l=100001,-1);
    extend(t,r=100000,1);

    printf("%d\n",r-l+1);
    for(int i=l;i<=r;++i)
	printf("%d ",q[i]);

    return 0;
}
```


### Prompt

Generate a CPP solution to the following problem:

A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.

Write a program which reads a list of N integers and prints the number of prime numbers in the list.

Constraints

1 ≤ N ≤ 10000

2 ≤ an element of the list ≤ 108

Input

The first line contains an integer N, the number of elements in the list.

N numbers are given in the following lines.

Output

Print the number of prime numbers in the given list.

Examples

Input

5
2
3
4
5
6

Output

3

Input

11
7
8
9
10
11
12
13
14
15
16
17

Output

4

### Response

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

bool isPrime(int n){
	if(n <= 1){
		return false;
	}
	for(int i = 2; i*i <= n; i++){
		if(n%i == 0){
			return false;
		}
	}
	return true;
}

int main(){
	int n,c = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int D;
		cin >> D;
		if(isPrime(D)){
			c++;
		}
	}
	cout << c << endl;
	return 0;
}

```


### Prompt

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

Snuke is having a barbeque party.

At the party, he will make N servings of Skewer Meal.

<image>

Example of a serving of Skewer Meal

He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.

To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Constraints

* 1≦N≦100
* 1≦L_i≦100
* For each i, L_i is an integer.

Input

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

N
L_1 L_2 ... L_{2N}

Output

Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.

Examples

Input

2
1 3 1 2

Output

3

Input

5
100 1 2 3 14 15 58 58 58 29

Output

135

### Response

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


### Prompt

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

There is a railroad in Takahashi Kingdom. The railroad consists of N sections, numbered 1, 2, ..., N, and N+1 stations, numbered 0, 1, ..., N. Section i directly connects the stations i-1 and i. A train takes exactly A_i minutes to run through section i, regardless of direction. Each of the N sections is either single-tracked over the whole length, or double-tracked over the whole length. If B_i = 1, section i is single-tracked; if B_i = 2, section i is double-tracked. Two trains running in opposite directions can cross each other on a double-tracked section, but not on a single-tracked section. Trains can also cross each other at a station.

Snuke is creating the timetable for this railroad. In this timetable, the trains on the railroad run every K minutes, as shown in the following figure. Here, bold lines represent the positions of trains running on the railroad. (See Sample 1 for clarification.)

<image>

When creating such a timetable, find the minimum sum of the amount of time required for a train to depart station 0 and reach station N, and the amount of time required for a train to depart station N and reach station 0. It can be proved that, if there exists a timetable satisfying the conditions in this problem, this minimum sum is always an integer.

Formally, the times at which trains arrive and depart must satisfy the following:

* Each train either departs station 0 and is bound for station N, or departs station N and is bound for station 0.
* Each train takes exactly A_i minutes to run through section i. For example, if a train bound for station N departs station i-1 at time t, the train arrives at station i exactly at time t+A_i.
* Assume that a train bound for station N arrives at a station at time s, and departs the station at time t. Then, the next train bound for station N arrives at the station at time s+K, and departs the station at time t+K. Additionally, the previous train bound for station N arrives at the station at time s-K, and departs the station at time t-K. This must also be true for trains bound for station 0.
* Trains running in opposite directions must not be running on the same single-tracked section (except the stations at both ends) at the same time.

Constraints

* 1 \leq N \leq 100000
* 1 \leq K \leq 10^9
* 1 \leq A_i \leq 10^9
* A_i is an integer.
* B_i is either 1 or 2.

Input

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

N K
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print an integer representing the minimum sum of the amount of time required for a train to depart station 0 and reach station N, and the amount of time required for a train to depart station N and reach station 0. If it is impossible to create a timetable satisfying the conditions, print -1 instead.

Examples

Input

3 10
4 1
3 1
4 1

Output

26

Input

1 10
10 1

Output

-1

Input

6 4
1 1
1 1
1 1
1 1
1 1
1 1

Output

12

Input

20 987654321
129662684 2
162021979 1
458437539 1
319670097 2
202863355 1
112218745 1
348732033 1
323036578 1
382398703 1
55854389 1
283445191 1
151300613 1
693338042 2
191178308 2
386707193 1
204580036 1
335134457 1
122253639 1
824646518 2
902554792 2

Output

14829091348

### Response

```cpp
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
using namespace std;
int read(){
	int x=0,f=1,c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f^=1;
	for(; isdigit(c);c=getchar())x=x*10+c-48;
	return f?x:-x;
}
const int N=1<<18;
int n,K;
int a[N],b[N];
ll L[N],R[N],rL[N],rR[N];
ll dpL[N],dpR[N];
void chkmin(int&x,int y){if(y<x)x=y;}
ll cst(ll x,ll y){return y>=x?y-x:y-x+K;}
struct SegT{
	int mn[N<<1];
	void ini(int v){
		for(int i=1;i<(N<<1);++i)mn[i]=v;
	}
	void upd(int l,int r,int v){
		for(l+=N,r+=N;l<r;l>>=1,r>>=1){
			if(l&1)chkmin(mn[l++],v);
			if(r&1)chkmin(mn[--r],v);
		}
	}
	int qry(int x){
		int ans=1<<30;
		for(x+=N;x;x>>=1){
			chkmin(ans,mn[x]);
		}
		return ans;
	}
}segt;
int main(){
	n=read(),K=read();
	for(int i=0;i<n;++i)a[i]=read(),b[i]=read();
	for(int i=0;i<n;++i){
		if(i)L[i]=((L[i-1]-2*a[i-1])%K+K)%K;
		R[i]=((R[i-1]-2*a[i])%K+K)%K;
	}
	for(int i=0;i<n;++i)
		if(b[i]==2)L[i]=0,R[i]=K-1;
		else if(2*a[i]>K){
			puts("-1");return 0;
		}
	vector<int>v;
	for(int i=0;i<n;++i)v.PB(L[i]),v.PB(R[i]);
	v.PB(0),v.PB(K);
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=0;i<n;++i){
		rL[i]=L[i],rR[i]=R[i];
		L[i]=lower_bound(v.begin(),v.end(),rL[i])-v.begin();
		R[i]=lower_bound(v.begin(),v.end(),rR[i])-v.begin();
	}
	dpL[n-1]=dpR[n-1]=0;
	segt.ini(1<<30);
	ll ans=1LL<<60;
	for(int i=n-2;~i;--i){
		if(L[i+1]<=R[i+1]){
			segt.upd(R[i+1]+1,v.size(),i+1);
			segt.upd(0,L[i+1],i+1);
		}else segt.upd(R[i+1]+1,L[i+1],i+1);
		int j;
		j=segt.qry(L[i]);
		if(j>=n)dpL[i]=0;
		else dpL[i]=min(dpL[j]+cst(rL[i],rL[j]),dpR[j]+cst(rL[i],rR[j]));
		j=segt.qry(R[i]);
		if(j>=n)dpR[i]=0;
		else dpR[i]=min(dpL[j]+cst(rR[i],rL[j]),dpR[j]+cst(rR[i],rR[j]));
	}
	segt.ini(1);
	for(int i=0;i<n;++i){
		int j;
		j=-segt.qry(L[i]);
		if(j<0)ans=min(ans,dpL[i]);
		j=-segt.qry(R[i]);
		if(j<0)ans=min(ans,dpR[i]);
		if(L[i]<=R[i]){
			segt.upd(R[i]+1,v.size(),-i);
			segt.upd(0,L[i],-i);
		}else segt.upd(R[i]+1,L[i],-i);
	}
	ll sum=0;
	for(int i=0;i<n;++i)sum+=a[i];
	printf("%lld\n",ans+2*sum);
	return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You are given a string S and an array of strings [t_1, t_2, ..., t_k]. Each string t_i consists of lowercase Latin letters from a to n; S consists of lowercase Latin letters from a to n and no more than 14 question marks.

Each string t_i has its cost c_i — an integer number. The value of some string T is calculated as ∑_{i = 1}^{k} F(T, t_i) ⋅ c_i, where F(T, t_i) is the number of occurences of string t_i in T as a substring. For example, F(aaabaaa, aa) = 4.

You have to replace all question marks in S with pairwise distinct lowercase Latin letters from a to n so the value of S is maximum possible.

Input

The first line contains one integer k (1 ≤ k ≤ 1000) — the number of strings in the array [t_1, t_2, ..., t_k].

Then k lines follow, each containing one string t_i (consisting of lowercase Latin letters from a to n) and one integer c_i (1 ≤ |t_i| ≤ 1000, -10^6 ≤ c_i ≤ 10^6). The sum of lengths of all strings t_i does not exceed 1000.

The last line contains one string S (1 ≤ |S| ≤ 4 ⋅ 10^5) consisting of lowercase Latin letters from a to n and question marks. The number of question marks in S is not greater than 14.

Output

Print one integer — the maximum value of S after replacing all question marks with pairwise distinct lowercase Latin letters from a to n.

Examples

Input

4
abc -10
a 1
b 1
c 3
?b?

Output

5

Input

2
a 1
a 1
?

Output

2

Input

3
a 1
b 3
ab 4
ab

Output

8

Input

1
a -1
?????????????

Output

0

Input

1
a -1
??????????????

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
bool debug = 0;
const int MAXN = 2e5 + 100;
const int LOG = 21;
const int mod = 998244353;
const int MX = (1e7 + 100);
int go[1024][26];
int sufLink[1024];
int leaf[1024];
int top = 1;
void build() {
  memset(sufLink, -1, sizeof sufLink);
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < 26; ++i) {
      int to = go[v][i];
      int suf = sufLink[v] == -1 ? 0 : go[sufLink[v]][i];
      if (to >= 0) {
        sufLink[to] = suf;
        q.push(to);
      } else {
        go[v][i] = suf;
      }
    }
    if (sufLink[v] >= 0) leaf[v] += leaf[sufLink[v]];
  }
}
long long dp[2][1 << 14][1024];
inline pair<int, long long> process_string(int v, const string &a) {
  long long res = 0;
  for (char c : a) {
    v = go[v][c];
    res += leaf[v];
  }
  return {v, res};
}
long long calc_cost[1024];
int calc_pos[1024];
void solve() {
  memset(go, -1, sizeof go);
  int k;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    string a;
    cin >> a;
    int v = 0;
    for (int c : a) {
      c = c - 'a';
      if (go[v][c] == -1) {
        go[v][c] = top++;
      }
      v = go[v][c];
    }
    int cost;
    cin >> cost;
    leaf[v] += cost;
  }
  build();
  string t;
  cin >> t;
  for (char &c : t) {
    if (c == '?') {
      continue;
    }
    c = c - 'a';
  }
  vector<int> pos;
  for (int i = 0; i < (int(t.size())); ++i) {
    if (t[i] == '?') {
      pos.push_back(i);
    }
  }
  long long ans = 0;
  if (pos.empty()) {
    int v = 0;
    for (char c : t) {
      v = go[v][c];
      ans += leaf[v];
    }
    cout << ans << "\n";
    return;
  }
  int st = pos[0];
  for (int i = 0; i < (1 << 14); ++i) {
    fill(dp[0][i], dp[0][i] + 1024, -inf_ll);
    fill(dp[1][i], dp[1][i] + 1024, -inf_ll);
  }
  auto x = process_string(0, t.substr(0, st));
  dp[0][0][x.first] = x.second;
  42;
  for (int i = 0; i < (int(pos.size())); ++i) {
    for (int mask = 0; mask < (1 << 14); ++mask) {
      for (int v = 0; v < top; ++v) {
        if (dp[0][mask][v] != -inf_ll) {
          long long val = dp[0][mask][v];
          for (int c = 0; c < 14; ++c) {
            if (!(mask & (1 << c))) {
              int to = go[v][c];
              dp[1][mask | (1 << c)][to] =
                  max(dp[1][mask | (1 << c)][to], val + leaf[to]);
            }
          }
          dp[0][mask][v] = -inf_ll;
        }
      }
    }
    string to_nxt = "";
    if (i + 1 < (int(pos.size()))) {
      to_nxt = t.substr(pos[i] + 1, pos[i + 1] - pos[i] - 1);
    } else {
      to_nxt = t.substr(pos[i] + 1, (int(t.size())) - pos[i] - 1);
    }
    42;
    for (int v = 0; v < top; ++v) {
      auto x = process_string(v, to_nxt);
      calc_cost[v] = x.second;
      calc_pos[v] = x.first;
    }
    for (int mask = 0; mask < (1 << 14); ++mask) {
      for (int v = 0; v < top; ++v) {
        if (dp[1][mask][v] != -inf_ll) {
          dp[0][mask][calc_pos[v]] =
              max(dp[0][mask][calc_pos[v]], dp[1][mask][v] + calc_cost[v]);
          dp[1][mask][v] = -inf_ll;
        }
      }
    }
  }
  ans = -inf_ll;
  for (int mask = 0; mask < (1 << 14); ++mask) {
    for (int v = 0; v < top; ++v) {
      ans = max(ans, dp[0][mask][v]);
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(2);
  int t = 1;
  while (t--) {
    solve();
  }
  42;
}

```


### Prompt

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

This problem is interactive.

We have hidden a permutation p_1, p_2, ..., p_n of numbers from 1 to n from you, where n is even. You can try to guess it using the following queries:

? k a_1 a_2 ... a_k.

In response, you will learn if the average of elements with indexes a_1, a_2, ..., a_k is an integer. In other words, you will receive 1 if \frac{p_{a_1} + p_{a_2} + ... + p_{a_k}}{k} is integer, and 0 otherwise.

You have to guess the permutation. You can ask not more than 18n queries.

Note that permutations [p_1, p_2, ..., p_k] and [n + 1 - p_1, n + 1 - p_2, ..., n + 1 - p_k] are indistinguishable. Therefore, you are guaranteed that p_1 ≤ n/2.

Note that the permutation p is fixed before the start of the interaction and doesn't depend on your queries. In other words, interactor is not adaptive.

Note that you don't have to minimize the number of queries.

Input

The first line contains a single integer n (2 ≤ n ≤ 800, n is even).

Interaction

You begin the interaction by reading n.

To ask a question about elements on positions a_1, a_2, ..., a_k, in a separate line output

? k a_1 a_2 ... a_k

Numbers in the query have to satisfy 1 ≤ a_i ≤ n, and all a_i have to be different. Don't forget to 'flush', to get the answer.

In response, you will receive 1 if \frac{p_{a_1} + p_{a_2} + ... + p_{a_k}}{k} is integer, and 0 otherwise.

In case your query is invalid or you asked more than 18n queries, the program will print -1 and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

When you determine permutation, output

! p_1 p_2 ... p_n

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

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

Hack format

For the hacks use the following format:

The first line has to contain a single integer n (2 ≤ n ≤ 800, n is even).

In the next line output n integers p_1, p_2, ..., p_n — the valid permutation of numbers from 1 to n. p_1 ≤ n/2 must hold.

Example

Input

2
1 2

Output

? 1 2
? 1 1
! 1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int pos, v, n, k;
  cin >> n >> k;
  map<int, int> m;
  int mx = -1;
  for (int i = 1; i <= k + 1; i++) {
    cout << "? ";
    for (int j = 1; j <= k + 1; j++) {
      if (j != i) cout << j << " ";
    }
    cout << endl;
    cin >> pos >> v;
    m[v]++;
    mx = max(mx, v);
  }
  cout << "! " << m[mx] << "\n";
}

```


### Prompt

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

Lavrenty, a baker, is going to make several buns with stuffings and sell them.

Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-th stuffing. It takes exactly bi grams of stuffing i and ci grams of dough to cook a bun with the i-th stuffing. Such bun can be sold for di tugriks.

Also he can make buns without stuffings. Each of such buns requires c0 grams of dough and it can be sold for d0 tugriks. So Lavrenty can cook any number of buns with different stuffings or without it unless he runs out of dough and the stuffings. Lavrenty throws away all excess material left after baking.

Find the maximum number of tugriks Lavrenty can earn.

Input

The first line contains 4 integers n, m, c0 and d0 (1 ≤ n ≤ 1000, 1 ≤ m ≤ 10, 1 ≤ c0, d0 ≤ 100). Each of the following m lines contains 4 integers. The i-th line contains numbers ai, bi, ci and di (1 ≤ ai, bi, ci, di ≤ 100).

Output

Print the only number — the maximum number of tugriks Lavrenty can earn.

Examples

Input

10 2 2 1
7 3 2 100
12 3 1 10

Output

241

Input

100 1 25 50
15 5 20 10

Output

200

Note

To get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing.

In the second sample Lavrenty should cook 4 buns without stuffings.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000 /HEAP:10000000")
using namespace std;
struct nachinka {
  int a;
  int b;
  int c;
  int d;
};
struct answer {
  vector<int> nach;
  int ans;
};
int main() {
  int i, j, n, m, c0, d0, M, pos;
  nachinka p;
  answer P, nul;
  cin >> n >> m >> c0 >> d0;
  M = c0;
  vector<nachinka> v;
  for (i = 0; i < m; i++) {
    cin >> p.a >> p.b >> p.c >> p.d;
    if (p.c < M) M = p.c;
    v.push_back(p);
  }
  P.nach.assign(m, 0);
  P.ans = 0;
  nul = P;
  vector<answer> dp;
  dp.push_back(P);
  for (i = 1; i <= n; i++) {
    if (i < M) {
      dp.push_back(P);
      continue;
    }
    P.ans = 0;
    pos = -1;
    for (j = 0; j < m; j++)
      if (i >= v[j].c) {
        if (dp[i - v[j].c].ans + v[j].d > P.ans &&
            (dp[i - v[j].c].nach[j] + 1) * v[j].b <= v[j].a) {
          P.ans = dp[i - v[j].c].ans + v[j].d;
          pos = j;
        }
      }
    if (i >= c0 && dp[i - c0].ans + d0 >= P.ans) {
      P.nach = dp[i - c0].nach;
      P.ans = dp[i - c0].ans + d0;
      dp.push_back(P);
    } else if (pos != -1) {
      P.nach = dp[i - v[pos].c].nach;
      P.nach[pos] = dp[i - v[pos].c].nach[pos] + 1;
      dp.push_back(P);
    } else
      dp.push_back(P);
  }
  M = -1;
  for (i = 1; i <= n; i++) M = max(M, dp[i].ans);
  cout << M;
  return 0;
}

```


### Prompt

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

The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson.

Nam created a sequence a consisting of n (1 ≤ n ≤ 105) elements a1, a2, ..., an (1 ≤ ai ≤ 105). A subsequence ai1, ai2, ..., aik where 1 ≤ i1 < i2 < ... < ik ≤ n is called increasing if ai1 < ai2 < ai3 < ... < aik. An increasing subsequence is called longest if it has maximum length among all increasing subsequences.

Nam realizes that a sequence may have several longest increasing subsequences. Hence, he divides all indexes i (1 ≤ i ≤ n), into three groups:

  1. group of all i such that ai belongs to no longest increasing subsequences.
  2. group of all i such that ai belongs to at least one but not every longest increasing subsequence.
  3. group of all i such that ai belongs to every longest increasing subsequence.

Since the number of longest increasing subsequences of a may be very large, categorizing process is very difficult. Your task is to help him finish this job.

Input

The first line contains the single integer n (1 ≤ n ≤ 105) denoting the number of elements of sequence a.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output

Print a string consisting of n characters. i-th character should be '1', '2' or '3' depending on which group among listed above index i belongs to.

Examples

Input

1
4

Output

3

Input

4
1 3 2 5

Output

3223

Input

4
1 5 2 3

Output

3133

Note

In the second sample, sequence a consists of 4 elements: {a1, a2, a3, a4} = {1, 3, 2, 5}. Sequence a has exactly 2 longest increasing subsequences of length 3, they are {a1, a2, a4} = {1, 3, 5} and {a1, a3, a4} = {1, 2, 5}.

In the third sample, sequence a consists of 4 elements: {a1, a2, a3, a4} = {1, 5, 2, 3}. Sequence a have exactly 1 longest increasing subsequence of length 3, that is {a1, a3, a4} = {1, 2, 3}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int lowest[100005];
int latest[100005];
vector<vector<pair<int, int> > > dp(100005);
class segment {
  int holder[100005 * 4];

 public:
  void init() { memset(holder, 0, sizeof(holder)); }
  int update(int k, int l, int r, int pos, int val) {
    if (l == r && l == pos) {
      return holder[k] = val;
    }
    if (l > pos || r < pos) {
      return holder[k];
    }
    return holder[k] = max(update(k * 2, l, (l + r) / 2, pos, val),
                           update(k * 2 + 1, (l + r) / 2 + 1, r, pos, val));
  }
  int find(int k, int l, int r, int a, int b) {
    if (l >= a && r <= b) {
      return holder[k];
    }
    if (l > b || r < a) {
      return 0;
    }
    return max(find(k * 2, l, (l + r) / 2, a, b),
               find(k * 2 + 1, (l + r) / 2 + 1, r, a, b));
  }
};
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= n; i++) {
    lowest[i] = 1000000000;
  }
  int longest = 0;
  for (int i = 0; i < n; i++) {
    int low = 0, high = longest;
    while (low < high) {
      int mid = (low + high) / 2;
      if (arr[i] > lowest[mid]) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    if (arr[i] > lowest[low]) {
      dp[low + 1].push_back(pair<int, int>(i, arr[i]));
      lowest[low + 1] = min(lowest[low + 1], arr[i]);
      longest = max(longest, low + 1);
    } else {
      dp[low].push_back(pair<int, int>(i, arr[i]));
      lowest[low] = arr[i];
    }
  }
  map<int, int> res;
  segment sg;
  sg.init();
  for (int i = 0; i < dp[longest].size(); i++) {
    res[dp[longest][i].first] = (dp[longest].size() == 1) + 2;
    sg.update(1, 1, n, dp[longest][i].first + 1, dp[longest][i].second);
  }
  for (int i = longest - 1; i >= 1; i--) {
    bool b = true;
    int k = -1;
    for (int j = 0; j < dp[i].size(); j++) {
      if (sg.find(1, 1, n, dp[i][j].first + 1, n) <= dp[i][j].second) {
        continue;
      }
      res[dp[i][j].first] = 2;
      sg.update(1, 1, n, dp[i][j].first + 1, dp[i][j].second);
      if (k == -1) {
        k = dp[i][j].first;
      } else {
        b = false;
      }
    }
    for (int j = 0; j < dp[i + 1].size(); j++) {
      sg.update(1, 1, n, dp[i + 1][j].first + 1, 0);
    }
    if (b) {
      res[k] = 3;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << max(1, res[i]);
  }
  return 0;
}

```


### Prompt

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

A palindrome is a string that reads the same backward as forward. For example, the strings "z", "aaa", "aba", and "abccba" are palindromes, but "codeforces" and "ab" are not. You hate palindromes because they give you déjà vu.

There is a string s. You must insert exactly one character 'a' somewhere in s. If it is possible to create a string that is not a palindrome, you should find one example. Otherwise, you should report that it is impossible.

For example, suppose s= "cbabc". By inserting an 'a', you can create "acbabc", "cababc", "cbaabc", "cbabac", or "cbabca". However "cbaabc" is a palindrome, so you must output one of the other options.

Input

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

The only line of each test case contains a string s consisting of lowercase English letters.

The total length of all strings does not exceed 3⋅ 10^5.

Output

For each test case, if there is no solution, output "NO".

Otherwise, output "YES" followed by your constructed string of length |s|+1 on the next line. If there are multiple solutions, you may print any.

You can print each letter of "YES" and "NO" in any case (upper or lower).

Example

Input

6
cbabc
ab
zza
ba
a
nutforajaroftuna

Output

YES
cbabac
YES
aab
YES
zaza
YES
baa
NO
YES
nutforajarofatuna

Note

The first test case is described in the statement.

In the second test case, we can make either "aab" or "aba". But "aba" is a palindrome, so "aab" is the only correct answer.

In the third test case, "zaza" and "zzaa" are correct answers, but not "azza".

In the fourth test case, "baa" is the only correct answer.

In the fifth test case, we can only make "aa", which is a palindrome. So the answer is "NO".

In the sixth test case, "anutforajaroftuna" is a palindrome, but inserting 'a' elsewhere is valid.

### Response

```cpp
#include <bits/stdc++.h>
#include<iostream>
#include<string.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

#define ll long long int
#define ull  unsigned long long
#define lcm(a,b) a*b/__gcd(a,b)
#define gcd(a,b) __gcd(a,b)

//vectors & pairs
#define all(a) a.begin(),a.end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define vi  vector<int>
#define vll  vector<ll>
#define vull  vector<ull>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vpll vector<pair<ll,ll>>
#define vp vector<pair<int,int>>
#define mp make_pair
#define sortVA(a) sort(a.begin(),a.end())
#define sortVD(a) sort(a.rbegin(),a.rend())

//map
#define f first
#define s second

//constants
double PIE = 3.1415926536;
int MOD = 1000000007;
int MAX = (1e9 + 5);
int MIN = -(1e9 + 5);
#define endl "\n"

//loop
#define ff(i,s,e)  for(i=(int)s; i< (int)e; i++)
#define rff(i,s,e) for(i=(int)e; i>=(int)s; i--)
#define vff(a) for(auto x: a)
#define read(a) for(auto &x: a) cin>>x;
#define put(a) for(auto &x: a) cout<<x<<" "; cout<<endl;

// global variables
int i,j;

//helper functions
ll ceil_div(ll x, ll y){
    return (x + y - 1) / y;
}

//coding starts here
void test_cases(){

    string s;
    cin>>s;
    int n=s.length();
    string temp3=s;

    int flag=1;
    ff(i,0,n){
        if(s[i]!='a'){
            flag=0;
        }
    }
    if(flag){
        cout<<"NO"<<endl;
        return;
    }

    cout<<"YES"<<endl;

    string temp2, temp;

    temp2 ='a' + s;
    temp=temp2;
    reverse(all(temp));
    if(temp!=temp2){
        cout<<temp2<<endl;
        return;
    }

    temp2 = s + 'a';
    temp=temp2;
    reverse(all(temp));
    if(temp!=temp2){
        cout<<temp2<<endl;
        return;
    }

    return;
}

int main()
{

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    cin>>T;
    while(T--){
        test_cases();
    }
    return 0;
}

```


### Prompt

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

We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i.

In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y).

We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the minimum total weight of the edges in such a cycle.

Examples

Input

3
1 5
4 2
6 3

Output

7

Input

4
1 5
2 6
3 7
4 8

Output

10

Input

6
19 92
64 64
78 48
57 33
73 6
95 73

Output

227

### Response

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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<pair<int, int>> p;
	long long as = 0, bs = 0, ans = 0;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		p.push_back({a, i});
		p.push_back({b, i});
		as += a;
		bs += b;
	}
	ans = min(as, bs);
	sort(p.begin(), p.end());
	vector<int> e(n);
	for(int i = 0; i < n; i++){
		e[p[i].second] = 1;
	}
	if(find(e.begin(), e.end(), 0) == e.end()){
		int q1, q2, q3, q4, d1, d2;
		if(p[n - 1].second != p[n].second){
			q1 = n - 1, q2 = n;
		}else{
			q1 = n - 1, q2 = n + 1;
		}
		if(p[n - 2].second != p[n].second){
			q3 = n - 2, q4 = n;
		} else{
			q3 = n - 2, q4 = n + 1;
		}
		d1 = p[q2].first - p[q1].first;
		d2 = p[q4].first - p[q3].first;
		if(d1 <= d2) swap(p[q1], p[q2]);
		else swap(p[q3], p[q4]);
	}
	long long sum = 0;
	for(int i = 0; i < n; i++){
		sum += p[i].first;
	}
	ans = min(ans, sum);
	cout << ans << endl;
	return 0;
}
```


### Prompt

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

Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0, 0). Robot can perform the following four kinds of operations:

  * U — move from (x, y) to (x, y + 1);
  * D — move from (x, y) to (x, y - 1);
  * L — move from (x, y) to (x - 1, y);
  * R — move from (x, y) to (x + 1, y).

Vasya also has got a sequence of n operations. Vasya wants to modify this sequence so after performing it the robot will end up in (x, y).

Vasya wants to change the sequence so the length of changed subsegment is minimum possible. This length can be calculated as follows: maxID - minID + 1, where maxID is the maximum index of a changed operation, and minID is the minimum index of a changed operation. For example, if Vasya changes RRRRRRR to RLRRLRL, then the operations with indices 2, 5 and 7 are changed, so the length of changed subsegment is 7 - 2 + 1 = 6. Another example: if Vasya changes DDDD to DDRD, then the length of changed subsegment is 1.

If there are no changes, then the length of changed subsegment is 0. Changing an operation means replacing it with some operation (possibly the same); Vasya can't insert new operations into the sequence or remove them.

Help Vasya! Tell him the minimum length of subsegment that he needs to change so that the robot will go from (0, 0) to (x, y), or tell him that it's impossible.

Input

The first line contains one integer number n~(1 ≤ n ≤ 2 ⋅ 10^5) — the number of operations.

The second line contains the sequence of operations — a string of n characters. Each character is either U, D, L or R.

The third line contains two integers x, y~(-10^9 ≤ x, y ≤ 10^9) — the coordinates of the cell where the robot should end its path.

Output

Print one integer — the minimum possible length of subsegment that can be changed so the resulting sequence of operations moves the robot from (0, 0) to (x, y). If this change is impossible, print -1.

Examples

Input

5
RURUU
-2 3

Output

3

Input

4
RULR
1 1

Output

0

Input

3
UUU
100 100

Output

-1

Note

In the first example the sequence can be changed to LULUU. So the length of the changed subsegment is 3 - 1 + 1 = 3.

In the second example the given sequence already leads the robot to (x, y), so the length of the changed subsegment is 0.

In the third example the robot can't end his path in the cell (x, y).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = ~(1 << 31);
const double EPS = 1e-9;
const double pi = acos(-1);
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
int need[200], have[200];
int main() {
  memset(need, 0, sizeof(need));
  memset(have, 0, sizeof(have));
  int sx = 0, sy = 0;
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (decltype(0) i = (0); i < (n); ++i) {
    if (s[i] == 'U') sy++;
    if (s[i] == 'R') sx++;
    if (s[i] == 'D') sy--;
    if (s[i] == 'L') sx--;
  }
  int ex, ey;
  cin >> ex >> ey;
  int dist = abs(ex - sx) + abs(ey - sy);
  int mn = INF;
  int l = 0, r = 0;
  while (l < n) {
    while (r < n) {
      int px = sx - have['R'] + have['L'], py = sy - have['U'] + have['D'];
      int dist = abs(ex - px) + abs(ey - py);
      if (dist % 2 == (r - l) % 2 && dist <= r - l) break;
      have[s[r]]++;
      r++;
    }
    int px = sx - have['R'] + have['L'], py = sy - have['U'] + have['D'];
    int dist = abs(ex - px) + abs(ey - py);
    if (dist % 2 == (r - l) % 2 && dist <= r - l) mn = min(mn, r - l);
    have[s[l]]--;
    l++;
  }
  if (mn == INF)
    cout << -1 << endl;
  else
    cout << max(mn, 0) << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.

A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:

  * Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
  * For any two indices i and j (i < j), aj must not be divisible by ai.

Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

Input

The input contains a single integer: n (1 ≤ n ≤ 105).

Output

Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.

If there are multiple solutions you can output any one.

Examples

Input

3

Output

2 9 15

Input

5

Output

11 14 20 27 31

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
bool x[10010000];
void sieve() {
  for (int i = 2; i <= 10000000; i++) {
    if (x[i]) continue;
    for (int c = i + i; c <= 10000000; c += i) x[c] = 1;
    primes.push_back(i);
  }
  return;
}
int main() {
  sieve();
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) printf("%d ", primes[i]);
}

```


### Prompt

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

The goal of the 8 puzzle problem is to complete pieces on $3 \times 3$ cells where one of the cells is empty space.

In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 8 as shown below.

1 3 0
4 2 5
7 8 6

You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps).

1 2 3
4 5 6
7 8 0

Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle.

Constraints

* There is a solution.

Input

The $3 \times 3$ integers denoting the pieces or space are given.

Output

Print the fewest steps in a line.

Example

Input

1 3 0
4 2 5
7 8 6

Output

4

### Response

```cpp
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define N 3
#define N2 9
using namespace std;

struct game{
  int b[N2];
  bool operator < (const game &other) const{
    for(int i=0;i<N2;i++){
      if(b[i]<other.b[i]){
        return true;
      }else if(b[i]>other.b[i]){
        return false;
      }
    }
    return false;
  }
};
game g;
map<game,int> checked;
queue<game> q;

void print(game _g){
  for(int i=0;i<N2;i++)
    printf("%d ",_g.b[i]);
  printf("\n");
}

bool clear(game _g){
  for(int i=0;i<N2;i++){
    if(_g.b[i]!=i+1) return false;
  }
  return true;
}

int solve(){
  q.push(g);
  checked.insert(make_pair(g,0));
  int depth;
  while(!q.empty()){
    g=q.front();q.pop();
    depth=checked[g];
    if(clear(g)){ return depth; }
    int w;
    for(int i=0;i<N2;i++){
      if(g.b[i]==N2) {
        w=i;
        break;
      }
    }
    vector<int> v;
    if(w%N<N-1) v.push_back(1);
    if(w%N>0  ) v.push_back(-1);
    if(w/N<N-1) v.push_back(N);
    if(w/N>0  ) v.push_back(-N);
    for(int i:v){
      game gt=g;
      swap(gt.b[w],gt.b[w+i]);
      if(checked.find(gt)==checked.end()){
        q.push(gt);
        checked.insert(make_pair(gt,depth+1));
      }
    }
  }
  return -1;
}

int main(){
  for(int i=0;i<N2;i++) {
    int tmp; cin>>tmp;
    if(tmp==0) tmp=N2;
    g.b[i]=tmp;
  }

  cout<<solve()<<endl;
}
```


### Prompt

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

You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).

Input

The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

Examples

Input

4
7 3 2 1

Output

2

Input

3
1 1 1

Output

3

Note

In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).

In the second example all pairs of indexes (i, j) (where i < j) include in answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n];
  map<long long, int> mp;
  map<long long, int> mp2;
  map<long long, int> mp3;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    for (long long j = 2; j < 1e12; j *= 2) {
      if (j - a[i] == a[i] && mp[a[i]] > 0) {
        mp2[j - a[i]]++;
      } else if (j - a[i] != a[i]) {
        mp3[j - a[i]]++;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (mp2[a[i]] / mp[a[i]]) * (mp[a[i]] - 1);
    ans += mp3[a[i]];
  }
  cout << ans / 2 << endl;
  return 0;
}

```


### Prompt

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

Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcoming birthday present. Yae wasn't very interested in Gachapon itself, but hopefully he would like a match with Jou.

For Gachapon that Yae wants to try, one prize will be given in one challenge. You can see how many types of prizes there are, including those that are out of stock, and how many of each prize remains. However, I don't know which prize will be given in one challenge. Therefore, regardless of the order in which the prizes are given, create a program that outputs the minimum number of challenges required for Yae to get two of the same prizes.

input

The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

N
k1 k2 ... kN

Each dataset has two lines, and the first line is given the integer N (1 ≤ N ≤ 10000), which indicates how many types of prizes there are. The next line is given the integer ki (0 ≤ ki ≤ 10000), which indicates how many prizes are left.

The number of datasets does not exceed 100.

output

For each dataset, the minimum number of challenges required to get two identical prizes is output. However, if it is not possible, NA is output.

Example

Input

2
3 2
3
0 1 1
1
1000
0

Output

3
NA
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,cnt;
	int k[10000];
	bool f;
	while(scanf("%d",&n)&&n){
		cnt=0;
		f=false;
		for(int i=0;i<n;i++)scanf("%d",&k[i]);
		for(int i=0;i<n;i++){
			if(k[i]>0){
				cnt++;
			}
			if(k[i]>1){
				f=true;
			}
		}
		if(f)printf("%d\n",cnt+1);
		else printf("NA\n");
	}
}
```


### Prompt

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

Yaroslav calls an array of r integers a1, a2, ..., ar good, if it meets the following conditions: |a1 - a2| = 1, |a2 - a3| = 1, ..., |ar - 1 - ar| = 1, |ar - a1| = 1, at that <image>.

An array of integers b1, b2, ..., br is called great, if it meets the following conditions:

  1. The elements in it do not decrease (bi ≤ bi + 1).
  2. If the inequalities 1 ≤ r ≤ n and 1 ≤ bi ≤ m hold.
  3. If we can rearrange its elements and get at least one and at most k distinct good arrays.

Yaroslav has three integers n, m, k. He needs to count the number of distinct great arrays. Help Yaroslav! As the answer may be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Two arrays are considered distinct if there is a position in which they have distinct numbers.

Input

The single line contains three integers n, m, k (1 ≤ n, m, k ≤ 100).

Output

In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7).

Examples

Input

1 1 1

Output

0

Input

3 3 3

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int NN = 110;
const int MM = 55;
int dp[MM][MM][MM][NN], c[NN][NN];
void add(int &u, int v) {
  u += v;
  if (u >= mod) u -= mod;
}
int main() {
  for (int i = (0); i < (NN); i++)
    for (int j = (0); j < (i + 1); j++) {
      c[i][j] = (i == 0 || j == 0) ? 1 : (c[i - 1][j] + c[i - 1][j - 1]);
      c[i][j] = min(c[i][j], NN);
    }
  int N, M, K, ans = 0, i, s, lst, w, res, nxt;
  scanf("%d%d%d", &N, &M, &K);
  dp[0][0][0][1] = 1;
  for (i = 0; i < M && i <= N / 2; i++) {
    for (s = 0; s <= N / 2; s++) {
      for (lst = 0; lst <= N / 2; lst++) {
        for (w = 1; w <= K; w++) {
          res = dp[i][s][lst][w];
          if (!res) continue;
          if (i > 0) add(ans, 1LL * res * (M - i) % mod);
          for (nxt = 1; nxt + s <= N / 2; nxt++) {
            int ww = w * c[lst + nxt - 1][nxt - 1];
            if (ww <= K) add(dp[i + 1][s + nxt][nxt][ww], res);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.

The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.

<image>

The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.

<image>

Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.

Input

The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ r1, r2, c1, c2, d1, d2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.

<image>

Output

Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).

If there are several solutions, output any.

Examples

Input

3 7
4 6
5 5

Output

1 2
3 4

Input

11 10
13 8
5 16

Output

4 7
9 1

Input

1 2
3 4
5 6

Output

-1

Input

10 10
10 10
10 10

Output

-1

Note

Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int r1, r2, c1, c2, d1, d2;
void fun() {
  int val1, val2, val3, val4;
  for (int i = 1; i < 10; i++) {
    val1 = i;
    val2 = r1 - val1;
    val3 = c1 - val1;
    val4 = c2 - val2;
    if (val1 == val2 || val1 == val3 || val1 == val4 || val2 == val3 ||
        val3 == val4 || val3 == val4 || val2 == val4 || val1 < 1 || val2 < 1 ||
        val3 < 1 || val4 < 1 || val1 > 9 || val2 > 9 || val3 > 9 || val4 > 9)
      continue;
    if (val1 + val2 == r1 && val1 + val3 == c1 && val1 + val4 == d1 &&
        val2 + val3 == d2 && val2 + val4 == c2 && val3 + val4 == r2) {
      cout << val1 << " " << val2 << endl << val3 << " " << val4 << endl;
      return;
    }
  }
  cout << -1 << endl;
  return;
}
int main() {
  cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
  fun();
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a matrix a, consisting of n rows and m columns. Each cell contains an integer in it.

You can change the order of rows arbitrarily (including leaving the initial order), but you can't change the order of cells in a row. After you pick some order of rows, you traverse the whole matrix the following way: firstly visit all cells of the first column from the top row to the bottom one, then the same for the second column and so on. During the traversal you write down the sequence of the numbers on the cells in the same order you visited them. Let that sequence be s_1, s_2, ..., s_{nm}.

The traversal is k-acceptable if for all i (1 ≤ i ≤ nm - 1) |s_i - s_{i + 1}| ≥ k.

Find the maximum integer k such that there exists some order of rows of matrix a that it produces a k-acceptable traversal.

Input

The first line contains two integers n and m (1 ≤ n ≤ 16, 1 ≤ m ≤ 10^4, 2 ≤ nm) — the number of rows and the number of columns, respectively.

Each of the next n lines contains m integers (1 ≤ a_{i, j} ≤ 10^9) — the description of the matrix.

Output

Print a single integer k — the maximum number such that there exists some order of rows of matrix a that it produces an k-acceptable traversal.

Examples

Input

4 2
9 9
10 8
5 3
4 3

Output

5

Input

2 4
1 2 3 4
10 3 7 3

Output

0

Input

6 1
3
6
2
5
1
4

Output

3

Note

In the first example you can rearrange rows as following to get the 5-acceptable traversal:

    5 3
    10 8
    4 3
    9 9

Then the sequence s will be [5, 10, 4, 9, 3, 8, 3, 9]. Each pair of neighbouring elements have at least k = 5 difference between them.

In the second example the maximum k = 0, any order is 0-acceptable.

In the third example the given order is already 3-acceptable, you can leave it as it is.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 18;
const int M = 100 * 1000 + 13;
const int INF = 1e9;
int dp[1 << N][N];
int n, m;
int a[N][M];
int mn1[N][N], mn2[N][N];
int calc(int mask, int v) {
  if (dp[mask][v] != -1) return dp[mask][v];
  dp[mask][v] = 0;
  for (int u = 0; u < int(n); u++)
    if (v != u && ((mask >> u) & 1))
      dp[mask][v] = max(dp[mask][v], min(mn1[u][v], calc(mask ^ (1 << v), u)));
  return dp[mask][v];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < int(n); i++)
    for (int j = 0; j < int(m); j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < int(n); i++)
    for (int j = 0; j < int(n); j++) {
      int val = INF;
      for (int k = 0; k < int(m); k++) val = min(val, abs(a[i][k] - a[j][k]));
      mn1[i][j] = val;
      val = INF;
      for (int k = 0; k < int(m - 1); k++)
        val = min(val, abs(a[i][k] - a[j][k + 1]));
      mn2[i][j] = val;
    }
  int ans = 0;
  for (int i = 0; i < int(n); i++) {
    memset(dp, -1, sizeof(dp));
    for (int j = 0; j < int(n); j++) dp[1 << j][j] = (j == i ? INF : 0);
    for (int j = 0; j < int(n); j++)
      ans = max(ans, min(mn2[j][i], calc((1 << n) - 1, j)));
  }
  printf("%d\n", ans);
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given a positive integer n. Let's build a graph on vertices 1, 2, ..., n in such a way that there is an edge between vertices u and v if and only if <image>. Let d(u, v) be the shortest distance between u and v, or 0 if there is no path between them. Compute the sum of values d(u, v) over all 1 ≤ u < v ≤ n.

The gcd (greatest common divisor) of two positive integers is the maximum positive integer that divides both of the integers.

Input

Single integer n (1 ≤ n ≤ 107).

Output

Print the sum of d(u, v) over all 1 ≤ u < v ≤ n.

Examples

Input

6

Output

8

Input

10

Output

44

Note

All shortest paths in the first example:

  * <image>
  * <image>
  * <image>
  * <image>
  * <image>
  * <image>

There are no paths between other pairs of vertices.

The total distance is 2 + 1 + 1 + 2 + 1 + 1 = 8.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int phi[N], fen[N], f[N];
bool pr[N];
void upd(int p, int vl) {
  for (p++; p < N; p += p & -p) fen[p] += vl;
  return;
}
int get(int p) {
  int res = 0;
  for (; p > 0; p -= p & -p) res += fen[p];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    phi[i] += i;
    if (!pr[i]) f[i] = i;
    for (int j = 2 * i; j <= n; j += i) {
      phi[j] -= phi[i];
      if (i - 1) pr[j] = true;
      if (f[j] == 0 && i > 1) f[j] = i;
    }
    if (i - 1) sum += phi[i];
  }
  int r = 1;
  for (int i = 2; i <= n; i++) {
    if (!pr[i] && 2 * i > n) r++;
  }
  sum -= 1LL * r * (r - 1) / 2 + 1LL * r * (n - r);
  sum = 1LL * (n - r) * (n - r - 1) / 2 - sum;
  ans += 1LL * (n - r) * (n - r - 1) / 2;
  long long k = 0;
  for (int i = 2; i <= n; i++) {
    int p = f[i];
    k += get(n / p + 1);
    upd(p, 1);
  }
  ans += k - sum;
  ans += 2LL * (1LL * (n - r) * (n - r - 1) / 2 - k);
  cout << ans << endl;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.

Input

First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».

Output

Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.

Examples

Input

2 2
AG
CT

Output

AG
CT

Input

3 5
AGCAG
AGCAG
AGCAG

Output

TGCAT
CATGC
TGCAT

Note

In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, ma;
vector<string> en;
vector<string> res;
vector<string> can;
int che(int i, char c1, char c2) {
  int c = 0;
  int j;
  for (j = 0; j < m; j += 2)
    if (en[i][j] == c1) c++;
  for (j = 1; j < m; j += 2)
    if (en[i][j] == c2) c++;
  return c;
}
int che2(int j, char c1, char c2) {
  int c = 0;
  int i;
  for (i = 0; i < n; i += 2)
    if (en[i][j] == c1) c++;
  for (i = 1; i < n; i += 2)
    if (en[i][j] == c2) c++;
  return c;
}
void p1(int i, char c1, char c2) {
  int j;
  for (j = 0; j < m; j += 2) can[i][j] = c1;
  for (j = 1; j < m; j += 2) can[i][j] = c2;
}
void p2(int j, char c1, char c2) {
  int i;
  for (i = 0; i < n; i += 2) can[i][j] = c1;
  for (i = 1; i < n; i += 2) can[i][j] = c2;
}
void fu(char c1, char c2, char c3, char c4) {
  int i, mc = 0, ca1, ca2;
  for (i = 0; i < n; i += 2) {
    ca1 = che(i, c1, c2);
    ca2 = che(i, c2, c1);
    if (ca1 > ca2) {
      mc += ca1;
      p1(i, c1, c2);
    } else {
      mc += ca2;
      p1(i, c2, c1);
    }
  }
  for (i = 1; i < n; i += 2) {
    ca1 = che(i, c3, c4);
    ca2 = che(i, c4, c3);
    if (ca1 > ca2) {
      mc += ca1;
      p1(i, c3, c4);
    } else {
      mc += ca2;
      p1(i, c4, c3);
    }
  }
  if (mc > ma) {
    ma = mc;
    res = can;
  }
  mc = 0;
  for (i = 0; i < m; i += 2) {
    ca1 = che2(i, c1, c2);
    ca2 = che2(i, c2, c1);
    if (ca1 > ca2) {
      mc += ca1;
      p2(i, c1, c2);
    } else {
      mc += ca2;
      p2(i, c2, c1);
    }
  }
  for (i = 1; i < m; i += 2) {
    ca1 = che2(i, c3, c4);
    ca2 = che2(i, c4, c3);
    if (ca1 > ca2) {
      mc += ca1;
      p2(i, c3, c4);
    } else {
      mc += ca2;
      p2(i, c4, c3);
    }
  }
  if (mc > ma) {
    ma = mc;
    res = can;
  }
}
int main() {
  cin >> n >> m;
  en.resize(n);
  can.resize(n);
  int i, ma = 0;
  for (i = 0; i < n; i++) {
    cin >> en[i];
    can[i] = en[i];
  }
  fu('G', 'C', 'T', 'A');
  fu('G', 'T', 'C', 'A');
  fu('G', 'A', 'T', 'C');
  fu('A', 'C', 'G', 'T');
  fu('T', 'C', 'G', 'A');
  fu('T', 'A', 'G', 'C');
  for (i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.

On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once.

Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.

As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.

Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies.

Valentine wants to choose such genre x (1 ≤ x ≤ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum.

Input

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres.

The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence.

Output

Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.

Examples

Input

10 3
1 1 2 3 2 3 3 1 1 3

Output

3

Input

7 3
3 1 3 2 3 1 2

Output

1

Note

In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses.

In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int Max = 110000;
int maxz(int x, int y) { return x > y ? x : y; }
int minz(int x, int y) { return x < y ? x : y; }
int a[123456];
int b[123456];
int num[123456];
int main() {
  int T, n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  int u = 1;
  for (i = 1; i < n; i++)
    if (a[i] != a[i - 1]) a[u++] = a[i];
  num[a[0]] = 1;
  for (i = 1; i < u - 1; i++) {
    num[a[i]]++;
    if (a[i - 1] == a[i + 1]) b[a[i]]++;
  }
  num[a[i]]++;
  int minn = 123456;
  int k = 0;
  for (i = 1; i <= m; i++)
    if (u - 1 - num[i] - b[i] < minn) {
      minn = u - 1 - num[i] - b[i];
      k = i;
    }
  printf("%d\n", k);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given a tree with N vertices 1,2,\ldots,N, and positive integers c_1,c_2,\ldots,c_N. The i-th edge in the tree (1 \leq i \leq N-1) connects Vertex a_i and Vertex b_i.

We will write a positive integer on each vertex in T and calculate our score as follows:

* On each edge, write the smaller of the integers written on the two endpoints.
* Let our score be the sum of the integers written on all the edges.

Find the maximum possible score when we write each of c_1,c_2,\ldots,c_N on one vertex in T, and show one way to achieve it. If an integer occurs multiple times in c_1,c_2,\ldots,c_N, we must use it that number of times.

Constraints

* 1 \leq N \leq 10000
* 1 \leq a_i,b_i \leq N
* 1 \leq c_i \leq 10^5
* The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}
c_1 \ldots c_N

Output

Use the following format:

M
d_1 \ldots d_N

where M is the maximum possible score, and d_i is the integer to write on Vertex i. d_1,d_2,\ldots,d_N must be a permutation of c_1,c_2,\ldots,c_N. If there are multiple ways to achieve the maximum score, any of them will be accepted.

Examples

Input

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

Output

10
1 2 3 4 5

Input

5
1 2
1 3
1 4
1 5
3141 59 26 53 59

Output

197
59 26 3141 59 53

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int a[10005],b[10005];
int c[10005];
int d[10005];
bool v[10005];
vector<int> G[10005];
int N;
void bfs(int x){
	queue<int> que;
	que.push(x);
	while(que.size()){
		int t=que.front(); que.pop();
		for(int i=0;i<G[t].size();i++){
			int e=G[t][i];
			//cout<<e<<"  ";
			if(v[e]==false){
				que.push(e);
				v[e]=true;
				d[e]=c[N];
				N--;
				//cout<<e<<endl;
			}
		}
	}
}
int main(void){
	int n; cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>a[i]>>b[i];
		G[a[i]-1].push_back(b[i]-1); G[b[i]-1].push_back(a[i]-1);
	}
	for(int i=0;i<n;i++){
		cin>>c[i];
		ans+=c[i];
	}
	sort(c,c+n);
	ans-=c[n-1];
	N=n-1;
	d[0]=c[N];
	N--;
	v[0]=true;
	bfs(0);
	cout<<ans<<endl;
	for(int i=0;i<n;i++){
		cout<<d[i];
		if(i!=n-1){
			cout<<" ";
		}
	}
	cout<<endl;

}

```


### Prompt

Please formulate a Cpp solution to the following problem:

In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.

Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.

Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.

Input

First line of input contains single integer number n (2 ≤ n ≤ 100 000) — number of inflorescences.

Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≤ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.

Output

Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.

Examples

Input

3
1 1

Output

1

Input

5
1 2 2 2

Output

3

Input

18
1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4

Output

4

Note

In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.

In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool visited[100005];
bool lvl[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, p;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p;
    adj[p].push_back(i);
    adj[i].push_back(p);
  }
  int maxl = 0;
  queue<pair<int, int> > q;
  q.push({1, 1});
  visited[1] = true;
  while (!q.empty()) {
    int cur = q.front().first;
    int l = q.front().second;
    maxl = max(maxl, l);
    lvl[l] = !lvl[l];
    q.pop();
    for (int y : adj[cur]) {
      if (!visited[y]) {
        q.push({y, l + 1});
        visited[y] = true;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= maxl; i++)
    if (lvl[i]) ans++;
  cout << ans << '\n';
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

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 MAXN = (int)(1e5 + 123);
vector<int> gg[MAXN], gb[MAXN];
bool was[MAXN], been[MAXN];
int cnt = 0;
void dfs(int v) {
  cnt++;
  was[v] = been[v] = true;
  for (auto to : gg[v]) {
    if (was[to]) continue;
    dfs(to);
  }
}
int main() {
  int n;
  cin >> n;
  int good;
  cin >> good;
  for (int i = 1; i <= good; i++) {
    int a, b;
    cin >> a >> b;
    gg[a].push_back(b);
    gg[b].push_back(a);
  }
  int bad;
  cin >> bad;
  for (int i = 1; i <= bad; i++) {
    int a, b;
    cin >> a >> b;
    gb[a].push_back(b);
    gb[b].push_back(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (was[i]) continue;
    cnt = 0;
    dfs(i);
    bool no = false;
    for (int j = 1; j <= n; j++) {
      if (been[j]) {
        for (auto to : gb[j])
          if (been[to]) {
            no = true;
            break;
          }
      }
      if (no) break;
    }
    if (!no) ans = max(ans, cnt);
    for (int j = 1; j <= n; j++) been[j] = false;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Vasya passes all exams! Despite expectations, Vasya is not tired, moreover, he is ready for new challenges. However, he does not want to work too hard on difficult problems.

Vasya remembered that he has a not-so-hard puzzle: m colored cubes are placed on a chessboard of size n × n. The fact is that m ≤ n and all cubes have distinct colors. Each cube occupies exactly one cell. Also, there is a designated cell for each cube on the board, the puzzle is to place each cube on its place. The cubes are fragile, so in one operation you only can move one cube onto one of four neighboring by side cells, if only it is empty. Vasya wants to be careful, so each operation takes exactly one second.

Vasya used to train hard for VK Cup Final, so he can focus his attention on the puzzle for at most 3 hours, that is 10800 seconds. Help Vasya find such a sequence of operations that all cubes will be moved onto their designated places, and Vasya won't lose his attention.

Input

The first line contains two integers n and m (1 ≤ m ≤ n ≤ 50).

Each of the next m lines contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ n), the initial positions of the cubes.

The next m lines describe the designated places for the cubes in the same format and order.

It is guaranteed that all initial positions are distinct and all designated places are distinct, however, it is possible that some initial positions coincide with some final positions.

Output

In the first line print a single integer k (0 ≤ k ≤ 10800) — the number of operations Vasya should make.

In each of the next k lines you should describe one operation: print four integers x_1, y_1, x_2, y_2, where x_1, y_1 is the position of the cube Vasya should move, and x_2, y_2 is the new position of the cube. The cells x_1, y_1 and x_2, y_2 should have a common side, the cell x_2, y_2 should be empty before the operation.

We can show that there always exists at least one solution. If there are multiple solutions, print any of them.

Examples

Input

2 1
1 1
2 2

Output

2
1 1 1 2
1 2 2 2

Input

2 2
1 1
2 2
1 2
2 1

Output

2
2 2 2 1
1 1 1 2

Input

2 2
2 1
2 2
2 2
2 1

Output

4
2 1 1 1
2 2 2 1
1 1 1 2
1 2 2 2

Input

4 3
2 2
2 3
3 3
3 2
2 2
2 3

Output

9
2 2 1 2
1 2 1 1
2 3 2 2
3 3 2 3
2 2 1 2
1 1 2 1
2 1 3 1
3 1 3 2
1 2 2 2

Note

In the fourth example the printed sequence of movements (shown on the picture below) is valid, but not shortest. There is a solution in 3 operations.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
int n, m, x[N], y[N], dx[4] = {-1, +1, 0, 0}, dy[4] = {0, 0, -1, +1}, ex[N],
                      ey[N], col[N][N];
vector<pair<int, int>> o;
bool vld(int x, int y) {
  return x >= 0 && y >= 0 && x < n && y < n && !col[x][y];
}
void dir_move(int id, int i) {
  assert(vld(x[id] + dx[i], y[id] + dy[i]));
  o.push_back({x[id] + 1, y[id] + 1});
  col[x[id]][y[id]] = 0;
  x[id] += dx[i], y[id] += dy[i];
  col[x[id]][y[id]] = id + 1;
  o.push_back({x[id] + 1, y[id] + 1});
}
void Up(int id) { dir_move(id, 0); }
void Down(int id) { dir_move(id, 1); }
void Left(int id) { dir_move(id, 2); }
void Right(int id) { dir_move(id, 3); }
void swap_cube(int i, int j) {
  if (i == j) return;
  if (y[i] > y[j]) swap(i, j);
  if (y[j] - y[i] == 1) {
    Down(i), Left(j), Right(i), Up(i);
    return;
  }
  Down(i), Down(i);
  Down(j);
  int t = y[j] - y[i];
  for (int k = 0; k < t; k++) Left(j);
  Up(j);
  for (int k = 0; k < t; k++) Right(i);
  Up(i), Up(i);
}
void print() {
  cerr << "HI\n";
  for (int i = 0; i < n; i++, cout << '\n')
    for (int j = 0; j < n; j++) cout << col[i][j] << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    --x[i], --y[i];
    col[x[i]][y[i]] = i + 1;
  }
  for (int i = 0; i < m; i++) cin >> ex[i] >> ey[i], ex[i]--, ey[i]--;
  vector<int> p(m);
  iota(p.begin(), p.end(), 0);
  sort(p.begin(), p.end(), [](int i, int j) {
    return make_pair(x[i], y[j]) < make_pair(x[j], y[i]);
  });
  for (auto id : p) {
    while (vld(x[id] - 1, y[id])) Up(id);
    while (vld(x[id], y[id] + 1)) Right(id);
  }
  sort(p.begin(), p.end(), [](int i, int j) {
    return make_pair(x[i], y[i]) < make_pair(x[j], y[j]);
  });
  for (auto id : p) {
    while (vld(x[id] - 1, y[id])) Up(id);
    while (vld(x[id], y[id] - 1)) Left(id);
  }
  for (int i = 0; i < m; i++) {
    int bruh = i;
    int id = col[0][bruh];
    for (int i = bruh; i < m; i++)
      if (col[0][i]) {
        int u = col[0][i];
        if (ey[u - 1] < ey[id - 1]) id = u;
      }
    swap_cube(col[0][i] - 1, id - 1);
  }
  sort(p.begin(), p.end(), [](int i, int j) {
    return make_pair(-ex[i], ey[i]) < make_pair(-ex[j], ey[j]);
  });
  for (int i = 0; i < m; i++) {
    int id = p[i];
    while (x[id] != ex[id]) Down(id);
  }
  vector<int> pp(m);
  iota(pp.begin(), pp.end(), 0);
  sort(pp.begin(), pp.end(), [](int i, int j) {
    return make_pair(x[i], y[i]) < make_pair(x[j], y[j]);
  });
  for (int i = 0; i < m; i++) {
    int id = pp[i];
    while (vld(x[id], y[id] - 1)) Left(id);
  }
  sort(p.begin(), p.end(), [](int i, int j) { return ey[i] > ey[j]; });
  for (int i = 0; i < m; i++) {
    int id = p[i];
    while (y[id] < ey[id]) Right(id);
  }
  int sz = (int)(o.size());
  cout << sz / 2 << '\n';
  for (int i = 0; i < sz; i++) {
    cout << o[i].first << ' ' << o[i].second << ' ';
    if (i % 2 == 1) cout << '\n';
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

John Doe offered his sister Jane Doe find the gcd of some set of numbers a.

Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbers of the set are evenly divisible by g'.

Unfortunately Jane couldn't cope with the task and John offered her to find the ghd of the same subset of numbers.

Ghd is a positive integer g, such that at least half of numbers from the set are evenly divisible by g and there isn't such g' (g' > g) that at least half of the numbers from the set are evenly divisible by g'.

Jane coped with the task for two hours. Please try it, too.

Input

The first line contains an integer n (1 ≤ n ≤ 106) showing how many numbers are in set a. The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1012). Please note, that given set can contain equal numbers.

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

Output

Print a single integer g — the Ghd of set a.

Examples

Input

6
6 2 3 4 5 6

Output

3

Input

5
5 5 6 10 15

Output

5

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O500")
#pragma comment(linker, "/STACK:1677777216")
#pragma warning(default : 4)
using namespace std;
const double eps = 1e-12;
const int oo = 0x3F3F3F3F;
const long long ooLL = 0x3F3F3F3F3F3F3F3FLL;
const int MOD = 1000000007;
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
void debpr(const T &);
template <typename T1, typename T2>
void debpr(const pair<T1, T2> &);
template <typename T1, typename T2>
void debpr(const vector<T1, T2> &);
template <typename T>
void debpr(const set<T> &);
template <typename T1, typename T2>
void debpr(const map<T1, T2> &);
template <typename T>
void prcont(T be, T en, const string &st, const string &fi, const string &mi) {
  debpr(st);
  bool ft = 0;
  while (be != en) {
    if (ft) debpr(mi);
    ft = 1;
    debpr(*be);
    ++be;
  }
  debpr(fi);
}
template <typename T>
void debpr(const T &a) {}
template <typename T1, typename T2>
void debpr(const pair<T1, T2> &p) {
  debpr("(");
  debpr(p.first);
  debpr(", ");
  debpr(p.second);
  debpr(")");
}
template <typename T1, typename T2>
void debpr(const vector<T1, T2> &a) {
  prcont(a.begin(), a.end(), "[", "]", ", ");
}
template <typename T>
void debpr(const set<T> &a) {
  prcont(a.begin(), a.end(), "{", "}", ", ");
}
template <typename T1, typename T2>
void debpr(const map<T1, T2> &a) {
  prcont(a.begin(), a.end(), "{", "}", ", ");
}
void deb(){};
template <typename T1>
void deb(const T1 &t1) {
  debpr(t1);
  debpr('\n');
}
template <typename T1, typename T2>
void deb(const T1 &t1, const T2 &t2) {
  debpr(t1);
  debpr(' ');
  debpr(t2);
  debpr('\n');
}
template <typename T1, typename T2, typename T3>
void deb(const T1 &t1, const T2 &t2, const T3 &t3) {
  debpr(t1);
  debpr(' ');
  debpr(t2);
  debpr(' ');
  debpr(t3);
  debpr('\n');
}
template <typename T1, typename T2, typename T3, typename T4>
void deb(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) {
  debpr(t1);
  debpr(' ');
  debpr(t2);
  debpr(' ');
  debpr(t3);
  debpr(' ');
  debpr(t4);
  debpr('\n');
}
const double PI = acos(-1.);
long long Round(double x) { return x < 0 ? x - .5 : x + .5; }
template <typename T>
void ass(bool v, const T &x, string m = "Fail") {
  if (!v) {
    deb(m);
    deb(x);
    throw;
  }
}
int main() {
  void run();
  run();
  return 0;
}
long long a[1 << 20];
int n;
long long gcd(long long a, long long b) {
  long long t;
  while (a) b %= a, t = a, a = b, b = t;
  return b;
}
long long mrand() {
  long long rs = 0;
  for (int i = (0), _b(60); i < _b; ++i)
    if (rand() % 2) rs += 1LL << i;
  return rs;
}
void run() {
  scanf("%d", &n);
  for (int i = (0), _b(n); i < _b; ++i) scanf("%lld", &a[i]);
  long long rs = 1;
  srand(3);
  for (int it = (0), _b(12); it < _b; ++it) {
    long long t = a[mrand() % n];
    unordered_map<long long, int> m;
    m.reserve(1 << 15);
    for (int i = (0), _b(n); i < _b; ++i) ++m[gcd(a[i], t)];
    vector<pair<long long, long long> > v((m).begin(), (m).end());
    for (int i = (0), _b(v.size()); i < _b; ++i) {
      int z = 0;
      for (int j = (0), _b(v.size()); j < _b; ++j)
        if (v[j].first % v[i].first == 0) z += v[j].second;
      if (z >= (n + 1) / 2) rs = max(rs, v[i].first);
    }
  }
  cout << rs << endl;
}

```


### Prompt

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

You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".

Constraints

* 0 \leq N_1, N_2, N_3, N_4 \leq 9
* N_1, N_2, N_3 and N_4 are integers.

Input

Input is given from Standard Input in the following format:

N_1 N_2 N_3 N_4

Output

If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`.

Examples

Input

1 7 9 4

Output

YES

Input

1 9 7 4

Output

YES

Input

1 2 9 1

Output

NO

Input

4 9 0 8

Output

NO

### Response

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

int main()
{
    bool b[10] {0};
    for(int i = 0; i < 4; i++){
        int n;
        cin >> n;
        b[n] = true;
    }
    if(b[1] && b[9] && b[7] && b[4]) cout << "YES" << endl;
    else cout << "NO" << endl;
}
```


### Prompt

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

There are N cards placed on a grid with H rows and W columns of squares.

The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.

Multiple cards may be placed on the same square.

You will first pick up at most one card from each row.

Then, you will pick up at most one card from each column.

Find the maximum possible sum of the integers written on the picked cards.

Constraints

* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W

Input

Input is given from Standard Input in the following format:

N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N

Output

Print the maximum possible sum of the integers written on the picked cards.

Examples

Input

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

Output

28

Input

13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537

Output

430590

Input

1 100000 100000
1 1 1

Output

1

### Response

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

using namespace std;

class UnionFind {
public:
    explicit UnionFind(int N) : root(N, -1), size(N, 1), edge(N, 0) {}
    int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); }
    int getSize(int u){ return size[getRoot(u)]; }
    int same(int a, int b){
        return getRoot(a) == getRoot(b);
    }
    bool merge(int a, int b){
        int u = getRoot(a);
        int v = getRoot(b);
        if(u != v){
            if(edge[u] + edge[v] + 1 > size[u] + size[v]) return false;
            root[u] = v;
            size[v] += size[u];
            edge[v] += edge[u] + 1;
        } else {
            if(edge[u] + 1 > size[u]) return false;
            edge[u]++;
        }
        return true;
    }
private:
    vector<int> root;
    vector<int> size;
    vector<int> edge;
};

int main(){
    int N, H, W;
    while(cin >> N >> H >> W){
        UnionFind uf(H+W);
        long long res = 0;
        vector<pair<int, pair<int, int>>> vp;
        for(int i=0;i<N;i++){
            int r, c, a; cin >> r >> c >> a;
            vp.emplace_back(a, make_pair(r-1, c-1+H));
        }
        sort(vp.rbegin(), vp.rend());
        for(auto& p : vp){
            if(uf.merge(p.second.first, p.second.second)){
                res += p.first;
            }
        }
        cout << res << endl;
    }
}
```


### Prompt

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

Oleg the bank client lives in Bankopolia. There are n cities in Bankopolia and some pair of cities are connected directly by bi-directional roads. The cities are numbered from 1 to n. There are a total of m roads in Bankopolia, the i-th road connects cities ui and vi. It is guaranteed that from each city it is possible to travel to any other city using some of the roads.

Oleg wants to give a label to each city. Suppose the label of city i is equal to xi. Then, it must hold that for all pairs of cities (u, v) the condition |xu - xv| ≤ 1 holds if and only if there is a road connecting u and v.

Oleg wonders if such a labeling is possible. Find an example of such labeling if the task is possible and state that it is impossible otherwise.

Input

The first line of input contains two space-separated integers n and m (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105) — the number of cities and the number of roads.

Next, m lines follow. The i-th line contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the cities connected by the i-th road. It is guaranteed that there is at most one road between each pair of cities and it is possible to travel from any city to any other city using some roads.

Output

If the required labeling is not possible, output a single line containing the string "NO" (without quotes).

Otherwise, output the string "YES" (without quotes) on the first line. On the next line, output n space-separated integers, x1, x2, ..., xn. The condition 1 ≤ xi ≤ 109 must hold for all i, and for all pairs of cities (u, v) the condition |xu - xv| ≤ 1 must hold if and only if there is a road connecting u and v.

Examples

Input

4 4
1 2
1 3
1 4
3 4

Output

YES
2 3 1 1

Input

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

Output

YES
1 1 1 1 1

Input

4 3
1 2
1 3
1 4

Output

NO

Note

For the first sample, x1 = 2, x2 = 3, x3 = x4 = 1 is a valid labeling. Indeed, (3, 4), (1, 2), (1, 3), (1, 4) are the only pairs of cities with difference of labels not greater than 1, and these are precisely the roads of Bankopolia.

For the second sample, all pairs of cities have difference of labels not greater than 1 and all pairs of cities have a road connecting them.

For the last sample, it is impossible to construct a labeling satisfying the given constraints.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 301000;
long long myrand() {
  return ((long long)rand() << 48) + ((long long)rand << 32) +
         ((long long)rand() << 16) + rand();
}
set<int> e[N];
int n, m, u, v, id[N], f[N], dep[N], t;
pair<int, int> E[N];
map<long long, int> hs;
long long lev[N], d[N];
void dfs(int u, int f, int d) {
  dep[u] = d;
  for (auto v : e[u])
    if (v != f) {
      dfs(v, u, d + 1);
    }
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  srand(time(0));
  scanf("%d%d", &n, &m);
  lev[0] = 1;
  for (int i = 1; i < n + 1; i++) lev[i] = lev[i - 1] * 111;
  for (int i = 1; i < n + 1; i++) d[i] = lev[i];
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    E[i] = make_pair(u, v);
    d[u] += lev[v];
    d[v] += lev[u];
  }
  for (int i = 1; i < n + 1; i++) {
    if (!hs.count(d[i])) hs[d[i]] = t++;
    id[i] = hs[d[i]];
  }
  for (int i = 0; i < t; i++) f[i] = i;
  for (int i = 0; i < m; i++) {
    u = id[E[i].first], v = id[E[i].second];
    if (u == v) continue;
    if (e[u].count(v) || e[v].count(u)) continue;
    if (find(u) == find(v)) {
      puts("NO");
      return 0;
    }
    f[find(u)] = find(v);
    e[u].insert(v);
    e[v].insert(u);
  }
  for (int i = 0; i < t; i++)
    if (((int)(e[i]).size()) > 2) {
      puts("NO");
      return 0;
    }
  for (int i = 0; i < t; i++)
    if (((int)(e[i]).size()) < 2) {
      dfs(i, -1, 1);
      puts("YES");
      for (int j = 1; j < n + 1; j++) printf("%d ", dep[id[j]]);
      puts("");
      return 0;
    }
}

```