### Prompt

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

You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands:

  * for n — for loop;
  * end — every command between "for n" and corresponding "end" is executed n times;
  * add — adds 1 to x.

After the execution of these commands, value of x is returned.

Every "for n" is matched with "end", thus the function is guaranteed to be valid. "for n" can be immediately followed by "end"."add" command can be outside of any for loops.

Notice that "add" commands might overflow the value of x! It means that the value of x becomes greater than 2^{32}-1 after some "add" command.

Now you run f(0) and wonder if the resulting value of x is correct or some overflow made it incorrect.

If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of x.

Input

The first line contains a single integer l (1 ≤ l ≤ 10^5) — the number of lines in the function.

Each of the next l lines contains a single command of one of three types:

  * for n (1 ≤ n ≤ 100) — for loop;
  * end — every command between "for n" and corresponding "end" is executed n times;
  * add — adds 1 to x.

Output

If overflow happened during execution of f(0), then output "OVERFLOW!!!", otherwise print the resulting value of x.

Examples

Input

9
add
for 43
end
for 10
for 15
add
end
add
end

Output

161

Input

2
for 62
end

Output

0

Input

11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end

Output

OVERFLOW!!!

Note

In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for n" can be immediately followed by "end" and that "add" can be outside of any for loops.

In the second example there are no commands "add", thus the returning value is 0.

In the third example "add" command is executed too many times, which causes x to go over 2^{32}-1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  long long f_true = 0;
  long long f_num = 1;
  long long ans = 0;
  stack<long long> v1;
  stack<long long> v2;
  for (long long z = 0; z < t; z++) {
    string a;
    cin >> a;
    if (a[0] == 'a') {
      ans++;
    } else if (a[0] == 'f') {
      long long b;
      cin >> b;
      v1.push(b);
      v2.push(ans);
    } else {
      long long x = v1.top();
      long long y = v2.top();
      long long p = ans - y;
      ans += (x - 1) * p;
      v1.pop();
      v2.pop();
    }
    if (ans >= 4294967296) {
      cout << "OVERFLOW!!!";
      return 0;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Duff is one if the heads of Mafia in her country, Andarz Gu. Andarz Gu has n cities (numbered from 1 to n) connected by m bidirectional roads (numbered by 1 to m).

Each road has a destructing time, and a color. i-th road connects cities vi and ui and its color is ci and its destructing time is ti.

Mafia wants to destruct a matching in Andarz Gu. A matching is a subset of roads such that no two roads in this subset has common endpoint. They can destruct these roads in parallel, i. e. the total destruction time is a maximum over destruction times of all selected roads.

<image>

They want two conditions to be satisfied:

  1. The remaining roads form a proper coloring.
  2. Destructing time of this matching is minimized.

The remaining roads after destructing this matching form a proper coloring if and only if no two roads of the same color have same endpoint, or, in the other words, edges of each color should form a matching.

There is no programmer in Mafia. That's why Duff asked for your help. Please help her and determine which matching to destruct in order to satisfied those conditions (or state that this is not possible).

Input

The first line of input contains two integers n and m (2 ≤ n ≤ 5 × 104 and 1 ≤ m ≤ 5 × 104), number of cities and number of roads in the country.

The next m lines contain the the roads. i - th of them contains four integers vi, ui, ci and ti (1 ≤ vi, ui ≤ n, vi ≠ ui and 1 ≤ ci, ti ≤ 109 for each 1 ≤ i ≤ m).

Output

In the first line of input, print "Yes" (without quotes) if satisfying the first condition is possible and "No" (without quotes) otherwise.

If it is possible, then you have to print two integers t and k in the second line, the minimum destructing time and the number of roads in the matching (<image>).

In the third line print k distinct integers separated by spaces, indices of the roads in the matching in any order. Roads are numbered starting from one in order of their appearance in the input.

If there's more than one solution, print any of them.

Examples

Input

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

Output

Yes
3 2
4 5

Input

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

Output

No

Note

Graph of Andarz Gu in the first sample case is as follows:

<image>

A solution would be to destruct the roads with crosses.

Graph of Andarz Gu in the second sample case is as follows:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50000;
const int MAXV = 6 * MAXN;
const int MAXE = 20 * MAXN;
struct Graph {
  struct edge {
    int to;
    edge *nxt;
  } edges[MAXE + 5], *adj[MAXV + 5], *ecnt;
  Graph() { ecnt = edges; }
  void addedge(int u, int v) {
    edge *p = (++ecnt);
    p->to = v, p->nxt = adj[u], adj[u] = p;
  }
} G1, G2;
int n, m, cnt;
struct edge {
  int u, v, c, t, id;
  edge() {}
  edge(int _u, int _v, int _c, int _t, int _id)
      : u(_u), v(_v), c(_c), t(_t), id(_id) {}
} e[MAXN + 5];
bool cmp(const edge &a, const edge &b) { return a.t < b.t; }
int dfn[MAXV + 5], low[MAXV + 5], id[MAXV + 5];
int stk[MAXV + 5], tp, dcnt, tot;
void dfs(int x) {
  dfn[x] = low[x] = (++dcnt), stk[++tp] = x;
  for (Graph::edge *p = G2.adj[x]; p; p = p->nxt) {
    if (dfn[p->to]) {
      if (!id[p->to]) low[x] = min(low[x], dfn[p->to]);
    } else
      dfs(p->to), low[x] = min(low[x], low[p->to]);
  }
  if (low[x] >= dfn[x]) {
    tot++;
    do {
      id[stk[tp]] = tot;
    } while (stk[tp--] != x);
  }
}
bool check(int x) {
  G2 = G1;
  for (int i = x + 1; i < m; i++) G2.addedge(e[i].id << 1 | 1, e[i].id << 1);
  for (int i = 0; i < cnt; i++) dfn[i] = low[i] = id[i] = 0;
  dcnt = tot = 0;
  for (int i = 0; i < cnt; i++)
    if (!dfn[i]) dfs(i);
  for (int i = 0; i < m; i++) {
    if (id[i << 1] == id[i << 1 | 1]) return false;
  }
  return true;
}
vector<int> v1[MAXV + 5];
void dfs2(int x) {
  dfn[x] = low[x] = (++dcnt), stk[++tp] = x;
  for (Graph::edge *p = G2.adj[x]; p; p = p->nxt) {
    if (dfn[p->to]) {
      if (!id[p->to]) low[x] = min(low[x], dfn[p->to]);
    } else
      dfs2(p->to), low[x] = min(low[x], low[p->to]);
  }
  if (low[x] >= dfn[x]) {
    tot++;
    do {
      v1[tot].push_back(stk[tp]);
      id[stk[tp]] = tot;
    } while (stk[tp--] != x);
  }
}
bool tag[MAXV + 5];
vector<int> ans;
void print(int x) {
  G2 = G1;
  for (int i = x + 1; i < m; i++) G2.addedge(e[i].id << 1 | 1, e[i].id << 1);
  for (int i = 0; i < cnt; i++) dfn[i] = low[i] = id[i] = 0;
  dcnt = tot = 0;
  for (int i = 0; i < cnt; i++)
    if (!dfn[i]) dfs2(i);
  for (int i = 1; i <= tot; i++) {
    for (int j = 0; j < (int)v1[i].size(); j++) {
      int x = v1[i][j];
      for (Graph::edge *p = G2.adj[x]; p; p = p->nxt)
        if (tag[id[p->to]]) tag[i] = true;
    }
    if (!tag[i]) {
      for (int j = 0; j < (int)v1[i].size(); j++)
        if (v1[i][j] < 2 * m) tag[id[v1[i][j] ^ 1]] = true;
    }
  }
  for (int i = 0; i < m; i++) {
    if (tag[id[i << 1]]) ans.push_back(i + 1);
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < (int)ans.size(); i++) printf("%d ", ans[i]);
}
map<int, int> mp;
vector<edge> vec[MAXN + 5];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, c, t;
    scanf("%d%d%d%d", &u, &v, &c, &t);
    e[i] = edge(u, v, c, t, i);
    vec[u].push_back(e[i]), vec[v].push_back(e[i]);
  }
  cnt = 2 * m;
  for (int i = 1; i <= n; i++) {
    bool flag = false;
    mp.clear();
    for (int j = 0; j < (int)vec[i].size(); j++) {
      if (mp.count(vec[i][j].c)) {
        if (flag)
          puts("No"), exit(0);
        else
          flag = true;
        int x = vec[i][j].id, y = mp[vec[i][j].c];
        G1.addedge(x << 1, y << 1 | 1), G1.addedge(y << 1, x << 1 | 1);
      } else
        mp[vec[i][j].c] = vec[i][j].id;
    }
    if (vec[i].size() >= 2) {
      int lst = (vec[i][0].id << 1);
      for (int j = 1; j < (int)vec[i].size(); j++) {
        int x = vec[i][j].id;
        G1.addedge(x << 1 | 1, lst);
        if (j + 1 == (int)vec[i].size()) break;
        G1.addedge(cnt, x << 1), G1.addedge(cnt, lst);
        lst = cnt, cnt++;
      }
      lst = (vec[i][vec[i].size() - 1].id << 1);
      for (int j = (int)vec[i].size() - 2; j >= 0; j--) {
        int x = vec[i][j].id;
        G1.addedge(x << 1 | 1, lst);
        if (j == 0) break;
        G1.addedge(cnt, x << 1), G1.addedge(cnt, lst);
        lst = cnt, cnt++;
      }
    }
  }
  sort(e, e + m, cmp);
  if (!check(m - 1))
    puts("No"), exit(0);
  else
    puts("Yes");
  int le = -1, ri = m - 1;
  while (le < ri) {
    int mid = (le + ri) >> 1;
    if (check(mid))
      ri = mid;
    else
      le = mid + 1;
  }
  printf("%d ", le == -1 ? 0 : e[le].t), print(le);
}

```


### Prompt

Create a solution in CPP for the following problem:

Little Petya likes to play very much. And most of all he likes to play the following game:

He is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of steps. Petya is not good at math, so he asks for your help.

The sequence a is called non-decreasing if a1 ≤ a2 ≤ ... ≤ aN holds, where N is the length of the sequence.

Input

The first line of the input contains single integer N (1 ≤ N ≤ 5000) — the length of the initial sequence. The following N lines contain one integer each — elements of the sequence. These numbers do not exceed 109 by absolute value.

Output

Output one integer — minimum number of steps required to achieve the goal.

Examples

Input

5
3 2 -1 2 11

Output

4

Input

5
2 1 1 1 1

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int dp[5001];
int main() {
  int n;
  cin >> n;
  long long int* a = new long long int[n];
  long long int* b = new long long int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    dp[i] = 0;
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[j] += abs(a[i] - b[j]);
      if (j > 0) dp[j] = min(dp[j - 1], dp[j]);
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}

```


### Prompt

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

Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one looks.

Heidi is presented with a screen that shows her a sequence of integers A and a positive integer p. She knows that the encryption code is a single number S, which is defined as follows:

Define the score of X to be the sum of the elements of X modulo p.

Heidi is given a sequence A that consists of N integers, and also given an integer p. She needs to split A into 2 parts such that:

  * Each part contains at least 1 element of A, and each part consists of contiguous elements of A.
  * The two parts do not overlap.
  * The total sum S of the scores of those two parts is maximized. This is the encryption code.

Output the sum S, which is the encryption code.

Input

The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 000, 2 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively.

The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000].

Output

Output the number S as described in the problem statement.

Examples

Input

4 10
3 4 7 2

Output

16

Input

10 12
16 3 24 13 9 8 7 5 12 12

Output

13

Note

In the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of <image>.

In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then, the score is <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFLL = 1001001001001001001LL;
template <typename T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <typename T>
void chmin(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T& a, T b) {
  if (a < b) a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
double fin() {
  double x;
  scanf("%lf", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int N, K, P, A[500005], S[500005], nxt[500005][101];
vector<int> pos[101];
int dp[101][10001];
int main() {
  N = in();
  K = in();
  P = in();
  int s = 0;
  for (int i = 0; i < N; ++i) {
    A[i] = in() % P;
    S[i] = ((s += A[i]) %= P);
    pos[s].push_back(i);
  }
  vector<int> nx(P, INF);
  for (int i = 0; i < P; ++i) {
    pos[i].push_back(INF);
    nx[i] = pos[i][0];
  }
  s = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < P; ++j) {
      nxt[i][(j - s + P) % P] = nx[j];
    }
    (s += A[i]) %= P;
    nx[s] = *upper_bound(pos[s].begin(), pos[s].end(), i);
  }
  for (int i = 0; i <= 100; ++i) {
    fill(dp[i], dp[i] + 10001, INF);
  }
  dp[0][0] = 0;
  for (int k = 0; k + 1 < K; ++k) {
    for (int x = 0; x < K * P; ++x) {
      if (dp[k][x] >= N) continue;
      const int f = dp[k][x];
      for (int p = 0; p < P; ++p) {
        if (nxt[f][p] == INF) continue;
        chmin(dp[k + 1][x + p], nxt[f][p] + 1);
      }
    }
  }
  int res = INF;
  for (int x = 0; x < K * P; ++x) {
    if (dp[K - 1][x] >= N) continue;
    int v = dp[K - 1][x];
    int t = (S[N - 1] - S[v - 1] + P) % P;
    chmin(res, x + t);
  }
  printf("%d\n", res);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

In this problem you will have to deal with a very special network.

The network consists of two parts: part A and part B. Each part consists of n vertices; i-th vertex of part A is denoted as Ai, and i-th vertex of part B is denoted as Bi.

For each index i (1 ≤ i < n) there is a directed edge from vertex Ai to vertex Ai + 1, and from Bi to Bi + 1, respectively. Capacities of these edges are given in the input. Also there might be several directed edges going from part A to part B (but never from B to A).

You have to calculate the [maximum flow value](https://en.wikipedia.org/wiki/Maximum_flow_problem) from A1 to Bn in this network. Capacities of edges connecting Ai to Ai + 1 might sometimes change, and you also have to maintain the maximum flow value after these changes. Apart from that, the network is fixed (there are no changes in part B, no changes of edges going from A to B, and no edge insertions or deletions).

Take a look at the example and the notes to understand the structure of the network better.

Input

The first line contains three integer numbers n, m and q (2 ≤ n, m ≤ 2·105, 0 ≤ q ≤ 2·105) — the number of vertices in each part, the number of edges going from A to B and the number of changes, respectively.

Then n - 1 lines follow, i-th line contains two integers xi and yi denoting that the edge from Ai to Ai + 1 has capacity xi and the edge from Bi to Bi + 1 has capacity yi (1 ≤ xi, yi ≤ 109).

Then m lines follow, describing the edges from A to B. Each line contains three integers x, y and z denoting an edge from Ax to By with capacity z (1 ≤ x, y ≤ n, 1 ≤ z ≤ 109). There might be multiple edges from Ax to By.

And then q lines follow, describing a sequence of changes to the network. i-th line contains two integers vi and wi, denoting that the capacity of the edge from Avi to Avi + 1 is set to wi (1 ≤ vi < n, 1 ≤ wi ≤ 109).

Output

Firstly, print the maximum flow value in the original network. Then print q integers, i-th of them must be equal to the maximum flow value after i-th change.

Example

Input

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

Output

9
14
14

Note

This is the original network in the example:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ans = 0, fh = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  return ans * fh;
}
const int maxn = 2e5 + 100;
const long long inf = 1e18;
int n, m, head[maxn], nex[maxn], v[maxn], num = 1;
long long p[maxn << 2], la[maxn << 2];
long long a[maxn], b[maxn], w[maxn];
inline void updata(int o) { p[o] = min(p[o << 1], p[o << 1 | 1]); }
inline void pushdown(int o) {
  if (!la[o]) return;
  p[o << 1] += la[o], p[o << 1 | 1] += la[o];
  la[o << 1] += la[o], la[o << 1 | 1] += la[o];
  la[o] = 0;
}
void revise(int o, int l, int r, int ql, int qr, long long qz) {
  if (ql == l && qr == r) {
    p[o] += qz, la[o] += qz;
    return;
  }
  int mid = l + r >> 1;
  pushdown(o);
  if (ql <= mid) revise(o << 1, l, mid, ql, min(qr, mid), qz);
  if (qr > mid) revise(o << 1 | 1, mid + 1, r, max(ql, mid + 1), qr, qz);
  updata(o);
}
long long query(int o, int l, int r, int ql, int qr) {
  if (ql == l && qr == r) return p[o];
  int mid = l + r >> 1;
  pushdown(o);
  long long ans = inf;
  if (ql <= mid) ans = query(o << 1, l, mid, ql, min(qr, mid));
  if (qr > mid)
    ans = min(ans, query(o << 1 | 1, mid + 1, r, max(ql, mid + 1), qr));
  return ans;
}
void build(int o, int l, int r) {
  la[o] = 0;
  if (l == r) {
    p[o] = b[l];
    return;
  }
  int mid = l + r >> 1;
  build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
  updata(o);
}
inline void add(int x, int y, long long z) {
  v[++num] = y;
  w[num] = z;
  nex[num] = head[x];
  head[x] = num;
}
int main() {
  n = read(), m = read();
  int T = read();
  for (int i = 1; i < n; i++) a[i] = read(), b[i] = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    add(x, y, read());
  }
  build(1, 0, n - 1);
  for (int x = 1; x <= n; x++) {
    for (int i = head[x]; i; i = nex[i]) revise(1, 0, n - 1, 0, v[i] - 1, w[i]);
    b[x] = a[x] + p[1];
  }
  build(1, 1, n);
  printf("%I64d\n", p[1]);
  while (T--) {
    int x = read(), y = read();
    revise(1, 1, n, x, x, y - a[x]), a[x] = y;
    printf("%I64d\n", p[1]);
  }
  return 0;
}

```


### Prompt

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

You are given a sequence of length N: A_1, A_2, ..., A_N. For each integer i between 1 and N (inclusive), answer the following question:

* Find the maximum value among the N-1 elements other than A_i in the sequence.

Constraints

* 2 \leq N \leq 200000
* 1 \leq A_i \leq 200000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

Examples

Input

3
1
4
3

Output

4
3
4

Input

2
5
5

Output

5
5

### Response

```cpp
#include <stdio.h>

int main(){
  int N,i,max=0,min=0;
  scanf("%d",&N);
  int a[N];
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
 	if(a[i]>max){
      max=a[i];
    }else if(a[i]>min){
      min=a[i];
    }
  }
  for(i=0;i<N;i++){
    if(a[i]==max){
      printf("%d\n",min);
    }else{
      printf("%d\n",max);
    }
  }
}
```


### Prompt

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

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya encountered a tree with n vertexes. Besides, the tree was weighted, i. e. each edge of the tree has weight (a positive integer). An edge is lucky if its weight is a lucky number. Note that a tree with n vertexes is an undirected connected graph that has exactly n - 1 edges.

Petya wondered how many vertex triples (i, j, k) exists that on the way from i to j, as well as on the way from i to k there must be at least one lucky edge (all three vertexes are pairwise distinct). The order of numbers in the triple matters, that is, the triple (1, 2, 3) is not equal to the triple (2, 1, 3) and is not equal to the triple (1, 3, 2).

Find how many such triples of vertexes exist.

Input

The first line contains the single integer n (1 ≤ n ≤ 105) — the number of tree vertexes. Next n - 1 lines contain three integers each: ui vi wi (1 ≤ ui, vi ≤ n, 1 ≤ wi ≤ 109) — the pair of vertexes connected by the edge and the edge's weight.

Output

On the single line print the single number — the answer.

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

Examples

Input

4
1 2 4
3 1 2
1 4 7

Output

16

Input

4
1 2 4
1 3 47
1 4 7447

Output

24

Note

The 16 triples of vertexes from the first sample are: (1, 2, 4), (1, 4, 2), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3), (3, 2, 4), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2).

In the second sample all the triples should be counted: 4·3·2 = 24.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << p.first << " " << p.second;
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long int l = v.size();
  for (long long int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
vector<long long int> adj[100000];
long long int dpsize[100000], dpdown[100000], dpup[100000];
map<pair<long long, long long>, bool> ed;
long long int n;
bool check(long long int num) {
  while (num) {
    long long int rem = num % 10;
    num /= 10;
    if (rem == 4 || rem == 7)
      continue;
    else
      return false;
  }
  return true;
}
void dfs(long long int second, long long int par) {
  dpsize[second] = 1;
  for (auto& e : adj[second]) {
    if (e != par) {
      dfs(e, second);
      dpsize[second] += dpsize[e];
      if (ed[make_pair(second, e)])
        dpdown[second] += dpsize[e];
      else
        dpdown[second] += dpdown[e];
    }
  }
}
void dfs1(long long int second, long long int par) {
  if (par != -1) {
    if (ed[make_pair(second, par)]) {
      dpup[second] = n - dpsize[second];
    } else {
      dpup[second] = dpup[par] + dpdown[par] - dpdown[second];
    }
  }
  for (auto& e : adj[second]) {
    if (e != par) {
      dfs1(e, second);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long int i = 0; i < n - 1; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    if (check(w)) {
      ed[make_pair(u, v)] = 1;
      ed[make_pair(v, u)] = 1;
    }
  }
  dfs(0, -1);
  dfs1(0, -1);
  long long int total = 0;
  for (long long int i = 0; i < n; i++) {
    long long int t = dpdown[i] + dpup[i];
    total += (t * (t - 1));
  }
  cout << total << "\n";
  return 0;
}

```


### Prompt

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

You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology).

A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of all digits of number x. Word "cascading" means that if the first summing gives us a number that consists of several digits, then we sum up all digits again, and again, until we get a one digit number.

For example, d(35047) = d((3 + 5 + 0 + 4)7) = d(157) = d((1 + 5)7) = d(67) = 67. In this sample the calculations are performed in the 7-base notation.

If a number's digital root equals b, the Martians also call this number lucky.

You have string s, which consists of n digits in the k-base notation system. Your task is to find, how many distinct substrings of the given string are lucky numbers. Leading zeroes are permitted in the numbers.

Note that substring s[i... j] of the string s = a1a2... an (1 ≤ i ≤ j ≤ n) is the string aiai + 1... aj. Two substrings s[i1... j1] and s[i2... j2] of the string s are different if either i1 ≠ i2 or j1 ≠ j2.

Input

The first line contains three integers k, b and n (2 ≤ k ≤ 109, 0 ≤ b < k, 1 ≤ n ≤ 105).

The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 ≤ ai < k) — the i-th digit of string s. The numbers in the lines are space-separated.

Output

Print a single integer — the number of substrings that are lucky numbers.

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

Examples

Input

10 5 6
3 2 0 5 6 1

Output

5

Input

7 6 4
3 5 0 4

Output

1

Input

257 0 3
0 0 256

Output

3

Note

In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int MOD;
inline int ADD(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return (int)a;
}
inline void ADDTO(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
inline void SUBTO(int &a, int b) {
  a -= b;
  if (a < 0) a += MOD;
}
inline int MUL(int a, int b) { return (int)((long long)a * b % MOD); }
int a[100010];
map<int, int> R;
int main() {
  int k, b, n;
  while (scanf("%d%d%d", &k, &b, &n) == 3) {
    R.clear();
    MOD = k - 1;
    for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
    long long zero = 0, len = 0;
    for (int i = (1); i <= (n + 1); ++i) {
      if (a[i] == 0 && i <= n)
        ++len;
      else {
        zero += 1LL * len * (len + 1) / 2;
        len = 0;
      }
    }
    long long ans = 0;
    if (b == 0)
      ans = zero;
    else {
      b %= MOD;
      int rem = 0;
      for (int i = (1); i <= (n); ++i) {
        rem = ADD(rem, a[i]);
        ++R[rem];
      }
      rem = 0;
      for (int i = (1); i <= (n); ++i) {
        int need = ADD(b, rem);
        ans += R[need];
        rem = ADD(rem, a[i]);
        --R[rem];
      }
      if (b == 0) ans -= zero;
    }
    cout << ans << endl;
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.

For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.

You have to write a program which prints the number of the child to be eliminated on every step.

Input

The first line contains two integer numbers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1).

The next line contains k integer numbers a1, a2, ..., ak (1 ≤ ai ≤ 109).

Output

Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.

Examples

Input

7 5
10 4 11 4 1

Output

4 2 5 6 1

Input

3 2
2 5

Output

3 2

Note

Let's consider first example:

  * In the first step child 4 is eliminated, child 5 becomes the leader.
  * In the second step child 2 is eliminated, child 3 becomes the leader.
  * In the third step child 5 is eliminated, child 6 becomes the leader.
  * In the fourth step child 6 is eliminated, child 7 becomes the leader.
  * In the final step child 1 is eliminated, child 3 becomes the leader.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  ios::sync_with_stdio(false);
  int a[500];
  while (cin >> n >> k) {
    int x = 0;
    int num;
    for (int i = 1; i <= n; i++) {
      a[i] = i;
    }
    for (int i = 0; i < k; i++) {
      cin >> num;
      x += num;
      x %= n;
      if (i != 0) {
        cout << " ";
      }
      cout << a[x + 1];
      n--;
      for (int j = x + 1; j <= n; j++) {
        a[j] = a[j + 1];
      }
    }
    cout << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.

A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of triangles. Any polygon model can be represented as a collection of surface information that represents a triangle.

One surface information represents three vertices side by side. However, if the same 3 points are arranged only in different arrangements, the same surface information will be represented. For example, in the tetrahedron shown below, the faces formed by connecting vertices 1, 2, and 3 can be represented as vertices 2, 3, 1, and vertices 3, 2, 1. In this way, if there are multiple pieces of the same surface information, it will be useless, so it is better to combine them into one.

<image>

Given the surface information, write a program to find the number of surface information that must be erased to eliminate duplicate surfaces.

Input

The input is given in the following format.

N
p11 p12 p13
p21 p22 p23
::
pN1 pN2 pN3

The number N (1 ≤ N ≤ 1000) of the surface information of the polygon model is given in the first line. The next N lines are given the number of vertices pij (1 ≤ pij ≤ 1000) used to create the i-th face. However, the same vertex is never used more than once for one face (pi1 ≠ pi2 and pi2 ≠ pi3 and pi1 ≠ pi3).

Output

Output the number of surface information that must be erased in order to eliminate duplicate surfaces on one line.

Examples

Input

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

Output

0

Input

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

Output

2

### Response

```cpp
#include<iostream>
#include<algorithm>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define N 1010
ll n;
unordered_set<ll> s;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
	ll p[3];
	for(int j=0;j<3;j++)cin>>p[j];
	sort(p,p+3);
	ll x=p[0]*N*N+p[1]*N+p[2];
	s.insert(x);
    }
    cout<<n-s.size()<<endl;
    return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive.

Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory.

Input

The first line contains a single integer n (1 ≤ n ≤ 18) — the number of participants of the Sith Tournament.

Each of the next n lines contains n real numbers, which form a matrix pij (0 ≤ pij ≤ 1). Each its element pij is the probability that the i-th participant defeats the j-th in a duel.

The elements on the main diagonal pii are equal to zero. For all different i, j the equality pij + pji = 1 holds. All probabilities are given with no more than six decimal places.

Jedi Ivan is the number 1 in the list of the participants.

Output

Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10 - 6.

Examples

Input

3
0.0 0.5 0.8
0.5 0.0 0.4
0.2 0.6 0.0

Output

0.680000000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double arr[18][18];
vector<vector<double>> dp;
vector<vector<bool>> done;
long long terminal, n;
double solve(long long mask, long long oponent) {
  if (terminal == (mask | (1 << oponent))) {
    return oponent == 0;
  }
  if (done[mask][oponent]) return dp[mask][oponent];
  double& res = dp[mask][oponent];
  for (long long i = 0; i < n; i++) {
    if ((mask & (1 << i)) == 0 && i != oponent) {
      res = max(res, arr[i][oponent] * solve(mask | (1 << oponent), i) +
                         arr[oponent][i] * solve(mask | (1 << i), oponent));
    }
  }
  done[mask][oponent] = true;
  return res;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  done.resize(1 << n, vector<bool>(n, false));
  dp.resize(1 << n, vector<double>(n, 0));
  terminal = (1 << n) - 1;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) cin >> arr[i][j];
  double res = 0;
  for (long long i = 0; i < n; i++) res = max(res, solve(0, i));
  cout << setprecision(12) << res << "\n";
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres).

Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body.

Input

The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi (1 ≤ ti ≤ 2; 1 ≤ pi ≤ 104), where ti is the vehicle type (1 – a kayak, 2 – a catamaran), and pi is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.

Output

In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.

Examples

Input

3 2
1 2
2 7
1 3

Output

7
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct borne {
  int p = 0, id;
  bool operator<(borne a) const { return a.p < p; }
};
int main() {
  int n, v;
  cin >> n >> v;
  int t;
  borne b1[n];
  borne b2[n];
  int i1 = 0, i2 = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &b1[i1].p);
      b1[i1].id = i + 1;
      i1++;
    } else {
      scanf("%d", &b2[i2].p);
      b2[i2].id = i + 1;
      i2++;
    }
  }
  sort(b1, b1 + i1);
  sort(b2, b2 + i2);
  int sum1[i1 + 1], sum2[i2 + 1];
  sum1[0] = 0;
  for (int i = 1; i <= i1; i++) {
    sum1[i] = sum1[i - 1] + (int)b1[i - 1].p;
  }
  sum2[0] = 0;
  for (int i = 1; i <= i2; i++) {
    sum2[i] = sum2[i - 1] + (int)b2[i - 1].p;
  }
  int m = 0;
  if (i1 > v) i1 = v;
  int max1 = 0, max2 = 0, tsum;
  for (int i = 0; i <= i1; i++) {
    int l = (v - i) / 2;
    if (l > i2) l = i2;
    tsum = sum1[i] + sum2[l];
    if (tsum > m) {
      m = tsum;
      max1 = i;
      max2 = l;
    }
  }
  cout << m << endl;
  for (int i = 0; i < max1; i++) {
    cout << b1[i].id << " ";
  }
  for (int i = 0; i < max2; i++) {
    cout << b2[i].id << " ";
  }
  return 0;
}

```


### Prompt

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

Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I know for sure that either x or y did it!'

The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at least p of n coders agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?

Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.

Input

The first line contains integers n and p (3 ≤ n ≤ 3·105; 0 ≤ p ≤ n) — the number of coders in the F company and the minimum number of agreed people.

Each of the next n lines contains two integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of coders named by the i-th coder. It is guaranteed that xi ≠ i, yi ≠ i, xi ≠ yi.

Output

Print a single integer — the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets (1, 2) and (2, 1) are considered identical.

Examples

Input

4 2
2 3
1 4
1 4
2 1

Output

6

Input

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

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[300004];
int n, p, _a, _b;
int rep[300003];
int rep_bs[300003];
int nn[300003];
int opa[300003];
int lzy = 0;
long long num = 0, nm;
long long sol = 0;
int getstuff(int ind) {
  if (opa[ind] == lzy) {
    return nn[ind];
  } else {
    return rep[ind];
  }
}
void update(int ind, int val) {
  if (opa[ind] != lzy) {
    opa[ind] = lzy;
    nn[ind] = rep[ind];
  }
  nn[ind] += val;
}
int main() {
  scanf("%d %d", &n, &p);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &_a, &_b);
    _a--;
    _b--;
    rep[_a]++;
    rep[_b]++;
    adj[_a].push_back(_b);
    adj[_b].push_back(_a);
  }
  for (int i = 0; i < n; i++) {
    rep_bs[i] = rep[i];
  }
  sort(rep_bs, rep_bs + n);
  for (int i = 0; i < n; i++) {
    lzy++;
    int l = -1, r = n;
    while (r - l > 1) {
      if (p - rep[i] <= rep_bs[(r + l) / 2]) {
        r = (r + l) / 2;
      } else {
        l = (r + l) / 2;
      }
    }
    num = n - r;
    if (rep[i] >= p - rep[i]) {
      num--;
    }
    for (int j = 0; j < adj[i].size(); j++) {
      int gg = adj[i][j];
      update(gg, -1);
      if (getstuff(gg) == p - rep[i] - 1) {
        num--;
      }
    }
    sol += num;
  }
  sol /= 2;
  printf("%I64d\n", sol);
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx.

You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other?

Constraints

* 2 \leq N \leq 200\,000
* S_i consists of lowercase English letters `a`-`z`.
* S_i \neq S_j
* 1 \leq |S_i|
* |S_1| + |S_2| + \ldots + |S_N| \leq 10^6

Input

Input is given from Standard Input in the following format.

N
S_1
S_2
\vdots
S_N

Output

Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other.

Examples

Input

3
abcxyx
cyx
abc

Output

1

Input

6
b
a
abc
c
d
ab

Output

5

### Response

```cpp
#include<iostream>
#include<string>
#define RI register int
#define CI const int&
using namespace std;
const int N=1000005;
int n,len[N],c[26]; string s[N]; long long ans;
class Trie
{
	private:
		struct Trie_Node
		{
			int ch[26],ct[26];
		}node[N]; int rt,tot=1;
		#define next(x,y) node[x].ch[y]
		#define C(x,y) node[x].ct[y]
	public:
		inline void reroot(void)
		{
			rt=1; for (RI i=0;i<26;++i) if (c[i]) ++C(rt,i);
		}
		inline void insert(const char& ch)
		{
			if (next(rt,ch-'a')) rt=next(rt,ch-'a'); else rt=next(rt,ch-'a')=++tot;
			for (RI i=0;i<26;++i) if (c[i]) ++C(rt,i);
		}
		inline int query(const string& s,CI len)
		{
			rt=1; for (RI i=len-1;i;--i)
			if (next(rt,s[i]-'a')) rt=next(rt,s[i]-'a'); else return 0;
			return C(rt,s[0]-'a');
		}
		#undef next
		#undef C
}T;
int main()
{
	RI i,j; ios::sync_with_stdio(0); for (cin>>n,i=1;i<=n;++i)
	{
		for (cin>>s[i],len[i]=s[i].size(),j=0;j<len[i];++j) ++c[s[i][j]-'a'];
		for (T.reroot(),j=len[i]-1;~j;--j) --c[s[i][j]-'a'],T.insert(s[i][j]);
	}
	for (i=1;i<=n;++i) ans+=T.query(s[i],len[i]); return cout<<ans-n,0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Constraints

* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 9900
* -2 × 107 ≤ di ≤ 2 × 107
* There are no parallel edges
* There are no self-loops

Input

An edge-weighted graph G (V, E).

|V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1

|V| is the number of vertices and |E| is the number of edges in G. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.

si and ti represent source and target vertices of i-th edge (directed) and di represents the cost of the i-th edge.

Output

If the graph contains a negative cycle (a cycle whose sum of edge costs is a negative value), print

NEGATIVE CYCLE

in a line.

Otherwise, print

D0,0 D0,1 ... D0,|V|-1
D1,0 D1,1 ... D1,|V|-1
:
D|V|-1,0 D1,1 ... D|V|-1,|V|-1

The output consists of |V| lines. For each ith line, print the cost of the shortest path from vertex i to each vertex j (j = 0, 1, ... |V|-1) respectively. If there is no path from vertex i to vertex j, print "INF". Print a space between the costs.

Examples

Input

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

Output

0 1 3 4
INF 0 2 3
INF INF 0 1
INF INF 7 0

Input

4 6
0 1 1
0 2 -5
1 2 2
1 3 4
2 3 1
3 2 7

Output

0 1 -5 -4
INF 0 2 3
INF INF 0 1
INF INF 7 0

Input

4 6
0 1 1
0 2 5
1 2 2
1 3 4
2 3 1
3 2 -7

Output

NEGATIVE CYCLE

### Response

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

static const int MAX=100;
static const long long INFTY=(1LL<<32);

int n;
long long d[MAX][MAX];

void floyd(){
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			if(d[i][k]==INFTY)continue;
			for (int j = 0; j < n; ++j) {
				if(d[k][j]==INFTY)continue;
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
}

int main(){
	int e,u,v,c;
	cin>>n>>e;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			d[i][j]=((i==j)?0:INFTY);
		}
	}
	for (int i = 0; i < e; ++i) {
		cin>>u>>v>>c;
		d[u][v]=c;
	}
	floyd();
	bool negative=false;
	for (int i = 0; i < n; ++i) {if(d[i][i]<0)negative=true;}
	if(negative){
		cout<<"NEGATIVE CYCLE"<<endl;
	}else{
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if(j)cout<<" ";
				if(d[i][j]==INFTY)cout<<"INF";
				else cout<<d[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}
```


### Prompt

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

One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..."

The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.

The bus fare equals one berland ruble in High Bertown. However, not everything is that easy — no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.

We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.

Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.

Input

The input file consists of a single line containing two space-separated numbers n and m (0 ≤ n, m ≤ 105) — the number of the grown-ups and the number of the children in the bus, correspondingly.

Output

If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly.

Otherwise, print "Impossible" (without the quotes).

Examples

Input

1 2

Output

2 2

Input

0 5

Output

Impossible

Input

2 2

Output

2 3

Note

In the first sample a grown-up rides with two children and pays two rubles.

In the second sample there are only children in the bus, so the situation is impossible.

In the third sample there are two cases:
  * Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total.
  * One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  if (n == 0 && m == 0) {
    printf("0 0");
    return 0;
  }
  if (n == 0) {
    printf("Impossible");
    return 0;
  }
  int mi, ma;
  mi = n + m - min(n, m);
  ma = n + m - 1;
  if (m == 0) ma++;
  printf("%d %d", mi, ma);
  return 0;
}

```


### Prompt

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

Tokitsukaze and CSL are playing a little game of stones.

In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?

Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.

Supposing that both players always take their best moves and never make mistakes, who will win the game?

Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.

Input

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

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_1, a_2, …, a_n ≤ 10^9), which mean the i-th pile has a_i stones.

Output

Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.

Examples

Input

1
0

Output

cslnb

Input

2
1 0

Output

cslnb

Input

2
2 2

Output

sjfnb

Input

3
2 3 1

Output

sjfnb

Note

In the first example, Tokitsukaze cannot take any stone, so CSL will win.

In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.

In the third example, Tokitsukaze will win. Here is one of the optimal ways:

  * Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
  * Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
  * Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.

In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e5 + 5;
int n, a[maxn];
int b[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int sum = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  bool poss = false;
  for (int i = 0; i < n; i++) {
    if (a[i] > 0) {
      if (--mp[a[i]] == 0) mp.erase(a[i]);
      ++mp[a[i] - 1];
      if (mp.size() == n) {
        poss = true;
      }
      if (--mp[a[i] - 1] == 0) mp.erase(a[i] - 1);
      ++mp[a[i]];
    }
  }
  if (!poss) {
    cout << "cslnb" << '\n';
    return 0;
  }
  sort(a, a + n);
  b[0] = 0;
  for (int i = 1; i < n; i++) {
    b[i] = min(a[i], b[i - 1] + 1);
  }
  for (int i = 0; i < n; i++) {
    sum += (a[i] - b[i] + 2) % 2;
    sum %= 2;
  }
  cout << (sum == 1 ? "sjfnb" : "cslnb") << '\n';
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each. Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.

Constraints

* N is an integer between 1 and 100, inclusive.

Input

Input is given from Standard Input in the following format:

N

Output

If there is a way to buy some cakes and some doughnuts for exactly N dollars, print `Yes`; otherwise, print `No`.

Examples

Input

11

Output

Yes

Input

40

Output

Yes

Input

3

Output

No

### Response

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

int main(){
	int N;
	cin >> N;
	for(int i = 0; i <= N/7; i++){
		if((N - 7 * i) % 4 == 0){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Petya and Vasya are competing with each other in a new interesting game as they always do.

At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0 ≤ K ≤ S.

In order to win, Vasya has to find a non-empty subarray in Petya's array such that the sum of all selected elements equals to either K or S - K. Otherwise Vasya loses.

You are given integers N and S. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that.

Input

The first line contains two integers N and S (1 ≤ N ≤ S ≤ 10^{6}) — the required length of the array and the required sum of its elements.

Output

If Petya can win, print "YES" (without quotes) in the first line. Then print Petya's array in the second line. The array should contain N positive integers with sum equal to S. In the third line print K. If there are many correct answers, you can print any of them.

If Petya can't win, print "NO" (without quotes).

You can print each letter in any register (lowercase or uppercase).

Examples

Input

1 4

Output

YES
4
2

Input

3 4

Output

NO

Input

3 8

Output

YES
2 1 5
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int64_t LINF = 9187201950435737471;
const int64_t nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const uint64_t ULINF = numeric_limits<uint64_t>::max();
const int MAXN = 1e7 + 15;
const int64_t MOD = 1e9 + 7;
const double EPS = 1e-9;
const int BLOCK = 500;
const double PI = acos(-1);
auto seed = 194113341;
mt19937 rnd(seed);
bool isEqual(double a, double b) { return abs(a - b) <= EPS; }
inline void IO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  for (auto& i : a) {
    out << i << " ";
  }
  return out;
}
template <typename T, typename D>
istream& operator>>(istream& in, pair<T, D>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T, typename D>
ostream& operator<<(ostream& out, const pair<T, D>& a) {
  out << a.first << " " << a.second;
  return out;
}
void solve() {
  int64_t n, s;
  cin >> n >> s;
  if (n == s) {
    cout << "NO";
    return;
  }
  if (n == 1) {
    cout << "YES\n";
    cout << s << "\n" << 1;
    return;
  }
  if (n * 2 <= s) {
    cout << "YES\n";
    for (int64_t i = 0; i < n - 1; ++i) {
      cout << "2 ";
      s -= 2;
    }
    cout << s << "\n";
    cout << "1";
    return;
  }
  cout << "NO";
}
signed main() {
  IO();
  int64_t t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Chris the Rabbit found the traces of an ancient Martian civilization. The brave astronomer managed to see through a small telescope an architecture masterpiece — "A Road to the Sun". The building stands on cubical stones of the same size. The foundation divides the entire "road" into cells, into which the cubical stones are fit tightly. Thus, to any cell of the foundation a coordinate can be assigned. To become the leader of the tribe, a Martian should build a Road to the Sun, that is to build from those cubical stones on a given foundation a stairway. The stairway should be described by the number of stones in the initial coordinate and the coordinates of the stairway's beginning and end. Each following cell in the coordinate's increasing order should contain one cubical stone more than the previous one. At that if the cell has already got stones, they do not count in this building process, the stairways were simply built on them. In other words, let us assume that a stairway is built with the initial coordinate of l, the final coordinate of r and the number of stones in the initial coordinate x. That means that x stones will be added in the cell l, x + 1 stones will be added in the cell l + 1, ..., x + r - l stones will be added in the cell r.

Chris managed to find an ancient manuscript, containing the descriptions of all the stairways. Now he wants to compare the data to be sure that he has really found "A Road to the Sun". For that he chose some road cells and counted the total number of cubical stones that has been accumulated throughout the Martian history and then asked you to count using the manuscript to what the sum should ideally total.

Input

The first line contains three space-separated integers: n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ min(n, 100)) which is the number of cells, the number of "Roads to the Sun" and the number of cells in the query correspondingly. Each of the following m roads contain three space-separated integers: ai, bi, ci (1 ≤ ai ≤ bi ≤ n, 1 ≤ ci ≤ 1000) which are the stairway's description, its beginning, end and the initial cell's height. Then follow a line, containing k different space-separated integers bi. All these numbers ranging from 1 to n are cells, the number of stones in which interests Chris.

Output

You have to print a single number on a single line which is the sum of stones in all the cells Chris is interested in.

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

Examples

Input

5 2 1
1 5 1
2 4 1
3

Output

5

Input

3 2 1
1 3 1
1 3 1
2

Output

4

Input

3 2 1
1 3 1
1 3 1
3

Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int MAXN = (int)1e5 + 10;
int n, m, k;
int put(int a, int b, int c, int pos) {
  if (pos < a || b < pos) return 0;
  return (c + pos - a);
}
int a[MAXN];
int b[MAXN];
int c[MAXN];
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < m; i++)
    scanf("%d %d %d", &a[i], &b[i], &c[i]), a[i]--, b[i]--;
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    int pos;
    scanf("%d", &pos);
    pos--;
    for (int j = 0; j < m; j++) ans += 1ll * put(a[j], b[j], c[j], pos);
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

Valera has n counters numbered from 1 to n. Some of them are connected by wires, and each of the counters has a special button.

Initially, all the counters contain number 0. When you press a button on a certain counter, the value it has increases by one. Also, the values recorded in all the counters, directly connected to it by a wire, increase by one.

Valera and Ignat started having a dispute, the dispute is as follows. Ignat thought of a sequence of n integers a1, a2, ..., an. Valera should choose some set of distinct counters and press buttons on each of them exactly once (on other counters the buttons won't be pressed). If after that there is a counter with the number i, which has value ai, then Valera loses the dispute, otherwise he wins the dispute.

Help Valera to determine on which counters he needs to press a button to win the dispute.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105), that denote the number of counters Valera has and the number of pairs of counters connected by wires.

Each of the following m lines contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), that mean that counters with numbers ui and vi are connected by a wire. It is guaranteed that each pair of connected counters occurs exactly once in the input.

The last line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 105), where ai is the value that Ignat choose for the i-th counter.

Output

If Valera can't win the dispute print in the first line -1.

Otherwise, print in the first line integer k (0 ≤ k ≤ n). In the second line print k distinct space-separated integers — the numbers of the counters, where Valera should push buttons to win the dispute, in arbitrary order.

If there exists multiple answers, you are allowed to print any of them.

Examples

Input

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

Output

2
1 2

Input

4 2
1 2
3 4
0 0 0 0

Output

3
1 3 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010];
vector<pair<int, int> > v;
queue<int> pq;
set<int> res;
int mark[100010];
int aa[100010];
int bb[100010];
void f(int x) {
  bb[x]++;
  for (int i = 0; i < adj[x].size(); i++)
    if (++bb[adj[x][i]] == aa[adj[x][i]]) pq.push(adj[x][i]);
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) cin >> aa[i];
  for (int i = 1; i <= n; i++)
    if (aa[i] == bb[i]) pq.push(i);
  while (!pq.empty()) {
    if (aa[pq.front()] == bb[pq.front()]) {
      if (res.find(pq.front()) != res.end()) {
        cout << -1 << endl;
        return 0;
      }
      res.insert(pq.front());
      f(pq.front());
    }
    pq.pop();
  }
  cout << res.size() << endl;
  set<int>::iterator it;
  string sp = "";
  for (it = res.begin(); it != res.end(); it++) cout << sp << *it, sp = " ";
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.

The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.

Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Examples

Input

3 1

Output

3
1 2
2 3
3 1

### Response

```cpp
#include <bits/stdc++.h>
const int MAX_N = int(1e3) + 7;
using namespace std;
int n, k, win[MAX_N];
bool g[MAX_N][MAX_N];
vector<pair<int, int> > sol;
bool fail() {
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (i == j || g[i][j]) continue;
      g[i][j] = g[j][i] = true;
      if (win[i] < k) {
        sol.push_back(make_pair(i + 1, j + 1));
        ++win[i];
      } else if (win[j] < k) {
        sol.push_back(make_pair(j + 1, i + 1));
        ++win[j];
      }
    }
    if (win[i] < k) return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &k);
  if (fail())
    printf("-1\n");
  else {
    printf("%d\n", (int)sol.size());
    for (auto &i : sol) printf("%d %d\n", i.first, i.second);
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

There are N zeros and M ones written on a blackboard. Starting from this state, we will repeat the following operation: select K of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those K numbers. Here, assume that N + M - 1 is divisible by K - 1.

Then, if we repeat this operation until it is no longer applicable, there will be eventually one rational number left on the blackboard.

Find the number of the different possible values taken by this rational number, modulo 10^9 + 7.

Constraints

* 1 ≦ N, M ≦ 2000
* 2 ≦ K ≦ 2000
* N + M - 1 is divisible by K - 1.

Input

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

N M K

Output

Print the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo 10^9 + 7.

Examples

Input

2 2 2

Output

5

Input

3 4 3

Output

9

Input

150 150 14

Output

937426930

### Response

```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int N=4010,P=1000000007;
void upd(LL &x,LL y){x=(x+y)%P;}
int n,m,p;
LL f[N][N],g[N][N],ans;
bool equ(int a,int b){
	if ((a==0)^(b==0)) return 0;
	a=(a-1)%(p-1)+1;
	b=(b-1)%(p-1)+1;
	return a==b;
}
int main(){
//	freopen("t.txt","r",stdin);
	scanf("%d%d%d",&n,&m,&p);
	int len=(n+m-1)/(p-1);
	f[0][0]=1;
	rep(i,1,len) rep(j,0,n){
		rep(k,0,p-1){
			if (j<k) continue;
			upd(f[i][j],f[i-1][j-k]);
		}
		rep(k,1,p-1){
			if (j<k) continue;
			upd(g[i][j],f[i-1][j-k]);
		}
		int x=j,y=i*(p-1)-j+1;
		if (equ(x,n)&&equ(y,m)&&y<=m){
			upd(ans,g[i][j]);
//			printf("ans=%lld ,from g[%d][%d]=%lld\n",ans,i,j,g[i][j]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Elections in Berland are coming. There are only two candidates — Alice and Bob.

The main Berland TV channel plans to show political debates. There are n people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views:

  * supporting none of candidates (this kind is denoted as "00"),
  * supporting Alice but not Bob (this kind is denoted as "10"),
  * supporting Bob but not Alice (this kind is denoted as "01"),
  * supporting both candidates (this kind is denoted as "11").

The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions:

  * at least half of spectators support Alice (i.e. 2 ⋅ a ≥ m, where a is number of spectators supporting Alice and m is the total number of spectators),
  * at least half of spectators support Bob (i.e. 2 ⋅ b ≥ m, where b is number of spectators supporting Bob and m is the total number of spectators),
  * the total influence of spectators is maximal possible.

Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.

Input

The first line contains integer n (1 ≤ n ≤ 4⋅10^5) — the number of people who want to take part in the debate as a spectator.

These people are described on the next n lines. Each line describes a single person and contains the string s_i and integer a_i separated by space (1 ≤ a_i ≤ 5000), where s_i denotes person's political views (possible values — "00", "10", "01", "11") and a_i — the influence of the i-th person.

Output

Print a single integer — maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.

Examples

Input

6
11 6
10 4
01 3
00 3
00 7
00 9

Output

22

Input

5
11 1
01 1
00 100
10 1
01 1

Output

103

Input

6
11 19
10 22
00 18
00 29
11 29
10 28

Output

105

Input

3
00 5000
00 5000
00 5000

Output

0

Note

In the first example 4 spectators can be invited to maximize total influence: 1, 2, 3 and 6. Their political views are: "11", "10", "01" and "00". So in total 2 out of 4 spectators support Alice and 2 out of 4 spectators support Bob. The total influence is 6+4+3+9=22.

In the second example the direction can select all the people except the 5-th person.

In the third example the direction can select people with indices: 1, 4, 5 and 6.

In the fourth example it is impossible to select any non-empty set of spectators.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<long long, string> > v(n);
  int xa = 0;
  int xb = 0;
  int num = 0;
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i].second >> v[i].first;
    if (v[i].second == "11") {
      res += v[i].first;
      ++num;
      v[i].first = 0;
    }
    if (v[i].second == "10") ++xa;
    if (v[i].second == "01") ++xb;
  }
  sort(v.begin(), v.end());
  int x = min(xa, xb);
  xa = xb = x;
  for (int i = n - 1; i >= 0; --i) {
    if (v[i].second == "10" and xa > 0) {
      --xa;
      res += v[i].first;
      v[i].first = 0;
    }
    if (v[i].second == "01" and xb > 0) {
      --xb;
      res += v[i].first;
      v[i].first = 0;
    }
  }
  sort(v.begin(), v.end());
  for (int i = n - 1; i > max(0, n - 1 - num); --i) {
    res += v[i].first;
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...

n friends live in a city which can be represented as a number line. The i-th friend lives in a house with an integer coordinate x_i. The i-th friend can come celebrate the New Year to the house with coordinate x_i-1, x_i+1 or stay at x_i. Each friend is allowed to move no more than once.

For all friends 1 ≤ x_i ≤ n holds, however, they can come to houses with coordinates 0 and n+1 (if their houses are at 1 or n, respectively).

For example, let the initial positions be x = [1, 2, 4, 4]. The final ones then can be [1, 3, 3, 4], [0, 2, 3, 3], [2, 2, 5, 5], [2, 1, 3, 5] and so on. The number of occupied houses is the number of distinct positions among the final ones.

So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?

Input

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

The second line contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ n) — the coordinates of the houses of the friends.

Output

Print two integers — the minimum and the maximum possible number of occupied houses after all moves are performed.

Examples

Input

4
1 2 4 4

Output

2 4

Input

9
1 1 8 8 8 4 4 4 4

Output

3 8

Input

7
4 3 7 1 4 3 3

Output

3 6

Note

In the first example friends can go to [2, 2, 3, 3]. So friend 1 goes to x_1+1, friend 2 stays at his house x_2, friend 3 goes to x_3-1 and friend 4 goes to x_4-1. [1, 1, 3, 3], [2, 2, 3, 3] or [2, 2, 4, 4] are also all valid options to obtain 2 occupied houses.

For the maximum number of occupied houses friends can go to [1, 2, 3, 4] or to [0, 2, 4, 5], for example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200000 + 5;
int n, x[MAX_N], dpMin[MAX_N][8], dpMax[MAX_N][8];
int dir[] = {-1, 0, 1};
pair<int, int> rec(int i, int mask) {
  if (i > n) return {0, 0};
  if (dpMax[i][mask] != -1) return {dpMin[i][mask], dpMax[i][mask]};
  int prv = x[i - 1], cur = x[i];
  int pa = (mask & 4) ? prv - 1 : -1;
  int pb = (mask & 2) ? prv : -1;
  int pc = (mask & 1) ? prv + 1 : -1;
  int cma = (cur - 1 == pa || cur - 1 == pb || cur - 1 == pc) ? 4 : 0;
  int cmb = (cur == pa || cur == pb || cur == pc) ? 2 : 0;
  int cmc = (cur + 1 == pa || cur + 1 == pb || cur + 1 == pc) ? 1 : 0;
  dpMin[i][mask] = MAX_N;
  dpMax[i][mask] = 0;
  pair<int, int> tmp = rec(i + 1, 4 | cmb | cmc);
  dpMin[i][mask] = min(dpMin[i][mask], !cma + tmp.first);
  dpMax[i][mask] = max(dpMax[i][mask], !cma + tmp.second);
  tmp = rec(i + 1, cma | 2 | cmc);
  dpMin[i][mask] = min(dpMin[i][mask], !cmb + tmp.first);
  dpMax[i][mask] = max(dpMax[i][mask], !cmb + tmp.second);
  tmp = rec(i + 1, cma | cmb | 1);
  dpMin[i][mask] = min(dpMin[i][mask], !cmc + tmp.first);
  dpMax[i][mask] = max(dpMax[i][mask], !cmc + tmp.second);
  return {dpMin[i][mask], dpMax[i][mask]};
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  sort(x + 1, x + n + 1);
  memset(dpMin, -1, sizeof(dpMin));
  memset(dpMax, -1, sizeof(dpMax));
  pair<int, int> res = rec(1, 0);
  cout << res.first << ' ' << res.second << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:

  * a1 = p, where p is some integer;
  * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is some integer.

Right now Gena has a piece of paper with sequence b, consisting of n integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.

Sequence s1, s2, ..., sk is a subsequence of sequence b1, b2, ..., bn, if there is such increasing sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n), that bij = sj. In other words, sequence s can be obtained from b by crossing out some elements.

Input

The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106).

Output

Print a single integer — the length of the required longest subsequence.

Examples

Input

2
3 5

Output

2

Input

4
10 20 10 30

Output

3

Note

In the first test the sequence actually is the suitable subsequence.

In the second test the following subsequence fits: 10, 20, 10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[4005][4005], v[4005], n, res;
vector<int> vec;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v[i] = x;
    vec.push_back(x);
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  for (int i = 0; i < n; i++) {
    int a = lower_bound(vec.begin(), vec.end(), v[i]) - vec.begin();
    dp[a][a]++;
    for (int j = 0; j < vec.size(); j++)
      if (j != a && dp[j][a] % 2 == 1) dp[j][a]++;
    for (int j = 0; j < vec.size(); j++)
      if (j != a && dp[a][j] % 2 == 0) dp[a][j]++;
  }
  for (int i = 0; i < 4005; i++)
    for (int j = 0; j < 4005; j++) res = max(res, dp[i][j]);
  cout << res << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Easy and hard versions are actually different problems, so we advise you to read both statements carefully.

You are given a weighted rooted tree, vertex 1 is the root of this tree. Also, each edge has its own cost.

A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last different from v vertex on the path from the root to the vertex v. Children of vertex v are all vertices for which v is the parent. A vertex is a leaf if it has no children. The weighted tree is such a tree that each edge of this tree has some weight.

The weight of the path is the sum of edges weights on this path. The weight of the path from the vertex to itself is 0.

You can make a sequence of zero or more moves. On each move, you select an edge and divide its weight by 2 rounding down. More formally, during one move, you choose some edge i and divide its weight by 2 rounding down (w_i := \left⌊(w_i)/(2)\right⌋).

Each edge i has an associated cost c_i which is either 1 or 2 coins. Each move with edge i costs c_i coins.

Your task is to find the minimum total cost to make the sum of weights of paths from the root to each leaf at most S. In other words, if w(i, j) is the weight of the path from the vertex i to the vertex j, then you have to make ∑_{v ∈ leaves} w(root, v) ≤ S, where leaves is the list of all leaves.

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 two integers n and S (2 ≤ n ≤ 10^5; 1 ≤ S ≤ 10^{16}) — the number of vertices in the tree and the maximum possible sum of weights you have to obtain. The next n-1 lines describe edges of the tree. The edge i is described as four integers v_i, u_i, w_i and c_i (1 ≤ v_i, u_i ≤ n; 1 ≤ w_i ≤ 10^6; 1 ≤ c_i ≤ 2), where v_i and u_i are vertices the edge i connects, w_i is the weight of this edge and c_i is the cost of this edge.

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

Output

For each test case, print the answer: the minimum total cost required to make the sum of weights paths from the root to each leaf at most S.

Example

Input

4
4 18
2 1 9 2
3 2 4 1
4 1 1 2
3 20
2 1 8 1
3 1 7 2
5 50
1 3 100 1
1 5 10 2
2 3 123 2
5 4 55 1
2 100
1 2 409 2

Output

0
0
11
6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double epsilon = 1e-7;
template <class T>
class Graph {
 public:
  int N;
  vector<vector<long long>> g;
  map<pair<long long, long long>, T> W;
  Graph(long long n) {
    N = n;
    g.assign(N, vector<long long>());
  }
  void refresh() {}
  void add(long long u, long long v, T w) {
    g[u].push_back(v);
    W[{u, v}] = w;
  }
  T getWeight(long long u, long long v) { return W[{u, v}]; }
  vector<long long>& operator[](long long u) { return g[u]; }
};
vector<long long> paths;
vector<int> par;
long long total;
set<pair<pair<long long, long long>, pair<long long, long long>>> one, two;
int r = 0;
void DFS(long long u, Graph<pair<long long, long long>>& g) {
  int cnt = 0;
  for (auto v : g[u]) {
    if (v != par[u]) {
      par[v] = u;
      DFS(v, g);
      paths[u] += paths[v];
      long long x = g.getWeight(u, v).first;
      long long c = g.getWeight(u, v).second;
      total += x * paths[v];
      r++;
      if (c == 1) {
        one.insert({{(x - x / 2) * paths[v], paths[v]}, {r, x}});
      } else {
        two.insert({{(x - x / 2) * paths[v], paths[v]}, {r, x}});
      }
      cnt++;
    }
  }
  if (cnt == 0) {
    paths[u] = 1;
  }
}
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t-- > 0) {
    long long n, s;
    cin >> n >> s;
    Graph<pair<long long, long long>> g(n);
    paths.assign(n, 0);
    par.assign(n, -1);
    total = 0ll;
    one.clear();
    two.clear();
    for (int i = 0; i < n - 1; i++) {
      long long u, v, w, c;
      cin >> u >> v >> w >> c;
      --u, --v;
      g.add(u, v, {w, c}), g.add(v, u, {w, c});
    }
    DFS(0, g);
    long long ans = 0ll;
    while (total > s) {
      if (!one.empty() and !two.empty()) {
        auto res1 = *one.rbegin();
        one.erase(res1);
        auto res2 = res1;
        long long x = res1.second.second / 2;
        res2.first.first = (x - x / 2) * res2.first.second;
        res2.second.second = x;
        one.insert(res2);
        auto res3 = *one.rbegin();
        auto res4 = *two.rbegin();
        if (total - res1.first.first <= s) {
          ans += 1;
          break;
        } else if (res4.first.first >= res1.first.first + res3.first.first) {
          auto res5 = res4;
          total -= res4.first.first;
          long long x = res4.second.second / 2;
          res5.first.first = (x - x / 2) * res5.first.second;
          res5.second.second = x;
          two.erase(res4);
          two.insert(res5);
          one.erase(res2);
          one.insert(res1);
          ans += 2;
        } else {
          total -= res1.first.first;
          ans += 1;
        }
      } else if (!one.empty()) {
        auto res1 = *one.rbegin();
        one.erase(res1);
        auto res2 = res1;
        long long x = res1.second.second / 2;
        res2.first.first = (x - x / 2) * res2.first.second;
        res2.second.second = x;
        one.insert(res2);
        total -= res1.first.first;
        ans += 1;
      } else {
        auto res1 = *two.rbegin();
        two.erase(res1);
        auto res2 = res1;
        long long x = res1.second.second / 2;
        res2.first.first = (x - x / 2) * res2.first.second;
        res2.second.second = x;
        two.insert(res2);
        total -= res1.first.first;
        ans += 2;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You're given an array a of length 2n. Is it possible to reorder it in such way so that the sum of the first n elements isn't equal to the sum of the last n elements?

Input

The first line contains an integer n (1 ≤ n ≤ 1000), where 2n is the number of elements in the array a.

The second line contains 2n space-separated integers a_1, a_2, …, a_{2n} (1 ≤ a_i ≤ 10^6) — the elements of the array a.

Output

If there's no solution, print "-1" (without quotes). Otherwise, print a single line containing 2n space-separated integers. They must form a reordering of a. You are allowed to not change the order.

Examples

Input

3
1 2 2 1 3 1

Output

2 1 3 1 1 2

Input

1
1 1

Output

-1

Note

In the first example, the first n elements have sum 2+1+3=6 while the last n elements have sum 1+1+2=4. The sums aren't equal.

In the second example, there's no solution.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  set<long long int> second;
  long long int a[2 * n];
  for (long long int(i) = 0; (i) < (2 * n); (i)++) {
    long long int x;
    cin >> x;
    a[i] = x;
    second.insert(x);
  }
  if ((long long int)second.size() != 1) {
    sort(a, a + 2 * n);
    for (long long int(i) = 0; (i) < (2 * n); (i)++) cout << a[i] << " ";
  } else
    cout << -1;
  return 0;
}

```


### Prompt

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

Your task is to calculate the number of arrays such that:

  * each array contains n elements;
  * each element is an integer from 1 to m;
  * for each array, there is exactly one pair of equal elements;
  * for each array a, there exists an index i such that the array is strictly ascending before the i-th element and strictly descending after it (formally, it means that a_j < a_{j + 1}, if j < i, and a_j > a_{j + 1}, if j ≥ i).

Input

The first line contains two integers n and m (2 ≤ n ≤ m ≤ 2 ⋅ 10^5).

Output

Print one integer — the number of arrays that meet all of the aforementioned conditions, taken modulo 998244353.

Examples

Input

3 4

Output

6

Input

3 5

Output

10

Input

42 1337

Output

806066790

Input

100000 200000

Output

707899035

Note

The arrays in the first example are:

  * [1, 2, 1];
  * [1, 3, 1];
  * [1, 4, 1];
  * [2, 3, 2];
  * [2, 4, 2];
  * [3, 4, 3].

### Response

```cpp
#include <bits/stdc++.h>
const long long N = 2e5 + 10, MOD = 998244353;
using namespace std;
long long n, m, t, factorial[N], inv[N];
long long binpow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
void fact() {
  factorial[0] = 1;
  for (long long i = 1; i < N; i++) factorial[i] = factorial[i - 1] * i % MOD;
}
void mul() {
  inv[1] = 1;
  for (int i = 2; i < N; ++i) inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
  for (int i = 2; i < N; ++i) inv[i] = inv[i] * inv[i - 1] % MOD;
}
long long nCr(long long n, long long r) {
  if (r > n) return 0;
  if (!r) return 1;
  return factorial[n] * (inv[r] * inv[n - r] % MOD) % MOD;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fact();
  mul();
  cin >> n >> m;
  cout << (nCr(m, n - 1) % MOD * (n - 2) % MOD) * binpow(2, n - 3) % MOD;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a.

For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its beauty is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.)

Find the maximum possible value for him.

Constraints

* 2 \leq N \leq 1000
* 1 \leq a_i \leq 10^9
* 1 \leq K \leq N(N+1)/2
* All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the answer.

Examples

Input

4 2
2 5 2 5

Output

12

Input

8 4
9 1 8 2 7 5 6 4

Output

32

### Response

```cpp
#include<cstdio>
using namespace std;
int main(){
    int n,k,cnt=0;
    long a[1000],sum[1001],ans=0,t[41],b;
    t[0]=1;
    for(int i=1;i<=40;i++){
        t[i]=t[i-1]*2;
    }
    sum[0]=0;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%ld",&a[i]);
        sum[i+1]=sum[i]+a[i];
    }
    for(int i=40;i>=0;i--){
        cnt=0;
        for(int j=0;j<n;j++){
            for(int l=j+1;l<=n;l++){
                b=(ans+t[i])&(sum[l]-sum[j]);
                if(b==ans+t[i]){
                    cnt++;
                }
            }
        }
        if(cnt>=k){
            ans+=t[i];
        }
    }
    printf("%ld\n",ans);
}
```


### Prompt

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

There are n positive integers written on the blackboard. Also, a positive number k ≥ 2 is chosen, and none of the numbers on the blackboard are divisible by k. In one operation, you can choose any two integers x and y, erase them and write one extra number f(x + y), where f(x) is equal to x if x is not divisible by k, otherwise f(x) = f(x / k).

In the end, there will be a single number of the blackboard. Is it possible to make the final number equal to 1? If so, restore any sequence of operations to do so.

Input

The first line contains two integers n and k — the initial number of integers on the blackboard, and the chosen number (2 ≤ n ≤ 16, 2 ≤ k ≤ 2000).

The second line contains n positive integers a_1, …, a_n initially written on the blackboard. It is guaranteed that none of the numbers a_i is divisible by k, and the sum of all a_i does not exceed 2000.

Output

If it is impossible to obtain 1 as the final number, print "NO" in the only line.

Otherwise, print "YES" on the first line, followed by n - 1 lines describing operations. The i-th of these lines has to contain two integers x_i and y_i to be erased and replaced with f(x_i + y_i) on the i-th operation. If there are several suitable ways, output any of them.

Examples

Input

2 2
1 1

Output

YES
1 1

Input

4 3
7 8 13 23

Output

YES
23 13
8 7
5 4

Input

3 4
1 2 3

Output

NO

Note

In the second sample case:

  * f(8 + 7) = f(15) = f(5) = 5;
  * f(23 + 13) = f(36) = f(12) = f(4) = 4;
  * f(5 + 4) = f(9) = f(3) = f(1) = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debug_out(T t) {
  cerr << t;
}
template <typename A, typename B>
void debug_out(pair<A, B> u) {
  cerr << "(" << u.first << " " << u.second << ")";
}
template <typename T>
void debug_out(vector<T> t) {
  int sz = t.size();
  for (int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if (i != sz - 1) cerr << ", ";
  }
}
template <typename T>
void debug_out(vector<vector<T>> t) {
  int sz = t.size();
  for (int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if (i != sz - 1) cerr << endl;
  }
}
int n, k;
int main() {
  cin >> n >> k;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int total = sum * sum;
  vector<int> p;
  p.push_back(1);
  while (p.back() <= total / k) p.push_back(p.back() * k);
  vector<vector<int>> dp(n + 1, vector<int>(total + 1, -1));
  dp[0][0] = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int s = total; s > -1; s--) {
      for (int j = 0; j < (int)p.size(); j++) {
        long long val = 1LL * s - 1LL * a[i - 1] * p[j];
        if (val < 0) break;
        if (dp[i - 1][val] != -1) {
          dp[i][s] = j;
          break;
        }
      }
    }
  }
  int ps = -1;
  for (int i = 0; i < (int)p.size(); i++) {
    if (dp[n][p[i]] != -1) {
      ps = i;
      break;
    }
  }
  if (ps == -1) {
    cout << "NO";
    return 0;
  }
  cout << "YES\n";
  int c = p[ps];
  vector<int> cur;
  for (int i = n; i > 0; i--) {
    cur.push_back(ps - dp[i][c]);
    c -= a[i - 1] * p[dp[i][c]];
  }
  reverse(cur.begin(), cur.end());
  vector<vector<int>> pref(ps + 1);
  for (int i = 0; i < n; i++) pref[cur[i]].push_back(a[i]);
  for (int i = ps; i > 0; i--) {
    while (!pref[i].empty()) {
      int sz = pref[i].size();
      assert(sz > 1);
      int s = pref[i][sz - 1] + pref[i][sz - 2];
      cout << pref[i][sz - 1] << " " << pref[i][sz - 2] << endl;
      pref[i].pop_back();
      pref[i].pop_back();
      int cnt = 0;
      while (s % k == 0) {
        s /= k;
        cnt++;
      }
      pref[i - cnt].push_back(s);
    }
  }
  assert(pref[0].size() == 1 && pref[0][0] == 1);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.

Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j. As Vasya is fond of different useless statistic he asks you to compute the sum of all values ρi, j among all pairs 1 ≤ i < j ≤ n.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of stations.

The second line contains n - 1 integer ai (i + 1 ≤ ai ≤ n), the i-th of them means that at the i-th station one may buy tickets to each station from i + 1 to ai inclusive.

Output

Print the sum of ρi, j among all pairs of 1 ≤ i < j ≤ n.

Examples

Input

4
4 4 4

Output

6

Input

5
2 3 5 5

Output

17

Note

In the first sample it's possible to get from any station to any other (with greater index) using only one ticket. The total number of pairs is 6, so the answer is also 6.

Consider the second sample:

  * ρ1, 2 = 1
  * ρ1, 3 = 2
  * ρ1, 4 = 3
  * ρ1, 5 = 3
  * ρ2, 3 = 1
  * ρ2, 4 = 2
  * ρ2, 5 = 2
  * ρ3, 4 = 1
  * ρ3, 5 = 1
  * ρ4, 5 = 1

Thus the answer equals 1 + 2 + 3 + 3 + 1 + 2 + 2 + 1 + 1 + 1 = 17.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
const long long MAXN = 1e5 + 5;
const long long LOG = 20;
long long lg[MAXN];
pair<long long, long long> t[MAXN][LOG];
long long n;
vector<long long> mas;
void build() {
  long long i, j;
  for (i = 0; i < n; i++) t[i][0] = {mas[i], i};
  lg[1] = 0;
  for (i = 2; i < n; i++) lg[i] = lg[i / 2] + 1;
  for (j = 0; j < LOG; j++)
    for (i = 0; i < n; i++) {
      if (i + (1 << (j + 1)) > n) break;
      if (t[i][j].first >= t[i + (1 << j)][j].first)
        t[i][j + 1] = t[i][j];
      else
        t[i][j + 1] = t[i + (1 << j)][j];
    }
}
pair<long long, long long> get(long long l, long long r) {
  long long j = lg[r - l + 1];
  if (t[l][j].first >= t[r - (1 << j) + 1][j].first) return t[l][j];
  return t[r - (1 << j) + 1][j];
}
signed main() {
  long long i;
  cin >> n;
  mas.resize(n);
  for (i = 0; i < n - 1; i++) {
    cin >> mas[i];
    mas[i]--;
  }
  mas[i] = n - 1;
  build();
  vector<long long> dp(n);
  dp[n - 1] = 0;
  long long val, num, sum = 0;
  for (i = n - 2; i >= 0; i--) {
    tie(val, num) = get(i + 1, mas[i]);
    dp[i] = num - i + dp[num] + n - 1 - mas[i];
    sum += dp[i];
  }
  cout << sum << '\n';
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya encountered a tree with n vertexes. Besides, the tree was weighted, i. e. each edge of the tree has weight (a positive integer). An edge is lucky if its weight is a lucky number. Note that a tree with n vertexes is an undirected connected graph that has exactly n - 1 edges.

Petya wondered how many vertex triples (i, j, k) exists that on the way from i to j, as well as on the way from i to k there must be at least one lucky edge (all three vertexes are pairwise distinct). The order of numbers in the triple matters, that is, the triple (1, 2, 3) is not equal to the triple (2, 1, 3) and is not equal to the triple (1, 3, 2).

Find how many such triples of vertexes exist.

Input

The first line contains the single integer n (1 ≤ n ≤ 105) — the number of tree vertexes. Next n - 1 lines contain three integers each: ui vi wi (1 ≤ ui, vi ≤ n, 1 ≤ wi ≤ 109) — the pair of vertexes connected by the edge and the edge's weight.

Output

On the single line print the single number — the answer.

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

Examples

Input

4
1 2 4
3 1 2
1 4 7

Output

16

Input

4
1 2 4
1 3 47
1 4 7447

Output

24

Note

The 16 triples of vertexes from the first sample are: (1, 2, 4), (1, 4, 2), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3), (3, 2, 4), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2).

In the second sample all the triples should be counted: 4·3·2 = 24.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int fa[1000000], sum[1000000];
int findfa(int a) {
  if (fa[a] == a) return a;
  int now = a, temp;
  while (fa[now] != now) {
    now = fa[now];
  }
  while (a != now) {
    temp = fa[a];
    fa[a] = now;
    a = temp;
  }
  return a;
}
void merge(int a, int b) {
  a = findfa(a);
  b = findfa(b);
  if (a == b) return;
  if (sum[a] > sum[b]) swap(a, b);
  sum[b] += sum[a];
  fa[a] = b;
}
int i, j, n, m;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    fa[i] = i;
    sum[i] = 1;
  }
  int a, b, c;
  for (i = 1; i < n; i++) {
    scanf("%d %d %d", &a, &b, &c);
    while (c) {
      if ((c % 10 != 4) && (c % 10 != 7)) {
        break;
      }
      c /= 10;
    }
    if (c) {
      merge(a, b);
    }
  }
  long long int ans = 0, ta, tb;
  for (i = 1; i <= n; i++) {
    if (findfa(i) == i) {
      ta = n - sum[i];
      ta *= ta - 1;
      ta *= sum[i];
      ans += ta;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}

```