### Prompt

Generate a Cpp solution to the following problem:

It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.

Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as pi the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and pi > pj.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.

Output

Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.

Examples

Input

5 2

Output

10

Input

1 10

Output

0

Note

In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.

In the second sample, there is only one cow, so the maximum possible messiness is 0.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128777216")
const int null = 0;
using namespace std;
template <class T, class Q>
class hash_map : unordered_map<T, Q> {};
template <class T>
int size(const T &a) {
  return int(a.size());
}
template <class T>
T abs(const T &a) {
  return (a < 0 ? -a : a);
}
template <class T>
T sqr(const T &a) {
  return a * a;
}
long long mod = int(1e9 + 7.1);
template <class T>
inline T msum(T a, T b) {
  return (a + b < mod ? a + b : a + b - mod);
}
template <class T>
inline void madd(T &a, T b) {
  a = msum(a, b);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  k = min(k, n / 2);
  cout << k * (n - k) + (n - k - k) * k + k * (k - 1) << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Thought it is already the XXI century, the Mass Media isn't very popular in Walrusland. The cities get news from messengers who can only travel along roads. The network of roads in Walrusland is built so that it is possible to get to any city from any other one in exactly one way, and the roads' lengths are equal.

The North Pole governor decided to carry out an information reform. Several cities were decided to be chosen and made regional centers. Maintaining a region center takes k fishlars (which is a local currency) per year. It is assumed that a regional center always has information on the latest news.

For every city which is not a regional center, it was decided to appoint a regional center which will be responsible for keeping this city informed. In that case the maintenance costs will be equal to dlen fishlars per year, where len is the distance from a city to the corresponding regional center, measured in the number of roads along which one needs to go.

Your task is to minimize the costs to carry out the reform.

Input

The first line contains two given numbers n and k (1 ≤ n ≤ 180, 1 ≤ k ≤ 105).

The second line contains n - 1 integers di, numbered starting with 1 (di ≤ di + 1, 0 ≤ di ≤ 105).

Next n - 1 lines contain the pairs of cities connected by a road.

Output

On the first line print the minimum number of fishlars needed for a year's maintenance. On the second line print n numbers, where the i-th number will represent the number of the regional center, appointed to the i-th city. If the i-th city is a regional center itself, then you should print number i.

If there are several solutions to that problem, print any of them.

Examples

Input

8 10
2 5 9 11 15 19 20
1 4
1 3
1 7
4 6
2 8
2 3
3 5

Output

38
3 3 3 4 3 4 3 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> e[301];
long long n, k, d[301], f[301][301], dp[301][301], mini[301], wwk[301];
void tr_dp(long long x, long long dd) {
  for (long long i = 1; i <= n; i++) dp[x][i] = d[f[x][i]] + k;
  for (long long i = 0; i < e[x].size(); i++) {
    long long y = e[x][i];
    if (dd == y) continue;
    tr_dp(y, x);
    for (long long j = 1; j <= n; j++)
      dp[x][j] += min(dp[y][mini[y]], dp[y][j] - k);
  }
  mini[x] = 1;
  for (long long i = 2; i <= n; i++)
    if (dp[x][i] < dp[x][mini[x]]) mini[x] = i;
}
void tr_put(long long x, long long dd, long long ff) {
  wwk[x] = ff;
  for (long long i = 0; i < e[x].size(); i++) {
    long long y = e[x][i];
    if (y == dd) continue;
    if (dp[y][mini[y]] < dp[y][ff] - k)
      tr_put(y, x, mini[y]);
    else
      tr_put(y, x, ff);
  }
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i < n; i++) scanf("%lld", &d[i]);
  memset(f, 0x3f3f3f3f, sizeof(f));
  for (long long i = 1; i <= n; i++) f[i][i] = 0;
  for (long long i = 1; i < n; i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
    f[a][b] = 1;
    f[b][a] = 1;
  }
  for (long long k = 1; k <= n; k++)
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= n; j++)
        f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
  tr_dp(1, 0);
  printf("%lld\n", dp[1][mini[1]]);
  tr_put(1, 0, mini[1]);
  for (long long i = 1; i <= n; i++) printf("%lld ", wwk[i]);
}

```


### Prompt

Create a solution in cpp for the following problem:

Limak is an old brown bear. He often goes bowling with his friends. Today he feels really good and tries to beat his own record!

For rolling a ball one gets a score — an integer (maybe negative) number of points. Score for i-th roll is multiplied by i and scores are summed up. So, for k rolls with scores s1, s2, ..., sk, total score is <image>. Total score is 0 if there were no rolls.

Limak made n rolls and got score ai for i-th of them. He wants to maximize his total score and he came up with an interesting idea. He will cancel some rolls, saying that something distracted him or there was a strong wind.

Limak is able to cancel any number of rolls, maybe even all or none of them. Total score is calculated as if there were only non-canceled rolls. Look at the sample tests for clarification. What maximum total score can Limak get?

Input

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

The second line contains n space-separated integers a1, a2, ..., an (|ai| ≤ 107) - scores for Limak's rolls.

Output

Print the maximum possible total score after choosing rolls to cancel.

Examples

Input

5
-2 -8 0 5 -3

Output

13

Input

6
-10 20 -30 40 -50 60

Output

400

Note

In first sample Limak should cancel rolls with scores  - 8 and  - 3. Then he is left with three rolls with scores  - 2, 0, 5. Total score is 1·( - 2) + 2·0 + 3·5 = 13.

In second sample Limak should cancel roll with score  - 50. Total score is 1·( - 10) + 2·20 + 3·( - 30) + 4·40 + 5·60 = 400.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
long long a[N], t[N], x[N], y[N], s[N];
int id[N], used[N], c[N];
vector<int> V[400];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  long long ans = 0, cur = 0;
  for (int i = 0; i < n; i++) cin >> a[i], cur += (i + 1) * a[i];
  ans = cur;
  for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
  auto cross = [&](int u, int v, int w) {
    return (x[v] - x[u]) * (y[w] - y[u]) - (x[w] - x[u]) * (y[v] - y[u]);
  };
  auto convex_hull = [&](vector<int> &a) {
    vector<int> b;
    for (int i : a) {
      while (b.size() > 1 && cross(b[b.size() - 2], b.back(), i) <= 0)
        b.pop_back();
      b.push_back(i);
    }
    a = b;
  };
  int m = 500;
  auto build = [&](int from, int to, int flag = 1) {
    int j = from / m;
    V[j].clear();
    int cnt = 0;
    long long tot = 0;
    for (int i = from; i < to; i++)
      if (!used[i]) tot += a[i];
    long long sum = 0;
    if (!flag) {
      for (int i = from; i < to; i++) id[i] = i;
      sort(id + from, id + to, [](int i, int j) { return a[i] > a[j]; });
    }
    for (int i = from; i < to; i++) {
      if (used[i])
        cnt++;
      else {
        sum += a[i];
        y[i] = (i + 1 - cnt) * 1LL * a[i] + tot - sum;
        x[i] = -a[i];
      }
    }
    vector<int> v;
    for (int i = from; i < to; i++) {
      int k = id[i];
      if (used[k]) continue;
      v.push_back(k);
    }
    for (int i = 0, k; i < v.size(); i = k) {
      auto cur = make_pair(y[v[i]], v[i]);
      for (k = i; k < v.size() && x[v[i]] == x[v[k]]; k++) {
        if (y[v[k]] < cur.first) {
          cur.first = y[v[k]];
          cur.second = v[k];
        }
      }
      V[j].push_back(cur.second);
    }
    convex_hull(V[j]);
    c[j] = cnt, t[j] = tot;
  };
  auto calc = [&](int u, long long p) {
    assert(abs(y[u]) <= 1.5e12);
    assert(abs(x[u]) <= 1.5e7);
    return p * x[u] + y[u];
  };
  for (int i = 0; i < n; i += m) build(i, min(n, i + m), 0);
  auto get = [&](int id, long long x) {
    auto ret = make_pair(LONG_LONG_MAX, -1);
    if (V[id].empty()) return ret;
    int st = 0, en = V[id].size() - 1;
    while (en - st > 2) {
      int mid1 = (st * 2 + en) / 3;
      int mid2 = (st + en * 2) / 3;
      long long ret1 = calc(V[id][mid1], x);
      long long ret2 = calc(V[id][mid2], x);
      if (ret1 < ret2) {
        en = mid2;
      } else {
        st = mid1;
      }
    }
    assert(st <= en);
    for (int i = st; i <= en; i++) {
      int u = V[id][i];
      long long cur = calc(u, x);
      if (cur < ret.first) {
        ret.first = cur;
        ret.second = u;
      }
    }
    return ret;
  };
  cur = s[n];
  long long cost = ans;
  for (int i = n - 1; i > 0; i--) {
    long long tsum = 0, csum = 0;
    long long dmin = LONG_LONG_MAX;
    int u = -1;
    int flag = 0;
    for (int j = 0; j < (n - 1) / m + 1; j++) {
      tsum += t[j];
      if (V[j].empty()) {
        csum += c[j];
        continue;
      }
      flag = 1;
      auto sol = get(j, csum);
      if (dmin > cur - tsum + sol.first) {
        dmin = cur - tsum + sol.first;
        u = sol.second;
      }
      csum += c[j];
    }
    assert(flag);
    cur -= a[u];
    cost -= dmin;
    used[u] = 1;
    build(u / m * m, min((u / m + 1) * m, n));
    ans = max(ans, cost);
  }
  ans = max(ans, 0LL);
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the solar system that contains the Death Star. However, this time the Empire has hidden the Death Star very well, and Heidi needs to find a place that appears on both maps in order to detect the Death Star.

The first map is an N × M grid, each cell of which shows some type of cosmic object that is present in the corresponding quadrant of space. The second map is an M × N grid. Heidi needs to align those two maps in such a way that they overlap over some M × M section in which all cosmic objects are identical. Help Heidi by identifying where such an M × M section lies within both maps.

Input

The first line of the input contains two space-separated integers N and M (1 ≤ N ≤ 2000, 1 ≤ M ≤ 200, M ≤ N). The next N lines each contain M lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next M lines each contain N characters, describing the second map in the same format.

Output

The only line of the output should contain two space-separated integers i and j, denoting that the section of size M × M in the first map that starts at the i-th row is equal to the section of the second map that starts at the j-th column. Rows and columns are numbered starting from 1.

If there are several possible ways to align the maps, Heidi will be satisfied with any of those. It is guaranteed that a solution exists.

Example

Input

10 5
somer
andom
noise
mayth
eforc
ebewi
thyou
hctwo
again
noise
somermayth
andomeforc
noiseebewi
againthyou
noisehctwo

Output

4 6

Note

The 5-by-5 grid for the first test case looks like this:

    mayth
    eforc
    ebewi
    thyou
    hctwo

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int p = 131;
int n, m;
char a[2005][205], b[205][2005];
unsigned int ha[2005];
unsigned int s1[2005], s2[2005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", a[i]);
    ha[i] = hash<string>()(string(a[i], a[i] + m));
  }
  for (int i = 0; i <= (n - m); ++i)
    for (int j = 0; j < m; ++j) s1[i] = s1[i] * p + ha[i + j];
  for (int i = 0; i < m; ++i) {
    scanf("%s", b[i]);
    for (int j = 0; j <= (n - m); ++j)
      s2[j] = s2[j] * p + hash<string>()(string(b[i] + j, b[i] + j + m));
  }
  for (int i = 0; i <= (n - m); ++i)
    for (int j = 0; j <= (n - m); ++j)
      if (s1[i] == s2[j]) {
        printf("%d %d\n", i + 1, j + 1);
        return 0;
      }
  return 0;
}

```


### Prompt

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

You are a paparazzi working in Manhattan.

Manhattan has r south-to-north streets, denoted by numbers 1, 2,…, r in order from west to east, and r west-to-east streets, denoted by numbers 1,2,…,r in order from south to north. Each of the r south-to-north streets intersects each of the r west-to-east streets; the intersection between the x-th south-to-north street and the y-th west-to-east street is denoted by (x, y). In order to move from the intersection (x,y) to the intersection (x', y') you need |x-x'|+|y-y'| minutes.

You know about the presence of n celebrities in the city and you want to take photos of as many of them as possible. More precisely, for each i=1,..., n, you know that the i-th celebrity will be at the intersection (x_i, y_i) in exactly t_i minutes from now (and he will stay there for a very short time, so you may take a photo of him only if at the t_i-th minute from now you are at the intersection (x_i, y_i)). You are very good at your job, so you are able to take photos instantaneously. You know that t_i < t_{i+1} for any i=1,2,…, n-1.

Currently you are at your office, which is located at the intersection (1, 1). If you plan your working day optimally, what is the maximum number of celebrities you can take a photo of?

Input

The first line of the input contains two positive integers r, n (1≤ r≤ 500, 1≤ n≤ 100,000) – the number of south-to-north/west-to-east streets and the number of celebrities.

Then n lines follow, each describing the appearance of a celebrity. The i-th of these lines contains 3 positive integers t_i, x_i, y_i (1≤ t_i≤ 1,000,000, 1≤ x_i, y_i≤ r) — denoting that the i-th celebrity will appear at the intersection (x_i, y_i) in t_i minutes from now.

It is guaranteed that t_i<t_{i+1} for any i=1,2,…, n-1.

Output

Print a single integer, the maximum number of celebrities you can take a photo of.

Examples

Input

10 1
11 6 8

Output

0

Input

6 9
1 2 6
7 5 1
8 5 5
10 3 1
12 4 4
13 6 2
17 6 6
20 1 4
21 5 4

Output

4

Input

10 4
1 2 1
5 10 9
13 8 8
15 9 9

Output

1

Input

500 10
69 477 122
73 186 235
341 101 145
372 77 497
390 117 440
494 471 37
522 300 498
682 149 379
821 486 359
855 157 386

Output

3

Note

Explanation of the first testcase: There is only one celebrity in the city, and he will be at intersection (6,8) exactly 11 minutes after the beginning of the working day. Since you are initially at (1,1) and you need |1-6|+|1-8|=5+7=12 minutes to reach (6,8) you cannot take a photo of the celebrity. Thus you cannot get any photo and the answer is 0.

Explanation of the second testcase: One way to take 4 photos (which is the maximum possible) is to take photos of celebrities with indexes 3, 5, 7, 9 (see the image for a visualization of the strategy):

  * To move from the office at (1,1) to the intersection (5,5) you need |1-5|+|1-5|=4+4=8 minutes, so you arrive at minute 8 and you are just in time to take a photo of celebrity 3.
  * Then, just after you have taken a photo of celebrity 3, you move toward the intersection (4,4). You need |5-4|+|5-4|=1+1=2 minutes to go there, so you arrive at minute 8+2=10 and you wait until minute 12, when celebrity 5 appears.
  * Then, just after you have taken a photo of celebrity 5, you go to the intersection (6,6). You need |4-6|+|4-6|=2+2=4 minutes to go there, so you arrive at minute 12+4=16 and you wait until minute 17, when celebrity 7 appears.
  * Then, just after you have taken a photo of celebrity 7, you go to the intersection (5,4). You need |6-5|+|6-4|=1+2=3 minutes to go there, so you arrive at minute 17+3=20 and you wait until minute 21 to take a photo of celebrity 9.

<image>

Explanation of the third testcase: The only way to take 1 photo (which is the maximum possible) is to take a photo of the celebrity with index 1 (since |2-1|+|1-1|=1, you can be at intersection (2,1) after exactly one minute, hence you are just in time to take a photo of celebrity 1).

Explanation of the fourth testcase: One way to take 3 photos (which is the maximum possible) is to take photos of celebrities with indexes 3, 8, 10:

  * To move from the office at (1,1) to the intersection (101,145) you need |1-101|+|1-145|=100+144=244 minutes, so you can manage to be there when the celebrity 3 appears (at minute 341).
  * Then, just after you have taken a photo of celebrity 3, you move toward the intersection (149,379). You need |101-149|+|145-379|=282 minutes to go there, so you arrive at minute 341+282=623 and you wait until minute 682, when celebrity 8 appears.
  * Then, just after you have taken a photo of celebrity 8, you go to the intersection (157,386). You need |149-157|+|379-386|=8+7=15 minutes to go there, so you arrive at minute 682+15=697 and you wait until minute 855 to take a photo of celebrity 10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_D = 1e3 + 100;
const int MAX_N = 1e5 + 5;
const int INF = 1e9 + 5;
int dp[MAX_N];
int cdp[MAX_N];
int x[MAX_N], y[MAX_N], t[MAX_N];
bool can(int i, int j) {
  return abs(x[i] - x[j]) + abs(y[i] - y[j]) <= abs(t[i] - t[j]);
}
int main() {
  int R, n;
  cin >> R >> n;
  x[0] = 1;
  y[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  cdp[0] = -INF;
  for (int i = 1; i <= n; i++) {
    dp[i] = -INF;
    if (can(0, i)) {
      dp[i] = 1;
    }
    for (int j = 1; j < MAX_D && 0 < i - j; j++) {
      if (can(i - j, i)) {
        dp[i] = max(dp[i], 1 + dp[i - j]);
      }
    }
    if (i - MAX_D > 0) {
      dp[i] = max(dp[i], 1 + cdp[i - MAX_D]);
    }
    cdp[i] = max(cdp[i - 1], dp[i]);
  }
  cout << max(0, cdp[n]) << '\n';
}

```


### Prompt

Generate a CPP solution to the following problem:

Boy Dima gave Julian a birthday present — set B consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!

Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two i and j with an edge if |i - j| belongs to B.

Unfortunately, Julian doesn't like the graph, that was built using B. Alex decided to rectify the situation, so he wants to erase some numbers from B, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from B so that graph constructed on the new set is bipartite.

Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.

Input

First line contains an integer n ~ (1 ⩽ n ⩽ 200 000) — size of B

Second line contains n integers b_1, b_2, …, b_n ~ (1 ⩽ b_i ⩽ 10^{18}) — numbers of B, all b_i are unique

Output

In the first line print single integer k – the number of erased elements. In the second line print k integers — values of erased elements.

If there are multiple answers, print any of them.

Examples

Input

3
1 2 3

Output

1
2

Input

2
2 6

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
int n, idx, cnt;
long long b[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < 60; i++) {
    long long c = 1LL << i;
    long long cc = c << 1;
    int tmp = 0;
    for (int j = 0; j < n; j++) {
      if (b[j] % c == 0 && b[j] % cc) tmp++;
    }
    if (tmp > cnt) {
      idx = i;
      cnt = tmp;
    }
  }
  cout << n - cnt << endl;
  for (int i = 0; i < n; i++) {
    long long c = 1LL << idx;
    long long cc = c << 1;
    if (!(b[i] % c == 0 && b[i] % cc)) {
      cout << b[i] << " ";
    }
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.

Constraints

* 1 ≤ N ≤ 50
* 1 ≤ K ≤ N
* S is a string of length N consisting of `A`, `B` and `C`.

Input

Input is given from Standard Input in the following format:

N K
S

Output

Print the string S after lowercasing the K-th character in it.

Examples

Input

3 1
ABC

Output

aBC

Input

4 3
CABA

Output

CAbA

### Response

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

int main(){
int N,K;
string S,A;
cin >> N >> K >> S;
S[K-1] = tolower(S[K-1]);
cout << S;
return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

You are given an undirected tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges.

Your task is to add the minimum number of edges in such a way that the length of the shortest path from the vertex 1 to any other vertex is at most 2. Note that you are not allowed to add loops and multiple edges.

Input

The first line contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of vertices in the tree.

The following n - 1 lines contain edges: edge i is given as a pair of vertices u_i, v_i (1 ≤ u_i, v_i ≤ n). It is guaranteed that the given edges form a tree. It is guaranteed that there are no loops and multiple edges in the given edges.

Output

Print a single integer — the minimum number of edges you have to add in order to make the shortest distance from the vertex 1 to any other vertex at most 2. Note that you are not allowed to add loops and multiple edges.

Examples

Input

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

Output

2

Input

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

Output

0

Input

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

Output

1

Note

The tree corresponding to the first example: <image> The answer is 2, some of the possible answers are the following: [(1, 5), (1, 6)], [(1, 4), (1, 7)], [(1, 6), (1, 7)].

The tree corresponding to the second example: <image> The answer is 0.

The tree corresponding to the third example: <image> The answer is 1, only one possible way to reach it is to add the edge (1, 3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> v[N];
int n;
int p[N];
int de[N];
void dfs(int now, int pre, int d = 0) {
  p[now] = pre;
  de[now] = d;
  for (auto k : v[now]) {
    if (k == pre) continue;
    dfs(k, now, d + 1);
  }
}
set<pair<int, int> > s;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int s, t;
    cin >> s >> t;
    v[s].push_back(t);
    v[t].push_back(s);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if (de[i] > 2) s.insert({-de[i], i});
  }
  int ans = 0;
  while (!s.empty()) {
    ans++;
    auto t = *s.begin();
    int vv = p[t.second];
    pair<int, int> x = {-de[vv], vv};
    auto G = s.find(x);
    if (G != s.end()) s.erase(G);
    for (auto k : v[vv]) {
      pair<int, int> x = {-de[k], k};
      auto G = s.find(x);
      if (G != s.end()) s.erase(G);
    }
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

Alexey recently held a programming contest for students from Berland. n students participated in a contest, i-th of them solved ai problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree, or won't receive any diplomas at all. Let cntx be the number of students that are awarded with diplomas of degree x (1 ≤ x ≤ 3). The following conditions must hold:

  * For each x (1 ≤ x ≤ 3) cntx > 0;
  * For any two degrees x and y cntx ≤ 2·cnty.

Of course, there are a lot of ways to distribute the diplomas. Let bi be the degree of diploma i-th student will receive (or  - 1 if i-th student won't receive any diplomas). Also for any x such that 1 ≤ x ≤ 3 let cx be the maximum number of problems solved by a student that receives a diploma of degree x, and dx be the minimum number of problems solved by a student that receives a diploma of degree x. Alexey wants to distribute the diplomas in such a way that:

  1. If student i solved more problems than student j, then he has to be awarded not worse than student j (it's impossible that student j receives a diploma and i doesn't receive any, and also it's impossible that both of them receive a diploma, but bj < bi);
  2. d1 - c2 is maximum possible;
  3. Among all ways that maximize the previous expression, d2 - c3 is maximum possible;
  4. Among all ways that correspond to the two previous conditions, d3 - c - 1 is maximum possible, where c - 1 is the maximum number of problems solved by a student that doesn't receive any diploma (or 0 if each student is awarded with some diploma).

Help Alexey to find a way to award the contestants!

Input

The first line contains one integer number n (3 ≤ n ≤ 3000).

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 5000).

Output

Output n numbers. i-th number must be equal to the degree of diploma i-th contestant will receive (or  - 1 if he doesn't receive any diploma).

If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists.

Examples

Input

4
1 2 3 4

Output

3 3 2 1

Input

6
1 4 3 1 1 2

Output

-1 1 2 -1 -1 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
vector<pair<int, int>> ds;
struct max_deque {
  int le, ri;
  int st[N];
  void reset() {
    le = 0;
    ri = -1;
  }
  max_deque() { reset(); }
  bool update(int l, int r) {
    if (l > r || l >= ds.size() || r < 0) return false;
    if (le > ri || st[ri] < l || st[le] > r)
      reset();
    else {
      while (le <= ri && st[le] < l) ++le;
    }
    if (le <= ri) l = max(l, st[ri] + 1);
    while (l <= r) {
      while (le <= ri && ds[st[ri]].first - ds[st[ri] + 1].first <
                             ds[l].first - ds[l + 1].first)
        --ri;
      st[++ri] = l;
      ++l;
    }
    return true;
  }
  int get() { return st[le]; }
};
max_deque dq;
pair<int, pair<int, int>> ans = {0, {0, 0}};
pair<int, pair<int, int>> kq;
int deg[N];
void answer(int cnt1, int cnt2, int cnt3) {
  int v1 = -ds[cnt1].first + ds[cnt1 - 1].first;
  int v2 = -ds[cnt1 + cnt2].first + ds[cnt1 + cnt2 - 1].first;
  int v3 = -ds[cnt1 + cnt2 + cnt3].first + ds[cnt1 + cnt2 + cnt3 - 1].first;
  pair<int, pair<int, int>> res = {v1, {v2, v3}};
  if (res > ans) {
    ans = res;
    kq = {cnt1, {cnt2, cnt3}};
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    ds.emplace_back(a, i);
  }
  sort(ds.begin(), ds.end(), greater<pair<int, int>>());
  ds.emplace_back(0, n + 1);
  for (int i = 0; i < n; i++) {
    int cnt1 = i + 1;
    dq.reset();
    for (int j = i + 1; j < n; j++) {
      int cnt2 = j - i;
      if (cnt2 <= cnt1 * 2 && cnt1 <= cnt2 * 2) {
        if (dq.update(j + (max(cnt1, cnt2) + 1) / 2,
                      min(j + 2 * min(cnt1, cnt2), n - 1)))
          answer(cnt1, cnt2, dq.get() - j);
      }
    }
  }
  int cnt1 = kq.first - 1;
  int cnt2 = cnt1 + kq.second.first;
  int cnt3 = cnt2 + kq.second.second;
  for (int i = 0; i < n; i++) {
    int t = -1;
    if (i <= cnt1)
      t = 1;
    else if (i <= cnt2)
      t = 2;
    else if (i <= cnt3)
      t = 3;
    deg[ds[i].second] = t;
  }
  for (int i = 1; i <= n; i++) printf("%d ", deg[i]);
}

```


### Prompt

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

A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:

* S is a palindrome.
* Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.
* The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.

Determine whether S is a strong palindrome.

Constraints

* S consists of lowercase English letters.
* The length of S is an odd number between 3 and 99 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

If S is a strong palindrome, print `Yes`; otherwise, print `No`.

Examples

Input

akasaka

Output

Yes

Input

level

Output

No

Input

atcoder

Output

No

### Response

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

int main(){
  string s;
  cin>>s;
  size_t n=s.length();
  for(int i=0;i<(n-1)/2;i++){
    if(s[i]!=s[(n+1)/2+i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

```


### Prompt

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

You are given a text consisting of n space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. w_i is the i-th word of text. All words consist only of lowercase Latin letters.

Let's denote a segment of words w[i..j] as a sequence of words w_i, w_{i + 1}, ..., w_j. Two segments of words w[i_1 .. j_1] and w[i_2 .. j_2] are considered equal if j_1 - i_1 = j_2 - i_2, j_1 ≥ i_1, j_2 ≥ i_2, and for every t ∈ [0, j_1 - i_1] w_{i_1 + t} = w_{i_2 + t}. For example, for the text "to be or not to be" the segments w[1..2] and w[5..6] are equal, they correspond to the words "to be".

An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words w[2..4] and w[6..8] with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words w[2..5] and w[6..9] with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c".

What is the minimum length of the text after at most one abbreviation?

Input

The first line of the input contains one integer n (1 ≤ n ≤ 300) — the number of words in the text.

The next line contains n space-separated words of the text w_1, w_2, ..., w_n. Each word consists only of lowercase Latin letters.

It is guaranteed that the length of text does not exceed 10^5.

Output

Print one integer — the minimum length of the text after at most one abbreviation.

Examples

Input

6
to be or not to be

Output

12

Input

10
a ab a a b ab a a b c

Output

13

Input

6
aa bb aa aa bb bb

Output

11

Note

In the first example you can obtain the text "TB or not TB".

In the second example you can obtain the text "a AAAB AAAB c".

In the third example you can obtain the text "AB aa AB bb".

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
template <typename T>
using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <typename T>
using max_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
using namespace std;
const long long A1 = 999999929;
const long long B1 = 999999937;
const long long A2 = 1000000007;
const long long B2 = 1000000009;
struct Hash {
  long long a, b;
  string orig;
  Hash(const string& s) {
    a = 0;
    b = 0;
    orig = s;
    long long A = 1;
    long long B = 1;
    for (int i = (s.length() - 1); i >= (0); i--) {
      int c = s[i];
      a = (a + A * c) % B1;
      b = (b + B * c) % B2;
      A *= A1;
      B *= A2;
    }
  }
  bool eq(Hash other) { return a == other.a && b == other.b; }
};
struct Data {
  Hash h = Hash("");
  int len;
  Data(const string& s) {
    h = Hash(s);
    len = s.length();
  }
};
vector<Data> words;
long long prefSum[100000];
int n;
int totalLength = 0, spaceLength;
vector<Data> make(int start, int len) {
  vector<Data> v;
  int i = start;
  while (v.size() < len && i < n) {
    v.push_back(words[i]);
    i++;
  }
  return v;
}
bool eq(std::pair<int, int> a, std::pair<int, int> b) {
  if (a.second - a.first != b.second - b.first) return false;
  for (int i = (a.first); i < (a.second); i++) {
    if (!words[i].h.eq(words[i - a.first + b.first].h)) return false;
  }
  return true;
}
long long getSum(int from, int to) {
  long long ans = prefSum[to];
  if (from > 0) ans -= prefSum[from - 1];
  return ans;
}
bool isPossible(int len) {
  for (int s1 = (0); s1 < (n - len + 1); s1++) {
    for (int s2 = (s1 + len); s2 < (n - len + 1); s2++) {
      std::pair<int, int> a = {s1, s1 + len};
      std::pair<int, int> b = {s2, s2 + len};
      if (eq(a, b)) {
        return true;
      }
    }
  }
  return false;
}
int solve(int len) {
  int best = ((1LL << 31) - 1);
  for (int s1 = (0); s1 < (n - len + 1); s1++) {
    vector<int> starts;
    for (int s2 = (s1 + len); s2 < (n - len + 1); s2++) {
      std::pair<int, int> a = {s1, s1 + len};
      std::pair<int, int> b = {s2, s2 + len};
      if (eq(a, b)) {
        starts.push_back(s2);
        s2 = s2 + len - 1;
      }
    }
    if (starts.size() > 0) {
      std::pair<int, int> a = {s1, s1 + len};
      int delta = getSum(a.first, a.second - 1);
      delta += a.second - a.first;
      delta -= a.second - a.first + 1;
      for (auto e : starts) {
        std::pair<int, int> b = {e, e + len};
        delta += getSum(b.first, b.second - 1);
        delta += b.second - b.first;
        delta -= b.second - b.first + 1;
      }
      best = min(best, totalLength - delta);
    }
  }
  return best;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  spaceLength = n - 1;
  for (int i = (0); i < (n); i++) {
    string s;
    cin >> s;
    totalLength += s.length();
    words.push_back(Data(s));
  }
  prefSum[0] = words[0].len;
  for (int i = (1); i < (n); i++) {
    prefSum[i] = prefSum[i - 1] + words[i].len;
  }
  totalLength += spaceLength;
  int best = totalLength;
  for (int len = (1); len < (n); len++) {
    best = min(best, solve(len));
  }
  cout << best << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Description

KULASIS is the name of a system developed and operated by the Higher Education Research and Development Promotion Organization for the purpose of providing information on common subjects throughout the university on the Web, supporting students and faculty members, and improving services. KULASIS started with the development of the online syllabus in 2003, and has gradually expanded the system to include Web bulletin boards, course registration, grades (scoring registration, scoring confirmation from students).
Students can use functions such as confirmation of academic affairs information (class cancellations, class changes, reports), course registration, and scoring confirmation from both inside and outside the university from a personal computer or mobile phone. The number of logins exceeds 10,000 on many days, and it has become widespread as an academic affairs information system at Kyoto University, and is indispensable for taking common courses throughout the university. We are developing this KULASIS so that it can be applied not only to common subjects throughout the university, but also to undergraduate specialized courses and graduate schools.
http://www.z.k.kyoto-u.ac.jp/introduction_kulasis.html

Q, a student at Kyoto University, was logged in to KULASIS to form a late syllabus. When I was wondering which subject I was going to enter, KULASIS suddenly gave off a dazzling light and moved to another page.
The page to which the transition was made was as shown in the figure below. The subject name and evaluation (impossible, acceptable, good, excellent) are written in the 5x5 square, and 16 ● buttons are arranged on the grid.
It was Q that I did not know what happened, but apparently when I press the ● button on the grid, the evaluation of the subjects in the upper right, lower right, upper left, and lower left is not possible → Yes, Yes → Good, Good → Excellent, Excellent → Impossible.

<image>

You can press the ● button as many times as you like.
I'm not sure if KULASIS has been rewritten by someone or if I'm dreaming, but if I can confirm my grades with this, Q wanted to get as good a grade as possible.
Confident that he was collecting a lot of credits, Q decided to maximize his fighting power in preparation for his assignment to the laboratory six months later than the number of credits itself.
Combat power is the total value of the evaluation of each subject converted into impossible → 0 points, acceptable → 60 points, good → 70 points, excellent → 80 points. It is thought (in the Q department) to show how superior it is.

Now that the subjects displayed on the KULASIS screen and their evaluations are given, please describe the program that outputs the maximum value of the combat power that can be obtained.

Input

The number of test cases is given on the first line of input. The number of test cases is guaranteed to be 100 or less.
From the second line onward, 5x5 numbers are lined up, and the evaluation of the subject displayed on the KULASIS screen is given, and 1,2,3,4 correspond to impossible, acceptable, good, and excellent, respectively.
If it is 0, no subject is registered in that frame.
The test cases are separated by a blank line.

Output

Output the maximum value of combat power that can be obtained for each test case.

Example

Input

5

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

1 1 1 0 0
1 1 1 1 0
1 0 1 1 0
0 0 1 1 1
1 1 1 1 1

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

4 3 4 3 4
3 4 3 4 3
4 3 4 3 4
3 4 3 4 3
4 3 4 3 4

2 2 2 2 2
0 0 0 2 0
2 2 0 2 0
2 2 0 2 0
0 0 0 2 0

Output

1280
1420
0
1920
1020

### Response

```cpp
// template {{{

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

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define all(c) std::begin(c), std::end(c)
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second
#define popcnt __builtin_popcountll

using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<double, double>;
using tp = tuple<int, int, int>;
using tp4 = tuple<int, int, int, int>;
using tp5 = tuple<int, int, int, int, int>;

template<typename T>
using max_pq = priority_queue<T, vector<T>, less<T>>;

template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int dx8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline bool chmax(T &x, U y){ if (x >= y) return false; x = y; return true; }

template<typename T, typename U>
inline bool chmin(T &x, U y){ if (x <= y) return false; x = y; return true; }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(std::begin(c), std::end(c)); c.erase(std::unique(all(c)), std::end(c)); }

// }}}

const int t[] = {0, 60, 70, 80};
bool f[5][5];
int a[5][5];
int dp[17][65536];

int calc(int p, int st)
{
	if (~dp[p][st]) return dp[p][st];
	if (p == 16) return 0;

	int res = 0;
	int ds = 0;
	int x = p / 4, y = p % 4;
	rep(i, 4){
		chmax(res, ds + calc(p + 1, (st * 4 + i) % 65536));
		rep(dx, 2) rep(dy, 2){
			if (f[x + dx][y + dy]){
				ds -= t[a[x + dx][y + dy]];
				++a[x + dx][y + dy] %= 4;
				ds += t[a[x + dx][y + dy]];
			}
		}
	}

	return dp[p][st] = res;
}

int main()
{
	int n;
	scanf("%d", &n);
	while (n--){
		rep(i, 5) rep(j, 5) scanf("%d", &a[i][j]), a[i][j]--;
		rep(i, 5) rep(j, 5) f[i][j] = a[i][j] >= 0;
		int sum = 0;
		rep(i, 5) rep(j, 5){
			if (f[i][j]) sum += t[a[i][j]];
		}
		memset(dp, -1, sizeof(dp));
		printf("%d\n", sum + calc(0, 0));
	}
}
```


### Prompt

Please formulate a cpp solution to the following problem:

When Mr. Kay was browsing a certain SNS as usual, the problem that "there are people who can solve IQ150 or more" came to the timeline. Mr. Kay has an IQ of over 150, so he solved the problem in an instant without even looking at it. For him, he doesn't have to work on such a mystery. It is enough to leave it to the computer.

problem

The following mysterious mathematical formula was written in the problem.

* \\ (5 + 3 = 28 \\)
* \\ (9 + 1 = 810 \\)
* \\ (8 + 6 = 214 \\)
* \\ (5 + 4 = 19 \\)
* \\ (2 + 2 = 4 \\)
* \\ (15 + 8 = 723 \\)
* \\ (7 + 9 = -216 \\)
* \\ (3 + 0 = 33 \\)

When thinking about the above operator \\ (+ \\), for a positive integer \\ (a \\) \\ (x \ geq 0, y \ geq 0 \\) and \\ (x + y =) Find the number of integer pairs \\ (x, y \\) such that a \\).

input

A positive integer \\ (a \\) is given on one line.

output

Output the number of pairs \\ ((x, y) \\) that satisfy \\ (a = x + y, x \ geq 0, y \ geq 0 \\) on one line.

Constraint

* \\ (1 \ leq a \ leq 10 ^ 9 (= 1000000000) \\)

Input / output example

Input 1

19

Output 1

1

There is one way of \\ (5 + 4 \\).

Input 2

twenty two

Output 2

2

There are two types: \\ (11 + 11 \\) and \\ (2 + 0 \\).

Input 3

1

Output 3

0

\\ (1 + 0 = 11, 0 + 1 = -11 \\). \\ (1 \\) cannot be generated.

Input 4

101

Output 4

0

Note that \\ (1 --0 \\) is not \\ (101 \\).

Input 5

660233276

Output 5

Four

Example

Input

19

Output

1

### Response

```cpp
#include<iostream>
#include<sstream>
#include<string>

using namespace std;

int string_to_int(const string& str){
  int n;
  istringstream iss(str);
  iss >> n;
  return n;
}

bool solve(const string& s, const string& t){
  if(t[0] == '0') return false;
  int x = s.empty() ? 0 : string_to_int(s);
  int y = string_to_int(t);
  if(x > y) return false;
  return (y-x)%2 == 0;
}

int main(){
  int ans=0;
  string str, s, t;
  cin >> str;
  for(int i=0; i<str.size(); ++i){
    s = str.substr(0, i);
    t = str.substr(i);
    if(s.size() > t.size()) break;
    if(solve(s, t)) ++ans;
  }
  cout << ans << endl;
  return 0;
}
```


### Prompt

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

Snuke has a string x of length N. Initially, every character in x is `0`.

Snuke can do the following two operations any number of times in any order:

* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.

Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).

Constraints

* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).

Examples

Input

4 2 3

Output

11

Input

10 7 2

Output

533

Input

1000 100 10

Output

828178524

### Response

```cpp
#include <cstdio>
#include <algorithm>

using namespace std;

const int mod = 1000000007;
int dp[5001];
int dp2[5001];
int dp3[5001][2];

int main() {
    int n, a, b, ans, i, j, k;

    scanf("%d %d %d", &n, &a, &b);

    if (a > b) swap(a, b);

    dp[1] = 1;

    for (i = 1; i < n; i++) {
        dp[i + 1] += dp[i];
        if (dp[i + 1] >= mod) dp[i + 1] -= mod;

        for (j = a + 1; i + j <= n; j++) {
            dp[i + j] += dp[i];
            if (dp[i + j] >= mod) dp[i + j] -= mod;
        }
    }

    dp2[0] = 1;

    for (i = 0; i < n; i++) {
        dp2[i + 1] += dp2[i];
        if (dp2[i + 1] >= mod) dp2[i + 1] -= mod;

        for (j = a + 1; i + j <= n; j++) {
            dp2[i + j] += dp2[i];
            if (dp2[i + j] >= mod) dp2[i + j] -= mod;
        }
    }

    for (i = 0; i < b; i++) dp3[i][1] = dp2[i];

    for (i = 0; i < n; i++) {
        for (j = 0; j < 2; j++) {
            if (dp3[i][j] == 0) continue;

            if (j != 0) {
                for (k = 1; k < a && i + k <= n; k++) {
                    dp3[i + k][0] += dp3[i][j];
                    if (dp3[i + k][0] >= mod) dp3[i + k][0] -= mod;
                }
            }

            if (j != 1) {
                for (k = 1; k < b && i + k < n; k++) {
                    dp3[i + k][1] += (long long)dp3[i][j] * dp[k] % mod;
                    if (dp3[i + k][1] >= mod) dp3[i + k][1] -= mod;
                }

                if (n - i < b) {
                    dp3[n][1] += (long long)dp3[i][j] * dp2[n - i] % mod;
                    if (dp3[n][1] >= mod) dp3[n][1] -= mod;
                }
            }
        }
    }

    ans = 1;
    for (i = 0; i < n; i++) ans = ans * 2 % mod;

    for (i = 0; i < 2; i++) {
        ans -= dp3[n][i];
        if (ans < 0) ans += mod;
    }

    printf("%d\n", ans);

    return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

The only difference between easy and hard versions is the length of the string.

You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).

For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".

You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.

If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).

Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Input

The first line of the input contains one string s consisting of at least 1 and at most 2 ⋅ 10^5 lowercase Latin letters.

The second line of the input contains one string t consisting of at least 1 and at most 2 ⋅ 10^5 lowercase Latin letters.

It is guaranteed that t is a subsequence of s.

Output

Print one integer — the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Examples

Input

bbaba
bb

Output

3

Input

baaba
ab

Output

2

Input

abcde
abcde

Output

0

Input

asdfasdf
fasd

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const string nl = "\n";
const long long MOD = 1000000007;
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  int j = m - 1;
  long long frnt[n], bck[n];
  long long cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    bck[i] = cnt;
    if (s[i] == t[j]) {
      cnt++;
      j--;
    }
  }
  j = 0;
  cnt = 0;
  for (int i = 0; i < n; i++) {
    frnt[i] = cnt;
    if (s[i] == t[j]) {
      cnt++;
      j++;
    }
  }
  int i = 0;
  j = 0;
  int mx = 0;
  while ((i < n) && (j < n)) {
    if (frnt[i] + bck[j] >= m) {
      j++;
    } else {
      mx = max(mx, j - i);
      if (i == j) j++;
      i++;
    }
  }
  mx = max(n - i, mx);
  cout << mx;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.

We'll call position i (1 ≤ i ≤ n) in permutation p1, p2, ..., pn good, if |p[i] - i| = 1. Count the number of permutations of size n with exactly k good positions. Print the answer modulo 1000000007 (109 + 7).

Input

The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 0 ≤ k ≤ n).

Output

Print the number of permutations of length n with exactly k good positions modulo 1000000007 (109 + 7).

Examples

Input

1 0

Output

1

Input

2 1

Output

0

Input

3 2

Output

4

Input

4 1

Output

6

Input

7 4

Output

328

Note

The only permutation of size 1 has 0 good positions.

Permutation (1, 2) has 0 good positions, and permutation (2, 1) has 2 positions.

Permutations of size 3:

  1. (1, 2, 3) — 0 positions
  2. <image> — 2 positions
  3. <image> — 2 positions
  4. <image> — 2 positions
  5. <image> — 2 positions
  6. (3, 2, 1) — 0 positions

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const long long mod = 1e9 + 7;
inline long long read() {
  long long ans = 0;
  char ch = getchar(), last = ' ';
  while (!isdigit(ch)) last = ch, ch = getchar();
  while (isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  if (last == '-') ans = -ans;
  return ans;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void MYFILE() {
  freopen("ha.in", "r", stdin);
  freopen("ha.out", "w", stdout);
}
int n, m;
long long dp[maxn][maxn][2][2], ans[maxn];
inline long long inc(long long a, long long b) {
  return a + b < mod ? a + b : a + b - mod;
}
long long fac[maxn], C[maxn][maxn];
inline void init() {
  fac[0] = 1;
  for (int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
  C[0][0] = 1;
  for (int i = 1; i < maxn; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = inc(C[i - 1][j - 1], C[i - 1][j]);
  }
}
int main() {
  n = read(), m = read();
  init();
  dp[0][0][1][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < i; ++j)
      for (int k = 0; k < 2; ++k)
        for (int h = 0; h < 2; ++h) {
          dp[i][j][h][0] = inc(dp[i][j][h][0], dp[i - 1][j][k][h]);
          if (!k)
            dp[i][j + 1][h][0] = inc(dp[i][j + 1][h][0], dp[i - 1][j][k][h]);
          if (i < n)
            dp[i][j + 1][h][1] = inc(dp[i][j + 1][h][1], dp[i - 1][j][k][h]);
        }
  for (int i = 0; i <= n; ++i) {
    for (int k = 0; k < 2; ++k)
      for (int h = 0; h < 2; ++h) ans[i] = inc(ans[i], dp[n][i][k][h]);
    ans[i] = ans[i] * fac[n - i] % mod;
  }
  for (int i = m + 1; i <= n; ++i) {
    long long tp = C[i][m] * ans[i] % mod;
    ans[m] = inc(ans[m], ((i - m) & 1) ? mod - tp : tp);
  }
  write(ans[m]), puts("");
  return 0;
}

```


### Prompt

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

Your task is to write a program which reads an expression and evaluates it.

* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109

Input

The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.

Output

For each datasets, prints the result of calculation.

Example

Input

2
4-2*3=
4*(8+4+3)=

Output

-2
60

### Response

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

int hyoka(string);
int isNum(int);

int main(){
	int n,i;
	string s;

	cin>>n;
	for(i=0;i<n;i++){
	 cin>>s;
	 cout<<hyoka(s)<<endl;
	}

	return 0;
}

int hyoka(string s){
	long int total=0,work=0;
	long int tmp1,tmp2;
	int oi=0;
	char oc;
	int n;
	string cs;

	if(s[oi]=='(' || isNum(s[oi])!=-1){s="+"+s;}
	//cout<<s<<endl;

	while(1){
	 oc=s[oi];if(oc=='='){total+=work;break;}

	 if(s[oi+1]!='('){	//??°???????????????
	  tmp1=0;
	  while(1){
	   oi++;
	   tmp2=isNum(s[oi]);
	   if(tmp2!=-1){tmp1=tmp1*10+tmp2;}else{break;}
	  }
	 }else{	//??????????????°
	  cs="";n=1;oi++;
	  while(1){
	   oi++;
	   switch(s[oi]){
		case '(':n++;break;
		case ')':n--;break;
	   }
	   if(n!=0){cs+=s[oi];}else{break;}
	  }
	  cs+='=';
	  //cout<<cs<<endl;
	  tmp1=hyoka(cs);
	 }

	 switch(oc){
	  case '+':total+=work;work=tmp1;break;
	  case '-':total+=work;work=-tmp1;break;
	  case '*':work*=tmp1;break;
	  case '/':work/=tmp1;break;
	 }
	}

	return total;
}

int isNum(int c){
	if(48<=c && c<=57){
	 return c-48;
	}
	return -1;
}
```


### Prompt

Create a solution in cpp for the following problem:

Inna loves sweets very much. That's why she decided to play a game called "Sweet Matrix".

Inna sees an n × m matrix and k candies. We'll index the matrix rows from 1 to n and the matrix columns from 1 to m. We'll represent the cell in the i-th row and j-th column as (i, j). Two cells (i, j) and (p, q) of the matrix are adjacent if |i - p| + |j - q| = 1. A path is a sequence of the matrix cells where each pair of neighbouring cells in the sequence is adjacent. We'll call the number of cells in the sequence the path's length.

Each cell of the matrix can have at most one candy. Initiallly, all the cells are empty. Inna is trying to place each of the k candies in the matrix one by one. For each candy Inna chooses cell (i, j) that will contains the candy, and also chooses the path that starts in cell (1, 1) and ends in cell (i, j) and doesn't contain any candies. After that Inna moves the candy along the path from cell (1, 1) to cell (i, j), where the candy stays forever. If at some moment Inna can't choose a path for the candy, she loses. If Inna can place all the candies in the matrix in the described manner, then her penalty equals the sum of lengths of all the paths she has used.

Help Inna to minimize the penalty in the game.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 1 ≤ k ≤ n·m).

Output

In the first line print an integer — Inna's minimum penalty in the game.

In the next k lines print the description of the path for each candy. The description of the path of the candy that is placed i-th should follow on the i-th line. The description of a path is a sequence of cells. Each cell must be written in the format (i, j), where i is the number of the row and j is the number of the column. You are allowed to print extra whitespaces in the line. If there are multiple optimal solutions, print any of them.

Please follow the output format strictly! If your program passes the first pretest, then the output format is correct.

Examples

Input

4 4 4

Output

8
(1,1) (2,1) (2,2)
(1,1) (1,2)
(1,1) (2,1)
(1,1)

Note

Note to the sample. Initially the matrix is empty. Then Inna follows her first path, the path penalty equals the number of cells in it — 3. Note that now no path can go through cell (2, 2), as it now contains a candy. The next two candies go to cells (1, 2) and (2, 1). Inna simply leaves the last candy at cell (1, 1), the path contains only this cell. The total penalty is: 3 + 2 + 2 + 1 = 8.

Note that Inna couldn't use cell (1, 1) to place, for instance, the third candy as in this case she couldn't have made the path for the fourth candy.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, -1, 0, 0};
int dy[] = {0, 0, 0, 1, -1};
pair<int, int> sir[100 * 100];
pair<int, int> T[100][100];
queue<pair<int, int> > q;
int n, m, sol, k, t, D[100][100];
void go(int x, int y) {
  if (x == 1 && y == 1) {
    cout << "(1,1) ";
    return;
  }
  go(T[x][y].first, T[x][y].second);
  cout << "(" << x << "," << y << ") ";
}
void bfs(int x, int y) {
  q.push(make_pair(x, y));
  D[x][y] = 1;
  while (!q.empty()) {
    pair<int, int> a = q.front();
    q.pop();
    sir[++t] = a;
    if (t == k) return;
    for (int i = 1; i <= 4; ++i) {
      x = a.first + dx[i];
      y = a.second + dy[i];
      if (x < 1 || x > n || y < 1 || y > m) continue;
      if (D[x][y]) continue;
      D[x][y] = D[a.first][a.second] + 1;
      T[x][y] = make_pair(a.first, a.second);
      q.push(make_pair(x, y));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  bfs(1, 1);
  for (int i = 1; i <= k; ++i) sol += D[sir[i].first][sir[i].second];
  cout << sol << "\n";
  for (int i = k; i >= 1; --i) {
    go(sir[i].first, sir[i].second);
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).

Input

The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).

Output

Print a single integer — the number of k-good numbers in a.

Examples

Input

10 6
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560

Output

10

Input

2 1
1
10

Output

1

### Response

```cpp
#include <bits/stdc++.h>
char L[11];
int k, l, n, ok, C[10];
int main() {
  scanf("%d %d", &n, &k);
  while (n--) {
    memset(C, 0, sizeof(C));
    scanf("%s", L);
    for (int i = 0; L[i]; i++) {
      C[L[i] - '0'] = 1;
    }
    ok = 1;
    for (int i = 0; i <= k; i++) {
      if (!C[i]) {
        ok = 0;
        break;
      }
    }
    if (ok) l++;
  }
  printf("%d\n", l);
  return 0;
}

```


### Prompt

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

Polycarp's phone book contains n phone numbers, each of them is described by s_i — the number itself and m_i — the number of times Polycarp dials it in daily.

Polycarp has just bought a brand new phone with an amazing speed dial feature! More precisely, k buttons on it can have a number assigned to it (not necessary from the phone book). To enter some number Polycarp can press one of these k buttons and then finish the number using usual digit buttons (entering a number with only digit buttons is also possible).

Speed dial button can only be used when no digits are entered. No button can have its number reassigned.

What is the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way?

Input

The first line contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ 10) — the amount of numbers in Polycarp's phone book and the number of speed dial buttons his new phone has.

The i-th of the next n lines contain a string s_i and an integer m_i (1 ≤ m_i ≤ 500), where s_i is a non-empty string of digits from 0 to 9 inclusive (the i-th number), and m_i is the amount of times it will be dialed, respectively.

It is guaranteed that the total length of all phone numbers will not exceed 500.

Output

Print a single integer — the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way.

Examples

Input

3 1
0001 5
001 4
01 1

Output

14

Input

3 1
0001 5
001 6
01 1

Output

18

Note

The only speed dial button in the first example should have "0001" on it. The total number of digit button presses will be 0 ⋅ 5 for the first number + 3 ⋅ 4 for the second + 2 ⋅ 1 for the third. 14 in total.

The only speed dial button in the second example should have "00" on it. The total number of digit button presses will be 2 ⋅ 5 for the first number + 1 ⋅ 6 for the second + 2 ⋅ 1 for the third. 18 in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, K, f[N][N][20], val[N], fa[N][N], ans = 0, cnt = 1;
int nxt[N][12], v[N], siz[N], tmp[N][12], dep[N];
char str[N];
void dfs(int u) {
  fa[u][0] = u;
  siz[u] = 1;
  for (int i = 0; i <= dep[u]; i++) f[u][i][!i] = dep[fa[u][i]] * v[u];
  for (int i = 0; i < 10; i++)
    if (nxt[u][i]) {
      int v = nxt[u][i];
      dep[v] = dep[u] + 1;
      for (int j = 0; j <= dep[u]; j++) fa[v][j + 1] = fa[u][j];
      dfs(v);
      for (int j = 0; j <= dep[u]; j++) {
        for (int k = 0; k <= siz[u] && k <= K; k++) {
          tmp[j][k] = f[u][j][k];
          f[u][j][k] = -0x7ffffff;
        }
      }
      for (int j = 0; j <= dep[u]; j++) {
        for (int k = 0; k <= siz[u] && k <= K; k++) {
          for (int l = 0; l <= siz[v] && l + k <= K; l++) {
            f[u][j][k + l] = max(f[u][j][k + l],
                                 tmp[j][k] + max(f[v][j + 1][l], f[v][0][l]));
          }
        }
      }
      siz[u] += siz[v];
    }
}
int main() {
  memset(f, 0xc0, sizeof(f));
  scanf("%d%d", &n, &K);
  K++;
  for (int i = 1, l, p; i <= n; i++) {
    scanf("%s%d", str + 1, &val[i]);
    l = strlen(str + 1);
    ans += l * val[i];
    p = 1;
    for (int j = 1; j <= l; j++) {
      int &k = nxt[p][str[j] - '0'];
      if (!k) k = ++cnt;
      p = k;
    }
    v[p] += val[i];
  }
  dfs(1);
  int mx = 0;
  for (int i = 1; i <= K; i++) mx = max(mx, f[1][0][i]);
  printf("%d\n", ans - mx);
}

```


### Prompt

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

A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.

Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i.

Your task is to count the number of almost identity permutations for given numbers n and k.

Input

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

Output

Print the number of almost identity permutations for given n and k.

Examples

Input

4 1

Output

1

Input

4 2

Output

7

Input

5 3

Output

31

Input

5 4

Output

76

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long Det[20000];
long long C[2000];
void det() {
  Det[0] = 1;
  Det[1] = 0;
  Det[2] = 1;
  for (long long i = 3; i <= 10009; i++) {
    Det[i] = (i - 1) * (Det[i - 1] + Det[i - 2]);
  }
}
long long binomialCoeff(long long n, long long k) {
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
int main() {
  long long i, j, k, l, m, n, ans = 0;
  det();
  cin >> n >> k;
  m = n - k;
  for (i = m; i <= n; i++) {
    ans += (binomialCoeff(n, i) * Det[n - i]);
  }
  cout << ans << endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Description

THE BY DOLM @ STER is a training simulation game scheduled to be released on EXIDNA by 1rem on April 1, 2010. For the time being, it probably has nothing to do with an arcade game where the network connection service stopped earlier this month.
This game is a game in which members of the unit (formation) to be produced are selected from the bidders, and through lessons and communication with the members, they (they) are raised to the top of the bidders, the top biddles.
Each bidle has three parameters, vocal, dance, and looks, and the unit's ability score is the sum of all the parameters of the biddles that belong to the unit. The highest of the three stats of a unit is the rank of the unit.
There is no limit to the number of people in a unit, and you can work as a unit with one, three, or 100 members. Of course, you can hire more than one of the same bidle, but hiring a bidle is expensive and must be taken into account.
As a producer, you decided to write and calculate a program to make the best unit.

Input

The input consists of multiple test cases.
The first line of each test case is given the number N of bid dollars and the available cost M. (1 <= N, M <= 300) The next 2 * N lines contain information about each bidle.
The name of the bidle is on the first line of the bidle information. Biddle names consist of alphabets and spaces, with 30 characters or less. Also, there is no bidle with the same name.
The second line is given the integers C, V, D, L. C is the cost of hiring one Biddle, V is the vocal, D is the dance, and L is the stat of the looks. (1 <= C, V, D, L <= 300)
Input ends with EOF.

Output

Answer the maximum rank of units that can be made within the given cost.
If you cannot make a unit, output 0.

Example

Input

3 10
Dobkeradops
7 5 23 10
PataPata
1 1 2 1
dop
5 3 11 14
2 300
Bydo System Alpha
7 11 4 7
Green Inferno
300 300 300 300

Output

29
462

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define MP make_pair

using namespace std;

typedef pair<int, int> P;

int dp[500];
int main(){
	int n, m;
	while(cin >> n >> m){
		vector<int> c(n);
		vector<vector<int> > v(3, vector<int>(n));
		rep(i, n){
			cin.ignore();
			string s;
			getline(cin, s);
			cin >> c[i] >> v[0][i] >> v[1][i] >> v[2][i];
		}
		int ans = 0;
		rep(j, 3){
			memset(dp, -1, sizeof(dp));
			dp[0] = 0;
			for(int k = 0; k < n; k++){
				for(int i = c[k]; i <= m; i++){
					if(dp[i-c[k]] != -1) dp[i] = max(dp[i], dp[i-c[k]]+v[j][k]);
				}
			}
			ans = max(ans, *max_element(dp, dp+500));
		}
		cout << ans << endl;
	}

	return 0;
}
```


### Prompt

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

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

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

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

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

Input

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

Output

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

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

Examples

Input

3
1 3
1 2
0 5

Output

3 1 3
3 2 2

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
struct var {
  long long x, y, wt;
};
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq1, pq2;
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 0; i < n; i++) {
      long long c, s;
      cin >> c >> s;
      if (c == 0) {
        pq1.push({s, i + 1});
      } else {
        pq2.push({s, i + 1});
      }
    }
    long long rem = 0;
    long long val = 0;
    pair<long long, long long> x1, y1, prev_x1;
    prev_x1 = {0, 0};
    vector<var> v1;
    while (!pq1.empty() || !pq2.empty()) {
      long long flag = 0;
      if (rem == 0) {
        if (!pq1.empty()) {
          flag++;
          x1 = pq1.top();
          pq1.pop();
          rem = x1.first;
        }
      }
      if (val == 0) {
        if (!pq2.empty()) {
          flag++;
          y1 = pq2.top();
          pq2.pop();
          val = y1.first;
        }
      }
      if (flag == 2 && prev_x1.second != 0) {
        v1.push_back({prev_x1.second, y1.second, 0});
      }
      long long temp = min(val, rem);
      val -= temp;
      rem -= temp;
      prev_x1 = x1;
      v1.push_back({x1.second, y1.second, temp});
    }
    for (auto p : v1) {
      cout << p.x << " " << p.y << " " << p.wt << '\n';
    }
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value:

* Operation A: The displayed value is doubled.
* Operation B: The displayed value increases by K.

Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.

Constraints

* 1 \leq N, K \leq 10
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the minimum possible value displayed in the board after N operations.

Examples

Input

4
3

Output

10

Input

10
10

Output

76

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
	int ans=1,n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		ans+=min(ans,k);
	}
	cout<<ans<<endl;
}
```


### Prompt

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

Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.

A set ρ of pairs (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation ρ, if pair <image>, in this case we use a notation <image>.

Binary relation is equivalence relation, if:

  1. It is reflexive (for any a it is true that <image>);
  2. It is symmetric (for any a, b it is true that if <image>, then <image>);
  3. It is transitive (if <image> and <image>, than <image>).

Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":

Take any two elements, a and b. If <image>, then <image> (according to property (2)), which means <image> (according to property (3)).

It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.

Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).

Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.

Input

A single line contains a single integer n (1 ≤ n ≤ 4000).

Output

In a single line print the answer to the problem modulo 109 + 7.

Examples

Input

1

Output

1

Input

2

Output

3

Input

3

Output

10

Note

If n = 1 there is only one such relation — an empty one, i.e. <image>. In other words, for a single element x of set A the following is hold: <image>.

If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are <image>, ρ = {(x, x)}, ρ = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
istream& operator>>(istream& is, __int128_t& x) {
  x = 0;
  string s;
  is >> s;
  int n = int(s.size()), it = 0;
  if (s[0] == '-') it++;
  for (; it < n; it++) x = (x * 10 + s[it] - '0');
  if (s[0] == '-') x = -x;
  return is;
}
ostream& operator<<(ostream& os, __int128_t x) {
  if (x == 0) return os << 0;
  if (x < 0) os << '-', x = -x;
  deque<int> deq;
  while (x) deq.emplace_front(x % 10), x /= 10;
  for (int e : deq) os << e;
  return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < int(v.size()); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "}";
}
template <class Container>
inline int SZ(Container& v) {
  return int(v.size());
}
template <class T>
inline void UNIQUE(vector<T>& v) {
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T1, class T2>
inline bool chmax(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2>
inline bool chmin(T1& a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline int topbit(int x) { return x == 0 ? -1 : 31 - __builtin_clz(x); }
inline int topbit(long long x) { return x == 0 ? -1 : 63 - __builtin_clzll(x); }
inline int botbit(int x) { return x == 0 ? 32 : __builtin_ctz(x); }
inline int botbit(long long x) { return x == 0 ? 64 : __builtin_ctzll(x); }
inline int popcount(int x) { return __builtin_popcount(x); }
inline int popcount(long long x) { return __builtin_popcountll(x); }
inline int kthbit(long long x, int k) { return (x >> k) & 1; }
inline constexpr long long TEN(int x) { return x == 0 ? 1 : TEN(x - 1) * 10; }
inline void print() { cout << "\n"; }
template <class T>
inline void print(const vector<T>& v) {
  for (int i = 0; i < int(v.size()); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  print();
}
template <class T, class... Args>
inline void print(const T& x, const Args&... args) {
  cout << x << " ";
  print(args...);
}
struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <int m>
struct ModInt {
 public:
  static constexpr int mod() { return m; }
  static ModInt raw(int v) {
    ModInt x;
    x._v = v;
    return x;
  }
  ModInt() : _v(0) {}
  ModInt(long long v) {
    long long x = (long long)(v % (long long)(umod()));
    if (x < 0) x += umod();
    _v = (unsigned int)(x);
  }
  unsigned int val() const { return _v; }
  ModInt& operator++() {
    _v++;
    if (_v == umod()) _v = 0;
    return *this;
  }
  ModInt& operator--() {
    if (_v == 0) _v = umod();
    _v--;
    return *this;
  }
  ModInt operator++(int) {
    ModInt result = *this;
    ++*this;
    return result;
  }
  ModInt operator--(int) {
    ModInt result = *this;
    --*this;
    return result;
  }
  ModInt& operator+=(const ModInt& rhs) {
    _v += rhs._v;
    if (_v >= umod()) _v -= umod();
    return *this;
  }
  ModInt& operator-=(const ModInt& rhs) {
    _v -= rhs._v;
    if (_v >= umod()) _v += umod();
    return *this;
  }
  ModInt& operator*=(const ModInt& rhs) {
    unsigned long long z = _v;
    z *= rhs._v;
    _v = (unsigned int)(z % umod());
    return *this;
  }
  ModInt& operator^=(long long n) {
    ModInt x = *this;
    *this = 1;
    if (n < 0) x = x.inv(), n = -n;
    while (n) {
      if (n & 1) *this *= x;
      x *= x;
      n >>= 1;
    }
    return *this;
  }
  ModInt& operator/=(const ModInt& rhs) { return *this = *this * rhs.inv(); }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { return ModInt() - *this; }
  ModInt pow(long long n) const {
    ModInt r = *this;
    r ^= n;
    return r;
  }
  ModInt inv() const {
    int a = _v, b = umod(), y = 1, z = 0, t;
    for (;;) {
      t = a / b;
      a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a;
      b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  friend ModInt operator+(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) += rhs;
  }
  friend ModInt operator-(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) -= rhs;
  }
  friend ModInt operator*(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) *= rhs;
  }
  friend ModInt operator/(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) /= rhs;
  }
  friend ModInt operator^(const ModInt& lhs, long long rhs) {
    return ModInt(lhs) ^= rhs;
  }
  friend bool operator==(const ModInt& lhs, const ModInt& rhs) {
    return lhs._v == rhs._v;
  }
  friend bool operator!=(const ModInt& lhs, const ModInt& rhs) {
    return lhs._v != rhs._v;
  }
  friend ModInt operator+(long long lhs, const ModInt& rhs) {
    return (ModInt(lhs) += rhs);
  }
  friend ModInt operator-(long long lhs, const ModInt& rhs) {
    return (ModInt(lhs) -= rhs);
  }
  friend ModInt operator*(long long lhs, const ModInt& rhs) {
    return (ModInt(lhs) *= rhs);
  }
  friend ostream& operator<<(ostream& os, const ModInt& rhs) {
    return os << rhs._v;
  }

 private:
  unsigned int _v;
  static constexpr unsigned int umod() { return m; }
};
constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;
struct ModCombination {
  vector<mint> Fac, Facinv;
  ModCombination(int x) {
    Fac.resize(x + 1);
    Facinv.resize(x + 1);
    Fac[0] = 1;
    for (int i = 0; i < x; ++i) Fac[i + 1] = Fac[i] * (i + 1);
    Facinv[x] = Fac[0] / Fac[x];
    for (int i = x; i > 0; --i) Facinv[i - 1] = Facinv[i] * i;
  }
  mint get(int n, int k) {
    if (k < 0 || k > n) return 0;
    return Fac[n] * Facinv[k] * Facinv[n - k];
  }
};
int main() {
  int N;
  cin >> N;
  ModCombination MC(100000);
  vector<vector<mint>> dp(N + 1, vector<mint>(N + 1));
  dp[0][0] = 1;
  for (int i = 0; i < (N); i++) {
    for (int j = 0; j < (N + 1); j++) {
      dp[i + 1][j] += dp[i][j] * j;
      if (j < N) dp[i + 1][j + 1] += dp[i][j];
    }
  }
  mint ans = 0;
  for (int i = 0; i < (N); i++)
    for (int j = 0; j < (i + 1); j++) ans += dp[i][j] * MC.get(N, i);
  cout << ans << ln;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

There are n piles of stones, where the i-th pile has a_i stones. Two people play a game, where they take alternating turns removing stones.

In a move, a player may remove a positive number of stones from the first non-empty pile (the pile with the minimal index, that has at least one stone). The first player who cannot make a move (because all piles are empty) loses the game. If both players play optimally, determine the winner of the game.

Input

The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next 2t lines contain descriptions of test cases.

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

The second line of each test case contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of stones in the i-th pile.

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

Output

For each test case, if the player who makes the first move will win, output "First". Otherwise, output "Second".

Example

Input

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

Output

First
Second
Second
First
First
Second
First

Note

In the first test case, the first player will win the game. His winning strategy is:

  1. The first player should take the stones from the first pile. He will take 1 stone. The numbers of stones in piles will be [1, 5, 4].
  2. The second player should take the stones from the first pile. He will take 1 stone because he can't take any other number of stones. The numbers of stones in piles will be [0, 5, 4].
  3. The first player should take the stones from the second pile because the first pile is empty. He will take 4 stones. The numbers of stones in piles will be [0, 1, 4].
  4. The second player should take the stones from the second pile because the first pile is empty. He will take 1 stone because he can't take any other number of stones. The numbers of stones in piles will be [0, 0, 4].
  5. The first player should take the stones from the third pile because the first and second piles are empty. He will take 4 stones. The numbers of stones in piles will be [0, 0, 0].
  6. The second player will lose the game because all piles will be empty.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b = 0, c = 0, n, t;
  cin >> t;
  for (int o = 1; o <= t; o++) {
    b = 0;
    c = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a;
      if (a != 1) {
        c = 1;
      } else {
        if (c == 0) {
          b = b + 1;
        }
      }
    }
    if (n == 1) {
      cout << "First";
    } else {
      if (c == 0) {
        if (n % 2 == 0) {
          cout << "Second";
        } else {
          cout << "First";
        }
      } else {
        if (b % 2 == 0) {
          cout << "First";
        } else {
          cout << "Second";
        }
      }
    }
    cout << endl;
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph.

Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no more than k. Distance between two vertices of the tree is the minimum possible number of edges of the path between them.

As this number of ways to paint the tree can be large, Ostap wants you to compute it modulo 109 + 7. Two ways to paint the tree are considered different if there exists a vertex that is painted black in one way and is not painted in the other one.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ min(20, n - 1)) — the number of vertices in Ostap's tree and the maximum allowed distance to the nearest black vertex. Don't miss the unusual constraint for k.

Each of the next n - 1 lines contain two integers ui and vi (1 ≤ ui, vi ≤ n) — indices of vertices, connected by the i-th edge. It's guaranteed that given graph is a tree.

Output

Print one integer — the remainder of division of the number of ways to paint the tree by 1 000 000 007 (109 + 7).

Examples

Input

2 0
1 2

Output

1

Input

2 1
1 2

Output

3

Input

4 1
1 2
2 3
3 4

Output

9

Input

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

Output

91

Note

In the first sample, Ostap has to paint both vertices black.

In the second sample, it is enough to paint only one of two vertices, thus the answer is 3: Ostap can paint only vertex 1, only vertex 2, vertices 1 and 2 both.

In the third sample, the valid ways to paint vertices are: {1, 3}, {1, 4}, {2, 3}, {2, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 110;
const int M = 30;
const int moder = (int)1e9 + 7;
int dp[N][M][M], sz[N], tmp[M][M];
int n, k;
std::vector<int> e[N];
inline void addmult(int &a, int b, int c) { a = (a + 1ll * b * c) % moder; }
inline void add(int &a, int b) {
  a += b;
  a -= a >= moder ? moder : 0;
}
inline void sub(int &a, int b) {
  a -= b;
  a += a < 0 ? moder : 0;
}
void dfs(int u, int fa) {
  sz[u] = 1;
  dp[u][0][0] = 1;
  for (auto v : e[u]) {
    if (v == fa) {
      continue;
    }
    dfs(v, u);
    memset(tmp, 0, sizeof(tmp));
    for (int i = 0; i <= k && i <= sz[u]; ++i) {
      for (int j = 0; j <= k && j <= sz[v]; ++j) {
        for (int a = 0; a <= k && a <= sz[u]; ++a) {
          if (dp[u][i][a] == 0 || (j > 0 && a > 0 && j + a <= k)) {
            continue;
          }
          for (int b = 0; b <= k && b <= sz[v]; ++b) {
            if (dp[v][j][b] == 0 || (i > 0 && b > 0 && i + b <= k)) {
              continue;
            }
            int ni = i == 0 ? j : j == 0 ? i : std::min(i, j);
            int nj = a == 0 ? b : b == 0 ? a : std::min(a, b);
            addmult(tmp[ni][nj], dp[u][i][a], dp[v][j][b]);
          }
        }
      }
    }
    memcpy(dp[u], tmp, sizeof(tmp));
    sz[u] += sz[v];
  }
  memset(tmp, 0, sizeof(tmp));
  for (int j = 0; j <= k; ++j) {
    sub(tmp[0][1], dp[u][0][j]);
  }
  for (int i = 0; i <= k; ++i) {
    add(tmp[1][0], dp[u][i][0]);
  }
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      int ni = i == 0 || i == k ? 0 : i + 1;
      int nj = j == 0 || j == k ? 0 : j + 1;
      add(tmp[ni][nj], dp[u][i][j]);
    }
  }
  memcpy(dp[u], tmp, sizeof(tmp));
}
int main() {
  srand((unsigned)time(nullptr));
  scanf("%d%d", &n, &k);
  for (int i = 0, u, v; i < n - 1; ++i) {
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  int root = rand() % n + 1;
  dfs(root, 0);
  int sum = 0;
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      add(sum, dp[root][i][j]);
    }
  }
  printf("%d\n", sum);
  return 0;
}

```


### Prompt

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

A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").

You are given a list of commands that will be given to the turtle. You have to change exactly n commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list?

Input

The first line of input contains a string commands — the original list of commands. The string commands contains between 1 and 100 characters, inclusive, and contains only characters "T" and "F".

The second line contains an integer n (1 ≤ n ≤ 50) — the number of commands you have to change in the list.

Output

Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list.

Examples

Input

FT
1

Output

2

Input

FFFTFFF
2

Output

6

Note

In the first example the best option is to change the second command ("T") to "F" — this way the turtle will cover a distance of 2 units.

In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
string s;
int n;
int best = 0;
int a[111][55][211][3];
void go(int pos, int change, int x, int dx) {
  if (a[pos][change][x + 100][dx + 1]) return;
  a[pos][change][x + 100][dx + 1] = 1;
  if (pos == s.size()) {
    if (change == 0) best = max(best, abs(x));
    return;
  }
  for (int i(0); i < (change + 1); i++) {
    int val = (s[pos] == 'F');
    if (i % 2) val ^= 1;
    go(pos + 1, change - i, x + (val == 1 ? dx : 0), dx * (val == 0 ? -1 : 1));
  }
}
int main() {
  cin >> s >> n;
  go(0, n, 0, 1);
  cout << best << endl;
  return 0;
}

```


### Prompt

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

Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the stack is empty, then the operation pop() does nothing.

Nikita made m operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the i-th step he remembers an operation he made pi-th. In other words, he remembers the operations in order of some permutation p1, p2, ..., pm. After each step Nikita wants to know what is the integer on the top of the stack after performing the operations he have already remembered, in the corresponding order. Help him!

Input

The first line contains the integer m (1 ≤ m ≤ 105) — the number of operations Nikita made.

The next m lines contain the operations Nikita remembers. The i-th line starts with two integers pi and ti (1 ≤ pi ≤ m, ti = 0 or ti = 1) — the index of operation he remembers on the step i, and the type of the operation. ti equals 0, if the operation is pop(), and 1, is the operation is push(x). If the operation is push(x), the line also contains the integer xi (1 ≤ xi ≤ 106) — the integer added to the stack.

It is guaranteed that each integer from 1 to m is present exactly once among integers pi.

Output

Print m integers. The integer i should equal the number on the top of the stack after performing all the operations Nikita remembered on the steps from 1 to i. If the stack is empty after performing all these operations, print -1.

Examples

Input

2
2 1 2
1 0

Output

2
2

Input

3
1 1 2
2 1 3
3 0

Output

2
3
2

Input

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

Output

-1
-1
-1
-1
2

Note

In the first example, after Nikita remembers the operation on the first step, the operation push(2) is the only operation, so the answer is 2. After he remembers the operation pop() which was done before push(2), answer stays the same.

In the second example, the operations are push(2), push(3) and pop(). Nikita remembers them in the order they were performed.

In the third example Nikita remembers the operations in the reversed order.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const bool D = 0;
struct Query {
  int p, t, x;
  friend istream &operator>>(istream &stream, Query &query) {
    stream >> query.p >> query.t;
    if (query.t == 1) {
      stream >> query.x;
    } else {
      query.t = -1;
    }
    --query.p;
    return stream;
  }
  friend ostream &operator<<(ostream &stream, Query &query) {
    stream << query.p << " " << query.t;
    if (query.t == 1) {
      stream << " " << query.x;
    }
    return stream;
  }
};
struct SegmentTree {
  vector<int> tree, pushing;
  void build(int n) {
    tree.clear();
    pushing.clear();
    tree.resize(4 * n, 0);
    pushing.resize(4 * n, 0);
  }
  void push(int v, int l, int r) {
    if (l < r) {
      tree[v * 2] += pushing[v];
      tree[v * 2 + 1] += pushing[v];
      pushing[v * 2] += pushing[v];
      pushing[v * 2 + 1] += pushing[v];
    }
    pushing[v] = 0;
  }
  void update(int v, int tl, int tr, int l, int r, int x) {
    push(v, tl, tr);
    if (l > r) {
      return;
    }
    if (tl == l && tr == r) {
      tree[v] += x;
      pushing[v] += x;
      return;
    }
    int tm = (tl + tr) / 2;
    update(v * 2, tl, tm, l, min(tm, r), x);
    update(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, x);
    tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
  }
  int get(int v, int tl, int tr, int l, int r, int k) {
    push(v, tl, tr);
    if (l > r) {
      return -1;
    }
    if (tree[v] < k) {
      return -1;
    }
    if (tl == tr) {
      return tl;
    }
    int tm = (tl + tr) / 2;
    if (tree[v * 2 + 1] >= k) {
      return get(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, k);
    }
    return get(v * 2, tl, tm, l, min(tm, r), k);
  }
};
int n, position;
vector<int> values;
vector<Query> queries;
SegmentTree tr;
int main() {
  cin >> n;
  queries.resize(n);
  values.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> queries[i];
    if (D) {
      cout << queries[i] << endl;
    }
    if (queries[i].t == 1) {
      values[queries[i].p] = queries[i].x;
    }
  }
  tr.build(n);
  for (int i = 0; i < n; ++i) {
    tr.update(1, 0, n - 1, 0, queries[i].p, queries[i].t);
    position = tr.get(1, 0, n - 1, 0, n - 1, 1);
    if (position == -1) {
      cout << position << endl;
    } else {
      cout << values[position] << endl;
    }
  }
  return 0;
}

```


### Prompt

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

There is a weighted tree with n nodes and n-1 edges. The nodes are conveniently labeled from 1 to n. The weights are positive integers at most 100. Define the distance between two nodes to be the sum of edges on the unique path between the nodes. You would like to find the diameter of the tree. Diameter is the maximum distance between a pair of nodes.

Unfortunately, the tree isn't given to you, but you can ask some questions about it. In one question, you can specify two nonempty disjoint sets of nodes p and q, and the judge will return the maximum distance between a node in p and a node in q. In the words, maximum distance between x and y, where x ∈ p and y ∈ q. After asking not more than 9 questions, you must report the maximum distance between any pair of nodes.

Interaction

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1 000). Description of the test cases follows.

The first line of each test case contains an integer n (2 ≤ n ≤ 100) — the number of nodes in the tree.

To ask a question, print "k_1\ k_2\ a_1\ a_2\ …\ a_{k_1}\ b_1\ b_2\ …\ b_{k_2}" (k_1, k_2 ≥ 1 and k_1+k_2 ≤ n). These two sets must be nonempty and disjoint. The judge will respond with a single integer max_{p,q} dist(a_p, b_q). If you ever get a result of -1 (because you printed an invalid query), exit immediately to avoid getting other verdicts.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

When you are ready to answer, print "-1\ d", where d is the maximum shortest distance over all pairs of nodes.

You can only ask at most 9 questions per test case.

Hack Format

To hack, use the following format. Note that you can only hack with one test case.

The first line should contain a single integer t (t=1).

The second line should contain a single integer n (2 ≤ n ≤ 100).

Each of the next n-1 lines should contain three integers a_i, b_i, c_i (1≤ a_i, b_i≤ n, 1 ≤ c_i ≤ 100). This denotes an undirected edge between nodes a_i and b_i with weight c_i. These edges must form a tree.

Example

Input

2
5
9
6
10
9
10
2
99

Output

1 4 1 2 3 4 5
1 4 2 3 4 5 1
1 4 3 4 5 1 2
1 4 4 5 1 2 3
1 4 5 1 2 3 4
-1 10
1 1 1 2
-1 99

Note

In the first example, the first tree looks as follows: <image>

In the first question, we have p = {1}, and q = {2, 3, 4, 5}. The maximum distance between a node in p and a node in q is 9 (the distance between nodes 1 and 5).

The second tree is a tree with two nodes with an edge with weight 99 between them.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int x;
long long int query(long long int x, long long int y) {
  printf("1 %lld ", y - x + 1);
  printf("1 ");
  for (long long int i = x; i <= y; i++) printf("%lld ", i);
  fflush(stdout);
  long long int inp;
  cin >> inp;
  return inp;
}
int main() {
  long long int n, i, j, k, y, t, m;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int start = 2;
    long long int end = n;
    printf("1 %lld ", n - 1);
    printf("1 ");
    for (i = 2; i <= n; i++) printf("%lld ", i);
    fflush(stdout);
    cin >> x;
    while (start < end) {
      long long int mid = (start + end) / 2;
      if (query(start, mid) == x) {
        end = mid;
      } else {
        start = mid + 1;
      }
    }
    printf("1 %lld ", n - 1);
    printf("%lld ", start);
    for (i = 1; i <= n; i++) {
      if (i != start) printf("%lld ", i);
    }
    fflush(stdout);
    cin >> x;
    printf("-1 ");
    cout << x << endl;
  }
}

```