### Prompt

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

Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests.

Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load.

Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable.

For example, if the load is described with one of the arrays [1, 2, 8, 4, 3], [1, 3, 5] or [10], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays [1, 2, 2, 1], [2, 1, 2] or [10, 10], then such load does not satisfy Polycarp.

Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from 1 to n.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.

Output

Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.

Examples

Input

5
1 4 3 2 5

Output

6

Input

5
1 2 2 2 1

Output

1

Input

7
10 20 40 50 70 90 30

Output

0

Note

In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests.

In the second example it is enough to make one additional request in the third minute, so the answer is 1.

In the third example the load already satisfies all conditions described in the statement, so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 100000;
long long a[kMaxN];
long long pre[kMaxN], suf[kMaxN];
long long opt_prefix[kMaxN], opt_suffix[kMaxN];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  pre[0] = a[0];
  for (int i = 1; i < n; ++i) {
    opt_prefix[i] = opt_prefix[i - 1];
    if (a[i] <= pre[i - 1]) {
      opt_prefix[i] += pre[i - 1] - a[i] + 1;
      pre[i] = 1 + pre[i - 1];
    } else {
      pre[i] = a[i];
    }
  }
  suf[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    opt_suffix[i] = opt_suffix[i + 1];
    if (a[i] <= suf[i + 1]) {
      opt_suffix[i] += suf[i + 1] - a[i] + 1;
      suf[i] = 1 + suf[i + 1];
    } else {
      suf[i] = a[i];
    }
  }
  long long answer = min(opt_prefix[n - 1], opt_suffix[0]);
  for (int i = 1; i < n - 1; ++i) {
    long long opt = opt_prefix[i - 1] + opt_suffix[i + 1];
    long long el = max(pre[i - 1], suf[i + 1]) + 1;
    if (a[i] < el) {
      opt += el - a[i];
    }
    if (opt < answer) {
      answer = opt;
    }
  }
  cout << answer << endl;
}

```


### Prompt

Generate a CPP solution to the following problem:

Rock... Paper!

After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.

A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x1, x2, ..., xn and y1, y2, ..., yn respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.

Then they count the number of ordered pairs (i, j) (1 ≤ i, j ≤ n) such that the value xi xor yj equals to one of the 2n integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.

Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.

Input

The first line of input contains a positive integer n (1 ≤ n ≤ 2 000) — the length of both sequences.

The second line contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 2·106) — the integers finally chosen by Koyomi.

The third line contains n space-separated integers y1, y2, ..., yn (1 ≤ yi ≤ 2·106) — the integers finally chosen by Karen.

Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i, j) (1 ≤ i, j ≤ n) exists such that one of the following holds: xi = yj; i ≠ j and xi = xj; i ≠ j and yi = yj.

Output

Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.

Examples

Input

3
1 2 3
4 5 6

Output

Karen

Input

5
2 4 6 8 10
9 7 5 3 1

Output

Karen

Note

In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.

In the second example, there are 16 such pairs, and Karen wins again.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() { cout << "Karen"; }

```


### Prompt

Create a solution in cpp for the following problem:

Just to remind, girls in Arpa's land are really nice.

Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 ≤ i < k, and a1 = x and ak = y.

<image>

Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.

Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.

Input

The first line contains integers n, m and w (1 ≤ n ≤ 1000, <image>, 1 ≤ w ≤ 1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.

The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 1000) — the weights of the Hoses.

The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106) — the beauties of the Hoses.

The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 ≤ xi, yi ≤ n, xi ≠ yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.

Output

Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.

Examples

Input

3 1 5
3 2 5
2 4 2
1 2

Output

6

Input

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

Output

7

Note

In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.

In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const long long mod = 1000000007;
vector<long long> w, b, u;
vector<vector<long long> > g;
vector<vector<long long> > comps;
void dfs(int v, int ind) {
  comps[ind].push_back(v);
  for (int i = 0; i < g[v].size(); i++) {
    if (u[g[v][i]] == 0) {
      u[g[v][i]] = 1;
      dfs(g[v][i], ind);
    }
  }
  return;
}
void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  w.resize(n), b.resize(n), u.resize(n, 0);
  g.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < m; i++) {
    int f, t;
    cin >> f >> t;
    t--;
    f--;
    g[f].push_back(t);
    g[t].push_back(f);
  }
  for (int i = 0; i < n; i++) {
    if (u[i] == 0) {
      comps.push_back(vector<long long>());
      u[i] = 1;
      dfs(i, comps.size() - 1);
    }
  }
  vector<vector<long long> > dp(comps.size() + 1, vector<long long>(q + 1, 0));
  for (int i = 0; i < comps.size(); i++) {
    for (int j = 0; j < q + 1; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      long long allb = 0, allw = 0;
      for (int z = 0; z < comps[i].size(); z++) {
        allb += b[comps[i][z]];
        allw += w[comps[i][z]];
        if (j + w[comps[i][z]] <= q) {
          dp[i + 1][j + w[comps[i][z]]] =
              max(dp[i + 1][j + w[comps[i][z]]], dp[i][j] + b[comps[i][z]]);
        }
      }
      if (j + allw <= q) {
        dp[i + 1][j + allw] = max(dp[i + 1][j + allw], dp[i][j] + allb);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= q; i++) ans = max(ans, dp[comps.size()][i]);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}

```


### Prompt

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

Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).

Constraints

* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* 0 ≤ wi ≤ 10,000
* G has arborescence(s) with the root r

Input

|V| |E| r
s0 t0 w0
s1 t1 w1
:
s|E|-1 t|E|-1 w|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence.

si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.

Output

Print the sum of the weights the Minimum-Cost Arborescence.

Examples

Input

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

Output

6

Input

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

Output

11

### Response

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

using namespace std;

const int inf = 1e9+10;

struct Edge {
    int from,to,weight;

    Edge(int f,int t,int w)
    {
        from=f;to=t;weight=w;
    }

    bool operator < (const Edge &x) const
    {
        return weight < x.weight;
    }
};

int edmonds(vector<Edge> &G, int V, int R)
{
    vector<Edge> minInEdge(V,Edge(-1, -1, inf));
    for (int i=0;i<G.size();i++)
    {
        const Edge &e = G[i];
        minInEdge[e.to] = min(minInEdge[e.to], e);
    }
    minInEdge[R] = Edge(-1, R, 0);

    vector<int> group(V, 0);
    vector<bool> visited(V, false), isCycleGroup(V, false);
    int cnt = 0;
    for (int i = 0; i < V; i++)
    {
        if (visited[i])
            continue;

        int node = i;
        vector<int> path;
        while (node != -1 && !visited[node])
        {
            visited[node] = true;
            path.push_back(node);
            node = minInEdge[node].from;
        }

        bool isCycle = false;
        for (int i=0;i<path.size();i++)
        {
            int v = path[i];
            group[v] = cnt;
            if (v == node)
                isCycleGroup[cnt] = isCycle = true;
            if (!isCycle)
                cnt++;
        }

        if (isCycle)
            cnt++;
    }

    if (cnt == V)
    {
        int answer = 0;
        for(int i=0;i<minInEdge.size();i++)
        {
            Edge &e = minInEdge[i];
            answer += e.weight;
        }

        return answer;
    }

    int answer = 0;
    for (int i=0;i<minInEdge.size();i++)
    {
        Edge &e = minInEdge[i];
        if (isCycleGroup[group[e.to]])
            answer += e.weight;
    }

    vector<Edge> n_G;
    for (int i=0;i<G.size();i++)
    {
        const Edge &e = G[i];
        int u = group[e.from], v = group[e.to], w = e.weight;
        if (u == v)
            continue;
        else
            n_G.push_back(Edge(u, v, w - (isCycleGroup[v] ? minInEdge[e.to].weight : 0)));
    }

    return answer + edmonds(n_G, cnt, group[R]);
}

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

    int v,e,r;
    cin>>v>>e>>r;

    vector<Edge> G;
    for(int i=0;i<e;i++)
    {
        int s,t,w;
        cin>>s>>t>>w;
        G.push_back(Edge(s,t,w));
    }

    cout<<edmonds(G,v,r)<<endl;

    return 0;
}

```


### Prompt

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

Eugene likes working with arrays. And today he needs your help in solving one challenging task.

An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Let's call a nonempty array good if for every nonempty subarray of this array, sum of the elements of this subarray is nonzero. For example, array [-1, 2, -3] is good, as all arrays [-1], [-1, 2], [-1, 2, -3], [2], [2, -3], [-3] have nonzero sums of elements. However, array [-1, 2, -1, -3] isn't good, as his subarray [-1, 2, -1] has sum of elements equal to 0.

Help Eugene to calculate the number of nonempty good subarrays of a given array a.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 2 × 10^5) — the length of array a.

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

Output

Output a single integer — the number of good subarrays of a.

Examples

Input

3
1 2 -3

Output

5

Input

3
41 -41 41

Output

3

Note

In the first sample, the following subarrays are good: [1], [1, 2], [2], [2, -3], [-3]. However, the subarray [1, 2, -3] isn't good, as its subarray [1, 2, -3] has sum of elements equal to 0.

In the second sample, three subarrays of size 1 are the only good subarrays. At the same time, the subarray [41, -41, 41] isn't good, as its subarray [41, -41] has sum of elements equal to 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  set<signed long long> s;
  signed long long ans = 0;
  vector<signed long long> sum(n + 1);
  for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
  for (int i = 0, j = 0; i <= n; ++i) {
    while (s.count(sum[i])) {
      s.erase(sum[j]);
      ++j;
    }
    s.insert(sum[i]);
    ans += i - j;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

The prehistoric caves of El Toll are located in Moià (Barcelona). You have heard that there is a treasure hidden in one of n possible spots in the caves. You assume that each of the spots has probability 1 / n to contain a treasure.

You cannot get into the caves yourself, so you have constructed a robot that can search the caves for treasure. Each day you can instruct the robot to visit exactly k distinct spots in the caves. If none of these spots contain treasure, then the robot will obviously return with empty hands. However, the caves are dark, and the robot may miss the treasure even when visiting the right spot. Formally, if one of the visited spots does contain a treasure, the robot will obtain it with probability 1 / 2, otherwise it will return empty. Each time the robot searches the spot with the treasure, his success probability is independent of all previous tries (that is, the probability to miss the treasure after searching the right spot x times is 1 / 2x).

What is the expected number of days it will take to obtain the treasure if you choose optimal scheduling for the robot? Output the answer as a rational number modulo 109 + 7. Formally, let the answer be an irreducible fraction P / Q, then you have to output <image>. It is guaranteed that Q is not divisible by 109 + 7.

Input

The first line contains the number of test cases T (1 ≤ T ≤ 1000).

Each of the next T lines contains two integers n and k (1 ≤ k ≤ n ≤ 5·108).

Output

For each test case output the answer in a separate line.

Example

Input

3
1 1
2 1
3 2

Output

2
500000007
777777786

Note

In the first case the robot will repeatedly search in the only spot. The expected number of days in this case is 2. Note that in spite of the fact that we know the treasure spot from the start, the robot still has to search there until he succesfully recovers the treasure.

In the second case the answer can be shown to be equal to 7 / 2 if we search the two spots alternatively. In the third case the answer is 25 / 9.

### Response

```cpp
#include <bits/stdc++.h>
long long n, k, p, mo, gc, t, c, answ;
int ttt;
long long gcd(long long x, long long y) {
  if (y == 0)
    return (x);
  else
    return (gcd(y, x % y));
}
long long mi(long long aa, long long bb) {
  long long s = 1;
  while (bb != 0) {
    if ((bb % 2) == 1) s = (s * aa) % mo;
    aa = (aa * aa) % mo;
    bb = bb / 2;
  }
  return (s);
}
void ask(long long ni, long long ki, long long x, long long y, long long xi,
         long long yi, long long sz, long long siz) {
  if (ki == 1) {
    long long li, ri, ai;
    li = mi(x, ni - 1);
    if ((x + mo) % mo == 1)
      ri = (ni - 1) * y % mo;
    else
      ri = (li - 1) * mi(x - 1, mo - 2) % mo * y % mo;
    ai = (xi * ri + yi) % mo * mi((1 - li * xi) % mo, mo - 2) % mo;
    if ((x + mo) % mo == 1) {
      answ = (answ + ni * ai % mo * siz) % mo;
      answ = (answ + ((ni - 1) * ni / 2) % mo * y % mo * siz) % mo;
    } else {
      answ = (answ + (li * x - 1) % mo * mi(x - 1, mo - 2) % mo *
                         (ai + (y * mi(x - 1, mo - 2)) % mo) % mo * siz) %
             mo;
      answ = (answ - ni * mi(x - 1, mo - 2) % mo * y % mo * siz) % mo;
    }
    answ = (answ - ai * (siz - sz)) % mo;
  } else {
    long long li, ri, mm = ni / ki, m = ni % ki, yy, sz1, sz2, aa, bb;
    li = mi(x, mm - 1);
    if ((x + mo) % mo == 1) {
      answ = (answ + ((mm + 1) * mm / 2) % mo * m % mo * y % mo * siz) % mo;
      answ =
          (answ + (mm * (mm - 1) / 2) % mo * (ki - m) % mo * y % mo * siz) % mo;
    } else {
      answ = (answ + (li * x - 1) % mo * mi(x - 1, 2 * mo - 4) % mo * (ki - m) %
                         mo * y % mo * siz) %
             mo;
      answ = (answ + ((li * x % mo) * x - 1) % mo * mi(x - 1, 2 * mo - 4) % mo *
                         m % mo * y % mo * siz) %
             mo;
      answ = (answ - ni * mi(x - 1, mo - 2) % mo * y % mo * siz) % mo;
    }
    if (x == 1) {
      sz1 = sz + mm * siz;
      sz2 = sz + (mm - 1) * siz;
    } else {
      sz1 = (sz + ((li * x % mo) * x - 1) % mo * siz % mo * mi(x - 1, mo - 2) -
             siz) %
            mo;
      sz2 = (sz + (li * x - 1) % mo * siz % mo * mi(x - 1, mo - 2) - siz) % mo;
    }
    if ((x + mo) % mo == 1) {
      ri = mm * y % mo;
      yy = (mm - 1) * y % mo;
    } else {
      ri = (li * x - 1) % mo * mi(x - 1, mo - 2) % mo * y % mo;
      ;
      yy = (li - 1) * mi(x - 1, mo - 2) % mo * y % mo;
    }
    aa = (li * xi % mo * x) % mo;
    bb = (li * xi) % mo;
    aa = mi(aa, mo - 2);
    bb = mi(bb, mo - 2);
    ask(ki, m, bb, (0 - yy * xi - yi) % mo * bb % mo, aa,
        (0 - ri * xi - yi) % mo * aa % mo, sz1, sz2);
  }
}
int main() {
  scanf("%d", &ttt);
  mo = 1000000007;
  p = (mo + 1) / 2;
  for (int iii = 1; iii <= ttt; iii++) {
    scanf("%I64d%I64d", &n, &k);
    gc = gcd(n, k);
    n = n / gc;
    k = k / gc;
    answ = 0;
    if (p != 1)
      ask(n, k, 1, 1, 1 - p, 1, 1, 1);
    else {
      t = n / k;
      answ = (t * (t + 1) / 2) % mo;
      answ = answ * k % mo;
      c = n % k;
      answ = (answ + c * (t + 1)) % mo;
    }
    answ = answ % mo;
    answ = (answ * mi(n, mo - 2)) % mo;
    answ = (answ + mo) % mo;
    printf("%I64d\n", answ);
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

There are n children, who study at the school №41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.

Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.

You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.

For instance, for the configuration shown below and k = 2 children can do the following steps:

<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration:  <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job.  <image>

It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".

Input

The first line of input contains two integers n and k (2 ≤ n ≤ 3000, 1 ≤ k ≤ 3000000) — the number of children and required number of moves.

The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.

Output

If there is no solution, print a single line with number -1.

Otherwise, output k lines. Each line has to start with a number n_i (1≤ n_i ≤ n/2) — the number of pairs of children, who turn at this move. After that print n_i distinct integers — the numbers of the children who will turn left during this move.

After performing all "headturns", there can't be a pair of two neighboring children looking at each other.

If there are many solutions, print any of them.

Examples

Input

2 1
RL

Output

1 1

Input

2 1
LR

Output

-1

Input

4 2
RLRL

Output

2 1 3
1 2

Note

The first sample contains a pair of children who look at each other. After one move, they can finish the process.

In the second sample, children can't make any move. As a result, they can't end in k>0 moves.

The third configuration is described in the statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed;
  cout.precision(10);
  int n, k;
  string s;
  cin >> n >> k >> s;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = (s[i] == 'R');
  }
  vector<int> cur;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] and !a[i + 1]) {
      cur.push_back(i);
    }
  }
  int total_moves = 0;
  vector<vector<int>> moves;
  while (!cur.empty()) {
    moves.push_back(cur);
    total_moves += cur.size();
    cur.clear();
    for (int x : moves.back()) {
      swap(a[x], a[x + 1]);
      if (x < n - 2 and !a[x + 2]) {
        cur.push_back(x + 1);
      }
      if (x > 0 and a[x - 1]) {
        cur.push_back(x - 1);
      }
    }
  }
  if (k < (int)moves.size() or k > total_moves) {
    cout << -1;
    exit(0);
  }
  int x = k - moves.size();
  vector<vector<int>> ans;
  bool is = true;
  for (auto in : moves) {
    for (int i : in) {
      if (x == 0) is = false;
      cur.push_back(i);
      if (is) {
        ans.push_back(cur);
        cur.clear();
        x--;
      }
    }
    x++;
    if (cur.size()) ans.push_back(cur);
    cur.clear();
  }
  for (auto i : ans) {
    cout << (int)i.size() << " ";
    for (auto j : i) {
      cout << j + 1 << " ";
    }
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

We have N locked treasure boxes, numbered 1 to N.

A shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each key purchased can be used any number of times.

Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.

Constraints

* All values in input are integers.
* 1 \leq N \leq 12
* 1 \leq M \leq 10^3
* 1 \leq a_i \leq 10^5
* 1 \leq b_i \leq N
* 1 \leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \leq N

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
c_{11} c_{12} ... c_{1{b_1}}
:
a_M b_M
c_{M1} c_{M2} ... c_{M{b_M}}

Output

Print the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.

Examples

Input

2 3
10 1
1
15 1
2
30 2
1 2

Output

25

Input

12 1
100000 1
2

Output

-1

Input

4 6
67786 3
1 3 4
3497 1
2
44908 3
2 3 4
2156 3
2 3 4
26230 1
2
86918 1
3

Output

69942

### Response

```cpp
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(1 << n, INF);
  p.at(0) = 0;
  for (int i = 0; i < m; i++) {
    int a, b, open = 0;
    cin >> a >> b;
    for (int j = 0; j < b; j++) {
      int c;
      cin >> c;
      open += 1 << (c - 1);
    }
    for (int j = 0; j < 1 << n; j++) {
      p.at(j) = min(p.at(j), p.at(j & (~open)) + a);
    }
  }
  if (p.at((1 << n) - 1) == INF) {
    cout << -1 << endl;
  } else {
    cout << p.at((1 << n) - 1) << endl;
  }
}

```


### Prompt

Generate a CPP solution to the following problem:

Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.

Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.

It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.

Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.

Write a program that, given sequence ai, will print the minimum number of folders.

Input

The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.

Output

Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.

If there are multiple ways to sort the reports into k days, print any of them.

Examples

Input

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

Output

3
5 3 3

Input

5
0 -1 100 -1 0

Output

1
5

Note

Here goes a way to sort the reports from the first sample into three folders:

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

In the second sample you can put all five reports in one folder.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
  int n, m, x = 0, y = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> m;
    ++x;
    if (m < 0) ++y;
    if (y == 3) {
      a.push_back(x - 1);
      x = 1;
      y = 1;
    }
  }
  cout << a.size() + 1 << endl;
  for (int i = 0; i < a.size(); ++i) cout << a[i] << ' ';
  cout << x;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:

<image>

In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.

Input

The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.

Output

Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).

Examples

Input

AB
XC
XB
AC

Output

YES

Input

AB
XC
AC
BX

Output

NO

Note

The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.

In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9 + 9091203;
const long long MOD = 1e9 + 696969;
const long long INF = 1e18;
const int BASE = 10000;
int n, m, b, c, k;
int goal[5];
int main() {
  char a;
  int tab[5], DL = 0;
  for (int i = 1; i <= 2; ++i)
    for (int j = 1; j <= 2; ++j) scanf(" %c", &a) ?: 0, tab[++DL] = a;
  DL = 0;
  for (int i = 1; i <= 2; ++i)
    for (int j = 1; j <= 2; ++j) scanf(" %c", &a) ?: 0, goal[++DL] = a;
  for (int steps = 0; steps < 10000000; ++steps) {
    int r = rand() % 4;
    if (r == 0 && (goal[1] == 'X' || goal[2] == 'X')) swap(goal[1], goal[2]);
    if (r == 1 && (goal[2] == 'X' || goal[4] == 'X')) swap(goal[2], goal[4]);
    if (r == 2 && (goal[4] == 'X' || goal[3] == 'X')) swap(goal[4], goal[3]);
    if (r == 3 && (goal[3] == 'X' || goal[1] == 'X')) swap(goal[3], goal[1]);
    bool b1 = 1;
    for (int i = 1; i <= 4; ++i)
      if (tab[i] != goal[i]) b1 = 0;
    if (b1) {
      cout << "YES";
      exit(0);
    };
  }
  {
    cout << "NO";
    exit(0);
  };
}

```


### Prompt

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

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

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

Input

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

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

Output

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

Examples

Input

5
1 2 3 4 5

Output

0

Input

3
8 12 7

Output

3

Input

3
3 2 1

Output

2

Note

Possible pairs in the second example:

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

In the third example:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], T[maxn];
int n;
void add(int x, int p) {
  for (; x <= n; x += x & -x) T[x] += p;
}
long long sum(int x) {
  long long res = 0;
  for (; x; x -= x & -x) res += T[x];
  return res;
}
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
int main() {
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) {
    while (!pq.empty() && pq.top().first < i) {
      add(pq.top().second, -1);
      pq.pop();
    }
    ans += sum(min(i, a[i]));
    if (a[i] <= i) continue;
    add(i, 1);
    pq.push(make_pair(a[i], i));
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Constraints

* 1 \leq |S| \leq 100
* S consists of lowercase English letters.
* 1 \leq K \leq 10^9
* K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Examples

Input

issii
2

Output

4

Input

qq
81

Output

81

Input

cooooooooonteeeeeeeeeest
999993333

Output

8999939997

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int k=0;
  long long n;
  cin>>n;
  long long count=0,a=0,b=0;

  while(s[0]==s[k++] && k<=s.length() && s[0]==s[s.length()-1])a++;
  k=s.length()-1;
  while(s[s.length()-1]==s[k--] && k>=0 &&s[0]==s[s.length()-1])b++;
  if(a==s.length())
  {
    cout<<n*a/2<<endl;
    return 0;
  }

    for(int i=a;i<s.length()-b;i++)
    {
		if(s[i]==s[i-1])
        {
          count++;
          i++;
        }
    }
  //cout<<a<<' '<<b<<' '<<count<<endl;
  long long sum=(a/2)+(b/2)+(n-1)*((a+b)/2)+n*(count);
  cout<<sum<<endl;
  return 0;
}
```


### Prompt

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

When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible.

Kefa knows that the i-th dish gives him ai units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself k rules of eating food of the following type — if he eats dish x exactly before dish y (there should be no other dishes between x and y), then his satisfaction level raises by c.

Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task!

Input

The first line of the input contains three space-separated numbers, n, m and k (1 ≤ m ≤ n ≤ 18, 0 ≤ k ≤ n * (n - 1)) — the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules.

The second line contains n space-separated numbers ai, (0 ≤ ai ≤ 109) — the satisfaction he gets from the i-th dish.

Next k lines contain the rules. The i-th rule is described by the three numbers xi, yi and ci (1 ≤ xi, yi ≤ n, 0 ≤ ci ≤ 109). That means that if you eat dish xi right before dish yi, then the Kefa's satisfaction increases by ci. It is guaranteed that there are no such pairs of indexes i and j (1 ≤ i < j ≤ k), that xi = xj and yi = yj.

Output

In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant.

Examples

Input

2 2 1
1 1
2 1 1

Output

3

Input

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

Output

12

Note

In the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule.

In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int const oo = 1e9, bound = 1e6, mod = oo + 7;
long long const OO = 1e18;
int n, m, k, aa[20];
int cc[20][20];
long long dp[18][1 << 18];
long long rec(int idx, int msk) {
  long long &ret = dp[idx][msk];
  if (ret != -1) return ret;
  int cop = msk, e = 0;
  while (cop) {
    if (cop & 1) e++;
    cop >>= 1;
  }
  if (e == m) return ret = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    if (!((msk >> i) & 1))
      ret = max(ret,
                rec(i, (1 << i) | msk) + aa[i] + (msk != 0 ? cc[idx][i] : 0));
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n), scanf("%d", &m), scanf("%d", &k);
  for (int(i) = 0; (i) < (n); (i)++) scanf("%d", &aa[i]);
  for (int(i) = 0; (i) < (k); (i)++) {
    int a, b, c;
    scanf("%d", &a), scanf("%d", &b), scanf("%d", &c);
    a--, b--;
    cc[a][b] = c;
  }
  long long mx = rec(0, 0);
  printf("%lld\n", mx);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

The Bitlandians are quite weird people. They have their own problems and their own solutions. They have their own thoughts and their own beliefs, they have their own values and their own merits. They have their own dishes and their own sausages!

In Bitland a sausage is an array of integers! A sausage's deliciousness is equal to the bitwise excluding OR (the xor operation) of all integers in that sausage.

One day, when Mr. Bitkoch (the local cook) was going to close his BitRestaurant, BitHaval and BitAryo, the most famous citizens of Bitland, entered the restaurant and each ordered a sausage.

But Mr. Bitkoch had only one sausage left. So he decided to cut a prefix (several, may be zero, first array elements) of the sausage and give it to BitHaval and a postfix (several, may be zero, last array elements) of the sausage and give it to BitAryo. Note that one or both pieces of the sausage can be empty. Of course, the cut pieces mustn't intersect (no array element can occur in both pieces).

The pleasure of BitHaval and BitAryo is equal to the bitwise XOR of their sausages' deliciousness. An empty sausage's deliciousness equals zero.

Find a way to cut a piece of sausage for BitHaval and BitAryo that maximizes the pleasure of these worthy citizens.

Input

The first line contains an integer n (1 ≤ n ≤ 105).

The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 1012) — Mr. Bitkoch's sausage.

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.

Output

Print a single integer — the maximum pleasure BitHaval and BitAryo can get from the dinner.

Examples

Input

2
1 2

Output

3

Input

3
1 2 3

Output

3

Input

2
1000 1000

Output

1000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long one = 1;
struct Tree {
  int ct;
  struct Tree *left, *right;
  Tree(int x) : ct(x), left(NULL), right(NULL) {}
};
void InsertNode(Tree *TreeNode, int level, long long x, int change) {
  if (level < 0) return;
  if ((x & (one << level)) == 0) {
    if (TreeNode->left == NULL) TreeNode->left = new Tree(0);
    TreeNode->left->ct += change;
    InsertNode(TreeNode->left, level - 1, x, change);
  } else {
    if (TreeNode->right == NULL) TreeNode->right = new Tree(0);
    TreeNode->right->ct += change;
    InsertNode(TreeNode->right, level - 1, x, change);
  }
}
long long query(Tree *TreeNode, int level, long long x) {
  if (TreeNode == NULL) return 0;
  if (level < 0) return 0;
  if ((one << level) & x) {
    if (TreeNode->left != NULL) {
      if (TreeNode->left->ct)
        return (one << level) + query(TreeNode->left, level - 1, x);
      else
        return query(TreeNode->right, level - 1, x);
    } else
      return query(TreeNode->right, level - 1, x);
  } else {
    if (TreeNode->right != NULL) {
      if (TreeNode->right->ct)
        return (one << level) + query(TreeNode->right, level - 1, x);
      else
        return query(TreeNode->left, level - 1, x);
    } else
      return query(TreeNode->left, level - 1, x);
  }
}
int main() {
  Tree *TreeNode = new Tree(0);
  int n;
  scanf("%d", &n);
  long long arr[n];
  for (int i(0); i < n; i++) scanf("%lld", &arr[i]);
  long long arr_suf[n + 1];
  arr_suf[n] = 0;
  InsertNode(TreeNode, 40, 0, 1);
  long long temp(0);
  for (int i(n - 1); i >= 0; i--) {
    temp = temp ^ arr[i];
    arr_suf[i] = temp;
    InsertNode(TreeNode, 40, temp, 1);
  }
  temp = 0;
  long long res = query(TreeNode, 40, 0);
  for (int i(0); i <= n - 1; i++) {
    InsertNode(TreeNode, 40, arr_suf[i], -1);
    temp = temp ^ arr[i];
    long long value = query(TreeNode, 40, temp);
    res = max(res, value);
  }
  printf("%lld\n", res);
  return 0;
}

```


### Prompt

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

Problem F and F2 are the same problem, but with different constraints and time limits.

We have a board divided into N horizontal rows and N vertical columns of square cells. The cell at the i-th row from the top and the j-th column from the left is called Cell (i,j). Each cell is either empty or occupied by an obstacle. Also, each empty cell has a digit written on it. If A_{i,j}= `1`, `2`, ..., or `9`, Cell (i,j) is empty and the digit A_{i,j} is written on it. If A_{i,j}= `#`, Cell (i,j) is occupied by an obstacle.

Cell Y is reachable from cell X when the following conditions are all met:

* Cells X and Y are different.
* Cells X and Y are both empty.
* One can reach from Cell X to Cell Y by repeatedly moving right or down to an adjacent empty cell.

Consider all pairs of cells (X,Y) such that cell Y is reachable from cell X. Find the sum of the products of the digits written on cell X and cell Y for all of those pairs.

Constraints

* 1 \leq N \leq 500
* A_{i,j} is one of the following characters: `1`, `2`, ... `9` and `#`.

Input

Input is given from Standard Input in the following format:

N
A_{1,1}A_{1,2}...A_{1,N}
A_{2,1}A_{2,2}...A_{2,N}
:
A_{N,1}A_{N,2}...A_{N,N}

Output

Print the sum of the products of the digits written on cell X and cell Y for all pairs (X,Y) such that cell Y is reachable from cell X.

Examples

Input

2
11
11

Output

5

Input

4
1111
11#1
1#11
1111

Output

47

Input

10
76##63##3#
8445669721
75#9542133
3#285##445
749632##89
2458##9515
5952578#77
1#3#44196#
4355#99#1#
298#63587

Output

36065

Input

10
4177143673
7#########
5#1716155#
6#4#####5#
2#3#597#6#
6#9#8#3#5#
5#2#899#9#
1#6#####6#
6#5359657#
5#########

Output

6525

### Response

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

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char *s) {
  return to_string((string)s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template<typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template<typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() {
  cerr << endl;
}

template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int inf = 0x3f3f3f3f;

void cmax(int &x, int y) {
  if (x < y) {
    x = y;
  }
}

void cmin(int &x, int y) {
  if (x > y) {
    x = y;
  }
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector<string> board(n);
  for (int i = 0; i < n; ++i) {
    cin >> board[i];
  }
  long long answer = 0;

  function<void(vector<string>)> solve = [&](vector<string> board) {
    int n = board.size(), m = board[0].size();

    if (n < m) {
      vector<string> rotated(m, string(n, ' '));
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
          rotated[j][i] = board[i][j];
        }
      }
      swap(n, m);
      board = rotated;
    }

    if (m == 1) {
      int sum = 0;
      for (int i = 0; i < n; ++i) {
        if (board[i][0] == '#') {
          sum = 0;
        } else {
          answer += (board[i][0] - '0') * sum;
          sum += board[i][0] - '0';
        }
      }
      return;
    }

    vector<string> u = vector<string> (board.begin(), board.begin() + (n >> 1));
    vector<string> d = vector<string> (board.begin() + (n >> 1), board.end());
    solve(u);
    solve(d);
    u.push_back(d[0]);

    int nu = n >> 1, nd = n + 1 >> 1;
    vector<vector<int>> left(nd, vector<int> (m, inf));
    vector<vector<int>> right(nd, vector<int> (m, -inf));
    vector<int> top(m);
    vector<int> bottom(m);
    for (int i = 0; i < m; ++i) {
      if (d[0][i] != '#') {
        left[0][i] = right[0][i] = i;
      }
    }
    for (int i = 0; i < nd; ++i) {
      for (int j = 0; j < m; ++j) {
        if (d[i][j] != '#') {
          if (i) {
            cmin(left[i][j], left[i - 1][j]);
            cmax(right[i][j], right[i - 1][j]);
          }
          if (j) {
            cmin(left[i][j], left[i][j - 1]);
            cmax(right[i][j], right[i][j - 1]);
          }
        }
      }
    }

    {
      vector<vector<int>> temp(nd, vector<int> (m, -inf));
      for (int i = nd - 1; ~i; --i) {
        for (int j = m - 1; ~j; --j) {
          if (d[i][j] != '#') {
            temp[i][j] = i;
            if (i + 1 < nd) {
              cmax(temp[i][j], temp[i + 1][j]);
            }
            if (j + 1 < m) {
              cmax(temp[i][j], temp[i][j + 1]);
            }
          }
        }
      }
      for (int i = 0; i < m; ++i) {
        bottom[i] = temp[0][i];
      }
    }

    {
      vector<vector<int>> temp(nu + 1, vector<int> (m, inf));
      for (int i = 0; i <= nu; ++i) {
        for (int j = 0; j < m; ++j) {
          if (u[i][j] != '#') {
            temp[i][j] = i;
            if (i) {
              cmin(temp[i][j], temp[i - 1][j]);
            }
            if (j) {
              cmin(temp[i][j], temp[i][j - 1]);
            }
          }
        }
      }
      for (int i = 0; i < m; ++i) {
        top[i] = temp[nu][i];
      }
    }

    vector<vector<int>> mp(m, vector<int> (m, inf));
    for (int i = 0; i < nd; ++i) {
      for (int j = 0; j < m; ++j) {
        if (left[i][j] <= right[i][j]) {
          cmin(mp[left[i][j]][right[i][j]], i);
        }
      }
    }
    for (int l = 0; l < m; ++l) {
      for (int r = m - 1; ~r; --r) {
        if (l) {
          cmin(mp[l][r], mp[l - 1][r]);
        }
        if (r + 1 < m) {
          cmin(mp[l][r], mp[l][r + 1]);
        }
      }
    }

    auto meeting_point = [&](int a, int b) {
      int p = mp[a][b];
      return p <= min(bottom[a], bottom[b]) ? p : inf;
    };

    vector<int> sum1(nd);
    vector<vector<int>> sum2(nd, vector<int> (m));
    vector<vector<int>> sum3(nd, vector<int> (m));
    vector<vector<int>> sum4(m, vector<int> (m));

    for (int i = 0; i < nd; ++i) {
      if (i) {
        sum1[i] = sum1[i - 1];
        for (int j = 0; j < m; ++j) {
          sum2[i][j] = sum2[i - 1][j];
          sum3[i][j] = sum3[i - 1][j];
        }
      }
      for (int j = 0; j < m; ++j) {
        if (left[i][j] <= right[i][j]) {
          sum1[i] += d[i][j] - '0';
          if (left[i][j]) {
            sum2[i][left[i][j] - 1] += d[i][j] - '0';
          }
          if (right[i][j] + 1 < m) {
            sum3[i][right[i][j] + 1] += d[i][j] - '0';
          }
          if (left[i][j] && right[i][j] + 1 < m) {
            sum4[left[i][j] - 1][right[i][j] + 1] += d[i][j] - '0';
          }
        }
      }
    }
    for (int i = 0; i < nd; ++i) {
      for (int j = m - 1; j; --j) {
        sum2[i][j - 1] += sum2[i][j];
      }
      for (int j = 1; j < m; ++j) {
        sum3[i][j] += sum3[i][j - 1];
      }
    }
    for (int l = m - 1; ~l; --l) {
      for (int r = l; r < m; ++r) {
        if (l + 1 < m) {
          sum4[l][r] += sum4[l + 1][r];
        }
        if (r) {
          sum4[l][r] += sum4[l][r - 1];
        }
        if (l + 1 < m && r) {
          sum4[l][r] -= sum4[l + 1][r - 1];
        }
      }
    }

    auto both_reachable = [&](int a, int b, int l) {
      if (meeting_point(a, b) > l) {
        return 0;
      } else {
        return sum1[l] - sum2[l][a] - sum3[l][b] + sum4[a][b];
      }
    };

    vector<int> reachable(m);
    for (int i = 0; i < m; ++i) {
      reachable[i] = both_reachable(i, i, bottom[i]);
    }

    vector<vector<int>> event(nu);
    vector<bool> ban(m);
    for (int i = 0; i < m; ++i) {
      if (top[i] >= nu) {
        ban[i] = true;
      } else {
        event[top[i]].push_back(i);
      }
    }
    vector<int> l(m), r(m);
    for (int i = m - 1; ~i; --i) {
      if (d[0][i] == '#') {
        l[i] = inf;
        r[i] = -inf;
      } else {
        l[i] = i;
        r[i] = max(i, i + 1 < m ? r[i + 1] : -inf);
      }
    }
    for (int row = nu - 1; ~row; --row) {
      for (int i = m - 1; ~i; --i) {
        if (u[row][i] == '#') {
          l[i] = inf;
          r[i] = -inf;
        } else if (i + 1 < m) {
          cmin(l[i], l[i + 1]);
          cmax(r[i], r[i + 1]);
        }
      }
      vector<int> has(m);
      vector<int> st(m);
      int sum = 0, stl = 0, str = 0, myl = 0, myr = -1;

      auto insert = [&](int x) {
        if (!ban[x]) {
          if (stl < str) {
            sum -= has[st[str - 1]];
            has[st[str - 1]] -= both_reachable(st[str - 1], x, min(bottom[st[str - 1]], bottom[x]));
            sum += has[st[str - 1]];
            if (bottom[st[str - 1]] <= bottom[x]) {
              --str;
              while (stl < str) {
                sum -= has[st[str - 1]];
                has[st[str - 1]] -= both_reachable(st[str - 1], x, min(bottom[st[str - 1]], bottom[x])) - both_reachable(st[str - 1], x, min(bottom[st[str]], bottom[x]));
                sum += has[st[str - 1]];
                if (bottom[st[str - 1]] <= bottom[x]) {
                  --str;
                } else {
                  break;
                }
              }
            }
          }
          st[str++] = x;
          has[x] = reachable[x];
          sum += has[x];
        }
      };

      auto erase = [&](int x) {
        if (!ban[x]) {
          sum -= has[x];
          if (stl < str && st[stl] == x) {
            ++stl;
          }
        }
      };

      for (int i = 0; i < m; ++i) {
        if (l[i] <= r[i]) {
          while (myr < r[i]) {
            insert(++myr);
          }
          while (myl < l[i]) {
            erase(myl++);
          }
          answer += (u[row][i] - '0') * sum;
        }
      }
      for (auto p : event[row]) {
        ban[p] = true;
      }
    }
  };

  solve(board);
  cout << answer << endl;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Kuro is living in a country called Uberland, consisting of n towns, numbered from 1 to n, and n - 1 bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns a and b. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns (u, v) (u ≠ v) and walk from u using the shortest path to v (note that (u, v) is considered to be different from (v, u)).

Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index x) and Beetopia (denoted with the index y). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns (u, v) if on the path from u to v, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.

Kuro wants to know how many pair of city (u, v) he can take as his route. Since he’s not really bright, he asked you to help him with this problem.

Input

The first line contains three integers n, x and y (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ x, y ≤ n, x ≠ y) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.

n - 1 lines follow, each line contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), describes a road connecting two towns a and b.

It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.

Output

A single integer resembles the number of pair of towns (u, v) that Kuro can use as his walking route.

Examples

Input

3 1 3
1 2
2 3

Output

5

Input

3 1 3
1 2
1 3

Output

4

Note

On the first example, Kuro can choose these pairs:

  * (1, 2): his route would be 1 → 2,
  * (2, 3): his route would be 2 → 3,
  * (3, 2): his route would be 3 → 2,
  * (2, 1): his route would be 2 → 1,
  * (3, 1): his route would be 3 → 2 → 1.

Kuro can't choose pair (1, 3) since his walking route would be 1 → 2 → 3, in which Kuro visits town 1 (Flowrisa) and then visits town 3 (Beetopia), which is not allowed (note that pair (3, 1) is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).

On the second example, Kuro can choose the following pairs:

  * (1, 2): his route would be 1 → 2,
  * (2, 1): his route would be 2 → 1,
  * (3, 2): his route would be 3 → 1 → 2,
  * (3, 1): his route would be 3 → 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
using namespace std;
vector<long long> e[MAXN];
vector<long long> re[MAXN];
long long use[MAXN];
long long num;
long long dfs(long long x, long long aim) {
  use[x] = 1;
  num++;
  long long k = 0;
  if (x == aim) k = 1;
  long long t1 = 0;
  for (long long i = 0; i < e[x].size(); i++) {
    long long t = e[x][i];
    if (!use[t]) t1 = dfs(t, aim);
    if (t1 == 1) k = 1;
  }
  return k;
}
int main() {
  long long n, i, j, k, t1, t2, t3, x, y, m1, m2, s, t;
  cin >> n >> s >> t;
  for (i = 0; i < n - 1; i++) {
    cin >> t1 >> t2;
    e[t1].push_back(t2);
    e[t2].push_back(t1);
  }
  num = 0;
  memset(use, 0, sizeof(use));
  use[s] = 1;
  m1 = 1;
  for (i = 0; i < e[s].size(); i++) {
    t1 = e[s][i];
    num = 0;
    if (!dfs(t1, t)) m1 += num;
  }
  memset(use, 0, sizeof(use));
  use[t] = 1;
  num = 0;
  m2 = 1;
  for (i = 0; i < e[t].size(); i++) {
    t1 = e[t][i];
    num = 0;
    if (!dfs(t1, s)) m2 += num;
  }
  cout << (n * (n - 1)) - m1 * m2;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given a tree with n vertices and you are allowed to perform no more than 2n transformations on it. Transformation is defined by three vertices x, y, y' and consists of deleting edge (x, y) and adding edge (x, y'). Transformation x, y, y' could be performed if all the following conditions are satisfied:

  1. There is an edge (x, y) in the current tree.
  2. After the transformation the graph remains a tree.
  3. After the deletion of edge (x, y) the tree would consist of two connected components. Let's denote the set of nodes in the component containing vertex x by Vx, and the set of nodes in the component containing vertex y by Vy. Then condition |Vx| > |Vy| should be satisfied, i.e. the size of the component with x should be strictly larger than the size of the component with y.

You should minimize the sum of squared distances between all pairs of vertices in a tree, which you could get after no more than 2n transformations and output any sequence of transformations leading initial tree to such state.

Note that you don't need to minimize the number of operations. It is necessary to minimize only the sum of the squared distances.

Input

The first line of input contains integer n (1 ≤ n ≤ 2·105) — number of vertices in tree.

The next n - 1 lines of input contains integers a and b (1 ≤ a, b ≤ n, a ≠ b) — the descriptions of edges. It is guaranteed that the given edges form a tree.

Output

In the first line output integer k (0 ≤ k ≤ 2n) — the number of transformations from your example, minimizing sum of squared distances between all pairs of vertices.

In each of the next k lines output three integers x, y, y' — indices of vertices from the corresponding transformation.

Transformations with y = y' are allowed (even though they don't change tree) if transformation conditions are satisfied.

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

Examples

Input

3
3 2
1 3

Output

0

Input

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

Output

2
4 3 2
4 5 6

Note

This is a picture for the second sample. Added edges are dark, deleted edges are dotted.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct tri {
  int x, y, z;
};
const int MAXN = 200005;
vector<int> sas[MAXN], tmp;
int rozm[MAXN], n, last;
int byl[MAXN];
queue<tri> q;
void dfs(int co, int nie) {
  rozm[co] = 1;
  bool ta = 1;
  for (auto x : sas[co])
    if (x != nie) {
      dfs(x, co);
      rozm[co] += rozm[x];
      if (rozm[x] * 2 > n) ta = 0;
    }
  if ((n - rozm[co]) * 2 > n) ta = 0;
  if (ta) byl[co] = 1;
}
void wal(int co) {
  byl[co] = 2;
  tri t;
  for (int x : sas[co])
    if (!byl[x]) {
      t.x = last;
      t.y = co;
      t.z = x;
      q.push(t);
      wal(x);
    }
  tmp.push_back(co);
  last = co;
}
int main() {
  int m, k, a, b, c, d, e, f;
  tri t;
  scanf("%d", &n);
  for (a = 1; a < n; a++) {
    scanf("%d%d", &b, &c);
    sas[b].push_back(c);
    sas[c].push_back(b);
  }
  dfs(1, 1);
  for (a = 1; a <= n; a++)
    if (byl[a] == 1)
      for (int x : sas[a])
        if (!byl[x]) {
          last = a;
          tmp.push_back(a);
          wal(x);
          for (b = tmp.size() - 4; b >= 0; b--) {
            t.x = tmp[b];
            t.y = tmp[b + 1];
            t.z = tmp[tmp.size() - 2];
            q.push(t);
          }
          tmp.clear();
        }
  printf("%d\n", q.size());
  while (!q.empty()) {
    t = q.front();
    q.pop();
    printf("%d %d %d\n", t.x, t.y, t.z);
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Wojtek has just won a maths competition in Byteland! The prize is admirable — a great book called 'Card Tricks for Everyone.' 'Great!' he thought, 'I can finally use this old, dusted deck of cards that's always been lying unused on my desk!'

The first chapter of the book is 'How to Shuffle k Cards in Any Order You Want.' It's basically a list of n intricate methods of shuffling the deck of k cards in a deterministic way. Specifically, the i-th recipe can be described as a permutation (P_{i,1}, P_{i,2}, ..., P_{i,k}) of integers from 1 to k. If we enumerate the cards in the deck from 1 to k from top to bottom, then P_{i,j} indicates the number of the j-th card from the top of the deck after the shuffle.

The day is short and Wojtek wants to learn only some of the tricks today. He will pick two integers l, r (1 ≤ l ≤ r ≤ n), and he will memorize each trick from the l-th to the r-th, inclusive. He will then take a sorted deck of k cards and repeatedly apply random memorized tricks until he gets bored. He still likes maths, so he started wondering: how many different decks can he have after he stops shuffling it?

Wojtek still didn't choose the integers l and r, but he is still curious. Therefore, he defined f(l, r) as the number of different decks he can get if he memorizes all the tricks between the l-th and the r-th, inclusive. What is the value of

$$$∑_{l=1}^n ∑_{r=l}^n f(l, r)?$$$

Input

The first line contains two integers n, k (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 5) — the number of tricks and the number of cards in Wojtek's deck.

Each of the following n lines describes a single trick and is described by k distinct integers P_{i,1}, P_{i,2}, ..., P_{i, k} (1 ≤ P_{i, j} ≤ k).

Output

Output the value of the sum described in the statement.

Examples

Input

3 3
2 1 3
3 1 2
1 3 2

Output

25

Input

2 4
4 1 3 2
4 3 1 2

Output

31

Note

Consider the first sample:

  * The first trick swaps two top cards.
  * The second trick takes a card from the bottom and puts it on the top of the deck.
  * The third trick swaps two bottom cards.

The first or the third trick allow Wojtek to generate only two distinct decks (either the two cards are swapped or not). Therefore, f(1, 1) = f(3, 3) = 2.

The second trick allows him to shuffle the deck in a cyclic order. Therefore, f(2,2)=3.

It turns that two first tricks or two last tricks are enough to shuffle the deck in any way desired by Wojtek. Therefore, f(1,2) = f(2,3) = f(1,3) = 3! = 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
int n, k, f[120][120], g[120][6], h[6][6][6][6][6];
vector<pair<pair<bitset<120>, int>, vector<int>>> V[2];
bitset<120> zr, b;
vector<int> t;
void dfs(int id) {
  for (auto x : t)
    if (!b[f[id][x]]) {
      b[f[id][x]] = 1;
      dfs(f[id][x]);
    }
}
bitset<120> sol(vector<int> v, int g) {
  v.push_back(g);
  t = v;
  b = zr;
  dfs(0);
  return b;
}
int main() {
  scanf("%d%d", &n, &k);
  zr[0] = 1;
  long long ans = 0;
  int p[6] = {0, 1, 2, 3, 4, 5};
  for (int i = 0; i < 120; i++) {
    for (int j = 1; j <= 5; j++) g[i][j] = p[j];
    h[p[1]][p[2]][p[3]][p[4]][p[5]] = i;
    next_permutation(p + 1, p + 6);
  }
  for (int i = 0; i < 120; i++)
    for (int j = 0; j < 120; j++)
      f[i][j] = h[g[j][g[i][1]]][g[j][g[i][2]]][g[j][g[i][3]]][g[j][g[i][4]]]
                 [g[j][g[i][5]]];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) scanf("%d", &p[j]);
    for (int j = k + 1; j <= 5; j++) p[j] = j;
    int id = h[p[1]][p[2]][p[3]][p[4]][p[5]], nw = i & 1, pr = nw ^ 1;
    vector<int> ff;
    V[pr].push_back({{zr, 1}, ff});
    V[nw].clear();
    for (auto t : V[pr]) {
      bitset<120> x = sol(t.second, id);
      if (x != t.first.first) t.first.first = x, t.second.push_back(id);
      if (!V[nw].empty() && V[nw].back().first.first == x)
        V[nw].back().first.second += t.first.second;
      else
        V[nw].push_back(t);
    }
    for (auto t : V[nw]) ans += t.first.first.count() * t.first.second;
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Dr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants to manipulate matrices outside, so he needs a small program similar to the excellent application for his handheld computer.

Your job is to provide him a program that computes expressions of matrices.

Expressions of matrices are described in a simple language. Its syntax is shown in Table J.1. Note that even a space and a newline have meaningful roles in the syntax.

<image>

The start symbol of this syntax is program that is defined as a sequence of assignments in Table J.1. Each assignment has a variable on the left hand side of an equal symbol ("=") and an expression of matrices on the right hand side followed by a period and a newline (NL). It denotes an assignment of the value of the expression to the variable. The variable (var in Table J.1) is indicated by an uppercase Roman letter. The value of the expression (expr) is a matrix or a scalar, whose elements are integers. Here, a scalar integer and a 1 × 1 matrix whose only element is the same integer can be used interchangeably.

An expression is one or more terms connected by "+" or "-" symbols. A term is one or more factors connected by "*" symbol. These operators ("+", "-", "*") are left associative.

A factor is either a primary expression (primary) or a "-" symbol followed by a factor. This unary operator "-" is right associative.

The meaning of operators are the same as those in the ordinary arithmetic on matrices: Denoting matrices by A and B, A + B, A - B, A * B, and -A are defined as the matrix sum, difference, product, and negation. The sizes of A and B should be the same for addition and subtraction. The number of columns of A and the number of rows of B should be the same for multiplication.

Note that all the operators +, -, * and unary - represent computations of addition, subtraction, multiplication and negation modulo M = 215 = 32768, respectively. Thus all the values are nonnegative integers between 0 and 32767, inclusive. For example, the result of an expression 2 - 3 should be 32767, instead of -1.

inum is a non-negative decimal integer less than M.

var represents the matrix that is assigned to the variable var in the most recent preceding assignment statement of the same variable.

matrix represents a mathematical matrix similar to a 2-dimensional array whose elements are integers. It is denoted by a row-seq with a pair of enclosing square brackets. row-seq represents a sequence of rows, adjacent two of which are separated by a semicolon. row represents a sequence of expressions, adjacent two of which are separated by a space character.

For example, [1 2 3;4 5 6] represents a matrix <image>. The first row has three integers separated by two space characters, i.e. "1 2 3". The second row has three integers, i.e. "4 5 6". Here, the row-seq consists of the two rows separated by a semicolon. The matrix is denoted by the row-seq with a pair of square brackets.

Note that elements of a row may be matrices again. Thus the nested representation of a matrix may appear. The number of rows of the value of each expression of a row should be the same, and the number of columns of the value of each row of a row-seq should be the same.

For example, a matrix represented by

[[1 2 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18]

is <image> The sizes of matrices should be consistent, as mentioned above, in order to form a well-formed matrix as the result. For example, [[1 2;3 4] [5;6;7];6 7 8] is not consistent since the first row "[1 2;3 4] [5;6;7]" has two matrices (2 × 2 and 3 × 1) whose numbers of rows are different. [1 2;3 4 5] is not consistent since the number of columns of two rows are different.

The multiplication of 1 × 1 matrix and m × n matrix is well-defined for arbitrary m > 0 and n > 0, since a 1 × 1 matrices can be regarded as a scalar integer. For example, 2*[1 2;3 4] and [1 2;3 4]*3 represent the products of a scalar and a matrix <image> and <image>. [2]*[1 2;3 4] and [1 2;3 4]*[3] are also well-defined similarly.

An indexed-primary is a primary expression followed by two expressions as indices. The first index is 1 × k integer matrix denoted by (i1 i2 ... ik), and the second index is 1 × l integer matrix denoted by (j1 j2 ... jl). The two indices specify the submatrix extracted from the matrix which is the value of the preceding primary expression. The size of the submatrix is k × l and whose (a, b)-element is the (ia, jb)-element of the value of the preceding primary expression. The way of indexing is one-origin, i.e., the first element is indexed by 1.

For example, the value of ([1 2;3 4]+[3 0;0 2])([1],[2]) is equal to 2, since the value of its primary expression is a matrix [4 2;3 6], and the first index [1] and the second [2] indicate the (1, 2)-element of the matrix. The same integer may appear twice or more in an index matrix, e.g., the first index matrix of an expression [1 2;3 4]([2 1 1],[2 1]) is [2 1 1], which has two 1's. Its value is <image>.

A transposed-primary is a primary expression followed by a single quote symbol ("'"), which indicates the transpose operation. The transposed matrix of an m × n matrix A = (aij) (i = 1, ..., m and j = 1, ... , n) is the n × m matrix B = (bij) (i = 1, ... , n and j = 1, ... , m), where bij = aji. For example, the value of [1 2;3 4]' is <image>.

Input

The input consists of multiple datasets, followed by a line containing a zero. Each dataset has the following format.

n
program

n is a positive integer, which is followed by a program that is a sequence of single or multiple lines each of which is an assignment statement whose syntax is defined in Table J.1. n indicates the number of the assignment statements in the program. All the values of vars are undefined at the beginning of a program.

You can assume the following:

* 1 ≤ n ≤ 10,
* the number of characters in a line does not exceed 80 (excluding a newline),
* there are no syntax errors and semantic errors (e.g., reference of undefined var),
* the number of rows of matrices appearing in the computations does not exceed 100, and
* the number of columns of matrices appearing in the computations does not exceed 100.

Output

For each dataset, the value of the expression of each assignment statement of the program should be printed in the same order. All the values should be printed as non-negative integers less than M.

When the value is an m × n matrix A = (aij) (i = 1, ... ,m and j = 1, ... , n), m lines should be printed. In the k-th line (1 ≤ k ≤ m), integers of the k-th row, i.e., ak1, ... , akn, should be printed separated by a space.

After the last value of a dataset is printed, a line containing five minus symbols '-----' should be printed for human readability.

The output should not contain any other extra characters.

Example

Input

1
A=[1 2 3;4 5 6].
1
A=[[1 2 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18].
3
B=[3 -2 1;-9 8 7].
C=([1 2 3;4 5 6]+B)(2,3).
D=([1 2 3;4 5 6]+B)([1 2],[2 3]).
5
A=2*[1 2;-3 4]'.
B=A([2 1 2],[2 1]).
A=[1 2;3 4]*3.
A=[2]*[1 2;3 4].
A=[1 2;3 4]*[3].
2
A=[11 12 13;0 22 23;0 0 33].
A=[A A';--A''' A].
2
A=[1 -1 1;1 1 -1;-1 1 1]*3.
A=[A -A+-A;-A'([3 2 1],[3 2 1]) -A'].
1
A=1([1 1 1],[1 1 1 1]).
3
A=[1 2 -3;4 -5 6;-7 8 9].
B=A([3 1 2],[2 1 3]).
C=A*B-B*A+-A*-B-B*-A.
3
A=[1 2 3 4 5].
B=A'*A.
C=B([1 5],[5 1]).
3
A=[-11 12 13;21 -22 23;31 32 -33].
B=[1 0 0;0 1 0;0 0 1].
C=[(A-B) (A+B)*B (A+B)*(B-A)([1 1 1],[3 2 1]) [1 2 3;2 1 1;-1 2 1]*(A-B)].
3
A=[11 12 13;0 22 23;0 0 33].
B=[1 2].
C=------A((((B))),B)(B,B)''''''.
2
A=1+[2]+[[3]]+[[[4]]]+2*[[[[5]]]]*3.
B=[(-[([(-A)]+-A)])].
8
A=[1 2;3 4].
B=[A A+[1 1;0 1]*4;A+[1 1;0 1]'*8 A+[1 1;0 1]''*12].
C=B([1],[1]).
C=B([1],[1 2 3 4]).
C=B([1 2 3 4],[1]).
C=B([2 3],[2 3]).
A=[1 2;1 2].
D=(A*-A+-A)'(A'(1,[1 2]),A'(2,[1 2])).
0

Output

1 2 3
4 5 6
-----
1 2 3 7 8 11
4 5 6 9 10 12
13 14 15 16 17 18
-----
3 32766 1
32759 8 7
13
0 4
13 13
-----
2 32762
4 8
8 4
32762 2
8 4
3 6
9 12
2 4
6 8
3 6
9 12
-----
11 12 13
0 22 23
0 0 33
11 12 13 11 0 0
0 22 23 12 22 0
0 0 33 13 23 33
11 0 0 11 12 13
12 22 0 0 22 23
13 23 33 0 0 33
-----
3 32765 3
3 3 32765
32765 3 3
3 32765 3 32762 6 32762
3 3 32765 32762 32762 6
32765 3 3 6 32762 32762
32765 3 32765 32765 32765 3
32765 32765 3 3 32765 32765
3 32765 32765 32765 3 32765
-----
1 1 1 1
1 1 1 1
1 1 1 1
-----
1 2 32765
4 32763 6
32761 8 9
8 32761 9
2 1 32765
32763 4 6
54 32734 32738
32752 32750 174
32598 186 32702
-----
1 2 3 4 5
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
5 1
25 5
-----
32757 12 13
21 32746 23
31 32 32735
1 0 0
0 1 0
0 0 1
32756 12 13 32758 12 13 32573 32588 180 123 62 32725
21 32745 23 21 32747 23 32469 32492 276 28 33 15
31 32 32734 31 32 32736 32365 32396 372 85 32742 32767
-----
11 12 13
0 22 23
0 0 33
1 2
11 12
0 22
-----
40
80
-----
1 2
3 4
1 2 5 6
3 4 3 8
9 2 13 14
11 12 3 16
1
1 2 5 6
1
3
9
11
4 3
2 13
1 2
1 2
32764 32764
32764 32764
-----

### Response

```cpp
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define MOD 32768
typedef vector<int> V;
typedef vector<V> MATRIX;

int N;
int global_index;
char buf[105];
MATRIX TABLE[26];

MATRIX expr();

MATRIX operator+(const MATRIX &A,const MATRIX &B){

	int num_row = A.size();
	int num_col = A[0].size();

	MATRIX RET(num_row,V(num_col));

	for(int row = 0; row < num_row; row++){
		for(int col = 0; col < num_col; col++){
			RET[row][col] = A[row][col]+B[row][col];
			RET[row][col] %= MOD;
		}
	}

	return RET;
}

MATRIX operator-(const MATRIX &A,const MATRIX &B){

	int num_row = A.size();
	int num_col = A[0].size();

	MATRIX RET(num_row,V(num_col));

	for(int row = 0; row < num_row; row++){
		for(int col = 0; col < num_col; col++){
			RET[row][col] = A[row][col]-B[row][col];
			RET[row][col] = (RET[row][col]+MOD)%MOD;
		}
	}

	return RET;
}

MATRIX operator*(const MATRIX &A, const MATRIX &B){

	int num_rowA = A.size();
	int num_colA = A[0].size();

	int num_rowB = B.size();
	int num_colB = B[0].size();

	if(num_rowA == 1 && num_colA == 1){ //Aがスカラー

		MATRIX RET(num_rowB,V(num_colB));

		for(int row = 0; row < num_rowB; row++){
			for(int col = 0; col < num_colB; col++){
				RET[row][col] = B[row][col]*A[0][0];
				RET[row][col] %= MOD;
			}
		}

		return RET;

	}else if(num_rowB == 1 && num_colB == 1){ //Bがスカラー

		MATRIX RET(num_rowA,V(num_colA));

		for(int row = 0; row < num_rowA; row++){
			for(int col = 0; col < num_colA; col++){
				RET[row][col] = A[row][col]*B[0][0];
				RET[row][col] %= MOD;
			}
		}

		return RET;

	}else{

		MATRIX RET(num_rowA,V(num_colB));

		for(int row = 0; row < num_rowA; row++){
			for(int col = 0; col < num_colB; col++){
				RET[row][col] = 0;
				for(int a = 0; a < num_colA; a++){
					RET[row][col] += A[row][a]*B[a][col];
					RET[row][col] %= MOD;
				}
			}
		}

		return RET;
	}
}

MATRIX operator-(const MATRIX &A){

	int num_rowA = A.size();
	int num_colA = A[0].size();
	MATRIX RET(num_rowA,V(num_colA));

	for(int row = 0; row < num_rowA; row++){
		for(int col = 0; col < num_colA; col++){
			RET[row][col] = (-A[row][col]+MOD)%MOD;
		}
	}
	return RET;
}

MATRIX transpose(MATRIX A){

	int num_row = A[0].size();
	int num_col = A.size();

	MATRIX RET(num_row,V(num_col));

	for(int row = 0; row < A.size(); row++){
		for(int col = 0; col < A[0].size(); col++){
			RET[col][row] = A[row][col];
		}
	}

	return RET;
}

MATRIX get_row(){

	MATRIX A = expr();

	while(buf[global_index] == ' '){
		global_index++;
		MATRIX B = expr();
		for(int a = 0; a < A.size(); a++){
			A[a].insert(A[a].end(),B[a].begin(),B[a].end());
		}
	}
	return A;
}

MATRIX row_seq(){
	MATRIX A = get_row();

	while(buf[global_index] == ';'){
		global_index++;
		MATRIX B = get_row();
		A.insert(A.end(),B.begin(),B.end());
	}

	return A;
}

MATRIX matrix(){

	global_index++;
	MATRIX A = row_seq();
	global_index++;

	return A;
}

MATRIX get_var(){

	MATRIX RET = TABLE[buf[global_index]-'A'];
	global_index++;

	return RET;
}

MATRIX inum(){

	int tmp = 0;

	while(buf[global_index] >= '0' && buf[global_index] <= '9'){
		tmp = 10*tmp+(buf[global_index]-'0');
		tmp %= MOD;
		global_index++;
	}

	MATRIX RET(1,V(1));

	RET[0][0] = tmp;

	return RET;
}

MATRIX primary(){

	MATRIX A;

	if(buf[global_index] >= '0' && buf[global_index] <= '9'){

		A = inum();

	}else if(buf[global_index] >= 'A' && buf[global_index] <= 'Z'){

		A = get_var();

	}else if(buf[global_index] == '['){

		A = matrix();

	}else if(buf[global_index] == '('){
		global_index++;
		A = expr();
		global_index++;
	}

	bool FLG;

	while(true){
		FLG = false;

		if(buf[global_index] == '('){

			FLG = true;
			global_index++;
			MATRIX B = expr();
			global_index++;
			MATRIX C = expr();
			global_index++;

			int num_row = B[0].size();
			int num_col = C[0].size();

			MATRIX TMP(num_row,V(num_col));

			for(int row = 0; row < num_row; row++){
				for(int col = 0; col < num_col; col++){
					TMP[row][col] = A[B[0][row]-1][C[0][col]-1];
				}
			}
			A = TMP;

		}else if(buf[global_index] == '\''){
			FLG = true;
			global_index++;
			A = transpose(A);
		}

		if(!FLG)break;
	}
	return A;
}

MATRIX factor(){

	if(buf[global_index] == '-'){

		global_index++;
		return -factor();

	}else{

		return primary();
	}
}

MATRIX term(){

	MATRIX A = factor();

	while(buf[global_index] == '*'){
		global_index++;
		A = A*factor();
	}
	return A;
}

MATRIX expr(){

	MATRIX A = term();
	char op;

	while(buf[global_index] == '+' || buf[global_index] == '-'){

		op = buf[global_index++];

		if(op == '+'){

			A = A+term();

		}else{

			A = A-term();
		}
	}

	return A;
}

void assignment(){

	int type = buf[0]-'A';
	global_index = 2;
	TABLE[type] = expr();

	global_index++;
}

void func(){

	getchar();
	for(int loop = 0; loop < N; loop++){
		fgets(buf,100,stdin);

		assignment();

		MATRIX A = TABLE[buf[0]-'A'];
		int num_row = A.size();
		int num_col = A[0].size();

		for(int row = 0; row < num_row; row++){
			printf("%d",A[row][0]);
			for(int col = 1; col < num_col; col++){
				printf(" %d",A[row][col]);
			}
			printf("\n");
		}
	}
	printf("-----\n");
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

All modern mobile applications are divided into free and paid. Even a single application developers often release two versions: a paid version without ads and a free version with ads.

<image>

Suppose that a paid version of the app costs p (p is an integer) rubles, and the free version of the application contains c ad banners. Each user can be described by two integers: ai — the number of rubles this user is willing to pay for the paid version of the application, and bi — the number of banners he is willing to tolerate in the free version.

The behavior of each member shall be considered strictly deterministic:

  * if for user i, value bi is at least c, then he uses the free version,
  * otherwise, if value ai is at least p, then he buys the paid version without advertising,
  * otherwise the user simply does not use the application.

Each user of the free version brings the profit of c × w rubles. Each user of the paid version brings the profit of p rubles.

Your task is to help the application developers to select the optimal parameters p and c. Namely, knowing all the characteristics of users, for each value of c from 0 to (max bi) + 1 you need to determine the maximum profit from the application and the corresponding parameter p.

Input

The first line contains two integers n and w (1 ≤ n ≤ 105; 1 ≤ w ≤ 105) — the number of users and the profit from a single banner. Each of the next n lines contains two integers ai and bi (0 ≤ ai, bi ≤ 105) — the characteristics of the i-th user.

Output

Print (max bi) + 2 lines, in the i-th line print two integers: pay — the maximum gained profit at c = i - 1, p (0 ≤ p ≤ 109) — the corresponding optimal app cost. If there are multiple optimal solutions, print any of them.

Examples

Input

2 1
2 0
0 2

Output

0 3
3 2
4 2
2 2

Input

3 1
3 1
2 2
1 3

Output

0 4
3 4
7 3
7 2
4 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
void read(int &x) {
  int f = 1;
  x = 0;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int n, w, Maxb, Maxa, bel[N], nn, tim[350], q[350][350], qh[350], qt[350];
long long d[N];
struct node {
  int a, b;
} l[N];
double cmp(node a, node b) { return a.b != b.b ? a.b < b.b : a.a > b.a; }
double slope(int i, int j) { return (d[i] - d[j]) * 1.0 / (j - i); }
void add(int x) {
  if (!x) return;
  for (int i = 1; i < bel[x]; ++i) {
    tim[i]++;
    while (qh[i] < qt[i] && slope(q[i][qh[i]], q[i][qh[i] + 1]) <= tim[i])
      ++qh[i];
  }
  int l = (bel[x] - 1) * nn + 1, r = min(bel[x] * nn, Maxa), id = bel[x];
  for (int i = l; i <= r; ++i) d[i] += (long long)tim[id] * i;
  for (int i = l; i <= x; ++i) d[i] += i;
  tim[id] = 0;
  qh[id] = 1;
  qt[id] = 0;
  for (int i = l; i <= r; ++i) {
    while (qh[id] < qt[id] &&
           slope(q[id][qt[id]], i) < slope(q[id][qt[id] - 1], q[id][qt[id]]))
      --qt[id];
    q[id][++qt[id]] = i;
  }
  while (qh[id] < qt[id] && slope(q[id][qh[id]], q[id][qh[id] + 1]) <= 0)
    ++qh[id];
}
int main() {
  read(n);
  read(w);
  for (int i = 1; i <= n; i++)
    read(l[i].a), Maxa = max(Maxa, l[i].a), read(l[i].b),
                  Maxb = max(Maxb, l[i].b);
  sort(l + 1, l + n + 1, cmp);
  int now = 1;
  nn = sqrt(Maxa);
  for (int i = 1; i <= Maxa; i++) bel[i] = (i - 1) / nn + 1;
  int tot = bel[Maxa];
  for (int i = 1; i <= tot; i++) qh[i] = 1, q[i][++qt[i]] = min(i * nn, Maxa);
  for (int c = 0; c <= Maxb + 1; c++) {
    while (now <= n && l[now].b < c) add(l[now].a), ++now;
    long long ans = 0;
    int ans1 = 0;
    for (int i = 1; i <= tot; ++i) {
      int x = q[i][qh[i]];
      if (d[x] + (long long)x * tim[i] > ans)
        ans = d[x] + (long long)x * tim[i], ans1 = x;
    }
    printf("%lld %d\n", ans + (long long)w * c * (n - now + 1), ans1);
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Some company is going to hold a fair in Byteland. There are n towns in Byteland and m two-way roads between towns. Of course, you can reach any town from any other town using roads.

There are k types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least s different types of goods. It costs d(u,v) coins to bring goods from town u to town v where d(u,v) is the length of the shortest path from u to v. Length of a path is the number of roads in this path.

The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of n towns.

Input

There are 4 integers n, m, k, s in the first line of input (1 ≤ n ≤ 10^{5}, 0 ≤ m ≤ 10^{5}, 1 ≤ s ≤ k ≤ min(n, 100)) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair.

In the next line there are n integers a_1, a_2, …, a_n (1 ≤ a_{i} ≤ k), where a_i is the type of goods produced in the i-th town. It is guaranteed that all integers between 1 and k occur at least once among integers a_{i}.

In the next m lines roads are described. Each road is described by two integers u v (1 ≤ u, v ≤ n, u ≠ v) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.

Output

Print n numbers, the i-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town i. Separate numbers with spaces.

Examples

Input

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

Output

2 2 2 2 3

Input

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

Output

1 1 1 2 2 1 1

Note

Let's look at the first sample.

To hold a fair in town 1 you can bring goods from towns 1 (0 coins), 2 (1 coin) and 4 (1 coin). Total numbers of coins is 2.

Town 2: Goods from towns 2 (0), 1 (1), 3 (1). Sum equals 2.

Town 3: Goods from towns 3 (0), 2 (1), 4 (1). Sum equals 2.

Town 4: Goods from towns 4 (0), 1 (1), 5 (1). Sum equals 2.

Town 5: Goods from towns 5 (0), 4 (1), 3 (2). Sum equals 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, K, S, tot, x, y, k[100100], h[101][100100], dis[100100][101],
    ans[100100], head[100100], vis[100100];
struct Node {
  int y, nxt;
} side[200100];
void add(int x, int y) {
  tot++;
  side[tot].y = y;
  side[tot].nxt = head[x];
  head[x] = tot;
}
void BFS(int t) {
  queue<int> q;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= h[t][0]; i++)
    q.push(h[t][i]), dis[h[t][i]][t] = 0, vis[h[t][i]] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    vis[x] = 0;
    for (int i = head[x]; i; i = side[i].nxt) {
      int y = side[i].y;
      if (dis[y][t] > dis[x][t] + 1) {
        dis[y][t] = dis[x][t] + 1;
        if (!vis[y]) q.push(y), vis[y] = 1;
      }
    }
  }
}
int main() {
  cin >> n >> m >> K >> S;
  for (int i = 1; i <= n; i++) cin >> k[i], h[k[i]][++h[k[i]][0]] = i;
  for (int i = 1; i <= m; i++) cin >> x >> y, add(x, y), add(y, x);
  memset(dis, 0x3f, sizeof(dis));
  for (int i = 1; i <= K; i++) BFS(i);
  for (int i = 1; i <= n; i++) {
    sort(dis[i] + 1, dis[i] + 1 + K);
    for (int j = 1; j <= S; j++) ans[i] += dis[i][j];
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
}

```


### Prompt

Create a solution in cpp for the following problem:

The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame.

7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped.

The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D).

The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6.

<image> | <image>
--- | ---
Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6

<image> | <image>
--- | ---
Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state)

Input

Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given.

Output

For each puzzle, output the minimum number of steps to move to the final state on one line.

Example

Input

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

Output

0
1
28

### Response

```cpp
#include <iostream>
#include <set>
#include <queue>
#define SWAP(A,B,C) ((C)=(A),(A)=(B),(B)=(C))
using namespace std;
class State{
public:
  int p[2][4];
  int cost;
  int zx, zy;
  bool operator < (const State &s) const {
    for(int i = 0; i < 2; i++) {
      for(int j = 0; j < 4; j++) {
    if(p[i][j] != s.p[i][j]) return p[i][j] < s.p[i][j];
      }
    }
    return false;
  }
};

int dx[] = {0,1,0,-1},dy[] = {-1,0,1,0};
int main()
{
	State a;
	for(int i = 0;i<2;i++)
		for(int j = 0;j<4;j++)
			a.p[i][j] = i*4+j;
	a.cost = 0;a.zx=0;a.zy=0;
	set<State> data;data.insert(a);
	queue<State> q;q.push(a);

	while(!q.empty())
	{
		State b = q.front();q.pop();
		for(int i = 0;i<4;i++)
		{
			State tb = b;
			int nx = tb.zx + dx[i];
			int ny = tb.zy + dy[i];
			if(nx<0||nx>=4||ny<0||ny>=2)continue;
			tb.cost++;
			int temp;
			SWAP(tb.p[b.zy][b.zx],tb.p[ny][nx],temp);
			tb.zy = ny;tb.zx = nx;
			if(data.find(tb)!=data.end())continue;
			data.insert(tb);
			q.push(tb);
		}
	}
	State input;
	while(cin >> input.p[0][0]) {
    	for(int i = 1; i < 8; i++) {
      	cin >> input.p[i/4][i%4];
    	}
		cout << data.find(input)->cost << endl;
	}

}
```


### Prompt

Construct a cpp code solution to the problem outlined:

Let's solve the puzzle by programming.

The numbers n x n are arranged in a grid pattern. Some of the numbers are circled and we will call them the starting point. The rules of the puzzle are as follows:

* Draw one line that goes vertically and horizontally from each starting point (cannot be drawn diagonally).
* Extend the line so that the sum of the numbers passed is the same as the starting number.
* The line must not be branched.
* Lines cannot pass through numbers already drawn (lines must not intersect).
* A line cannot pass through more than one origin.

As shown in the figure below, the goal of the puzzle is to use all the starting points and draw lines on all the numbers.

<image>

Your job is to create a puzzle-solving program. However, in this problem, it is only necessary to determine whether the given puzzle can be solved.

Input

The input consists of multiple datasets. The format of each dataset is as follows:

n
n x n numbers

Indicates a puzzle given a number of n x n, the starting number is given as a negative number.

When n is 0, it indicates the end of input.

It can be assumed that n is 3 or more and 8 or less, numbers other than the starting point are 1 or more and 50 or less, and the starting point is -50 or more and -1 or less. You may also assume the following as the nature of the puzzle being entered:

* Each row and column of a given puzzle has at least one starting point.
* The number of starting points is about 20% to 40% of the total number of numbers (n x n).

Output

For each dataset, print "YES" if the puzzle can be solved, otherwise "NO" on one line.

Example

Input

3
-3 1 1
2 -4 1
2 1 -1
3
-4 1 1
1 1 -6
1 -5 3
4
-8 6 -2 1
2 -7 -2 1
1 -1 1 1
1 1 1 -5
6
2 2 3 -7 3 2
1 -10 1 1 3 2
2 6 5 2 -6 1
3 4 -23 2 2 5
3 3 -6 2 3 7
-7 2 3 2 -5 -13
6
2 2 3 -7 3 2
1 -10 1 1 3 2
2 6 5 2 -6 1
3 4 -23 2 2 5
3 3 -6 2 3 7
-7 2 3 2 -5 -12
0

Output

YES
NO
NO
YES
NO

### Response

```cpp
#include<iostream>
#include<vector>
#include<tuple>
using namespace std;
struct State { int x[8][8]; };
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int F[8][8], n; vector<tuple<int,int,int>>vec;
int solve(State S, int pos, int rec, int px, int py, int cnts) {
	if (pos == vec.size() - 1 && cnts == n*n) { return 1; }
	int cnt = 0;
	for (int i = 0; i < 4; i++) {
		int cx = px + dx[i], cy = py + dy[i];
		if (cx < 0 || cy < 0 || cx >= n || cy >= n || S.x[cx][cy] == 1)continue;
		if (F[cx][cy] + rec > get<2>(vec[pos]))continue;
		State T = S; T.x[cx][cy] = 1;
		if (F[cx][cy] + rec == get<2>(vec[pos])) {
			cnt += solve(T, pos + 1, 0, get<0>(vec[pos + 1]), get<1>(vec[pos + 1]), cnts + 1);
		}
		else {
			cnt += solve(T, pos, rec + F[cx][cy], cx, cy, cnts + 1);
		}
	}
	return cnt;
}
int main() {
	while (true) {
		cin >> n; if (n == 0)break; vec.clear();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> F[i][j];
				if (F[i][j] < 0)vec.push_back(make_tuple(i, j, -F[i][j]));
			}
		}
		State ST; vec.push_back(make_tuple(-1, -1, -1));
		for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ST.x[i][j] = 0; if (F[i][j] < 0)ST.x[i][j] = 1; } }
		int sum = solve(ST, 0, 0, get<0>(vec[0]), get<1>(vec[0]), vec.size() - 1);
		if (sum >= 1)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given two arrays a_1, a_2, ... , a_n and b_1, b_2, ... , b_m. Array b is sorted in ascending order (b_i < b_{i + 1} for each i from 1 to m - 1).

You have to divide the array a into m consecutive subarrays so that, for each i from 1 to m, the minimum on the i-th subarray is equal to b_i. Note that each element belongs to exactly one subarray, and they are formed in such a way: the first several elements of a compose the first subarray, the next several elements of a compose the second subarray, and so on.

For example, if a = [12, 10, 20, 20, 25, 30] and b = [10, 20, 30] then there are two good partitions of array a:

  1. [12, 10, 20], [20, 25], [30];
  2. [12, 10], [20, 20, 25], [30].

You have to calculate the number of ways to divide the array a. Since the number can be pretty large print it modulo 998244353.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the length of arrays a and b respectively.

The second line contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ 10^9) — the array a.

The third line contains m integers b_1, b_2, ... , b_m (1 ≤ b_i ≤ 10^9; b_i < b_{i+1}) — the array b.

Output

In only line print one integer — the number of ways to divide the array a modulo 998244353.

Examples

Input

6 3
12 10 20 20 25 30
10 20 30

Output

2

Input

4 2
1 3 3 7
3 7

Output

0

Input

8 2
1 2 2 2 2 2 2 2
1 2

Output

7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  long long n, m, i, j, cnt, flg, ans, chk, ini, fin;
  cin >> n >> m;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  chk = 0;
  flg = 0;
  long long b[m];
  long long fpos[m];
  long long ipos[m];
  for (i = 0; i < m; i++) {
    cin >> b[i];
    fpos[i] = -1;
    ipos[i] = -1;
  }
  j = m - 1;
  for (i = n - 1; i > -1 && j > -1; i--) {
    if (a[i] == b[j]) {
      if (ipos[j] == -1) ipos[j] = i;
    } else if (a[i] < b[j]) {
      if (ipos[j] == -1) {
        flg = 1;
        break;
      }
      if (j == 0) {
        flg = 1;
        break;
      }
      fpos[j] = i + 1;
      i++;
      j--;
      if (j < 0) break;
    }
  }
  for (i = 0; i < m; i++) {
    if (ipos[i] == -1) {
      flg = 1;
      break;
    }
  }
  fpos[0] = ipos[0];
  ans = 1;
  j = 0;
  i = 0;
  for (i = 0; i < m; i++) {
    ans = ((ans % mod) * ((ipos[i] - fpos[i] + 1) % mod)) % mod;
  }
  if (flg) {
    cout << 0;
  } else {
    cout << ans % mod;
  }
  cout << "\n";
}

```


### Prompt

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

Given is an integer N.

Takahashi chooses an integer a from the positive integers not greater than N with equal probability.

Find the probability that a is odd.

Constraints

* 1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the probability that a is odd. Your output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.

Examples

Input

4

Output

0.5000000000

Input

5

Output

0.6000000000

Input

1

Output

1.0000000000

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
  double n;
  cin >> n;
  cout << (int(n+1)/2/n) << endl;
  return 0;
}

```


### Prompt

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

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

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

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

Input

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

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

Output

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

Examples

Input

4
0 1 3 2

Output

1 0

Input

9
10 7 9 10 7 5 5 3 5

Output

4 14

Input

3
8 10 3

Output

0 8

Note

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

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

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, A[300005], B[300005], C[300005];
ll mergesort(int s, int e) {
  if (s == e) return 0;
  int mid = (s + e) >> 1;
  ll res = mergesort(s, mid) + mergesort(mid + 1, e);
  for (int i = s; i <= e; i++) C[i] = B[i];
  int i1 = s, i2 = mid + 1;
  for (int x = 0; x <= e - s; x++) {
    if (i1 > mid) {
      B[s + x] = C[i2++];
    } else if (i2 > e) {
      B[s + x] = C[i1++];
      res += i2 - mid - 1;
    } else if (C[i1] <= C[i2]) {
      B[s + x] = C[i1++];
      res += i2 - mid - 1;
    } else {
      B[s + x] = C[i2++];
    }
  }
  return res;
}
ll go(int bit) {
  for (int i = 1; i <= N; i++) B[i] = (A[i] ^ bit);
  return mergesort(1, N);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", A + i);
  int ans = 0;
  ll cur = go(0);
  for (int i = 30; ~i; i--) {
    ll res = go(ans | (1 << i));
    if (cur > res) {
      cur = res;
      ans |= (1 << i);
    }
  }
  printf("%lld %d\n", cur, ans);
}

```