### Prompt

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

We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly.

More formally, you've got two arrays of integers a1, a2, ..., an and b1, b2, ..., bn of length n. Also, you've got m queries of two types:

  1. Copy the subsegment of array a of length k, starting from position x, into array b, starting from position y, that is, execute by + q = ax + q for all integer q (0 ≤ q < k). The given operation is correct — both subsegments do not touch unexistent elements.
  2. Determine the value in position x of array b, that is, find value bx.

For each query of the second type print the result — the value of the corresponding element of array b.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of elements in the arrays and the number of queries, correspondingly. The second line contains an array of integers a1, a2, ..., an (|ai| ≤ 109). The third line contains an array of integers b1, b2, ..., bn (|bi| ≤ 109).

Next m lines contain the descriptions of the queries. The i-th line first contains integer ti — the type of the i-th query (1 ≤ ti ≤ 2). If ti = 1, then the i-th query means the copying operation. If ti = 2, then the i-th query means taking the value in array b. If ti = 1, then the query type is followed by three integers xi, yi, ki (1 ≤ xi, yi, ki ≤ n) — the parameters of the copying query. If ti = 2, then the query type is followed by integer xi (1 ≤ xi ≤ n) — the position in array b.

All numbers in the lines are separated with single spaces. It is guaranteed that all the queries are correct, that is, the copying borders fit into the borders of arrays a and b.

Output

For each second type query print the result on a single line.

Examples

Input

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

Output

0
3
-1
3
2
3
-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, typ;
int a[100005], b[100005];
struct query {
  int ain;
  int bin;
  int len;
};
int tree[400000];
int flag[400000];
inline void propagate(int n, int ts, int te) {
  if (flag[n]) {
    tree[n] = flag[n];
    if (ts != te) {
      flag[2 * n] = flag[n];
      flag[2 * n + 1] = flag[n];
    }
    flag[n] = 0;
  }
}
void update(int n, int ts, int te, int qs, int qe, int qno) {
  propagate(n, ts, te);
  if (te < qs || qe < ts)
    return;
  else if (qs <= ts && qe >= te) {
    tree[n] = qno;
    if (ts != te) {
      flag[2 * n] = qno;
      flag[2 * n + 1] = qno;
    }
    return;
  }
  update(2 * n, ts, (ts + te) / 2, qs, qe, qno);
  update(2 * n + 1, (ts + te) / 2 + 1, te, qs, qe, qno);
  tree[n] = qno;
}
int query(int n, int ts, int te, int nq) {
  propagate(n, ts, te);
  if ((ts == te) && (ts == nq))
    return tree[n];
  else if (nq > te || nq < ts)
    return -1;
  int lq = query(2 * n, ts, (ts + te) / 2, nq);
  int rq = query(2 * n + 1, (ts + te) / 2 + 1, te, nq);
  if (lq == -1) return rq;
  return lq;
}
int main() {
  scanf("%d%d", &n, &m);
  int ain, bin, len;
  struct query queries[100005];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &typ);
    if (typ == 1) {
      scanf("%d%d%d", &queries[i].ain, &queries[i].bin, &queries[i].len);
      update(1, 1, n, queries[i].bin, queries[i].bin + queries[i].len - 1, i);
    } else {
      int nq;
      scanf("%d", &nq);
      int qno = query(1, 1, n, nq);
      if (!qno)
        printf("%d\n", b[nq]);
      else {
        printf("%d\n", a[nq - queries[qno].bin + queries[qno].ain]);
      }
    }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.

Polycarp has n (2 ≤ n ≤ 10) bank cards, the PIN code of the i-th card is p_i.

Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all n codes would become different.

Formally, in one step, Polycarp picks i-th card (1 ≤ i ≤ n), then in its PIN code p_i selects one position (from 1 to 4), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.

Polycarp quickly solved this problem. Can you solve it?

Input

The first line contains integer t (1 ≤ t ≤ 100) — the number of test cases in the input. Then test cases follow.

The first line of each of t test sets contains a single integer n (2 ≤ n ≤ 10) — the number of Polycarp's bank cards. The next n lines contain the PIN codes p_1, p_2, ..., p_n — one per line. The length of each of them is 4. All PIN codes consist of digits only.

Output

Print the answers to t test sets. The answer to each set should consist of a n + 1 lines

In the first line print k — the least number of changes to make all PIN codes different. In the next n lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.

Example

Input

3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

Output

0
1234
0600
1
1337
1237
3
3139
3138
3939
6139

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int t, n, i, x, k, cur, ar[10005], sayi[11];
bool vis[10005], vus[10005], vas[10005];
void coutt(int x) {
  if (x / 1000)
    cout << x << endl;
  else if (x / 100)
    cout << 0 << x << endl;
  else if (x / 10)
    cout << 0 << 0 << x << endl;
  else
    cout << 0 << 0 << 0 << x << endl;
}
void solve() {
  for (i = 0; i < 10005; i++) {
    k = vis[i] = vus[i] = ar[i] = vas[i] = 0;
  }
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> sayi[i];
    ar[sayi[i]]++;
    vus[sayi[i]] = 1;
    vis[sayi[i]] = 1;
  }
  for (i = 0; i < 10005; i++) {
    if (ar[i]) k += ar[i] - 1;
  }
  cout << k << endl;
  for (i = 0; i < 10005; i++) {
    while (ar[i] > 1) {
      ar[i]--;
      cur = i - i % 10;
      while (vis[cur] or vus[cur]) cur++;
      vis[cur] = 1;
    }
  }
  for (i = 0; i < n; i++) {
    cur = sayi[i];
    if (vus[cur] and !vas[cur]) {
      coutt(cur);
      vas[cur] = 1;
      continue;
    }
    cur -= cur % 10;
    while ((!vis[cur] or vus[cur]) or vas[cur]) cur++;
    vas[cur] = 1;
    coutt(cur);
  }
}
int main() {
  cin >> t;
  while (t--) solve();
}

```


### Prompt

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

Polycarp has n different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100".

Polycarp wants to offer his set of n binary words to play a game "words". In this game, players name words and each next word (starting from the second) must start with the last character of the previous word. The first word can be any. For example, these sequence of words can be named during the game: "0101", "1", "10", "00", "00001".

Word reversal is the operation of reversing the order of the characters. For example, the word "0111" after the reversal becomes "1110", the word "11010" after the reversal becomes "01011".

Probably, Polycarp has such a set of words that there is no way to put them in the order correspondent to the game rules. In this situation, he wants to reverse some words from his set so that:

  * the final set of n words still contains different words (i.e. all words are unique);
  * there is a way to put all words of the final set of words in the order so that the final sequence of n words is consistent with the game rules.

Polycarp wants to reverse minimal number of words. Please, help him.

Input

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

The first line of a test case contains one integer n (1 ≤ n ≤ 2⋅10^5) — the number of words in the Polycarp's set. Next n lines contain these words. All of n words aren't empty and contains only characters '0' and '1'. The sum of word lengths doesn't exceed 4⋅10^6. All words are different.

Guaranteed, that the sum of n for all test cases in the input doesn't exceed 2⋅10^5. Also, guaranteed that the sum of word lengths for all test cases in the input doesn't exceed 4⋅10^6.

Output

Print answer for all of t test cases in the order they appear.

If there is no answer for the test case, print -1. Otherwise, the first line of the output should contain k (0 ≤ k ≤ n) — the minimal number of words in the set which should be reversed. The second line of the output should contain k distinct integers — the indexes of the words in the set which should be reversed. Words are numerated from 1 to n in the order they appear. If k=0 you can skip this line (or you can print an empty line). If there are many answers you can print any of them.

Example

Input

4
4
0001
1000
0011
0111
3
010
101
0
2
00000
00001
4
01
001
0001
00001

Output

1
3
-1
0

2
1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> vv[5];
map<string, int> aaa;
int vis[maxn], ans[maxn];
void add(string s, int len, int id) {
  if (s[0] == '0' && s[len - 1] == '0') vv[0].push_back(id);
  if (s[0] == '0' && s[len - 1] == '1') vv[1].push_back(id);
  if (s[0] == '1' && s[len - 1] == '0') vv[2].push_back(id);
  if (s[0] == '1' && s[len - 1] == '1') vv[3].push_back(id);
}
int solve() {
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; ++i) vis[i] = 0;
  aaa.clear();
  memset(vv, 0, sizeof(vv));
  for (int i = 1; i < n + 1; ++i) {
    string s;
    cin >> s;
    int len = s.length();
    add(s, len, i);
    aaa[s] = i;
    reverse(s.begin(), s.end());
    if (aaa.count(s))
      vis[aaa[s]] = 1, vis[i] = 1;
    else
      vis[i] = 0;
  }
  int sz[5];
  memset(sz, 0, sizeof(sz));
  for (int i = 0; i < 4; ++i) sz[i] = vv[i].size();
  if (!sz[1] && !sz[2]) {
    if (!sz[0] || !sz[3]) return puts("0");
    return puts("-1");
  } else {
    pair<int, int> p;
    p = sz[1] > sz[2] ? pair<int, int>(sz[1] - sz[2], 1)
                      : pair<int, int>(sz[2] - sz[1], 2);
    p.first /= 2;
    for (int i = 0; i < n; ++i) ans[i] = 0;
    int cnt(0);
    for (int i = 0; i < sz[p.second]; ++i) {
      if (!p.first) break;
      if (!vis[vv[p.second][i]]) {
        ans[cnt++] = vv[p.second][i];
        p.first--;
      }
    }
    if (p.first)
      return puts("-1");
    else {
      cout << cnt << '\n';
      for (int i = 0; i < cnt; ++i) cout << ans[i] << ' ';
      cout << '\n';
      return 0;
    }
  }
}
int main() {
  int _;
  cin >> _;
  while (_--) solve();
}

```


### Prompt

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

There is a tree with N vertices. The vertices are numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. The lengths of all the edges are 1.

Snuke likes some of the vertices. The information on his favorite vertices are given to you as a string s of length N. For each 1 ≤ i ≤ N, s_i is `1` if Snuke likes vertex i, and `0` if he does not like vertex i.

Initially, all the vertices are white. Snuke will perform the following operation exactly once:

* Select a vertex v that he likes, and a non-negative integer d. Then, paint all the vertices black whose distances from v are at most d.

Find the number of the possible combinations of colors of the vertices after the operation.

Constraints

* 2 ≤ N ≤ 2×10^5
* 1 ≤ a_i, b_i ≤ N
* The given graph is a tree.
* |s| = N
* s consists of `0` and `1`.
* s contains at least one occurrence of `1`.

Input

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

N
a_1 b_1
a_2 b_2
:
a_{N - 1} b_{N - 1}
s

Output

Print the number of the possible combinations of colors of the vertices after the operation.

Examples

Input

4
1 2
1 3
1 4
1100

Output

4

Input

5
1 2
1 3
1 4
4 5
11111

Output

11

Input

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

Output

8

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=200010,INF=0x7f7f7f7f;
lint ans=1;
char s[N];
int onecnt=0;
namespace T{
	const int E=N<<1;
	int to[E],bro[E],head[N],e=0;
	inline void init(){
		memset(head,-1,sizeof(head));
	}
	inline void ae(int u,int v){
		to[e]=v,bro[e]=head[u],head[u]=e++;
	}
	inline void add(int u,int v){
		ae(u,v),ae(v,u);
	}
	int dep[E],cnt[E];
	void dfs1(int x,int e){
		if(~e){
			dep[e]=1;
			cnt[e]=s[x]=='1';
		}
		for(int i=head[x],v;~i;i=bro[i]){
			if(i^e^1){
				dfs1(v=to[i],i);
				if(~e){
					cnt[e]+=cnt[i];
					apmax(dep[e],dep[i]+1);
				}
			}
		}
		if(~e){
			cnt[e^1]=onecnt-cnt[e];
		}
	}
	void dfs2(int x,int fa){
		int mx1=0,mx2=0,mn=s[x]=='1'?0:INF;
		int fr=0;
		for(int i=head[x];~i;i=bro[i]){
			if(dep[i]>mx1){
				mx2=mx1,mx1=dep[i];
				fr=i;
			}else if(dep[i]>mx2){
				mx2=dep[i];
			}
			if(cnt[i]){
				apmin(mn,dep[i]);
			}
		}
		ans+=max(min(mx1-1,mx2+1)-mn+1,0);
		for(int i=head[x],v;~i;i=bro[i]){
			if((v=to[i])!=fa){
				dep[i^1]=(fr!=i?mx1:mx2)+1;
				dfs2(v,x);
			}
		}
	}
}
inline lint Main(){
	int n=ni;
	T::init();
	for(int i=1;i<n;i++){
		T::add(ni,ni);
	}
	scanf("%s",s+1);
	for(int i=1;i<=n;i++){
		onecnt+=s[i]=='1';
	}
	T::dfs1(1,-1),T::dfs2(1,0);
	return ans;
}
int main(){
	printf("%lld\n",Main());
	return 0;
}
```


### Prompt

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

It is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.

Given an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.

Constraints

* 1 \leq r \leq 100
* r is an integer.

Input

Input is given from Standard Input in the following format:

r

Output

Print an integer representing the area of the regular dodecagon.

Examples

Input

4

Output

48

Input

15

Output

675

Input

80

Output

19200

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;cin >> a;printf("%d\n",3*a*a);
}

```


### Prompt

Develop a solution in CPP to the problem described below:

You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j.

Consider adding edges to G by repeatedly performing the following operation:

* Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c.

Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation.

Constraints

* 2 \leq N \leq 2000
* 1 \leq M \leq 2000
* 1 \leq a_i, b_i \leq N
* a_i \neq b_i
* 1 \leq c_j, d_j \leq N
* c_j \neq d_j
* G does not contain multiple edges.
* T is a tree.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
:
a_{N-1} b_{N-1}
c_1 d_1
:
c_M d_M

Output

Print the final number of edges in G.

Examples

Input

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

Output

6

Input

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

Output

11

Input

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

Output

27

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+10;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,fa[N][N],top[N][N],ans;
vi E[N];
bool G[N][N];

void dfs(int u,int ff,int t) {
	fa[t][u]=ff;
	for(auto v:E[u])
		if(v^ff) dfs(v,u,t);
}

void add(int x,int y) {
	if(G[x][y]||x==y) return;
	if(~top[x][y]) add(top[x][y],y);
	else if(~top[y][x]) add(top[y][x],x);
	else {
		vector<pii> e;
		for(int i=0;i<2;i++) {
			top[x][y]=y;G[x][y]=1;
			queue<int> q;q.push(y);
			while(!q.empty()) {
				int u=q.front();q.pop();
				for(auto v:E[u])
					if(v^fa[x][u]) {
						if(!~top[x][v]) top[x][v]=y,q.push(v);
						else if(G[x][v]) {
							G[x][v]=G[v][x]=0;top[x][v]=top[v][x]=-1;e.pb(mp(y,v));
						}
					}
			}
			swap(x,y);
		}
		for(auto x:e) add(x.fi,x.se);
	}
}

void dfs2(int u,int ff,int t) {
	if(top[t][u]==u) ++ans,t=u;
	for(auto v:E[u])
		if(v^ff) dfs2(v,u,t);
}

int main() {
	cin>>n>>m;
	for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
	for(int i=1;i<=n;i++) dfs(i,0,i);
	memset(top,-1,sizeof(top));
	for(int i=1,u,v;i<=m;i++) u=gi(),v=gi(),add(u,v);
	for(int i=1;i<=n;i++)
		for(auto j:E[i]) dfs2(j,i,i);
	cout<<ans/2;
	return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order of their difficulty. Unfortunately, some tasks can have the same difficulty, so the order in which one can perform the tasks may vary.

Menshykov, Uslada and Horace ask you to deal with this nuisance and come up with individual plans for each of them. The plan is a sequence describing the order in which an animal should do all the n tasks. Besides, each of them wants to have its own unique plan. Therefore three plans must form three different sequences. You are to find the required plans, or otherwise deliver the sad news to them by stating that it is impossible to come up with three distinct plans for the given tasks.

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.

Output

In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order they are done according to the first plan. In the third and fourth line print two remaining plans in the same form.

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

Examples

Input

4
1 3 3 1

Output

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

Input

5
2 4 1 4 8

Output

NO

Note

In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer.

In the second sample there are only two sequences of tasks that meet the conditions — [3, 1, 2, 4, 5] and [3, 1, 4, 2, 5]. Consequently, it is impossible to make three distinct sequences of tasks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} a[2010];
int cmp(node x, node y) { return x.x < y.x; }
node a1[2010], a2[2010], a3[2010];
int main() {
  int m, n, i, j, k;
  while (scanf("%d", &n) != -1) {
    memset(a, 0, sizeof(a));
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i].x);
      a[i].y = i;
    }
    sort(a + 1, a + 1 + n, cmp);
    for (i = 1; i <= n; i++) {
      a1[i].y = a[i].y;
      a1[i].x = a[i].x;
    }
    int flag = 0;
    for (i = 1; i <= n; i++) {
      if (a1[i].x == a1[i + 1].x && !flag) {
        k = i;
        flag = 1;
        a2[i].y = a1[i + 1].y;
        a2[i + 1].y = a1[i].y;
        i++;
        continue;
      }
      a2[i].x = a1[i].x;
      a2[i].y = a1[i].y;
    }
    if (flag == 0) {
      printf("NO\n");
      continue;
    }
    for (i = 1; i <= n; i++) {
      if (a1[i].x == a1[i + 1].x && i != k && flag == 1) {
        flag = 2;
        a3[i].y = a1[i + 1].y;
        a3[i + 1].y = a1[i].y;
        i++;
        continue;
      }
      a3[i].y = a1[i].y;
    }
    if (flag != 2) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    for (i = 1; i <= n; i++)
      if (i == 1)
        printf("%d", a1[i].y);
      else
        printf(" %d", a1[i].y);
    printf("\n");
    for (i = 1; i <= n; i++)
      if (i == 1)
        printf("%d", a2[i].y);
      else
        printf(" %d", a2[i].y);
    printf("\n");
    for (i = 1; i <= n; i++)
      if (i == 1)
        printf("%d", a3[i].y);
      else
        printf(" %d", a3[i].y);
    printf("\n");
  }
  return 0;
}

```


### Prompt

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

Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank.

The Wizarding bank is in the form of a tree with total n vaults where each vault has some type, denoted by a number between 1 to m. A tree is an undirected connected graph with no cycles.

The vaults with the highest security are of type k, and all vaults of type k have the highest security.

There can be at most x vaults of highest security.

Also, if a vault is of the highest security, its adjacent vaults are guaranteed to not be of the highest security and their type is guaranteed to be less than k.

Harry wants to consider every possibility so that he can easily find the best path to reach Bellatrix's vault. So, you have to tell him, given the tree structure of Gringotts, the number of possible ways of giving each vault a type such that the above conditions hold.

Input

The first line of input contains two space separated integers, n and m — the number of vaults and the number of different vault types possible. (1 ≤ n ≤ 105, 1 ≤ m ≤ 109).

Each of the next n - 1 lines contain two space separated integers ui and vi (1 ≤ ui, vi ≤ n) representing the i-th edge, which shows there is a path between the two vaults ui and vi. It is guaranteed that the given graph is a tree.

The last line of input contains two integers k and x (1 ≤ k ≤ m, 1 ≤ x ≤ 10), the type of the highest security vault and the maximum possible number of vaults of highest security.

Output

Output a single integer, the number of ways of giving each vault a type following the conditions modulo 109 + 7.

Examples

Input

4 2
1 2
2 3
1 4
1 2

Output

1

Input

3 3
1 2
1 3
2 1

Output

13

Input

3 1
1 2
1 3
1 1

Output

0

Note

In test case 1, we cannot have any vault of the highest security as its type is 1 implying that its adjacent vaults would have to have a vault type less than 1, which is not allowed. Thus, there is only one possible combination, in which all the vaults have type 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int N = 100002;
int n, m, k, x;
long long DP[N][3][12], storage[3][12];
vector<int> adj[N];
void dfs(int v, int par) {
  DP[v][0][0] = k - 1;
  DP[v][1][1] = 1;
  DP[v][2][0] = m - k;
  for (auto vv : adj[v]) {
    if (vv == par) continue;
    dfs(vv, v);
    memset(storage, 0, sizeof(storage));
    for (int j = 0; j <= x; j++)
      for (int k = 0; k <= x; k++) {
        if (j + k <= x)
          storage[0][j + k] =
              (storage[0][j + k] +
               DP[v][0][j] * (DP[vv][0][k] + DP[vv][1][k] + DP[vv][2][k])) %
              (1000000007LL);
        if (j + k <= x)
          storage[1][j + k] =
              (storage[1][j + k] + DP[v][1][j] * DP[vv][0][k]) % (1000000007LL);
        if (j + k <= x)
          storage[2][j + k] = (storage[2][j + k] +
                               DP[v][2][j] * (DP[vv][0][k] + DP[vv][2][k])) %
                              (1000000007LL);
      }
    for (int j = 0; j <= x; j++) {
      DP[v][0][j] = storage[0][j];
      DP[v][1][j] = storage[1][j];
      DP[v][2][j] = storage[2][j];
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int e = n - 1;
  while (e--) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  scanf("%d%d", &k, &x);
  dfs(1, -1);
  long long ans = 0;
  for (int j = 0; j <= x; j++) {
    ans = (ans + DP[1][0][j]) % (1000000007LL);
    ans = (ans + DP[1][1][j]) % (1000000007LL);
    ans = (ans + DP[1][2][j]) % (1000000007LL);
  }
  ans %= (1000000007LL);
  ans += (1000000007LL);
  ans %= (1000000007LL);
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

— Hey folks, how do you like this problem?

— That'll do it.

BThero is a powerful magician. He has got n piles of candies, the i-th pile initially contains a_i candies. BThero can cast a copy-paste spell as follows:

  1. He chooses two piles (i, j) such that 1 ≤ i, j ≤ n and i ≠ j.
  2. All candies from pile i are copied into pile j. Formally, the operation a_j := a_j + a_i is performed.

BThero can cast this spell any number of times he wants to — but unfortunately, if some pile contains strictly more than k candies, he loses his magic power. What is the maximum number of times BThero can cast the spell without losing his power?

Input

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

Each test case consists of two lines:

  * the first line contains two integers n and k (2 ≤ n ≤ 1000, 2 ≤ k ≤ 10^4);
  * the second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k).

It is guaranteed that the sum of n over all test cases does not exceed 1000, and the sum of k over all test cases does not exceed 10^4.

Output

For each test case, print one integer — the maximum number of times BThero can cast the spell without losing his magic power.

Example

Input

3
2 2
1 1
3 5
1 2 3
3 7
3 2 2

Output

1
5
4

Note

In the first test case we get either a = [1, 2] or a = [2, 1] after casting the spell for the first time, and it is impossible to cast it again.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, k, a;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    vector<int> candie;
    for (int i = 0; i < n; i++) {
      cin >> a;
      candie.push_back(a);
    }
    sort(candie.begin(), candie.end());
    long long out = 0;
    for (int i = 1; i < n; i++) {
      out += (k - candie[i]) / candie[0];
    }
    printf("%lld\n", out);
  }
}

```


### Prompt

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

The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.

Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge contains its value written on it as a non-negative integer.

A bad boy Vasya came up to the board and wrote number sv near each node v — the sum of values of all edges that are incident to this node. Then Vasya removed the edges and their values from the board.

Your task is to restore the original tree by the node colors and numbers sv.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 105) — the number of nodes in the tree. Next n lines contain pairs of space-separated integers ci, si (0 ≤ ci ≤ 1, 0 ≤ si ≤ 109), where ci stands for the color of the i-th vertex (0 is for white, 1 is for black), and si represents the sum of values of the edges that are incident to the i-th vertex of the tree that is painted on the board.

Output

Print the description of n - 1 edges of the tree graph. Each description is a group of three integers vi, ui, wi (1 ≤ vi, ui ≤ n, vi ≠ ui, 0 ≤ wi ≤ 109), where vi and ui — are the numbers of the nodes that are connected by the i-th edge, and wi is its value. Note that the following condition must fulfill cvi ≠ cui.

It is guaranteed that for any input data there exists at least one graph that meets these data. If there are multiple solutions, print any of them. You are allowed to print the edges in any order. As you print the numbers, separate them with spaces.

Examples

Input

3
1 3
1 2
0 5

Output

3 1 3
3 2 2

Input

6
1 0
0 3
1 8
0 2
0 3
0 0

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, w;
priority_queue<pair<int, int> > pq[2];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    pq[a].push(make_pair(-b, i));
  }
  w = 0;
  for (int i = 1; i <= n - 1; ++i) {
    if (-pq[w].top().first < -pq[w ^ 1].top().first) w ^= 1;
    if ((pq[w].top().first == pq[w ^ 1].top().first) &&
        (pq[w].size() > pq[w ^ 1].size()))
      w ^= 1;
    int a = -pq[w].top().first;
    int b = pq[w].top().second;
    printf("%d %d %d\n", pq[w].top().second, pq[w ^ 1].top().second,
           -pq[w ^ 1].top().first);
    a -= -pq[w ^ 1].top().first;
    pq[0].pop();
    pq[1].pop();
    pq[w].push(make_pair(-a, b));
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.

Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)

Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!

Input

The first line of the input contains three space-separated integers l, r and k (1 ≤ l ≤ r ≤ 1018, 2 ≤ k ≤ 109).

Output

Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).

Examples

Input

1 10 2

Output

1 2 4 8

Input

2 4 5

Output

-1

Note

Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long int l, r, k, x, num, temp;
  cin >> l >> r >> k;
  x = (double(log(l) / log(k)));
  num = 1;
  bool flag = 0;
  while (num <= r) {
    if (num >= l) {
      cout << num << " ";
      flag = 1;
    }
    temp = num * k;
    if (temp / num != k) break;
    num = temp;
  }
  if (flag == 0) {
    cout << "-1";
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.

For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction —  it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to).

Here is one exercise that you have found in your task list. You are given the word s. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language.

Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match.

Let's look at the example: the word abacabaca is given. This word can be obtained in the following ways: <image>, where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {aca, ba, ca}.

Input

The only line contains a string s (5 ≤ |s| ≤ 104) consisting of lowercase English letters.

Output

On the first line print integer k — a number of distinct possible suffixes. On the next k lines print suffixes.

Print suffixes in lexicographical (alphabetical) order.

Examples

Input

abacabaca

Output

3
aca
ba
ca

Input

abaca

Output

0

Note

The first test was analysed in the problem statement.

In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 10005;
const ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  bool dp[N][2] = {0};
  set<string> u;
  int n;
  cin >> s;
  n = s.size();
  s = '#' + s + '#' + '#' + '#';
  dp[n + 1][0] = dp[n + 1][1] = 1;
  for (int i = n; i >= 7; i--) {
    string x, y, x1, y1;
    x = s[i - 1];
    x += s[i];
    y = s[i - 2];
    y += s[i - 1];
    y += s[i];
    x1 = s[i + 1];
    x1 += s[i + 2];
    y1 = s[i + 1];
    y1 += s[i + 2];
    y1 += s[i + 3];
    if ((x != x1 && (dp[i + 1][0] || dp[i + 1][1])) ||
        (x == x1 && dp[i + 1][1])) {
      dp[i - 1][0] = 1;
      u.insert(x);
    }
    if (i > 7)
      if ((y != y1 && (dp[i + 1][0] || dp[i + 1][1])) ||
          (y == y1 && dp[i + 1][0])) {
        dp[i - 2][1] = 1;
        u.insert(y);
      }
  }
  cout << u.size() << E;
  for (auto i : u) {
    cout << i << E;
  }
  return 0;
}

```


### Prompt

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

In this problem you will meet the simplified model of game Pudding Monsters.

An important process in developing any game is creating levels. A game field in Pudding Monsters is an n × n rectangular grid, n of its cells contain monsters and some other cells contain game objects. The gameplay is about moving the monsters around the field. When two monsters are touching each other, they glue together into a single big one (as they are from pudding, remember?).

<image>

Statistics showed that the most interesting maps appear if initially each row and each column contains exactly one monster and the rest of map specifics is set up by the correct positioning of the other game objects.

A technique that's widely used to make the development process more efficient is reusing the available resources. For example, if there is a large n × n map, you can choose in it a smaller k × k square part, containing exactly k monsters and suggest it as a simplified version of the original map.

You wonder how many ways there are to choose in the initial map a k × k (1 ≤ k ≤ n) square fragment, containing exactly k pudding monsters. Calculate this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 3 × 105) — the size of the initial field.

Next n lines contain the coordinates of the cells initially containing monsters. The i-th of the next lines contains two numbers ri, ci (1 ≤ ri, ci ≤ n) — the row number and the column number of the cell that initially contains the i-th monster.

It is guaranteed that all ri are distinct numbers and all ci are distinct numbers.

Output

Print the number of distinct square fragments of the original field that can form a new map.

Examples

Input

5
1 1
4 3
3 2
2 4
5 5

Output

10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 300005;
pair<int, int> st[4 * N];
int lz[4 * N];
void prop(int p, int L, int R) {
  if (lz[p]) {
    st[p].first += lz[p];
    if (L < R) {
      lz[2 * p] += lz[p];
      lz[2 * p + 1] += lz[p];
    }
    lz[p] = 0;
  }
}
pair<int, int> comb(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first) return a;
  if (b.first < a.first) return b;
  return {a.first, a.second + b.second};
}
void upd(int p, int L, int R, int i, int j, int val) {
  prop(p, L, R);
  if (i > R or j < L) return;
  if (L >= i and R <= j) {
    lz[p] = val;
    prop(p, L, R);
    return;
  }
  int mid = (L + R) / 2;
  upd(2 * p, L, mid, i, j, val);
  upd(2 * p + 1, mid + 1, R, i, j, val);
  st[p] = comb(st[2 * p], st[2 * p + 1]);
}
pair<int, int> query(int p, int L, int R, int i, int j) {
  prop(p, L, R);
  if (i > R or j < L) return make_pair(int(1e9), 0);
  if (L >= i and R <= j) return st[p];
  int mid = (L + R) / 2;
  return comb(query(2 * p, L, mid, i, j), query(2 * p + 1, mid + 1, R, i, j));
}
void build(int p, int L, int R) {
  if (L == R) {
    st[p] = {-L, 1};
    return;
  }
  int mid = (L + R) / 2;
  build(2 * p, L, mid);
  build(2 * p + 1, mid + 1, R);
  st[p] = comb(st[2 * p], st[2 * p + 1]);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  {
    vector<pair<int, int>> tmp(n);
    for (auto &p : tmp) scanf("%d %d", &p.first, &p.second);
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < n; i++) a[i] = tmp[i].second;
  }
  build(1, 0, n - 1);
  vector<int> rigmn(n), rigmx(n);
  stack<int> smx, smn;
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    while (!smx.empty() and a[smx.top()] < a[i]) {
      int id = smx.top();
      smx.pop();
      int nx = smx.empty() ? n - 1 : smx.top() - 1;
      upd(1, 0, n - 1, id, nx, -a[id]);
    }
    while (!smn.empty() and a[smn.top()] > a[i]) {
      int id = smn.top();
      smn.pop();
      int nx = smn.empty() ? n - 1 : smn.top() - 1;
      upd(1, 0, n - 1, id, nx, a[id]);
    }
    rigmn[i] = smn.empty() ? n - 1 : smn.top() - 1;
    rigmx[i] = smx.empty() ? n - 1 : smx.top() - 1;
    smx.push(i);
    smn.push(i);
    upd(1, 0, n - 1, i, rigmn[i], -a[i]);
    upd(1, 0, n - 1, i, rigmx[i], a[i]);
    auto tmp = query(1, 0, n - 1, i, n - 1);
    if (tmp.first == -i) {
      ans += tmp.second;
    }
  }
  printf("%lld\n", ans);
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.

Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend.

Each of the following n lines contains two integers xi and yi ( - 1000 ≤ xi, yi ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.

It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.

Output

Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print  - 1.

Examples

Input

2
0 0
1 1

Output

1

Input

1
1 1

Output

-1

Note

In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.

In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int t1, t2;
  set<int> xs, ys;
  for (long long i = 0; i < n; i++) {
    cin >> t1 >> t2;
    xs.insert(t1);
    ys.insert(t2);
  }
  if (xs.size() == 2 && ys.size() == 2) {
    auto it1 = xs.begin(), it2 = ys.begin();
    int ans = abs(*(it1++) - *it1) * abs(*(it2++) - *it2);
    cout << ans;
  } else {
    cout << -1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:

  * f(0) = 0;
  * f(2·x) = f(x);
  * f(2·x + 1) = f(x) + 1.

Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.

Input

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

The numbers in the lines are separated by single spaces.

Output

In a single line print the answer to the problem.

Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3
1 2 4

Output

3

Input

3
5 3 1

Output

1

Note

In the first sample any pair (i, j) will do, so the answer is 3.

In the second sample only pair (1, 2) will do.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, l, m, n, k2, c;
  cin >> n;
  long long int ar[100] = {0};
  for (i = 0; i < n; i++) {
    cin >> k2;
    c = 0;
    while (k2 > 0) {
      if (k2 & 1) c++;
      k2 = k2 >> 1;
    }
    ar[c]++;
  }
  long long int ans = 0;
  for (i = 0; i < 100; i++) {
    ans += (ar[i] * (ar[i] - 1)) / 2;
  }
  cout << ans;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.

There is a collection of n proteins (not necessarily distinct). Each protein is a string consisting of lowercase Latin letters. The problem that the scientists offered to the Beaver is to select a subcollection of size k from the initial collection of proteins so that the representativity of the selected subset of proteins is maximum possible.

The Smart Beaver from ABBYY did some research and came to the conclusion that the representativity of a collection of proteins can be evaluated by a single number, which is simply calculated. Let's suppose we have a collection {a1, ..., ak} consisting of k strings describing proteins. The representativity of this collection is the following value:

<image>

where f(x, y) is the length of the longest common prefix of strings x and y; for example, f("abc", "abd") = 2, and f("ab", "bcd") = 0.

Thus, the representativity of collection of proteins {"abc", "abd", "abe"} equals 6, and the representativity of collection {"aaa", "ba", "ba"} equals 2.

Having discovered that, the Smart Beaver from ABBYY asked the Cup contestants to write a program that selects, from the given collection of proteins, a subcollection of size k which has the largest possible value of representativity. Help him to solve this problem!

Input

The first input line contains two integers n and k (1 ≤ k ≤ n), separated by a single space. The following n lines contain the descriptions of proteins, one per line. Each protein is a non-empty string of no more than 500 characters consisting of only lowercase Latin letters (a...z). Some of the strings may be equal.

The input limitations for getting 20 points are:

  * 1 ≤ n ≤ 20

The input limitations for getting 50 points are:

  * 1 ≤ n ≤ 100

The input limitations for getting 100 points are:

  * 1 ≤ n ≤ 2000

Output

Print a single number denoting the largest possible value of representativity that a subcollection of size k of the given collection of proteins can have.

Examples

Input

3 2
aba
bzd
abq

Output

2

Input

4 3
eee
rrr
ttt
qqq

Output

0

Input

4 3
aaa
abba
abbc
abbd

Output

9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 10;
int n, k;
string a[N];
int lcp[N];
int tot, f[N * 3][N];
int *solve(int l, int r) {
  int *ff = f[++tot];
  if (l == r) return ff;
  int w = l + 1;
  for (int i = (l + 1); i <= (r); i++)
    if (lcp[i] < lcp[w]) w = i;
  int *fl = solve(l, w - 1), *fr = solve(w, r), n = r - l + 1;
  for (int k = (1); k <= (n); k++)
    for (int k1 = (0); k1 <= (k); k1++)
      ff[k] = max(ff[k], fl[k1] + fr[k - k1] + k1 * (k - k1) * lcp[w]);
  return ff;
}
int main() {
  cin >> n >> k;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = (2); i <= (n); i++)
    for (int j = (1);
         j <= (min(((int)(a[i]).size()), ((int)(a[i - 1]).size()))); j++)
      if (a[i][j - 1] != a[i - 1][j - 1])
        break;
      else
        lcp[i] = j;
  cout << solve(1, n)[k] << endl;
  return 0;
}

```


### Prompt

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

Limak is a little grizzly bear. He will once attack Deerland but now he can only destroy trees in role-playing games. Limak starts with a tree with one vertex. The only vertex has index 1 and is a root of the tree.

Sometimes, a game chooses a subtree and allows Limak to attack it. When a subtree is attacked then each of its edges is destroyed with probability <image>, independently of other edges. Then, Limak gets the penalty — an integer equal to the height of the subtree after the attack. The height is defined as the maximum number of edges on the path between the root of the subtree and any vertex in the subtree.

You must handle queries of two types.

  * 1 v denotes a query of the first type. A new vertex appears and its parent is v. A new vertex has the next available index (so, new vertices will be numbered 2, 3, ...).
  * 2 v denotes a query of the second type. For a moment let's assume that the game allows Limak to attack a subtree rooted in v. Then, what would be the expected value of the penalty Limak gets after the attack?

In a query of the second type, Limak doesn't actually attack the subtree and thus the query doesn't affect next queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 500 000) — the number of queries.

Then, q lines follow. The i-th of them contains two integers typei and vi (1 ≤ typei ≤ 2). If typei = 1 then vi denotes a parent of a new vertex, while if typei = 2 then you should print the answer for a subtree rooted in vi.

It's guaranteed that there will be at least 1 query of the second type, that is, the output won't be empty.

It's guaranteed that just before the i-th query a vertex vi already exists.

Output

For each query of the second type print one real number —the expected value of the penalty if Limak attacks the given subtree. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if <image>.

Examples

Input

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

Output

0.7500000000
0.5000000000
1.1875000000

Input

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

Output

0.0000000000
0.9375000000
0.9687500000

Note

Below, you can see the drawing for the first sample. Red circles denote queries of the second type.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double dp[500010][41];
int n, T, fa[500010];
void dfs(int x, int i, double tmp) {
  if (i == 41) return;
  if (x == 0) return;
  double t = dp[x][i];
  dp[x][i] *= tmp;
  dfs(fa[x], i + 1, (dp[x][i] + 1) / (t + 1));
}
int main() {
  scanf("%d", &T);
  n = 1;
  for (int i = 0; i <= 40; i++) dp[1][i] = 1;
  while (T--) {
    int op, v;
    scanf("%d%d", &op, &v);
    if (op == 1) {
      n++;
      fa[n] = v;
      for (int i = 0; i <= 40; i++) dp[n][i] = 1;
      double t = dp[v][0];
      dp[v][0] *= 0.5;
      dfs(fa[v], 1, (dp[v][0] + 1) / (t + 1));
    } else {
      double ans = 0;
      for (int i = 1; i <= 40; i++)
        ans += (double)i * (dp[v][i] - dp[v][i - 1]);
      printf("%.10lf\n", ans);
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)).

An inversion in the b array is a pair of integers i and j such that 1 ≤ i < j ≤ n and b_i > b_j.

You should choose x in such a way that the number of inversions in b is minimized. If there are several options for x — output the smallest one.

Input

First line contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of elements in a.

Second line contains n space-separated integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.

Output

Output two integers: the minimum possible number of inversions in b, and the minimum possible value of x, which achieves those number of inversions.

Examples

Input

4
0 1 3 2

Output

1 0

Input

9
10 7 9 10 7 5 5 3 5

Output

4 14

Input

3
8 10 3

Output

0 8

Note

In the first sample it is optimal to leave the array as it is by choosing x = 0.

In the second sample the selection of x = 14 results in b: [4, 9, 7, 4, 9, 11, 11, 13, 11]. It has 4 inversions:

  * i = 2, j = 3;
  * i = 2, j = 4;
  * i = 3, j = 4;
  * i = 8, j = 9.

In the third sample the selection of x = 8 results in b: [0, 2, 11]. It has no inversions.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int temp[300005];
long long _mergeSort(int arr[], int temp[], int left, int right);
long long merge(int arr[], int temp[], int left, int mid, int right);
long long mergeSort(int arr[], int array_size) {
  return _mergeSort(arr, temp, 0, array_size - 1);
}
long long _mergeSort(int arr[], int temp[], int left, int right) {
  int mid;
  long long inv_count = 0;
  if (right > left) {
    mid = (right + left) / 2;
    inv_count += _mergeSort(arr, temp, left, mid);
    inv_count += _mergeSort(arr, temp, mid + 1, right);
    inv_count += merge(arr, temp, left, mid + 1, right);
  }
  return inv_count;
}
long long merge(int arr[], int temp[], int left, int mid, int right) {
  int i, j, k;
  long long inv_count = 0;
  i = left;
  j = mid;
  k = left;
  while ((i <= mid - 1) && (j <= right)) {
    if (arr[i] <= arr[j]) {
      temp[k++] = arr[i++];
    } else {
      temp[k++] = arr[j++];
      inv_count = inv_count + (mid - i);
    }
  }
  while (i <= mid - 1) temp[k++] = arr[i++];
  while (j <= right) temp[k++] = arr[j++];
  for (i = left; i <= right; i++) arr[i] = temp[i];
  return inv_count;
}
int a[300005];
int b[300005];
long long invCount(int a[], int n) {
  for (int i = 0; i < n; ++i) {
    b[i] = a[i];
  }
  return mergeSort(b, n);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  bool fresh = true;
  long long ic0 = invCount(a, n);
  long long ans = 0;
  for (int bit = 29; bit >= 0; --bit) {
    if (!fresh) {
      ic0 = invCount(a, n);
      fresh = true;
    }
    for (int i = 0; i < n; ++i) {
      a[i] ^= (1 << bit);
    }
    long long ic1 = invCount(a, n);
    if (ic1 < ic0) {
      ans ^= (1 << bit);
      fresh = false;
      continue;
    }
    for (int i = 0; i < n; ++i) {
      a[i] ^= (1 << bit);
    }
  }
  cout << invCount(a, n) << " " << ans;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given n integer numbers a_1, a_2, ..., a_n. Consider graph on n nodes, in which nodes i, j (i≠ j) are connected if and only if, a_i AND a_j≠ 0, where AND denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

Find the length of the shortest cycle in this graph or determine that it doesn't have cycles at all.

Input

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

The second line contains n integer numbers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{18}).

Output

If the graph doesn't have any cycles, output -1. Else output the length of the shortest cycle.

Examples

Input

4
3 6 28 9

Output

4

Input

5
5 12 9 16 48

Output

3

Input

4
1 2 4 8

Output

-1

Note

In the first example, the shortest cycle is (9, 3, 6, 28).

In the second example, the shortest cycle is (5, 12, 9).

The graph has no cycles in the third example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool graph[120][120];
int bfs(int startNode, int endNode) {
  queue<int> Q;
  bool visited[120];
  int dist[120];
  memset(visited, false, sizeof(visited));
  Q.push(startNode);
  visited[startNode] = true;
  dist[startNode] = 0;
  while (!Q.empty()) {
    int curr = Q.front();
    Q.pop();
    if (curr == endNode) {
      return dist[curr];
    }
    for (int i = 0; i < 120; ++i) {
      if (!visited[i] && graph[curr][i]) {
        visited[i] = true;
        dist[i] = dist[curr] + 1;
        Q.push(i);
      }
    }
  }
  return -1;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> arr;
  memset(graph, false, sizeof(graph));
  for (int i = 0; i < n; ++i) {
    long long temp;
    scanf("%lld", &temp);
    if (temp > 0) arr.push_back(temp);
  }
  if (arr.size() > 120) {
    printf("3");
    return 0;
  }
  for (int i = 0; i < arr.size(); ++i) {
    for (int j = 0; j < arr.size(); ++j) {
      for (long long bt = 1; bt <= (1LL << 60); bt *= 2) {
        if (i == j) continue;
        if ((arr[i] & bt) && (arr[j] & bt)) {
          graph[i][j] = true;
        }
      }
    }
  }
  int best = -1;
  for (int i = 0; i < arr.size(); ++i) {
    for (int j = 0; j < arr.size(); ++j) {
      if (i == j) continue;
      if (!graph[i][j]) continue;
      graph[i][j] = false;
      graph[j][i] = false;
      int result = bfs(i, j);
      if (result != -1) {
        if (best == -1)
          best = result + 1;
        else
          best = min(best, result + 1);
      }
      graph[i][j] = true;
      graph[j][i] = true;
    }
  }
  printf("%d", best);
  return 0;
}

```


### Prompt

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

The sequence of m integers is called the permutation if it contains all integers from 1 to m exactly once. The number m is called the length of the permutation.

Dreamoon has two permutations p_1 and p_2 of non-zero lengths l_1 and l_2.

Now Dreamoon concatenates these two permutations into another sequence a of length l_1 + l_2. First l_1 elements of a is the permutation p_1 and next l_2 elements of a is the permutation p_2.

You are given the sequence a, and you need to find two permutations p_1 and p_2. If there are several possible ways to restore them, you should find all of them. (Note that it is also possible that there will be no ways.)

Input

The first line contains an integer t (1 ≤ t ≤ 10 000) denoting the number of test cases in the input.

Each test case contains two lines. The first line contains one integer n (2 ≤ n ≤ 200 000): the length of a. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n-1).

The total sum of n is less than 200 000.

Output

For each test case, the first line of output should contain one integer k: the number of ways to divide a into permutations p_1 and p_2.

Each of the next k lines should contain two integers l_1 and l_2 (1 ≤ l_1, l_2 ≤ n, l_1 + l_2 = n), denoting, that it is possible to divide a into two permutations of length l_1 and l_2 (p_1 is the first l_1 elements of a, and p_2 is the last l_2 elements of a). You can print solutions in any order.

Example

Input

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

Output

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

Note

In the first example, two possible ways to divide a into permutations are \{1\} + \{4, 3, 2, 1\} and \{1,4,3,2\} + \{1\}.

In the second example, the only way to divide a into permutations is \{2,4,1,3\} + \{2,1\}.

In the third example, there are no possible ways.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int sz = 100005;
const long long int szz = 1000006;
set<long long int> s1, s2;
long long int n;
bool check1(long long int ar[]) {
  bool flag = true;
  for (long long int i = 0; i < n; i++) {
    if (s1.find(ar[i]) == s1.end() and flag) {
      s1.insert(ar[i]);
    } else {
      flag = false;
      s2.insert(ar[i]);
    }
  }
  long long int ptr = 1;
  for (auto x : s1) {
    if (x != ptr) return false;
    ptr++;
  }
  ptr = 1;
  for (auto x : s2) {
    if (x != ptr) return false;
    ptr++;
  }
  return true;
}
bool check2(long long int ar[]) {
  bool flag = true;
  for (long long int i = n - 1; i >= 0; i--) {
    if (s2.find(ar[i]) == s2.end() and flag) {
      s2.insert(ar[i]);
    } else
      s1.insert(ar[i]), flag = false;
  }
  long long int ptr = 1;
  for (auto x : s1) {
    if (x != ptr) return false;
    ptr++;
  }
  ptr = 1;
  for (auto x : s2) {
    if (x != ptr) return false;
    ptr++;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int ar[n];
    s1.clear();
    s2.clear();
    for (long long int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    long long int sz11 = -1, sz12 = -1, sz21 = -1, sz22 = -1;
    long long int ans = 0;
    if (check1(ar) and
        (long long int) s1.size() + (long long int)s2.size() == n) {
      sz11 = s1.size();
      sz12 = s2.size();
      ans++;
    }
    s1.clear();
    s2.clear();
    if (check2(ar) and
        (long long int) s1.size() + (long long int)s2.size() == n and
        (long long int) s1.size() != sz11) {
      sz21 = s1.size();
      sz22 = s2.size();
      ans++;
    }
    cout << ans << "\n";
    if (ans != 0) {
      if (sz11 != -1) {
        cout << sz11 << " " << sz12 << "\n";
      }
      if (sz21 != -1) {
        cout << sz21 << " " << sz22 << "\n";
      }
    }
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 1310 = 11012, so it has 3 bits set and 13 will be reduced to 3 in one operation.

He calls a number special if the minimum number of operations to reduce it to 1 is k.

He wants to find out how many special numbers exist which are not greater than n. Please help the Travelling Salesman, as he is about to reach his destination!

Since the answer can be large, output it modulo 109 + 7.

Input

The first line contains integer n (1 ≤ n < 21000).

The second line contains integer k (0 ≤ k ≤ 1000).

Note that n is given in its binary representation without any leading zeros.

Output

Output a single integer — the number of special numbers not greater than n, modulo 109 + 7.

Examples

Input

110
2

Output

3

Input

111111011
2

Output

169

Note

In the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string n;
int k, num = 0;
long long dp[1001] = {0};
long long comb[1002][1002];
long long ones(long long n) {
  long long num = 0LL;
  while (n) {
    if (n & 1) num++;
    n >>= 1;
  }
  return num;
}
long long solve(long long num) {
  long long res = 0LL;
  long long s = n.size();
  for (int i = 0; i < s; i++) {
    if (n[i] == '1') {
      res += comb[s - i - 1][num];
      num--;
      res %= 1000000007;
    }
    if (num < 0) break;
  }
  return res + ((num == 0) ? 1 : 0);
}
int main() {
  cin >> n >> k;
  if (k == 0) {
    cout << 1 << endl;
    return 0;
  }
  long long num = 0;
  for (int i = 0; i < n.size(); i++)
    if (n[i] == '1') num++;
  dp[1] = 0;
  long long s = n.size();
  for (int i = 2; i <= s; i++) {
    long long res = ones(i);
    dp[i] = dp[res] + 1;
  }
  comb[0][0] = 1;
  for (int i = 1; i < 1001; i++) {
    comb[i][0] = 1;
    comb[i][1] = i;
    comb[i][i] = 1;
  }
  for (int i = 2; i <= s; i++) {
    for (int j = 1; j <= i; j++) {
      comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % 1000000007;
    }
  }
  long long out = 0LL;
  for (int i = 1; i <= s; i++) {
    if (dp[i] == k - 1) {
      out += solve(i);
    }
    out %= 1000000007;
  }
  cout << ((k == 1) ? out - 1 : out) << endl;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i.

Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.

Constraints

* 1≦N≦10^5
* 0≦A_i≦N-1

Input

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

N
A_1 A_2 ... A_N

Output

Print the number of the possible orders in which they were standing, modulo 10^9+7.

Examples

Input

5
2 4 4 0 2

Output

4

Input

7
6 4 0 2 4 0 2

Output

0

Input

8
7 5 1 1 7 3 5 3

Output

16

### Response

```cpp
#include <iostream>
int main(){
  int n,t,a=0,i,c[100001]={},inf=1e9+7;
  bool f=true;
  for(std::cin>>n,i=0;i<n;++i){std::cin>>t;++c[t];}
  for(i=0;i<(n+1)/2;++i){
    if(n%2){if(c[2*i]!=(i==0?1:2)){f=false;break;}}
    else if(c[2*i+1]!=2){f=false;break;}
  }
  if(f){
    a=1;
    for(i=0;i<n/2;++i)a=(a*2)%inf;
  }
  std::cout<<a<<"\n";
}
```


### Prompt

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

The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.

The New Year tree is an undirected tree with n vertices and root in the vertex 1.

You should process the queries of the two types:

  1. Change the colours of all vertices in the subtree of the vertex v to the colour c.
  2. Find the number of different colours in the subtree of the vertex v.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 4·105) — the number of vertices in the tree and the number of the queries.

The second line contains n integers ci (1 ≤ ci ≤ 60) — the colour of the i-th vertex.

Each of the next n - 1 lines contains two integers xj, yj (1 ≤ xj, yj ≤ n) — the vertices of the j-th edge. It is guaranteed that you are given correct undirected tree.

The last m lines contains the description of the queries. Each description starts with the integer tk (1 ≤ tk ≤ 2) — the type of the k-th query. For the queries of the first type then follows two integers vk, ck (1 ≤ vk ≤ n, 1 ≤ ck ≤ 60) — the number of the vertex whose subtree will be recoloured with the colour ck. For the queries of the second type then follows integer vk (1 ≤ vk ≤ n) — the number of the vertex for which subtree you should find the number of different colours.

Output

For each query of the second type print the integer a — the number of different colours in the subtree of the vertex given in the query.

Each of the numbers should be printed on a separate line in order of query appearing in the input.

Examples

Input

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

Output

2
3
4
5
1
2

Input

23 30
1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6
1 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10
4 11
6 12
6 13
7 14
7 15
7 16
8 17
8 18
10 19
10 20
10 21
11 22
11 23
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4
1 12 1
1 13 1
1 14 1
1 15 1
1 16 1
1 17 1
1 18 1
1 19 1
1 20 1
1 21 1
1 22 1
1 23 1
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
const int N = 400010;
vector<int> Adj[N + 1];
long long colorVal[4 * N + 1];
int dfs_timer = 1;
int begin1[N + 1];
int size1[N + 1];
int initColor[N + 1];
class SegTree {
 public:
  vector<long long> colors;
  vector<bool> lazyp;
  vector<long long> lazyColor;
  SegTree(int n) {
    colors.resize(4 * n + 1);
    lazyp.resize(4 * n + 1);
    lazyColor.resize(4 * n + 1);
    build(1, 1, n);
  }
  void build(int node, int b, int e) {
    if (b > e) return;
    if (b == e) {
      colors[node] = 0, lazyColor[node] = 0, lazyp[node] = false;
      return;
    }
    build(2 * node, b, (b + e) / 2);
    build(2 * node + 1, (b + e) / 2 + 1, e);
  }
  void push(int node, int b, int e) {
    if (lazyColor[node] == 0) return;
    colors[node] = 0;
    colors[node] |= (1LL << lazyColor[node]);
    if (b != e) {
      lazyColor[2 * node] = lazyColor[node];
      lazyColor[2 * node + 1] = lazyColor[node];
    }
    lazyColor[node] = 0;
  }
  void update(int node, int b, int e, int i, int j, int color) {
    push(node, b, e);
    if (b > e || i > e || j < b) return;
    if (i <= b and e <= j) {
      lazyColor[node] = color;
      push(node, b, e);
      return;
    }
    update(2 * node, b, (b + e) / 2, i, j, color);
    update(2 * node + 1, (b + e) / 2 + 1, e, i, j, color);
    colors[node] = (colors[2 * node] | colors[2 * node + 1]);
    return;
  }
  long long query(int node, int b, int e, int i, int j) {
    push(node, b, e);
    if (b > e || i > e || j < b) return 0LL;
    if (i <= b and e <= j) {
      return colors[node];
    }
    long long colLeft = query(2 * node, b, (b + e) / 2, i, j);
    long long colRight = query(2 * node + 1, (b + e) / 2 + 1, e, i, j);
    colors[node] = (colors[2 * node] | colors[2 * node + 1]);
    long long answers = (colLeft | colRight);
    return answers;
  }
};
void DFS(int u, int p) {
  begin1[u] = dfs_timer++;
  size1[u] = 1;
  for (auto v : Adj[u]) {
    if (v != p) {
      DFS(v, u);
      size1[u] += size1[v];
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int temp;
    cin >> temp;
    initColor[i] = temp;
  }
  SegTree st(n);
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int a1, b1;
    cin >> a1 >> b1;
    Adj[a1].push_back(b1), Adj[b1].push_back(a1);
  }
  DFS(1, 0);
  for (int i = (int)(1); i <= (int)(n); i++) {
    st.update(1, 1, n, begin1[i], begin1[i], initColor[i]);
  }
  while (m--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int vk, ck;
      cin >> vk >> ck;
      st.update(1, 1, n, begin1[vk], begin1[vk] + size1[vk] - 1, ck);
    } else {
      int vk;
      cin >> vk;
      long long answer1 =
          st.query(1, 1, n, begin1[vk], begin1[vk] + size1[vk] - 1);
      cout << __builtin_popcountll(answer1) << "\n";
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Problem

Aizu Magic School is a school where people who can use magic gather. Haruka, one of the students of that school, can use the magic of warp on the magic team.

From her house to the school, there is a straight road of length L. There are also magic circles on this road.
She uses this road every day to go to school, so she wants to get to school in the shortest possible time.

So as a programmer, you decided to teach her the minimum amount of time it would take to get to school.

Haruka can walk forward by a distance of 1 in 1 minute (* cannot go back). Also, by casting magic at the position Pi where the magic circle of the warp is written, you can move in Ti minutes to the place just Di from Pi. Even if there is a magic circle at the destination, it will be continuous. You can use warp magic.

The location of her house is 0 and the location of her school is L.

Constraints

The input meets the following conditions.

* All numbers given are integers
* 1 ≤ L ≤ 109
* 0 ≤ n ≤ min (103, L) (min represents the smaller of A and B)
* 0 ≤ Pi ≤ L -1
* 0 ≤ Di ≤ L --Pi
* 0 ≤ Ti ≤ 103
* Pi ≠ Pj

Input

L n
P1 D1 T1
P2 D2 T2
..
..
Pn Dn Tn

The first line is given the length of the road L, the number of magic circles n. Next, the state of n magic circles is given. Pi is the position where the i-th magic circle is, and Di is the i-th magic circle. Distance to warp from, Ti represents the time it takes to warp using the i-th magic circle.

Output

Output the minimum time to get to school in one line.

Examples

Input

10 3
2 2 1
4 2 1
8 1 1

Output

8

Input

10 2
2 3 1
3 5 1

Output

6

Input

1 0

Output

1

### Response

```cpp
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

bool check(string l, string r) {
	for (int i = 0; i < l.size(); ++i) {
		if (l[i] == r[i] || r[i] == '_') {

		}
		else {
			return false;
		}
	}
	return true;
}
struct warp {
	int x;
	int d;
	int t;
};
bool operator < (const warp&l, const warp&r) {
	return l.x<r.x;
}
int main() {
	int L,N;cin>>L>>N;
	vector<warp>warps;
	warps.push_back(warp{ 0,0,0 });
	for (int i = 0; i < N; ++i) {
		int a,b,c;cin>>a>>b>>c;
		warps.push_back(warp{ a,b,c });
	}
	warps.push_back(warp{ L,0,0 });
	sort(warps.begin(),warps.end());
	vector<int>costs(N+2,1e9);
	costs[0]=0;
	for (int k = 0; k < N + 1; ++k) {
		const int nx=warps[k].x;
		const int nd=warps[k].d;
		const int nt=warps[k].t;
		auto it = lower_bound(warps.begin(), warps.end(), warp{ nx + nd,0,0 });

		const int nextx=it->x;
		costs[it-warps.begin()]=min(costs[it - warps.begin()],costs[k]+nt+nextx-(nx+nd));

		costs[k+1]=min(costs[k+1],costs[k]+(warps[k+1].x-nx));
	}
	cout<<costs[N+1]<<endl;

	return 0;
}

```


### Prompt

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

There are infinitely many cards, numbered 1, 2, 3, ... Initially, Cards x_1, x_2, ..., x_N are face up, and the others are face down.

Snuke can perform the following operation repeatedly:

* Select a prime p greater than or equal to 3. Then, select p consecutive cards and flip all of them.

Snuke's objective is to have all the cards face down. Find the minimum number of operations required to achieve the objective.

Constraints

* 1 ≤ N ≤ 100
* 1 ≤ x_1 < x_2 < ... < x_N ≤ 10^7

Input

Input is given from Standard Input in the following format:

N
x_1 x_2 ... x_N

Output

Print the minimum number of operations required to achieve the objective.

Examples

Input

2
4 5

Output

2

Input

9
1 2 3 4 5 6 7 8 9

Output

3

Input

2
1 10000000

Output

4

### Response

```cpp
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int n,A[101],B[101];
bool yes[10000010];
int pr[670010],P;
int fir[210],dep[210],head[210],dis[3000010],nxt[3000010],w[3000010],id=1,S,T;
void link(int a,int b,int c){
	nxt[++id]=fir[a],fir[a]=id,dis[id]=b,w[id]=c;
	nxt[++id]=fir[b],fir[b]=id,dis[id]=a,w[id]=0;
}
bool BFS(){
	static int que[210],hd,tl;
	hd=tl=0;que[tl++]=S;memset(dep,0,sizeof dep);
	dep[S]=1;
	while(hd^tl){
		int x=que[hd++];
		for(int i=fir[x];i;i=nxt[i])
			if(w[i]&&!dep[dis[i]])dep[dis[i]]=dep[x]+1,que[tl++]=dis[i];
	}
	return dep[T];
}
int Dinic(int x,int maxflow){
	if(x==T)return maxflow;
	int ret=0;
	for(int&i=head[x];i;i=nxt[i])
		if(dep[dis[i]]==dep[x]+1&&w[i]){
			int d=Dinic(dis[i],std::min(w[i],maxflow-ret));
			w[i]-=d,w[i^1]+=d;ret+=d;if(ret==maxflow)break;
		}
	return ret;
}
int main(){
	n=gi();
	for(int i=1;i<=n;++i)A[i]=gi();
	std::sort(A+1,A+n+1),n=std::unique(A+1,A+n+1)-A-1;
	A[0]=A[n+1]=-1;
	int m=0;
	for(int i=1;i<=n;++i){
		if(A[i]!=A[i-1]+1)B[++m]=A[i]-1;
		if(A[i]!=A[i+1]-1)B[++m]=A[i];
	}
	S=m+1,T=m+2;
	int odd=0,even=0;
	for(int i=1;i<=m;++i)if(B[i]&1)++odd,link(S,i,1);else++even,link(i,T,1);
	for(int i=2;i<=A[n];++i){
		if(!yes[i])pr[++P]=i;
		for(int j=1;j<=P&&i*pr[j]<=A[n];++j){
			yes[i*pr[j]]=1;
			if(i%pr[j]==0)break;
		}
	}
	yes[0]=yes[1]=yes[2]=1;
	for(int i=1;i<=m;++i)if(B[i]&1)
		for(int j=1;j<=m;++j)
			if(!yes[abs(B[j]-B[i])])
				link(i,j,1);
	int ans=0;while(BFS())memcpy(head,fir,sizeof fir),ans+=Dinic(S,1e9);
	printf("%d\n",ans+2*((odd-ans>>1)+(even-ans>>1))+3*(odd-ans&1));
	return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.

Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i is strictly greater than the value at position j.

Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the n arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most <image> (at most <image> pairs). Help Iahub, find any suitable array.

Input

The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each element x of the array i, 1 ≤ x ≤ 106 holds.

Output

On the first line of the output print an integer p, the size of the array (p can be at most <image>). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices.

If there are multiple correct answers, you can print any.

Examples

Input

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

Output

3
2 4
2 3
4 5

Input

3 2 1
1 2
2 3
3 4

Output

1
2 1

Note

Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, t;
  vector<int> v;
  vector<vector<int>> vv;
  vector<pair<int, int>> p;
  cin >> n >> m >> k;
  v.assign(m, 0);
  p.assign(0, make_pair(0, 0));
  vv.assign(n, v);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> vv[i][j];
    }
  }
  if (k == 0) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        for (int l = j + 1; l < m; l++) {
          if (vv[i][j] > vv[i][l]) {
            t = vv[i][l];
            vv[i][l] = vv[i][j];
            vv[i][j] = t;
            p.push_back(make_pair(j + 1, l + 1));
            for (int r = i + 1; r < n; r++) {
              if (vv[r][j] > vv[r][l]) {
                t = vv[r][l];
                vv[r][l] = vv[r][j];
                vv[r][j] = t;
              }
            }
          }
        }
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        for (int l = j + 1; l < m; l++) {
          if (vv[i][j] < vv[i][l]) {
            t = vv[i][l];
            vv[i][l] = vv[i][j];
            vv[i][j] = t;
            p.push_back(make_pair(l + 1, j + 1));
            for (int r = i + 1; r < n; r++) {
              if (vv[r][j] < vv[r][l]) {
                t = vv[r][l];
                vv[r][l] = vv[r][j];
                vv[r][j] = t;
              }
            }
          }
        }
      }
    }
  }
  cout << p.size() << endl;
  for (int i = 0; i < p.size(); i++) {
    cout << p[i].first << ' ' << p[i].second << endl;
  }
  return 0;
}

```


### Prompt

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

An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.

Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:

  1. initially the atom is in the state i,
  2. we spend Ek - Ei energy to put the atom in the state k,
  3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
  4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
  5. the process repeats from step 1.

Let's define the energy conversion efficiency as <image>, i. e. the ration between the useful energy of the photon and spent energy.

Due to some limitations, Arkady can only choose such three states that Ek - Ei ≤ U.

Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.

Input

The first line contains two integers n and U (3 ≤ n ≤ 105, 1 ≤ U ≤ 109) — the number of states and the maximum possible difference between Ek and Ei.

The second line contains a sequence of integers E1, E2, ..., En (1 ≤ E1 < E2... < En ≤ 109). It is guaranteed that all Ei are given in increasing order.

Output

If it is not possible to choose three states that satisfy all constraints, print -1.

Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.

Examples

Input

4 4
1 3 5 7

Output

0.5

Input

10 8
10 13 15 16 17 19 20 22 24 25

Output

0.875

Input

3 1
2 5 10

Output

-1

Note

In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <image>.

In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << setprecision(17);
  int n;
  long long a[200000];
  long long u;
  cin >> n >> u;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = 10000000000000;
  long double ans = -1;
  for (int i = 0; i < n - 2; i++) {
    int i0 = i;
    int i1;
    int i2 = n - 1;
    int mid = (i + n - 1) / 2;
    while (i2 - i0 > 1) {
      if (a[mid] > a[i] + u) {
        i2 = mid;
        mid = (i0 + mid) / 2;
      } else {
        i0 = mid;
        mid = (mid + i2) / 2;
      }
    }
    if (a[i0] <= a[i] + u && a[i0 + 1] > a[i] + u) {
      i1 = i0;
    }
    if (a[i2] <= a[i] + u && a[i2 + 1] > a[i] + u) {
      i1 = i2;
    }
    if (a[i0 - 1] <= a[i] + u && a[i0] > a[i] + u) {
      i1 = i0 - 1;
    }
    if (i1 > i + 1) {
      if (ans < (1.0 * (a[i1] - a[i + 1])) / (1.0 * (a[i1] - a[i]))) {
        ans = (1.0 * (a[i1] - a[i + 1])) / (1.0 * (a[i1] - a[i]));
      }
    }
  }
  if (ans < -0.5) {
    cout << "-1";
  } else {
    cout << ans;
  }
  return 0;
}

```


### Prompt

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

There are two sequences of colorful stones. The color of each stone is one of red, green, or blue. You are given two strings s and t. The i-th (1-based) character of s represents the color of the i-th stone of the first sequence. Similarly, the i-th (1-based) character of t represents the color of the i-th stone of the second sequence. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.

Initially Squirrel Liss is standing on the first stone of the first sequence and Cat Vasya is standing on the first stone of the second sequence. You can perform the following instructions zero or more times.

Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, the animals standing on stones whose colors are c will move one stone forward. For example, if you perform an instruction «RED», the animals standing on red stones will move one stone forward. You are not allowed to perform instructions that lead some animals out of the sequences. In other words, if some animals are standing on the last stones, you can't perform the instructions of the colors of those stones.

A pair of positions (position of Liss, position of Vasya) is called a state. A state is called reachable if the state is reachable by performing instructions zero or more times from the initial state (1, 1). Calculate the number of distinct reachable states.

Input

The input contains two lines. The first line contains the string s (1 ≤ |s| ≤ 106). The second line contains the string t (1 ≤ |t| ≤ 106). The characters of each string will be one of "R", "G", or "B".

Output

Print the number of distinct reachable states in a single line.

Please, do not write 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

RBR
RGG

Output

5

Input

RGBB
BRRBRR

Output

19

Input

RRRRRRRRRR
RRRRRRRR

Output

8

Note

In the first example, there are five reachable states: (1, 1), (2, 2), (2, 3), (3, 2), and (3, 3). For example, the state (3, 3) is reachable because if you perform instructions "RED", "GREEN", and "BLUE" in this order from the initial state, the state will be (3, 3). The following picture shows how the instructions work in this case.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long sum[3][3][2100010];
long long a[2000100], b[2001000];
char s[2000100];
long long cti(char x) {
  if (x == 'R') return 0;
  if (x == 'G') return 1;
  if (x == 'B') return 2;
}
signed main() {
  scanf("%s", s + 1);
  long long n = strlen(s + 1);
  for (long long i = 1; i <= n; ++i) a[i] = cti(s[i]);
  scanf("%s", s + 1);
  long long m = strlen(s + 1);
  for (long long i = 1; i <= m; ++i) b[i] = cti(s[i]);
  for (long long i = 0; i <= 2; ++i)
    for (long long j = 0; j <= 2; ++j) {
      for (long long k = 1; k <= m; ++k) {
        if (b[k - 1] == i && b[k] == j) sum[i][j][k] = 1;
        sum[i][j][k] += sum[i][j][k - 1];
      }
    }
  long long l = 1, r = 1;
  while (r < m && b[r] != a[1]) r++;
  long long ans = r - l + 1;
  for (long long i = 2; i <= n; ++i) {
    if (l <= m && a[i - 1] == b[l]) l++;
    if (l > m) break;
    if (r < m) {
      r++;
      while (r < m && b[r] != a[i]) r++;
    }
    ans += r - l + 1;
    if (a[i] != a[i - 1])
      ans -= sum[a[i]][a[i - 1]][r] - sum[a[i]][a[i - 1]][l - 1];
  }
  printf("%lld", ans);
}

```


### Prompt

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

Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.

Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Arya can make with them? She is jealous and she doesn't want Arya to make a lot of values. So she wants to know all the values x, such that Arya will be able to make x using some subset of coins with the sum k.

Formally, Pari wants to know the values x such that there exists a subset of coins with the sum k such that some subset of this subset has the sum x, i.e. there is exists some way to pay for the chocolate, such that Arya will be able to make the sum x using these coins.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of coins and the price of the chocolate, respectively.

Next line will contain n integers c1, c2, ..., cn (1 ≤ ci ≤ 500) — the values of Pari's coins.

It's guaranteed that one can make value k using these coins.

Output

First line of the output must contain a single integer q— the number of suitable values x. Then print q integers in ascending order — the values that Arya can make for some subset of coins of Pari that pays for the chocolate.

Examples

Input

6 18
5 6 1 10 12 2

Output

16
0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18

Input

3 50
25 25 50

Output

3
0 25 50

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int MO = 1e9 + 7;
const int MAXN = 500 + 5;
template <class T>
inline bool ChKKmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
template <class T>
inline bool ChKKmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <class T>
inline T read(T &x) {
  static int f;
  static char c;
  for (f = 1; !isdigit(c = getchar());)
    if (c == '-') f = -1;
  for (x = 0; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return x *= f;
}
template <class T>
inline void write(T x, char P = '\n') {
  static char s[20];
  static int top = 0;
  if (x < 0) x = -x, putchar('-');
  do {
    s[++top] = x % 10;
  } while (x /= 10);
  do {
    putchar(s[top] + 48);
  } while (--top);
  putchar(P);
}
inline void open() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int n, KK;
bool f[MAXN][MAXN], dp[MAXN];
int main() {
  f[0][0] = 1;
  read(n), read(KK);
  for (int i = 1, x; i <= n; ++i) {
    read(x);
    for (int j = KK; j >= 0; j--)
      for (int l = KK; l >= 0; l--)
        if ((j >= x && f[j - x][l]) || (l >= x && f[j][l - x])) f[j][l] = 1;
  }
  for (int i = 0; i <= KK; ++i)
    if (f[i][KK - i]) dp[i] = dp[KK - i] = 1;
  int tot = 0;
  for (int i = 0; i <= KK; ++i) tot += dp[i];
  cout << tot << endl;
  for (int i = 0; i <= KK; ++i)
    if (dp[i]) write(i, ' ');
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given an array consisting of n integers a_1, a_2, ..., a_n, and a positive integer m. It is guaranteed that m is a divisor of n.

In a single move, you can choose any position i between 1 and n and increase a_i by 1.

Let's calculate c_r (0 ≤ r ≤ m-1) — the number of elements having remainder r when divided by m. In other words, for each remainder, let's find the number of corresponding elements in a with that remainder.

Your task is to change the array in such a way that c_0 = c_1 = ... = c_{m-1} = n/m.

Find the minimum number of moves to satisfy the above requirement.

Input

The first line of input contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ n). It is guaranteed that m is a divisor of n.

The second line of input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9), the elements of the array.

Output

In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from 0 to m - 1, the number of elements of the array having this remainder equals n/m.

In the second line, print any array satisfying the condition and can be obtained from the given array with the minimum number of moves. The values of the elements of the resulting array must not exceed 10^{18}.

Examples

Input

6 3
3 2 0 6 10 12

Output

3
3 2 0 7 10 14

Input

4 2
0 1 2 3

Output

0
0 1 2 3

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const double pi = 3.141592653589793;
template <class T>
using V = vector<T>;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline void out(T a) {
  cout << a << '\n';
}
void YN(bool ok) {
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
const long long INF = 1e18;
const int mx = 200005;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  V<long long> cnt(m, 0);
  V<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i] % m]++;
  }
  priority_queue<long long, V<long long>, greater<long long>> que;
  V<V<int>> vec(m);
  long long ans = 0;
  for (int i = 0; i < 2 * m; i++) {
    if (cnt[i % m] < n / m) {
      while (que.size() && cnt[i % m] < n / m) {
        long long from = que.top();
        que.pop();
        long long cost = i % m - from;
        if (cost < 0) cost = cost + m;
        ans = ans + cost;
        vec[from].push_back(i % m);
        cnt[i % m]++;
      }
    } else if (cnt[i % m] > n / m) {
      while (cnt[i % m] > n / m) {
        que.push(i % m);
        cnt[i % m]--;
      }
    }
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    if (vec[a[i] % m].size()) {
      long long cost = vec[a[i] % m].back() - a[i] % m;
      if (cost < 0) cost += m;
      vec[a[i] % m].pop_back();
      a[i] += cost;
    }
    cout << a[i] << ' ';
  }
  cout << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.

One day, the cats went out to play. Cat i went on a trip to hill hi, finished its trip at time ti, and then waited at hill hi for a feeder. The feeders must take all the cats. Each feeder goes straightly from hill 1 to n without waiting at a hill and takes all the waiting cats at each hill away. Feeders walk at a speed of 1 meter per unit time and are strong enough to take as many cats as they want.

For example, suppose we have two hills (d2 = 1) and one cat that finished its trip at time 3 at hill 2 (h1 = 2). Then if the feeder leaves hill 1 at time 2 or at time 3, he can take this cat, but if he leaves hill 1 at time 1 he can't take it. If the feeder leaves hill 1 at time 2, the cat waits him for 0 time units, if the feeder leaves hill 1 at time 3, the cat waits him for 1 time units.

Your task is to schedule the time leaving from hill 1 for each feeder so that the sum of the waiting time of all cats is minimized.

Input

The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).

The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).

Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109).

Output

Output an integer, the minimum sum of waiting time of all cats.

Please, do not write 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 6 2
1 3 5
1 0
2 1
4 9
1 10
2 10
3 12

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
long long l, r, n, m, p, x, y, a[N], d[N], q[N], g[N], s[N], f[105][N];
signed main() {
  scanf("%lld%lld%lld", &n, &m, &p);
  for (long long i = 2; i <= n; i++) {
    scanf("%lld", &x);
    d[i] = d[i - 1] + x;
  }
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld", &x, &y);
    a[i] = y - d[x];
  }
  sort(a + 1, a + m + 1);
  for (long long i = 1; i <= m; i++) s[i] = s[i - 1] + a[i];
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (long long i = 1; i <= p; i++) {
    for (long long j = 1; j <= m; j++) g[j] = f[i - 1][j] + s[j];
    l = r = 1;
    q[1] = 0;
    for (long long j = 1; j <= m; j++) {
      while (l < r && (g[q[l + 1]] - g[q[l]]) <= a[j] * (q[l + 1] - q[l])) l++;
      f[i][j] = min(f[i - 1][j], g[q[l]] + a[j] * j - s[j] - a[j] * q[l]);
      if (g[j] >= 0x3f3f3f3f3f3f3f3fll) continue;
      while (l < r && (g[q[r]] - g[q[r - 1]]) * (j - q[r]) >=
                          (g[j] - g[q[r]]) * (q[r] - q[r - 1]))
        r--;
      q[++r] = j;
    }
  }
  cout << f[p][m];
}

```


### Prompt

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

Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base p and regard the expression as written in the base p positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78 + 87 in the base 16 positional notation is equal to FF16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length.

The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78 + 87 = ? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones.

Input

The first letter contains two space-separated numbers a and b (1 ≤ a, b ≤ 1000) which represent the given summands.

Output

Print a single number — the length of the longest answer.

Examples

Input

78 87

Output

3

Input

1 1

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b;
  c = a + b;
  int Max = 0, A = 0, B = 0, sum, system;
  for (int i = 0; i < c.length(); ++i) {
    if (static_cast<int>(c[i]) - static_cast<int>('0') > Max)
      Max = static_cast<int>(c[i]) - static_cast<int>('0');
  }
  system = Max + 1;
  vector<int> x;
  vector<int> y;
  int p = 0;
  for (int i = a.length() - 1; i >= 0; --i) {
    x.push_back((static_cast<int>(a[i]) - static_cast<int>('0')) *
                pow(system, p));
    A = A + x[p];
    ++p;
  }
  p = 0;
  for (int i = b.length() - 1; i >= 0; --i) {
    y.push_back((static_cast<int>(b[i]) - static_cast<int>('0')) *
                pow(system, p));
    B = B + y[p];
    ++p;
  }
  sum = A + B;
  vector<int> v;
  for (;;) {
    v.push_back(sum % system);
    if (sum % system == sum) break;
    sum = sum / system;
  }
  cout << v.size();
}

```