### Prompt

Generate a cpp solution to the following problem:

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)

* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.

You are given the sequence a_i. Find the number of times we will perform the above operation.

Constraints

* 2 ≤ N ≤ 50
* 0 ≤ a_i ≤ 10^{16} + 1000

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the number of times the operation will be performed.

Examples

Input

4
3 3 3 3

Output

0

Input

3
1 0 3

Output

1

Input

2
2 2

Output

2

Input

7
27 0 0 0 0 0 0

Output

3

Input

10
1000 193 256 777 0 1 1192 1234567891011 48 425

Output

1234567894848

### Response

```cpp
#include<cstdio>
using namespace std;
typedef long long ll;
ll a[60],div,ans;
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%lld",a+i);
	for(int flag=0,p;!flag;){
		if(a[p=1]<n)flag=1;
		for(int i=2;i<=n;++i)
			if(a[i]>a[p]&&a[i]>=n)flag=0,p=i;
		if(!flag){
			ans+=(div=a[p]/n);a[p]%=n;
			for(int i=1;i<=n;++i)
				if(i!=p)a[i]+=div;
		}
	}
	printf("%lld\n",ans);
    return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?

Input

The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.

Output

Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.

Examples

Input

9
1 5 -6 7 9 -16 0 -2 2

Output

3

Input

3
1 1 1

Output

0

Input

2
0 0

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> dp(n + 1);
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1] + a[i];
  }
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (2 * dp[i] == dp[n]) {
      ans++;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}

```


### Prompt

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

Let's consider one interesting word game. In this game you should transform one word into another through special operations.

Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation is transforming word w = xy into word u = yx. For example, a split operation can transform word "wordcut" into word "cutword".

You are given two words start and end. Count in how many ways we can transform word start into word end, if we apply exactly k split operations consecutively to word start.

Two ways are considered different if the sequences of applied operations differ. Two operation sequences are different if exists such number i (1 ≤ i ≤ k), that in the i-th operation of the first sequence the word splits into parts x and y, in the i-th operation of the second sequence the word splits into parts a and b, and additionally x ≠ a holds.

Input

The first line contains a non-empty word start, the second line contains a non-empty word end. The words consist of lowercase Latin letters. The number of letters in word start equals the number of letters in word end and is at least 2 and doesn't exceed 1000 letters.

The third line contains integer k (0 ≤ k ≤ 105) — the required number of operations.

Output

Print a single number — the answer to the problem. As this number can be rather large, print it modulo 1000000007 (109 + 7).

Examples

Input

ab
ab
2

Output

1

Input

ababab
ababab
1

Output

2

Input

ab
ba
2

Output

0

Note

The sought way in the first sample is:

ab →  a|b →  ba →  b|a →  ab

In the second sample the two sought ways are:

  * ababab →  abab|ab →  ababab
  * ababab →  ab|abab →  ababab

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
char s[1005], t[1005];
int n, k, gs;
long long dp[100005][2];
long long f(int nop, int state) {
  printf("f(%d, %d)\n", nop, state);
  if (nop == k) return (long long)state;
  long long &ret = dp[nop][state];
  if (ret != -1LL) return ret;
  ret = 0LL;
  if (state) {
    if (gs - 1 >= 0)
      ret = (ret + (f(nop + 1, 1) * (long long)(gs - 1)) % MOD) % MOD;
    if (n - 1 - (gs - 1) >= 0)
      ret = (ret + (f(nop + 1, 0) * (long long)(n - 1 - (gs - 1))) % MOD) % MOD;
  } else {
    if (gs >= 0) ret = (ret + (f(nop + 1, 1) * (long long)(gs)) % MOD) % MOD;
    if (n - 1 - gs >= 0)
      ret = (ret + (f(nop + 1, 0) * (long long)(n - 1 - gs)) % MOD) % MOD;
  }
  return ret;
}
int main() {
  scanf("%s%s %d", &s, &t, &k);
  n = strlen(s);
  gs = 0;
  bool sgs = 0;
  for (int i = 0; i < n; ++i) {
    bool match = 1;
    for (int j = 0; j < n; ++j)
      if (s[(i + j) % n] != t[j]) {
        match = 0;
        break;
      }
    if (match) {
      gs++;
      if (i == 0) sgs = 1;
    }
  }
  dp[k][0] = 0LL;
  dp[k][1] = 1LL;
  for (int i = k - 1; i >= 0; --i)
    for (int j = 0; j <= 1; ++j) {
      long long &ret = dp[i][j] = 0;
      if (j) {
        if (gs - 1 >= 0)
          ret = (ret + (dp[i + 1][1] * (long long)(gs - 1)) % MOD) % MOD;
        if (n - 1 - (gs - 1) >= 0)
          ret = (ret + (dp[i + 1][0] * (long long)(n - 1 - (gs - 1))) % MOD) %
                MOD;
      } else {
        if (gs >= 0) ret = (ret + (dp[i + 1][1] * (long long)(gs)) % MOD) % MOD;
        if (n - 1 - gs >= 0)
          ret = (ret + (dp[i + 1][0] * (long long)(n - 1 - gs)) % MOD) % MOD;
      }
    }
  cout << dp[0][sgs] << endl;
  return 0;
}

```


### Prompt

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

George loves graphs. Most of all, he loves interesting graphs. We will assume that a directed graph is interesting, if it meets the following criteria:

  * The graph doesn't contain any multiple arcs;
  * There is vertex v (we'll call her the center), such that for any vertex of graph u, the graph contains arcs (u, v) and (v, u). Please note that the graph also contains loop (v, v).
  * The outdegree of all vertexes except for the center equals two and the indegree of all vertexes except for the center equals two. The outdegree of vertex u is the number of arcs that go out of u, the indegree of vertex u is the number of arcs that go in u. Please note that the graph can contain loops.

However, not everything's that simple. George got a directed graph of n vertices and m arcs as a present. The graph didn't have any multiple arcs. As George loves interesting graphs, he wants to slightly alter the presented graph and transform it into an interesting one. In one alteration he can either remove an arbitrary existing arc from the graph or add an arbitrary arc to the graph.

George wonders: what is the minimum number of changes that he needs to obtain an interesting graph from the graph he's got as a present? Help George and find the answer to the question.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 500, 1 ≤ m ≤ 1000) — the number of vertices and arcs in the presented graph.

Each of the next m lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n) — the descriptions of the graph's arcs. Pair (ai, bi) means that the graph contains an arc from vertex number ai to vertex number bi. It is guaranteed that the presented graph doesn't contain multiple arcs.

Assume that the grah vertices are numbered 1 through n.

Output

Print a single integer — the answer to George's question.

Examples

Input

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

Output

0

Input

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

Output

1

Input

3 1
2 2

Output

6

Note

For more information about directed graphs, please visit: http://en.wikipedia.org/wiki/Directed_graph

In the first sample the graph already is interesting, its center is vertex 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
const int N = 10005, M = 200005;
vector<array<int, 2>> v[N];
vector<int> edgeId(M), flow(M);
int n;
class Dinic {
 public:
  int src, des, n;
  vector<int> lvl, nxt;
  vector<array<int, 2>> path;
  Dinic() {
    lvl = vector<int>(N);
    nxt = vector<int>(N);
  }
  void init(int n1, int Src, int Des, int m1) {
    n = n1;
    src = Src;
    des = Des;
    for (int i = 0; i <= m1; i++) {
      edgeId[i] = 0;
      flow[i] = 0;
    }
    for (int i = 0; i <= n; i++) {
      v[i].clear();
    }
  }
  bool bfs() {
    queue<int> q;
    q.push(src);
    fill(lvl.begin(), lvl.end(), -1);
    lvl[src] = 0;
    while (!q.empty()) {
      int node = q.front();
      q.pop();
      for (auto i : v[node]) {
        if (lvl[i[0]] != -1 || edgeId[i[1]] == 0) continue;
        q.push(i[0]);
        lvl[i[0]] = lvl[node] + 1;
      }
    }
    return lvl[des] != -1;
  }
  int dfs(int node, int push) {
    if (push == 0 || node == des) {
      if (node == des) path.push_back({des, -1});
      return push;
    }
    for (; nxt[node] < v[node].size(); nxt[node]++, path.clear()) {
      int id = v[node][nxt[node]][1];
      int y = v[node][nxt[node]][0];
      if (edgeId[id] == 0 || lvl[node] + 1 != lvl[y]) continue;
      int f = dfs(y, min(push, edgeId[id]));
      if (f == 0) continue;
      flow[id] += f;
      path.push_back({node, id});
      return f;
    }
    return 0;
  }
  int maxflow() {
    int mx = 0;
    while (bfs()) {
      fill(nxt.begin(), nxt.end(), 0);
      for (int f; f = dfs(src, INT_MAX);) {
        if (f == 0) {
          path.clear();
          break;
        }
        reverse(path.begin(), path.end());
        for (int j = 0; j < path.size() - 1; j++) {
          edgeId[path[j][1]] -= f;
          edgeId[path[j][1] ^ 1] += f;
        }
        mx += f;
        path.clear();
      }
    }
    return mx;
  }
};
int m1;
int N1 = 505;
vector<int> g[505];
Dinic d;
int solve(int c) {
  int ans = 0;
  int tot = m1;
  for (int i = 1; i <= n; i++) {
    if (i == c) {
      ans += (n - g[c].size());
      tot -= g[c].size();
    } else {
      int f = 0;
      for (auto j : g[i]) {
        if (j == c) {
          f = 1;
          break;
        }
      }
      if (f) {
        tot--;
      } else {
        ans++;
      }
    }
  }
  int src = 0;
  int des = 2 * n + 1;
  int id = 1;
  d.init(2 * n + 100, src, des, m1 + 2 * n + 1000);
  for (int i = 1; i <= n; i++) {
    if (i == c) continue;
    for (auto j : g[i]) {
      if (j == c) continue;
      v[i].push_back({j + n, ++id});
      edgeId[id] = 1;
      v[j + n].push_back({i, ++id});
    }
  }
  for (int i = 1; i <= n; i++) {
    v[src].push_back({i, ++id});
    edgeId[id] = 1;
    v[i].push_back({src, ++id});
  }
  for (int i = 1; i <= n; i++) {
    v[n + i].push_back({des, ++id});
    edgeId[id] = 1;
    v[des].push_back({n + i, ++id});
  }
  int x = d.maxflow();
  int y = tot - x + (n - 1 - x);
  ans += y;
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m1;
  int ans = 1e18;
  int x, y;
  for (int i = 1; i <= m1; i++) {
    cin >> x >> y;
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    sort(g[i].begin(), g[i].end());
  }
  for (int i = 1; i <= n; i++) {
    ans = min(ans, solve(i));
  }
  cout << ans;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given a string s=s_1s_2... s_n of length n, which only contains digits 1, 2, ..., 9.

A substring s[l ... r] of s is a string s_l s_{l + 1} s_{l + 2} … s_r. A substring s[l ... r] of s is called even if the number represented by it is even.

Find the number of even substrings of s. Note, that even if some substrings are equal as strings, but have different l and r, they are counted as different substrings.

Input

The first line contains an integer n (1 ≤ n ≤ 65000) — the length of the string s.

The second line contains a string s of length n. The string s consists only of digits 1, 2, ..., 9.

Output

Print the number of even substrings of s.

Examples

Input

4
1234

Output

6

Input

4
2244

Output

10

Note

In the first example, the [l, r] pairs corresponding to even substrings are:

  * s[1 ... 2]
  * s[2 ... 2]
  * s[1 ... 4]
  * s[2 ... 4]
  * s[3 ... 4]
  * s[4 ... 4]

In the second example, all 10 substrings of s are even substrings. Note, that while substrings s[1 ... 1] and s[2 ... 2] both define the substring "2", they are still counted as different substrings.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  string str;
  cin >> n >> str;
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if ((str[i] - '0') % 2 == 0) {
      res += (i + 1);
    }
  }
  cout << res << "\n";
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.

Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.

Input

The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.

Output

Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.

Examples

Input

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

Output

11

Input

3
1 2 3
2
3 1 2
3 1 3

Output

-1

Note

In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  long n;
  scanf("%ld", &n);
  for (long p = 0; p < n; p++) {
    long x;
    scanf("%ld", &x);
  }
  long m;
  scanf("%ld", &m);
  std::map<long, long> cost;
  while (m--) {
    long x, y, c;
    scanf("%ld %ld %ld", &x, &y, &c);
    if (cost.count(y) > 0) {
      cost[y] = (cost[y] < c) ? cost[y] : c;
    } else {
      cost[y] = c;
    }
  }
  if (cost.size() < n - 1) {
    puts("-1");
    return 0;
  }
  long long total(0);
  for (std::map<long, long>::iterator it = cost.begin(); it != cost.end();
       it++) {
    total += it->second;
  }
  printf("%lld\n", total);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.

<image>

However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.

<image>

You have met a cat. Can you figure out whether it's normal or grumpy?

Interaction

This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9.

In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase.

Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out.

Note

Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  for (int i = 0; i < 7; i++) {
    cout << i << endl;
    string s;
    getline(cin, s);
    if (s == "no" || s.substr(0, 3) == "don") continue;
    if (s.substr(0, 3) == "gre" || s == "cool" || s.substr(0, 3) == "not")
      cout << "normal" << endl;
    else
      cout << "grumpy" << endl;
    return 0;
  }
  cout << "normal" << endl;
}

```


### Prompt

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

Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:

We will define the distance between two strings s and t of the same length consisting of digits zero and one as the number of positions i, such that si isn't equal to ti.

As besides everything else Susie loves symmetry, she wants to find for two strings s and t of length n such string p of length n, that the distance from p to s was equal to the distance from p to t.

It's time for Susie to go to bed, help her find such string p or state that it is impossible.

Input

The first line contains string s of length n.

The second line contains string t of length n.

The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.

Output

Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).

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

Examples

Input

0001
1011

Output

0011

Input

000
111

Output

impossible

Note

In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int ans = 0;
  string a, b;
  char c[100000 + 10];
  cin >> a >> b;
  if (a.size() != b.size()) {
    cout << "impossible" << endl;
    return 0;
  }
  for (int i = 0; i < a.size(); i++)
    if (a[i] != b[i]) ans++;
  if (ans & 1) {
    cout << "impossible" << endl;
    return 0;
  }
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i]) {
      if (ans & 1)
        c[i] = a[i];
      else
        c[i] = b[i];
      ans--;
    } else
      c[i] = a[i];
  }
  for (int i = 0; i < a.size(); i++) cout << c[i];
  cout << endl;
  return 0;
}

```


### Prompt

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

Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array.

Now he wonders what is the number of segments in his array with the sum less than t. Help Petya to calculate this number.

More formally, you are required to calculate the number of pairs l, r (l ≤ r) such that a_l + a_{l+1} + ... + a_{r-1} + a_r < t.

Input

The first line contains two integers n and t (1 ≤ n ≤ 200 000, |t| ≤ 2⋅10^{14}).

The second line contains a sequence of integers a_1, a_2, ..., a_n (|a_{i}| ≤ 10^{9}) — the description of Petya's array. Note that there might be negative, zero and positive elements.

Output

Print the number of segments in Petya's array with the sum of elements less than t.

Examples

Input

5 4
5 -1 3 4 -1

Output

5

Input

3 0
-1 2 -3

Output

4

Input

4 -1
-2 1 -2 3

Output

3

Note

In the first example the following segments have sum less than 4:

  * [2, 2], sum of elements is -1
  * [2, 3], sum of elements is 2
  * [3, 3], sum of elements is 3
  * [4, 5], sum of elements is 3
  * [5, 5], sum of elements is -1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
int ch[MAX * 2][2], Size[MAX * 2], f[MAX * 2], cnt[MAX * 2];
long long key[MAX * 2];
int sz, root;
inline int get(int x) { return ch[f[x]][1] == x; }
inline void clean(int x) {
  ch[x][0] = ch[x][1] = f[x] = cnt[x] = key[x] = Size[x] = 0;
}
inline void update(int x) {
  if (x) {
    Size[x] = cnt[x];
    if (ch[x][0]) Size[x] += Size[ch[x][0]];
    if (ch[x][1]) Size[x] += Size[ch[x][1]];
  }
}
inline void Rotate(int x) {
  int y = f[x], z = f[y];
  int kind = get(x);
  ch[y][kind] = ch[x][!kind];
  f[ch[y][kind]] = y;
  f[y] = x;
  ch[x][!kind] = y;
  f[x] = z;
  if (z) ch[z][ch[z][1] == y] = x;
  update(y);
  update(x);
}
void splay(int x) {
  for (int fa; (fa = f[x]); Rotate(x)) {
    if (f[fa]) Rotate((get(x) == get(fa)) ? fa : x);
  }
  root = x;
}
bool Insert(long long x) {
  if (root == 0) {
    sz++;
    Size[sz] = cnt[sz] = 1;
    ch[sz][0] = ch[sz][1] = f[sz] = 0;
    root = sz;
    key[sz] = x;
    return true;
  }
  int now = root, fa = 0;
  while (true) {
    if (key[now] == x) {
      cnt[now]++;
      update(fa);
      splay(now);
      return false;
    }
    fa = now;
    now = ch[now][x > key[now]];
    if (now == 0) {
      sz++;
      Size[sz] = cnt[sz] = 1;
      ch[sz][0] = ch[sz][1] = 0;
      key[sz] = x;
      f[sz] = fa;
      ch[fa][x > key[fa]] = sz;
      splay(sz);
      return true;
    }
  }
}
int QueryNumRank(long long x) {
  int ans = 0, now = root;
  while (true) {
    if (x < key[now])
      now = ch[now][0];
    else {
      ans += ch[now][0] ? Size[ch[now][0]] : 0;
      if (key[now] == x) {
        splay(now);
        return ans + 1;
      }
      ans += cnt[now];
      now = ch[now][1];
    }
  }
}
int QueryPre() {
  int k = ch[root][0];
  while (ch[k][1]) k = ch[k][1];
  return k;
}
void del(long long x) {
  QueryNumRank(x);
  if (cnt[root] > 1)
    cnt[root]--;
  else if (!ch[root][0] && !ch[root][1]) {
    clean(root);
    root = 0;
  } else if (!ch[root][0]) {
    int tmp = root;
    root = ch[root][1];
    f[root] = 0;
    clean(tmp);
  } else if (!ch[root][1]) {
    int tmp = root;
    root = ch[root][0];
    f[root] = 0;
    clean(tmp);
  } else {
    int t = QueryPre();
    int tmp = root;
    splay(t);
    ch[root][1] = ch[tmp][1];
    f[ch[tmp][1]] = root;
    clean(tmp);
    update(root);
  }
}
long long sum[MAX];
int main(void) {
  int N;
  long long a, t;
  scanf("%d%lld", &N, &t);
  for (int i = 1; i <= N; ++i) {
    scanf("%lld", &a);
    sum[i] = sum[i - 1] + a;
  }
  long long res = 0;
  Insert(t);
  for (int i = 1; i <= N; ++i) {
    Insert(sum[i]);
    res += Size[ch[root][1]];
    del(sum[i]);
    Insert(sum[i] + t);
  }
  printf("%lld\n", res);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.

You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.

You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?

Note that outcome of a match can not be a draw, it has to be either win or loss.

Input

The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).

Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.

Output

For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).

Examples

Input

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

Output

yes
yes
yes
no
no

Note

Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.

Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".

Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 7;
const long long mod = 1e9 + 7;
int main() {
  long long t, n, m, d1, d2, mx, mi, s;
  cin >> t;
  while (t--) {
    cin >> n >> m >> d1 >> d2;
    if ((m - d1 - d2) >= 0 && (m - d1 - d2) % 3 == 0 &&
        (m - d1 - d2) / 3 >= 0) {
      mx = max(d1, d2);
      mi = min(d1, d2);
      s = n - m - 2 * mx + mi;
      if (s >= 0 && s % 3 == 0) {
        cout << "yes" << endl;
        continue;
      }
    }
    if ((m - d1 + d2) >= 0 && (m - d1 + d2) % 3 == 0 &&
        (m - d1 + d2) / 3 - d2 >= 0) {
      s = n - m - 2 * d1 - d2;
      if (s >= 0 && s % 3 == 0) {
        cout << "yes" << endl;
        continue;
      }
    }
    if ((m + d1 - d2) >= 0 && (m + d1 - d2) % 3 == 0 &&
        (m + d1 - d2) / 3 - d1 >= 0) {
      s = n - m - 2 * d2 - d1;
      if (s >= 0 && s % 3 == 0) {
        cout << "yes" << endl;
        continue;
      }
    }
    if ((m + d1 + d2) >= 0 && (m + d1 + d2) % 3 == 0 &&
        (m + d1 + d2) / 3 - max(d1, d2) >= 0) {
      s = n - m - d2 - d1;
      if (s >= 0 && s % 3 == 0) {
        cout << "yes" << endl;
        continue;
      }
    }
    cout << "no" << endl;
  }
}

```


### Prompt

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

Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he will knock the cans down.

Vasya knows that the durability of the i-th can is a_i. It means that if Vasya has already knocked x cans down and is now about to start shooting the i-th one, he will need (a_i ⋅ x + 1) shots to knock it down. You can assume that if Vasya starts shooting the i-th can, he will be shooting it until he knocks it down.

Your task is to choose such an order of shooting so that the number of shots required to knock each of the n given cans down exactly once is minimum possible.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 1 000) — the number of cans.

The second line of the input contains the sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 1 000), where a_i is the durability of the i-th can.

Output

In the first line print the minimum number of shots required to knock each of the n given cans down exactly once.

In the second line print the sequence consisting of n distinct integers from 1 to n — the order of indices of cans that minimizes the number of shots required. If there are several answers, you can print any of them.

Examples

Input

3
20 10 20

Output

43
1 3 2

Input

4
10 10 10 10

Output

64
2 1 4 3

Input

6
5 4 5 4 4 5

Output

69
6 1 3 5 2 4

Input

2
1 4

Output

3
2 1

Note

In the first example Vasya can start shooting from the first can. He knocks it down with the first shot because he haven't knocked any other cans down before. After that he has to shoot the third can. To knock it down he shoots 20 ⋅ 1 + 1 = 21 times. After that only second can remains. To knock it down Vasya shoots 10 ⋅ 2 + 1 = 21 times. So the total number of shots is 1 + 21 + 21 = 43.

In the second example the order of shooting does not matter because all cans have the same durability.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 100000 + 5;
using namespace std;
vector<long long> v, dx;
long long c = 1;
long long mx() {
  long long i, mx = 0, ans = 0;
  for (i = 0; i < v.size(); i++) {
    if (v[i] >= mx) {
      ans = i;
      mx = v[i];
    }
  }
  dx.push_back(ans + 1);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, i, ans = 0, a, x = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  for (i = 0; i < n; i++) {
    long long temp = mx();
    ans += v[temp] * x + 1;
    x++;
    v[temp] = -1;
  }
  cout << ans << "\n";
  for (i = 0; i < dx.size(); i++) {
    cout << dx[i] << " ";
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits.

For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units.

Input

The input is given in the following format.

W

The input consists of one line and is given the amount of data W (0 ≤ W ≤ 100).

Output

Outputs the bitwise value on one line.

Examples

Input

4

Output

128

Input

3

Output

96

### Response

```cpp
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n; cin >> n;
	cout << n * 32 << endl;
	cin >> n;
}

```


### Prompt

Generate a CPP solution to the following problem:

You are given a binary string s consisting of n zeros and ones.

Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string belongs to exactly one subsequence and each subsequence looks like "010101 ..." or "101010 ..." (i.e. the subsequence should not contain two adjacent zeros or ones).

Recall that a subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. For example, subsequences of "1011101" are "0", "1", "11111", "0111", "101", "1001", but not "000", "101010" and "11100".

You have to answer t independent test cases.

Input

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

The first line of the test case contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of s. The second line of the test case contains n characters '0' and '1' — the string s.

It is guaranteed that the sum of n does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer: in the first line print one integer k (1 ≤ k ≤ n) — the minimum number of subsequences you can divide the string s to. In the second line print n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the number of subsequence the i-th character of s belongs to.

If there are several answers, you can print any.

Example

Input

4
4
0011
6
111111
5
10101
8
01010000

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = acos(-1);
const int maxn = 2e5 + 5;
int t;
void slove() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> one, zero;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      zero.push_back(i);
    else
      one.push_back(i);
  }
  vector<int> ans(n, 0);
  vector<int> vis(n, 0);
  int idx = 1;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    int pos = -1;
    int tar = s[i];
    while (1) {
      if (tar == '1') {
        auto p = lower_bound(one.begin(), one.end(), pos);
        if (p == one.end()) break;
        ans[*p] = idx;
        vis[*p] = 1;
        pos = *p;
        tar = '0';
        one.erase(p);
      } else {
        auto p = lower_bound(zero.begin(), zero.end(), pos);
        if (p == zero.end()) break;
        ans[*p] = idx;
        vis[*p] = 1;
        pos = *p;
        tar = '1';
        zero.erase(p);
      }
    }
    idx++;
  }
  cout << idx - 1 << '\n';
  for (int v : ans) cout << v << ' ';
  cout << '\n';
}
int main() {
  t = 1;
  cin >> t;
  while (t--) {
    slove();
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

This is the easy version of this problem. The only difference between easy and hard versions is the constraints on k and m (in this version k=2 and m=3). Also, in this version of the problem, you DON'T NEED to output the answer by modulo.

You are given a sequence a of length n consisting of integers from 1 to n. The sequence may contain duplicates (i.e. some elements can be equal).

Find the number of tuples of m = 3 elements such that the maximum number in the tuple differs from the minimum by no more than k = 2. Formally, you need to find the number of triples of indices i < j < z such that

$$$max(a_i, a_j, a_z) - min(a_i, a_j, a_z) ≤ 2.$$$

For example, if n=4 and a=[1,2,4,3], then there are two such triples (i=1, j=2, z=4 and i=2, j=3, z=4). If n=4 and a=[1,1,1,1], then all four possible triples are suitable.

Input

The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — the number of test cases. Then t test cases follow.

The first line of each test case contains an integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the sequence a.

The next line contains n integers a_1, a_2,…, a_n (1 ≤ a_i ≤ n) — the sequence a.

It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.

Output

Output t answers to the given test cases. Each answer is the required number of triples of elements, such that the maximum value in the triple differs from the minimum by no more than 2. Note that in difference to the hard version of the problem, you don't need to output the answer by modulo. You must output the exact value of the answer.

Example

Input

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

Output

2
4
0
15

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (lli i = a; i < b; i++)
#define lli long long int
#define hell 1000000000000000
#define pb push_back
#define vi vector<lli>
#define vip vector<pair<lli, lli>>
#define f first
// #define s second
#define mod 998244353
int vis[1001] = {0};
vector<int> ar[1001];
lli Gcd(lli a, lli b)
{
    if (a % b == 0)
    {
        return b;
    }
    return Gcd(b, a % b);
}
lli power(lli a, lli n)
{
    lli res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = ((res % mod) * (a % mod)) % mod, n--;
        else
            a = ((a % mod) * (a % mod)) % mod, n /= 2;
    }
    return res;
}
void solve()
{
    lli n;
    cin >> n;
    vi v;
    rep(i, 0, n)
    {
        lli x;
        cin >> x;
        v.pb(x);
    };
    sort(v.begin(), v.end());
    lli sum = 0;
    rep(i, 2, n)
    {
        lli j = lower_bound(v.begin(), v.end(), v[i] - 2) - v.begin();
        lli x = (i - j);
        sum += (x * (x - 1)) / 2;
    }
    cout << sum;
    cout << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //sieve();
    lli t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

```


### Prompt

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

There is always an integer in Takahashi's mind.

Initially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is `+` or `-`. When he eats `+`, the integer in his mind increases by 1; when he eats `-`, the integer in his mind decreases by 1.

The symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.

Find the integer in Takahashi's mind after he eats all the symbols.

Constraints

* The length of S is 4.
* Each character in S is `+` or `-`.

Input

Input is given from Standard Input in the following format:

S

Output

Print the integer in Takahashi's mind after he eats all the symbols.

Examples

Input

+-++

Output

2

Input

-+--

Output

-2

Input

----

Output

-4

### Response

```cpp
#include <iostream>

using namespace std;

int main()
{

string arr;
cin>>arr;
int x =0;
for( int i =0;i<4;i++)
{
if(arr[i]=='+'){
x++;
}
else{
x--;
}
}
cout<<x<<endl;

    return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.

<image>

So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.

Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.

Mike has asked you for your help. Calculate the minimum time or say it will never happen.

Input

The first line of input contains integer m (2 ≤ m ≤ 106).

The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).

The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).

The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).

The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).

It is guaranteed that h1 ≠ a1 and h2 ≠ a2.

Output

Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.

Examples

Input

5
4 2
1 1
0 1
2 3

Output

3

Input

1023
1 2
1 0
1 2
1 1

Output

-1

Note

In the first sample, heights sequences are following:

Xaniar: <image>

Abol: <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void period(int m, long long h, long long x, long long y, int *P, int *N,
            int &pad, int &len) {
  fill(P, P + 1000010, -1);
  fill(N, N + 1000010, -1);
  int p = 0;
  do {
    P[p] = h;
    N[h] = p;
    h = (x * h + y) % m;
    p++;
  } while (N[h] == -1);
  len = p - N[h];
  pad = p - len;
}
int getPos(long long t, int len, int pad) {
  if (t < pad + len) {
    return t;
  } else {
    return (t - pad) % len + pad;
  }
}
int main() {
  int m;
  while (cin >> m) {
    int h1, a1, x1, y1;
    cin >> h1 >> a1 >> x1 >> y1;
    int h2, a2, x2, y2;
    cin >> h2 >> a2 >> x2 >> y2;
    static int N1[1000010], N2[1000010];
    static int P1[1000010], P2[1000010];
    int pad1, len1;
    int pad2, len2;
    period(m, h1, x1, y1, P1, N1, pad1, len1);
    period(m, h2, x2, y2, P2, N2, pad2, len2);
    if (N1[a1] == -1 || N2[a2] == -1) {
      cout << -1 << endl;
    } else {
      bool answer = false;
      long long t = 0;
      for (; t < max(pad1 + len1, pad2 + len2); t++) {
        if (P1[getPos(t, len1, pad1)] == a1 &&
            P2[getPos(t, len2, pad2)] == a2) {
          answer = true;
          break;
        }
      }
      if (!answer) {
        t = max(N1[a1], N2[a2]);
        int iter = 0;
        answer = true;
        while (P1[getPos(t, len1, pad1)] != a1 ||
               P2[getPos(t, len2, pad2)] != a2) {
          t += (N1[a1] > N2[a2]) ? len1 : len2;
          iter++;
          if (iter > max(len1, len2)) {
            answer = false;
            break;
          }
        }
      }
      cout << (answer ? t : -1) << endl;
    }
  }
  return 0;
}

```


### Prompt

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

An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full.

Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000"  →  "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address.

Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0.

You can see examples of zero block shortenings below:

  * "a56f:00d3:0000:0124:0001:0000:0000:0000"  →  "a56f:00d3:0000:0124:0001::";
  * "a56f:0000:0000:0124:0001:0000:1234:0ff0"  →  "a56f::0124:0001:0000:1234:0ff0";
  * "a56f:0000:0000:0000:0001:0000:1234:0ff0"  →  "a56f:0000::0000:0001:0000:1234:0ff0";
  * "a56f:00d3:0000:0124:0001:0000:0000:0000"  →  "a56f:00d3:0000:0124:0001::0000";
  * "0000:0000:0000:0000:0000:0000:0000:0000"  →  "::".

It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon.

The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short.

You've got several short records of IPv6 addresses. Restore their full record.

Input

The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).

Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".

It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address.

Output

For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input.

Examples

Input

6
a56f:d3:0:0124:01:f19a:1000:00
a56f:00d3:0000:0124:0001::
a56f::0124:0001:0000:1234:0ff0
a56f:0000::0000:0001:0000:1234:0ff0
::
0ea::4d:f4:6:0

Output

a56f:00d3:0000:0124:0001:f19a:1000:0000
a56f:00d3:0000:0124:0001:0000:0000:0000
a56f:0000:0000:0124:0001:0000:1234:0ff0
a56f:0000:0000:0000:0001:0000:1234:0ff0
0000:0000:0000:0000:0000:0000:0000:0000
00ea:0000:0000:0000:004d:00f4:0006:0000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int q, a[2000];
char second[20000];
int main() {
  scanf("%d\n", &q);
  while (q--) {
    gets(second);
    int n = strlen(second);
    int k = 0;
    int ok = 0;
    for (int i = 0; i < n; ++i)
      if (second[i] == ':') a[++k] = i;
    int pn = -1;
    for (int i = 1; i < k; ++i) {
      if (a[i + 1] - a[i] == 1) pn = i;
    }
    if (pn == -1) {
      a[0] = -1;
      a[++k] = n;
      for (int i = 0; i < k; ++i) {
        for (int j = 0; j < 5 + a[i] - a[i + 1]; ++j) putchar('0');
        for (int j = a[i] + 1; j < a[i + 1]; ++j) putchar(second[j]);
        if (i + 1 < k) putchar(':');
      }
    } else {
      a[0] = -1;
      a[++k] = n;
      for (int i = 0; i < k; ++i) {
        if (i > 0 && i + 1 < k && a[i] + 1 == a[i + 1]) {
          for (int j = 0; j < 9 - k; ++j) {
            printf("0000");
            if (i + 1 < k) putchar(':');
          }
          continue;
        }
        for (int j = 0; j < 5 + a[i] - a[i + 1]; ++j) putchar('0');
        for (int j = a[i] + 1; j < a[i + 1]; ++j) putchar(second[j]);
        if (i + 1 < k) putchar(':');
      }
    }
    puts("");
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?"

We have a tree T with n vertices and m types of ice cream numerated from 1 to m. Each vertex i has a set of si types of ice cream. Vertices which have the i-th (1 ≤ i ≤ m) type of ice cream form a connected subgraph. We build a new graph G with m vertices. We put an edge between the v-th and the u-th (1 ≤ u, v ≤ m, u ≠ v) vertices in G if and only if there exists a vertex in T that has both the v-th and the u-th types of ice cream in its set. The problem is to paint the vertices of G with minimum possible number of colors in a way that no adjacent vertices have the same color.

Please note that we consider that empty set of vertices form a connected subgraph in this problem.

As usual, Modsart don't like to abandon the previous problem, so Isart wants you to solve the new problem.

Input

The first line contains two integer n and m (1 ≤ n, m ≤ 3·105) — the number of vertices in T and the number of ice cream types.

n lines follow, the i-th of these lines contain single integer si (0 ≤ si ≤ 3·105) and then si distinct integers, each between 1 and m — the types of ice cream in the i-th vertex. The sum of si doesn't exceed 5·105.

n - 1 lines follow. Each of these lines describes an edge of the tree with two integers u and v (1 ≤ u, v ≤ n) — the indexes of connected by this edge vertices.

Output

Print single integer c in the first line — the minimum number of colors to paint the vertices in graph G.

In the second line print m integers, the i-th of which should be the color of the i-th vertex. The colors should be between 1 and c. If there are some answers, print any of them.

Examples

Input

3 3
1 1
2 2 3
1 2
1 2
2 3

Output

2
1 1 2

Input

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

Output

3
1 1 1 2 3

Note

In the first example the first type of ice cream is present in the first vertex only, so we can color it in any color. The second and the third ice cream are both presented in the second vertex, so we should paint them in different colors.

In the second example the colors of the second, the fourth and the fifth ice cream should obviously be distinct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> v[300001];
unordered_set<int> ice[300001], used[300001];
int colors[300001];
void dfs(const int nod, const int parent) {
  for (const int x : ice[nod]) {
    if (ice[parent].find(x) != ice[parent].end()) {
      used[nod].insert(colors[x]);
    }
  }
  int nr = 0;
  for (const int x : ice[nod]) {
    if (ice[parent].find(x) == ice[parent].end()) {
      nr++;
      while (used[nod].find(nr) != used[nod].end()) {
        nr++;
      }
      colors[x] = nr;
      used[nod].insert(nr);
    }
  }
  for (const int x : v[nod]) {
    if (x == parent) {
      continue;
    }
    dfs(x, nod);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int cnt;
    cin >> cnt;
    for (int j = 1; j <= cnt; j++) {
      int x;
      cin >> x;
      ice[i].insert(x);
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int sol = 1;
  for (int i = 1; i <= n; i++) {
    sol = max(sol, (int)ice[i].size());
  }
  cout << sol << '\n';
  dfs(1, 0);
  for (int i = 1; i <= m; i++) {
    cout << max(colors[i], 1) << " ";
  }
  cout << '\n';
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.

You are given a weighted directed graph with n vertices and m edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path.

Help Pashmak, print the number of edges in the required path.

Input

The first line contains two integers n, m (2 ≤ n ≤ 3·105; 1 ≤ m ≤ min(n·(n - 1), 3·105)). Then, m lines follows. The i-th line contains three space separated integers: ui, vi, wi (1 ≤ ui, vi ≤ n; 1 ≤ wi ≤ 105) which indicates that there's a directed edge with weight wi from vertex ui to vertex vi.

It's guaranteed that the graph doesn't contain self-loops and multiple edges.

Output

Print a single integer — the answer to the problem.

Examples

Input

3 3
1 2 1
2 3 1
3 1 1

Output

1

Input

3 3
1 2 1
2 3 2
3 1 3

Output

3

Input

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

Output

6

Note

In the first sample the maximum trail can be any of this trails: <image>.

In the second sample the maximum trail is <image>.

In the third sample the maximum trail is <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000000000000000;
long long mod = 1000000000;
long double pi = 3.141592653589793238;
void pls() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long dp[300001];
vector<pair<long long, long long>> g[100001];
vector<long long> temp(300001);
void solve() {
  long long n, m;
  cin >> n >> m;
  long long mx = 0;
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    g[w].push_back({u, v});
    mx = max(mx, w);
  }
  for (int i = 1; i <= mx; i++) {
    long long u, v;
    for (int j = 0; j < g[i].size(); j++) {
      u = g[i][j].first;
      v = g[i][j].second;
      temp[v] = 0;
    }
    for (int j = 0; j < g[i].size(); j++) {
      u = g[i][j].first;
      v = g[i][j].second;
      temp[v] = max(temp[v], dp[u] + 1);
    }
    for (int j = 0; j < g[i].size(); j++) {
      u = g[i][j].first;
      v = g[i][j].second;
      dp[v] = max(dp[v], temp[v]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
}
int main() {
  pls();
  solve();
  return 0;
}

```


### Prompt

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

You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion.

All strings that can be obtained in this way can be evaluated as formulas.

Evaluate all possible formulas, and print the sum of the results.

Constraints

* 1 \leq |S| \leq 10
* All letters in S are digits between `1` and `9`, inclusive.

Input

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

S

Output

Print the sum of the evaluated value over all possible formulas.

Examples

Input

125

Output

176

Input

9999999999

Output

12656242944

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  string s;cin>>s;
  ll ans=0,k=1<<(s.size()-1),l=k;
  for(ll i=s.size()-1;i>=0;i--) ans+=(s[i]-'0')*k,k=k*5+l/2;
  cout<<ans<<endl;
}
```


### Prompt

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

In a magical land there are n cities conveniently numbered 1, 2, ..., n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may appear between two cities.

Vicky the witch has been tasked with performing deliveries between some pairs of cities. However, Vicky is a beginner, so she can only complete a delivery if she can move from her starting city to her destination city through a double rainbow. A double rainbow is a sequence of cities c_1, c_2, ..., c_k satisfying the following properties:

  * For each i with 1 ≤ i ≤ k - 1, the cities c_i and c_{i + 1} are connected by a road.
  * For each i with 1 ≤ i ≤ (k - 1)/(2), the roads connecting c_{2i} with c_{2i - 1} and c_{2i + 1} have the same color.

For example if k = 5, the road between c_1 and c_2 must be the same color as the road between c_2 and c_3, and the road between c_3 and c_4 must be the same color as the road between c_4 and c_5.

Vicky has a list of events in chronological order, where each event is either a delivery she must perform, or appearance of a new road. Help her determine which of her deliveries she will be able to complete.

Input

The first line contains four integers n, m, c, and q (2 ≤ n ≤ 10^5, 1 ≤ m, c, q ≤ 10^5), denoting respectively the number of cities, the number of roads initially present, the number of different colors the roads can take, and the number of events.

Each of the following m lines contains three integers x, y, and z (1 ≤ x, y ≤ n, 1 ≤ z ≤ c), describing that there initially exists a bidirectional road with color z between cities x and y.

Then q lines follow, describing the events. Each event is one of the following two types:

  1. + x y z (1 ≤ x, y ≤ n, 1 ≤ z ≤ c), meaning a road with color z appears between cities x and y;
  2. ? x y (1 ≤ x, y ≤ n), meaning you should determine whether Vicky can make a delivery starting at city x and ending at city y. It is guaranteed that x ≠ y.

It is guaranteed that at any moment, there is at most one road connecting any pair of cities, and that no road connects a city to itself. It is guaranteed that the input contains at least one event of the second type.

Output

For each event of the second type, print a single line containing "Yes" (without quotes) if the delivery can be made, or a single line containing "No" (without quotes) otherwise.

Example

Input

4 3 2 4
1 2 1
2 3 1
3 4 2
? 1 4
? 4 1
+ 3 1 2
? 4 1

Output

Yes
No
Yes

Note

The following picture corresponds to the sample.

<image>

For her first delivery, Vicky can use the sequence 1, 2, 3, 4 which is a double rainbow. However, she cannot complete the second delivery, as she can only reach city 3. After adding the road between cities 1 and 3, she can now complete a delivery from city 4 to city 1 by using the double rainbow 4, 3, 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> col;
set<int> AdjList[100001];
int p[100001];
int anc(int x) {
  if (p[x] == x) return x;
  return p[x] = anc(p[x]);
}
void join(int x, int y) { p[anc(x)] = anc(y); }
struct Query {
  int type, u, v, c;
  Query() {}
  Query(int _type, int _u, int _v, int _c) {
    type = _type;
    u = _u;
    v = _v;
    c = _c;
  }
};
vector<Query> Q;
int n;
int m, C, q;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> C >> q;
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    Q.push_back(Query(0, u, v, c));
  }
  for (int i = 1; i <= q; i++) {
    char z;
    cin >> z;
    if (z == '+') {
      int u, v, c;
      cin >> u >> v >> c;
      Q.push_back(Query(0, u, v, c));
    } else {
      int u, v;
      cin >> u >> v;
      Q.push_back(Query(1, u, v, -1));
    }
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < Q.size(); i++) {
    if (!Q[i].type) {
      int u = Q[i].u;
      int v = Q[i].v;
      int c = Q[i].c;
      int anc_u = anc(u);
      int anc_v = anc(v);
      AdjList[anc_u].insert(v);
      AdjList[anc_v].insert(u);
      if (!col[pair<int, int>(u, c)]) col[pair<int, int>(u, c)] = v;
      if (!col[pair<int, int>(v, c)]) col[pair<int, int>(v, c)] = u;
      int z = col[pair<int, int>(v, c)];
      int anc_z = anc(z);
      if (anc_u != anc_z) {
        if (AdjList[anc_u].size() > AdjList[anc_z].size())
          swap(AdjList[anc_u], AdjList[anc_z]);
        while (!AdjList[anc_u].empty()) {
          AdjList[anc_z].insert(*AdjList[anc_u].begin());
          AdjList[anc_u].erase(AdjList[anc_u].begin());
        }
        p[anc_u] = anc_z;
      }
      z = col[pair<int, int>(u, c)];
      anc_z = anc(z);
      if (anc_v != anc_z) {
        if (AdjList[anc_v].size() > AdjList[anc_z].size())
          swap(AdjList[anc_v], AdjList[anc_z]);
        while (!AdjList[anc_v].empty()) {
          AdjList[anc_z].insert(*AdjList[anc_v].begin());
          AdjList[anc_v].erase(AdjList[anc_v].begin());
        }
        p[anc_v] = anc_z;
      }
    } else {
      int u = Q[i].u;
      int v = Q[i].v;
      int anc_u = anc(u);
      int anc_v = anc(v);
      if (anc_u == anc_v)
        cout << "Yes" << '\n';
      else if (AdjList[anc_u].find(v) != AdjList[anc_u].end())
        cout << "Yes" << '\n';
      else
        cout << "No" << '\n';
    }
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Joisino has a lot of red and blue bricks and a large box. She will build a tower of these bricks in the following manner.

First, she will pick a total of N bricks and put them into the box. Here, there may be any number of bricks of each color in the box, as long as there are N bricks in total. Particularly, there may be zero red bricks or zero blue bricks. Then, she will repeat an operation M times, which consists of the following three steps:

* Take out an arbitrary brick from the box.
* Put one red brick and one blue brick into the box.
* Take out another arbitrary brick from the box.

After the M operations, Joisino will build a tower by stacking the 2 \times M bricks removed from the box, in the order they are taken out. She is interested in the following question: how many different sequences of colors of these 2 \times M bricks are possible? Write a program to find the answer. Since it can be extremely large, print the count modulo 10^9+7.

Constraints

* 1 \leq N \leq 3000
* 1 \leq M \leq 3000

Input

Input is given from Standard Input in the following format:

N M

Output

Print the count of the different possible sequences of colors of 2 \times M bricks that will be stacked, modulo 10^9+7.

Examples

Input

2 3

Output

56

Input

1000 10

Output

1048576

Input

1000 3000

Output

693347555

### Response

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

const int maxN=3010;
const int Mod=1e9+7;

int n,m;
int F[maxN][maxN][2];

void Plus(int &x,int y);
int main(){
    scanf("%d%d",&n,&m);
    F[0][0][1]=1;
    for (int i=1;i<=n;i++) F[0][i][0]=1;
    for (int i=0;i<m;i++) for (int j=0;j<=n;j++) for (int k=0;k<=1;k++){
        if (!F[i][j][k]) continue;
        if (j>=1) Plus(F[i+1][j-1][k|(j==1)],F[i][j][k]),Plus(F[i+1][j][k|(j==1)],F[i][j][k]);
        if (j<n) Plus(F[i+1][j][k],F[i][j][k]),Plus(F[i+1][j+1][k],F[i][j][k]);
    }
    int Ans=0;
    for (int i=0;i<=n;i++) Plus(Ans,F[m][i][1]);
    printf("%d\n",Ans);return 0;
}
void Plus(int &x,int y){
    x+=y;if (x>=Mod) x-=Mod;return;
}
```


### Prompt

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

On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the coordinates (x,y), where x is the column number and y is the row number.

Every day there are fights between black and white pieces on this board. Today, the black ones won, but at what price? Only the rook survived, and it was driven into the lower left corner — a cell with coordinates (1,1). But it is still happy, because the victory has been won and it's time to celebrate it! In order to do this, the rook needs to go home, namely — on the upper side of the field (that is, in any cell that is in the row with number 10^9).

Everything would have been fine, but the treacherous white figures put spells on some places of the field before the end of the game. There are two types of spells:

  * Vertical. Each of these is defined by one number x. Such spells create an infinite blocking line between the columns x and x+1.
  * Horizontal. Each of these is defined by three numbers x_1, x_2, y. Such spells create a blocking segment that passes through the top side of the cells, which are in the row y and in columns from x_1 to x_2 inclusive. The peculiarity of these spells is that it is impossible for a certain pair of such spells to have a common point. Note that horizontal spells can have common points with vertical spells.

<image> An example of a chessboard.

Let's recall that the rook is a chess piece that in one move can move to any point that is in the same row or column with its initial position. In our task, the rook can move from the cell (r_0,c_0) into the cell (r_1,c_1) only under the condition that r_1 = r_0 or c_1 = c_0 and there is no blocking lines or blocking segments between these cells (For better understanding, look at the samples).

Fortunately, the rook can remove spells, but for this it has to put tremendous efforts, therefore, it wants to remove the minimum possible number of spells in such way, that after this it can return home. Find this number!

Input

The first line contains two integers n and m (0 ≤ n,m ≤ 10^5) — the number of vertical and horizontal spells.

Each of the following n lines contains one integer x (1 ≤ x < 10^9) — the description of the vertical spell. It will create a blocking line between the columns of x and x+1.

Each of the following m lines contains three integers x_1, x_2 and y (1 ≤ x_{1} ≤ x_{2} ≤ 10^9, 1 ≤ y < 10^9) — the numbers that describe the horizontal spell. It will create a blocking segment that passes through the top sides of the cells that are in the row with the number y, in columns from x_1 to x_2 inclusive.

It is guaranteed that all spells are different, as well as the fact that for each pair of horizontal spells it is true that the segments that describe them do not have common points.

Output

In a single line print one integer — the minimum number of spells the rook needs to remove so it can get from the cell (1,1) to at least one cell in the row with the number 10^9

Examples

Input

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

Output

1

Input

1 3
4
1 5 3
1 9 4
4 6 6

Output

1

Input

0 2
1 1000000000 4
1 1000000000 2

Output

2

Input

0 0

Output

0

Input

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

Output

2

Note

In the first sample, in order for the rook return home, it is enough to remove the second horizontal spell.

<image> Illustration for the first sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the second horizontal spell. It also shows the path, on which the rook would be going home.

In the second sample, in order for the rook to return home, it is enough to remove the only vertical spell. If we tried to remove just one of the horizontal spells, it would not allow the rook to get home, because it would be blocked from above by one of the remaining horizontal spells (either first one or second one), and to the right it would be blocked by a vertical spell.

<image> Illustration for the second sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletion of the vertical spell. It also shows the path, on which the rook would be going home.

In the third sample, we have two horizontal spells that go through the whole field. These spells can not be bypassed, so we need to remove both of them.

<image> Illustration for the third sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the horizontal spells. It also shows the path, on which the rook would be going home.

In the fourth sample, we have no spells, which means that we do not need to remove anything.

In the fifth example, we can remove the first vertical and third horizontal spells.

<image> Illustration for the fifth sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletions. It also shows the path, on which the rook would be going home.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long inf = numeric_limits<long long>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(-1);
inline void solve(), read();
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  read();
  solve();
  return 0;
}
struct hor {
  long long x1, x2, y;
};
long long MAXC = 1e9;
long long n, m;
vector<long long> vs;
vector<hor> hs;
vector<long long> coord;
vector<long long> bucks;
long long max1 = 0;
void reduce() {
  coord.push_back(0);
  coord.push_back(1);
  for (long long i = 0; i < n; i++) {
    coord.push_back(vs[i]);
    coord.push_back(vs[i] + 1);
  }
  for (long long i = 0; i < m; i++) {
    coord.push_back(hs[i].x1);
    coord.push_back(hs[i].x2);
    coord.push_back(hs[i].x2 + 1);
    coord.push_back(hs[i].y);
  }
  coord.push_back(MAXC);
  sort((coord).begin(), (coord).end());
  coord.resize(unique((coord).begin(), (coord).end()) - coord.begin());
  for (long long i = 0; i < n; i++) {
    vs[i] = lower_bound((coord).begin(), (coord).end(), vs[i]) - coord.begin();
  }
  for (long long i = 0; i < m; i++) {
    hs[i].x1 =
        lower_bound((coord).begin(), (coord).end(), hs[i].x1) - coord.begin();
    hs[i].x2 =
        lower_bound((coord).begin(), (coord).end(), hs[i].x2) - coord.begin();
    hs[i].y =
        lower_bound((coord).begin(), (coord).end(), hs[i].y) - coord.begin();
    if (hs[i].x1 == 1) {
      (max1) = ((max1) < (hs[i].x2)) ? (hs[i].x2) : (max1);
    }
  }
  MAXC = lower_bound((coord).begin(), (coord).end(), MAXC) - coord.begin();
}
inline void solve() {
  reduce();
  bucks.resize((long long)((coord).size()));
  for (long long i = 0; i < m; i++) {
    if (hs[i].x1 == 1) {
      ++bucks[hs[i].x1];
      --bucks[hs[i].x2 + 1];
    }
  }
  sort((vs).begin(), (vs).end());
  long long j = 0;
  long long ans = inf;
  long long cur = 0;
  long long z = 0;
  for (long long i = 1; i <= MAXC; i++) {
    z += bucks[i];
    while (j < (long long)((vs).size()) && vs[j] < i) {
      ++j;
    }
    if (i > max1) {
      (ans) = ((ans) > (j)) ? (j) : (ans);
    } else {
      (ans) = ((ans) > (j + z)) ? (j + z) : (ans);
    }
  }
  cout << ans << "\n";
}
inline void read() {
  cin >> n >> m;
  vs.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> vs[i];
  }
  hs.resize(m);
  for (long long i = 0; i < m; i++) {
    cin >> hs[i].x1 >> hs[i].x2 >> hs[i].y;
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

There is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enumerated from 1 to n, the junction 1 is called the root.

A subtree of a junction v is a set of junctions u such that the path from u to the root must pass through v. Note that v itself is included in a subtree of v.

A leaf is such a junction that its subtree contains exactly one junction.

The New Year is coming, so Arkady wants to decorate the tree. He will put a light bulb of some color on each leaf junction and then count the number happy junctions. A happy junction is such a junction t that all light bulbs in the subtree of t have different colors.

Arkady is interested in the following question: for each k from 1 to n, what is the minimum number of different colors needed to make the number of happy junctions be greater than or equal to k?

Input

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

The second line contains n - 1 integers p_2, p_3, ..., p_n (1 ≤ p_i < i), where p_i means there is a branch between junctions i and p_i. It is guaranteed that this set of branches forms a tree.

Output

Output n integers. The i-th of them should be the minimum number of colors needed to make the number of happy junctions be at least i.

Examples

Input

3
1 1

Output

1 1 2

Input

5
1 1 3 3

Output

1 1 1 2 3

Note

In the first example for k = 1 and k = 2 we can use only one color: the junctions 2 and 3 will be happy. For k = 3 you have to put the bulbs of different colors to make all the junctions happy.

In the second example for k = 4 you can, for example, put the bulbs of color 1 in junctions 2 and 4, and a bulb of color 2 into junction 5. The happy junctions are the ones with indices 2, 3, 4 and 5 then.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int fa[100005], sz[100005], ans[100005];
vector<int> e[100005];
void dfs0(int u) {
  if (e[u].size() == 0) {
    sz[u] = 1;
    return;
  }
  int v;
  for (int i = 0; i < e[u].size(); i++) {
    v = e[u][i];
    dfs0(v);
    sz[u] += sz[v];
  }
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> fa[i];
    e[fa[i]].push_back(i);
  }
  dfs0(1);
  sort(sz + 1, sz + n + 1);
  for (int i = 1; i <= n; i++) cout << sz[i] << " ";
  return 0;
}

```


### Prompt

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

In Doodle Jump the aim is to guide a four-legged creature called "The Doodler" up a never-ending series of platforms without falling. — Wikipedia.

It is a very popular game and xiaodao likes it very much. One day when playing the game she wondered whether there exists a platform that the doodler couldn't reach due to the limits of its jumping ability. Consider the following problem.

There are n platforms. The height of the x-th (1 ≤ x ≤ n) platform is a·x mod p, where a and p are positive co-prime integers. The maximum possible height of a Doodler's jump is h. That is, it can jump from height h1 to height h2 (h1 < h2) if h2 - h1 ≤ h. Initially, the Doodler is on the ground, the height of which is 0. The question is whether it can reach the highest platform or not.

For example, when a = 7, n = 4, p = 12, h = 2, the heights of the platforms are 7, 2, 9, 4 as in the picture below. With the first jump the Doodler can jump to the platform at height 2, with the second one the Doodler can jump to the platform at height 4, but then it can't jump to any of the higher platforms. So, it can't reach the highest platform.

<image>

User xiaodao thought about the problem for a long time but didn't solve it, so she asks you for help. Also, she has a lot of instances of the problem. Your task is solve all of these instances.

Input

The first line contains an integer t (1 ≤ t ≤ 104) — the number of problem instances. Each of the next t lines contains four integers a, n, p and h (1 ≤ a ≤ 109, 1 ≤ n < p ≤ 109, 0 ≤ h ≤ 109). It's guaranteed that a and p are co-prime.

Output

For each problem instance, if the Doodler can reach the highest platform, output "YES", otherwise output "NO".

Examples

Input

3
7 4 12 2
7 1 9 4
7 4 12 3

Output

NO
NO
YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  long long a, n, p, h, hi;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld%lld%lld", &a, &n, &p, &h);
    hi = -1;
    a %= p;
    while (a * n >= p) {
      long long k = a * n / p;
      if (p - p % a - a * n % p >= a) k--;
      long long na = min(a - p % a, p % a), np = a;
      hi = p = np;
      a = na;
      n = k;
    }
    puts(h < max(a, hi - n * a) ? "NO" : "YES");
  }
}

```


### Prompt

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

This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.

Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit after station i is station i+1 if 1 ≤ i < n or station 1 if i = n. It takes the train 1 second to travel to its next station as described.

Bob gave Alice a fun task before he left: to deliver m candies that are initially at some stations to their independent destinations using the train. The candies are enumerated from 1 through m. Candy i (1 ≤ i ≤ m), now at station a_i, should be delivered to station b_i (a_i ≠ b_i).

<image> The blue numbers on the candies correspond to b_i values. The image corresponds to the 1-st example.

The train has infinite capacity, and it is possible to load off any number of candies at a station. However, only at most one candy can be loaded from a station onto the train before it leaves the station. You can choose any candy at this station. The time it takes to move the candies is negligible.

Now, Alice wonders how much time is needed for the train to deliver all candies. Your task is to find, for each station, the minimum time the train would need to deliver all the candies were it to start from there.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 100; 1 ≤ m ≤ 200) — the number of stations and the number of candies, respectively.

The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n; a_i ≠ b_i) — the station that initially contains candy i and the destination station of the candy, respectively.

Output

In the first and only line, print n space-separated integers, the i-th of which is the minimum time, in seconds, the train would need to deliver all the candies were it to start from station i.

Examples

Input

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

Output

10 9 10 10 9

Input

2 3
1 2
1 2
1 2

Output

5 6

Note

Consider the second sample.

If the train started at station 1, the optimal strategy is as follows.

  1. Load the first candy onto the train.
  2. Proceed to station 2. This step takes 1 second.
  3. Deliver the first candy.
  4. Proceed to station 1. This step takes 1 second.
  5. Load the second candy onto the train.
  6. Proceed to station 2. This step takes 1 second.
  7. Deliver the second candy.
  8. Proceed to station 1. This step takes 1 second.
  9. Load the third candy onto the train.
  10. Proceed to station 2. This step takes 1 second.
  11. Deliver the third candy.

Hence, the train needs 5 seconds to complete the tasks.

If the train were to start at station 2, however, it would need to move to station 1 before it could load the first candy, which would take one additional second. Thus, the answer in this scenario is 5+1 = 6 seconds.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
inline int read() {
  int s = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return s;
}
int n, m;
int a[N], b[N];
vector<int> G[N];
inline int dis(int i, int j) { return i > j ? (n - i + j) : (j - i); }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    a[i] = read(), b[i] = read();
    G[a[i]].push_back(dis(a[i], b[i]));
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, (int)G[i].size());
    sort(G[i].begin(), G[i].end());
  }
  int ans = (mx - 1) * n;
  for (int i = 1; i <= n; i++) {
    int t = 0;
    for (int j = i; j <= n; j++) {
      if (!G[j].size()) continue;
      if (G[j].size() == mx)
        t = max(t, j + G[j][0] - i);
      else if (G[j].size() == mx - 1) {
        int tmp = j + G[j][0];
        if (tmp > n) tmp -= n;
        if (tmp > j) continue;
        t = max(t, tmp - i);
      }
    }
    for (int j = 1; j < i; j++) {
      if (!G[j].size()) continue;
      if (G[j].size() == mx)
        t = max(t, j + G[j][0] + n - i);
      else if (G[j].size() == mx - 1) {
        int tmp = j + G[j][0];
        t = max(t, tmp - i);
      };
    }
    printf("%d ", ans + t);
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town i is X_i.

You are now at town 1, and you want to visit all the other towns. You have two ways to travel:

* Walk on the line. Your fatigue level increases by A each time you travel a distance of 1, regardless of direction.

* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.

Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.

Constraints

* All input values are integers.
* 2≤N≤10^5
* 1≤X_i≤10^9
* For all i(1≤i≤N-1), X_i<X_{i+1}.
* 1≤A≤10^9
* 1≤B≤10^9

Input

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

N A B
X_1 X_2 ... X_N

Output

Print the minimum possible total increase of your fatigue level when you visit all the towns.

Examples

Input

4 2 5
1 2 5 7

Output

11

Input

7 1 100
40 43 45 105 108 115 124

Output

84

Input

7 1 2
24 35 40 68 72 99 103

Output

12

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
long long x[100001],a,b;
int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	  cin>>x[i];
	long long ans=0;
	for(int i=2;i<=n;i++)
	  if((x[i]-x[i-1])*a>b) ans+=b;
	  else ans+=(x[i]-x[i-1])*a;
	cout<<ans;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universal (∀) and existential (∃). You can read more about them here.

The universal quantifier is used to make a claim that a statement holds for all real numbers. For example:

  * ∀ x,x<100 is read as: for all real numbers x, x is less than 100. This statement is false.
  * ∀ x,x>x-1 is read as: for all real numbers x, x is greater than x-1. This statement is true.

The existential quantifier is used to make a claim that there exists some real number for which the statement holds. For example:

  * ∃ x,x<100 is read as: there exists a real number x such that x is less than 100. This statement is true.
  * ∃ x,x>x-1 is read as: there exists a real number x such that x is greater than x-1. This statement is true.

Moreover, these quantifiers can be nested. For example:

  * ∀ x,∃ y,x<y is read as: for all real numbers x, there exists a real number y such that x is less than y. This statement is true since for every x, there exists y=x+1.
  * ∃ y,∀ x,x<y is read as: there exists a real number y such that for all real numbers x, x is less than y. This statement is false because it claims that there is a maximum real number: a number y larger than every x.

Note that the order of variables and quantifiers is important for the meaning and veracity of a statement.

There are n variables x_1,x_2,…,x_n, and you are given some formula of the form $$$ f(x_1,...,x_n):=(x_{j_1}<x_{k_1})∧ (x_{j_2}<x_{k_2})∧ ⋅⋅⋅∧ (x_{j_m}<x_{k_m}), $$$

where ∧ denotes logical AND. That is, f(x_1,…, x_n) is true if every inequality x_{j_i}<x_{k_i} holds. Otherwise, if at least one inequality does not hold, then f(x_1,…,x_n) is false.

Your task is to assign quantifiers Q_1,…,Q_n to either universal (∀) or existential (∃) so that the statement $$$ Q_1 x_1, Q_2 x_2, …, Q_n x_n, f(x_1,…, x_n) $$$

is true, and the number of universal quantifiers is maximized, or determine that the statement is false for every possible assignment of quantifiers.

Note that the order the variables appear in the statement is fixed. For example, if f(x_1,x_2):=(x_1<x_2) then you are not allowed to make x_2 appear first and use the statement ∀ x_2,∃ x_1, x_1<x_2. If you assign Q_1=∃ and Q_2=∀, it will only be interpreted as ∃ x_1,∀ x_2,x_1<x_2.

Input

The first line contains two integers n and m (2≤ n≤ 2⋅ 10^5; 1≤ m≤ 2⋅ 10^5) — the number of variables and the number of inequalities in the formula, respectively.

The next m lines describe the formula. The i-th of these lines contains two integers j_i,k_i (1≤ j_i,k_i≤ n, j_i≠ k_i).

Output

If there is no assignment of quantifiers for which the statement is true, output a single integer -1.

Otherwise, on the first line output an integer, the maximum possible number of universal quantifiers.

On the next line, output a string of length n, where the i-th character is "A" if Q_i should be a universal quantifier (∀), or "E" if Q_i should be an existential quantifier (∃). All letters should be upper-case. If there are multiple solutions where the number of universal quantifiers is maximum, print any.

Examples

Input

2 1
1 2

Output

1
AE

Input

4 3
1 2
2 3
3 1

Output

-1

Input

3 2
1 3
2 3

Output

2
AAE

Note

For the first test, the statement ∀ x_1, ∃ x_2, x_1<x_2 is true. Answers of "EA" and "AA" give false statements. The answer "EE" gives a true statement, but the number of universal quantifiers in this string is less than in our answer.

For the second test, we can show that no assignment of quantifiers, for which the statement is true exists.

For the third test, the statement ∀ x_1, ∀ x_2, ∃ x_3, (x_1<x_3)∧ (x_2<x_3) is true: We can set x_3=max\\{x_1,x_2\}+1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int le = 2 * 1e5;
vector<int> g[le];
vector<int> rg[le];
int usedi[le];
bool cycle = false;
void dfs0(int v) {
  usedi[v] = -1;
  for (int e : g[v]) {
    if (!usedi[e]) dfs0(e);
    if (usedi[e] == -1) cycle = true;
  }
  usedi[v] = 1;
}
bool used1[le];
bool used2[le];
void dfs1(int v) {
  used1[v] = true;
  for (int e : g[v]) {
    if (used1[e]) continue;
    dfs1(e);
  }
}
void dfs2(int v) {
  used2[v] = true;
  for (int e : rg[v]) {
    if (used2[e]) continue;
    dfs2(e);
  }
}
char result[le];
int main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    rg[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (!usedi[i]) dfs0(i);
  }
  if (cycle) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!used1[i] && !used2[i]) {
      ans++;
      result[i] = 'A';
    } else {
      result[i] = 'E';
    }
    if (!used1[i]) dfs1(i);
    if (!used2[i]) dfs2(i);
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << result[i];
  cout << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in n ⋅ m colored pieces that form a rectangle with n rows and m columns.

The colored pieces attracted Innokenty's attention so he immediately came up with the following business plan. If he cuts out a subrectangle consisting of three colored stripes, he can sell it as a flag of some country. Innokenty decided that a subrectangle is similar enough to a flag of some country if it consists of three stripes of equal heights placed one above another, where each stripe consists of cells of equal color. Of course, the color of the top stripe must be different from the color of the middle stripe; and the color of the middle stripe must be different from the color of the bottom stripe.

Innokenty has not yet decided what part he will cut out, but he is sure that the flag's boundaries should go along grid lines. Also, Innokenty won't rotate the blanket. Please help Innokenty and count the number of different subrectangles Innokenty can cut out and sell as a flag. Two subrectangles located in different places but forming the same flag are still considered different.

<image> <image> <image>

These subrectangles are flags.

<image> <image> <image> <image> <image> <image>

These subrectangles are not flags.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 1 000) — the number of rows and the number of columns on the blanket.

Each of the next n lines contains m lowercase English letters from 'a' to 'z' and describes a row of the blanket. Equal letters correspond to equal colors, different letters correspond to different colors.

Output

In the only line print the number of subrectangles which form valid flags.

Examples

Input

4 3
aaa
bbb
ccb
ddd

Output

6

Input

6 1
a
a
b
b
c
c

Output

1

Note

<image> <image>

The selected subrectangles are flags in the first example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char str[1005][1005];
int sum[1005][1005], W[1005][1005], F[1005][1005];
int main() {
  int n, m;
  long long ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", str[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == str[i - 1][j])
        sum[i][j] = sum[i - 1][j] + 1;
      else
        sum[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int l = i, r = n, len = 0, k = sum[i][j];
      k--;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (sum[mid][j] - k == mid - i + 1)
          len = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      int L = len - i, u = len + L + 1, v = u + L + 1, flg = 0;
      if (u <= n && sum[u][j] == L + 1) flg |= 1;
      if (v <= n && sum[v][j] == L + 1) flg |= 2;
      if (flg == 3) {
        ans++;
        if (W[i][j - 1] == len && str[i][j - 1] == str[i][j] &&
            str[u][j] == str[u][j - 1] && str[v][j] == str[v][j - 1])
          ans += F[i][j - 1], F[i][j] = F[i][j - 1] + 1;
        else
          F[i][j] = 1;
        W[i][j] = len;
      }
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b — as bj.

The distance between permutations a and b is the minimum absolute value of the difference between the positions of the occurrences of some number in a and in b. More formally, it's such minimum |i - j|, that ai = bj.

A cyclic shift number i (1 ≤ i ≤ n) of permutation b consisting from n elements is a permutation bibi + 1... bnb1b2... bi - 1. Overall a permutation has n cyclic shifts.

The Little Elephant wonders, for all cyclic shifts of permutation b, what is the distance between the cyclic shift and permutation a?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the permutations. The second line contains permutation a as n distinct numbers from 1 to n, inclusive. The numbers are separated with single spaces. The third line contains permutation b in the same format.

Output

In n lines print n integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation b, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on.

Examples

Input

2
1 2
2 1

Output

1
0

Input

4
2 1 3 4
3 4 2 1

Output

2
1
0
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n, a[N], b[N], A[N], B[N], c[N];
map<int, int> M;
int main() {
  scanf("%d", &n);
  for (int i = n; i >= 1; i--) {
    scanf("%d", &b[i]);
    B[b[i]] = i;
  }
  for (int i = n; i >= 1; i--) {
    scanf("%d", &a[i]);
    A[a[i]] = i;
  }
  M.clear();
  for (int i = 1; i <= n; i++) {
    c[i] = A[i] - B[i];
    M[c[i]]++;
  }
  for (int i = 0; i < n; i++) {
    map<int, int>::iterator t1 = M.lower_bound(-i);
    int ans = 10000000;
    if (t1 != M.end()) {
      ans = (*t1).first + i;
    }
    if (t1 != M.begin()) {
      t1--;
      ans = min(ans, -i - (*t1).first);
    }
    printf("%d\n", ans);
    M[c[a[n - i]]]--;
    if (M[c[a[n - i]]] == 0) M.erase(c[a[n - i]]);
    M[-i - B[a[n - i]]]++;
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.

Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:

  * b - a ≤ 1 (it means b = a or b = a + 1);
  * the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).

⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.

Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.

You have to answer t independent test cases.

Input

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

The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.

Output

For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.

Example

Input

5
5 2
19 4
12 7
6 2
100000 50010

Output

5
18
10
6
75015

Note

In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.

In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.

In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.

In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long d = k / 2;
    long long cc = n / k;
    long long sum = cc * k;
    long long rem1 = n - sum;
    sum += min(d, rem1);
    cout << sum << '\n';
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Heidi found out that the Daleks have created a network of bidirectional Time Corridors connecting different destinations (at different times!). She suspects that they are planning another invasion on the entire Space and Time. In order to counter the invasion, she plans to deploy a trap in the Time Vortex, along a carefully chosen Time Corridor. She knows that tinkering with the Time Vortex is dangerous, so she consulted the Doctor on how to proceed. She has learned the following:

  * Different Time Corridors require different amounts of energy to keep stable.
  * Daleks are unlikely to use all corridors in their invasion. They will pick a set of Corridors that requires the smallest total energy to maintain, yet still makes (time) travel possible between any two destinations (for those in the know: they will use a minimum spanning tree).
  * Setting the trap may modify the energy required to keep the Corridor stable.

Heidi decided to carry out a field test and deploy one trap, placing it along the first Corridor. But she needs to know whether the Daleks are going to use this corridor after the deployment of the trap.

She gives you a map of Time Corridors (an undirected graph) with energy requirements for each Corridor.

For a Corridor c, E_{max}(c) is the largest e ≤ 10^9 such that if we changed the required amount of energy of c to e, then the Daleks may still be using c in their invasion (that is, it belongs to some minimum spanning tree). Your task is to calculate E_{max}(c_1) for the Corridor c_1 that Heidi plans to arm with a trap, which is the first edge in the graph.

Input

The first line contains integers n and m (2 ≤ n ≤ 10^5, n - 1 ≤ m ≤ 10^6), number of destinations to be invaded and the number of Time Corridors.

Each of the next m lines describes a Corridor: destinations a, b and energy e (1 ≤ a, b ≤ n, a ≠ b, 0 ≤ e ≤ 10^9).

It's guaranteed, that no pair \\{a, b\} will repeat and that the graph is connected — that is, it is possible to travel between any two destinations using zero or more Time Corridors.

Output

Output a single integer: E_{max}(c_1) for the first Corridor c_1 from the input.

Example

Input

3 3
1 2 8
2 3 3
3 1 4

Output

4

Note

After the trap is set, the new energy requirement for the first Corridor may be either smaller, larger, or equal to the old energy requiremenet.

In the example, if the energy of the first Corridor is set to 4 or less, then the Daleks may use the set of Corridors \{ \{ 1,2 \}, \{ 2,3 \} \} (in particular, if it were set to less than 4, then this would be the only set of Corridors that they would use). However, if it is larger than 4, then they will instead use the set \{ \{2,3\}, \{3,1\} \}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int INF = LONG_LONG_MAX >> 1;
const long long int NINF = LONG_LONG_MIN / 2;
const long long int N = 200005;
vector<long long int> adj[N];
long long int parent[N];
long long int sz[N];
void make_set(long long int v) {
  parent[v] = v;
  sz[v] = 1;
}
long long int find_set(long long int v) {
  if (parent[v] == v) return v;
  return parent[v] = find_set(parent[v]);
}
void union_set(long long int u, long long int v) {
  u = find_set(u);
  v = find_set(v);
  if (u != v) {
    if (sz[u] > sz[v]) swap(u, v);
    parent[u] = v;
    sz[v] += sz[u];
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<pair<pair<long long int, long long int>, long long int>> elist;
  for (long long int i = 0; i < m; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    elist.push_back({{u, v}, w});
  }
  long long int low = 0, high = 1000000001;
  while (low < high) {
    long long int mid = (low + high) >> 1;
    vector<pair<pair<long long int, long long int>, long long int>> temp =
        elist;
    temp[0].second = mid;
    pair<pair<long long int, long long int>, long long int> p = temp[0];
    sort((temp).begin(), (temp).end(),
         [](pair<pair<long long int, long long int>, long long int> aa,
            pair<pair<long long int, long long int>, long long int> bb) {
           return aa.second < bb.second;
         });
    for (long long int i = 1; i <= n; i++) make_set(i);
    long long int start = -1;
    for (long long int i = 0; i < m; i++) {
      if (temp[i].second == p.second) {
        if (start == -1) {
          start = i;
        } else if (p == temp[i]) {
          swap(temp[i], temp[start]);
          break;
        }
      }
    }
    bool used = false;
    long long int ans = 0;
    for (long long int i = 0; i < m; i++) {
      if (find_set(temp[i].first.first) != find_set(temp[i].first.second)) {
        ans += temp[i].second;
        union_set(temp[i].first.first, temp[i].first.second);
        if (temp[i] == p) used = true;
      }
    }
    if (used) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  cout << low - 1 << endl;
}

```


### Prompt

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

Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>.

The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is the number that is equal to the bitwise excluding OR of the maximum element of the sequence and the second maximum element of the sequence.

You've got a sequence of distinct positive integers s1, s2, ..., sn (n > 1). Let's denote sequence sl, sl + 1, ..., sr as s[l..r] (1 ≤ l < r ≤ n). Your task is to find the maximum number among all lucky numbers of sequences s[l..r].

Note that as all numbers in sequence s are distinct, all the given definitions make sence.

Input

The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).

Output

Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].

Examples

Input

5
5 2 1 4 3

Output

7

Input

5
9 8 3 5 7

Output

15

Note

For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2].

For the second sample you must choose s[2..5] = {8, 3, 5, 7}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, mx = 0, x;
  cin >> n;
  stack<long long> d;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    if (d.empty()) {
      d.push(x);
    } else {
      while (!d.empty() && x > d.top()) {
        if ((x ^ d.top()) > mx) {
          mx = x ^ d.top();
        }
        d.pop();
      }
      if (!d.empty() && (x ^ d.top()) > mx) {
        mx = x ^ d.top();
      }
      d.push(x);
    }
  }
  cout << mx;
}

```