### Prompt

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

You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.

Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.

Input

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

The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.

Output

Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.

Examples

Input

3
0 3
1 3
3 8

Output

6 2 1

Input

3
1 3
2 4
5 7

Output

5 2 0

Note

The picture describing the first example:

<image>

Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.

The picture describing the second example:

<image>

Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp, ans;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long in1, in2;
    cin >> in1 >> in2;
    mp[in1]++;
    mp[in2 + 1]--;
  }
  long long now = 0;
  for (map<long long, long long>::iterator it = mp.begin();
       next(it) != mp.end(); it++) {
    now += it->second;
    long long l = it->first;
    long long r = next(it)->first;
    if (now > 0) ans[now] += r - l;
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

After learning a lot about space exploration, a little girl named Ana wants to change the subject.

Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so she came up with a more interesting one and she needs your help to solve it:

You are given an array of strings which consist of only small letters of the alphabet. Your task is to find how many palindrome pairs are there in the array. A palindrome pair is a pair of strings such that the following condition holds: at least one permutation of the concatenation of the two strings is a palindrome. In other words, if you have two strings, let's say "aab" and "abcac", and you concatenate them into "aababcac", we have to check if there exists a permutation of this new string such that it is a palindrome (in this case there exists the permutation "aabccbaa").

Two pairs are considered different if the strings are located on different indices. The pair of strings with indices (i,j) is considered the same as the pair (j,i).

Input

The first line contains a positive integer N (1 ≤ N ≤ 100 000), representing the length of the input array.

Eacg of the next N lines contains a string (consisting of lowercase English letters from 'a' to 'z') — an element of the input array.

The total number of characters in the input array will be less than 1 000 000.

Output

Output one number, representing how many palindrome pairs there are in the array.

Examples

Input

3
aa
bb
cd

Output

1

Input

6
aab
abcac
dffe
ed
aa
aade

Output

6

Note

The first example:

  1. aa + bb → abba.

The second example:

  1. aab + abcac = aababcac → aabccbaa
  2. aab + aa = aabaa
  3. abcac + aa = abcacaa → aacbcaa
  4. dffe + ed = dffeed → fdeedf
  5. dffe + aade = dffeaade → adfaafde
  6. ed + aade = edaade → aeddea

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<long long, int> st;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    int c[26];
    for (int j = 0; j < 26; j++) c[j] = 0;
    for (int j = 0; j < str.length(); j++) c[str[j] - 'a']++;
    long long btv = 0;
    for (int j = 0; j < 26; j++) {
      btv *= 2;
      btv += c[j] % 2;
    }
    ans += st[btv];
    for (int j = 0; j < 26; j++) ans += st[btv ^ (1ll << j)];
    st[btv]++;
  }
  cout << ans;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

We have a string S of length N consisting of `R`, `G`, and `B`.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

* S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.
* j - i \neq k - j.

Constraints

* 1 \leq N \leq 4000
* S is a string of length N consisting of `R`, `G`, and `B`.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Examples

Input

4
RRGB

Output

1

Input

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Output

1800

### Response

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

int main(){
  int a,k;
  string s;
  cin>>a>>s;
  long long color , l=0, r=0,g=0,b=0;
  for(int i=0;i<a;i++){
    if(s.at(i)=='R')r++;
    else if(s.at(i)=='G')g++;
    else b++;
  }
  color=r*g*b;
  for(int i=0;i<a;i++){
    for(int j=i+1;j<a;j++){
      k=2*j-i;
      if(k>=a || s.at(i)==s.at(k) || s.at(j)==s.at(k) || s.at(i)==s.at(j))continue;
      l++;
    }
  }
  cout <<color - l<<endl;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.

We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ..., xr, where xi is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

<image>

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.

The second line contains n integers ai (0 ≤ ai ≤ 109).

The third line contains n integers bi (0 ≤ bi ≤ 109).

Output

Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

Examples

Input

5
1 2 4 3 2
2 3 3 12 1

Output

22

Input

10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6

Output

46

Note

Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation.

In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 and r = 5, l = 3 and r = 4, or l = 3 and r = 5.

In the second sample, the maximum value is obtained for l = 1 and r = 9.

### Response

```cpp
#include <bits/stdc++.h>
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
int A[1005];
int B[1005];
int preA[1005];
int preB[1005];
int main() {
  int n;
  A[0] = B[0] = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    preA[i] = preA[i - 1] | A[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> B[i];
    preB[i] = preB[i - 1] | B[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int tempA = preA[j] | preA[i] | A[i];
      int tempB = preB[j] | preB[i] | B[i];
      ans = max(ans, tempA + tempB);
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.

Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi (0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.

Output

Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.

Examples

Input

4
0.1 0.2 0.3 0.8

Output

0.800000000000

Input

2
0.1 0.2

Output

0.260000000000

Note

In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.

In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
double m[101], s = 0, pr = 1, sn = 0, answer;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> m[i];
  sort(&m[1], &m[n + 1]);
  if (m[n] == 1)
    answer = 1;
  else {
    for (int i = n; i > 0; --i) {
      if (s < 1) {
        s += m[i] / (1 - m[i]);
        pr *= (1 - m[i]);
      } else
        break;
    }
    answer = s * pr;
  }
  cout << fixed;
  cout.precision(12);
  cout << answer;
  return 0;
}

```


### Prompt

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

You are given a directed graph G which can contain loops (edges from a vertex to itself). Multi-edges are absent in G which means that for all ordered pairs (u, v) exists at most one edge from u to v. Vertices are numbered from 1 to n.

A path from u to v is a sequence of edges such that:

  * vertex u is the start of the first edge in the path;
  * vertex v is the end of the last edge in the path;
  * for all pairs of adjacent edges next edge starts at the vertex that the previous edge ends on.

We will assume that the empty sequence of edges is a path from u to u.

For each vertex v output one of four values:

  * 0, if there are no paths from 1 to v;
  * 1, if there is only one path from 1 to v;
  * 2, if there is more than one path from 1 to v and the number of paths is finite;
  * -1, if the number of paths from 1 to v is infinite.

Let's look at the example shown in the figure.

<image>

Then:

  * the answer for vertex 1 is 1: there is only one path from 1 to 1 (path with length 0);
  * the answer for vertex 2 is 0: there are no paths from 1 to 2;
  * the answer for vertex 3 is 1: there is only one path from 1 to 3 (it is the edge (1, 3));
  * the answer for vertex 4 is 2: there are more than one paths from 1 to 4 and the number of paths are finite (two paths: [(1, 3), (3, 4)] and [(1, 4)]);
  * the answer for vertex 5 is -1: the number of paths from 1 to 5 is infinite (the loop can be used in a path many times);
  * the answer for vertex 6 is -1: the number of paths from 1 to 6 is infinite (the loop can be used in a path many times).

Input

The first contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Before each test case, there is an empty line.

The first line of the test case contains two integers n and m (1 ≤ n ≤ 4 ⋅ 10^5, 0 ≤ m ≤ 4 ⋅ 10^5) — numbers of vertices and edges in graph respectively. The next m lines contain edges descriptions. Each line contains two integers a_i, b_i (1 ≤ a_i, b_i ≤ n) — the start and the end of the i-th edge. The vertices of the graph are numbered from 1 to n. The given graph can contain loops (it is possible that a_i = b_i), but cannot contain multi-edges (it is not possible that a_i = a_j and b_i = b_j for i ≠ j).

The sum of n over all test cases does not exceed 4 ⋅ 10^5. Similarly, the sum of m over all test cases does not exceed 4 ⋅ 10^5.

Output

Output t lines. The i-th line should contain an answer for the i-th test case: a sequence of n integers from -1 to 2.

Example

Input

5

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

1 0

3 3
1 2
2 3
3 1

5 0

4 4
1 2
2 3
1 4
4 3

Output

1 0 1 2 -1 -1
1
-1 -1 -1
1 0 0 0 0
1 1 2 1

### Response

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

typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>vll;
#define sf scanf
#define pf printf
#define nl printf("\n")
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d%d",&x,&y)
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define chk cerr<<"CAME HERE"<<endl
#define dbug(x) cerr<<"value of "<<#x<<" = "<<x<<endl
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
mt19937 rng((uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
inline int rand(int l, int r){uniform_int_distribution<int> RNG(l,r);return RNG(rng);}

const int N = 4e5+5;

vector<int>graph[N],dag[N],rgraph[N];
int discovery_time[N],parent[N];
int Time=0,scc=0;
stack<int>curTree;
bool inTree[N]={0};
bool selfloop[N]={0};
bool cmploop[N]={0};
ll cnt2[N]={0},cnt[N]={0};
pll dp[N];

void resetAll(int n){
	while(!curTree.empty())curTree.pop();
	for(int i=0; i<=n; i++){
		discovery_time[i]=0;
		selfloop[i]=0;
		parent[i]=0;
		cnt[i]=0;
		cmploop[i]=0;
		graph[i].clear();
		rgraph[i].clear();
		dag[i].clear();
		cnt2[i]=0;
		dp[i]={-1,0};
	}
	Time=0;
	scc=1;
}

int tarjan_scc(int u){
    int low=discovery_time[u]=++Time;
    curTree.push(u);
    inTree[u]=1;

    for(int v:graph[u])
        if(!discovery_time[v])
            low=min(low,tarjan_scc(v));
        else if(inTree[v])
            low=min(low,discovery_time[v]);

    if(low==discovery_time[u]){
        int top;
        do{
            top=curTree.top();
			cnt[scc]++;
            curTree.pop();
            inTree[top]=0;
            parent[top]=scc;
        }while(u!=top && !curTree.empty());

        scc++;
    }
    return low;
}

int target;

pll f(int u){
	if(u==target)return pll(1,cmploop[u] || cnt[u]>1);
	pll &ret = dp[u];
	if(ret.first!=-1)return ret;
	ret=pll(0,cmploop[u] || cnt[u]>1);
	for(int v:rgraph[u]){
		pll x = f(v);
		ret.first+=x.first;
		if(x.first>0)ret.second|=x.second;
		if(ret.first>=2)ret.first=2;
	}
	return ret;
}

void solve(int casenum){
	int n,m;
	sii(n,m);
	if(casenum==1)resetAll(n);
	for(int i=0,u,v; i<m; i++){
		sii(u,v);
		if(u==v)selfloop[u]=1;
		else{
			graph[u].push_back(v);
		}
	}

	for(int i=1; i<=n; i++)if(!discovery_time[i])tarjan_scc(i);

	for(int i=1; i<=n; i++){
		if(selfloop[i])cmploop[parent[i]]=1;
		for(int v:graph[i]){
			if(parent[i]!=parent[v]){
				dag[parent[i]].push_back(parent[v]);
				rgraph[parent[v]].push_back(parent[i]);
			}
		}
	}
	target=parent[1];

	for(int i=1; i<=n; i++){
		int x = parent[i];
		//pf("zzfsd %d %d %d %d %d\n",i,parent[i],cnt[x],cnt2[x],cnt3[x]);
		pll p = f(x);
		if(p.first==0)pf("0 ");
		else {
			if(p.second || cmploop[x])pf("-1 ");
			else if(p.first>1)pf("2 ");
			else pf("1 ");
		}
	}
	nl;
	resetAll(n);
}

int main(){

    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int T=1;
    scanf("%d",&T);
    //cin>>T;
    for(int i=1; i<=T; i++)
        solve(i);

return 0;
}
```


### Prompt

Generate a CPP solution to the following problem:

There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.

Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:

* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.

Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.

When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.

Constraints

* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.

Input

Input is given from Standard Input in the following format:

N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.

Examples

Input

2 2
2 3
1 4

Output

3

Input

3 4
2 5 10
1 3 7 13

Output

8

Input

4 1
1 2 4 5
3

Output

1

Input

4 5
2 5 7 11
1 3 6 9 13

Output

6

Input

10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30

Output

22

### Response

```cpp
#include<algorithm>
#include<cstdio>
#define N 100001
#define p 1000000007
using namespace std;
inline int mod(int x){return x<p?x:x-p;}
int a[N],b[N],c[N],d[N],e[N],f[N],i,j,m,n,s,t,x;
inline bool cmpd(int u,int v){return d[u]<d[v];}
inline bool cmpc(int u,int v){return c[u]==c[v]?d[v]<d[u]:c[u]<c[v];}
inline void add(int u,int v){while(u<=j)f[u]=mod(f[u]+v),u+=u&-u;}
inline int sum(int u)
{
    int v=0;
    while(u)v=mod(v+f[u]),u^=u&-u;
    return v;
}
int main()
{
    scanf("%d%d",&m,&n);
    for(i=1;i<=m;i++)scanf("%d",a+i);
    for(i=1;i<=n;i++)scanf("%d",b+i);
    for(i=1,j=0;i<=m;j&&j<n?c[++t]=a[i]-b[j],d[t]=b[j+1]-a[i],e[t]=t:0,i++)while(j<n&&b[j+1]<a[i])j++;
    for(sort(e+1,e+t+1,cmpd),i=1,j=0;i<=t;i++)d[e[i]]=d[e[i]]!=j?j=d[e[i]],d[e[i-1]]+1:d[e[i-1]];
    for(j=d[e[t]],sort(e+1,e+t+1,cmpc),i=x=1;i<=t;i++)if(c[e[i]]!=c[e[i-1]]||d[e[i]]!=d[e[i-1]])s=mod(sum(d[e[i]]-1)+1),x=mod(x+s),add(d[e[i]],s);
    return 0&printf("%d\n",x);
}
```


### Prompt

Please create a solution in Cpp to the following problem:

You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:

  * Write parity(a) to the end of a. For example, <image>.
  * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty.

You can use as many operations as you want. The problem is, is it possible to turn a into b?

The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.

Input

The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.

Output

Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.

Examples

Input

01011
0110

Output

YES

Input

0011
1110

Output

NO

Note

In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int A = 0, B = 0, mx, i;
  cin >> a >> b;
  for (i = 0; i < a.size(); i++)
    if (a[i] == '1') A++;
  for (i = 0; i < b.size(); i++)
    if (b[i] == '1') B++;
  mx = A + (A % 2);
  if (mx >= B)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

  1. on this day the gym is closed and the contest is not carried out;
  2. on this day the gym is closed and the contest is carried out;
  3. on this day the gym is open and the contest is not carried out;
  4. on this day the gym is open and the contest is carried out.

On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

Input

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations.

The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:

  * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
  * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
  * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
  * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.

Output

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:

  * to do sport on any two consecutive days,
  * to write the contest on any two consecutive days.

Examples

Input

4
1 3 2 0

Output

2

Input

7
1 3 3 2 1 2 3

Output

0

Input

2
2 2

Output

1

Note

In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[102], dp[102][5];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[2][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
    if (a[i] == 1 || a[i] == 3) {
      dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
    } else
      dp[i][1] = dp[i - 1][1];
    if (a[i] == 2 || a[i] == 3) {
      dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
    } else
      dp[i][2] = dp[i - 1][2];
  }
  cout << (n - max(dp[n][0], max(dp[n][1], dp[n][2]))) << '\n';
}

```


### Prompt

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

Suppose you are given a sequence S of k pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_k, b_k).

You can perform the following operations on it:

  1. Choose some position i and increase a_i by 1. That can be performed only if there exists at least one such position j that i ≠ j and a_i = a_j. The cost of this operation is b_i;
  2. Choose some position i and decrease a_i by 1. That can be performed only if there exists at least one such position j that a_i = a_j + 1. The cost of this operation is -b_i.

Each operation can be performed arbitrary number of times (possibly zero).

Let f(S) be minimum possible x such that there exists a sequence of operations with total cost x, after which all a_i from S are pairwise distinct.

Now for the task itself ...

You are given a sequence P consisting of n pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_n, b_n). All b_i are pairwise distinct. Let P_i be the sequence consisting of the first i pairs of P. Your task is to calculate the values of f(P_1), f(P_2), ..., f(P_n).

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of pairs in sequence P.

Next n lines contain the elements of P: i-th of the next n lines contains two integers a_i and b_i (1 ≤ a_i ≤ 2 ⋅ 10^5, 1 ≤ b_i ≤ n). It is guaranteed that all values of b_i are pairwise distinct.

Output

Print n integers — the i-th number should be equal to f(P_i).

Examples

Input

5
1 1
3 3
5 5
4 2
2 4

Output

0
0
0
-5
-16

Input

4
2 4
2 3
2 2
1 1

Output

0
3
7
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long kq, cd, p[500005], cur, mn[500005], done[500005];
long long aug[500005], red[500005];
vector<pair<long long, long long> > block[500005];
struct custom_hash {
  size_t operator()(long long x) const { return x; }
};
unordered_map<long long, pair<long long, long long> > a[500005];
pair<long long, long long> get(long long u, long long i) {
  pair<long long, long long> kq = pair<long long, long long>(0, 0);
  while (i > 0) {
    if (a[u].find(i) != a[u].end())
      kq.first += a[u][i].first, kq.second += a[u][i].second;
    i -= i & -i;
  }
  return kq;
}
void update(long long u, long long i, long long val) {
  while (i <= cd) a[u][i].first += val, a[u][i].second += 1, i += i & -i;
}
long long dad(long long u) {
  while (p[u] != 0) u = p[u];
  return u;
}
void add(long long u, pair<long long, long long> key) {
  long long val = key.first, v = key.second;
  pair<long long, long long> sp = get(u, val);
  kq -= (-red[u] + aug[u]);
  if (block[u].size() == 0) mn[u] = v;
  if (mn[u] > v) red[u] += get(u, cd).first * (mn[u] - v), mn[u] = v;
  red[u] += val * (v - mn[u]);
  aug[u] += val * (block[u].size() - sp.second) + sp.first;
  kq += (-red[u] + aug[u]);
  update(u, val, val);
  block[u].push_back(key);
  done[mn[u] + block[u].size() - 1] = 1;
  if (mn[u] + block[u].size() - 1 != u) p[mn[u] + block[u].size() - 1] = u;
}
void fused(long long u, long long v) {
  if (block[u].size() < block[v].size()) swap(u, v);
  p[v] = u;
  if (block[v].size() == 0) return;
  kq -= (-red[v] + aug[v]);
  for (auto x : block[v]) add(u, x);
  long long nx = mn[u] + block[u].size();
  long long dadnx = dad(nx);
  if (done[nx] == 1 && dadnx != u) fused(u, dadnx);
}
void inp() { cin >> cd; }
void do_it() {
  long long u, v;
  for (long long i = 1; i <= cd; i++) {
    cin >> u >> v;
    done[u] = 1;
    if (u != 1 && done[u - 1] != 0) {
      long long dadu = dad(u), dadu1 = dad(u - 1);
      if (dadu != dadu1) fused(dadu, dadu1);
    }
    if (u != cd && done[u + 1] != 0) {
      long long dadu = dad(u), dadu1 = dad(u + 1);
      if (dadu != dadu1) fused(dadu, dadu1);
    }
    add(dad(u), pair<long long, long long>(v, u));
    long long dadu = dad(u);
    long long nx = mn[dadu] + block[dadu].size();
    long long dadnx = dad(nx);
    if (done[nx] == 1 && dadnx != dadu) fused(dadu, dadnx);
    cout << kq << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  inp();
  do_it();
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given n points on the plane. You need to delete exactly k of them (k < n) so that the diameter of the set of the remaining n - k points were as small as possible. The diameter of a set of points is the maximum pairwise distance between the points of the set. The diameter of a one point set equals zero.

Input

The first input line contains a pair of integers n, k (2 ≤ n ≤ 1000, 1 ≤ k ≤ 30, k < n) — the numbers of points on the plane and the number of points to delete, correspondingly.

Next n lines describe the points, one per line. Each description consists of a pair of integers xi, yi (0 ≤ xi, yi ≤ 32000) — the coordinates of the i-th point. The given points can coincide.

Output

Print k different space-separated integers from 1 to n — the numbers of points to delete. The points are numbered in the order, in which they are given in the input from 1 to n. You can print the numbers in any order. If there are multiple solutions, print any of them.

Examples

Input

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

Output

5 2

Input

4 1
0 0
0 0
1 1
1 1

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
} p[1010];
int n, k, cnt, d[1000010], g[1010][1010], vis[1010];
vector<int> Map[1010];
int dis(int i, int j) {
  return (p[i].x - p[j].x) * (p[i].x - p[j].x) +
         (p[i].y - p[j].y) * (p[i].y - p[j].y);
}
bool dfs(int cnt, int m) {
  if (cnt > n) return 1;
  if (vis[cnt]) return dfs(cnt + 1, m);
  int Len = Map[cnt].size();
  for (int(i) = (0); (i) <= (Len - 1); (i)++) {
    m += !vis[Map[cnt][i]];
    vis[Map[cnt][i]]++;
  }
  if (m <= k && dfs(cnt + 1, m)) return 1;
  int temp = m;
  for (int(i) = (0); (i) <= (Len - 1); (i)++) {
    vis[Map[cnt][i]]--;
    m -= !vis[Map[cnt][i]];
  }
  if (Map[cnt].size() != 1) {
    vis[cnt]++;
    if (m + 1 <= k && m + 1 < temp && dfs(cnt + 1, m + 1)) return true;
    vis[cnt]--;
  }
  return false;
}
bool check(int Dis) {
  memset(vis, 0, sizeof vis);
  for (int(i) = (1); (i) <= (n); (i)++) Map[i].clear();
  for (int(i) = (1); (i) <= (n); (i)++)
    for (int(j) = (i + 1); (j) <= (n); (j)++)
      if (g[i][j] > Dis) {
        Map[i].push_back(j);
        Map[j].push_back(i);
      }
  return dfs(1, 0);
}
int Two_Find(int left, int right) {
  while (left < right) {
    int mid = (left + right) >> 1;
    if (check(d[mid]))
      right = mid;
    else
      left = mid + 1;
  }
  return left;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%d %d", &p[i].x, &p[i].y);
  for (int(i) = (1); (i) <= (n); (i)++)
    for (int(j) = (1); (j) <= (n); (j)++) d[++cnt] = g[i][j] = dis(i, j);
  sort(d, d + cnt + 1);
  int num = unique(d, d + cnt + 1) - d - 1;
  int mx = Two_Find(0, num);
  check(d[mx]);
  bool first = false;
  for (int i = n; i >= 1; --i)
    if (vis[i]) {
      if (first) putchar(' ');
      printf("%d", i);
      k--;
      first = true;
    }
  for (int i = n; i >= 1 && k > 0; --i)
    if (!vis[i]) {
      if (first) putchar(' ');
      printf("%d", i);
      k--;
      first = true;
    }
  return 0;
}

```


### Prompt

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

You are given three integers n, d and k.

Your task is to construct an undirected tree on n vertices with diameter d and degree of each vertex at most k, or say that it is impossible.

An undirected tree is a connected undirected graph with n - 1 edges.

Diameter of a tree is the maximum length of a simple path (a path in which each vertex appears at most once) between all pairs of vertices of this tree.

Degree of a vertex is the number of edges incident to this vertex (i.e. for a vertex u it is the number of edges (u, v) that belong to the tree, where v is any other vertex of a tree).

Input

The first line of the input contains three integers n, d and k (1 ≤ n, d, k ≤ 4 ⋅ 10^5).

Output

If there is no tree satisfying the conditions above, print only one word "NO" (without quotes).

Otherwise in the first line print "YES" (without quotes), and then print n - 1 lines describing edges of a tree satisfying the conditions above. Vertices of the tree must be numbered from 1 to n. You can print edges and vertices connected by an edge in any order. If there are multiple answers, print any of them.1

Examples

Input

6 3 3

Output

YES
3 1
4 1
1 2
5 2
2 6

Input

6 2 3

Output

NO

Input

10 4 3

Output

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

Input

8 5 3

Output

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

### Response

```cpp
#include <bits/stdc++.h>
long long inf = 1LL << 62;
long long mod = 1000000007;
using namespace std;
int n, k, d, label;
int seen[400010], out[400010];
vector<int> g[400010];
void dfs(int cur, int depth) {
  if (depth == 0 || label == n + 1 || seen[cur]) return;
  seen[cur] = 1;
  for (int i = 0; i < out[cur]; i++) {
    if (label == n + 1) return;
    g[cur].push_back(label);
    g[label].push_back(cur);
    out[label]--;
    label++;
  }
  for (int i = 0; i < g[cur].size(); i++) {
    if (!seen[g[cur][i]]) dfs(g[cur][i], depth - 1);
  }
}
void print(int cur, int par) {
  for (int i = 0; i < g[cur].size(); i++) {
    if (g[cur][i] != par)
      cout << cur << " " << g[cur][i] << endl, print(g[cur][i], cur);
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d >> k;
  if (d > n) {
    cout << "NO";
    return 0;
  }
  for (int i = 1; i <= n; i++) out[i] = k;
  for (int i = 1; i <= d; i++) {
    out[i]--, out[i + 1]--;
    seen[i] = seen[i + 1] = 1;
    if (out[i] < 0 || out[i + 1] < 0) {
      cout << "NO";
      return 0;
    }
    g[i].push_back(i + 1);
    g[i + 1].push_back(i);
  }
  label = d + 2;
  for (int i = 1; i <= d + 1; i++) {
    int depth = min(i - 1, d + 1 - i);
    if (label == n + 1) break;
    seen[i] = 0;
    dfs(i, depth);
  }
  if (label < n + 1) {
    cout << "NO";
    return 0;
  }
  cout << "YES\n";
  print(1, 0);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Polycarp likes numbers that are divisible by 3.

He has a huge number s. Polycarp wants to cut from it the maximum number of numbers that are divisible by 3. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after m such cuts, there will be m+1 parts in total. Polycarp analyzes each of the obtained numbers and finds the number of those that are divisible by 3.

For example, if the original number is s=3121, then Polycarp can cut it into three parts with two cuts: 3|1|21. As a result, he will get two numbers that are divisible by 3.

Polycarp can make an arbitrary number of vertical cuts, where each cut is made between a pair of adjacent digits. The resulting numbers cannot contain extra leading zeroes (that is, the number can begin with 0 if and only if this number is exactly one character '0'). For example, 007, 01 and 00099 are not valid numbers, but 90, 0 and 10001 are valid.

What is the maximum number of numbers divisible by 3 that Polycarp can obtain?

Input

The first line of the input contains a positive integer s. The number of digits of the number s is between 1 and 2⋅10^5, inclusive. The first (leftmost) digit is not equal to 0.

Output

Print the maximum number of numbers divisible by 3 that Polycarp can get by making vertical cuts in the given number s.

Examples

Input

3121

Output

2

Input

6

Output

1

Input

1000000000000000000000000000000000

Output

33

Input

201920181

Output

4

Note

In the first example, an example set of optimal cuts on the number is 3|1|21.

In the second example, you do not need to make any cuts. The specified number 6 forms one number that is divisible by 3.

In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and 33 digits 0. Each of the 33 digits 0 forms a number that is divisible by 3.

In the fourth example, an example set of optimal cuts is 2|0|1|9|201|81. The numbers 0, 9, 201 and 81 are divisible by 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int val(char ch) { return (ch - '0') % 3; }
int main() {
  string s;
  cin >> s;
  int a[s.size()];
  for (int i = 0; i < s.size(); i++) {
    a[i] = val(s[i]);
  }
  int p = 0, c = 0;
  map<int, int> m;
  for (int i = 0; i < s.size(); i++) {
    if (a[i] != 0) {
      p += a[i];
      if (p % 3 == 0 || m[(p % 3)] > 0) {
        p = 0;
        m.clear();
        c++;
      } else {
        m[p % 3]++;
      }
    } else {
      m.clear();
      p = 0;
      c++;
    }
  }
  cout << c;
}

```


### Prompt

Create a solution in Cpp for the following problem:

The farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table, where n is the number of rows, and m is the number of columns in the table. Each cell of the table contains a haystack. The height in meters of the hay located in the i-th row and the j-th column is equal to an integer ai, j and coincides with the number of cubic meters of hay in the haystack, because all cells have the size of the base 1 × 1. Polycarp has decided to tidy up in the warehouse by removing an arbitrary integer amount of cubic meters of hay from the top of each stack. You can take different amounts of hay from different haystacks. Besides, it is allowed not to touch a stack at all, or, on the contrary, to remove it completely. If a stack is completely removed, the corresponding cell becomes empty and no longer contains the stack.

Polycarp wants the following requirements to hold after the reorganization:

  * the total amount of hay remaining in the warehouse must be equal to k,
  * the heights of all stacks (i.e., cells containing a non-zero amount of hay) should be the same,
  * the height of at least one stack must remain the same as it was,
  * for the stability of the remaining structure all the stacks should form one connected region.

The two stacks are considered adjacent if they share a side in the table. The area is called connected if from any of the stack in the area you can get to any other stack in this area, moving only to adjacent stacks. In this case two adjacent stacks necessarily belong to the same area.

Help Polycarp complete this challenging task or inform that it is impossible.

Input

The first line of the input contains three integers n, m (1 ≤ n, m ≤ 1000) and k (1 ≤ k ≤ 1018) — the number of rows and columns of the rectangular table where heaps of hay are lain and the required total number cubic meters of hay after the reorganization.

Then n lines follow, each containing m positive integers ai, j (1 ≤ ai, j ≤ 109), where ai, j is equal to the number of cubic meters of hay making the hay stack on the i-th row and j-th column of the table.

Output

In the first line print "YES" (without quotes), if Polycarpus can perform the reorganisation and "NO" (without quotes) otherwise. If the answer is "YES" (without quotes), then in next n lines print m numbers — the heights of the remaining hay stacks. All the remaining non-zero values should be equal, represent a connected area and at least one of these values shouldn't be altered.

If there are multiple answers, print any of them.

Examples

Input

2 3 35
10 4 9
9 9 7

Output

YES
7 0 7
7 7 7

Input

4 4 50
5 9 1 1
5 1 1 5
5 1 5 5
5 5 7 1

Output

YES
5 5 0 0
5 0 0 5
5 0 5 5
5 5 5 0

Input

2 4 12
1 1 3 1
1 6 2 4

Output

NO

Note

In the first sample non-zero values make up a connected area, their values do not exceed the initial heights of hay stacks. All the non-zero values equal 7, and their number is 5, so the total volume of the remaining hay equals the required value k = 7·5 = 35. At that the stack that is on the second line and third row remained unaltered.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> dsu, sz;
vector<bool> used;
vector<vector<long long>> v;
void init(long long n) {
  used.resize(n);
  dsu.resize(n);
  sz.resize(n, 1);
  for (long long i = 0; i < n; i++) dsu[i] = i;
}
long long Find(long long a) {
  return (dsu[a] == a ? a : dsu[a] = Find(dsu[a]));
}
void Unite(long long a, long long b) {
  a = Find(a);
  b = Find(b);
  if (rand() % 2) swap(a, b);
  dsu[b] = a;
  sz[a] += sz[b];
}
void Add(long long a, long long n, long long m) {
  long long c1 = -1, c2 = -1, c3 = -1, c4 = -1;
  if (a % m > 0) c4 = a - 1;
  if ((a + 1) % m > 0) c2 = a + 1;
  if (a - m >= 0) c1 = a - m;
  if (a + m < m * n) c3 = a + m;
  used[a] = true;
  if (c1 != -1 && used[c1] && Find(a) != Find(c1)) Unite(a, c1);
  if (c2 != -1 && used[c2] && Find(a) != Find(c2)) Unite(a, c2);
  if (c3 != -1 && used[c3] && Find(a) != Find(c3)) Unite(a, c3);
  if (c4 != -1 && used[c4] && Find(a) != Find(c4)) Unite(a, c4);
}
long long delnow = 0, delall;
vector<bool> usedindfs;
void dfs(long long ver, long long n, long long m) {
  usedindfs[ver] = true;
  long long c1 = -1, c2 = -1, c3 = -1, c4 = -1;
  if (ver % m > 0) c4 = ver - 1;
  if ((ver + 1) % m > 0) c2 = ver + 1;
  if (ver - m >= 0) c1 = ver - m;
  if (ver + m < m * n) c3 = ver + m;
  if (c1 != -1 && Find(c1) == Find(ver) && !usedindfs[c1]) dfs(c1, n, m);
  if (c2 != -1 && Find(c2) == Find(ver) && !usedindfs[c2]) dfs(c2, n, m);
  if (c3 != -1 && Find(c3) == Find(ver) && !usedindfs[c3]) dfs(c3, n, m);
  if (c4 != -1 && Find(c4) == Find(ver) && !usedindfs[c4]) dfs(c4, n, m);
  if (delnow < delall) {
    v[ver / m][ver % m] = 0;
    delnow++;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, k;
  cin >> n >> m >> k;
  v.resize(n, vector<long long>(m));
  init(n * m);
  vector<pair<long long, long long>> lens;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> v[i][j];
      lens.push_back({v[i][j], i * m + j});
    }
  }
  sort(lens.rbegin(), lens.rend());
  vector<long long> eq;
  long long len = -1, del = 0, delincomp = 0, ind;
  for (long long i = 0; i < lens.size(); i++) {
    if (i < lens.size() - 1 && lens[i].first == lens[i + 1].first) {
      Add(lens[i].second, n, m);
      eq.push_back(lens[i].second);
      continue;
    }
    Add(lens[i].second, n, m);
    eq.push_back(lens[i].second);
    if (lens[i].first * (i + 1) < k) {
      eq.clear();
      continue;
    }
    if (lens[i].first * (i + 1) == k && sz[Find(lens[i].second)] == (i + 1)) {
      len = lens[i].first;
      break;
    } else if (lens[i].first * (i + 1) == k || k % lens[i].first != 0) {
      eq.clear();
      continue;
    }
    long long delnum = i + 1 - k / lens[i].first;
    bool flag = false;
    for (long long j = 0; j < eq.size(); j++) {
      if ((i + 1) - sz[Find(eq[j])] <= delnum) {
        if ((i + 1) - sz[Find(eq[j])] < delnum)
          delincomp = delnum - ((i + 1) - sz[Find(eq[j])]);
        flag = true;
        len = lens[i].first;
        del = delnum;
        ind = eq[j];
        break;
      }
    }
    if (flag) break;
    eq.clear();
  }
  if (len == -1) {
    cout << "NO";
    return 0;
  }
  if (del != 0) {
    if (delincomp != 0) {
      delall = delincomp;
      usedindfs.resize(n * m);
      dfs(ind, n, m);
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (v[i][j] < len || Find(i * m + j) != Find(ind))
          v[i][j] = 0;
        else
          v[i][j] = len;
      }
    }
  } else {
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (v[i][j] < len)
          v[i][j] = 0;
        else
          v[i][j] = len;
      }
    }
  }
  cout << "YES" << endl;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cout << v[i][j] << " ";
    }
    cout << endl;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

In some other world, today is December D-th.

Write a program that prints `Christmas` if D = 25, `Christmas Eve` if D = 24, `Christmas Eve Eve` if D = 23 and `Christmas Eve Eve Eve` if D = 22.

Constraints

* 22 \leq D \leq 25
* D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Examples

Input

25

Output

Christmas

Input

22

Output

Christmas Eve Eve Eve

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,a;cin>>a;
    printf("Christmas");
    for(i=0;i<25-a;i++){
        printf(" Eve");
    }
    printf("\n");
}
```


### Prompt

Please formulate a cpp solution to the following problem:

Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a.

Namely, it takes several iterations to calculate value v. At the first iteration, Xenia writes a new sequence a1 or a2, a3 or a4, ..., a2n - 1 or a2n, consisting of 2n - 1 elements. In other words, she writes down the bit-wise OR of adjacent elements of sequence a. At the second iteration, Xenia writes the bitwise exclusive OR of adjacent elements of the sequence obtained after the first iteration. At the third iteration Xenia writes the bitwise OR of the adjacent elements of the sequence obtained after the second iteration. And so on; the operations of bitwise exclusive OR and bitwise OR alternate. In the end, she obtains a sequence consisting of one element, and that element is v.

Let's consider an example. Suppose that sequence a = (1, 2, 3, 4). Then let's write down all the transformations (1, 2, 3, 4) →  (1 or 2 = 3, 3 or 4 = 7) →  (3 xor 7 = 4). The result is v = 4.

You are given Xenia's initial sequence. But to calculate value v for a given sequence would be too easy, so you are given additional m queries. Each query is a pair of integers p, b. Query p, b means that you need to perform the assignment ap = b. After each query, you need to print the new value v for the new sequence a.

Input

The first line contains two integers n and m (1 ≤ n ≤ 17, 1 ≤ m ≤ 105). The next line contains 2n integers a1, a2, ..., a2n (0 ≤ ai < 230). Each of the next m lines contains queries. The i-th line contains integers pi, bi (1 ≤ pi ≤ 2n, 0 ≤ bi < 230) — the i-th query.

Output

Print m integers — the i-th integer denotes value v for sequence a after the i-th query.

Examples

Input

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

Output

1
3
3
3

Note

For more information on the bit operations, you can follow this link: http://en.wikipedia.org/wiki/Bitwise_operation

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int *buildTree(long long int *arr, int n) {
  long long int *nod;
  nod = new long long int[2 * ((int)pow(2, n))];
  int index = pow(2, n);
  for (int i = 0; i < pow(2, n); i++) nod[index + i] = arr[i];
  n--;
  int type = 0;
  while (n >= 0) {
    index = pow(2, n);
    for (int i = index; i < 2 * index; i++) {
      if (type == 1)
        nod[i] = nod[2 * i] ^ nod[2 * i + 1];
      else
        nod[i] = nod[2 * i] | nod[2 * i + 1];
    }
    if (type == 1)
      type = 0;
    else
      type = 1;
    n--;
  }
  return nod;
}
void updateTree(long long int *nod, int n, pair<int, long long int> query) {
  int index = pow(2, n) + query.first - 1;
  nod[index] = query.second;
  int type = 0;
  index /= 2;
  while (index != 0) {
    if (type == 0) {
      nod[index] = nod[2 * index] | nod[2 * index + 1];
      type = 1;
    } else {
      nod[index] = nod[2 * index] ^ nod[2 * index + 1];
      type = 0;
    }
    index /= 2;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  long long int *arr;
  pair<int, long long int> *query;
  cin >> n >> m;
  int nArr = pow(2, n);
  arr = new long long int[nArr];
  query = new pair<int, long long int>[m];
  for (int i = 0; i < nArr; i++) cin >> arr[i];
  long long int *tree;
  tree = buildTree(arr, n);
  for (int i = 0; i < m; i++) cin >> query[i].first >> query[i].second;
  for (int i = 0; i < m; i++) {
    updateTree(tree, n, query[i]);
    cout << tree[1] << endl;
  }
  delete[] arr;
  delete[] query;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the city u and go by a simple path to city v. He hasn't determined the path, so it's time to do it. Note that chosen path can consist of only one vertex.

A filling station is located in every city. Because of strange law, Nut can buy only w_i liters of gasoline in the i-th city. We can assume, that he has infinite money. Each road has a length, and as soon as Nut drives through this road, the amount of gasoline decreases by length. Of course, Nut can't choose a path, which consists of roads, where he runs out of gasoline. He can buy gasoline in every visited city, even in the first and the last.

He also wants to find the maximum amount of gasoline that he can have at the end of the path. Help him: count it.

Input

The first line contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of cities.

The second line contains n integers w_1, w_2, …, w_n (0 ≤ w_{i} ≤ 10^9) — the maximum amounts of liters of gasoline that Nut can buy in cities.

Each of the next n - 1 lines describes road and contains three integers u, v, c (1 ≤ u, v ≤ n, 1 ≤ c ≤ 10^9, u ≠ v), where u and v — cities that are connected by this road and c — its length.

It is guaranteed that graph of road connectivity is a tree.

Output

Print one number — the maximum amount of gasoline that he can have at the end of the path.

Examples

Input

3
1 3 3
1 2 2
1 3 2

Output

3

Input

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

Output

7

Note

The optimal way in the first example is 2 → 1 → 3.

<image>

The optimal way in the second example is 2 → 4.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 10;
const long long M = 1e9 + 7;
int n, x, y, z;
int last[N], to[2 * N], w[2 * N], num, nxt[2 * N];
long long a[N];
long long ans;
void Add(int u, int v, int c) {
  nxt[++num] = last[u];
  to[num] = v;
  w[num] = c;
  last[u] = num;
}
long long dp[N];
long long dfs(int u, int f) {
  long long max1, max2;
  max1 = max2 = 0;
  for (int i = last[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == f) continue;
    dfs(v, u);
    long long now = dp[v] - w[i];
    if (now >= max1) {
      max2 = max1;
      max1 = now;
    } else if (now > max2)
      max2 = now;
  }
  long long tot = max1 + max2 + a[u];
  ans = max(ans, tot);
  return dp[u] = max(max1, max2) + a[u];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    Add(x, y, z);
    Add(y, x, z);
  }
  dfs(1, 0);
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art.

First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string.

Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer.

Input

First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100.

Output

The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating.

If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t.

Examples

Input

abc
cbaabc

Output

2
3 1
1 3

Input

aaabrytaaa
ayrat

Output

3
1 1
6 5
8 7

Input

ami
no

Output

-1

Note

In the first sample string "cbaabc" = "cba" + "abc".

In the second sample: "ayrat" = "a" + "yr" + "at".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s1[2201], s2[2201];
bool mark1[200];
long long prefixhash[2201];
long long invbase[2201];
long long inv;
long long suffixhash[2201];
long long power(long long a, long long b, long long m = 1000000007) {
  a %= m;
  long long x = 1;
  while (b) {
    if ((1 & b)) x = x * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return x;
}
void hash2(int n) {
  prefixhash[0] = 0;
  invbase[0] = 1;
  inv = power(29, 1000000007 - 2, 1000000007);
  long long b = 29;
  for (int i = 1; i <= n; i++) {
    prefixhash[i] = prefixhash[i - 1];
    long long x = s2[i - 1] * b;
    b *= 29;
    b %= 1000000007;
    invbase[i] = (invbase[i - 1] * inv) % 1000000007;
    prefixhash[i] = (prefixhash[i] + x) % 1000000007;
  }
  b = 29;
  suffixhash[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    suffixhash[i] = suffixhash[i + 1];
    long long x = s2[i - 1] * b;
    b *= 29;
    b %= 1000000007;
    suffixhash[i] = (suffixhash[i] + x) % 1000000007;
  }
}
long long rangef(long long i, long long j) {
  long long ans = 1000000007 + prefixhash[j] - prefixhash[i - 1];
  if (ans >= 1000000007) ans -= 1000000007;
  return (ans * invbase[i - 1]) % 1000000007;
}
int tn;
long long rangeb(long long i, long long j) {
  long long ans = 1000000007 + suffixhash[i] - suffixhash[j + 1];
  if (ans >= 1000000007) ans -= 1000000007;
  return (ans * invbase[tn - j]) % 1000000007;
}
long long prefixhash1[2201];
long long invbase1[2201];
long long inv1;
long long suffixhash1[2201];
void hash1(int n) {
  prefixhash1[0] = 0;
  invbase1[0] = 1;
  inv1 = power(29, 1000000007 - 2, 1000000007);
  long long b = 29;
  for (int i = 1; i <= n; i++) {
    prefixhash1[i] = prefixhash1[i - 1];
    long long x = s1[i - 1] * b;
    b *= 29;
    b %= 1000000007;
    invbase1[i] = (invbase1[i - 1] * inv1) % 1000000007;
    prefixhash1[i] = (prefixhash1[i] + x) % 1000000007;
  }
  b = 29;
  suffixhash1[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    suffixhash1[i] = suffixhash1[i + 1];
    long long x = s1[i - 1] * b;
    b *= 29;
    b %= 1000000007;
    suffixhash1[i] = (suffixhash1[i] + x) % 1000000007;
  }
}
long long rangef1(long long i, long long j) {
  long long ans = 1000000007 + prefixhash1[j] - prefixhash1[i - 1];
  if (ans >= 1000000007) ans -= 1000000007;
  return (ans * invbase1[i - 1]) % 1000000007;
}
int t1;
long long rangeb1(long long i, long long j) {
  long long ans = 1000000007 + suffixhash1[i] - suffixhash1[j + 1];
  if (ans >= 1000000007) ans -= 1000000007;
  return (ans * invbase1[tn - j]) % 1000000007;
}
bool pos(long long got, long long x) {
  for (int i = 0; i + x - 1 < t1; i++) {
    if (rangef1(i + 1, i + x) == got) return true;
  }
  return false;
}
bool can(int s, int e) {
  if (pos(rangef(s + 1, e + 1), e - s + 1)) return true;
  if (pos(rangeb(s + 1, e + 1), e - s + 1)) return true;
  return false;
}
vector<pair<int, int> > my;
bool pos1(long long got, long long x, bool flag) {
  if (flag == 0) {
    for (int i = 0; i + x - 1 < t1; i++) {
      if (rangef1(i + 1, i + x) == got) {
        my.push_back(make_pair(i + 1, i + x));
        return true;
      }
    }
    return false;
  } else {
    for (int i = 0; i + x - 1 < t1; i++) {
      if (rangef1(i + 1, i + x) == got) {
        my.push_back(make_pair(i + x, i + 1));
        return true;
      }
    }
    return false;
  }
}
void mysearch(int s, int e) {
  if (pos1(rangef(s + 1, e + 1), e - s + 1, 0)) return;
  pos1(rangeb(s + 1, e + 1), e - s + 1, 1);
}
int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  int l1 = strlen(s1), l2 = strlen(s2);
  hash2(l2);
  tn = l2;
  t1 = l1;
  hash1(l1);
  for (int i = 0; i < 200; i++) mark1[i] = false;
  for (int i = 0; i < l1; i++) {
    mark1[s1[i]] = 1;
  }
  string fuck = "-1";
  for (int i = 0; i < l2; i++) {
    if (!mark1[s2[i]]) {
      cout << fuck << endl;
      return 0;
    }
  }
  int found = 0, moves = 0, end;
  for (int i = 1; i < l2; i++) {
    if (can(found, i)) continue;
    end = i - 1;
    moves++;
    mysearch(found, end);
    found = i;
  }
  end = l2 - 1;
  moves++;
  mysearch(found, end);
  printf("%d\n", moves);
  for (int i = 0; i < my.size(); i++) {
    cout << my[i].first << " " << my[i].second << endl;
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

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

Constraints

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

Input

The input is given in the following format.

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

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

Output

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

Examples

Input

4
1 2 3 4
2
2 4

Output

1

Input

4
1 2 3 4
3
1 2 5

Output

0

### Response

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

int n;

bool binary_search(vector<int> &a ,int k){
    int x , y , z;
    x = 0;
    z = n - 1;
    while( x <= z ){
        y = (x + z) / 2;
        if(k == a[y]) return true;
        else if(k < a[y]) z = y - 1;
        else x = y + 1;
    }
    return false;
}

int main(){
    bool ans = true;
    cin >> n;
    vector<int> a(n);
    rep(i ,n) cin >> a[i];
    int m; cin >> m;
    vector<int> b(m);
    rep(i ,m) cin >> b[i];
    rep(i , m){
        if(!binary_search(a,b[i])) {
            ans = false; break;
        }
    }
    cout << ( ans ? 1 : 0) << endl;
}

```


### Prompt

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

In the year 2500 the annual graduation ceremony in the German University in Cairo (GUC) has run smoothly for almost 500 years so far.

The most important part of the ceremony is related to the arrangement of the professors in the ceremonial hall.

Traditionally GUC has n professors. Each professor has his seniority level. All seniorities are different. Let's enumerate the professors from 1 to n, with 1 being the most senior professor and n being the most junior professor.

The ceremonial hall has n seats, one seat for each professor. Some places in this hall are meant for more senior professors than the others. More specifically, m pairs of seats are in "senior-junior" relation, and the tradition requires that for all m pairs of seats (ai, bi) the professor seated in "senior" position ai should be more senior than the professor seated in "junior" position bi.

GUC is very strict about its traditions, which have been carefully observed starting from year 2001. The tradition requires that:

  * The seating of the professors changes every year.
  * Year 2001 ceremony was using lexicographically first arrangement of professors in the ceremonial hall.
  * Each consecutive year lexicographically next arrangement of the professors is used.

The arrangement of the professors is the list of n integers, where the first integer is the seniority of the professor seated in position number one, the second integer is the seniority of the professor seated in position number two, etc.

Given n, the number of professors, y, the current year and m pairs of restrictions, output the arrangement of the professors for this year.

Input

The first line contains three integers n, y and m (1 ≤ n ≤ 16, 2001 ≤ y ≤ 1018, 0 ≤ m ≤ 100) — the number of professors, the year for which the arrangement should be computed, and the number of pairs of seats for which the seniority relation should be kept, respectively.

The next m lines contain one pair of integers each, "ai bi", indicating that professor on the ai-th seat is more senior than professor on the bi-th seat (1 ≤ ai, bi ≤ n, ai ≠ bi). Some pair may be listed more than once.

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

Output

Print the order in which the professors should be seated in the requested year.

If by this year the GUC would have ran out of arrangements, or the given "senior-junior" relation are contradictory, print "The times have changed" (without quotes).

Examples

Input

3 2001 2
1 2
2 3

Output

1 2 3

Input

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

Output

1 2 3 7 4 6 5

Input

10 3630801 0

Output

The times have changed

Input

3 2001 3
1 2
2 3
3 1

Output

The times have changed

Note

In the first example the lexicographically first order of seating is 1 2 3.

In the third example the GUC will run out of arrangements after the year 3630800.

In the fourth example there are no valid arrangements for the seating.

The lexicographical comparison of arrangements is performed by the < operator in modern programming languages. The arrangement a is lexicographically less that the arrangement b, if there exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int BIT = (1 << 17), M = 110, N = 25;
int n, m, cnt[BIT], a[M];
long long f[BIT][N], b[N], p[N], year;
void solve(int x) {
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  int maxb = (1 << n);
  for (int i = 0; i < maxb; i++) {
    for (int j = 0; j <= n; j++) {
      int y = cnt[i] + 1;
      if (b[y]) {
        if ((a[b[y]] & i) != a[b[y]]) continue;
        if ((1 << (b[y] - 1) & i) == (1 << b[y] - 1)) continue;
        f[i | (1 << b[y] - 1)][j] += f[i][j];
      } else {
        for (int k = 1; k <= n; k++) {
          if (!(i & (1 << k - 1))) {
            if ((a[k] & i) != a[k]) continue;
            if (k == x)
              f[i | (1 << k - 1)][y] += f[i][j];
            else
              f[i | (1 << k - 1)][j] += f[i][j];
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d%lld%d", &n, &year, &m);
  year -= 2000;
  for (int i = 1; i < BIT; i++) cnt[i] = cnt[i ^ (i & (-i))] + 1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[y] |= (1 << x - 1);
  }
  for (int i = 1; i <= n; i++) {
    solve(i);
    long long sum = 0;
    for (int j = 1; j <= n; j++) {
      if (!b[j] && sum + f[(1 << n) - 1][j] >= year) {
        b[j] = i;
        p[i] = j;
        year -= sum;
        break;
      }
      sum += f[(1 << n) - 1][j];
    }
    if (!p[i]) {
      puts("The times have changed");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) printf("%lld ", p[i]);
  puts("");
  return 0;
}

```


### Prompt

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

Donghyun's new social network service (SNS) contains n users numbered 1, 2, …, n. Internally, their network is a tree graph, so there are n-1 direct connections between each user. Each user can reach every other users by using some sequence of direct connections. From now on, we will denote this primary network as T_1.

To prevent a possible server breakdown, Donghyun created a backup network T_2, which also connects the same n users via a tree graph. If a system breaks down, exactly one edge e ∈ T_1 becomes unusable. In this case, Donghyun will protect the edge e by picking another edge f ∈ T_2, and add it to the existing network. This new edge should make the network be connected again.

Donghyun wants to assign a replacement edge f ∈ T_2 for as many edges e ∈ T_1 as possible. However, since the backup network T_2 is fragile, f ∈ T_2 can be assigned as the replacement edge for at most one edge in T_1. With this restriction, Donghyun wants to protect as many edges in T_1 as possible.

Formally, let E(T) be an edge set of the tree T. We consider a bipartite graph with two parts E(T_1) and E(T_2). For e ∈ E(T_1), f ∈ E(T_2), there is an edge connecting \\{e, f\} if and only if graph T_1 - \\{e\} + \\{f\} is a tree. You should find a maximum matching in this bipartite graph.

Input

The first line contains an integer n (2 ≤ n ≤ 250 000), the number of users.

In the next n-1 lines, two integers a_i, b_i (1 ≤ a_i, b_i ≤ n) are given. Those two numbers denote the indices of the vertices connected by the corresponding edge in T_1.

In the next n-1 lines, two integers c_i, d_i (1 ≤ c_i, d_i ≤ n) are given. Those two numbers denote the indices of the vertices connected by the corresponding edge in T_2.

It is guaranteed that both edge sets form a tree of size n.

Output

In the first line, print the number m (0 ≤ m < n), the maximum number of edges that can be protected.

In the next m lines, print four integers a_i, b_i, c_i, d_i. Those four numbers denote that the edge (a_i, b_i) in T_1 is will be replaced with an edge (c_i, d_i) in T_2.

All printed edges should belong to their respective network, and they should link to distinct edges in their respective network. If one removes an edge (a_i, b_i) from T_1 and adds edge (c_i, d_i) from T_2, the network should remain connected. The order of printing the edges or the order of vertices in each edge does not matter.

If there are several solutions, you can print any.

Examples

Input

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

Output

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

Input

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

Output

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

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
int ch[250001][2], mn[250001], mx[250001], fa[250001];
bool lazy[250001];
bool son(int x) { return ch[fa[x]][1] == x; }
bool isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
void pushup(int x) {
  mn[x] = mn[ch[x][0]] ? mn[ch[x][0]] : x;
  mx[x] = mx[ch[x][1]] ? mx[ch[x][1]] : x;
}
void Rotate(int x) {
  int faz = fa[x], fazz = fa[faz], g = son(x);
  fa[x] = fazz;
  if (!isroot(faz)) ch[fazz][son(faz)] = x;
  fa[ch[x][!g]] = faz;
  ch[faz][g] = ch[x][!g];
  ch[x][!g] = faz;
  fa[faz] = x;
  pushup(faz);
  pushup(x);
}
void pushdown(int x) {
  if (!x) return;
  lazy[x] ^= 1;
  std::swap(ch[x][0], ch[x][1]);
  std::swap(mn[x], mx[x]);
}
void spread(int x) {
  if (lazy[x]) pushdown(ch[x][0]), pushdown(ch[x][1]), lazy[x] = 0;
}
void clear(int x) {
  if (!isroot(x)) clear(fa[x]);
  spread(x);
}
void splay(int x) {
  clear(x);
  while (!isroot(x)) {
    if (!isroot(fa[x]))
      if (son(x) ^ son(fa[x]))
        Rotate(x);
      else
        Rotate(fa[x]);
    Rotate(x);
  }
}
void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) splay(x), ch[x][1] = y, pushup(x);
}
void mroot(int x) {
  access(x);
  splay(x);
  pushdown(x);
}
void split(int x, int y) {
  mroot(x);
  access(y);
  splay(y);
}
void link(int x, int y) {
  mroot(x);
  fa[x] = y;
}
void cut(int x, int y) {
  split(x, y);
  ch[y][0] = fa[x] = 0;
  pushup(y);
}
int head[250001], nxt[500001], b[500001], k, dfn[250001], end[250001], now, n;
void push(int s, int t) {
  nxt[++k] = head[s];
  head[s] = k;
  b[k] = t;
}
void dfs(int x, int f) {
  dfn[x] = ++now;
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f) dfs(b[i], x);
  end[x] = now;
}
bool in(int x, int y) { return dfn[x] >= dfn[y] && dfn[x] <= end[y]; }
void getedge(int x, int c1, int c2) {
  spread(x);
  if (ch[x][0] && in(mx[ch[x][0]], c1) ^ in(x, c1)) {
    printf("%d %d %d %d\n", c1, c2, x, mx[ch[x][0]]);
    cut(x, mx[ch[x][0]]);
    link(c1, c2);
    return;
  }
  if (ch[x][1] && in(mn[ch[x][1]], c1) ^ in(x, c1)) {
    printf("%d %d %d %d\n", c1, c2, x, mn[ch[x][1]]);
    cut(x, mn[ch[x][1]]);
    link(c1, c2);
    return;
  }
  if (ch[x][0] && in(mn[ch[x][0]], c1) ^ in(x, c1))
    getedge(ch[x][0], c1, c2);
  else
    getedge(ch[x][1], c1, c2);
}
void dfs(int x) {
  if (!x) return;
  spread(x);
  dfs(ch[x][0]);
  printf("%d ", x);
  dfs(ch[x][1]);
}
int tot;
int xx[250001], yy[250001];
void getans(int x, int f) {
  if (f) {
    xx[++tot] = x;
    yy[tot] = f;
  }
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f) getans(b[i], x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    push(u, v);
    push(v, u);
  }
  dfs(1, 0);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    link(u, v);
  }
  printf("%d\n", n - 1);
  getans(1, 0);
  for (int i = 1; i < n; ++i) b[i] = i;
  std::random_shuffle(b + 1, b + n);
  for (int i = 1; i < n; ++i) {
    int x(xx[i]), f(yy[i]);
    split(x, f);
    getedge(f, x, f);
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

Problem statement

You and AOR Ika are preparing for a graph problem in competitive programming. Generating input cases is AOR Ika-chan's job. The input case for that problem is a directed graph of the $ N $ vertices. The vertices are numbered from $ 1 $ to $ N $. Edges may contain self-loops, but not multiple edges.

However, AOR Ika suddenly lost communication and couldn't get the original graph. All that remains is the following information:

* The number of vertices with degree $ i $ is $ a_i $. That is, the number of vertices ending in $ i $ is $ a_i $.
* The number of vertices with degree $ i $ is $ b_i $. That is, the number of vertices starting from $ i $ is $ b_i $.

Is there a directed graph that is consistent with the information left behind? Judge it, output YES if it exists, and then output one consistent directed graph. If there are more than one, any one may be output. If it does not exist, output NO.

Input constraints

$ 1 \ leq n \ leq 50 $
$ 0 \ leq a_i \ leq n $
$ 0 \ leq b_i \ leq n $

sample

Sample input 1

3
1 2 0 0
1 2 0 0

Sample output 1

YES YES
0 1 0
0 0 1
0 0 0

Sample input 2

1
Ten
Ten

Sample output 2

YES YES
0

Sample input 3

2
0 2 0
0 2 0

Sample output 3

YES YES
0 1
Ten

Sample input 4

Four
1 3 0 0 0
3 0 0 1 0

Sample output 4

YES YES
0 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0

Sample input 5

1
1 1
0 0

Sample output 5

NO

input

$ n $
$ a_0 \ cdots a_n $
$ b_0 \ cdots b_n $

output

If there is a graph that meets the conditions, output it in the following format. $ e_ {ij} $ should be 1 if there is a directed edge from $ i $ to $ j $, or 0 otherwise. Be careful not to print a blank at the end of the line.

YES YES
$ e_ {11} \ e_ {12} \ cdots e_ {1n} $
$ e_ {21} \ e_ {22} \ cdots e_ {2n} $
$ \ vdots $
$ e_ {n1} \ e_ {n2} \ cdots e_ {nn} $

If not, output as follows.

NO

Example

Input

3
1 2 0 0
1 2 0 0

Output

YES
0 1 0
0 0 1
0 0 0

### Response

```cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#include <queue>
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define endl "\n"
#define int long long
using namespace std;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

#define MAX 55

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

    int n;
    int num;
    int s1 = 0, s2 = 0;
    priority_queue<pair<int,int>> a, b;
    static int ans[MAX][MAX];

    cin>>n;

    for(int i = 0, sum = 0; i <= n; i++){
        cin>>num;
        s1 += num;
        for(int j = 0; j < num; j++){

            a.push(make_pair(i,sum++));

        }
    }

    for(int j = 0, sum = 0; j <= n; j++){
        cin>>num;
        s2 += num;
        for(int k = 0; k < num; k++){

            b.push(make_pair(j,sum++));

        }
    }

    if(s1 =! s2 || s1 != n){
        cout<<"NO"<<endl;
        return 0;
    }
    while(!a.empty()){
        pair<int,int> A = a.top(); a.pop();
        vector<pair<int,int>> temp;

        if(A.first == 0) break;

        for(int i = 0; i < A.first; i++){

            if(b.size() == 0){
                cout<<"NO"<<endl;
                return 0;
            }
            pair<int,int> B = b.top(); b.pop();

            if(B.first == 0){
                cout<<"NO"<<endl;
                return 0;
            }

            if(B.first-1 > 0)temp.push_back(make_pair(B.first-1,B.second));

            ans[B.second][A.second]++;
        }

        for(int j = 0; j < temp.size(); j++){
            b.push(temp[j]);
        }
    }

    cout<<"YES"<<endl;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(j) cout<<" ";
            cout<<ans[i][j];
        }
        cout<<endl;
    }

    return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

* If the monster's health is 1, it drops to 0.
* If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

* 1 \leq H \leq 10^{12}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Examples

Input

2

Output

3

Input

4

Output

7

Input

1000000000000

Output

1099511627775

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long H;
  long long ans_=1;
  cin>>H;
  while(H!=0){
    ans_*=2;
    H=H/2;
  }
  cout<<ans_-1<<endl;
}
```


### Prompt

Generate a CPP solution to the following problem:

An n × n table a is defined as follows:

  * The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for all i = 1, 2, ..., n.
  * Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula ai, j = ai - 1, j + ai, j - 1.

These conditions define all the values in the table.

You are given a number n. You need to determine the maximum value in the n × n table defined by the rules above.

Input

The only line of input contains a positive integer n (1 ≤ n ≤ 10) — the number of rows and columns of the table.

Output

Print a single line containing a positive integer m — the maximum value in the table.

Examples

Input

1

Output

1

Input

5

Output

70

Note

In the second test the rows of the table look as follows:

{1, 1, 1, 1, 1},  {1, 2, 3, 4, 5},  {1, 3, 6, 10, 15},  {1, 4, 10, 20, 35},  {1, 5, 15, 35, 70}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, i, j, n, m, l, r;
  cin >> n;
  long long a[n + 1][n + 1];
  for (i = 0; i < n; i++) a[0][i] = a[i][0] = 1;
  for (i = 1; i < n; i++) {
    for (j = 1; j < n; j++) {
      a[i][j] = a[i - 1][j] + a[i][j - 1];
    }
  }
  cout << a[n - 1][n - 1] << "\n";
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.

Each vertex has a color, let's denote the color of vertex v by cv. Initially cv = 0.

You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex v and a color x, and then color all vectices in the subtree of v (including v itself) in color x. In other words, for every vertex u, such that the path from root to u passes through v, set cu = x.

It is guaranteed that you have to color each vertex in a color different from 0.

You can learn what a rooted tree is using the link: https://en.wikipedia.org/wiki/Tree_(graph_theory).

Input

The first line contains a single integer n (2 ≤ n ≤ 104) — the number of vertices in the tree.

The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi < i), where pi means that there is an edge between vertices i and pi.

The third line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ n), where ci is the color you should color the i-th vertex into.

It is guaranteed that the given graph is a tree.

Output

Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.

Examples

Input

6
1 2 2 1 5
2 1 1 1 1 1

Output

3

Input

7
1 1 2 3 1 4
3 3 1 1 1 2 3

Output

5

Note

The tree from the first sample is shown on the picture (numbers are vetices' indices):

<image>

On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):

<image>

On seond step we color all vertices in the subtree of vertex 5 into color 1:

<image>

On third step we color all vertices in the subtree of vertex 2 into color 1:

<image>

The tree from the second sample is shown on the picture (numbers are vetices' indices):

<image>

On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors):

<image>

On second step we color all vertices in the subtree of vertex 3 into color 1:

<image>

On third step we color all vertices in the subtree of vertex 6 into color 2:

<image>

On fourth step we color all vertices in the subtree of vertex 4 into color 1:

<image>

On fith step we color all vertices in the subtree of vertex 7 into color 3:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, t;
  scanf("%d", &n);
  vector<int> v[n + 1];
  for (i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    v[i].push_back(x);
    v[x].push_back(i);
  }
  int colour[n + 1];
  for (i = 0; i <= n; i++) colour[i] = 0;
  int req[n + 1];
  for (i = 1; i <= n; i++) scanf("%d", &req[i]);
  queue<int> q1, q2;
  q2.push(1);
  int dist[n + 1], visited[n + 1], visi[n + 1];
  for (i = 0; i <= n; i++) {
    dist[i] = 0;
    visited[i] = 0;
    visi[i] = 0;
  }
  visited[1] = 1;
  while (!q2.empty()) {
    int x = q2.front();
    q2.pop();
    for (auto l : v[x]) {
      if (visited[l] == 0) {
        visited[l] = 1;
        dist[l] = dist[x] + 1;
        q2.push(l);
      }
    }
  }
  q2.push(1);
  int count = 0;
  while (!q2.empty()) {
    int x = q2.front();
    q2.pop();
    if (req[x] != colour[x]) {
      count++;
      colour[x] = req[x];
      q1.push(x);
      for (i = 0; i <= n; i++) {
        visited[i] = 0;
      }
      visited[x] = 1;
      while (!q1.empty()) {
        int y = q1.front();
        q1.pop();
        for (auto l : v[y]) {
          if (dist[l] >= dist[x] && visited[l] == 0) {
            visited[l] = 1;
            colour[l] = req[x];
            q1.push(l);
          }
        }
      }
    }
    for (auto l : v[x]) {
      if (visi[l] == 0) {
        visi[l] = 1;
        q2.push(l);
      }
    }
  }
  cout << count << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.

A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:

  * the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
  * the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).

Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of numbers.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n). Furthermore, there are no pair of indices i ≠ j such that a_i = a_j.

Output

Print s — a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".

Examples

Input

8
3 6 5 4 2 7 1 8

Output

BAAAABAB

Input

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

Output

ABAAAABBBAABAAB

Note

In the first sample, if Bob puts the token on the number (not position):

  * 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
  * 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
  * 3: Alice can only move to 4, after which Bob wins by moving to 8.
  * 4, 5, or 6: Alice wins by moving to 8.
  * 7, 8: Alice has no move, and hence she loses immediately.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar(), f = 0;
  for (; c < '0' || c > '9'; c = getchar())
    if (!(c ^ 45)) f = 1;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
}
int n, a[100005], dp[100005];
pair<int, int> p[100005];
int main() {
  read(n), memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) read(a[i]), p[i] = make_pair(a[i], i);
  sort(p + 1, p + n + 1, greater<pair<int, int> >());
  for (int i = 1; i <= n; i++) {
    int id = p[i].second;
    dp[id] = 0;
    for (int j = id % a[id]; j <= n; j += a[id])
      if (j != id && !dp[j]) {
        dp[id] = 1;
        break;
      }
  }
  for (int i = 1; i <= n; i++) putchar(66 - dp[i]);
  return putchar('\n'), 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.

The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path is a sequence of different cities, connected sequentially by roads. The company is allowed to choose by itself the paths to repair. The only condition they have to meet is that the two paths shouldn't cross (i.e. shouldn't have common cities).

It is known that the profit, the «Two Paths» company will get, equals the product of the lengths of the two paths. Let's consider the length of each road equals 1, and the length of a path equals the amount of roads in it. Find the maximum possible profit for the company.

Input

The first line contains an integer n (2 ≤ n ≤ 200), where n is the amount of cities in the country. The following n - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai, bi (1 ≤ ai, bi ≤ n).

Output

Output the maximum possible profit.

Examples

Input

4
1 2
2 3
3 4

Output

1

Input

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

Output

0

Input

6
1 2
2 3
2 4
5 4
6 4

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct FAIL {
  FAIL() {
    cout << "CHANGE!!!"
         << "\n";
  }
};
vector<vector<int>> g;
vector<int> used1;
vector<int> used2;
vector<int> used3;
int maxc = 0;
int maxi = -1;
int res = 0;
int n;
void dfs3(int x, int h = 0) {
  used3[x] = 1;
  if (h >= maxc) {
    maxc = h;
    maxi = x;
  }
  for (auto i : g[x]) {
    if (used3[i]) {
      continue;
    }
    dfs3(i, h + 1);
  }
}
void dfs2(int x, int h = 0) {
  used2[x] = 1;
  used3[x] = 1;
  auto t = used3;
  vector<int> last(n, -1);
  for (int i = (0); i < (n); ++i) {
    if (!used3[i]) {
      maxc = -1;
      dfs3(i);
      last[i] = maxi;
    }
  }
  used3 = t;
  for (int i = (0); i < (n); ++i) {
    if (last[i] != -1) {
      maxc = -1;
      dfs3(last[i]);
      res = max(res, h * maxc);
    }
  }
  used3 = t;
  for (auto i : g[x]) {
    if (used2[i]) {
      continue;
    }
    dfs2(i, h + 1);
  }
  used3[x] = 0;
}
void dfs1(int x) {
  used1[x] = 1;
  used2.assign(n, 0);
  dfs2(x);
  for (auto i : g[x]) {
    if (used1[i]) {
      continue;
    }
    dfs1(i);
  }
}
int main() {
  cin >> n;
  g.resize(n);
  used1.resize(n);
  used2.resize(n);
  used3.resize(n);
  for (int i = (0); i < (n - 1); ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs1(0);
  cout << res;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.

The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (x, y) either y = 0, or there is a cube with coordinates (x - 1, y - 1), (x, y - 1) or (x + 1, y - 1).

Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the m-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.

Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 109 + 9.

Input

The first line contains number m (2 ≤ m ≤ 105).

The following m lines contain the coordinates of the cubes xi, yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ 109) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.

No two cubes occupy the same place.

Output

In the only line print the answer to the problem.

Examples

Input

3
2 1
1 0
0 1

Output

19

Input

5
0 0
0 1
0 2
0 3
0 4

Output

2930

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct BLOCK {
  int id, outdegree;
  int x, y;
  vector<int> above;
  vector<int> below;
  bool alive;
  BLOCK() {}
  BLOCK(int id) : id(id) {
    alive = true;
    outdegree = 0;
  }
} block[100005];
int m;
int trans[100005];
const long long MOD = 1e9 + 9;
map<pair<int, int>, int> pos_to_id;
void preprocess() {
  for (int i = 0; i < m; ++i) {
    pair<int, int> now;
    now.first = block[i].x;
    now.second = block[i].y;
    pair<int, int> tmp = now;
    tmp.second--;
    if (pos_to_id.count(tmp) != 0) {
      ++block[i].outdegree;
      block[i].below.push_back(pos_to_id[tmp]);
      block[pos_to_id[tmp]].above.push_back(pos_to_id[now]);
    }
    --tmp.first;
    if (pos_to_id.count(tmp) != 0) {
      ++block[i].outdegree;
      block[i].below.push_back(pos_to_id[tmp]);
      block[pos_to_id[tmp]].above.push_back(pos_to_id[now]);
    }
    tmp.first += 2;
    if (pos_to_id.count(tmp) != 0) {
      ++block[i].outdegree;
      block[i].below.push_back(pos_to_id[tmp]);
      block[pos_to_id[tmp]].above.push_back(pos_to_id[now]);
    }
  }
}
bool cmp(const BLOCK& x, const BLOCK& y) {
  if (x.y > y.y) return true;
  if (x.y < y.y) return false;
  if (x.x < y.x) return true;
  if (x.x > y.x) return false;
  return false;
}
bool cmp2(const BLOCK& x, const BLOCK& y) { return x.id > y.id; }
void print() {
  cout << "===" << endl;
  for (int i = 0; i < m; ++i) {
    cout << block[i].id << " outdegree: " << block[i].outdegree << endl;
    for (int j = 0; j < block[i].above.size(); ++j) {
      cout << block[i].above[i] << " ";
    }
    cout << endl;
  }
  cout << "===" << endl;
}
bool availible(int block_code) {
  for (int i = 0; i < block[block_code].above.size(); ++i) {
    int target = trans[block[block_code].above[i]];
    if (!block[target].alive) continue;
    if (block[target].outdegree == 1) return false;
  }
  return true;
}
void take(int block_code, long long& ans,
          priority_queue<int, vector<int>, less<int> >& gpq,
          priority_queue<int, vector<int>, greater<int> >& lpq) {
  ans = (ans * m + block[block_code].id) % MOD;
  for (int i = 0; i < block[block_code].above.size(); ++i) {
    --block[trans[block[block_code].above[i]]].outdegree;
  }
  block[block_code].alive = false;
  for (int i = 0; i < block[block_code].below.size(); ++i) {
    int target = trans[block[block_code].below[i]];
    if (!block[target].alive) continue;
    if (availible(target)) {
      gpq.push(block[block_code].below[i]);
      lpq.push(block[block_code].below[i]);
    }
  }
}
void solve() {
  int last = m;
  long long ans = 0;
  priority_queue<int, vector<int>, less<int> > gpq;
  priority_queue<int, vector<int>, greater<int> > lpq;
  for (int i = 0; i < m; ++i) {
    if (availible(i)) {
      gpq.push(block[i].id);
      lpq.push(block[i].id);
    }
  }
  while (last) {
    while (gpq.size()) {
      int now = gpq.top();
      gpq.pop();
      int target = trans[now];
      if (!block[target].alive) continue;
      if (!availible(target)) continue;
      take(target, ans, gpq, lpq);
      break;
    }
    --last;
    if (last == 0) break;
    while (lpq.size()) {
      int now = lpq.top();
      lpq.pop();
      int target = trans[now];
      if (!block[target].alive) continue;
      if (!availible(target)) continue;
      take(target, ans, gpq, lpq);
      break;
    }
    --last;
  }
  cout << ans << endl;
}
void make_table() {
  for (int i = 0; i < m; ++i) {
    trans[block[i].id] = i;
  }
}
int main() {
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    block[i] = BLOCK(i);
    pair<int, int> tmp;
    scanf("%d%d", &tmp.first, &tmp.second);
    block[i].x = tmp.first;
    block[i].y = tmp.second;
    pos_to_id[tmp] = i;
  }
  preprocess();
  sort(block, block + m, cmp2);
  make_table();
  solve();
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the entire series someday and won't be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.

TV series have n seasons (numbered 1 through n), the i-th season has ai episodes (numbered 1 through ai). Polycarp thinks that if for some pair of integers x and y (x < y) exist both season x episode y and season y episode x then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs!

Input

The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons.

The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.

Output

Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.

Examples

Input

5
1 2 3 4 5

Output

0

Input

3
8 12 7

Output

3

Input

3
3 2 1

Output

2

Note

Possible pairs in the second example:

  1. x = 1, y = 2 (season 1 episode 2 <image> season 2 episode 1);
  2. x = 2, y = 3 (season 2 episode 3 <image> season 3 episode 2);
  3. x = 1, y = 3 (season 1 episode 3 <image> season 3 episode 1).

In the third example:

  1. x = 1, y = 2 (season 1 episode 2 <image> season 2 episode 1);
  2. x = 1, y = 3 (season 1 episode 3 <image> season 3 episode 1).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long ep[200005];
long long tree[400010], res;
vector<long long> vt[200005];
int n;
inline long long lowbit(int x) { return x & (-x); }
long long query(int pos) {
  long long ans = 0;
  while (pos) {
    ans += tree[pos];
    pos -= lowbit(pos);
  }
  return ans;
}
void update(int pos, int val) {
  while (pos < 200005) {
    tree[pos] += val;
    pos += lowbit(pos);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ep[i];
    ep[i] = min(ep[i], (long long)n);
    vt[min((long long)i - 1, ep[i])].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    update(ep[i], 1);
    for (auto it : vt[i]) res += query(n) - query(it - 1);
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).

A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.

You have integer n. Find some lucky permutation p of size n.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the required permutation size.

Output

Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.

Otherwise, print n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) after a space — the required permutation.

If there are multiple answers, you can print any of them.

Examples

Input

1

Output

1

Input

2

Output

-1

Input

4

Output

2 4 1 3

Input

5

Output

2 5 3 1 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ara[100005];
int main() {
  int n;
  cin >> n;
  if (n % 4 <= 1) {
    int in = 2;
    for (int i = 1; i <= n / 2; i += 2, in += 2) {
      ara[i] = in;
      ara[n - i + 1] = n - in + 1;
    }
    in = n;
    for (int i = 2; i <= n / 2; i += 2, in -= 2) {
      ara[i] = in;
      ara[n - i + 1] = n + 1 - in;
    }
    if (n % 4 == 1) ara[n / 2 + 1] = n / 2 + 1;
    for (int i = 1; i <= n; i++) cout << ara[i] << " ";
  } else {
    cout << -1;
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.

Note that the order of the points inside the group of three chosen points doesn't matter.

Input

The first line contains two integers: n and d (1 ≤ n ≤ 105; 1 ≤ d ≤ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 — the x-coordinates of the points that Petya has got.

It is guaranteed that the coordinates of the points in the input strictly increase.

Output

Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed d.

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

Examples

Input

4 3
1 2 3 4

Output

4

Input

4 2
-3 -2 -1 0

Output

2

Input

5 19
1 10 20 30 50

Output

1

Note

In the first sample any group of three points meets our conditions.

In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.

In the third sample only one group does: {1, 10, 20}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)2 * 1e9;
const long long MOD = (long long)1e9 + 7;
const long long MAX_N = 100000;
const long double pi = 3.1415926;
const long double eps = 1e-6;
long long a[MAX_N];
long long bin_search(long long x, long long* a, long long n) {
  long long l = 0, r = n, mid;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (x >= a[mid])
      l = mid;
    else
      r = mid;
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, d;
  cin >> n >> d;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long j = bin_search(a[i] + d, a, n);
    long long cnt = j - i;
    ans += cnt * (cnt - 1) / 2;
  }
  cout << ans;
  return 0;
}

```