### Prompt

Please formulate a CPP solution to the following problem:

You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour.

Input

The first line contains three integers a, b, m (1 ≤ a, b ≤ 1000, 0 ≤ m ≤ 105), a is the size of the first part, b is the size of the second part, m is the number of edges in the graph.

Each of the next m lines contains two integers x, y (1 ≤ x ≤ a, 1 ≤ y ≤ b), where x is the number of the vertex in the first part and y is the number of the vertex in the second part. It is guaranteed that there are no multiple edges.

Output

In the first line print integer c — the minimal number of colours. The second line should contain m integers from 1 to c — the colours of the edges (in the order they appear in the input).

If there are several solutions, you can print any one of them.

Examples

Input

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

Output

3
1 2 3 1 2

### Response

```cpp
#include <bits/stdc++.h>
namespace chtholly {
char buf[1 << 23], *p1 = buf, *p2 = buf;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
  return f ? x : -x;
}
template <typename mitsuha>
inline bool read(mitsuha &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c) && ~c; c = getchar()) f ^= c == '-';
  if (!~c) return 0;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
  return x = f ? x : -x, 1;
}
template <typename mitsuha>
inline int write(mitsuha x) {
  if (!x) return 0 & putchar(48);
  if (x < 0) putchar('-'), x = -x;
  int bit[20], i, p = 0;
  for (; x; x /= 10) bit[++p] = x % 10;
  for (i = p; i; --i) putchar(bit[i] + 48);
  return 0;
}
inline char fuhao() {
  char c = getchar();
  for (; isspace(c); c = getchar())
    ;
  return c;
}
}  // namespace chtholly
using namespace chtholly;
using namespace std;
const int yuzu = 1e5, aoi = 1018;
int cl[2][aoi][aoi], id[aoi][aoi], ans[yuzu | 10];
void dfs(int p, int u, int v, int c1, int c2) {
  int t = cl[!p][v][c1];
  cl[p][u][c1] = v, cl[!p][v][c1] = u;
  if (!t) return void(cl[!p][v][c2] = 0);
  dfs(!p, v, t, c2, c1);
}
int main() {
  int n, m, k, i, u, v, j, llx = 0;
  read(n), read(m), read(k);
  for (i = 1; i <= k; ++i) {
    u = read(), v = read();
    id[u][v] = i;
    int c1 = 1, c2 = 1;
    for (; cl[0][u][c1]; ++c1)
      ;
    for (; cl[1][v][c2]; ++c2)
      ;
    llx = max(llx, max(c1, c2));
    if (c1 == c2)
      cl[0][u][c1] = v, cl[1][v][c2] = u;
    else
      dfs(0, u, v, c1, c2);
  }
  write(llx), puts("");
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= llx; ++j)
      if (cl[0][i][j]) ans[id[i][cl[0][i][j]]] = j;
  for (i = 1; i <= k; ++i) write(ans[i]), putchar(' ');
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:

    XX   XX   .X   X.
    X.   .X   XX   XX

Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.

Vasya has a board with 2× n squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully.

Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns.

Input

The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed 100.

Output

Output a single integer — the maximum amount of bishwocks that can be placed onto the given board.

Examples

Input

00
00

Output

1

Input

00X00X0XXX0
0XXX0X00X00

Output

4

Input

0X0X0
0X0X0

Output

0

Input

0XXX0
00000

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int k = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    k = k * 10 + ch - '0';
    ch = getchar();
  }
  return k * f;
}
inline void write(int x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(int x) {
  write(x);
  puts("");
}
char s[3][100010];
int main() {
  scanf("%s%s", s[1] + 1, s[2] + 1);
  int l = strlen(s[1] + 1), ans = 0;
  for (int i = 1; i <= l; i++) {
    if (s[1][i] == '0' && s[2][i] == '0') {
      if (s[1][i + 1] == '0') {
        s[1][i] = s[2][i] = s[1][i + 1] = 'X';
        ans++;
      } else if (s[2][i + 1] == '0') {
        s[1][i] = s[2][i] = s[2][i + 1] = 'X';
        ans++;
      }
    } else if (s[1][i] == '0') {
      if (s[1][i + 1] == '0' && s[2][i + 1] == '0') {
        s[1][i] = s[1][i + 1] = s[2][i + 1] = 'X';
        ans++;
      }
    } else if (s[2][i] == '0') {
      if (s[1][i + 1] == '0' && s[2][i + 1] == '0') {
        s[2][i] = s[1][i + 1] = s[2][i + 1] = 'X';
        ans++;
      }
    }
  }
  writeln(ans);
  return 0;
}

```


### Prompt

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

You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.

You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.

Input

First line contains an integer n (6 ≤ n ≤ 8) – the length of the string.

Next line contains a string consisting of n characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).

Output

Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).

Examples

Input

7
j......

Output

jolteon

Input

7
...feon

Output

leafeon

Input

7
.l.r.o.

Output

flareon

Note

Here's a set of names in a form you can paste into your solution:

["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]

{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string p;
  cin >> n;
  cin >> p;
  if (p[0] == 'j' || p[1] == 'o' || p[3] == 't') {
    cout << "jolteon";
  }
  if (n == 8) {
    cout << "vaporeon" << endl;
  }
  if (p[0] == 'f' || p[3] == 'r') {
    cout << "flareon" << endl;
  }
  if (n == 6) {
    cout << "espeon" << endl;
  }
  if (p[0] == 'u' || p[1] == 'm' || p[2] == 'b') {
    cout << "umbreon" << endl;
  }
  if (p[0] == 'l' || p[1] == 'e' || p[3] == 'f') {
    cout << "leafeon" << endl;
  }
  if (p[0] == 's' || p[1] == 'y' || p[3] == 'v') {
    cout << "sylveon" << endl;
  }
  if (p[0] == 'g' || p[3] == 'c') {
    cout << "glaceon" << endl;
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

<image>

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

Input

The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).

Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.

Output

For each query, print its answer in a single line.

Examples

Input

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

Output

4
-1
8
-1

Input

1 5 2
1 5 10
2 7 4

Output

1
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct people {
  int x, y, num;
  bool win;
};
int n, j, i, h, k, q1, q2, q, mx, x[200500], y[200500], cur;
long long a, b, t, m, l, r1, r2, r;
bool check(long long r) {
  long long c = a * (r - l + 1LL) + b * (l - 1LL) * (r - l + 1LL) +
                b * (r - l + 1LL) * (r - l) / 2LL;
  return (a + (r - 1LL) * b <= t && c <= m * t);
}
void solve() {
  scanf("%I64d%I64d%d", &a, &b, &n);
  for (j = 1; j <= n; j++) {
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    if (a + (l - 1) * b > t) {
      printf("-1\n");
      continue;
    }
    r2 = 2000000;
    r1 = l;
    while (r1 < r2) {
      r = (r1 + r2 + 1) >> 1;
      if (check(r)) {
        r1 = r;
      } else {
        r2 = r - 1;
      }
    }
    printf("%d\n", r1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(333);
  solve();
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.

When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the i-th reading head is above the track number hi. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered h1, h2, ..., hn have been read at the beginning of the operation.

<image>

Mike needs to read the data on m distinct tracks with numbers p1, p2, ..., pm. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.

Input

The first line of the input contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers hi in ascending order (1 ≤ hi ≤ 1010, hi < hi + 1) — the initial positions of the heads. The third line contains m distinct integers pi in ascending order (1 ≤ pi ≤ 1010, pi < pi + 1) - the numbers of tracks to read.

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

Output

Print a single number — the minimum time required, in seconds, to read all the needed tracks.

Examples

Input

3 4
2 5 6
1 3 6 8

Output

2

Input

3 3
1 2 3
1 2 3

Output

0

Input

1 2
165
142 200

Output

81

Note

The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way:

  1. during the first second move the 1-st head to the left and let it stay there;
  2. move the second head to the left twice;
  3. move the third head to the right twice (note that the 6-th track has already been read at the beginning).

One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxx = 100050;
int n, m, k;
long long a[maxx];
long long b[maxx];
int ans = 0, cnt = 0, pos = 0;
long long l = 0, r = 0;
int ok(long long mid) {
  cnt = 0;
  for (int i = 0; i < n; i++) {
    if (cnt >= m) break;
    long long t = b[cnt];
    if (a[i] - b[cnt] > mid) return 1;
    long long end = a[i];
    if (a[i] < b[cnt])
      end = a[i] + mid;
    else {
      end = max(end, a[i] + mid - 2 * (a[i] - b[cnt]));
      end = max(end, a[i] + (mid - (a[i] - b[cnt])) / 2);
    }
    while (cnt < m && b[cnt] <= end) cnt++;
  }
  if (cnt < m)
    return 1;
  else
    return 0;
}
void erfen() {
  long long mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (ok(mid)) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  l--;
}
int main() {
  scanf("%d%d", &n, &m);
  r = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r += a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    r += b[i];
  }
  l = 0;
  erfen();
  cout << l + 1;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.

One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.

The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.

You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).

Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor».

Input

The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100).

This number may contain leading zeros.

Output

Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).

Examples

Input

11

Output

6

Input

01

Output

2

Input

1

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename L>
inline bool smax(T &x, L y) {
  return x < y ? (x = y, true) : false;
}
template <typename T, typename L>
inline bool smin(T &x, L y) {
  return y < x ? (x = y, true) : false;
}
constexpr int MAXN = 256;
constexpr int MOD = 1e9 + 7;
string s;
long long ans;
long long pw[MAXN];
int main() {
  cin >> s;
  pw[0] = 1;
  for (int i = 1; i < MAXN; i++) {
    pw[i] = (pw[i - 1] << 1) % MOD;
  }
  for (int i = (int)s.size() - 1; ~i; i--) {
    if (s[i] == '0') {
      ans = (ans << 1) % MOD;
    } else {
      ans = ((ans << 1) + pw[((s.size() - i - 1) << 1)]) % MOD;
    }
  }
  return cout << ans << '\n', false;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other.

A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type Widget. For simplicity we will identify the widget and its type.

Types HBox and VBox are derivatives of type Widget, so they also are types Widget. Widgets HBox and VBox are special. They can store other widgets. Both those widgets can use the pack() method to pack directly in itself some other widget. Widgets of types HBox and VBox can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method pack() only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change.

We shall assume that the widget a is packed in the widget b if there exists a chain of widgets a = c1, c2, ..., ck = b, k ≥ 2, for which ci is packed directly to ci + 1 for any 1 ≤ i < k. In Vasya's library the situation when the widget a is packed in the widget a (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error.

Also, the widgets HBox and VBox have parameters border and spacing, which are determined by the methods set_border() and set_spacing() respectively. By default both of these options equal 0.

<image>

The picture above shows how the widgets are packed into HBox and VBox. At that HBox and VBox automatically change their size depending on the size of packed widgets. As for HBox and VBox, they only differ in that in HBox the widgets are packed horizontally and in VBox — vertically. The parameter spacing sets the distance between adjacent widgets, and border — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the pack() method was called for them. If within HBox or VBox there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options border and spacing.

The construction of all the widgets is performed using a scripting language VasyaScript. The description of the language can be found in the input data.

For the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of VasyaScript.

Input

The first line contains an integer n — the number of instructions (1 ≤ n ≤ 100). Next n lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below.

  * "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x] units and the height of [y] units.
  * "HBox [name]" — create a new widget [name] of the type HBox.
  * "VBox [name]" — create a new widget [name] of the type VBox.
  * "[name1].pack([name2])" — pack the widget [name2] in the widget [name1]. At that, the widget [name1] must be of type HBox or VBox.
  * "[name].set_border([x])" — set for a widget [name] the border parameter to [x] units. The widget [name] must be of type HBox or VBox.
  * "[name].set_spacing([x])" — set for a widget [name] the spacing parameter to [x] units. The widget [name] must be of type HBox or VBox.

All instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them.

The case matters, for example, "wiDget x" is not a correct instruction. The case of the letters is correct in the input data.

All names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive

It is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget.

Output

For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name.

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

Examples

Input

12
Widget me(50,40)
VBox grandpa
HBox father
grandpa.pack(father)
father.pack(me)
grandpa.set_border(10)
grandpa.set_spacing(20)
Widget brother(30,60)
father.pack(brother)
Widget friend(20,60)
Widget uncle(100,20)
grandpa.pack(uncle)

Output

brother 30 60
father 80 60
friend 20 60
grandpa 120 120
me 50 40
uncle 100 20

Input

15
Widget pack(10,10)
HBox dummy
HBox x
VBox y
y.pack(dummy)
y.set_border(5)
y.set_spacing(55)
dummy.set_border(10)
dummy.set_spacing(20)
x.set_border(10)
x.set_spacing(10)
x.pack(pack)
x.pack(dummy)
x.pack(pack)
x.set_border(0)

Output

dummy 0 0
pack 10 10
x 40 10
y 10 10

Note

In the first sample the widgets are arranged as follows:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef struct {
  string nome;
  long long int tipo;
  long long int altura, largura;
  long long int borda, espaco;
  vector<long long int> filhos;
} wid;
wid v[128];
long long int T, n, L[128];
char s[1024], aux[1024];
bool cmp(long long int a, long long int b) { return v[a].nome < v[b].nome; }
bool substr(char *s, const char *p) {
  long long int ns = strlen(s);
  long long int np = strlen(p);
  for (long long int i = 0; i < ns; i++)
    if (!strncmp(s + i, p, np)) return true;
  return false;
}
long long int getaltura(long long int u) {
  if (v[u].altura != -1) return v[u].altura;
  if (v[u].filhos.size() == 0) return v[u].altura = 0;
  if (v[u].tipo == 1) {
    long long int maior = 0;
    for (long long int i = 0; i < v[u].filhos.size(); i++) {
      long long int t = getaltura(v[u].filhos[i]);
      if (t > maior) maior = t;
    }
    return v[u].altura = maior + 2 * v[u].borda;
  } else if (v[u].tipo == 2) {
    long long int soma = 0;
    for (long long int i = 0; i < v[u].filhos.size(); i++) {
      long long int t = getaltura(v[u].filhos[i]);
      soma += t;
    }
    return v[u].altura =
               soma + 2 * v[u].borda + (v[u].filhos.size() - 1) * v[u].espaco;
  }
  return -1;
}
long long int getlargura(long long int u) {
  if (v[u].largura != -1) return v[u].largura;
  if (v[u].filhos.size() == 0) return v[u].largura = 0;
  if (v[u].tipo == 2) {
    long long int maior = 0;
    for (long long int i = 0; i < v[u].filhos.size(); i++) {
      long long int t = getlargura(v[u].filhos[i]);
      if (t > maior) maior = t;
    }
    return v[u].largura = maior + 2 * v[u].borda;
  } else if (v[u].tipo == 1) {
    long long int soma = 0;
    for (long long int i = 0; i < v[u].filhos.size(); i++) {
      long long int t = getlargura(v[u].filhos[i]);
      soma += t;
    }
    return v[u].largura =
               soma + 2 * v[u].borda + (v[u].filhos.size() - 1) * v[u].espaco;
  }
  return -1;
}
int main() {
  scanf("%I64d\n", &T);
  n = 0;
  while (T--) {
    fgets(s, 1024, stdin);
    s[strlen(s) - 1] = '\0';
    if (!strncmp(s, "Widget", 6)) {
      char *c = strtok(s, " ().,");
      c = strtok(NULL, " ().,");
      v[n].nome = c;
      v[n].tipo = 0;
      c = strtok(NULL, " ().,");
      sscanf(c, "%I64d", &(v[n].largura));
      c = strtok(NULL, " ().,");
      sscanf(c, "%I64d", &(v[n].altura));
      v[n].filhos.clear();
      n++;
      continue;
    }
    if (!strncmp(s, "HBox", 4)) {
      sscanf(s, "HBox %s", aux);
      v[n].nome = aux;
      v[n].tipo = 1;
      v[n].altura = v[n].largura = -1;
      v[n].borda = v[n].espaco = 0;
      v[n].filhos.clear();
      n++;
      continue;
    }
    if (!strncmp(s, "VBox", 4)) {
      sscanf(s, "VBox %s", aux);
      v[n].nome = aux;
      v[n].tipo = 2;
      v[n].altura = v[n].largura = -1;
      v[n].borda = v[n].espaco = 0;
      v[n].filhos.clear();
      n++;
      continue;
    }
    if (substr(s, ".pack(")) {
      char *c = strtok(s, " ().,");
      string nome = c;
      long long int eu = -1;
      for (long long int i = 0; i < n; i++)
        if (v[i].nome == nome) {
          eu = i;
          break;
        }
      c = strtok(NULL, " ().,");
      c = strtok(NULL, " ().,");
      nome = c;
      long long int filho = -1;
      for (long long int i = 0; i < n; i++)
        if (v[i].nome == nome) {
          filho = i;
          break;
        }
      v[eu].filhos.push_back(filho);
      continue;
    }
    if (substr(s, ".set_border(")) {
      char *c = strtok(s, " ().,");
      string nome = c;
      long long int eu = -1;
      for (long long int i = 0; i < n; i++)
        if (v[i].nome == nome) {
          eu = i;
          break;
        }
      c = strtok(NULL, " ().,");
      c = strtok(NULL, " ().,");
      long long int b;
      sscanf(c, "%I64d", &b);
      v[eu].borda = b;
      continue;
    }
    if (substr(s, ".set_spacing(")) {
      char *c = strtok(s, " ().,");
      string nome = c;
      long long int eu = -1;
      for (long long int i = 0; i < n; i++)
        if (v[i].nome == nome) {
          eu = i;
          break;
        }
      c = strtok(NULL, " ().,");
      c = strtok(NULL, " ().,");
      long long int b;
      sscanf(c, "%I64d", &b);
      v[eu].espaco = b;
      continue;
    }
  }
  for (long long int i = 0; i < n; i++) {
    v[i].altura = getaltura(i);
    v[i].largura = getlargura(i);
  }
  for (long long int i = 0; i < n; i++) L[i] = i;
  sort(L, L + n, cmp);
  for (long long int i = 0; i < n; i++) {
    printf("%s %I64d %I64d\n", v[L[i]].nome.c_str(), v[L[i]].largura,
           v[L[i]].altura);
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.

You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.

For examples, each of these pictures contain crosses:

<image>

The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).

Following images don't contain crosses:

<image>

You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.

What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?

You are also asked to answer multiple independent queries.

Input

The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.

The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.

Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.

It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.

Output

Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.

Example

Input

9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**

Output

0
0
0
0
0
4
1
1
2

Note

The example contains all the pictures from above in the same order.

The first 5 pictures already contain a cross, thus you don't have to paint anything.

You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.

You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).

You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.

There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int row[100010], col[100010];
vector<char> mat[100010];
int main() {
  int t, n, m, mx, mxRow, mxCol, ans;
  char ch;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    mx = max(n, m);
    for (int i = 0; i <= mx; i++) {
      row[i] = 0, col[i] = 0;
      ;
      mat[i].clear();
    }
    mxRow = 0, mxCol = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> ch;
        mat[i].push_back(ch);
        if (ch == '*') {
          row[i]++;
          col[j]++;
        }
        if (row[i] >= mxRow) {
          mxRow = row[i];
        }
        if (col[j] >= mxCol) {
          mxCol = col[j];
        }
      }
    }
    ans = (n - mxRow) + (m - mxCol);
    int i, j;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (row[i] != mxRow || col[j] != mxCol) continue;
        if (mat[i][j] == '.') {
          ans--;
          break;
        }
      }
      if (j != m) break;
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

We have N integers. The i-th integer is A_i.

Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

* 2 \leq N \leq 3 \times 10^5
* 0 \leq A_i < 2^{60}
* 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 value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Examples

Input

3
1 2 3

Output

6

Input

10
3 1 4 1 5 9 2 6 5 3

Output

237

Input

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Output

103715602

### Response

```cpp
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;
constexpr ll MOD=1e9+7;

int main()
{
	int N;
	cin>>N;
	vector<ll> A(N);
	rep(i,N)cin>>A[i];
	ll res=0;
	rep(idx,60){
		ll cnt0=0,cnt1=0;
		for(auto a:A)((a>>idx)&1?cnt1:cnt0)++;
		ll tres = (1ll<<idx)%MOD;
		(tres*=cnt0)%=MOD;
		(tres*=cnt1)%=MOD;
		(res+=tres)%=MOD;
	}
	cout<<res<<endl;
	return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

PolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white and red.

Colorfulness of the graph is a value min(dr, dw), where dr is the diameter of the red subgraph and dw is the diameter of white subgraph. The diameter of a graph is a largest value d such that shortest path between some pair of vertices in it is equal to d. If the graph is not connected, we consider its diameter to be -1.

PolandBall wants the final graph to be as neat as possible. He wants the final colorfulness to be equal to k. Can you help him and find any graph which satisfies PolandBall's requests?

Input

The only one input line contains two integers n and k (2 ≤ n ≤ 1000, 1 ≤ k ≤ 1000), representing graph's size and sought colorfulness.

Output

If it's impossible to find a suitable graph, print -1.

Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output m — the number of red edges in your graph. Then, you should output m lines, each containing two integers ai and bi, (1 ≤ ai, bi ≤ n, ai ≠ bi) which means that there is an undirected red edge between vertices ai and bi. Every red edge should be printed exactly once, you can print the edges and the vertices of every edge in arbitrary order.

Remember that PolandBall's graph should remain simple, so no loops or multiple edges are allowed.

Examples

Input

4 1

Output

-1

Input

5 2

Output

4
1 2
2 3
3 4
4 5

Note

In the first sample case, no graph can fulfill PolandBall's requirements.

In the second sample case, red graph is a path from 1 to 5. Its diameter is 4. However, white graph has diameter 2, because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
void fmain(int tid) {
  scanf("%d%d", &n, &k);
  if (k == 1 || k >= 4) et();
  if (k == 2) {
    if (n < 5) et();
    printf("%d\n", n - 1);
    for (int(i) = 1; (i) <= (int)(n - 1); (i)++) printf("%d %d\n", i, i + 1);
  } else {
    if (n < 4) et();
    printf("%d\n", n - 1);
    puts("1 2");
    puts("2 3");
    for (int i = 4; i <= n; i++) {
      printf("%d %d\n", 3, i);
    }
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}

```


### Prompt

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

A little boy Petya dreams of growing up and becoming the Head Berland Plumber. He is thinking of the problems he will have to solve in the future. Unfortunately, Petya is too inexperienced, so you are about to solve one of such problems for Petya, the one he's the most interested in.

The Berland capital has n water tanks numbered from 1 to n. These tanks are connected by unidirectional pipes in some manner. Any pair of water tanks is connected by at most one pipe in each direction. Each pipe has a strictly positive integer width. Width determines the number of liters of water per a unit of time this pipe can transport. The water goes to the city from the main water tank (its number is 1). The water must go through some pipe path and get to the sewer tank with cleaning system (its number is n).

Petya wants to increase the width of some subset of pipes by at most k units in total so that the width of each pipe remains integer. Help him determine the maximum amount of water that can be transmitted per a unit of time from the main tank to the sewer tank after such operation is completed.

Input

The first line contains two space-separated integers n and k (2 ≤ n ≤ 50, 0 ≤ k ≤ 1000). Then follow n lines, each line contains n integers separated by single spaces. The i + 1-th row and j-th column contain number cij — the width of the pipe that goes from tank i to tank j (0 ≤ cij ≤ 106, cii = 0). If cij = 0, then there is no pipe from tank i to tank j.

Output

Print a single integer — the maximum amount of water that can be transmitted from the main tank to the sewer tank per a unit of time.

Examples

Input

5 7
0 1 0 2 0
0 0 4 10 0
0 0 0 0 5
0 0 0 0 10
0 0 0 0 0

Output

10

Input

5 10
0 1 0 0 0
0 0 2 0 0
0 0 0 3 0
0 0 0 0 4
100 0 0 0 0

Output

5

Note

In the first test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 7 units.

In the second test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 4 units, from the 2nd to the 3rd water tank by 3 units, from the 3rd to the 4th water tank by 2 units and from the 4th to 5th water tank by 1 unit.

### Response

```cpp
#include <bits/stdc++.h>
const int inf = -1u / 4;
struct edge {
  int u, v, cap, cost;
};
edge e[50 * 50 * 4];
int n, lim, ne;
int maxflow, mincost;
int sol[55];
int dp[55];
int main() {
  scanf("%d %d", &n, &lim);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x;
      scanf("%d", &x);
      if (x) {
        e[ne++] = {i, j, x, 0};
        e[ne++] = {j, i, 0, 0};
        e[ne++] = {i, j, inf, 1};
        e[ne++] = {j, i, 0, -1};
      }
    }
  }
  for (;;) {
    for (int i = 1; i < n; i++) {
      dp[i] = inf;
    }
    for (int _ = 1, yes = 1; yes and _ < n; _++) {
      yes = 0;
      for (int i = 0; i < ne; i++) {
        if (e[i].cap and dp[e[i].v] > dp[e[i].u] + e[i].cost) {
          dp[e[i].v] = dp[e[i].u] + e[i].cost;
          sol[e[i].v] = i;
          yes = 1;
        }
      }
    }
    mincost += dp[n - 1];
    if (mincost > lim) {
      break;
    }
    int flow;
    if (dp[n - 1] == 0) {
      flow = inf;
      for (int v = n - 1; v;) {
        int i = sol[v];
        if (e[i].cap < flow) {
          flow = e[i].cap;
        }
        v = e[i].u;
      }
    } else {
      flow = 1;
    }
    maxflow += flow;
    for (int v = n - 1; v;) {
      int i = sol[v];
      e[i].cap -= flow;
      e[(i & 1 ^ 1) + (i >> 1 << 1)].cap += flow;
      v = e[i].u;
    }
  }
  printf("%d\n", maxflow);
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are given a set of strings S. Each string consists of lowercase Latin letters.

For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string and transform it into the string you want to type using the following actions:

  * if the current string is t, choose some lowercase Latin letter c and append it to the back of t, so the current string becomes t + c. This action takes 1 second;
  * use autocompletion. When you try to autocomplete the current string t, a list of all strings s ∈ S such that t is a prefix of s is shown to you. This list includes t itself, if t is a string from S, and the strings are ordered lexicographically. You can transform t into the i-th string from this list in i seconds. Note that you may choose any string from this list you want, it is not necessarily the string you are trying to type.

What is the minimum number of seconds that you have to spend to type each string from S?

Note that the strings from S are given in an unusual way.

Input

The first line contains one integer n (1 ≤ n ≤ 10^6).

Then n lines follow, the i-th line contains one integer p_i (0 ≤ p_i < i) and one lowercase Latin character c_i. These lines form some set of strings such that S is its subset as follows: there are n + 1 strings, numbered from 0 to n; the 0-th string is an empty string, and the i-th string (i ≥ 1) is the result of appending the character c_i to the string p_i. It is guaranteed that all these strings are distinct.

The next line contains one integer k (1 ≤ k ≤ n) — the number of strings in S.

The last line contains k integers a_1, a_2, ..., a_k (1 ≤ a_i ≤ n, all a_i are pairwise distinct) denoting the indices of the strings generated by above-mentioned process that form the set S — formally, if we denote the i-th generated string as s_i, then S = {s_{a_1}, s_{a_2}, ..., s_{a_k}}.

Output

Print k integers, the i-th of them should be equal to the minimum number of seconds required to type the string s_{a_i}.

Examples

Input

10
0 i
1 q
2 g
0 k
1 e
5 r
4 m
5 h
3 p
3 e
5
8 9 1 10 6

Output

2 4 1 3 3

Input

8
0 a
1 b
2 a
2 b
4 a
4 b
5 c
6 d
5
2 3 4 7 8

Output

1 2 2 4 4

Note

In the first example, S consists of the following strings: ieh, iqgp, i, iqge, ier.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
vector<vector<int>> g;
vector<int> exist;
set<pair<int, int>> se;
int cnt;
vector<int> dp;
vector<int> val;
void dfs(int now, int par) {
  if (par != -1) dp[now] = dp[par] + 1;
  if (exist[now]) {
    if (se.size()) {
      auto itr = se.begin();
      chmin(dp[now], cnt + 1 + (*itr).first);
    }
  }
  val[now] = dp[now] - cnt;
  se.insert(make_pair(val[now], now));
  if (exist[now]) ++cnt;
  for (auto nex : g[now]) {
    dfs(nex, now);
  }
  se.erase(make_pair(val[now], now));
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> P(N + 1);
  vector<char> C(N + 1);
  for (int i = 0; i < (N); ++i) cin >> P[i + 1] >> C[i + 1];
  g.resize(N + 1);
  for (int i = 0; i < (N); ++i) g[P[i + 1]].push_back(i + 1);
  for (int i = 0; i < (N); ++i) {
    sort(g[i].begin(), g[i].end(), [&](int a, int b) { return C[a] < C[b]; });
  }
  int K;
  cin >> K;
  vector<int> A(K);
  for (int i = 0; i < (K); ++i) cin >> A[i];
  exist.resize(N + 1, 0);
  for (int i = 0; i < (K); ++i) exist[A[i]] = 1;
  dp.resize(N + 1, 0);
  val.resize(N + 1, 0);
  dfs(0, -1);
  for (int i = 0; i < (K); ++i) cout << dp[A[i]] << " ";
  cout << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given a string s. You should answer n queries. The i-th query consists of integer k_i and string m_i. The answer for this query is the minimum length of such a string t that t is a substring of s and m_i has at least k_i occurrences as a substring in t.

A substring of a string is a continuous segment of characters of the string.

It is guaranteed that for any two queries the strings m_i from these queries are different.

Input

The first line contains string s (1 ≤ \left | s \right | ≤ 10^{5}).

The second line contains an integer n (1 ≤ n ≤ 10^5).

Each of next n lines contains an integer k_i (1 ≤ k_i ≤ |s|) and a non-empty string m_i — parameters of the query with number i, in this order.

All strings in input consists of lowercase English letters. Sum of length of all strings in input doesn't exceed 10^5. All m_i are distinct.

Output

For each query output the answer for it in a separate line.

If a string m_{i} occurs in s less that k_{i} times, output -1.

Examples

Input

aaaaa
5
3 a
3 aa
2 aaa
3 aaaa
1 aaaaa

Output

3
4
4
-1
5

Input

abbb
7
4 b
1 ab
3 bb
1 abb
2 bbb
1 a
2 abbb

Output

-1
2
-1
3
-1
1
-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
template <class T, class T2>
inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
template <class T>
inline void sortl(T &a) {
  sort(a.begin(), a.end());
}
template <class T>
inline void sortg(T &a) {
  sort(a.begin(), a.end(), greater<int>());
}
template <class T, class T2>
inline istream &operator>>(istream &is, pair<T, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class T2>
inline ostream &operator<<(ostream &os, const pair<T, T2> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v) {
  for (auto &curr : v) is >> curr;
  return is;
}
template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto curr : v) os << curr << ' ';
  return os;
}
template <class T, class T2>
inline ostream &operator<<(ostream &os, const map<T, T2> &m) {
  auto id = m.begin();
  while (id != m.end()) os << (*id).first << ' ' << (*(id++)).second;
  return os;
}
template <class T, class T2>
inline ostream &operator<<(ostream &os, const unordered_map<T, T2> &um) {
  auto id = um.begin();
  while (id != um.end()) os << (*id).first << ' ' << (*(id++)).second;
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const list<T> &l) {
  auto id = l.begin();
  while (id != l.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const set<T> &second) {
  auto id = second.begin();
  while (id != second.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const unordered_set<T> &us) {
  auto id = us.begin();
  while (id != us.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const multiset<T> &ms) {
  auto id = ms.begin();
  while (id != ms.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline ostream &operator<<(ostream &os, const unordered_multiset<T> &mus) {
  auto id = mus.begin();
  while (id != mus.end()) os << *(id++) << ' ';
  return os;
}
template <class T>
inline void inArray(T a[], const int &n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <class T>
inline void outArray(T a[], const int &n) {
  for (int i = 0; i < n; i++) cout << a[i] << ' ';
}
const bool hasTests = 0;
struct node {
  int par, link;
  int key;
  vector<int> ch, go;
  vector<int> eow;
  node(int par, int key) : par(par), key(key) {
    link = 0;
    ch.resize(26, 0);
  };
};
vector<node> tr;
vector<queue<int>> app;
vector<int> need, sz;
vector<int> ans;
string second;
int n;
void addString(string &second, int k) {
  int curr = 0;
  for (char ch : second) {
    int c = ch - 'a';
    if (!tr[curr].ch[c]) {
      tr[curr].ch[c] = ((int)tr.size());
      tr[curr].go.push_back(((int)tr.size()));
      tr.emplace_back(curr, c);
    }
    curr = tr[curr].ch[c];
  }
  tr[curr].eow.push_back(k);
}
void input() {
  cin >> second >> n;
  app.resize(n);
  need.resize(n);
  sz.resize(n);
  ans.resize(n, ((int)second.size()) + 1);
  tr.emplace_back(0, -1);
  string temps;
  for (int i = 0; i < n; i++) {
    cin >> need[i] >> temps;
    sz[i] = ((int)temps.size());
    addString(temps, i);
  }
}
void output() {
  for (int i = 0; i < n; i++) {
    if (ans[i] == ((int)second.size()) + 1) {
      cout << "-1\n";
    } else {
      cout << ans[i] + sz[i] << '\n';
    }
  }
}
void findLink(int u) {
  if (tr[u].par == 0) {
    return;
  }
  int p = tr[tr[u].par].link;
  int c = tr[u].key;
  while (p && !tr[p].ch[c]) {
    p = tr[p].link;
  }
  tr[u].link = tr[p].ch[c];
}
void findEndingWords(int u) {
  int v = tr[u].link;
  for (auto w : tr[v].eow) {
    tr[u].eow.push_back(w);
  }
}
void pushLinks() {
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    findLink(u);
    findEndingWords(u);
    for (auto v : tr[u].go) {
      q.push(v);
    }
  }
}
void endingIn(int w, int pos) {
  app[w].push(pos);
  if (app[w].size() > need[w]) {
    app[w].pop();
  }
  if (app[w].size() == need[w]) {
    chkmin(ans[w], pos - app[w].front());
  }
}
void solve() {
  pushLinks();
  int p = 0;
  for (int i = 0; i < ((int)second.size()); i++) {
    int c = second[i] - 'a';
    while (p && !tr[p].ch[c]) {
      p = tr[p].link;
    }
    p = tr[p].ch[c];
    for (auto w : tr[p].eow) {
      endingIn(w, i);
    }
  }
}
void start() {
  int t = 1;
  if (hasTests) cin >> t;
  for (int i = 1; i <= t; i++) {
    input();
    solve();
    output();
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  start();
  return 0;
}

```


### Prompt

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

In the advanced algorithm class, n2 students sit in n rows and n columns. One day, a professor who teaches this subject comes into the class, asks the shortest student in each row to lift up his left hand, and the tallest student in each column to lift up his right hand. What is the height of the student whose both hands are up ? The student will become a target for professor’s questions.

Given the size of the class, and the height of the students in the class, you have to print the height of the student who has both his hands up in the class.

Input

The input will consist of several cases. the first line of each case will be n(0 < n < 100), the number of rows and columns in the class. It will then be followed by a n-by-n matrix, each row of the matrix appearing on a single line. Note that the elements of the matrix may not be necessarily distinct. The input will be terminated by the case n = 0.

Output

For each input case, you have to print the height of the student in the class whose both hands are up. If there is no such student, then print 0 for that case.

Example

Input

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

Output

7
7

### Response

```cpp
//============================================================================
// Name        : testcpp2.cpp
// Author      : luyikei
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	while(true){
	int n=0;
	cin >> n;
	if(!n)
			break;
	vector< vector<int> >list;
	for (int i=0;i<n;i++){
		vector<int>tmp_v;
		for (int i2=0;i2<n;i2++){
			int tmp;
			cin >> tmp;
			tmp_v.push_back(tmp);
		}
		list.push_back(tmp_v);
	}
	vector<int> r_max_list;
	for (int i=0;i<n;i++){
		int r_max=100;
		for (int i2=0;i2<n;i2++){
			if(r_max > list[i][i2] ){
				r_max = list[i][i2];
			}
		}
		r_max_list.push_back(r_max);
	}
	vector<int> c_max_list;
		for (int i=0;i<n;i++){
			int c_max=0;
			for (int i2=0;i2<n;i2++){
				if(c_max < list[i2][i] ){
					c_max = list[i2][i];
				}
			}
			c_max_list.push_back(c_max);
		}
	int max=0;
	for (int i=0;i<n;i++){
		for (int i2=0;i2<n;i2++){
			if(r_max_list[i]==c_max_list[i2]){
				max = r_max_list[i];
			}
		}
	}
	cout << max << endl;
	}
	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:

We will define the distance between two strings s and t of the same length consisting of digits zero and one as the number of positions i, such that si isn't equal to ti.

As besides everything else Susie loves symmetry, she wants to find for two strings s and t of length n such string p of length n, that the distance from p to s was equal to the distance from p to t.

It's time for Susie to go to bed, help her find such string p or state that it is impossible.

Input

The first line contains string s of length n.

The second line contains string t of length n.

The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.

Output

Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).

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

Examples

Input

0001
1011

Output

0011

Input

000
111

Output

impossible

Note

In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int nax = 1e6 + 10;
vector<int> tree(4 * nax);
unsigned long long int i, j, x, y, k, f, z;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t, p;
  unsigned long long int cnt = 0;
  cin >> s >> t;
  for (i = 0; i < s.length(); i++) {
    if (s[i] != t[i]) cnt++;
  }
  if (cnt % 2 != 0)
    cout << "impossible" << endl;
  else {
    unsigned long long int S = 0, T = 1;
    for (i = 0; i < s.length(); i++) {
      if (s[i] != t[i]) {
        if (S == 0)
          p += s[i], S = 1, T = 0;
        else
          p += t[i], T = 1, S = 0;
      } else {
        p += s[i];
      }
    }
    cout << p << endl;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.

So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, ..., an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.

Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system.

Input

The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to.

The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

Output

If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".

Examples

Input

8 4
1 2 1 2 1 2 1

Output

YES

Input

8 5
1 2 1 2 1 1 1

Output

NO

Note

In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.

In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
int arr[100000 + 7];
int main() {
  int n, k, pos = 1;
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  while (pos < n) {
    pos = pos + arr[pos];
    if (pos == k) {
      printf("YES\n");
      return 0;
    }
  }
  if (pos == k) {
    printf("YES\n");
    return 0;
  }
  printf("NO\n");
  return 0;
}

```


### Prompt

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

One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.

He took a checkered white square piece of paper, consisting of n × n cells. After that, he started to paint the white cells black one after the other. In total he painted m different cells on the piece of paper. Since Valera was keen on everything square, he wondered, how many moves (i.e. times the boy paints a square black) he should make till a black square with side 3 can be found on the piece of paper. But Valera does not know the answer to this question, so he asks you to help him.

Your task is to find the minimum number of moves, till the checkered piece of paper has at least one black square with side of 3. Otherwise determine that such move does not exist.

Input

The first line contains two integers n and m (1 ≤ n ≤ 1000, 1 ≤ m ≤ min(n·n, 105)) — the size of the squared piece of paper and the number of moves, correspondingly.

Then, m lines contain the description of the moves. The i-th line contains two integers xi, yi (1 ≤ xi, yi ≤ n) — the number of row and column of the square that gets painted on the i-th move.

All numbers on the lines are separated by single spaces. It is guaranteed that all moves are different. The moves are numbered starting from 1 in the order, in which they are given in the input. The columns of the squared piece of paper are numbered starting from 1, from the left to the right. The rows of the squared piece of paper are numbered starting from 1, from top to bottom.

Output

On a single line print the answer to the problem — the minimum number of the move after which the piece of paper has a black square with side 3. If no such move exists, print -1.

Examples

Input

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

Output

10

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int maxm = 300010;
const int INF = 999999999;
int n, m;
int mk[maxn][maxn];
bool judge(int x, int y) {
  if (x - 1 < 1 || x + 1 > n || y - 1 < 1 || y + 1 > n) return false;
  int ans = 0;
  for (int i = x - 1; i <= x + 1; i++)
    for (int j = y - 1; j <= y + 1; j++) ans += mk[i][j];
  return ans == 9;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(mk, 0, sizeof(mk));
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    mk[x][y] = 1;
    if (judge(x + 1, y + 1) || judge(x + 1, y) || judge(x + 1, y - 1) ||
        judge(x, y + 1) || judge(x, y) || judge(x, y - 1) ||
        judge(x - 1, y + 1) || judge(x - 1, y) || judge(x - 1, y - 1)) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
  return 0;
}

```


### Prompt

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

A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points. These p_1 + … + p_D problems are all of the problems available on AtCode.

A user of AtCode has a value called total score. The total score of a user is the sum of the following two elements:

* Base score: the sum of the scores of all problems solved by the user.
* Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).

Takahashi, who is the new user of AtCode, has not solved any problem. His objective is to have a total score of G or more points. At least how many problems does he need to solve for this objective?

Constraints

* 1 ≤ D ≤ 10
* 1 ≤ p_i ≤ 100
* 100 ≤ c_i ≤ 10^6
* 100 ≤ G
* All values in input are integers.
* c_i and G are all multiples of 100.
* It is possible to have a total score of G or more points.

Input

Input is given from Standard Input in the following format:

D G
p_1 c_1
:
p_D c_D

Output

Print the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).

Examples

Input

2 700
3 500
5 800

Output

3

Input

2 2000
3 500
5 800

Output

7

Input

2 400
3 500
5 800

Output

2

Input

5 25000
20 1000
40 1000
50 1000
30 1000
1 1000

Output

66

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d,g;
bool used[10];
ll p[10],c[10];
ll dfs(ll kai,ll g){
  ll ret=1000000000;
  for(ll i=0;i<d;i++){
    if(used[i])continue;
    used[i]=true;
    double x=g/(100*(i+1)*1.0);
    ll y=ceil(x);
    if(y<=p[i])ret=min(ret,y+kai);
    else{
      if(100*(i+1)*p[i]+c[i]>=g)ret=min(ret,kai+p[i]);
      else ret=min(ret,dfs(kai+p[i],g-(100*(i+1)*p[i]+c[i])));
    }
    used[i]=false;
  }
  return ret;
}
int main(){
  cin>>d>>g;
  for(ll i=0;i<d;i++)cin>>p[i]>>c[i];
  for(ll i=0;i<d;i++)used[i]=false;
  cout<<dfs(0,g)<<endl;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?

You're given a sequence of n data points a1, ..., an. There aren't any big jumps between consecutive data points — for each 1 ≤ i < n, it's guaranteed that |ai + 1 - ai| ≤ 1.

A range [l, r] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let M be the maximum and m the minimum value of ai for l ≤ i ≤ r; the range [l, r] is almost constant if M - m ≤ 1.

Find the length of the longest almost constant range.

Input

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

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000).

Output

Print a single number — the maximum length of an almost constant range of the given sequence.

Examples

Input

5
1 2 3 3 2

Output

4

Input

11
5 4 5 5 6 7 8 8 8 7 6

Output

5

Note

In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.

In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100069], i, n, l, r;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> l;
    a[l] = i;
    r = max(r, i - min(max(a[l - 2], a[l + 1]), max(a[l - 1], a[l + 2])));
  }
  cout << r;
}

```


### Prompt

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

Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play t matches of a digit game...

In each of t matches of the digit game, a positive integer is generated. It consists of n digits. The digits of this integer are numerated from 1 to n from the highest-order digit to the lowest-order digit. After this integer is announced, the match starts.

Agents play in turns. Raze starts. In one turn an agent can choose any unmarked digit and mark it. Raze can choose digits on odd positions, but can not choose digits on even positions. Breach can choose digits on even positions, but can not choose digits on odd positions. The match ends, when there is only one unmarked digit left. If the single last digit is odd, then Raze wins, else Breach wins.

It can be proved, that before the end of the match (for every initial integer with n digits) each agent has an ability to make a turn, i.e. there is at least one unmarked digit, that stands on a position of required parity.

For each of t matches find out, which agent wins, if both of them want to win and play optimally.

Input

First line of input contains an integer t (1 ≤ t ≤ 100) — the number of matches.

The first line of each match description contains an integer n (1 ≤ n ≤ 10^3) — the number of digits of the generated number.

The second line of each match description contains an n-digit positive integer without leading zeros.

Output

For each match print 1, if Raze wins, and 2, if Breach wins.

Example

Input

4
1
2
1
3
3
102
4
2069

Output

2
1
1
2

Note

In the first match no one can make a turn, the only digit left is 2, it's even, so Breach wins.

In the second match the only digit left is 3, it's odd, so Raze wins.

In the third match Raze can mark the last digit, after that Breach can only mark 0. 1 will be the last digit left, it's odd, so Raze wins.

In the fourth match no matter how Raze plays, Breach can mark 9, and in the end there will be digit 0. It's even, so Breach wins.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n == 1) {
      int num = s[0] - '0';
      if (num % 2 == 0)
        cout << 2 << endl;
      else
        cout << 1 << endl;
    } else if (n % 2 != 0) {
      int flag = 0;
      for (int i = 0; i < s.length(); i += 2) {
        if ((s[i] - '0') % 2 != 0) {
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        cout << 2 << endl;
      else
        cout << 1 << endl;
    } else {
      int flag = 0;
      for (int i = 1; i < s.length(); i += 2) {
        if ((s[i] - '0') % 2 == 0) {
          flag = 1;
          break;
        }
      }
      if (flag == 1)
        cout << 2 << endl;
      else
        cout << 1 << endl;
    }
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called k-balanced if every substring of size k of this bitstring has an equal amount of 0 and 1 characters (k/2 of each).

You are given an integer k and a string s which is composed only of characters 0, 1, and ?. You need to determine whether you can make a k-balanced bitstring by replacing every ? characters in s with either 0 or 1.

A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Input

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

The first line of each test case contains two integers n and k (2 ≤ k ≤ n ≤ 3 ⋅ 10^5, k is even) — the length of the string and the parameter for a balanced bitstring.

The next line contains the string s (|s| = n). It is given that s consists of only 0, 1, and ?.

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

Output

For each test case, print YES if we can replace every ? in s with 0 or 1 such that the resulting bitstring is k-balanced, or NO if it is not possible.

Example

Input

9
6 4
100110
3 2
1?1
3 2
1?0
4 4
????
7 4
1?0??1?
10 10
11??11??11
4 2
1??1
4 4
?0?0
6 2
????00

Output

YES
YES
NO
YES
YES
NO
NO
YES
NO

Note

For the first test case, the string is already a 4-balanced bitstring.

For the second test case, the string can be transformed into 101.

For the fourth test case, the string can be transformed into 0110.

For the fifth test case, the string can be transformed into 1100110.

### Response

```cpp
#include <bits/stdc++.h>
const long long inf = 1e9;
const long long cont = 1e18;
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  bool on[k], off[k];
  memset(on, 0, sizeof on);
  memset(off, 0, sizeof off);
  bool ok = true;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') on[i % k] = true;
    if (s[i] == '0') off[i % k] = true;
  }
  for (long long i = 0; i < k; i++) {
    if (on[i] && off[i]) {
      ok = false;
    }
  }
  long long oncnt = 0, offcnt = 0;
  for (long long i = 0; i < k; i++) {
    if (on[i])
      oncnt++;
    else if (off[i])
      offcnt++;
  }
  if (oncnt * 2 > k || offcnt * 2 > k) {
    ok = false;
  }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  long long tst;
  cin >> tst;
  while (tst--) solve();
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.

A column vector with m elements is represented by the following equation.

\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]

A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.

\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]

$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).

The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:

\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]

Constraints

* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$

Input

In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.

Output

The output consists of $n$ lines. Print $c_i$ in a line.

Example

Input

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

Output

5
6
9

### Response

```cpp
#include <stdio.h>
int main()
{
	int n,m,a[100][100]={0},b[100],c[100]={0};
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=0;i<m;i++)
		scanf("%d",&b[i]);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			c[i]=c[i]+a[i][j]*b[j];
		}
		printf("%d\n",c[i]);
	}
	return 0;
}
```


### Prompt

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

At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.

Help the university pick the passing rate in a way that meets these requirements.

Input

The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.

Output

If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.

Examples

Input

5
3 4 3 2 1
6 8

Output

3

Input

5
0 3 3 4 2
3 10

Output

4

Input

2
2 5
3 6

Output

0

Note

In the first sample the beginner group has 7 students, the intermediate group has 6 of them.

In the second sample another correct answer is 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void PLAY() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int max(int a, int b) {
  if (a > b) return a;
  return b;
}
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
long long fx4[] = {-1, 1, 0, 0};
long long fy4[] = {0, 0, -1, 1};
long long fx8[] = {-1, -1, -1, 0, 1, 1, 1, 0};
long long fy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const double PI = 3.141592653589793;
const long long N = 2e5 + 5;
const long long mod = 1000000007;
long long n;
long long arr[N];
long long x, y;
int32_t main() {
  PLAY();
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> arr[i];
  cin >> x >> y;
  for (long long i = 1; i < n; i++) arr[i] = arr[i - 1] + arr[i];
  for (long long i = 0; i < n; i++) {
    long long a = arr[i];
    long long b = arr[n - 1] - arr[i];
    if (a >= x and a <= y and b >= x and b <= y) {
      cout << i + 2 << "\n";
      return 0;
    }
  }
  cout << "0"
       << "\n";
}

```


### Prompt

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

Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!

He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!

The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.

Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.

Input

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

Each of the next n - 1 lines contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) — the edges of the tree. It is guaranteed that the given edges form a tree.

Output

If there are no decompositions, print the only line containing "No".

Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition m.

Each of the next m lines should contain two integers u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) denoting that one of the paths in the decomposition is the simple path between nodes u_i and v_i.

Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.

If there are multiple decompositions, print any.

Examples

Input

4
1 2
2 3
3 4

Output

Yes
1
1 4

Input

6
1 2
2 3
3 4
2 5
3 6

Output

No

Input

5
1 2
1 3
1 4
1 5

Output

Yes
4
1 2
1 3
1 4
1 5

Note

The tree from the first example is shown on the picture below: <image> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.

The tree from the second example is shown on the picture below: <image> We can show that there are no valid decompositions of this tree.

The tree from the third example is shown on the picture below: <image> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, u, v, cou = 0, r = -1, re, le, ri;
vector<int> q;
vector<vector<int> > edge;
vector<bool> leaf, visit;
int main() {
  scanf("%d", &n);
  edge.resize(n + 1);
  visit.resize(n + 1);
  for (int i = (1); i < (n + 1); i++) {
    edge[i].resize(0);
    visit[i] = false;
  }
  for (int i = (0); i < (n - 1); i++) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  for (int i = (1); i < (n + 1); i++)
    if (edge[i].size() > 2) {
      cou++;
      r = i;
    }
  if (cou > 1) {
    printf("No");
    return 0;
  }
  if (r == -1) r = 1;
  leaf.resize(n + 1);
  for (int i = (1); i < (n + 1); i++) leaf[i] = true;
  q.resize(0);
  q.push_back(r);
  le = -1;
  ri = 0;
  visit[r] = true;
  while (++le <= ri) {
    u = q[le];
    for (int i = (0); i < (edge[u].size()); i++) {
      v = edge[u][i];
      if (visit[v] == false) {
        visit[v] = true;
        leaf[u] = false;
        q.push_back(v);
        ri++;
      }
    }
  }
  for (int i = (1); i < (n + 1); i++)
    if (leaf[i]) re++;
  printf("Yes\n");
  printf("%d\n", re);
  for (int i = (1); i < (n + 1); i++)
    if (leaf[i]) {
      printf("%d %d\n", i, r);
    }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean.

Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.

You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map.

The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).

It is guaranteed that the map contain at least k lakes.

Output

In the first line print the minimum number of cells which should be transformed from water to land.

In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.

It is guaranteed that the answer exists on the given data.

Examples

Input

5 4 1
****
*..*
****
**.*
..**

Output

1
****
*..*
****
****
..**

Input

3 3 0
***
*.*
***

Output

1
***
***
***

Note

In the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int grid[55][55];
int vis[55][55];
vector<pair<long long, long long> > sz;
int num_comp;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool valid(int i, int j) {
  return i >= 0 && j >= 0 && i <= n + 1 && j <= m + 1;
}
int dfs(int i, int j) {
  vis[i][j] = num_comp;
  int ans = 1;
  for (int l = 0; l < 4; ++l) {
    int new_x = i + dx[l], new_y = j + dy[l];
    if (valid(new_x, new_y) && !vis[new_x][new_y] && grid[new_x][new_y] == 0)
      ans += dfs(new_x, new_y);
  }
  return ans;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n + 2; ++i)
    for (int j = 0; j < m + 2; ++j) {
      if (i == 0 || i == n + 1 || j == 0 || j == m + 1)
        grid[i][j] = 0;
      else {
        char x;
        cin >> x;
        if (x == '.')
          grid[i][j] = 0;
        else
          grid[i][j] = 1;
      }
    }
  for (int i = 0; i < n + 2; ++i)
    for (int j = 0; j < m + 2; ++j) {
      if (!vis[i][j] && grid[i][j] == 0) {
        num_comp++;
        int x = dfs(i, j);
        if (num_comp != 1) sz.push_back({x, num_comp});
      }
    }
  sort(sz.begin(), sz.end());
  int ans = 0;
  for (int p = 0; p < sz.size() - k; p++) {
    ans += sz[p].first;
    for (int i = 0; i < n + 2; ++i)
      for (int j = 0; j < m + 2; ++j)
        if (grid[i][j] == 0 && vis[i][j] == sz[p].second) grid[i][j] = 1;
  }
  cout << ans << endl;
  for (int i = 1; i < n + 1; ++i) {
    for (int j = 1; j < m + 1; ++j) {
      if (grid[i][j])
        cout << "*";
      else
        cout << ".";
    }
    cout << endl;
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

There are 2^N players, numbered 1, 2, ..., 2^N. They decided to hold a tournament.

The tournament proceeds as follows:

* Choose a permutation of 1, 2, ..., 2^N: p_1, p_2, ..., p_{2^N}.
* The players stand in a row in the order of Player p_1, Player p_2, ..., Player p_{2^N}.
* Repeat the following until there is only one player remaining in the row:
* Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
* The last player who remains in the row is the champion.

It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input:

* When y = A_i for some i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player y.
* When y \neq A_i for every i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player 1.
* When 2 \leq x < y \leq 2^N, the winner of the match between Player x and Player y will be Player x.

The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7.

Constraints

* 1 \leq N \leq 16
* 0 \leq M \leq 16
* 2 \leq A_i \leq 2^N (1 \leq i \leq M)
* A_i < A_{i + 1} (1 \leq i < M)

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_M

Output

Print the answer.

Examples

Input

2 1
3

Output

8

Input

4 3
2 4 6

Output

0

Input

3 0

Output

40320

Input

3 3
3 4 7

Output

2688

Input

16 16
5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003

Output

816646464

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int P=1e9+7,maxn=(1<<16)+5;
int n,m,a[20];
LL f[20][maxn],fac[maxn],inv[maxn],fac_inv[maxn],ans;
LL C(int n,int m){
  if(n<0||m<0||n<m) return 0;
  return fac[n]*fac_inv[m]%P*fac_inv[n-m]%P;
}
int main(){
  scanf("%d%d",&n,&m);
  fac[0]=1; for(int i=1;i<=(1<<n);i++) fac[i]=fac[i-1]*i%P;
  inv[1]=1; for(int i=2;i<=(1<<n);i++) inv[i]=(LL)(P-P/i)*inv[P%i]%P;
  fac_inv[0]=1; for(int i=1;i<=(1<<n);i++) fac_inv[i]=fac_inv[i-1]*inv[i]%P;
  for(int i=1;i<=m;i++) scanf("%d",&a[i]);
  sort(a+1,a+1+m,greater<int>());
  f[0][0]=1;
  for(int i=0;i<=m-1;i++)
    for(int s=0;s<=(1<<n)-1;s++)
      if(f[i][s]){
	(f[i+1][s]+=f[i][s])%=P;
	for(int j=0;j<=n-1;j++)
	  if(!((s>>j)&1))
	    (f[i+1][s|(1<<j)]+=f[i][s]*C((1<<n)-a[i+1]-s,(1<<j)-1)%P*fac[1<<j]%P)%=P;
      }
  for(int s=0;s<=(1<<n)-1;s++){
    int sz=0; for(int i=0;i<=n-1;i++) if((s>>i)&1) sz++;
    ans=(ans+f[m][s]*fac[(1<<n)-1-s]*((sz&1)?-1:1))%P;
  }
  printf("%d\n",(ans*(1<<n)%P+P)%P);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.

Help Bender to solve this difficult task.

Input

The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers — the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.

Output

If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod.

If there are multiple solutions, print any of them.

Examples

Input

4 2
0 0
0 2
2 2
2 0
4 4

Output

YES
1 -1 2 -1

Input

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

Output

YES
1 -1 2 -1 3 -1

Input

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

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
int n, m;
vector<int> len;
vector<pair<int, int> > pos;
deque<int> ans;
vector<bool> vis;
int find(int x) {
  for (int i = 0; i < (int)len.size(); ++i) {
    if (len[i] == x and !vis[i]) return i;
  }
  return -1;
}
int main() {
  cin >> n >> m;
  pos = vector<pair<int, int> >(n);
  len = vector<int>(m);
  for (int i = 0; i < n; ++i) cin >> pos[i].first >> pos[i].second;
  for (int i = 0; i < m; ++i) cin >> len[i];
  if (n % 2) {
    cout << "NO" << endl;
    return 0;
  }
  bool good = 0;
  vis = vector<bool>(m, 0);
  ans = deque<int>();
  for (int i = 0; i < n; i += 2) {
    int prev = (i + n - 1) % n;
    int dist1 = (int)hypot(pos[prev].first - pos[i].first,
                           pos[prev].second - pos[i].second);
    int dist2 = (int)hypot(pos[i + 1].first - pos[i].first,
                           pos[i + 1].second - pos[i].second);
    int idx = find(dist1 + dist2);
    if (idx != -1) {
      vis[idx] = 1;
      ans.push_back(idx);
    } else
      goto no;
  }
  cout << "YES" << endl;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 1)
      cout << -1 << " ";
    else {
      cout << ans.front() + 1 << " ";
      ans.pop_front();
    }
  }
  cout << endl;
  return 0;
no:;
  vis = vector<bool>(m, 0);
  ans = deque<int>();
  for (int i = 1; i < n; i += 2) {
    int nxt = (i + n + 1) % n;
    int dist1 = (int)hypot(pos[i - 1].first - pos[i].first,
                           pos[i - 1].second - pos[i].second);
    int dist2 = (int)hypot(pos[nxt].first - pos[i].first,
                           pos[nxt].second - pos[i].second);
    int idx = find(dist1 + dist2);
    if (idx != -1) {
      vis[idx] = 1;
      ans.push_back(idx);
    } else {
      good = 0;
      goto noo;
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0)
      cout << -1 << " ";
    else {
      cout << ans.front() + 1 << " ";
      ans.pop_front();
    }
  }
  cout << endl;
  return 0;
noo:;
  cout << "NO" << endl;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given an integer n.

You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:

  1. Replace n with n/2 if n is divisible by 2;
  2. Replace n with 2n/3 if n is divisible by 3;
  3. Replace n with 4n/5 if n is divisible by 5.

For example, you can replace 30 with 15 using the first operation, with 20 using the second operation or with 24 using the third operation.

Your task is to find the minimum number of moves required to obtain 1 from n or say that it is impossible to do it.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries.

The next q lines contain the queries. For each query you are given the integer number n (1 ≤ n ≤ 10^{18}).

Output

Print the answer for each query on a new line. If it is impossible to obtain 1 from n, print -1. Otherwise, print the minimum number of moves required to do it.

Example

Input

7
1
10
25
30
14
27
1000000000000000000

Output

0
4
6
6
-1
6
72

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long T, n, ans;
signed main() {
  cin >> T;
  for (long long i = 1; i <= T; i++) {
    ans = 0;
    scanf("%lld", &n);
    while (n > 1) {
      if (n % 2 == 0) {
        n = n / 2;
        ans++;
      } else if (n % 3 == 0) {
        n = n / 3;
        ans += 2;
      } else if (n % 5 == 0) {
        n = n / 5;
        ans += 3;
      } else
        break;
    }
    if (n == 1)
      printf("%lld\n", ans);
    else
      puts("-1");
  }
}

```


### Prompt

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

This is an interactive problem.

Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order.

Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you:

  * if t = 1, the area of the triangle a_ia_ja_k multiplied by 2.
  * if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}.

Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a ⋅ y_b - x_b ⋅ y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0.

You can ask at most 3 ⋅ n queries.

Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order.

Interaction

You start the interaction by reading n (3 ≤ n ≤ 1 000) — the number of vertices.

To ask a query, write 4 integers t, i, j, k (1 ≤ t ≤ 2, 1 ≤ i, j, k ≤ n) in a separate line. i, j and k should be distinct.

Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer.

When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line.

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

To hack, use the following format:

The first line contains an integer n (3 ≤ n ≤ 1 000) — the number of vertices.

The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — the coordinate of the point a_i.

Example

Input

6

15

-1

1

Output

1 1 4 6

2 1 5 6

2 2 1 4

0 1 3 4 2 6 5

Note

The image below shows the hidden polygon in the example:

<image>

The interaction in the example goes as below:

  * Contestant reads n = 6.
  * Contestant asks a query with t = 1, i = 1, j = 4, k = 6.
  * Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle.
  * Contestant asks a query with t = 2, i = 1, j = 5, k = 6.
  * Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1.
  * Contestant asks a query with t = 2, i = 2, j = 1, k = 4.
  * Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1.
  * Contestant says that the permutation is (1, 3, 4, 2, 6, 5).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll query1(int i, int j, int k) {
  cout << "1 " << i + 1 << ' ' << j + 1 << ' ' << k + 1 << endl;
  ll s;
  cin >> s;
  return s;
}
int query2(int i, int j, int k) {
  cout << "2 " << i + 1 << ' ' << j + 1 << ' ' << k + 1 << endl;
  int s;
  cin >> s;
  return s;
}
const ll INF = 5e18;
int main() {
  int n;
  cin >> n;
  vector<bool> dir(n);
  for (int i = 2; i < n; i++) {
    dir[i] = query2(0, 1, i) > 0;
  }
  vector<ll> S(n);
  for (int i = 2; i < n; i++) {
    S[i] = query1(0, 1, i);
  }
  int id1 = 0, id2 = 1;
  ll ma1 = 0, ma2 = 0;
  for (int i = 2; i < n; i++) {
    if (dir[i]) {
      if (ma1 < S[i]) {
        ma1 = S[i];
        id1 = i;
      }
    } else {
      if (ma2 < S[i]) {
        ma2 = S[i];
        id2 = i;
      }
    }
  }
  vector<int> flag(n);
  for (int i = 2; i < n; i++)
    if (i != id1 && i != id2) {
      flag[i] = query2(id1, id2, i) > 0;
    }
  vector<tuple<int, ll, int>> ids;
  ids.emplace_back(0, 0, 0);
  if (id2 != 1) ids.emplace_back(1, -INF, id2);
  ids.emplace_back(2, 0, 1);
  if (id1 != 0) ids.emplace_back(3, -INF, id1);
  for (int i = 2; i < n; i++)
    if (i != id1 && i != id2) {
      if (dir[i]) {
        if (flag[i]) {
          ids.emplace_back(2, S[i], i);
        } else {
          ids.emplace_back(3, -S[i], i);
        }
      } else {
        if (flag[i]) {
          ids.emplace_back(1, -S[i], i);
        } else {
          ids.emplace_back(0, S[i], i);
        }
      }
    }
  sort(ids.begin(), ids.end());
  cout << 0;
  for (int i = 0; i < n; i++) {
    cout << ' ' << get<2>(ids[i]) + 1;
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1, z1). The six faces of the box contain some numbers a1, a2, ..., a6, exactly one number right in the center of each face.

<image>

The numbers are located on the box like that:

  * number a1 is written on the face that lies on the ZOX plane;
  * a2 is written on the face, parallel to the plane from the previous point;
  * a3 is written on the face that lies on the XOY plane;
  * a4 is written on the face, parallel to the plane from the previous point;
  * a5 is written on the face that lies on the YOZ plane;
  * a6 is written on the face, parallel to the plane from the previous point.

At the moment Vasya is looking at the box from point (x, y, z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the ai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some ai = 6, then he can't mistake this number for 9 and so on).

Input

The fist input line contains three space-separated integers x, y and z (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integers x1, y1, z1 (1 ≤ x1, y1, z1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers a1, a2, ..., a6 (1 ≤ ai ≤ 106) — the numbers that are written on the box faces.

It is guaranteed that point (x, y, z) is located strictly outside the box.

Output

Print a single integer — the sum of all numbers on the box faces that Vasya sees.

Examples

Input

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

Output

12

Input

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

Output

4

Note

The first sample corresponds to perspective, depicted on the picture. Vasya sees numbers a2 (on the top face that is the darkest), a6 (on the right face that is the lightest) and a4 (on the left visible face).

In the second sample Vasya can only see number a4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
const long long int maxi = 1e6 + 1;
long long int modexp(long long int x, long long int y, long long int mod) {
  long long int ans = 1ll;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % mod;
    x = (x * x) % mod;
    y = y >> 1;
  }
  return ans;
}
long long int modinv(long long int x, long long int mod) {
  return modexp(x, mod - 2, mod);
}
long long int gsum(int arr[], int n) {
  long long int ans = 0;
  for (int i = 0; i < (int)(n); ++i) ans += (long long int)arr[i];
  return ans;
}
string second;
long long int n, m, t, a, b, c;
void solve() {}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  ;
  int x, y, z, x1, y1, z1;
  cin >> x >> y >> z >> x1 >> y1 >> z1;
  int a1, a2, a3, a4, a5, a6;
  cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;
  long long int ans = 0;
  if (y < 0) ans += a1;
  if (y > y1) ans += a2;
  if (z < 0) ans += a3;
  if (z > z1) ans += a4;
  if (x < 0) ans += a5;
  if (x > x1) ans += a6;
  cout << ans;
  return 0;
}

```