### Prompt

Create a solution in Cpp for the following problem:

Snow Queen told Kay to form a word "eternity" using pieces of ice. Kay is eager to deal with the task, because he will then become free, and Snow Queen will give him all the world and a pair of skates.

Behind the palace of the Snow Queen there is an infinite field consisting of cells. There are n pieces of ice spread over the field, each piece occupying exactly one cell and no two pieces occupying the same cell. To estimate the difficulty of the task Kay looks at some squares of size k × k cells, with corners located at the corners of the cells and sides parallel to coordinate axis and counts the number of pieces of the ice inside them.

This method gives an estimation of the difficulty of some part of the field. However, Kay also wants to estimate the total difficulty, so he came up with the following criteria: for each x (1 ≤ x ≤ n) he wants to count the number of squares of size k × k, such that there are exactly x pieces of the ice inside.

Please, help Kay estimate the difficulty of the task given by the Snow Queen.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 300) — the number of pieces of the ice and the value k, respectively. Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — coordinates of the cell containing i-th piece of the ice. It's guaranteed, that no two pieces of the ice occupy the same cell.

Output

Print n integers: the number of squares of size k × k containing exactly 1, 2, ..., n pieces of the ice.

Example

Input

5 3
4 5
4 6
5 5
5 6
7 7

Output

10 8 1 4 0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
multiset<int> s;
int n, K, top, q[100000 + 5];
pair<int, int> a[100000 + 5];
long long ans[100000 + 5];
int main() {
  n = read();
  K = read();
  for (int i = 1; i <= n; ++i) a[i].first = read(), a[i].second = read();
  sort(a + 1, a + n + 1);
  for (int i = 1, j; i <= n; i = j + 1) {
    for (j = i + 1; j <= n && a[j].first - a[j - 1].first < K; ++j)
      ;
    --j;
    s.clear();
    for (int k = a[i].first, l = i, r = i; k <= a[j].first + K - 1; ++k) {
      for (; l <= j && a[l].first <= k; ++l) s.insert(a[l].second);
      for (; r <= j && a[r].first + K <= k; ++r)
        s.erase(s.lower_bound(a[r].second));
      top = 0;
      for (multiset<int>::iterator it = s.begin(); it != s.end(); ++it)
        q[++top] = *it;
      for (int L = 1, R = 1, pre = q[1] - 1; L <= top;) {
        if (R <= top && q[R] <= q[L] + K)
          ans[R - L] += q[R] - pre, pre = q[R], ++R;
        else
          ans[R - L] += q[L] + K - pre, pre = q[L] + K, ++L;
      }
    }
  }
  for (int i = 1; i <= n; ++i) printf("%lld ", ans[i]);
  return 0;
}

```


### Prompt

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

Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was written.

Grigory couldn't understand for a long time what these letters remind him of, so he became interested in the following question: if we put a letter "V" or "K" on each unreadable position, which values can the period of the resulting string be equal to?

A period of a string is such an integer d from 1 to the length of the string that if we put the string shifted by d positions to the right on itself, then all overlapping letters coincide. For example, 3 and 5 are periods of "VKKVK".

Input

There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases.

There is an empty line before each test case. Each test case is described in two lines: the first line contains single integer n (1 ≤ n ≤ 5·105) — the length of the string, the second line contains the string of length n, consisting of letters "V", "K" and characters "?". The latter means the letter on its position is unreadable.

It is guaranteed that the sum of lengths among all test cases doesn't exceed 5·105.

For hacks you can only use tests with one test case.

Output

For each test case print two lines. In the first line print the number of possible periods after we replace each unreadable letter with "V" or "K". In the next line print all these values in increasing order.

Example

Input

3

5
V??VK

6
??????

4
?VK?

Output

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

Note

In the first test case from example we can obtain, for example, "VKKVK", which has periods 3 and 5.

In the second test case we can obtain "VVVVVV" which has all periods from 1 to 6.

In the third test case string "KVKV" has periods 2 and 4, and string "KVKK" has periods 3 and 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1048576;
struct comp {
  double x, y;
  comp() {}
  comp(double a, double b) {
    x = a;
    y = b;
  }
  comp operator+(const comp &A) const { return comp(x + A.x, y + A.y); }
  comp operator-(const comp &A) const { return comp(x - A.x, y - A.y); }
  comp operator*(const comp &A) const {
    return comp(x * A.x - y * A.y, x * A.y + y * A.x);
  }
} a[maxn], b[maxn];
const double pi = acos(-1.0);
void fft(comp *a, int N, int sign) {
  for (int i = 1, j = 0, k = N; i < N; ++i, k = N) {
    do j ^= (k >>= 1);
    while (j < k);
    if (j < i) swap(a[i], a[j]);
  }
  for (int j = 2; j <= N; j <<= 1) {
    int m = j >> 1;
    comp wn(cos(2.0 * pi / j), sign * sin(2.0 * pi / j));
    for (comp *p = a; p != a + N; p = p + j) {
      comp w(1, 0);
      for (int k = 0; k < m; ++k, w = w * wn) {
        comp t = w * p[m + k];
        p[m + k] = p[k] - t;
        p[k] = p[k] + t;
      }
    }
  }
  if (sign == -1) {
    for (int i = 0; i < N; ++i) a[i].x /= N;
  }
}
int n;
char str[maxn];
int seq[maxn], revseq[maxn];
double sum[maxn];
bool check(int x) {
  for (int i = x; i < n; i += x) {
    if (fabs(sum[n - i - 1]) > 1e-6) return false;
  }
  return true;
}
void work() {
  scanf("%d%s", &n, str);
  for (int i = 0; i < n; ++i) {
    seq[i] = (str[i] == '?') ? 0 : (str[i] == 'V' ? 1 : 2);
  }
  for (int i = 0; i < n; ++i) {
    revseq[i] = seq[n - i - 1];
  }
  for (int i = 0; i < n; ++i) {
    a[i] = comp(seq[i] * seq[i] * seq[i], 0);
    b[i] = comp(revseq[i], 0);
  }
  int N = 1;
  while (N <= n) N <<= 1;
  N <<= 1;
  for (int i = 0; i < N; ++i) sum[i] = 0;
  for (int i = n; i < N; ++i) a[i] = comp(0, 0);
  for (int i = n; i < N; ++i) b[i] = comp(0, 0);
  fft(a, N, 1);
  fft(b, N, 1);
  for (int i = 0; i < N; ++i) a[i] = a[i] * b[i];
  fft(a, N, -1);
  for (int i = 0; i < N; ++i) sum[i] += a[i].x;
  for (int i = 0; i < n; ++i) {
    a[i] = comp(seq[i], 0);
    b[i] = comp(revseq[i] * revseq[i] * revseq[i], 0);
  }
  for (int i = n; i < N; ++i) a[i] = comp(0, 0);
  for (int i = n; i < N; ++i) b[i] = comp(0, 0);
  fft(a, N, 1);
  fft(b, N, 1);
  for (int i = 0; i < N; ++i) a[i] = a[i] * b[i];
  fft(a, N, -1);
  for (int i = 0; i < N; ++i) sum[i] += a[i].x;
  for (int i = 0; i < n; ++i) {
    a[i] = comp(seq[i] * seq[i], 0);
    b[i] = comp(revseq[i] * revseq[i], 0);
  }
  for (int i = n; i < N; ++i) a[i] = comp(0, 0);
  for (int i = n; i < N; ++i) b[i] = comp(0, 0);
  fft(a, N, 1);
  fft(b, N, 1);
  for (int i = 0; i < N; ++i) a[i] = a[i] * b[i];
  fft(a, N, -1);
  for (int i = 0; i < N; ++i) sum[i] -= 2.0 * a[i].x;
  int cnt = 1;
  for (int i = 1; i < n; ++i) {
    if (check(i)) cnt++;
  }
  printf("%d\n", cnt);
  for (int i = 1; i < n; ++i) {
    if (check(i)) printf("%d ", i);
  }
  printf("%d\n", n);
}
int main() {
  a[0].x = 1;
  a[1].x = 1;
  int tests;
  scanf("%d", &tests);
  while (tests--) {
    work();
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

This is the hard version of the problem. You can find the easy version in the Div. 2 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.

This is an interactive problem.

You're considering moving to another city, where one of your friends already lives. There are n cafés in this city, where n is a power of two. The i-th café produces a single variety of coffee a_i.

As you're a coffee-lover, before deciding to move or not, you want to know the number d of distinct varieties of coffees produced in this city.

You don't know the values a_1, …, a_n. Fortunately, your friend has a memory of size k, where k is a power of two.

Once per day, you can ask him to taste a cup of coffee produced by the café c, and he will tell you if he tasted a similar coffee during the last k days.

You can also ask him to take a medication that will reset his memory. He will forget all previous cups of coffee tasted. You can reset his memory at most 30\ 000 times.

More formally, the memory of your friend is a queue S. Doing a query on café c will:

  * Tell you if a_c is in S;
  * Add a_c at the back of S;
  * If |S| > k, pop the front element of S.

Doing a reset request will pop all elements out of S.

Your friend can taste at most (3n^2)/(2k) cups of coffee in total. Find the diversity d (number of distinct values in the array a).

Note that asking your friend to reset his memory does not count towards the number of times you ask your friend to taste a cup of coffee.

In some test cases the behavior of the interactor is adaptive. It means that the array a may be not fixed before the start of the interaction and may depend on your queries. It is guaranteed that at any moment of the interaction, there is at least one array a consistent with all the answers given so far.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 1024, k and n are powers of two).

It is guaranteed that (3n^2)/(2k) ≤ 15\ 000.

Interaction

You begin the interaction by reading n and k.

  * To ask your friend to taste a cup of coffee produced by the café c, in a separate line output

? c

Where c must satisfy 1 ≤ c ≤ n. Don't forget to flush, to get the answer.

In response, you will receive a single letter Y (yes) or N (no), telling you if variety a_c is one of the last k varieties of coffee in his memory.

  * To reset the memory of your friend, in a separate line output the single letter R in upper case. You can do this operation at most 30\ 000 times.
  * When you determine the number d of different coffee varieties, output

! d

In case your query is invalid, you asked more than (3n^2)/(2k) queries of type ? or you asked more than 30\ 000 queries of type R, the program will print the letter E and will finish interaction. You will receive a Wrong Answer verdict. Make sure to exit immediately to avoid getting other verdicts.

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

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

Hack format

The first line should contain the word fixed

The second line should contain two integers n and k, separated by space (1 ≤ k ≤ n ≤ 1024, k and n are powers of two).

It must hold that (3n^2)/(2k) ≤ 15\ 000.

The third line should contain n integers a_1, a_2, …, a_n, separated by spaces (1 ≤ a_i ≤ n).

Examples

Input

4 2
N
N
Y
N
N
N
N

Output

? 1
? 2
? 3
? 4
R
? 4
? 1
? 2
! 3

Input

8 8
N
N
N
N
Y
Y

Output

? 2
? 6
? 4
? 5
? 2
? 5
! 6

Note

In the first example, the array is a = [1, 4, 1, 3]. The city produces 3 different varieties of coffee (1, 3 and 4).

The successive varieties of coffee tasted by your friend are 1, 4, 1, 3, 3, 1, 4 (bold answers correspond to Y answers). Note that between the two ? 4 asks, there is a reset memory request R, so the answer to the second ? 4 ask is N. Had there been no reset memory request, the answer to the second ? 4 ask is Y.

In the second example, the array is a = [1, 2, 3, 4, 5, 6, 6, 6]. The city produces 6 different varieties of coffee.

The successive varieties of coffee tasted by your friend are 2, 6, 4, 5, 2, 5.

### Response

```cpp
#include <bits/stdc++.h>
namespace IO {
char gc() { return getchar(); }
template <typename Tp>
bool get1(Tp &x) {
  bool neg = 0;
  char c = gc();
  while (c != EOF && (c < '0' || c > '9') && c != '-') c = gc();
  if (c == '-') c = gc(), neg = 1;
  if (c == EOF) return false;
  x = 0;
  for (; c >= '0' && c <= '9'; c = gc()) x = x * 10 + c - '0';
  if (neg) x = -x;
  return true;
}
template <typename Tp>
void printendl(Tp x) {
  if (x < 0) putchar('-'), x = -x;
  static short a[40], sz;
  sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
  puts("");
}
}  // namespace IO
using IO::get1;
using IO::printendl;
const int inf = 0x3f3f3f3f;
const long long Linf = 1ll << 61;
void reset() {
  puts("R");
  fflush(stdout);
}
int count;
int query(int c) {
  static char s[5];
  count++;
  printf("? %d\n", c);
  fflush(stdout);
  scanf("%s", s);
  if (s[0] == 'Y')
    return 1;
  else
    return 0;
}
const int maxn = 1111;
int n, k;
bool alive[maxn];
int main() {
  get1(n) && get1(k);
  int Block = std::max(1, k / 2), BlockN = n / Block;
  for (int i = 1; i <= n; i++) alive[i] = 1;
  for (int dltB = 1; dltB < BlockN; dltB++) {
    for (int stB = 1; stB <= dltB && stB + dltB <= BlockN; stB++) {
      reset();
      for (int b = stB; b <= BlockN; b += dltB) {
        for (int i = 0; i < Block; i++) {
          int cur = (b - 1) * Block + i + 1;
          if (query(cur)) alive[cur] = 0;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += alive[i];
  printf("! %d\n", ans);
  return 0;
}

```


### Prompt

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

Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.

Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and b, erase them from the sequence, and append to the sequence either a + b, or a - b, or a × b.

After n - 1 steps there is only one number left. Can you make this number equal to 24?

Input

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

Output

If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes).

If there is a way to obtain 24 as the result number, in the following n - 1 lines print the required operations an operation per line. Each operation should be in form: "a op b = c". Where a and b are the numbers you've picked at this operation; op is either "+", or "-", or "*"; c is the result of corresponding operation. Note, that the absolute value of c mustn't be greater than 1018. The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces.

If there are multiple valid answers, you may print any of them.

Examples

Input

1

Output

NO

Input

8

Output

YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
queue<long long> q;
void solve() {
  int n;
  cin >> n;
  if (n < 4) {
    cout << "NO";
    return;
  }
  cout << "YES\n";
  vector<int> v;
  int cnt = 0;
  if (n % 2) {
    for (int i = n; i > 6; i -= 2) {
      cout << i << " - " << i - 1 << " = 1\n";
      cnt++;
    }
    cout << "4 * 2 = 8\n";
    cout << "5 * 3 = 15\n";
    cout << "15 + 8 = 23\n";
    cout << "23 + 1 = 24\n";
    for (int i = 1; i <= cnt - 1; i += 2) {
      cout << "24 + 1 = 25\n";
      cout << "25 - 1 = 24\n";
    }
    if (cnt % 2) cout << "24 * 1 = 24";
  } else {
    for (int i = n; i > 5; i -= 2) {
      cout << i << " - " << i - 1 << " = 1\n";
      cnt++;
    }
    cout << "4 * 3 = 12\n";
    cout << "12 * 2 = 24\n";
    for (int i = 1; i <= cnt; i += 2) {
      cout << "24 + 1 = 25\n";
      cout << "25 - 1 = 24\n";
    }
    if (cnt % 2 == 0) cout << "24 * 1 = 24";
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
    cout << endl;
  }
}

```


### Prompt

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

Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0).

Next day Misha couldn't remember what graph he initially had. Misha has values degreev and sv left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.

Input

The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.

The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.

Output

In the first line print number m, the number of edges of the graph.

Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).

Edges can be printed in any order; vertices of the edge can also be printed in any order.

Examples

Input

3
2 3
1 0
1 0

Output

2
1 0
2 0

Input

2
1 1
1 0

Output

1
0 1

Note

The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 70000;
int deg[N], xorsum[N], xorhave[N], n;
vector<pair<int, int> > ans;
stack<int> nodes;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &deg[i], &xorsum[i]);
    if (deg[i] == 1) {
      nodes.push(i);
    }
  }
  while (!nodes.empty()) {
    if (deg[nodes.top()] == 0) {
      nodes.pop();
      continue;
    }
    int newnode = xorhave[nodes.top()] ^ xorsum[nodes.top()];
    deg[newnode]--;
    deg[nodes.top()]--;
    xorhave[newnode] ^= nodes.top();
    ans.push_back(make_pair(nodes.top(), newnode));
    nodes.pop();
    if (deg[newnode] == 1) {
      nodes.push(newnode);
    }
  }
  int sz = ans.size();
  printf("%d\n", sz);
  for (int i = 0; i < sz; i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

<image>

Recently, a wild Krakozyabra appeared at Jelly Castle. It is, truth to be said, always eager to have something for dinner.

Its favorite meal is natural numbers (typically served with honey sauce), or, to be more precise, the zeros in their corresponding decimal representations. As for other digits, Krakozyabra dislikes them; moreover, they often cause it indigestion! So, as a necessary precaution, Krakozyabra prefers to sort the digits of a number in non-descending order before proceeding to feast. Then, the leading zeros of the resulting number are eaten and the remaining part is discarded as an inedible tail.

For example, if Krakozyabra is to have the number 57040 for dinner, its inedible tail would be the number 457.

Slastyona is not really fond of the idea of Krakozyabra living in her castle. Hovewer, her natural hospitality prevents her from leaving her guest without food. Slastyona has a range of natural numbers from L to R, which she is going to feed the guest with. Help her determine how many distinct inedible tails are going to be discarded by Krakozyabra by the end of the dinner.

Input

In the first and only string, the numbers L and R are given – the boundaries of the range (1 ≤ L ≤ R ≤ 1018).

Output

Output the sole number – the answer for the problem.

Examples

Input

1 10

Output

9

Input

40 57

Output

17

Input

157 165

Output

9

Note

In the first sample case, the inedible tails are the numbers from 1 to 9. Note that 10 and 1 have the same inedible tail – the number 1.

In the second sample case, each number has a unique inedible tail, except for the pair 45, 54. The answer to this sample case is going to be (57 - 40 + 1) - 1 = 17.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int l[20], r[20], cnt[20], tmp[20], tmp2[20];
long long ans;
void inp(int *a) {
  long long x;
  cin >> x;
  for (int i = 0; i < 20; i++) {
    a[19 - i] = x % 10;
    x /= 10;
  }
}
bool checkr(int pos) {
  memcpy(tmp2, tmp, sizeof tmp2);
  int lim = 0;
  while (pos < 20) {
    while (lim < 20 && tmp2[lim] == 0) lim++;
    if (r[pos] < lim) return 0;
    if (r[pos] > lim) return 1;
    tmp2[r[pos]]--, pos++;
  }
  return 1;
}
bool checkl(int pos) {
  memcpy(tmp2, tmp, sizeof tmp2);
  int lim = 9;
  while (pos < 20) {
    while (lim >= 0 && tmp2[lim] == 0) lim--;
    if (l[pos] > lim) return 0;
    if (l[pos] < lim) return 1;
    tmp2[l[pos]]--, pos++;
  }
  return 1;
}
bool ok() {
  memcpy(tmp, cnt, sizeof cnt);
  int pt = 0;
  while (pt < 20 && l[pt] == r[pt]) {
    if (tmp[l[pt]] == 0) return 0;
    tmp[l[pt]]--;
    pt++;
  }
  if (pt == 20) return 1;
  for (int w = l[pt] + 1; w < r[pt]; w++) {
    if (tmp[w]) return 1;
  }
  if (tmp[l[pt]]) {
    tmp[l[pt]]--;
    if (checkl(pt + 1)) return 1;
    tmp[l[pt]]++;
  }
  if (tmp[r[pt]]) {
    tmp[r[pt]]--;
    if (checkr(pt + 1)) return 1;
  }
  return 0;
}
void go(int sm = 0, int who = 1) {
  if (who == 10) {
    cnt[0] = 20 - sm;
    ans += ok();
    return;
  }
  for (cnt[who] = 0; sm <= 18; cnt[who]++, sm++) {
    go(sm, who + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  inp(l), inp(r), go();
  return cout << ans << endl, 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Arkady's code contains n variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.

He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincide with some old name of another or same variable). Among such possibilities he wants to find the way with the smallest possible total length of the new names.

A string a is a prefix of a string b if you can delete some (possibly none) characters from the end of b and obtain a.

Please find this minimum possible total length of new names.

Input

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

The next n lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than 10^5. The variable names are distinct.

Output

Print a single integer — the minimum possible total length of new variable names.

Examples

Input

3
codeforces
codehorses
code

Output

6

Input

5
abba
abb
ab
aa
aacada

Output

11

Input

3
telegram
digital
resistance

Output

3

Note

In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c".

In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
struct Trie_Tree {
  int cnt, Trie[MAXN + 5][30];
  int fin[MAXN + 5], depth[MAXN + 5];
  void Build() {
    cnt = 0;
    memset(Trie, 0, sizeof(Trie));
    memset(fin, 0, sizeof(fin));
  }
  void Insert(char *str) {
    int len = strlen(str), u = 0;
    for (int i = 0; i < len; i++) {
      int num = str[i] - 'a';
      if (!Trie[u][num]) Trie[u][num] = ++cnt;
      depth[Trie[u][num]] = depth[u] + 1;
      u = Trie[u][num];
    }
    fin[u]++;
  }
} Tree;
struct cmp {
  bool operator()(int a, int b) { return Tree.depth[a] < Tree.depth[b]; }
};
priority_queue<int, vector<int>, cmp> Que[MAXN + 5];
void solve(int root) {
  for (int i = 0; i < 26; i++) {
    if (Tree.Trie[root][i] == 0) continue;
    solve(Tree.Trie[root][i]);
    while (!Que[Tree.Trie[root][i]].empty()) {
      Que[root].push(Que[Tree.Trie[root][i]].top());
      Que[Tree.Trie[root][i]].pop();
    }
  }
  if (!Que[root].empty() && Tree.fin[root] == 0 && root != 0) {
    Tree.fin[Que[root].top()]--;
    Tree.fin[root]++;
    Que[root].pop();
  }
  if (Tree.fin[root] == 1) Que[root].push(root);
}
int n;
char str[MAXN + 5];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", str), Tree.Insert(str);
  solve(0);
  int sum = 0;
  while (!Que[0].empty()) {
    sum += Tree.depth[Que[0].top()];
    Que[0].pop();
  }
  printf("%d\n", sum);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.

Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card contains a digit: 0 or 1. Players move in turns and Masha moves first. During each move a player should remove a card from the table and shift all other cards so as to close the gap left by the removed card. For example, if before somebody's move the cards on the table formed a sequence 01010101, then after the fourth card is removed (the cards are numbered starting from 1), the sequence will look like that: 0100101.

The game ends when exactly two cards are left on the table. The digits on these cards determine the number in binary notation: the most significant bit is located to the left. Masha's aim is to minimize the number and Petya's aim is to maximize it.

An unpleasant accident occurred before the game started. The kids spilled juice on some of the cards and the digits on the cards got blurred. Each one of the spoiled cards could have either 0 or 1 written on it. Consider all possible variants of initial arrangement of the digits (before the juice spilling). For each variant, let's find which two cards are left by the end of the game, assuming that both Petya and Masha play optimally. An ordered pair of digits written on those two cards is called an outcome. Your task is to find the set of outcomes for all variants of initial digits arrangement.

Input

The first line contains a sequence of characters each of which can either be a "0", a "1" or a "?". This sequence determines the initial arrangement of cards on the table from the left to the right. The characters "?" mean that the given card was spoiled before the game. The sequence's length ranges from 2 to 105, inclusive.

Output

Print the set of outcomes for all possible initial digits arrangements. Print each possible outcome on a single line. Each outcome should be represented by two characters: the digits written on the cards that were left by the end of the game. The outcomes should be sorted lexicographically in ascending order (see the first sample).

Examples

Input

????

Output

00
01
10
11

Input

1010

Output

10

Input

1?1

Output

01
11

Note

In the first sample all 16 variants of numbers arrangement are possible. For the variant 0000 the outcome is 00. For the variant 1111 the outcome is 11. For the variant 0011 the outcome is 01. For the variant 1100 the outcome is 10. Regardless of outcomes for all other variants the set which we are looking for will contain all 4 possible outcomes.

In the third sample only 2 variants of numbers arrangement are possible: 111 and 101. For the variant 111 the outcome is 11. For the variant 101 the outcome is 01, because on the first turn Masha can remove the first card from the left after which the game will end.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[1234567], t[1234567];
string evaluate(int n) {
  queue<int> q[2];
  for (int i = 0; i < n; ++i) {
    q[t[i] - '0'].push(i);
  }
  int cnt = 0;
  while (cnt < n - 2) q[cnt % 2 == 0].pop(), ++cnt;
  if (q[0].front() < q[1].front()) return "01";
  return "10";
}
int main() {
  scanf("%s", s);
  int n = strlen(s);
  set<string> ans;
  int zero = 0, one = 0, spoiled = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0')
      zero++;
    else if (s[i] == '1')
      one++;
    else
      spoiled++;
  }
  for (int extraZero = 0; extraZero <= spoiled; ++extraZero) {
    int zeros = zero + extraZero;
    int ones = one + spoiled - extraZero;
    if (zeros - 2 >= ones || zeros > ones)
      ans.insert("00");
    else if (ones - 2 >= zeros)
      ans.insert("11");
    else {
      int remain = extraZero;
      for (int i = 0; i < n; ++i) {
        if (s[i] != '?')
          t[i] = s[i];
        else if (remain)
          t[i] = '0', remain--;
        else
          t[i] = '1';
      }
      ans.insert(evaluate(n));
      remain = spoiled - extraZero;
      for (int i = 0; i < n; ++i) {
        if (s[i] != '?')
          t[i] = s[i];
        else if (remain)
          t[i] = '1', remain--;
        else
          t[i] = '0';
      }
      ans.insert(evaluate(n));
    }
  }
  for (auto p : ans) puts(p.c_str());
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.

You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches.

Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch.

Input

The only line contains an integer n (1 ≤ n ≤ 10000).

Output

Print two non-negative space-separated integers a and b, where a is the numbers of feet and b is the number of inches.

Examples

Input

42

Output

1 2

Input

5

Output

0 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, i, f;
int main() {
  cin >> n;
  while (n >= 3) {
    n -= 3;
    i++;
  }
  if (n == 2) i++;
  while (i >= 12) {
    i -= 12;
    f++;
  }
  cout << f << " " << i;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet.

He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are H blocks on every square:

* Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least M and at most M + D blocks on that square.

Tell him how many ways there are to have H blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 10^9+7.

Constraints

* 2 \leq N \leq 10^6
* 1 \leq D \leq H \leq 10^6
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N H D

Output

Print the number of ways to have H blocks on every square, modulo 10^9+7.

Examples

Input

2 2 1

Output

6

Input

2 30 15

Output

94182806

Input

31415 9265 3589

Output

312069529

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=1000000007;
ll N,H,D;
ll dp[2][1000005];
ll fac[1000005];
int main(){
  cin>>N>>H>>D;
  fac[0]=1;ll sum=0;
  for(ll i=1;i<=N;i++){
    fac[i]=(fac[i-1]*i)%mod;
    sum=(sum+fac[i])%mod;
  }dp[1][0]=fac[N];
  for(ll i=1;i<H;i++){
  dp[1][i]=(sum*(dp[0][i-1]+dp[1][i-1]))%mod;
    dp[0][i]=(dp[0][i-1]+dp[1][i-1])%mod;
    if(0<=i-D)
      dp[0][i]=(dp[0][i]-dp[1][i-D]+mod)%mod;
  }ll ans=(dp[0][H-1]+dp[1][H-1])%mod;
  cout<<ans<<endl;

  return 0;
}
```


### Prompt

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

Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree T:

  1. Set pointer to the root of a tree.
  2. Return success if the value in the current vertex is equal to the number you are looking for
  3. Go to the left child of the vertex if the value in the current vertex is greater than the number you are looking for
  4. Go to the right child of the vertex if the value in the current vertex is less than the number you are looking for
  5. Return fail if you try to go to the vertex that doesn't exist

Here is the pseudo-code of the described algorithm:

    bool find(TreeNode t, int x) {
        if (t == null)
            return false;
        if (t.value == x)
            return true;
        if (x < t.value)
            return find(t.left, x);
        else
            return find(t.right, x);
    }
    find(root, x);

The described algorithm works correctly if the tree is binary search tree (i.e. for each node the values of left subtree are less than the value in the node, the values of right subtree are greater than the value in the node). But it can return invalid result if tree is not a binary search tree.

Since the given tree is not necessarily a binary search tree, not all numbers can be found this way. Your task is to calculate, how many times the search will fail being running on every value from the tree.

If the tree has multiple vertices with the same values on them then you should run algorithm on every one of them separately.

Input

First line contains integer number n (1 ≤ n ≤ 105) — number of vertices in the tree.

Each of the next n lines contains 3 numbers v, l, r (0 ≤ v ≤ 109) — value on current vertex, index of the left child of the vertex and index of the right child of the vertex, respectively. If some child doesn't exist then number  - 1 is set instead. Note that different vertices of the tree may contain the same values.

Output

Print number of times when search algorithm will fail.

Examples

Input

3
15 -1 -1
10 1 3
5 -1 -1

Output

2

Input

8
6 2 3
3 4 5
12 6 7
1 -1 8
4 -1 -1
5 -1 -1
14 -1 -1
2 -1 -1

Output

1

Note

In the example the root of the tree in vertex 2. Search of numbers 5 and 15 will return fail because on the first step algorithm will choose the subtree which doesn't contain numbers you are looking for.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int n, rt;
int val[100005], pa[100005], son[100005][2];
int ans;
multiset<int> lebnd, ribnd;
map<int, bool> can;
void dfs(int x) {
  if (*lebnd.rbegin() <= val[x] && *ribnd.begin() >= val[x]) can[val[x]] = 1;
  ribnd.insert(val[x]);
  if (son[x][0] != -1) dfs(son[x][0]);
  ribnd.erase(ribnd.find(val[x]));
  lebnd.insert(val[x]);
  if (son[x][1] != -1) dfs(son[x][1]);
  lebnd.erase(lebnd.find(val[x]));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &val[i], &son[i][0], &son[i][1]);
    if (son[i][0] != -1) pa[son[i][0]] = i;
    if (son[i][1] != -1) pa[son[i][1]] = i;
  }
  rt = 1;
  while (pa[rt]) rt = pa[rt];
  lebnd.insert(-INF), ribnd.insert(INF);
  dfs(rt);
  for (int i = 1; i <= n; i++)
    if (!can.count(val[i])) ans++;
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.

In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?

Constraints

* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.

Input

Input is given from Standard Input in the following format:

a b

Output

Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.

Examples

Input

5 5

Output

5

Input

2 1

Output

1

Input

11 30

Output

11

### Response

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

int main(){
  int A,B;cin>>A>>B;
  A<=B ? cout<<A<<endl:cout<<A-1<<endl;
}
```


### Prompt

Please create a solution in cpp to the following problem:

Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side.

Determine a minimal number of wooden bars which are needed to make the frames for two doors. Petya can cut the wooden bars into any parts, but each side of each door should be a solid piece of a wooden bar (or a whole wooden bar).

Input

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the length of each wooden bar.

The second line contains a single integer a (1 ≤ a ≤ n) — the length of the vertical (left and right) sides of a door frame.

The third line contains a single integer b (1 ≤ b ≤ n) — the length of the upper side of a door frame.

Output

Print the minimal number of wooden bars with length n which are needed to make the frames for two doors.

Examples

Input

8
1
2

Output

1

Input

5
3
4

Output

6

Input

6
4
2

Output

4

Input

20
5
6

Output

2

Note

In the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8.

In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105 + 777, maxd = 1e8;
const long long mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;
int n, a, b;
int m[7];
int main() {
  scanf("%d %d %d", &n, &a, &b);
  m[0] = m[1] = b;
  m[2] = m[3] = m[4] = m[5] = a;
  sort(m, m + 6);
  int ans = 6;
  do {
    int sum = n, i = 0, t = 1;
    for (int i = 0; i < 6; ++i) {
      if (sum < m[i]) {
        t++;
        sum = n - m[i];
      } else
        sum -= m[i];
    }
    ans = min(ans, t);
  } while (next_permutation(m, m + 6));
  printf("%d", ans);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, if Jack uses the sequence 'right, left, break', when the sergeant yells: 'Left! Right! Left! Right! Left! Right!', Jack first makes a step with the right foot, then one with the left foot, then he is confused and stops for a moment, then again - this time according to the order - starts with the right foot, then uses the left foot, then - to the sergeant's irritation - he stops to catch his breath, to incorrectly start with the right foot again... Marching this way, Jack will make the step that he is supposed to in the given moment in only one third of cases.

When the officers convinced him he should do something about it, Jack decided to modify the basic sequence of steps that he repeats. However, in order not to get too tired, he has decided that the only thing he'll do is adding any number of breaks in any positions of the original sequence (a break corresponds to stopping for the duration of one step). Of course, Jack can't make a step on the same foot twice in a row, if there is no pause between these steps. It is, however, not impossible that the sequence of steps he used so far is incorrect (it would explain a lot, actually).

Help Private Jack! Given the sequence of steps he keeps repeating, calculate the maximal percentage of time that he can spend marching correctly after adding some breaks to his scheme.

Input

The first line of input contains a sequence consisting only of characters 'L', 'R' and 'X', where 'L' corresponds to a step with the left foot, 'R' — with the right foot, and 'X' — to a break. The length of the sequence will not exceed 106.

Output

Output the maximum percentage of time that Jack can spend marching correctly, rounded down to exactly six digits after the decimal point.

Examples

Input

X

Output

0.000000

Input

LXRR

Output

50.000000

Note

In the second example, if we add two breaks to receive LXXRXR, Jack will march: LXXRXRLXXRXRL... instead of LRLRLRLRLRLRL... and will make the correct step in half the cases. If we didn't add any breaks, the sequence would be incorrect — Jack can't step on his right foot twice in a row.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
char c[N], s[N];
double f[N][2];
int m = 0;
inline bool check(double mid) {
  for (register int i = 1; i <= m; i++) {
    f[i][0] = f[i][1] = INT_MIN;
  }
  f[0][0] = 0;
  f[0][1] = -mid;
  for (register int i = 1; i <= m; i++) {
    if (s[i] == 'L') {
      f[i][1] = max(f[i][1], f[i - 1][0] + 1 - mid);
    } else {
      f[i][1] = max(f[i][1], f[i - 1][0] - mid);
    }
    if (s[i] == 'R') {
      f[i][0] = max(f[i][0], f[i - 1][1] + 1 - mid);
    } else {
      f[i][0] = max(f[i][0], f[i - 1][1] - mid);
    }
    f[i][1] = max(f[i][1], f[i][0] - mid);
    f[i][0] = max(f[i][0], f[i][1] - mid);
  }
  if (f[m][0] > 0) {
    return 1;
  } else {
    return 0;
  }
}
signed main() {
  scanf("%s", c + 1);
  int n = strlen(c + 1);
  if (c[1] == c[n] && c[1] == 'R') {
    m++;
    s[m] = 'X';
  }
  for (register int i = 1; i <= n; i++) {
    m++;
    s[m] = c[i];
    if (i != n && c[i] != 'X' && c[i + 1] != 'X' && c[i] == c[i + 1]) {
      m++;
      s[m] = 'X';
    }
  }
  if (s[1] != 'X' && s[m] == s[1] && s[m] == 'L') {
    m++;
    s[m] = 'X';
  }
  double l = 0, r = 1;
  double ans = 0;
  while (l <= r - 1e-9) {
    double mid = (l + r) / 2;
    if (check(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  int count = (l + 1e-9) * 1e8;
  printf("%d.%.06d", count / 1000000, count % 1000000);
  return 0;
}

```


### Prompt

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

You are given two positive integer numbers x and y. An array F is called an y-factorization of x iff the following conditions are met:

  * There are y elements in F, and all of them are integer numbers;
  * <image>.

You have to count the number of pairwise distinct arrays that are y-factorizations of x. Two arrays A and B are considered different iff there exists at least one index i (1 ≤ i ≤ y) such that Ai ≠ Bi. Since the answer can be very large, print it modulo 109 + 7.

Input

The first line contains one integer q (1 ≤ q ≤ 105) — the number of testcases to solve.

Then q lines follow, each containing two integers xi and yi (1 ≤ xi, yi ≤ 106). Each of these lines represents a testcase.

Output

Print q integers. i-th integer has to be equal to the number of yi-factorizations of xi modulo 109 + 7.

Example

Input

2
6 3
4 2

Output

36
6

Note

In the second testcase of the example there are six y-factorizations:

  * { - 4, - 1};
  * { - 2, - 2};
  * { - 1, - 4};
  * {1, 4};
  * {2, 2};
  * {4, 1}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long fac[2000005];
long long fastpow(long long base, long long ex) {
  long long ret = 1;
  while (ex) {
    if (ex % 2) {
      ret *= base;
      ret %= mod;
      ex--;
    }
    base *= base;
    base %= mod;
    ex /= 2;
  }
  return ret;
}
long long Comb(long long n, long long r) {
  long long ret = fac[n];
  ret *= fastpow(fac[r], mod - 2);
  ret %= mod;
  ret *= fastpow(fac[n - r], mod - 2);
  ret %= mod;
  return ret;
}
void solve(int tt) {
  long long n, m;
  cin >> n >> m;
  long long ans = 1;
  long long temp = n;
  for (int i = 2; i * i <= temp; i++) {
    long long counter = 0;
    while (n % i == 0) {
      n /= i;
      counter++;
    }
    if (counter) {
      ans *= Comb(counter + m - 1, m - 1);
      ans %= mod;
    }
  }
  if (n > 1) {
    ans *= (Comb(m, m - 1));
    ans %= mod;
  }
  ans *= fastpow(2, m - 1);
  ans %= mod;
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  fac[0] = 1;
  for (long long(i) = (1); (i) < (2e6 + 4); (i)++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  int tc;
  tc = 1;
  cin >> tc;
  for (long long(tt) = (1); (tt) < (tc + 1); (tt)++) {
    solve(tt);
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!

Your task is to write a program which calculates two things:

  1. The maximum beauty difference of flowers that Pashmak can give to Parmida.
  2. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.

Input

The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).

Output

The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.

Examples

Input

2
1 2

Output

1 1

Input

3
1 4 5

Output

4 1

Input

5
3 1 2 3 1

Output

2 4

Note

In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:

  1. choosing the first and the second flowers;
  2. choosing the first and the fifth flowers;
  3. choosing the fourth and the second flowers;
  4. choosing the fourth and the fifth flowers.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  long long i, n, *b, w, cmax = 0, cmin = 0, max, min;
  scanf("%lld", &n);
  b = (long long *)malloc(n * sizeof(long long));
  for (i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    if (i == 0)
      max = min = b[i];
    else if (b[i] > max)
      max = b[i];
    else if (b[i] < min)
      min = b[i];
  }
  if (max == min)
    w = n * (n - 1) / 2;
  else {
    for (i = 0; i < n; i++) {
      if (b[i] == max)
        cmax++;
      else if (b[i] == min)
        cmin++;
    }
    w = cmax * cmin;
  }
  printf("%lld %lld", max - min, w);
  free(b);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from 1 to n. For every edge e of this tree, Monocarp has written two numbers: the maximum indices of the vertices of the two components formed if the edge e (and only this edge) is erased from the tree.

Monocarp has given you a list of n - 1 pairs of numbers. He wants you to provide an example of a tree that will produce the said list if this tree exists. If such tree does not exist, say so.

Input

The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of vertices in the tree.

Each of the next n-1 lines contains two integers a_i and b_i each (1 ≤ a_i < b_i ≤ n) — the maximal indices of vertices in the components formed if the i-th edge is removed.

Output

If there is no such tree that can produce the given list of pairs, print "NO" (without quotes).

Otherwise print "YES" (without quotes) in the first line and the edges of the tree in the next n - 1 lines. Each of the last n - 1 lines should contain two integers x_i and y_i (1 ≤ x_i, y_i ≤ n) — vertices connected by an edge.

Note: The numeration of edges doesn't matter for this task. Your solution will be considered correct if your tree produces the same pairs as given in the input file (possibly reordered). That means that you can print the edges of the tree you reconstructed in any order.

Examples

Input

4
3 4
1 4
3 4

Output

YES
1 3
3 2
2 4

Input

3
1 3
1 3

Output

NO

Input

3
1 2
2 3

Output

NO

Note

Possible tree from the first example. Dotted lines show edges you need to remove to get appropriate pairs.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long power(long long a, long long b) {
  long long x = 1;
  a = a % 1000000007ULL;
  while (b) {
    if (b & 1) x = (x * a) % 1000000007ULL;
    a = (a * a) % 1000000007ULL;
    b >>= 1;
  }
  return x;
}
inline long long inv(long long a) { return power(a, 1000000007ULL - 2); }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
const int N = 1e5 + 5;
queue<int> unused;
int n;
int cnt[1005];
map<int, pair<int, int> > mpp;
vector<int> adj[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(i);
    adj[v].push_back(i);
    cnt[u]++;
    cnt[v]++;
  }
  for (int i = 1; i < n; i++) {
    if (cnt[i] == 0)
      unused.push(i);
    else {
      int v = i;
      int tmp = cnt[i];
      if (unused.size() < tmp - 1) {
        cout << "NO\n";
        return 0;
      }
      int par = n;
      for (auto it : adj[i]) {
        if (cnt[i] == 1) {
          cnt[i]--;
          mpp[it] = make_pair(par, i);
          break;
        }
        int uu = unused.front();
        unused.pop();
        mpp[it] = make_pair(par, uu);
        par = uu;
        cnt[i]--;
      }
    }
  }
  cout << "YES\n";
  for (int i = 1; i < n; i++)
    cout << mpp[i].first << " " << mpp[i].second << endl;
  return 0;
}

```


### Prompt

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

Little Maxim loves interesting problems. He decided to share one such problem with you.

Initially there is an array a, consisting of n zeroes. The elements of the array are indexed, starting from 1. Then follow queries to change array a. Each query is characterized by two integers vi, ti. In the answer to the query we should make the vi-th array element equal ti (avi = ti; 1 ≤ vi ≤ n).

Maxim thinks that some pairs of integers (x, y) are good and some are not. Maxim thinks that array a, consisting of n integers, is lucky, if for all integer i, (1 ≤ i ≤ n - 1) the pair of integers (ai, ai + 1) — is good. Note that the order of numbers in the pairs is important, that is, specifically, (1, 2) ≠ (2, 1).

After each query to change array a Maxim wants to know, how many ways there are to replace all zeroes in array a with integers from one to three so as to make the resulting array (without zeroes) lucky. Of course, distinct zeroes can be replaced by distinct integers.

Maxim told you the sequence of queries and all pairs of integers he considers lucky. Help Maxim, solve this problem for him.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 77777) — the number of elements in the array and the number of commands.

The next three lines contain matrix w, consisting only of zeroes and ones; the j-th number in the i-th of these lines — wi, j. If wi, j = 1 (1 ≤ i, j ≤ 3), then pair (i, j) is good, otherwise it is not good. Matrix does not have to be symmetric relative to the main diagonal.

Next m lines contain pairs of integers vi, ti (1 ≤ vi ≤ n, 0 ≤ ti ≤ 3) — the queries to change the array.

Output

Print m integers — the i-th number should equal to the number of ways to replace all zeroes in array a (changed after the i-th query) by integers from one to three so as to make the resulting array (without zeroes) lucky. Separate the numbers by whitespaces. As the answers can be rather large, print the remainder from dividing them by 777777777.

Examples

Input

3 10
1 1 0
1 0 0
1 1 1
1 1
1 3
2 2
3 0
2 1
3 0
3 1
2 0
3 1
1 0

Output

3
6
1
1
2
2
1
3
3
6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 80007;
const int MAX = 3;
const int MOD = 777777777;
const int MAXS = MAXN * 4;
const int MAXL = 131072;
const int TP = 4;
struct mT {
  mT() { clear(); }
  void clear() { memset(a, 0, sizeof(a)); }
  void setunit() {
    clear();
    for (int i = 0; i < MAX; ++i) a[i][i] = 1;
  }
  mT operator*(const mT &x) const {
    mT ans;
    for (int i = 0; i < MAX; ++i) {
      for (int j = 0; j < MAX; ++j) {
        for (int k = 0; k < MAX; ++k) ans.a[i][j] += a[i][k] * x.a[k][j];
        ans.a[i][j] %= MOD;
      }
    }
    return ans;
  }
  void operator*=(const mT &x) { (*this) = (*this) * x; }
  long long a[MAX][MAX];
};
class stT {
 public:
  stT() {
    for (int i = 0; i < MAXS; ++i) data[i].setunit();
  }
  void upd(int p, mT &x) {
    p += MAXL - 1;
    data[p] = x;
    for (p >>= 1; p; p >>= 1) data[p] = data[p << 1 | 1] * data[p << 1];
  }
  mT query() { return data[1]; }

 private:
  mT data[MAXS];
} st;
int n, m, fp;
mT mat[TP];
int v, t;
void init();
void input();
void inputq();
void work();
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < MAX; ++i)
    for (int j = 0; j < MAX; ++j) scanf("%d", &mat[0].a[j][i]);
}
void inputq() { scanf("%d%d", &v, &t); }
void work() {
  for (int i = 1; i < TP; ++i) {
    for (int j = 0; j < MAX; ++j)
      for (int k = 0; k < MAX; ++k)
        if (j == i - 1) mat[i].a[j][k] = mat[0].a[j][k];
  }
  for (int i = 1; i < n; ++i) st.upd(i, mat[0]);
  fp = 0;
  int cc;
  mT now;
  for (int i = 0; i < m; ++i) {
    inputq();
    --v;
    if (v) {
      st.upd(v, mat[t]);
    } else
      fp = t;
    now.clear();
    if (fp)
      now.a[fp - 1][0] = 1;
    else
      for (int i = 0; i < MAX; ++i) now.a[i][0] = 1;
    now = st.query() * now;
    cc = 0;
    for (int i = 0; i < MAX; ++i) (cc += now.a[i][0]) %= MOD;
    printf("%d\n", cc);
  }
}

```


### Prompt

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

You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).

In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?

Here the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.

For both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.

Since the answer can be tremendous, print the number modulo 10^9+7.

Constraints

* 1 \leq N, M \leq 2 \times 10^3
* The length of S is N.
* The length of T is M.
* 1 \leq S_i, T_i \leq 10^5
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
S_1 S_2 ... S_{N-1} S_{N}
T_1 T_2 ... T_{M-1} T_{M}

Output

Print the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.

Examples

Input

2 2
1 3
3 1

Output

3

Input

2 2
1 1
1 1

Output

6

Input

4 4
3 4 5 6
3 4 5 6

Output

16

Input

10 9
9 6 5 7 5 9 8 5 6 7
8 6 8 5 5 7 9 9 7

Output

191

Input

20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output

846527861

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
long long dp[2010][2010];
int s[2010];
int t[2010];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i=1;i<=n;i++)
		cin >> s[i];
	for (int i=1;i<=m;i++)
		cin >> t[i];
	for (int i=0;i<=n;i++)
		dp[i][0]=1;
	for (int j=0;j<=m;j++)
		dp[0][j]=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
			if (s[i]==t[j]) dp[i][j]+=dp[i-1][j-1];
			dp[i][j]=(dp[i][j]+1000000007)%1000000007;
		}
	cout << dp[n][m];
	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

The only difference between easy and hard versions is constraints.

Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.

There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins. The second way is to make m_i other voters vote for you, and the i-th voter will vote for free.

Moreover, the process of such voting takes place in several steps. For example, if there are five voters with m_1 = 1, m_2 = 2, m_3 = 2, m_4 = 4, m_5 = 5, then you can buy the vote of the fifth voter, and eventually everyone will vote for you. Set of people voting for you will change as follows: {5} → {1, 5} → {1, 2, 3, 5} → {1, 2, 3, 4, 5}.

Calculate the minimum number of coins you have to spend so that everyone votes for you.

Input

The first line contains one integer t (1 ≤ t ≤ 5000) — the number of test cases.

The first line of each test case contains one integer n (1 ≤ n ≤ 5000) — the number of voters.

The next n lines contains the description of voters. i-th line contains two integers m_i and p_i (1 ≤ p_i ≤ 10^9, 0 ≤ m_i < n).

It is guaranteed that the sum of all n over all test cases does not exceed 5000.

Output

For each test case print one integer — the minimum number of coins you have to spend so that everyone votes for you.

Example

Input

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

Output

8
0
7

Note

In the first test case you have to buy vote of the third voter. Then the set of people voting for you will change as follows: {3} → {1, 3} → {1, 2, 3}.

In the second example you don't need to buy votes. The set of people voting for you will change as follows: {1} → {1, 3, 5} → {1, 2, 3, 5} → {1, 2, 3, 5, 6, 7} → {1, 2, 3, 4, 5, 6, 7}.

In the third test case you have to buy votes of the second and the fifth voters. Then the set of people voting for you will change as follows: {2, 5} → {1, 2, 3, 4, 5} → {1, 2, 3, 4, 5, 6}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int NR = 2e5 + 5;
vector<int> g[NR];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, x, y;
    scanf("%d", &n);
    for (int i = 0; i <= n; i++) g[i].clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &x, &y);
      g[x].push_back(y);
    }
    long long ans = 0;
    priority_queue<int, vector<int>, greater<int> > q;
    for (int i = n - 1; i >= 0; i--) {
      for (unsigned int j = 0; j < g[i].size(); j++) {
        q.push(g[i][j]);
      }
      while (i > n - (int)q.size()) {
        ans += 1ll * q.top();
        q.pop();
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a permutation p_1, p_2, ..., p_n. A permutation of length n is a sequence such that each integer between 1 and n occurs exactly once in the sequence.

Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of the median of p_l, p_{l+1}, ..., p_r is exactly the given number m.

The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used.

For example, if a=[4, 2, 7, 5] then its median is 4 since after sorting the sequence, it will look like [2, 4, 5, 7] and the left of two middle elements is equal to 4. The median of [7, 1, 2, 9, 6] equals 6 since after sorting, the value 6 will be in the middle of the sequence.

Write a program to find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of the median of p_l, p_{l+1}, ..., p_r is exactly the given number m.

Input

The first line contains integers n and m (1 ≤ n ≤ 2⋅10^5, 1 ≤ m ≤ n) — the length of the given sequence and the required value of the median.

The second line contains a permutation p_1, p_2, ..., p_n (1 ≤ p_i ≤ n). Each integer between 1 and n occurs in p exactly once.

Output

Print the required number.

Examples

Input

5 4
2 4 5 3 1

Output

4

Input

5 5
1 2 3 4 5

Output

1

Input

15 8
1 15 2 14 3 13 4 8 12 5 11 6 10 7 9

Output

48

Note

In the first example, the suitable pairs of indices are: (1, 3), (2, 2), (2, 3) and (2, 4).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int v[200001];
int main() {
  long long int n, m, mi;
  vector<long long int> vleft;
  vector<long long int> vright(1, 0);
  bool swapou = false;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a, vai = 1;
    cin >> a;
    if (a > m)
      vai = 1;
    else
      vai = -1;
    v[i] = a;
    if (a == m) {
      swapou = true;
    } else if (swapou) {
      vright.push_back(vai);
    } else {
      vleft.push_back(vai);
    }
  }
  vleft.push_back(0);
  reverse(vleft.begin(), vleft.end());
  for (int i = 1; i < vleft.size(); i++) {
    vleft[i] += vleft[i - 1];
  }
  for (int i = 1; i < vright.size(); i++) {
    vright[i] += vright[i - 1];
  }
  sort(vleft.begin(), vleft.end());
  map<long long int, long long int> M;
  for (long long int x : vright) {
    M[x]++;
  }
  long long int cnt = 0;
  for (long long int x : vleft) {
    cnt += M[-x] + M[1ll - x];
  }
  cout << cnt << "\n";
  return 0;
}

```


### Prompt

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

While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.

Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.

A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.

Input

The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.

Output

If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.

Examples

Input

abcd
defgh

Output

5

Input

a
a

Output

-1

Note

In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[800000], b[800000];
  int t = 0;
  cin >> a >> b;
  if (strlen(a) > strlen(b))
    cout << strlen(a);
  else if (strlen(a) < strlen(b))
    cout << strlen(b);
  else {
    for (int i = 0; i < strlen(a); i++) {
      if (a[i] != b[i]) {
        t = 1;
        break;
      }
    }
    if (t == 1)
      cout << strlen(a);
    else
      cout << -1;
  }
  return 0;
}

```


### Prompt

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

The Hedgehog likes to give presents to his friend, but no less he likes to receive them.

Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?

In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle:

  * on each holiday day the Hedgehog will necessarily receive a present,
  * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day).

For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer).

Input

The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N).

The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them.

Output

Print a single number — the minimal number of presents the Hedgehog will receive over the following N days.

Examples

Input

5 2
1 3

Output

3

Input

10 1
3 6 7 8

Output

10

### Response

```cpp
#include <bits/stdc++.h>
int main(void) {
  int n, k, c;
  static char days[366];
  int i;
  int count;
  int end;
  scanf("%d %d", &n, &k);
  memset(days, 0, n + 1);
  scanf("%d", &c);
  for (i = 0; i < c; i++) {
    int t;
    scanf("%d", &t);
    days[t] = 1;
  }
  end = k;
  for (i = 1, count = 0; i <= n; i++) {
    if (days[i] || i == end) {
      count++;
      end = i + k;
    }
  }
  printf("%d\n", count);
  return 0;
}

```


### Prompt

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

You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.

In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.

Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.

Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.

Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.

Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.

Input

In the first line of input, there are two integers n, m (1 ≤ n, m ≤ 5 ⋅ 10^5) denoting the number of vectors in S and the number of dimensions.

Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 ≤ k ≤ 2) and then follow k distinct integers x_1, ... x_k (1 ≤ x_i ≤ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.

Among the n vectors, no two are the same.

Output

In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.

Examples

Input

3 2
1 1
1 2
2 2 1

Output

4 2
1 2

Input

2 3
2 1 3
2 1 2

Output

4 2
1 2

Input

3 5
2 1 2
1 3
1 4

Output

8 3
1 2 3

Note

In the first example we are given three vectors:

  * 10
  * 01
  * 11

It turns out that we can represent all vectors from our 2-dimensional space using these vectors:

  * 00 is a sum of the empty subset of above vectors;
  * 01 = 11 + 10, is a sum of the first and third vector;
  * 10 = 10, is just the first vector;
  * 11 = 10 + 01, is a sum of the first and the second vector.

Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:

  * 00 is a sum of the empty subset;
  * 01 = 01 is just the second vector;
  * 10 = 10 is just the first vector;
  * 11 = 10 + 01 is a sum of the first and the second vector.

### Response

```cpp
#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define ll long long
#define ull unsigned ll
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
//#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll M = 1e9 + 7;
//const ll M = 998244353;
//const ll M = 1e9 + 9;
//const ll M = 1e6;
#define tiii tuple<int,int,int>
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll ret = 1;
	while(b){
		if(b & 1){
			ret = ret * a % M;
		}
		a = a * a % M;
		b >>= 1;
	}
	return ret;
}
void solve(){
	int n, m;
	cin >> n >> m;
	vi basis(m + 1);
	vi nxt(m + 1);
	iota(td(nxt), 0);
	function<int (int)> f = [&](int i){
		if(nxt[i] == i or nxt[i] == -1) return nxt[i];
		return nxt[i] = f(nxt[i]);
	};
	vector<vector<int>> vecs(n);
	vector<int> s;
	for(int i=0;i<n;i++){
		int k; cin >> k;
		vecs[i].resize(k);
		re(vecs[i]);
		sort(td(vecs[i]));
		// check if is represented
		int a = f(vecs[i][0]);
		int b = -1;
		if(k > 1) b = f(vecs[i][1]);
		if(a == b){
			continue;
		}
		if(a == -1){
			if(b == -1) continue;
			basis[b] = 1;
			s.eb(i);
			nxt[b] = -1;
		}
		else{
			basis[a] = i;
			s.eb(i);
			nxt[a] = b;
		}
	}
	cout << binpow(2, s.size()) << " " << s.size() << endl;
	for(int x : s) cout << x + 1 << " ";
	cout << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}
```


### Prompt

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

Kate has a set S of n integers \{1, ..., n\} .

She thinks that imperfection of a subset M ⊆ S is equal to the maximum of gcd(a, b) over all pairs (a, b) such that both a and b are in M and a ≠ b.

Kate is a very neat girl and for each k ∈ \{2, ..., n\} she wants to find a subset that has the smallest imperfection among all subsets in S of size k. There can be more than one subset with the smallest imperfection and the same size, but you don't need to worry about it. Kate wants to find all the subsets herself, but she needs your help to find the smallest possible imperfection for each size k, will name it I_k.

Please, help Kate to find I_2, I_3, ..., I_n.

Input

The first and only line in the input consists of only one integer n (2≤ n ≤ 5 ⋅ 10^5) — the size of the given set S.

Output

Output contains only one line that includes n - 1 integers: I_2, I_3, ..., I_n.

Examples

Input

2

Output

1

Input

3

Output

1 1

Note

First sample: answer is 1, because gcd(1, 2) = 1.

Second sample: there are subsets of S with sizes 2, 3 with imperfection equal to 1. For example, \{2,3\} and \{1, 2, 3\}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-2;
const int mod = 1e9 + 7;
const int maxn = 3e6 + 100;
const int maxm = maxn * 150;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
int n, m;
int a[maxn];
int main() {
  scanf("%d", &n);
  int m = (int)sqrt(n + 0.9);
  for (int i = 2; i <= n; i++) {
    a[i] = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        a[i] = i / j;
        break;
      }
    }
  }
  for (int i = 2; i <= n; i++) a[i] == -1 ? 1 : i / a[i];
  sort(a + 2, a + 1 + n);
  for (int i = 2; i <= n; i++) {
    printf("%d ", a[i]);
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Acacius is studying strings theory. Today he came with the following problem.

You are given a string s of length n consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?

Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".

Occurrence of a string t of length m in the string s of length n as a substring is a index i (1 ≤ i ≤ n - m + 1) such that string s[i..i+m-1] consisting of m consecutive symbols of s starting from i-th equals to string t. For example string "ababa" has two occurrences of a string "aba" as a substring with i = 1 and i = 3, but there are no occurrences of a string "aba" in the string "acba" as a substring.

Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once.

Input

First line of input contains an integer T (1 ≤ T ≤ 5000), number of test cases. T pairs of lines with test case descriptions follow.

The first line of a test case description contains a single integer n (7 ≤ n ≤ 50), length of a string s.

The second line of a test case description contains string s of length n consisting of lowercase English letters and question marks.

Output

For each test case output an answer for it.

In case if there is no way to replace question marks in string s with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No".

Otherwise output "Yes" and in the next line output a resulting string consisting of n lowercase English letters. If there are multiple possible strings, output any.

You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).

Example

Input

6
7
abacaba
7
???????
11
aba?abacaba
11
abacaba?aba
15
asdf???f???qwer
11
abacabacaba

Output

Yes
abacaba
Yes
abacaba
Yes
abadabacaba
Yes
abacabadaba
No
No

Note

In first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.

In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.

In sixth example there are two occurrences of a string "abacaba" as a substring.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const string target = "abacaba";
bool isok(string s) {
  int cnt = 0;
  for (int i = 0; i < s.size() - 6; i++)
    if (s.substr(i, 7) == target) cnt++;
  return cnt == 1;
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string old = string(7, ' ');
  for (int i = 0; i < n - 6; i++) {
    bool ok = true;
    for (int j = 0; j < 7; j++) {
      old[j] = s[i + j];
      if (s[i + j] == '?') s[i + j] = target[j];
    }
    if (isok(s)) {
      for (int i = 0; i < n; i++)
        if (s[i] == '?') s[i] = 'z';
      puts("YES");
      cout << s << endl;
      return;
    }
    for (int j = 0; j < 7; j++) s[i + j] = old[j];
  }
  puts("NO");
}
int main() {
  int tt;
  cin >> tt;
  while (tt--) solve();
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Slime has a sequence of positive integers a_1, a_2, …, a_n.

In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}.

In this problem, for the integer multiset s, the median of s is equal to the ⌊ (|s|+1)/(2)⌋-th smallest number in it. For example, the median of \{1,4,4,6,5\} is 4, and the median of \{1,7,5,8\} is 5.

Slime wants Orac to make a_1 = a_2 = … = a_n = k using these operations.

Orac thinks that it is impossible, and he does not want to waste his time, so he decided to ask you if it is possible to satisfy the Slime's requirement, he may ask you these questions several times.

Input

The first line of the input is a single integer t: the number of queries.

The first line of each query contains two integers n\ (1≤ n≤ 100 000) and k\ (1≤ k≤ 10^9), the second line contains n positive integers a_1,a_2,...,a_n\ (1≤ a_i≤ 10^9)

The total sum of n is at most 100 000.

Output

The output should contain t lines. The i-th line should be equal to 'yes' if it is possible to make all integers k in some number of operations or 'no', otherwise. You can print each letter in lowercase or uppercase.

Example

Input

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

Output

no
yes
yes
no
yes

Note

In the first query, Orac can't turn all elements into 3.

In the second query, a_1=6 is already satisfied.

In the third query, Orac can select the complete array and turn all elements into 2.

In the fourth query, Orac can't turn all elements into 3.

In the fifth query, Orac can select [1,6] at first and then select [2,10].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[400005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long test;
  cin >> test;
  while (test > 0) {
    test--;
    long long n, k;
    cin >> n >> k;
    set<long long> h;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      h.insert(a[i]);
    }
    if (n == 1) {
      if (k == a[0])
        cout << "yes\n";
      else
        cout << "no\n";
      continue;
    }
    if (h.count(k) == 0) {
      cout << "no\n";
      continue;
    }
    if (n == 2) {
      if (a[0] >= k && a[1] >= k)
        cout << "yes\n";
      else
        cout << "no\n";
      continue;
    }
    bool yes = false;
    for (int i = 0; i < n - 2; i++) {
      int cnt = 0;
      if (a[i] >= k) cnt++;
      if (a[i + 1] >= k) cnt++;
      if (a[i + 2] >= k) cnt++;
      if (cnt >= 2) yes = true;
    }
    if (yes)
      cout << "yes\n";
    else
      cout << "no\n";
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices.

A set of edges is called a matching if no two edges share an endpoint.

A set of vertices is called an independent set if no two vertices are connected with an edge.

Input

The first line contains a single integer T ≥ 1 — the number of graphs you need to process. The description of T graphs follows.

The first line of description of a single graph contains two integers n and m, where 3 ⋅ n is the number of vertices, and m is the number of edges in the graph (1 ≤ n ≤ 10^{5}, 0 ≤ m ≤ 5 ⋅ 10^{5}).

Each of the next m lines contains two integers v_i and u_i (1 ≤ v_i, u_i ≤ 3 ⋅ n), meaning that there is an edge between vertices v_i and u_i.

It is guaranteed that there are no self-loops and no multiple edges in the graph.

It is guaranteed that the sum of all n over all graphs in a single test does not exceed 10^{5}, and the sum of all m over all graphs in a single test does not exceed 5 ⋅ 10^{5}.

Output

Print your answer for each of the T graphs. Output your answer for a single graph in the following format.

If you found a matching of size n, on the first line print "Matching" (without quotes), and on the second line print n integers — the indices of the edges in the matching. The edges are numbered from 1 to m in the input order.

If you found an independent set of size n, on the first line print "IndSet" (without quotes), and on the second line print n integers — the indices of the vertices in the independent set.

If there is no matching and no independent set of the specified size, print "Impossible" (without quotes).

You can print edges and vertices in any order.

If there are several solutions, print any. In particular, if there are both a matching of size n, and an independent set of size n, then you should print exactly one of such matchings or exactly one of such independent sets.

Example

Input

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

Output

Matching
2
IndSet
1
IndSet
2 4
Matching
1 15

Note

The first two graphs are same, and there are both a matching of size 1 and an independent set of size 1. Any of these matchings and independent sets is a correct answer.

The third graph does not have a matching of size 2, however, there is an independent set of size 2. Moreover, there is an independent set of size 5: 2 3 4 5 6. However such answer is not correct, because you are asked to find an independent set (or matching) of size exactly n.

The fourth graph does not have an independent set of size 2, but there is a matching of size 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double PI = acos(-1.0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n, m;
    cin >> n >> m;
    vector<long long int> ver(3 * n + 1, 0);
    vector<pair<long long int, long long int>> edge(m);
    for (long long int i = 0; i < m; i++) {
      cin >> edge[i].first;
      cin >> edge[i].second;
    }
    vector<long long int> ans1;
    for (long long int i = 0; i < m; i++) {
      if (ver[edge[i].first] == 0 && ver[edge[i].second] == 0) {
        ans1.push_back(i + 1);
        ver[edge[i].first] = 1;
        ver[edge[i].second] = 1;
      }
      if (ans1.size() == n) break;
    }
    if (ans1.size() == n) {
      cout << "Matching" << '\n';
      for (auto i : ans1) cout << i << " ";
      cout << '\n';
    } else {
      cout << "IndSet" << '\n';
      long long int done = 0;
      for (long long int i = 1; i < 3 * n + 1; i++) {
        if (ver[i] == 0) {
          done++;
          cout << i << " ";
        }
        if (done == n) break;
      }
      cout << '\n';
    }
  }
  return 0;
}

```


### Prompt

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

In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.

He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.

Input

The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.

Output

Print the string that satisfies all the constraints.

If there are multiple answers, print any of them.

Examples

Input

2

Output

aa

Input

3

Output

bba

Note

A palindrome is a sequence of characters which reads the same backward and forward.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s = 0;
  for (int i = 0; i < n; i++) {
    if (s == 0) {
      putchar('a');
      s++;
    } else if (s == 1) {
      putchar('a');
      s++;
    } else if (s == 2) {
      putchar('b');
      s++;
    } else {
      putchar('b');
      s = 0;
    }
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the number at the first glance. Could it be shortened? For example, instead of 1000000 you could write 10^{6}, instead of 1000000000 —10^{9}, instead of 1000000007 — 10^{9}+7.

Vasya decided that, to be concise, the notation should follow several rules:

  * the notation should only consist of numbers, operations of addition ("+"), multiplication ("*") and exponentiation ("^"), in particular, the use of braces is forbidden;
  * the use of several exponentiation operations in a row is forbidden, for example, writing "2^3^4" is unacceptable;
  * the value of the resulting expression equals to the initial number;
  * the notation should consist of the minimal amount of symbols.

Given n, find the equivalent concise notation for it.

Input

The only line contains a single integer n (1 ≤ n ≤ 10 000 000 000).

Output

Output a concise notation of the number n. If there are several concise notations, output any of them.

Examples

Input

2018

Output

2018

Input

1000000007

Output

10^9+7

Input

10000000000

Output

100^5

Input

2000000000

Output

2*10^9

Note

The third sample allows the answer 10^10 also of the length 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const bool debugger1 = 1;
const bool debugger2 = 0;
const bool debugger3 = 0;
const bool debugger4 = 0;
const bool debugger5 = 0;
const long long wielkosc = 1e5 + 90;
const long long maxlen = 7;
long long n;
long long p10[10];
map<long long, string> m;
set<long long> second[10];
template <class T>
string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
long long getlen(long long x) {
  long long ans = 0;
  while (x) {
    x /= 10;
    ans++;
  }
  return max(ans, (long long)1);
}
string daj(long long x) {
  if (m.count(x)) return m[x];
  return toString(x);
}
void uprosc(long long x, string str) {
  if (x > n || str.length() >= getlen(x)) return;
  if (m.count(x) && m[x].length() <= str.length()) return;
  second[m[x].length()].erase(x);
  m[x] = str;
  second[str.length()].insert(x);
}
void pot10() {
  p10[0] = 1;
  for (int i = 1; i < 10; i++) p10[i] = 10 * p10[i - 1];
}
void zrob_potegi() {
  for (long long x = 2; x * x <= n; x++) {
    long long c = x * x;
    long long akpot = 2;
    while (c <= n) {
      string temp = toString(x) + "^" + toString(akpot);
      uprosc(c, temp);
      c *= x;
      akpot++;
    }
  }
}
void potrazypot() {
  for (long long i = 1; i <= maxlen; i++) {
    for (long long j = i; i + j + 1 <= maxlen; j++) {
      for (auto x : second[i]) {
        for (auto y : second[j]) {
          uprosc(x * y, daj(x) + "*" + daj(y));
        }
      }
    }
  }
}
void potrazynum() {
  for (long long i = 1; i + 2 <= maxlen; i++) {
    for (long long x = 1; x < p10[maxlen - 1 - i]; x++) {
      for (long long y : second[i]) {
        uprosc(x * y, toString(x) + '*' + daj(y));
      }
    }
  }
}
void pocz() {
  zrob_potegi();
  potrazypot();
  potrazynum();
}
string ans;
void ustans(string second) {
  if (ans.length() > second.length()) {
    ans = second;
  }
}
void dajodp() {
  for (long long i = 1; i * 2 + 1 < ans.length(); i++) {
    for (long long x = 1; x <= p10[i]; x++) {
      ustans(daj(n - x) + "+" + daj(x));
      if (n % x == 0) {
        ustans(daj(n / x) + "*" + daj(x));
      }
    }
    for (auto x : second[i]) {
      ustans(daj(n - x) + "+" + daj(x));
      if (n % x == 0) {
        ustans(daj(n / x) + "*" + daj(x));
      }
    }
  }
}
int main() {
  pot10();
  scanf("%lld", &n);
  pocz();
  ans = daj(n);
  dajodp();
  cout << ans;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

There is a bus route as shown in Figure 1. There are 10 stops, each numbered 0-9. The bus turns back at stop 0, but the other side is a circulation route, which circulates in the order of 5 → 6 → 7 → 8 → 9 → 5 as shown in the figure.

<image>

For this bus route, create a program that inputs the stop to get on and the stop to get off, and outputs the number of the stop that goes from getting on to getting off.

However, you can take a two-way bus at stops 1-5, but we will take a bus that arrives at the stop on a shorter route. For example, if you are going from stop 4 to stop 2, take the bus going to the left and follow the route "4 → 3 → 2". Also, once you get on the bus, you will not get off the bus. The same stop is not designated as a boarding stop or a getting-off stop.

Input

Given multiple datasets. The first line gives the number of datasets n (n ≤ 20). For each dataset, the stop number to get on and the stop number to get off are given on one line separated by blanks.

Output

For each data set, output the list of passing stop numbers on one line separated by blanks.

Example

Input

2
2 4
4 2

Output

2 3 4
4 3 2

### Response

```cpp
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;

int main(){
	int n;
	scanf("%d",&n);
	int a[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8};
	int b[] = {0,1,2,3,4,5};
	rep(q,n){
		int from,to;
		bool f = false;
		scanf("%d%d",&from,&to);
		if(from < 6 && to < 6){
			if(from > to){
				int x = from;
				while(1){
					if(b[x] == to){
						printf(" %d\n",to);
						break;
					}
					if(f)printf(" ");
					printf("%d",b[x]);
					x--;
					f = true;
				}
			}
			else{
				int x = from;
				while(1){
					if(b[x] == to){
						printf(" %d\n",to);
						break;
					}
					if(f)printf(" ");
					printf("%d",b[x]);
					x++;
					f = true;
				}
			}
		}
		else{
			int x = from;
			while(1){
				if(a[x] == to){
					printf(" %d\n",to);
					break;
				}
				if(f)printf(" ");
				printf("%d",a[x]);
				x++;
				f = true;
			}
		}
	}
	return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.

He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.

Input

The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.

Output

Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.

Examples

Input

1 1 1 1 1 1

Output

6

Input

1 2 1 2 1 2

Output

13

Note

This is what Gerald's hexagon looks like in the first sample:

<image>

And that's what it looks like in the second sample:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, e, f, n_tringle;
  cin >> a >> b >> c >> d >> e >> f;
  n_tringle = (a + b + c) * (a + b + c) - (a * a + c * c + e * e);
  cout << n_tringle << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of the numbers written on the two cards shall be the score of the player who took the card. However, if the same number is written on the two open cards, it is a draw and each player takes one of his own cards.

For example, consider the case where the hands of A and B are arranged as shown in the following input examples 1 to 3. However, the input file consists of n + 1 lines, the first line contains the number of cards n for each player, and the i + 1 line (i = 1, 2, ..., n) is A. The numbers on the i-th card from the left and the numbers on the i-th card from the left of B are written in this order, with a blank as the delimiter. That is, from the second row onward of the input file, the left column represents the sequence of A cards, and the right column represents the sequence of B cards. At this time, the scores of A and B after the end of the game are shown in the corresponding output examples, respectively.

Create a program that outputs the score of A and the score of B when the game corresponding to the input file ends on one line with a space as a delimiter in this order. However, n ≤ 10000.

Input example 1 | Input example 2 | Input example 3
--- | --- | ---
3 | 3 | 3
9 1 | 9 1 | 9 1
5 4 | 5 4 | 5 5
0 8 | 1 0 | 1 8
Output example 1 | Output example 2 | Output example 3
19 8 | 20 0 | 15 14

input

The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.

output

For each dataset, the score of A and the score of B are output on one line.

Input example

3
9 1
5 4
0 8
3
9 1
5 4
Ten
3
9 1
5 5
1 8
0

Output example

19 8
20 0
15 14

Insert a line break after the output of each dataset (after the score of B).

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

Example

Input

3
9 1
5 4
0 8
3
9 1
5 4
1 0
3
9 1
5 5
1 8
0

Output

19 8
20 0
15 14

### Response

```cpp
#include<cstdio>

int n;

int main(){
	while(1){
		int A,B,Aanswer=0,Banswer=0;
		scanf("%d",&n);
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			scanf("%d %d",&A,&B);
			if(A>B)Aanswer+=A+B;
			else if(A<B)Banswer+=A+B;
			else{
				Aanswer+=A;
				Banswer+=B;
			}
		}
		printf("%d %d\n",Aanswer,Banswer);
	}
	return 0;
}
```


### Prompt

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

There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i.

Snuke will repeat the following operation until two cards remain:

* Choose three consecutive cards from the stack.
* Eat the middle card of the three.
* For each of the other two cards, replace the integer written on it by the sum of that integer and the integer written on the card eaten.
* Return the two cards to the original position in the stack, without swapping them.

Find the minimum possible sum of the integers written on the last two cards remaining.

Constraints

* 2 \leq N \leq 18
* 0 \leq A_i \leq 10^9 (1\leq i\leq N)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sum of the integers written on the last two cards remaining.

Examples

Input

4
3 1 4 2

Output

16

Input

6
5 2 4 1 6 9

Output

51

Input

10
3 1 4 1 5 9 2 6 5 3

Output

115

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <functional>
#include <limits>
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int64_t> A(N);
    for(auto &a:A) cin>>a;
    function<int64_t(int64_t,int64_t,int64_t,int64_t)> rec = [&](int64_t l, int64_t r, int64_t lx, int64_t rx){
        if(r-l==1) return int64_t(0);
        int64_t ret = numeric_limits<int64_t>::max();
        for(int k=l+1;k<r;k++){
            ret = min(ret, rec(l,k,lx,lx+rx)+rec(k,r,lx+rx,rx)+A[k]*(lx+rx));
        }
        return ret;
    };
    cout<<rec(0,N-1,1,1)+A[0]+A[N-1]<<endl;
    return 0;
}
```