### Prompt

Create a solution in Cpp for the following problem:

An extension of a complex number is called a quaternion. It is a convenient number that can be used to control the arm of a robot because it is convenient for expressing the rotation of an object. Quaternions are $ using four real numbers $ x $, $ y $, $ z $, $ w $ and special numbers (extended imaginary numbers) $ i $, $ j $, $ k $. It is expressed as x + yi + zj + wk $. The sum of such quaternions is defined as:

$ (x_1 + y_1 i + z_1 j + w_1 k) + (x_2 + y_2 i + z_2 j + w_2 k) = (x_1 + x_2) + (y_1 + y_2) i + (z_1 + z_2) j + (w_1 + w_2) k $

On the other hand, the product between 1, $ i $, $ j $, and $ k $ is given as follows.

<image>

This table represents the product $ AB $ of two special numbers $ A $ and $ B $. For example, the product $ ij $ of $ i $ and $ j $ is $ k $, and the product $ ji $ of $ j $ and $ i $ is $ -k $.

The product of common quaternions is calculated to satisfy this relationship. For example, the product of two quaternions, $ 1 + 2i + 3j + 4k $ and $ 7 + 6i + 7j + 8k $, is calculated as follows:

$ (1 + 2i + 3j + 4k) \ times (7 + 6i + 7j + 8k) = $
$ 7 + 6i + 7j + 8k $
$ + 14i + 12i ^ 2 + 14ij + 16ik $
$ + 21j + 18ji + 21j ^ 2 + 24jk $
$ + 28k + 24ki + 28kj + 32k ^ 2 $

By applying the table above

$ = -58 + 16i + 36j + 32k $

It will be.

Two quaternions ($ x_1 + y_1 i + z_1 j + w_1 k $) and ($) where the four coefficients $ x $, $ y $, $ z $, $ w $ are integers and not all zeros x_2 + y_2 i + z_2 j + w_2 k $), and the product is ($ x_3 + y_3 i + z_3 j + w_3 k $), $ x_3 $, $ y_3 $, $ z_3 $, $ Create a program that outputs w_3 $.

input

Given multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

$ n $
$ data_1 $
$ data_2 $
::
$ data_n $

The first line gives the number of pairs of quaternions to process $ n $ ($ n \ leq 10 $). The following $ n $ line is given the $ i $ th quaternion pair of information $ data_i $ in the following format:

$ x_1 $ $ y_1 $ $ z_1 $ $ w_1 $ $ x_2 $ $ y_2 $ $ z_2 $ $ w_2 $

All coefficients given should be -1000 or more and 1000 or less. The number of datasets does not exceed 50.

output

Prints the product of a given set of quaternions for each dataset.

Example

Input

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

Output

-58 16 36 32
-50 32 28 48

### Response

```cpp
#include <iostream>

using namespace std;

int main(){
  int N;

  while(cin >> N, N){
    int x,y,z,w;
    int x1,y1,z1,w1,x2,y2,z2,w2;
    for(int i = 0 ; i < N ; i++){
      cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
      x = x1*x2-y1*y2-z1*z2-w1*w2;
      y = x1*y2+x2*y1+z1*w2-w1*z2;
      z = x1*z2-y1*w2+x2*z1+w1*y2;
      w = x1*w2+y1*z2-z1*y2+w1*x2;
      cout << x << " " << y << " " << z << " " << w << endl;
    }
  }

  return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

A permutation p is an ordered group of numbers p1, p2, ..., pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1, p2, ..., pn.

Simon has a positive integer n and a non-negative integer k, such that 2k ≤ n. Help him find permutation a of length 2n, such that it meets this equation: <image>.

Input

The first line contains two integers n and k (1 ≤ n ≤ 50000, 0 ≤ 2k ≤ n).

Output

Print 2n integers a1, a2, ..., a2n — the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.

Examples

Input

1 0

Output

1 2

Input

2 1

Output

3 2 1 4

Input

4 0

Output

2 7 4 6 1 3 5 8

Note

Record |x| represents the absolute value of number x.

In the first sample |1 - 2| - |1 - 2| = 0.

In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.

In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, ans[100005], t, i, j;
  cin >> n >> k;
  if (k == 0) {
    for (i = 1; i <= 2 * n; i++) ans[i] = i;
  } else {
    ans[1] = 1;
    ans[2] = 1 + k;
    t = 2 * n;
    i = 3;
    while (i <= 2 * n) {
      if (t != (1 + k) && t != 1) {
        ans[i] = t;
        t--;
        i = i + 2;
      } else
        t--;
    }
    j = 4;
    while (j <= 2 * n) {
      if (t != 1 + k && t != 1) {
        ans[j] = t;
        t--;
        j = j + 2;
      } else
        t--;
    }
  }
  for (i = 1; i <= 2 * n; i++) cout << ans[i] << " ";
  return 0;
}

```


### Prompt

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

You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the expected value of the number of inversions in the resulting permutation.

Input

The first line of input contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 109). The next line contains n integers p1, p2, ..., pn — the given permutation. All pi are different and in range from 1 to n.

The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.

  * In subproblem G1 (3 points), the constraints 1 ≤ n ≤ 6, 1 ≤ k ≤ 4 will hold.
  * In subproblem G2 (5 points), the constraints 1 ≤ n ≤ 30, 1 ≤ k ≤ 200 will hold.
  * In subproblem G3 (16 points), the constraints 1 ≤ n ≤ 100, 1 ≤ k ≤ 109 will hold.

Output

Output the answer with absolute or relative error no more than 1e - 9.

Examples

Input

3 1
1 2 3

Output

0.833333333333333

Input

3 4
1 3 2

Output

1.458333333333334

Note

Consider the first sample test. We will randomly pick an interval of the permutation (1, 2, 3) (which has no inversions) and reverse the order of its elements. With probability <image>, the interval will consist of a single element and the permutation will not be altered. With probability <image> we will inverse the first two elements' order and obtain the permutation (2, 1, 3) which has one inversion. With the same probability we might pick the interval consisting of the last two elements which will lead to the permutation (1, 3, 2) with one inversion. Finally, with probability <image> the randomly picked interval will contain all elements, leading to the permutation (3, 2, 1) with 3 inversions. Hence, the expected number of inversions is equal to <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
int p[10];
long double rek(int k) {
  if (k == 0) {
    int x = 0;
    for (int i = 0; i < n; ++i)
      for (int j = i + 1; j < n; ++j)
        if (p[i] > p[j]) ++x;
    return x;
  }
  long double R = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j) {
      int sz = j - i + 1;
      for (int kk = 0; kk < sz / 2; ++kk) swap(p[i + kk], p[j - kk]);
      R += rek(k - 1);
      for (int kk = 0; kk < sz / 2; ++kk) swap(p[i + kk], p[j - kk]);
    }
  R /= n;
  R /= n + 1;
  R *= 2;
  return R;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", p + i);
  printf("%.12lf\n", (double)rek(k));
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.

Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the resulting word must be prefix of at least one string from the group. A player loses if he cannot move.

Andrew and Alex decided to play this game k times. The player who is the loser of the i-th game makes the first move in the (i + 1)-th game. Guys decided that the winner of all games is the player who wins the last (k-th) game. Andrew and Alex already started the game. Fedor wants to know who wins the game if both players will play optimally. Help him.

Input

The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109).

Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters.

Output

If the player who moves first wins, print "First", otherwise print "Second" (without the quotes).

Examples

Input

2 3
a
b

Output

First

Input

3 1
a
b
c

Output

First

Input

1 2
ab

Output

Second

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int n, k, sz, trie[MAX][26];
bool win[MAX], lose[MAX];
char s[MAX];
void dfs(int u) {
  int ady = 0;
  for (int i = 0; i < 26; i++) {
    if (trie[u][i] == 0) continue;
    ady++;
    int v = trie[u][i];
    dfs(v);
    win[u] |= !win[v];
    lose[u] |= !lose[v];
  }
  if (ady == 0) {
    win[u] = 0;
    lose[u] = 1;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    int l = strlen(s);
    int r = 0;
    for (int i = 0; i < l; i++) {
      int c = s[i] - 'a';
      if (trie[r][c] == 0) trie[r][c] = ++sz;
      r = trie[r][c];
    }
  }
  dfs(0);
  if (win[0] && lose[0])
    printf("First\n");
  else if (win[0] && !lose[0]) {
    if (k & 1)
      printf("First\n");
    else
      printf("Second\n");
  } else if (!win[0] && lose[0])
    printf("Second\n");
  else
    printf("Second\n");
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_form)

In the other words, CNF is a formula of type <image>, where & represents a logical "AND" (conjunction), <image> represents a logical "OR" (disjunction), and vij are some boolean variables or their negations. Each statement in brackets is called a clause, and vij are called literals.

You are given a CNF containing variables x1, ..., xm and their negations. We know that each variable occurs in at most two clauses (with negation and without negation in total). Your task is to determine whether this CNF is satisfiable, that is, whether there are such values of variables where the CNF value is true. If CNF is satisfiable, then you also need to determine the values of the variables at which the CNF is true.

It is guaranteed that each variable occurs at most once in each clause.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 2·105) — the number of clauses and the number variables, correspondingly.

Next n lines contain the descriptions of each clause. The i-th line first contains first number ki (ki ≥ 1) — the number of literals in the i-th clauses. Then follow space-separated literals vij (1 ≤ |vij| ≤ m). A literal that corresponds to vij is x|vij| either with negation, if vij is negative, or without negation otherwise.

Output

If CNF is not satisfiable, print a single line "NO" (without the quotes), otherwise print two strings: string "YES" (without the quotes), and then a string of m numbers zero or one — the values of variables in satisfying assignment in the order from x1 to xm.

Examples

Input

2 2
2 1 -2
2 2 -1

Output

YES
11

Input

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

Output

NO

Input

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

Output

YES
100010

Note

In the first sample test formula is <image>. One of possible answer is x1 = TRUE, x2 = TRUE.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n, m, l, a;
int idx[400005][2];
vector<int> model;
vector<vector<int> > clauses;
vector<bool> satisfied;
bool impossible;
int cntDetermined;
stack<pair<vector<int>, vector<int> > > st;
bool isDeterministic(int i) {
  int k = idx[i][0];
  if (i > m) i -= m;
  for (int l = 0; l < (int)clauses[k].size(); l++) {
    int ii = clauses[k][l];
    if (abs(ii) == i) continue;
    if (model[abs(ii)] == -1) return 0;
  }
  return 1;
}
void findModel(int i);
void updateSatisfied(int i) {
  satisfied[i] = 1;
  for (int j = 0; j < (int)clauses[i].size(); j++) {
    int next = clauses[i][j];
    if (model[abs(next)] == -1) {
      if (next < 0) next = abs(next) + m;
      if (idx[next][0] == i)
        idx[next][0] = idx[next][1];
      else
        idx[next][1] = -1;
      if (idx[next][0] == -1) {
        if (next > m) next -= m;
        findModel(next);
      }
    }
  }
}
void findModel(int i) {
  if (idx[i][0] == -1 && idx[i + m][0] == -1) {
    model[i] = 1;
    cntDetermined++;
    return;
  } else if (idx[i][0] == -1) {
    model[i] = 0;
    cntDetermined++;
    if (satisfied[idx[i + m][0]] == 0) updateSatisfied(idx[i + m][0]);
    if (idx[i + m][1] != -1 && satisfied[idx[i + m][1]] == 0)
      updateSatisfied(idx[i + m][1]);
  } else if (idx[i + m][0] == -1) {
    model[i] = 1;
    cntDetermined++;
    if (satisfied[idx[i][0]] == 0) updateSatisfied(idx[i][0]);
    if (idx[i][1] != -1 && satisfied[idx[i][1]] == 0)
      updateSatisfied(idx[i][1]);
  } else {
    if (satisfied[idx[i][0]] && satisfied[idx[i + m][0]]) {
      model[i] = 1;
      cntDetermined++;
      return;
    } else if (satisfied[idx[i][0]]) {
      model[i] = 0;
      cntDetermined++;
      updateSatisfied(idx[i + m][0]);
      return;
    } else if (satisfied[idx[i + m][0]]) {
      model[i] = 1;
      cntDetermined++;
      updateSatisfied(idx[i][0]);
      return;
    }
    bool determined = isDeterministic(i);
    if (determined) {
      model[i] = 1;
      cntDetermined++;
      if (satisfied[idx[i][0]] == 0) updateSatisfied(idx[i][0]);
      return;
    }
    determined = isDeterministic(i + m);
    if (determined) {
      model[i] = 0;
      cntDetermined++;
      if (satisfied[idx[i + m][0]] == 0) updateSatisfied(idx[i + m][0]);
      return;
    }
  }
}
void findModel(int i, vector<int>& idx1, vector<int>& idx2);
void updateSatisfied(int i, vector<int>& idx1, vector<int>& idx2) {
  satisfied[i] = 1;
  idx2.push_back(i);
  for (int j = 0; j < (int)clauses[i].size(); j++) {
    int next = clauses[i][j];
    if (model[abs(next)] == -1) {
      if (next < 0) next = abs(next) + m;
      if (idx[next][0] == i)
        idx[next][0] = idx[next][1];
      else
        idx[next][1] = -1;
      if (idx[next][0] == -1) {
        if (next > m) next -= m;
        findModel(next, idx1, idx2);
      }
    }
  }
}
void findModel(int i, vector<int>& idx1, vector<int>& idx2) {
  if (idx[i][0] == -1 && idx[i + m][0] == -1) {
    model[i] = 1;
    idx1.push_back(i);
    cntDetermined++;
    return;
  } else if (idx[i][0] == -1) {
    model[i] = 0;
    idx1.push_back(i);
    cntDetermined++;
    if (satisfied[idx[i + m][0]] == 0) updateSatisfied(idx[i + m][0]);
    if (idx[i + m][1] != -1 && satisfied[idx[i + m][1]] == 0)
      updateSatisfied(idx[i + m][1]);
  } else if (idx[i + m][0] == -1) {
    model[i] = 1;
    idx1.push_back(i);
    cntDetermined++;
    if (satisfied[idx[i][0]] == 0) updateSatisfied(idx[i][0]);
    if (idx[i][1] != -1 && satisfied[idx[i][1]] == 0)
      updateSatisfied(idx[i][1]);
  } else {
    if (satisfied[idx[i][0]] && satisfied[idx[i + m][0]]) {
      model[i] = 1;
      idx1.push_back(i);
      cntDetermined++;
      return;
    } else if (satisfied[idx[i][0]]) {
      model[i] = 0;
      idx1.push_back(i);
      cntDetermined++;
      updateSatisfied(idx[i + m][0]);
      return;
    } else if (satisfied[idx[i + m][0]]) {
      model[i] = 1;
      idx1.push_back(i);
      cntDetermined++;
      updateSatisfied(idx[i][0]);
      return;
    }
    bool determined = isDeterministic(i);
    if (determined) {
      model[i] = 1;
      idx1.push_back(i);
      cntDetermined++;
      if (satisfied[idx[i][0]] == 0) updateSatisfied(idx[i][0]);
      return;
    }
    determined = isDeterministic(i + m);
    if (determined) {
      model[i] = 0;
      idx1.push_back(i);
      cntDetermined++;
      if (satisfied[idx[i + m][0]] == 0) updateSatisfied(idx[i + m][0]);
      return;
    }
  }
}
bool isCorrectModel() {
  for (int i = 0; i < (int)n; i++) {
    bool possible = false;
    for (int j = 0; j < (int)clauses[i].size(); j++) {
      int ii = clauses[i][j];
      if (ii > 0 && model[ii] == 1) {
        possible = true;
        break;
      } else if (ii < 0 && model[-ii] == 0) {
        possible = true;
        break;
      }
    }
    if (!possible) return false;
  }
  return true;
}
bool fullSearch(int lim) {
  if (cntDetermined == m) {
    if (isCorrectModel()) {
      return true;
    }
    return false;
  }
  for (int j = lim; j < (int)m + 1; j++) {
    if (model[j] == -1) {
      for (int k = 0; k < (int)2; k++) {
        vector<int> idx1, idx2;
        model[j] = k;
        cntDetermined++;
        if (satisfied[idx[j + m * (1 - k)][0]] == 0) {
          satisfied[idx[j + m * (1 - k)][0]] = 1;
          idx2.push_back(idx[j + m * (1 - k)][0]);
        }
        idx1.push_back(j);
        while (1) {
          int cnt = cntDetermined;
          bool next = false;
          for (int i = 1; i < (int)m + 1; i++) {
            if (model[i] == -1) {
              next = true;
              findModel(i, idx1, idx2);
            }
          }
          if (cnt == cntDetermined) break;
          if (!next || impossible) break;
        }
        st.push(make_pair(idx1, idx2));
        if (fullSearch(j + 1))
          return true;
        else {
          vector<int> idx1 = st.top().first, idx2 = st.top().second;
          st.pop();
          cntDetermined -= idx1.size();
          for (int l = 0; l < (int)idx1.size(); l++) model[idx1[l]] = -1;
          for (int l = 0; l < (int)idx2.size(); l++) satisfied[idx2[l]] = 0;
          continue;
        }
      }
      return false;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  model.resize(m + 1, -1);
  memset(idx, -1, sizeof(idx));
  for (int i = 0; i < (int)n; i++) {
    cin >> l;
    vector<int> clause(l);
    for (int j = 0; j < (int)l; j++) {
      cin >> a;
      clause[j] = a;
      if (a < 0) a = abs(a) + m;
      if (idx[a][0] == -1)
        idx[a][0] = i;
      else
        idx[a][1] = i;
    }
    clauses.push_back(clause);
  }
  satisfied.resize(n, 0);
  impossible = false;
  cntDetermined = 0;
  int lim = 1;
  while (1) {
    int cnt = cntDetermined;
    bool next = false;
    int lim1 = -1;
    for (int i = lim; i < (int)m + 1; i++) {
      if (model[i] == -1) {
        if (lim1 == -1) lim1 = i;
        next = true;
        findModel(i);
      }
    }
    lim = lim1;
    if (cnt == cntDetermined) break;
    if (!next || impossible) break;
  }
  if (cntDetermined != m) {
    fullSearch(1);
  }
  impossible = !isCorrectModel();
  if (impossible)
    cout << "NO" << endl;
  else {
    cout << "YES" << endl;
    for (int i = 1; i < (int)m + 1; i++) cout << model[i];
    cout << endl;
  }
  return 0;
}

```


### Prompt

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

Given simple (without self-intersections) n-gon. It is not necessary convex. Also you are given m lines. For each line find the length of common part of the line and the n-gon.

The boundary of n-gon belongs to polygon. It is possible that n-gon contains 180-degree angles.

Input

The first line contains integers n and m (3 ≤ n ≤ 1000;1 ≤ m ≤ 100). The following n lines contain coordinates of polygon vertices (in clockwise or counterclockwise direction). All vertices are distinct.

The following m lines contain line descriptions. Each of them contains two distict points of a line by their coordinates.

All given in the input coordinates are real numbers, given with at most two digits after decimal point. They do not exceed 105 by absolute values.

Output

Print m lines, the i-th line should contain the length of common part of the given n-gon and the i-th line. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Examples

Input

4 3
0 0
1 0
1 1
0 1
0 0 1 1
0 0 0 1
0 0 1 -1

Output

1.41421356237309514547
1.00000000000000000000
0.00000000000000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
double first[2005], second[2005], X[2005], Y[2005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> X[i] >> Y[i];
  }
  X[n + 1] = X[1];
  Y[n + 1] = Y[1];
  for (int i = 1; i <= m; ++i) {
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    c -= a;
    d -= b;
    double L = sqrt(c * c + d * d + 1e-11), SIN = d / L, COS = c / L;
    for (int j = 1; j <= n + 1; ++j) {
      double xx = X[j] - a, yy = Y[j] - b;
      first[j] = xx * COS + yy * SIN;
      second[j] = yy * COS - xx * SIN;
    }
    vector<double> pt;
    vector<pair<double, double> > tag;
    pt.clear();
    tag.clear();
    for (int j = 1; j <= n; ++j) {
      if (fabs(second[j]) <= 1e-5 && fabs(second[j + 1]) <= 1e-5) {
        if (first[j] > first[j + 1])
          tag.push_back(make_pair(first[j + 1], first[j]));
        else
          tag.push_back(make_pair(first[j], first[j + 1]));
      } else if ((second[j] < -1e-10) ^ (second[j + 1] < -1e-10)) {
        double pos =
            first[j] + (first[j + 1] - first[j]) *
                           fabs(second[j] / (second[j + 1] - second[j]));
        pt.push_back(pos);
      }
    }
    sort(tag.begin(), tag.end());
    sort(pt.begin(), pt.end());
    int p = 0;
    double mx = -1e9, ans = 0;
    assert(pt.size() % 2 == 0);
    while (pt.size() && p < tag.size() && tag[p].first <= pt[0]) {
      if (tag[p].second > mx) {
        ans += min(pt[0], tag[p].second) - max(mx, tag[p].first);
        mx = tag[p].second;
      }
      p++;
    }
    for (int i = 0; i < (int)pt.size() - 1; ++i) {
      while (p < tag.size() && tag[p].first <= pt[i]) {
        mx = max(mx, tag[p].second);
        p++;
      }
      if (i + 1 & 1) {
        ans += pt[i + 1] - pt[i];
        mx = max(mx, pt[i + 1]);
      } else {
        if (mx > pt[i]) ans += mx - pt[i];
        while (p < tag.size() && tag[p].first <= pt[i + 1]) {
          if (tag[p].second > mx) {
            ans += min(pt[i + 1], tag[p].second) - max(mx, tag[p].first);
            mx = tag[p].second;
          }
          p++;
        }
      }
    }
    for (int i = p; i < tag.size(); ++i) {
      if (tag[i].second > mx) {
        ans += tag[i].second - max(mx, tag[i].first);
        mx = tag[i].second;
      }
    }
    printf("%.12lf\n", ans);
  }
  return 0;
}

```


### Prompt

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

problem

You have to play a darts game with the following rules.

You can throw up to four arrows towards the target. You don't have to throw all four, you don't have to throw one. The target is divided into N parts. The score P1, ..., PN is written in each part. The total score S of the place where the arrow is stuck is the basis of your score. S is a predetermined score M or less. In the case of, S will be your score as it is. However, if S exceeds M, your score will be 0 points.

Create a program that finds the maximum number of points you can get given the written points and the value of M.

input

The input consists of multiple datasets. Each dataset is given in the following format.

On the first line, the integers N (1 ≤ N ≤ 1000) and M (1 ≤ M ≤ 200000000 = 2 × 108) are written in this order, separated by blanks. In (1 ≤ i ≤ N), Pi (1 ≤ Pi ≤ 100000000 = 108) is written.

Of the scoring data, 20% of the points satisfy N ≤ 100 and 50% of the points satisfy N ≤ 300.

When both N and M are 0, the input is completed. The number of data sets does not exceed 10.

output

Outputs the maximum number of points you can get for each dataset on one line.

Examples

Input

4 50
3
14
15
9
3 21
16
11
2
0 0

Output

48
20

Input

None

Output

None

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,p[1001],ans,yoso;
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    vector<int> vec;
    for(int i=0;i<n;i++) cin >> p[i];
    p[n] = 0;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	vec.push_back(p[i]+p[j]);
      }
    }
    sort(vec.begin(),vec.end());
    ans = 0;
    for(int i=0;i<=vec.size();i++){
      yoso = upper_bound(vec.begin(),vec.end(),m-vec[i])-vec.begin()-1;
      if(yoso >= 0) ans = max(ans,vec[i] + vec[yoso]);
    }
    cout << ans << endl;
  }
  return (0);
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

This is an interactive problem.

Vasya and Petya are going to play the following game: Petya has some positive integer number a. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbers (x, y). Petya will answer him:

  * "x", if (x mod a) ≥ (y mod a).
  * "y", if (x mod a) < (y mod a).

We define (x mod a) as a remainder of division x by a.

Vasya should guess the number a using no more, than 60 questions.

It's guaranteed that Petya has a number, that satisfies the inequality 1 ≤ a ≤ 10^9.

Help Vasya playing this game and write a program, that will guess the number a.

Interaction

Your program should play several games.

Before the start of any game your program should read the string:

  * "start" (without quotes) — the start of the new game.
  * "mistake" (without quotes) — in the previous game, you found the wrong answer. Your program should terminate after reading this string and it will get verdict "Wrong answer".
  * "end" (without quotes) — all games finished. Your program should terminate after reading this string.

After reading the string "start" (without quotes) the new game starts.

At the beginning, your program should ask several questions about pairs of non-negative integer numbers (x, y). You can only ask the numbers, that satisfy the inequalities 0 ≤ x, y ≤ 2 ⋅ 10^9. To ask a question print "? x y" (without quotes). As the answer, you should read one symbol:

  * "x" (without quotes), if (x mod a) ≥ (y mod a).
  * "y" (without quotes), if (x mod a) < (y mod a).
  * "e" (without quotes) — you asked more than 60 questions. Your program should terminate after reading this string and it will get verdict "Wrong answer".

After your program asked several questions your program should print the answer in form "! a" (without quotes). You should print the number a satisfying the inequalities 1 ≤ a ≤ 10^9. It's guaranteed that Petya's number a satisfied this condition. After that, the current game will finish.

We recall that your program can't ask more than 60 questions during one game.

If your program doesn't terminate after reading "mistake" (without quotes), "end" (without quotes) or "e" (without quotes), it can get any verdict, because it will continue reading from closed input. Also, if your program prints answer or question in the incorrect format it can get any verdict, too. Be careful.

Don't forget to flush the output after printing questions and answers.

To flush the output, you can use:

  * fflush(stdout) in C++.
  * System.out.flush() in Java.
  * stdout.flush() in Python.
  * flush(output) in Pascal.
  * See the documentation for other languages.

It's guaranteed that you should play at least 1 and no more than 100 games.

Hacks:

In hacks, you can use only one game. To hack a solution with Petya's number a (1 ≤ a ≤ 10^9) in the first line you should write a single number 1 and in the second line you should write a single number a.

Example

Input

start
x
x
start
x
x
y
start
x
x
y
y
end

Output

? 0 0
? 10 1
! 1
? 0 0
? 3 4
? 2 5
! 2
? 2 4
? 2 5
? 3 10
? 9 1
! 3

Note

In the first test, you should play 3 games with Petya's numbers 1, 2 and 3.

In the first game, Petya will answer "x" (without quotes) to any question, because (x mod 1) = 0 for any integer x.

In the second game, if you will ask pair (0, 0), the answer will be "x" (without quotes), because (0 mod 2) ≥ (0 mod 2). But if you will ask pair (2, 5), the answer will be "y" (without quotes), because (2 mod 2) < (5 mod 2), because (2 mod 2) = 0 and (5 mod 2) = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[10];
int num = 0;
void binary(int l, int r) {
  if (r - l == 1) {
    printf("! %d\n", r);
    fflush(stdout);
    return;
  }
  int mid = (r - l) / 2 + l;
  printf("? %d %d\n", l, mid);
  fflush(stdout);
  scanf("%s", s);
  if (s[0] == 'x')
    binary(l, mid);
  else
    binary(mid, r);
}
void solve() {
  int a = 0, b = 1;
  num = 0;
  printf("? %d %d\n", a, b);
  fflush(stdout);
  scanf("%s", s);
  while (s[0] == 'y') {
    if (a == 0)
      a = 1;
    else
      a <<= 1;
    b <<= 1;
    printf("? %d %d\n", a, b);
    fflush(stdout);
    scanf("%s", s);
  }
  binary(a, b);
}
int main() {
  while (scanf("%s", s) && s[0] == 's') solve();
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.

You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string s = "BBAABBBA" the answer is two-gram "BB", which contained in s three times. In other words, find any most frequent two-gram.

Note that occurrences of the two-gram can overlap with each other.

Input

The first line of the input contains integer number n (2 ≤ n ≤ 100) — the length of string s. The second line of the input contains the string s consisting of n capital Latin letters.

Output

Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string s as a substring (i.e. two consecutive characters of the string) maximal number of times.

Examples

Input

7
ABACABA

Output

AB

Input

5
ZZZAA

Output

ZZ

Note

In the first example "BA" is also valid answer.

In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  map<string, long long int> m;
  for (long long int i = 0; i + 1 < n; i++) {
    string t = "";
    t += s[i];
    t += s[i + 1];
    m[t]++;
  }
  long long int mx = 0;
  for (auto x : m) {
    mx = max(mx, x.second);
  }
  for (auto x : m) {
    if (x.second == mx) {
      cout << x.first << "\n";
      return 0;
    }
  }
  return 0;
}

```


### Prompt

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

You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:

  1. All cells in a set have the same color.
  2. Every two cells in a set share row or column.

Input

The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly.

The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.

Output

Output single integer — the number of non-empty sets from the problem description.

Examples

Input

1 1
0

Output

1

Input

2 3
1 0 1
0 1 0

Output

8

Note

In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = 3.141592653589793238462;
const int dr[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int grid[55][55];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long white = 0, black = 0;
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      white += grid[i][j] * 1LL;
      black += (!grid[i][j]) * 1LL;
    }
    ans += (long long)(1LL << black) - 1;
    ans += (long long)(1LL << white) - 1;
  }
  for (int j = 0; j < m; j++) {
    long long white = 0, black = 0;
    for (int i = 0; i < n; i++) {
      cin >> grid[i][j];
      white += grid[i][j] * 1LL;
      black += (!grid[i][j]) * 1LL;
    }
    ans += (long long)(1LL << black) - black - 1;
    ans += (long long)(1LL << white) - white - 1;
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

One of the games that uses the Hyakunin Isshu tag is "Buddhist turning". It is a simple game that uses only picture cards, so it is widely enjoyed. There are various derivative types of rules, but the shaved turn considered here is performed by N participants according to the following rules.

* Use a total of 100 cards, including 64 "men", 15 "boys", and 21 "princesses".
* Turn the bill over so that you can't see the picture and mix well to make a "bill pile".
* Draw one card from the first participant in order. After the Nth person, repeat from the first person.
* If the drawn card is a man, the person who draws will get the card.
* If the drawn card is a shaven, the person who draws puts all the cards he has, including that card, into the "field".
* If the drawn card is a princess, the person who draws gets all the cards in play, including that card.
* When there are no more cards in the bill pile, the game ends, and the person with the most cards wins.

Given the number of participants and the order of the cards piled up in the bill pile, the number of cards each participant has at the end of the game is arranged in ascending order, and the number of cards remaining in the field is shown. Create a program to output.

input

The input consists of multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

N
c1c2 ... c100

Each dataset has two rows, and the first row is given the integer N (2 ≤ N ≤ 10) representing the number of participants. The next line is given a character string that represents the arrangement of the bills piled up in the bill pile. The letter ci represents the i-th drawn tag, where M is a man, S is a shaven, and L is a princess. There is no space between each character.

The number of datasets does not exceed 100.

output

For each data set, the sequence of the number of cards at the end of the game is output on one line. As the number of cards, the number of cards that each participant has is arranged in ascending order, and then the number of cards remaining in the field is output. Separate each number of bills with one blank. Do not print blanks at the end of the line.

Example

Input

2
SSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
2
SSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMSL
5
MMMMMMSLSLLMMMSMMSLMMMLMMMMLSLLLLMLSMMLMMLLMSSSLMMMMLMLSMLMSMMMMMMMSMMMMMMLMMMMMSMMMLMMLMMMMMMMMMSSM
0

Output

42 58 0
0 100 0
0 0 3 10 59 28

### Response

```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N;
	while(cin>>N,N){
		int te[N],ba=0;
		for(int i=0;i<N;++i)te[i]=0;
		string str;
		cin>>str;
		for(int i=0;i<100;++i){
			int m=i%N;
			if (str[i]=='M'){
				te[m]++;
			}else if(str[i]=='S'){
				ba+=te[m]+1;
				te[m]=0;
			}else if(str[i]=='L'){
				te[m]+=ba+1;
				ba=0;
			}
		}
		sort(te,te+N);
		for(int i=0;i<N;++i)cout<<te[i]<<" ";
		cout<<ba<<endl;
	}
}
```


### Prompt

Please formulate a cpp solution to the following problem:

In the country there are exactly n cities numbered with positive integers from 1 to n. In each city there is an airport is located.

Also, there is the only one airline, which makes m flights. Unfortunately, to use them, you need to be a regular customer of this company, namely, you have the opportunity to enjoy flight i from city ai to city bi only if you have already made at least di flights before that.

Please note that flight i flies exactly from city ai to city bi. It can not be used to fly from city bi to city ai. An interesting fact is that there may possibly be recreational flights with a beautiful view of the sky, which begin and end in the same city.

You need to get from city 1 to city n. Unfortunately, you've never traveled by plane before. What minimum number of flights you have to perform in order to get to city n?

Note that the same flight can be used multiple times.

Input

The first line contains two integers, n and m (2 ≤ n ≤ 150, 1 ≤ m ≤ 150) — the number of cities in the country and the number of flights the company provides.

Next m lines contain numbers ai, bi, di (1 ≤ ai, bi ≤ n, 0 ≤ di ≤ 109), representing flight number i from city ai to city bi, accessible to only the clients who have made at least di flights.

Output

Print "Impossible" (without the quotes), if it is impossible to get from city 1 to city n using the airways.

But if there is at least one way, print a single integer — the minimum number of flights you need to make to get to the destination point.

Examples

Input

3 2
1 2 0
2 3 1

Output

2

Input

2 1
1 2 100500

Output

Impossible

Input

3 3
2 1 0
2 3 6
1 2 0

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, sgn = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') sgn = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
  return x * sgn;
}
const int N = 155;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, m;
int lim[N];
struct edge {
  int u, v, d;
} e[N];
bool operator<(edge a, edge b) { return a.d < b.d; }
struct mat {
  bitset<155> arr[N];
  mat() {
    for (int i = 1; i <= n; i++) arr[i].reset();
  }
  bitset<155>& operator[](int x) { return arr[x]; }
  const bitset<155>& operator[](int x) const { return arr[x]; }
  friend bitset<155> operator*(bitset<155> a, mat b) {
    bitset<155> c;
    for (int i = 1; i <= n; i++) c[i] = (a & b[i]).any();
    return c;
  }
  friend mat operator*(mat a, mat b) {
    mat c;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (a[i][j]) c[i] |= b[j];
    return c;
  }
} c;
bitset<155> v;
long long d[N], ans = inf;
bitset<155> qp(mat a, bitset<155> b, int t) {
  for (; t; t >>= 1, a = a * a)
    if (t & 1) b = b * a;
  return b;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++)
    e[i].u = read(), e[i].v = read(), e[i].d = read();
  sort(e + 1, e + m + 1);
  v[1] = 1;
  for (int i = 1; i <= m; i++) {
    if (e[i].d >= ans) break;
    v = qp(c, v, e[i].d - e[i - 1].d);
    c[e[i].v][e[i].u] = 1;
    queue<int> q;
    for (int j = 1; j <= n; j++)
      if (v[j])
        d[j] = 0, q.push(j);
      else
        d[j] = inf;
    while (q.size()) {
      int x = q.front();
      q.pop();
      for (int k = 1; k <= n; k++)
        if (c[k][x] && d[k] == inf) d[k] = d[x] + 1, q.push(k);
    }
    ans = min(ans, e[i].d + d[n]);
  }
  if (ans < inf)
    printf("%lld\n", ans);
  else
    puts("Impossible");
  return 0;
}

```


### Prompt

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

Two best friends Serozha and Gena play a game.

Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak = 1. Naturally, the number of piles k should be no less than two.

The friends play in turns. The player who cannot make a move loses. Serozha makes the first move. Who will win if both players play in the optimal way?

Input

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

Output

If Serozha wins, print k, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game.

If Gena wins, print "-1" (without the quotes).

Examples

Input

3

Output

2

Input

6

Output

-1

Input

100

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  long long f[n + 1];
  f[0] = 0;
  long long ans[n + 1];
  long long pref[n + 1];
  pref[0] = 0;
  ans[0] = -1;
  for (long long i = 1; i < n + 1; ++i) {
    long long to = ((long long)sqrt(i) + 10) * 2;
    vector<pair<long long, long long>> b;
    for (long long j = 2; j <= to; ++j) {
      if (i >= j * (j + 1) / 2 && (i - j * (j + 1) / 2) % j == 0) {
        long long s = 1 + (i - j * (j + 1) / 2) / j;
        long long t = s + j - 1;
        b.push_back({pref[t] ^ pref[s - 1], j});
      }
    }
    long long mex = 0;
    sort(b.begin(), b.end());
    for (long long k = 0; k < b.size(); ++k) {
      if (mex == b[k].first) mex++;
    }
    f[i] = mex;
    if (f[i] == 0) {
      ans[i] = -1;
    } else {
      long long mn = 1e9;
      for (long long j = 0; j < b.size(); ++j) {
        if (b[j].first == 0) {
          mn = min(mn, b[j].second);
        }
      }
      ans[i] = mn;
    }
    pref[i] = pref[i - 1] ^ f[i];
  }
  cout << ans[n];
}

```


### Prompt

Create a solution in cpp for the following problem:

So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.

The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.

Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

Input

The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

Output

Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

Examples

Input

SANTACLAUS
DEDMOROZ
SANTAMOROZDEDCLAUS

Output

YES

Input

PAPAINOEL
JOULUPUKKI
JOULNAPAOILELUPUKKI

Output

NO

Input

BABBONATALE
FATHERCHRISTMAS
BABCHRISTMASBONATALLEFATHER

Output

NO

Note

In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.

In the second sample letter "P" is missing from the pile and there's an extra letter "L".

In the third sample there's an extra letter "L".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c, s;
  cin >> a >> b >> c;
  s = a + b;
  sort(s.begin(), s.end());
  sort(c.begin(), c.end());
  if (s == c)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

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

Given are three integers N, K, and S.

Find a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below. We can prove that, under the conditions in Constraints, such a sequence always exists.

* There are exactly K pairs (l, r) of integers such that 1 \leq l \leq r \leq N and A_l + A_{l + 1} + \cdots + A_r = S.

Constraints

* 1 \leq N \leq 10^5
* 0 \leq K \leq N
* 1 \leq S \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K S

Output

Print a sequence satisfying the condition, in the following format:

A_1 A_2 ... A_N

Output

Print a sequence satisfying the condition, in the following format:

A_1 A_2 ... A_N

Examples

Input

4 2 3

Output

1 2 3 4

Input

5 3 100

Output

50 50 50 30 70

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

int main() {
  int N, K, S;
  cin >> N >> K >> S;

  vector<int> A(N, S == pow(10, 9) ? 1 : S+1);
  rep(i,0,K-1) A[i] = S;
  for (auto i : A) cout << i << ' ';
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?

Input

The first line contains two integers n and k (1 ≤ n ≤ 200 000, 0 ≤ k ≤ n) — the number of digits in the decimal representation of S and the maximum allowed number of changed digits.

The second line contains the integer S. It's guaranteed that S has exactly n digits and doesn't contain any leading zeroes.

Output

Output the minimal possible value of S which Ania can end with. Note that the resulting integer should also have n digits.

Examples

Input

5 3
51528

Output

10028

Input

3 2
102

Output

100

Input

1 1
1

Output

0

Note

A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don't have leading zeroes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename a>
void SWAP(a &b, a &c) {
  a d = b;
  b = c;
  c = d;
}
long long power(long long a, long long b) {
  long long result = 1;
  while (b) {
    if (b & 1) result = a * result;
    a *= a;
    b >>= 1;
  }
  return result;
}
long long gcd(long long a, long long b) {
  while (b) {
    a = a % b;
    SWAP(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
string solve(string a, long long n, long long k) {
  string ans;
  for (long long i = 0, j = 0; i < n && j < k; i++) {
    if (i == 0) {
      if (n == 1) {
        a[i] = '0';
        j++;
      } else if (a[i] != '1') {
        a[i] = '1';
        j++;
      }
    } else {
      if (a[i] != '0') {
        a[i] = '0';
        j++;
      }
    }
  }
  return a;
}
int main() {
  long long n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  str = solve(str, n, k);
  cout << str << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

There are n chips arranged in a circle, numbered from 1 to n.

Initially each chip has black or white color. Then k iterations occur. During each iteration the chips change their colors according to the following rules. For each chip i, three chips are considered: chip i itself and two its neighbours. If the number of white chips among these three is greater than the number of black chips among these three chips, then the chip i becomes white. Otherwise, the chip i becomes black.

Note that for each i from 2 to (n - 1) two neighbouring chips have numbers (i - 1) and (i + 1). The neighbours for the chip i = 1 are n and 2. The neighbours of i = n are (n - 1) and 1.

The following picture describes one iteration with n = 6. The chips 1, 3 and 4 are initially black, and the chips 2, 5 and 6 are white. After the iteration 2, 3 and 4 become black, and 1, 5 and 6 become white.

<image>

Your task is to determine the color of each chip after k iterations.

Input

The first line contains two integers n and k (3 ≤ n ≤ 200 000, 1 ≤ k ≤ 10^{9}) — the number of chips and the number of iterations, respectively.

The second line contains a string consisting of n characters "W" and "B". If the i-th character is "W", then the i-th chip is white initially. If the i-th character is "B", then the i-th chip is black initially.

Output

Print a string consisting of n characters "W" and "B". If after k iterations the i-th chip is white, then the i-th character should be "W". Otherwise the i-th character should be "B".

Examples

Input

6 1
BWBBWW

Output

WBBBWW

Input

7 3
WBWBWBW

Output

WWWWWWW

Input

6 4
BWBWBW

Output

BWBWBW

Note

The first example is described in the statement.

The second example: "WBWBWBW" → "WWBWBWW" → "WWWBWWW" → "WWWWWWW". So all chips become white.

The third example: "BWBWBW" → "WBWBWB" → "BWBWBW" → "WBWBWB" → "BWBWBW".

### Response

```cpp
#include <bits/stdc++.h>
int n, k, d, dis1[400005], dis2[400005];
char a[400005], b[400005];
bool check() {
  if (n & 1) return 0;
  for (register int i = 2; i <= n; ++i)
    if (a[i] == a[i - 1]) return 0;
  return 1;
}
int main() {
  scanf("%d%d%s", &n, &k, a + 1);
  if (check()) {
    if (k & 1) std ::reverse(a + 1, a + 1 + n);
    return printf("%s", a + 1), 0;
  }
  for (register int i = 1; i <= n; ++i) a[n + i] = a[i];
  for (register int i = n + 2; i < (n << 1); ++i)
    if (a[i - 1] != a[i] && a[i] != a[i + 1])
      continue;
    else {
      d = i - 1;
      break;
    }
  if (!d) d = (n << 1) - 1;
  for (register int i = d - n + 1; i <= d; ++i)
    if (a[i - 1] != a[i] && a[i] != a[i + 1])
      dis1[i] = dis1[i - 1] + 1;
    else
      dis1[i] = 0;
  for (register int i = d; i > d - n; --i)
    if (a[i - 1] != a[i] && a[i] != a[i + 1])
      dis2[i] = dis2[i + 1] + 1;
    else
      dis2[i] = 0;
  for (register int i = d - n + 1; i <= d; ++i)
    if (a[i - 1] != a[i] && a[i] != a[i + 1])
      if (k >= std ::min(dis1[i], dis2[i]))
        if (dis1[i] < dis2[i])
          b[i] = a[i - dis1[i]];
        else
          b[i] = a[i + dis2[i]];
      else
        b[i] =
            a[i] == 'B' && (k & 1) || (a[i] == 'W' && (k & 1 ^ 1)) ? 'W' : 'B';
    else
      b[i] = a[i];
  for (register int i = 1; i <= d - n; ++i) putchar(b[i + n]);
  for (register int i = d - n + 1; i <= n; ++i) putchar(b[i]);
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.

You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on all edges on the simple path between u and v.

For example, on the picture below you can see the result of applying two operations to the graph: adding 2 on the path from 7 to 6, and then adding -0.5 on the path from 4 to 5.

<image>

Is it true that for any configuration of real numbers written on edges, we can achieve it with a finite number of operations?

Leaf is a node of a tree of degree 1. Simple path is a path that doesn't contain any node twice.

Input

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

Each of the next n-1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v), meaning that there is an edge between nodes u and v. It is guaranteed that these edges form a tree.

Output

If there is a configuration of real numbers written on edges of the tree that we can't achieve by performing the operations, output "NO".

Otherwise, output "YES".

You can print each letter in any case (upper or lower).

Examples

Input

2
1 2

Output

YES

Input

3
1 2
2 3

Output

NO

Input

5
1 2
1 3
1 4
2 5

Output

NO

Input

6
1 2
1 3
1 4
2 5
2 6

Output

YES

Note

In the first example, we can add any real x to the value written on the only edge (1, 2).

<image>

In the second example, one of configurations that we can't reach is 0 written on (1, 2) and 1 written on (2, 3).

<image>

Below you can see graphs from examples 3, 4:

<image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int main() {
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n) {
    fill(a, a + n + 5, 0);
    int x, y;
    for (int i = 0; i < n - 1; i++) {
      cin >> x >> y;
      a[x]++;
      a[y]++;
    }
    int f = 1;
    for (int i = 1; i <= 100005; i++) {
      if (a[i] == 2) {
        f = 0;
        break;
      }
    }
    if (f)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

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

Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you?

Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.

Guaranteed that the length of the string s doesn't exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.

Input

The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly.

The second line contains n lowercase English letters — string s.

The third line contains m lowercase English letters — string t.

Output

In the first line print single integer k — the minimal number of symbols that need to be replaced.

In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.

Examples

Input

3 5
abc
xaybz

Output

2
2 3

Input

4 10
abcd
ebceabazcd

Output

1
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
char s1[1010], s2[1010];
vector<int> vec, vv;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  scanf("%s%s", s1 + 1, s2 + 1);
  int ans = n;
  for (int i = 1; i <= n; i++) vv.push_back(i);
  for (int i = 1; i <= m - n + 1; i++) {
    int num = 0;
    for (int j = 1; j <= n; j++) {
      if (s2[i + j - 1] != s1[j]) {
        num++;
        vec.push_back(j);
      }
    }
    if (num < ans) {
      ans = num;
      vv = vec;
    }
    vec.clear();
  }
  printf("%d\n", ans);
  for (int i = 0; i < vv.size(); i++) {
    printf("%d ", vv[i]);
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vertex v, which denotes the number of vertices on the path from vertex v to the root. Clearly, s_1=a_1 and h_1=1.

Then Mitya erased all numbers a_v, and by accident he also erased all values s_v for vertices with even depth (vertices with even h_v). Your task is to restore the values a_v for every vertex, or determine that Mitya made a mistake. In case there are multiple ways to restore the values, you're required to find one which minimizes the total sum of values a_v for all vertices in the tree.

Input

The first line contains one integer n — the number of vertices in the tree (2 ≤ n ≤ 10^5). The following line contains integers p_2, p_3, ... p_n, where p_i stands for the parent of vertex with index i in the tree (1 ≤ p_i < i). The last line contains integer values s_1, s_2, ..., s_n (-1 ≤ s_v ≤ 10^9), where erased values are replaced by -1.

Output

Output one integer — the minimum total sum of all values a_v in the original tree, or -1 if such tree does not exist.

Examples

Input

5
1 1 1 1
1 -1 -1 -1 -1

Output

1

Input

5
1 2 3 1
1 -1 2 -1 -1

Output

2

Input

3
1 2
2 -1 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool flag;
long long int par[200005];
long long int val[200005];
long long int av[2000005];
vector<vector<long long int> > t;
void dfs(long long int r, long long int p, long long int n, long long int h) {
  if (h % 2 != 0) {
    if (val[r] >= n)
      av[r] = val[r] - n;
    else
      flag = false;
  } else {
    long long int m = 0x3f3f3f3f;
    for (auto i : t[r])
      if (i != p)
        m = min((long long int)m, (long long int)val[i] - n), av[r] = m;
    if (m < 0) flag = false;
  }
  for (auto i : t[r])
    if (i != p) dfs(i, r, n + av[r], h + 1);
}
signed main() {
  std::ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  t.clear();
  t.resize(n + 1);
  for (long long int i = 2; i < n + 1; i++)
    cin >> par[i], t[par[i]].push_back(i);
  for (long long int i = 1; i < n + 1; i++) cin >> val[i];
  flag = true;
  dfs(1, 0, 0, 1);
  long long int sum = 0;
  if (flag) {
    for (long long int i = 1; i < n + 1; i++) sum += av[i];
    cout << sum << "\n";
  } else
    cout << -1 << "\n";
}

```


### Prompt

Please create a solution in cpp to the following problem:

Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:

* $update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$.
* $getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$.

Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.

Constraints

* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$

Input

$n$ $q$
$query_1$
$query_2$
:
$query_q$

In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$-th query $query_i$ is given in the following format:

0 $s$ $t$ $x$

or

1 $s$ $t$

The first digit represents the type of the query. '0' denotes $update(s, t, x)$ and '1' denotes $find(s, t)$.

Output

For each $getSum$ query, print the sum in a line.

Example

Input

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

Output

-5
1
6
8

### Response

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

template<typename T> constexpr function<T(T, T)> ex_assign(T initE) {
  return [&initE](const T& x, const T& y) -> const T { return (y == initE) ? x : y; };
}
template<typename T> constexpr function<T(T, int)> ex_multiplies(T initE) {
  return [&initE](const T& x, int y) -> const T { return (x == initE) ? x : x * y; };
}
template<typename T, typename E> struct LazySegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  using P = function<E(E, int)>;

  int n;
  T initT;
  E initE;
  F f;
  G g;
  H h;
  P p;
  vector<T> data;
  vector<E> lazy;

  LazySegmentTree() {}
  LazySegmentTree(int n_, F f, G g, H h, T initT = INT_MAX, E initE = INT_MAX,
      vector<T> v = vector<T>(), P p = [](E a, size_t b) { ++b; return a; })
      : f(f), g(g), h(h), initT(initT), initE(initE), p(p) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(n * 2 - 1, initT);
    lazy.assign(n * 2 - 1, initE);
    if (n_ == v.size()) build(v);
  }
  void build(vector<T> v) {
    for (int i = 0; i < v.size(); ++i) data[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  inline void eval(int len, int k) {
    if (lazy[k] == initE) return;
    if (k * 2 + 1 < n * 2 - 1) {
      lazy[k * 2 + 1] = h(lazy[k * 2 + 1], lazy[k]);
      lazy[k * 2 + 2] = h(lazy[k * 2 + 2], lazy[k]);
    }
    data[k] = g(data[k], p(lazy[k], len));
    lazy[k] = initE;
  }
  T update(int a, int b, E x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return data[k];
    if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      eval(r - l, k);
      return data[k];
    }
    T vl = update(a, b, x, k * 2 + 1, l, (l + r) / 2);
    T vr = update(a, b, x, k * 2 + 2, (l + r) / 2, r);
    return data[k] = f(vl, vr);
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return initT;
    if (a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};

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

  const ll initT = 0;
  const ll initE = 1e9;
  const LazySegmentTree<ll, ll>::F f = plus<ll>();
  const LazySegmentTree<ll, ll>::G g = ex_assign<ll>(initE);
  const LazySegmentTree<ll, ll>::H h = ex_assign<ll>(initE);
  const LazySegmentTree<ll, ll>::P p = ex_multiplies<ll>(initE);

  int n, q; cin >> n >> q;
  LazySegmentTree<ll, ll> seg(n, f, g, h, initT, initE, vector<ll>(), p);

  while (q--) {
    int com; cin >> com;
    if (com) {
      int s, t; cin >> s >> t;
      cout << seg.query(s, t + 1) << endl;
    } else {
      int s, t, x; cin >> s >> t >> x;
      seg.update(s, t + 1, x);
    }
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.

Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree with colored vertices.

Now Appleman wonders, what is the number of sets splitting the tree in such a way that each resulting part will have exactly one black vertex? Find this number modulo 1000000007 (109 + 7).

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of tree vertices.

The second line contains the description of the tree: n - 1 integers p0, p1, ..., pn - 2 (0 ≤ pi ≤ i). Where pi means that there is an edge connecting vertex (i + 1) of the tree and vertex pi. Consider tree vertices are numbered from 0 to n - 1.

The third line contains the description of the colors of the vertices: n integers x0, x1, ..., xn - 1 (xi is either 0 or 1). If xi is equal to 1, vertex i is colored black. Otherwise, vertex i is colored white.

Output

Output a single integer — the number of ways to split the tree modulo 1000000007 (109 + 7).

Examples

Input

3
0 0
0 1 1

Output

2

Input

6
0 1 1 0 4
1 1 0 0 1 0

Output

1

Input

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

Output

27

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> G[100010], ter;
long long n, root, c[100010], par[100010], dt[100010][2], ans;
void dfs(int v, int pv) {
  dt[v][0] = 1;
  dt[v][1] = 0;
  for (int w : G[v])
    if (w != pv) {
      dfs(w, v);
      dt[v][1] *= dt[w][0];
      dt[v][1] += dt[v][0] * dt[w][1];
      dt[v][0] *= dt[w][0];
      dt[v][1] %= 1000000007, dt[v][0] %= 1000000007;
    }
  if (c[v] == 1)
    dt[v][1] = dt[v][0];
  else
    dt[v][0] += dt[v][1];
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1, t; i < n; i++) {
    cin >> t;
    G[i].push_back(t), G[t].push_back(i);
  }
  for (int i = 0; i < n; i++) cin >> c[i];
  dfs(0, 0);
  cout << dt[0][1] << endl;
  return 0;
}

```


### Prompt

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

A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.

The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.

Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

Input

The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).

Output

Output the amount of possible positions of the new house.

Examples

Input

2 2
0 4
6 2

Output

4

Input

2 2
0 4
5 2

Output

3

Input

2 3
0 4
5 2

Output

2

Note

It is possible for the x-coordinate of the new house to have non-integer value.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int main() {
  int n, t;
  cin >> n >> t;
  if (n == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < (int)(n); i++) {
    int x, y;
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  int ans = 2;
  sort(a.begin(), a.end(), cmp);
  for (int i = 1; i < n; i++)
    if (2 * a[i].first - a[i].second - 2 * t >
        2 * a[i - 1].first + a[i - 1].second)
      ans++;
  for (int i = 0; i < (int)(n - 1); i++)
    if (2 * a[i].first + a[i].second + 2 * t <
        2 * a[i + 1].first - a[i + 1].second)
      ans++;
  for (int i = 0; i < (int)(n - 1); i++)
    if (2 * a[i].first + a[i].second + 2 * t ==
        2 * a[i + 1].first - a[i + 1].second)
      ans++;
  cout << ans;
}

```


### Prompt

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

Petya has recently learned data structure named "Binary heap".

The heap he is now operating with allows the following operations:

  * put the given number into the heap;
  * get the value of the minimum element in the heap;
  * extract the minimum element from the heap;

Thus, at any moment of time the heap contains several integers (possibly none), some of them might be equal.

In order to better learn this data structure Petya took an empty heap and applied some operations above to it. Also, he carefully wrote down all the operations and their results to his event log, following the format:

  * insert x — put the element with value x in the heap;
  * getMin x — the value of the minimum element contained in the heap was equal to x;
  * removeMin — the minimum element was extracted from the heap (only one instance, if there were many).

All the operations were correct, i.e. there was at least one element in the heap each time getMin or removeMin operations were applied.

While Petya was away for a lunch, his little brother Vova came to the room, took away some of the pages from Petya's log and used them to make paper boats.

Now Vova is worried, if he made Petya's sequence of operations inconsistent. For example, if one apply operations one-by-one in the order they are written in the event log, results of getMin operations might differ from the results recorded by Petya, and some of getMin or removeMin operations may be incorrect, as the heap is empty at the moment they are applied.

Now Vova wants to add some new operation records to the event log in order to make the resulting sequence of operations correct. That is, the result of each getMin operation is equal to the result in the record, and the heap is non-empty when getMin ad removeMin are applied. Vova wants to complete this as fast as possible, as the Petya may get back at any moment. He asks you to add the least possible number of operation records to the current log. Note that arbitrary number of operations may be added at the beginning, between any two other operations, or at the end of the log.

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 100 000) — the number of the records left in Petya's journal.

Each of the following n lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers not exceeding 109 by their absolute value.

Output

The first line of the output should contain a single integer m — the minimum possible number of records in the modified sequence of operations.

Next m lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applied. All the numbers in the output should be integers not exceeding 109 by their absolute value.

Note that the input sequence of operations must be the subsequence of the output sequence.

It's guaranteed that there exists the correct answer consisting of no more than 1 000 000 operations.

Examples

Input

2
insert 3
getMin 4

Output

4
insert 3
removeMin
insert 4
getMin 4

Input

4
insert 1
insert 1
removeMin
getMin 2

Output

6
insert 1
insert 1
removeMin
removeMin
insert 2
getMin 2

Note

In the first sample, after number 3 is inserted into the heap, the minimum number is 3. To make the result of the first getMin equal to 4 one should firstly remove number 3 from the heap and then add number 4 into the heap.

In the second sample case number 1 is inserted two times, so should be similarly removed twice.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct operacion {
  string name;
  int x;
  operacion() {}
  operacion(string name, int x) : name(name), x(x) {}
};
int n;
priority_queue<int, vector<int>, greater<int> > q;
vector<operacion> v;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int cas = 0; cas < n; cas++) {
    string name;
    cin >> name;
    if (name == "insert") {
      int x;
      cin >> x;
      v.push_back(operacion(name, x));
      q.push(x);
    } else if (name == "getMin") {
      int x;
      cin >> x;
      while (int(q.size()) > 0 and q.top() < x) {
        v.push_back(operacion("removeMin", 0));
        q.pop();
      }
      if (int(q.size()) == 0 or q.top() != x) {
        v.push_back(operacion("insert", x));
        q.push(x);
      }
      v.push_back(operacion("getMin", x));
    } else if (name == "removeMin") {
      if (int(q.size()) == 0) {
        v.push_back(operacion("insert", 1));
        q.push(1);
      }
      v.push_back(operacion("removeMin", 0));
      q.pop();
    }
  }
  cout << int(v.size()) << endl;
  for (int i = 0; i < int(v.size()); i++) {
    cout << v[i].name;
    if (v[i].name != "removeMin") cout << " " << v[i].x;
    cout << endl;
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.

Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.

And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.

Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.

Your task is to write a program that will determine the required number of seconds t.

Input

The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.

The numbers in the lines are separated by single spaces.

Output

In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.

Examples

Input

5
0 1
1 0
0 1
1 1
0 1

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int l1 = 0, l0 = 0, r0 = 0, r1 = 0;
  while (n--) {
    int l, r;
    cin >> l >> r;
    if (l == 1)
      l1++;
    else
      l0++;
    if (r == 1)
      r1++;
    else
      r0++;
  }
  cout << min(l1, l0) + min(r1, r0) << endl;
}

```


### Prompt

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

Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.

He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.

Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).

Input

First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list.

Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.

Output

Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.

You can print each letter in any case (upper or lower).

Examples

Input

6
tom
lucius
ginny
harry
ginny
harry

Output

NO
NO
NO
NO
YES
YES

Input

3
a
a
a

Output

NO
YES
YES

Note

In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mx = (1e5) + 1;
const long long mod = 1000000007;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  map<string, int> mp;
  while (n--) {
    cin >> s;
    if (mp[s] == 0) {
      cout << "NO" << endl;
      mp[s]++;
    } else {
      cout << "YES" << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.

Constraints

* 1 ≤ L ≤ 1000
* L is an integer.

Input

Input is given from Standard Input in the following format:

L

Output

Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Your output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.

Examples

Input

3

Output

1.000000000000

Input

999

Output

36926037.000000000000

### Response

```cpp
#include<cstdio>
using namespace std;
double l;
int main(){
	return scanf("%lf",&l),printf("%lf",l*l*l/27),0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

Railroad Trip

There are N cities in the JOI country, numbered 1, 2, ..., and N, respectively. In addition, there are N − 1 railroads, which are numbered 1, 2, ..., and N − 1, respectively. The railroad i (1 ≤ i ≤ N − 1) connects the city i and the city i + 1 in both directions.

There are two ways to get on the JOI railway, one is to use a paper ticket and the other is to use an IC card.

* The fare for boarding the railway i with a paper ticket is Ai yen.
* The fare for boarding the railway i with an IC card is Bi Yen. However, in order to board the railway i with an IC card, it is necessary to purchase an IC card that can be used with the railway i in advance. It costs Ci yen to purchase an IC card that can be used on the railway i. Once purchased, the IC card can be used any number of times.

Since the IC card makes it easier to process the amount, the fare for boarding with an IC card is cheaper than the fare for boarding with a paper ticket. That is, for i = 1, 2, ..., N − 1, Ai> Bi holds. Since the specifications of IC cards are all different for each railroad, the IC card that can be used on railroad i cannot be used on other railroads for any i.

You decide to travel all over the JOI country. We plan to start from the city P1 and visit the cities in the order of P2, P3, ..., PM. The trip consists of an M-1 day journey. On day j (1 ≤ j ≤ M − 1), travel by rail from city Pj to city Pj + 1. At this time, it may move by connecting several railroads. You may also visit the same city more than once. The railroads in JOI are so fast that you can travel from any city to any city in a day.

You currently do not have an IC card for any railroad. You want to purchase some railroad IC cards in advance and minimize the cost of this trip, that is, the sum of the IC card purchase cost and the railroad fare you boarded.

Task

Given the number of cities in the JOI country, the itinerary of the trip, and the fare and IC card price for each railroad in the JOI country. At this time, create a program to find the minimum amount of money required for the trip.

input

Read the following data from standard input.

* On the first line, integers N and M are written with blanks as delimiters. Each of these represents that there are N cities in the JOI country and the trip consists of an M-1 day journey.
* On the second line, M integers P1, P2, ..., PM are written with a space as a delimiter. These represent the rail movement from city Pj to city Pj + 1 on day j (1 ≤ j ≤ M − 1).
* On the i-th line (1 ≤ i ≤ N − 1) of the following N − 1 lines, three integers Ai, Bi, and Ci are written separated by blanks. These indicate that the fare when boarding the railway i with a paper ticket is Ai yen, the fare when boarding with an IC card is Bi yen, and the amount of the IC card that can be used on the railway i is Ci yen.

output

On the standard output, output an integer that represents the minimum value of the travel amount in yen on one line.

Limits

All input data satisfy the following conditions.

* 2 ≤ N ≤ 100 000.
* 2 ≤ M ≤ 100 000.
* 1 ≤ Bi <Ai ≤ 100 000 (1 ≤ i ≤ N − 1).
* 1 ≤ Ci ≤ 100 000 (1 ≤ i ≤ N − 1).
* 1 ≤ Pj ≤ N (1 ≤ j ≤ M).
* Pj ≠ Pj + 1 (1 ≤ j ≤ M − 1).

Input / output example

Input example 1

4 4
1 3 2 4
120 90 100
110 50 80
250 70 130

Output example 1

550

In this case, the method to minimize the cost of travel is as follows.

* Purchase IC cards for Railroad 2 and Railroad 3. This costs 80 + 130 = 210 yen.
* On the first day, move from city 1 to city 2 using a paper ticket, and then move from city 2 to city 3 using an IC card. This costs 120 + 50 = 170 yen.
* On the second day, move from city 3 to city 2 using an IC card. This costs 50 yen.
* On the third day, move from city 2 to city 3 using an IC card, and then move from city 3 to city 4 using an IC card. This costs 50 + 70 = 120 yen.

When moving in this way, the total amount of money spent on the trip is 210 + 170 + 50 + 120 = 550 yen. Since this is the minimum, it outputs 550.

Input example 2

8 5
7 5 3 5 4
12 5 8
16 2 1
3 1 5
17 12 17
19 7 5
12 2 19
4 1 3

Output example 2

81

The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.

Example

Input

4 4
1 3 2 4
120 90 100
110 50 80
250 70 130

Output

550

### Response

```cpp
#include<stdio.h>
#include<iostream>

using namespace std;

#define min(a,b) ((a<b)?a:b)

int main(void){
    int n,m,i,j,from,to;
    long long int a,b,c,t[100001],ans=0LL,add;
    scanf("%d%d",&n,&m);
    fill(t,t+n,0LL);
    n--;
    scanf("%d",&from);
    t[0]=0;
    for(i=1; i<m; i++){
        scanf("%d",&to);
        if(from<to){
            t[from]++;
            t[to]--;
        }else{
            t[to]++;
            t[from]--;
        }
        from = to;
    }
    for(i=1; i<=n; i++){
        t[i]+=t[i-1];
        scanf("%lld%lld%lld",&a,&b,&c);
        add=min(a*t[i],b*t[i]+c);
        ans+=add;
    }
    printf("%lld\n",ans);
    return 0;
}
```


### Prompt

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

Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.

For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.

You are asked to help her by calculating how many weights are required.

<image>

Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight

<image>

Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights

Input

The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.

The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.

Output

The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.

* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.

No extra characters (e.g. extra spaces) should appear in the output.

Example

Input

700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0

Output

1 3
1 1
1 0
0 3
1 1
49 74
3333 1

### Response

```cpp
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
int a, b;
int ansa = 0;
int ansb = 0;
void update(int aa,int ab) {
	if (ansa + ansb > aa + ab) {
		ansa = aa;
		ansb = ab;
		return;
	}
	if (ansa + ansb == aa + ab) {
		if (ansa*a + ansb*b > aa*a + ab*b) {
			ansa = aa;
			ansb = ab;
			return;
	}
	}
}
int main() {
	int d;
	while (cin>>a>>b>>d,a|b|d) {
		vi amal(d + 1,-1);
		vi bmal(d + 1,-1);
		ansa = 100000;
		ansb = 100000;
		for (int i = 0;i <= d;i += a) {
			if ((d - i) % b == 0)
				update(i / a, (d - i) / b);
		}
		for (int i = 0;i < 100000;i++) {
			if ((d + i*a) % b == 0)
				update(i, (d + i*a) / b);
		}
		for (int i = 0;i < 100000;i++) {
			if ((d + i*b) % a == 0)
				update((d + i*b) / a, i);
		}

		cout << ansa << ' ' << ansb << endl;
	}
}
```


### Prompt

Create a solution in CPP for the following problem:

Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he wants to know the minimum number of days he should wait before sending a ranger to collect the orbs such that the probability of him getting at least one of each kind of orb is at least <image>, where ε < 10 - 7.

To better prepare himself, he wants to know the answer for q different values of pi. Since he is busy designing the battle strategy with Sam, he asks you for your help.

Input

First line consists of two space separated integers k, q (1 ≤ k, q ≤ 1000) — number of different kinds of orbs and number of queries respectively.

Each of the next q lines contain a single integer pi (1 ≤ pi ≤ 1000) — i-th query.

Output

Output q lines. On i-th of them output single integer — answer for i-th query.

Examples

Input

1 1
1

Output

1

Input

2 2
1
2

Output

2
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double dp[10009][1009], EPS = 1e-12;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k, q, i, j;
  cin >> k >> q;
  dp[1][1] = 1;
  for (i = 2; i <= 10 * k; i++) {
    for (j = 1; j <= min(i, k); j++) {
      if (j > 1) dp[i][j] += dp[i - 1][j - 1] * (k - j + 1.0) / (k * 1.0);
      dp[i][j] += dp[i - 1][j] * j * 1.0 / (k * 1.0);
    }
  }
  while (q--) {
    cin >> j;
    for (i = 1; i <= 10 * k; i++) {
      if (dp[i][k] > ((j - 1e-7) / 2000.0) ||
          fabs(dp[i][k] - ((j - 1e-7) / 2000.0)) <= EPS) {
        break;
      }
    }
    cout << i << endl;
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.

His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.

<image>

He ate coffee mix without water again, so right now he's really messed up and can't think.

Your task is to help him by telling him what to type.

Input

The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.

Output

In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.

Examples

Input

6

Output

six

Input

99

Output

ninety-nine

Input

20

Output

twenty

Note

You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> .

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void nvastacnel(int &a) {
  while (a % 2 == 0) a /= 2;
  while (a % 3 == 0) a /= 3;
}
string y;
int main() {
  int n;
  cin >> n;
  string a1[] = {"zero", "one", "two",   "three", "four",
                 "five", "six", "seven", "eight", "nine"};
  string a2[] = {"",      "",      "twenty",  "thirty", "forty",
                 "fifty", "sixty", "seventy", "eighty", "ninety"};
  if (n <= 9)
    cout << a1[n];
  else if (n == 10)
    cout << "ten";
  else if (n == 11)
    cout << "eleven";
  else if (n == 12)
    cout << "twelve";
  else if (n == 13)
    cout << "thirteen";
  else if (n == 14)
    cout << "fourteen";
  else if (n == 15)
    cout << "fifteen";
  else if (n == 16)
    cout << "sixteen";
  else if (n == 17)
    cout << "seventeen";
  else if (n == 18)
    cout << "eighteen";
  else if (n == 19)
    cout << "nineteen";
  else {
    int sec = n % 10;
    int first = (n / 10) % 10;
    cout << a2[first];
    if (sec != 0) cout << '-' << a1[sec];
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

Let's introduce the designation <image>, where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc.

We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, strings ab and aсba can be obtained from string xacbac, and strings bx and aaa cannot be obtained from it.

Sereja has two strings, w = [a, b] and q = [c, d]. He wants to find such maximum integer p (p > 0), that [q, p] can be obtained from string w.

Input

The first line contains two integers b, d (1 ≤ b, d ≤ 107). The second line contains string a. The third line contains string c. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed 100.

Output

In a single line print an integer — the largest number p. If the required value of p doesn't exist, print 0.

Examples

Input

10 3
abab
bab

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char w[120];
char q[120];
int b, d, wlen, qlen;
int matched[120];
int main() {
  scanf("%d %d", &b, &d);
  scanf("%s", w);
  scanf("%s", q);
  wlen = strlen(w);
  qlen = strlen(q);
  for (int i = (0); i < (qlen); ++i) {
    bool ok = false;
    for (int j = (0); j < (wlen); ++j)
      if (w[j] == q[i]) ok = true;
    if (!ok) {
      puts("0");
      return 0;
    }
  }
  for (int i = (0); i < (qlen); ++i) {
    int wpos = 0;
    int qpos = i;
    matched[i] = 0;
    while (true) {
      char to_f = q[qpos];
      while (wpos < wlen && w[wpos] != to_f) ++wpos;
      if (wpos == wlen) break;
      ++wpos;
      ++qpos;
      ++matched[i];
      if (qpos == qlen) {
        qpos = 0;
      }
    }
  }
  int cnt = 0;
  int qpos = 0;
  for (int i = (0); i < (b); ++i) {
    cnt += matched[qpos];
    qpos = cnt % qlen;
  }
  int qres = cnt / qlen;
  int res = qres / d;
  cout << res << endl;
}

```


### Prompt

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

Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.

Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.

Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.

Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.

The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.

The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.

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

Output

For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.

It can be proven that it is always possible for Omkar to achieve this under the given constraints.

Example

Input

5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR

Output

0
1
1
3
2

Note

In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.

In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17;
const long long mod = 1000000007;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  bool ok = false;
  vector<long long> seg(n, 0);
  for (long long i = (0); i < (n); i++) {
    if (s[i] == 'R' && s[(i - 1 + n) % n] == 'L') {
      seg[i] = 1;
      seg[(i - 1 + n) % n] = -1;
      ok = true;
    }
  }
  vector<string> xs;
  if (!ok) {
    xs.push_back(s);
  } else {
    long long cnt = 0, st = 0;
    while (cnt < n) {
      if (seg[st] == 1) {
        string x;
        while (seg[st] != -1) {
          x.push_back(s[st]);
          st = (st + 1) % n;
        }
        x.push_back(s[st]);
        cnt += x.length();
        xs.push_back(x);
        st = (st + 1) % n;
      } else
        st = (st + 1) % n;
    }
  }
  long long ans = 0;
  for (auto x : xs) {
    long long l, r;
    l = r = 0;
    for (long long i = (0); i < (x.size()); i++) (x[i] == 'R') ? r++ : l++;
    if (l && r) {
      l--;
      r--;
    } else if (r) {
      ans++;
      r -= 2;
    } else if (l) {
      ans++;
      l -= 2;
    }
    ans += r / 3 + (r % 3 == 2) + l / 3 + (l % 3 == 2);
  }
  cout << ans << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}

```