### Prompt

Construct a cpp code solution to the problem outlined:

On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.

The j-th key can be used to unlock the i-th chest if and only if the sum of the key number and the chest number is an odd number. Formally, a_i + b_j ≡ 1 \pmod{2}. One key can be used to open at most one chest, and one chest can be opened at most once.

Find the maximum number of chests Neko can open.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 10^5) — the number of chests and the number of keys.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the numbers written on the treasure chests.

The third line contains m integers b_1, b_2, …, b_m (1 ≤ b_i ≤ 10^9) — the numbers written on the keys.

Output

Print the maximum number of chests you can open.

Examples

Input

5 4
9 14 6 2 11
8 4 7 20

Output

3

Input

5 1
2 4 6 8 10
5

Output

1

Input

1 4
10
20 30 40 50

Output

0

Note

In the first example, one possible way to unlock 3 chests is as follows:

  * Use first key to unlock the fifth chest,
  * Use third key to unlock the second chest,
  * Use fourth key to unlock the first chest.

In the second example, you can use the only key to unlock any single chest (note that one key can't be used twice).

In the third example, no key can unlock the given chest.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, even = 0, odd = 0, e = 0, o = 0;
  cin >> n >> m;
  vector<long long int> a, b;
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    a.push_back(x);
    if (x % 2 == 0) {
      e++;
    } else {
      o++;
    }
  }
  for (int i = 0; i < m; i++) {
    long long int x;
    cin >> x;
    b.push_back(x);
    if (x % 2 == 0) {
      even++;
    } else {
      odd++;
    }
  }
  long long int EVEN = 0, ODD = 0;
  EVEN = min(e, odd);
  ODD = min(even, o);
  cout << EVEN + ODD << endl;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.

You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.

The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations:

  * remove any self-closing tag "<tagname/>",
  * remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>".

For example, you may be given such document: "

" but you may not be given documents "", "", "" or "".

Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.

We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list:

  * there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on),
  * this sequence ends with element t (i.e. tagname of element t equals "xn").

For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.

Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule.

Input

The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters.

The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10.

Output

Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0.

Examples

Input

<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>
4
a
a b b
a b
b a

Output

2
1
4
0

Input

<b><aa/></b><aa><b/><b/></aa>
5
aa b
b
aa
b aa
a

Output

2
3
2
1
0

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:260108864")
using namespace std;
char s[1000005];
int lenS;
int d[1000001];
int query[1000001];
int haveTo[1000001];
int n;
int now;
int qN;
map<string, int> m;
void prepare() {
  now = 0;
  int k(0);
  for (int i(0); i <= ((int)(lenS)-1); ++i) {
    ++i;
    string tag;
    int upTo(0);
    bool close = false;
    while (s[i + upTo] != '>') {
      if (s[i + upTo] != '/') tag += s[i + upTo];
      ++upTo;
    }
    if (m[tag] == 0) m[tag] = ++k;
    if (s[i] == '/') close = true;
    if (s[i + upTo - 1] == '/') {
      d[now++] = m[tag];
      d[now++] = -m[tag];
    } else if (close)
      d[now++] = -m[tag];
    else
      d[now++] = m[tag];
    i += upTo;
  }
}
void prepareQ() {
  qN = 0;
  for (int i(0); i <= ((int)(lenS)-1); ++i) {
    int upTo(0);
    string tag;
    while (s[i + upTo] != 0 && s[i + upTo] != ' ') tag += s[i + upTo], ++upTo;
    int tagN(0);
    if (m.count(tag) != 0) tagN = m[tag];
    query[qN++] = tagN;
    i += upTo;
  }
}
int calc() {
  int nowSt(1);
  haveTo[0] = 0;
  int res(0);
  for (int i(0); i <= ((int)(now)-1); ++i) {
    if (d[i] < 0)
      --nowSt;
    else {
      if (d[i] == query[haveTo[nowSt - 1]])
        haveTo[nowSt] = haveTo[nowSt - 1] + 1;
      else
        haveTo[nowSt] = haveTo[nowSt - 1];
      if (haveTo[nowSt] == qN) ++res, haveTo[nowSt] -= 1;
      ++nowSt;
    }
  }
  return res;
}
int main() {
  gets(s);
  lenS = strlen(s);
  prepare();
  int n;
  scanf("%d\n", &n);
  for (int i(0); i <= ((int)(n)-1); ++i) {
    gets(s);
    lenS = strlen(s);
    prepareQ();
    printf("%d\n", calc());
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Mishka wants to buy some food in the nearby shop. Initially, he has s burles on his card.

Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number 1 ≤ x ≤ s, buy food that costs exactly x burles and obtain ⌊x/10⌋ burles as a cashback (in other words, Mishka spends x burles and obtains ⌊x/10⌋ back). The operation ⌊a/b⌋ means a divided by b rounded down.

It is guaranteed that you can always buy some food that costs x for any possible value of x.

Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.

For example, if Mishka has s=19 burles then the maximum number of burles he can spend is 21. Firstly, he can spend x=10 burles, obtain 1 burle as a cashback. Now he has s=10 burles, so can spend x=10 burles, obtain 1 burle as a cashback and spend it too.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases.

The next t lines describe test cases. Each test case is given on a separate line and consists of one integer s (1 ≤ s ≤ 10^9) — the number of burles Mishka initially has.

Output

For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.

Example

Input

6
1
10
19
9876
12345
1000000000

Output

1
11
21
10973
13716
1111111111

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100000000000;
long long Ceil(long long a, long long b) { return (a / b) + ((a % b) != 0); }
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long cb = 0, rem = 0, total = 0;
    while (n / 10 > 0) {
      cb = n / 10;
      rem = n % 10;
      total += cb * 10;
      n = cb + rem;
    }
    cout << total + (n % 10) << endl;
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

For a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of its edges is minimum possible.

You are given a graph G. If you run a MST algorithm on graph it would give you only one MST and it causes other edges to become jealous. You are given some queries, each query contains a set of edges of graph G, and you should determine whether there is a MST containing all these edges or not.

Input

The first line contains two integers n, m (2 ≤ n, m ≤ 5·105, n - 1 ≤ m) — the number of vertices and edges in the graph and the number of queries.

The i-th of the next m lines contains three integers ui, vi, wi (ui ≠ vi, 1 ≤ wi ≤ 5·105) — the endpoints and weight of the i-th edge. There can be more than one edges between two vertices. It's guaranteed that the given graph is connected.

The next line contains a single integer q (1 ≤ q ≤ 5·105) — the number of queries.

q lines follow, the i-th of them contains the i-th query. It starts with an integer ki (1 ≤ ki ≤ n - 1) — the size of edges subset and continues with ki distinct space-separated integers from 1 to m — the indices of the edges. It is guaranteed that the sum of ki for 1 ≤ i ≤ q does not exceed 5·105.

Output

For each query you should print "YES" (without quotes) if there's a MST containing these edges and "NO" (of course without quotes again) otherwise.

Example

Input

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

Output

YES
NO
YES
NO

Note

This is the graph of sample:

<image>

Weight of minimum spanning tree on this graph is 6.

MST with edges (1, 3, 4, 6), contains all of edges from the first query, so answer on the first query is "YES".

Edges from the second query form a cycle of length 3, so there is no spanning tree including these three edges. Thus, answer is "NO".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXBUF = 10000;
char buf[MAXBUF], *ps = buf, *pe = buf + 1;
inline bool isdigit(const char& n) { return (n >= '0' && n <= '9'); }
inline void rnext() {
  if (++ps == pe)
    pe = (ps = buf) +
         fread(buf, sizeof(char), sizeof(buf) / sizeof(char), stdin);
}
template <class T>
inline bool in(T& ans) {
  ans = 0;
  T f = 1;
  if (ps == pe) return false;
  do {
    rnext();
    if ('-' == *ps) f = -1;
  } while (!isdigit(*ps) && ps != pe);
  if (ps == pe) return false;
  do {
    ans = (ans << 1) + (ans << 3) + *ps - 48;
    rnext();
  } while (isdigit(*ps) && ps != pe);
  ans *= f;
  return true;
}
const int MAXOUT = 10000;
char bufout[MAXOUT], outtmp[50], *pout = bufout, *pend = bufout + MAXOUT;
inline void write() {
  fwrite(bufout, sizeof(char), pout - bufout, stdout);
  pout = bufout;
}
inline void out_char(char c) {
  *(pout++) = c;
  if (pout == pend) write();
}
inline void out_str(char* s) {
  while (*s) {
    *(pout++) = *(s++);
    if (pout == pend) write();
  }
}
template <class T>
inline void out_int(T x) {
  if (!x) {
    out_char('0');
    return;
  }
  if (x < 0) x = -x, out_char('-');
  int len = 0;
  while (x) {
    outtmp[len++] = x % 10 + 48;
    x /= 10;
  }
  outtmp[len] = 0;
  for (int i = 0, j = len - 1; i < j; i++, j--) swap(outtmp[i], outtmp[j]);
  out_str(outtmp);
}
template <typename T, typename... T2>
inline int in(T& value, T2&... value2) {
  in(value);
  return in(value2...);
}
const double eps = 1e-9;
const int maxn = 5e5 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int N, M, tmp, K, Q;
struct Edge {
  int u, v, w, id;
} edge[maxn];
struct node {
  int w, id, pointer;
  friend bool operator<(node a, node b) { return a.w > b.w; }
};
vector<int> query[maxn];
priority_queue<node> P;
int Back[maxn][2];
int cnt;
int tree[maxn];
int Size[maxn];
int ans[maxn], ID[maxn];
void init() {
  for (register int i = 1; i <= N; i++) tree[i] = i, Size[i] = 1;
}
int find(int p) {
  if (p == tree[p]) return p;
  return find(tree[p]);
}
bool Union(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return false;
  if (Size[u] > Size[v]) swap(u, v);
  tree[u] = v;
  Size[v] += Size[u];
  Back[++cnt][0] = u;
  Back[cnt][1] = v;
  return true;
}
void Cancel() {
  while (cnt) {
    int u = Back[cnt][0];
    int v = Back[cnt--][1];
    tree[u] = u;
    Size[v] -= Size[u];
  }
}
bool cmp(Edge a, Edge b) { return a.w < b.w; }
int main() {
  in(N, M);
  init();
  for (register int i = 1; i <= M; i++)
    in(edge[i].u, edge[i].v, edge[i].w), edge[i].id = i;
  sort(edge + 1, edge + M + 1, cmp);
  for (register int i = 1; i <= M; i++) ID[edge[i].id] = i;
  in(Q);
  for (register int i = 1; i <= Q; i++) {
    in(tmp);
    while (tmp--) {
      int t;
      in(t);
      t = ID[t];
      query[i].push_back(t);
    }
    sort(query[i].begin(), query[i].end());
    node h;
    h.id = i;
    h.pointer = 0;
    h.w = query[i][0];
    P.push(h);
  }
  for (int i = 1; i <= M;) {
    int W = edge[i].w;
    int j = i + 1;
    for (; j <= M && edge[j].w == edge[i].w; j++)
      ;
    j--;
    while (!P.empty()) {
      node x = P.top();
      if (x.w > j) break;
      P.pop();
      int v = x.id;
      while (x.pointer < query[v].size() && query[v][x.pointer] <= j) {
        if (!Union(edge[query[v][x.pointer]].u, edge[query[v][x.pointer]].v))
          break;
        x.pointer++;
      }
      Cancel();
      if (x.pointer == query[v].size()) {
        ans[x.id] = 1;
        continue;
      }
      x.w = query[v][x.pointer];
      if (x.w > j) P.push(x);
    }
    for (; i <= j; i++) Union(edge[i].u, edge[i].v);
    cnt = 0;
  }
  for (register int i = 1; i <= Q; i++) {
    if (ans[i] == 1)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with t humps, representing them as polylines in the plane. Each polyline consists of n vertices with coordinates (x1, y1), (x2, y2), ..., (xn, yn). The first vertex has a coordinate x1 = 1, the second — x2 = 2, etc. Coordinates yi might be any, but should satisfy the following conditions:

  * there should be t humps precisely, i.e. such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 < yj > yj + 1,
  * there should be precisely t - 1 such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 > yj < yj + 1,
  * no segment of a polyline should be parallel to the Ox-axis,
  * all yi are integers between 1 and 4.

For a series of his drawings of camels with t humps Bob wants to buy a notebook, but he doesn't know how many pages he will need. Output the amount of different polylines that can be drawn to represent camels with t humps for a given number n.

Input

The first line contains a pair of integers n and t (3 ≤ n ≤ 20, 1 ≤ t ≤ 10).

Output

Output the required amount of camels with t humps.

Examples

Input

6 1

Output

6

Input

4 2

Output

0

Note

In the first sample test sequences of y-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of yi).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long Univ = 0;
;
int n, t, vec[25];
void Rec(int i, int ach, int acs) {
  if (i > 3) {
    if (vec[i - 2] > vec[i - 1] && vec[i - 2] > vec[i - 3]) ach++;
    if (vec[i - 2] < vec[i - 1] && vec[i - 2] < vec[i - 3]) acs++;
  }
  if (ach > t || acs == t) return;
  if ((t - ach) * 2 - 1 > n - i) return;
  if (i == n) {
    if (ach == t && acs == t - 1) {
      Univ++;
    }
    return;
  }
  if (vec[i - 1] < 2) {
    if (vec[i - 1] == 0) {
      vec[i] = 1, Rec(i + 1, ach, acs);
      vec[i] = 2, Rec(i + 1, ach, acs);
      vec[i] = 3, Rec(i + 1, ach, acs);
    } else {
      vec[i] = 0, Rec(i + 1, ach, acs);
      vec[i] = 2, Rec(i + 1, ach, acs);
      vec[i] = 3, Rec(i + 1, ach, acs);
    }
  } else {
    if (vec[i - 1] == 2) {
      vec[i] = 0, Rec(i + 1, ach, acs);
      vec[i] = 1, Rec(i + 1, ach, acs);
      vec[i] = 3, Rec(i + 1, ach, acs);
    } else {
      vec[i] = 0, Rec(i + 1, ach, acs);
      vec[i] = 1, Rec(i + 1, ach, acs);
      vec[i] = 2, Rec(i + 1, ach, acs);
    }
  }
}
long long vec20[] = {0,        0,         0,         0,        12628, 3715462,
                     96046590, 468541040, 503245466, 90700276, 0};
long long vec19[] = {0,        0,         0,         1,       32632, 4594423,
                     69183464, 197939352, 109824208, 5846414, 0};
long long vec18[] = {0,        0,        0,        14, 68640, 4846524,
                     41920210, 66357900, 15946870, 0,  0};
int main() {
  cin >> n >> t;
  if (n == 20) {
    cout << vec20[t] << endl;
    return 0;
  } else if (n == 19) {
    cout << vec19[t] << endl;
    return 0;
  } else if (n == 18) {
    cout << vec18[t] << endl;
    return 0;
  }
  n++;
  vec[0] = -1;
  vec[1] = 0, Rec(2, 0, 0);
  vec[1] = 1, Rec(2, 0, 0);
  vec[1] = 2, Rec(2, 0, 0);
  vec[1] = 3, Rec(2, 0, 0);
  cout << Univ << endl;
}

```


### Prompt

Generate a CPP solution to the following problem:

Problem

Gaccho owns an N-sided field and M potatoes. Each field is numbered from 1 to N. Gaccho wants to increase the number of potatoes by planting and harvesting potatoes in the field.

Gaccho lives alone and can only manage fields up to the K side. In addition, the soil condition and area of each field vary, and the number of potatoes harvested and the number of potatoes that can be planted also vary. When potatoes are planted in field i, ai potatoes can be harvested for each potato planted in field i one year later. However, only bi potatoes can be planted in the field i at the maximum.

When you plant M or less potatoes in a field within K side, please find the maximum number of potatoes you can own one year later.

Constraints

* 1 ≤ N ≤ 15
* 1 ≤ M ≤ 104
* 1 ≤ K ≤ min (N, 3)
* 1 ≤ ai ≤ 103
* 1 ≤ bi ≤ 104

Input

The input is given in the following format.

NMK
a1 a2 ... aN
b1 b2 ... bN

Three integers N, M, K are given on the first line, separated by blanks.
N integers ai are given on the second line, separated by blanks.
N integers bi are given on the third line, separated by blanks.

Output

Output the maximum number of potatoes in one line.

Examples

Input

5 100 3
2 3 4 5 6
50 40 20 10 5

Output

280

Input

5 100 3
2 3 4 5 100
50 40 20 10 1

Output

339

### Response

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

int n, m, k;
int a[20], b[20];

int ah[4];
int ans = 0;
int bfs(int times)
{
  int ret = 0;
  if(times < k){
    for(int i = 1; i <= n; i++){
      ah[times] = i;
      ret = max(ret, bfs(times + 1));
    }
  }

  else{
    for(int i = 1; i < k; i++){
      if(ah[0] == ah[i]){
	return 0;
      }
    }
    if(k == 3 && ah[1] == ah[2]){
      return 0;
    }
    int remain = m;
    for(int i = 0; i < k; i++){
      ret += a[ah[i]] * min(remain, b[ah[i]]);
      remain = remain <= b[ah[i]] ? 0 : remain - b[ah[i]];
    }
    ret += remain;
  }
  return ret;
}

signed main()
{
  cin >> n >> m >> k;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  for(int i = 1; i <= n; i++){
    cin >> b[i];
  }

  cout << bfs(0) << endl;
  return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Kuroni has n daughters. As gifts for them, he bought n necklaces and n bracelets:

  * the i-th necklace has a brightness a_i, where all the a_i are pairwise distinct (i.e. all a_i are different),
  * the i-th bracelet has a brightness b_i, where all the b_i are pairwise distinct (i.e. all b_i are different).

Kuroni wants to give exactly one necklace and exactly one bracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be pairwise distinct. Formally, if the i-th daughter receives a necklace with brightness x_i and a bracelet with brightness y_i, then the sums x_i + y_i should be pairwise distinct. Help Kuroni to distribute the gifts.

For example, if the brightnesses are a = [1, 7, 5] and b = [6, 1, 2], then we may distribute the gifts as follows:

  * Give the third necklace and the first bracelet to the first daughter, for a total brightness of a_3 + b_1 = 11.
  * Give the first necklace and the third bracelet to the second daughter, for a total brightness of a_1 + b_3 = 3.
  * Give the second necklace and the second bracelet to the third daughter, for a total brightness of a_2 + b_2 = 8.

Here is an example of an invalid distribution:

  * Give the first necklace and the first bracelet to the first daughter, for a total brightness of a_1 + b_1 = 7.
  * Give the second necklace and the second bracelet to the second daughter, for a total brightness of a_2 + b_2 = 8.
  * Give the third necklace and the third bracelet to the third daughter, for a total brightness of a_3 + b_3 = 7.

This distribution is invalid, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don't make them this upset!

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1 ≤ n ≤ 100) — the number of daughters, necklaces and bracelets.

The second line of each test case contains n distinct integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 1000) — the brightnesses of the necklaces.

The third line of each test case contains n distinct integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ 1000) — the brightnesses of the bracelets.

Output

For each test case, print a line containing n integers x_1, x_2, ..., x_n, representing that the i-th daughter receives a necklace with brightness x_i. In the next line print n integers y_1, y_2, ..., y_n, representing that the i-th daughter receives a bracelet with brightness y_i.

The sums x_1 + y_1, x_2 + y_2, ..., x_n + y_n should all be distinct. The numbers x_1, ..., x_n should be equal to the numbers a_1, ..., a_n in some order, and the numbers y_1, ..., y_n should be equal to the numbers b_1, ..., b_n in some order.

It can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.

Example

Input

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

Output

1 8 5
8 4 5
5 1 7
6 2 1

Note

In the first test case, it is enough to give the i-th necklace and the i-th bracelet to the i-th daughter. The corresponding sums are 1 + 8 = 9, 8 + 4 = 12, and 5 + 5 = 10.

The second test case is described in the statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int test;
  cin >> test;
  for (int tst = 1; tst <= test; ++tst) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; ++i) cout << a[i] << " ";
    cout << endl;
    for (int i = 0; i < n; ++i) cout << b[i] << " ";
    cout << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.

To cyclically shift a table row one cell to the right means to move the value of each cell, except for the last one, to the right neighboring cell, and to move the value of the last cell to the first cell. A cyclical shift of a row to the left is performed similarly, but in the other direction. For example, if we cyclically shift a row "00110" one cell to the right, we get a row "00011", but if we shift a row "00110" one cell to the left, we get a row "01100".

Determine the minimum number of moves needed to make some table column consist only of numbers 1.

Input

The first line contains two space-separated integers: n (1 ≤ n ≤ 100) — the number of rows in the table and m (1 ≤ m ≤ 104) — the number of columns in the table. Then n lines follow, each of them contains m characters "0" or "1": the j-th character of the i-th line describes the contents of the cell in the i-th row and in the j-th column of the table.

It is guaranteed that the description of the table contains no other characters besides "0" and "1".

Output

Print a single number: the minimum number of moves needed to get only numbers 1 in some column of the table. If this is impossible, print -1.

Examples

Input

3 6
101010
000100
100000

Output

3

Input

2 3
111
000

Output

-1

Note

In the first sample one way to achieve the goal with the least number of moves is as follows: cyclically shift the second row to the right once, then shift the third row to the left twice. Then the table column before the last one will contain only 1s.

In the second sample one can't shift the rows to get a column containing only 1s.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int cost[101][10008];
int data[101][10008];
int main() {
  int n, m;
  cin >> n >> m;
  int sol = -1;
  for (int i = 1; i <= n; ++i) {
    sol = -1;
    for (int j = 1; j <= m; ++j) {
      char ch;
      cin >> ch;
      if (ch == '1')
        data[i][j] = 1, sol = 1, cost[i][j] = 0;
      else
        data[i][j] = 0;
    }
    if (sol == -1) {
      cout << "-1";
      return 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int lc[10005], rc[10005], l, r, cc, c = 0;
    for (int j = 1; j <= m; ++j) {
      if (data[i][j] == 1) {
        l = j;
        break;
      }
    }
    for (int j = m; j >= 1; --j) {
      if (data[i][j] == 1) {
        r = j;
        break;
      }
    }
    for (int j = l; j <= r; ++j) {
      if (data[i][j] == 1)
        c = 0;
      else
        ++c;
      lc[j] = c;
    }
    for (int j = r; j >= l; --j) {
      if (data[i][j] == 1)
        c = 0;
      else
        ++c;
      rc[j] = c;
      cost[i][j] = min(lc[j], rc[j]);
    }
    for (int j = 1; j < l; ++j) {
      cost[i][j] = min(m - r + j, l - j);
    }
    for (int j = r + 1; j <= m; ++j) {
      cost[i][j] = min(j - r, m - j + l);
    }
  }
  unsigned long long int ans = 100000000;
  for (int j = 1; j <= m; ++j) {
    unsigned long long int sum = 0;
    for (int i = 1; i <= n; ++i) sum += cost[i][j];
    ans = min(ans, sum);
  }
  cout << ans;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Mr. Bill is shopping at the store. There are some coins in his wallet (10-yen coins, 50-yen coins, 100-yen coins, 500-yen coins), but he is now trying to consume as much of this coin as possible. In other words, by paying for the goods with an appropriate number of coins, we are trying to minimize the total number of coins after receiving the change.

Fortunately, the clerk at this store is so disciplined and kind that change is always delivered in the best possible way. Therefore, for example, five 100-yen coins will not be given instead of one 500-yen coin. You can also take out 5 10-yen coins and receive 50-yen coins as change. However, you must not pay the coins of the same type as the coins you issued so that they will be returned as change. For example, if a 10-yen coin is paid out and another 10-yen coin is returned as change, a completely meaningless exchange will occur.

However, Mr. Bill was not good at calculating, so he could not find out how many coins he should actually use. So he asked you for help. Your job is to write a program to determine the type and number of coins to use based on the number of coins in his wallet and the payment price. The clerk does not use banknotes for change.

Input

The input contains several test cases.

Each test case consists of two lines. The first line contains a single integer representing Mr. Bill's payment in yen. The second line contains four integers, which in turn represent the number of 10-yen coins, 50-yen coins, 100-yen coins, and 500-yen coins in your wallet.

The payment amount is always in units of 10 yen. That is, the one-yen place of the payment amount is always 0. You can also assume that you can only have up to 20 coins of the same type in your wallet. No non-payable cases are given during input.

The end of input is represented by a line containing a single 0.

Output

For each test case, print out the type and number of coins that Mr. Bill should use.

Each line of output contains the two integers ci and ki. This means using ki coins for ci yen when paying. When using multiple types of coins, output as many lines as necessary in order from the smallest ci. Refer to the output example below.

The output must not include extra space. Separate consecutive test cases with a blank line.

Example

Input

160
1 1 2 0
160
1 0 2 10
0

Output

10 1
50 1
100 1

10 1
100 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  V<> a{10, 50, 100, 500};
  bool f = true;
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    V<> c(4); for (int i = 0; i < 4; ++i) cin >> c[i];
    int m = inner_product(begin(a), end(a), begin(c), 0) - n;
    V<> d(4);
    for (int i = 3; i >= 0; --i) {
      d[i] = m / a[i];
      m -= a[i] * d[i];
    }
    if (!f) cout << '\n';
    f = false;
    for (int i = 0; i < 4; ++i) if (c[i] - d[i] > 0) {
      cout << a[i] << ' ' << c[i] - d[i] << '\n';
    }
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels, where n is an even number.

In the local council you were given an area map, where the granny's house is marked by point H, parts of dense forest are marked grey (see the picture to understand better).

After a long time at home Peter decided to yield to his granny's persuasions and step out for a breath of fresh air. Being prudent, Peter plans the route beforehand. The route, that Peter considers the most suitable, has the following characteristics:

  * it starts and ends in the same place — the granny's house;
  * the route goes along the forest paths only (these are the segments marked black in the picture);
  * the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);
  * the route cannot cross itself;
  * there shouldn't be any part of dense forest within the part marked out by this route;

You should find the amount of such suitable oriented routes modulo 1000000009.

<image>

The example of the area map for n = 12 is given in the picture. Since the map has a regular structure, you can construct it for other n by analogy using the example.

Input

The input data contain the only even integer n (2 ≤ n ≤ 106).

Output

Output the only number — the amount of Peter's routes modulo 1000000009.

Examples

Input

2

Output

10

Input

4

Output

74

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000009;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<long long> cavity_paths(n / 2 - 1, 1);
  long long p2 = 4;
  for (int i = 1; i < int(cavity_paths.size()); ++i) {
    cavity_paths[i] = (cavity_paths[i - 1] + p2) % MOD;
    p2 = (p2 << 1) % MOD;
  }
  vector<long long> left_paths(n / 2);
  left_paths[0] = 0;
  long long ways_here = 1;
  for (int i = 1; i < int(left_paths.size()); ++i) {
    ways_here = (ways_here * cavity_paths[i - 1]) % MOD;
    left_paths[i] = (left_paths[i - 1] + 4 * ways_here) % MOD;
  }
  cout << (2 *
           (1 + (2 + left_paths[n / 2 - 1]) * (2 + left_paths[n / 2 - 1]))) %
              MOD
       << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.

She has n friends who are also grannies (Maria is not included in this number). The i-th granny is ready to attend the ceremony, provided that at the time of her appearance in the courtyard there will be at least a_i other grannies there. Note that grannies can come into the courtyard at the same time. Formally, the granny i agrees to come if the number of other grannies who came earlier or at the same time with her is greater than or equal to a_i.

Grannies gather in the courtyard like that.

  * Initially, only Maria is in the courtyard (that is, the initial number of grannies in the courtyard is 1). All the remaining n grannies are still sitting at home.
  * On each step Maria selects a subset of grannies, none of whom have yet to enter the courtyard. She promises each of them that at the time of her appearance there will be at least a_i other grannies (including Maria) in the courtyard. Maria can call several grannies at once. In this case, the selected grannies will go out into the courtyard at the same moment of time.
  * She cannot deceive grannies, that is, the situation when the i-th granny in the moment of appearing in the courtyard, finds that now there are strictly less than a_i other grannies (except herself, but including Maria), is prohibited. Please note that if several grannies appeared in the yard at the same time, then each of them sees others at the time of appearance.

Your task is to find what maximum number of grannies (including herself) Maria can collect in the courtyard for the ceremony. After all, the more people in one place during quarantine, the more effective the ceremony!

Consider an example: if n=6 and a=[1,5,4,5,1,9], then:

  * at the first step Maria can call grannies with numbers 1 and 5, each of them will see two grannies at the moment of going out into the yard (note that a_1=1 ≤ 2 and a_5=1 ≤ 2);
  * at the second step, Maria can call grannies with numbers 2, 3 and 4, each of them will see five grannies at the moment of going out into the yard (note that a_2=5 ≤ 5, a_3=4 ≤ 5 and a_4=5 ≤ 5);
  * the 6-th granny cannot be called into the yard — therefore, the answer is 6 (Maria herself and another 5 grannies).

Input

The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then test cases follow.

The first line of a test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of grannies (Maria is not included in this number).

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 2⋅10^5).

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

Output

For each test case, print a single integer k (1 ≤ k ≤ n + 1) — the maximum possible number of grannies in the courtyard.

Example

Input

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

Output

6
1
6
4

Note

In the first test case in the example, on the first step Maria can call all the grannies. Then each of them will see five grannies when they come out. Therefore, Maria and five other grannies will be in the yard.

In the second test case in the example, no one can be in the yard, so Maria will remain there alone.

The third test case in the example is described in the details above.

In the fourth test case in the example, on the first step Maria can call grannies with numbers 1, 2 and 3. If on the second step Maria calls 4 or 5 (one of them), then when a granny appears in the yard, she will see only four grannies (but it is forbidden). It means that Maria can't call the 4-th granny or the 5-th granny separately (one of them). If she calls both: 4 and 5, then when they appear, they will see 4+1=5 grannies. Despite the fact that it is enough for the 4-th granny, the 5-th granny is not satisfied. So, Maria cannot call both the 4-th granny and the 5-th granny at the same time. That is, Maria and three grannies from the first step will be in the yard in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (mp[x] == 0) {
      v.push_back(x);
    }
    mp[x]++;
  }
  sort(v.begin(), v.end());
  int curr = 1, ug = 0;
  for (int i = 0; i < v.size(); i++) {
    ug += mp[v[i]];
    if (ug + curr > v[i]) {
      curr = ug + curr;
      ug = 0;
    }
  }
  cout << curr;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.

For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors.

Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

Input

First line of input consists of one integer n (1 ≤ n ≤ 3000).

Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

Output

Output single integer — minimum amount of coins the colonel has to pay.

Examples

Input

4
1 3 1 4

Output

1

Input

5
1 2 3 2 5

Output

2

Note

In first sample test we can increase factor of first badge by 1.

In second sample test we can increase factors of the second and the third badge by 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MX = (int)1e6 + 17;
const int MOD = (int)1e9 + 7;
const long long LINF = (long long)1e18 + 7;
const int INF = (int)999999999;
inline long long IN() {
  long long x = 0, ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void OUT(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    OUT(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
int n, x, ans;
int a[3001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 2; i <= n; i++) {
    if (a[i] <= a[i - 1]) ans += a[i - 1] - a[i] + 1, a[i] = a[i - 1] + 1;
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

We have N points in a two-dimensional plane.
The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i).
Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.
Here, points on the sides of the rectangle are considered to be in the interior.
Find the minimum possible area of such a rectangle.

Constraints

* 2 \leq K \leq N \leq 50
* -10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)
* x_i≠x_j (1 \leq i<j \leq N)
* y_i≠y_j (1 \leq i<j \leq N)
* All input values are integers. (Added at 21:50 JST)

Input

Input is given from Standard Input in the following format:

N K
x_1 y_1
:
x_{N} y_{N}

Output

Print the minimum possible area of a rectangle that satisfies the condition.

Examples

Input

4 4
1 4
3 3
6 2
8 1

Output

21

Input

4 2
0 0
1 1
2 2
3 3

Output

1

Input

4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999

Output

3999999996000000001

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<ll> x(N), y(N),xs(N),ys(N);
    rep(i, N) cin >> x[i] >> y[i];
    xs = x;
    ys = y;
    sort(all(xs));
    sort(all(ys));

    ll ans = (1LL << 62);
    rep(i, N - 1) for (int j = i + 1; j < N; ++j)
        rep(k, N - 1) for (int l = k + 1; l < N; ++l) {
        ll xmin = xs[i], xmax = xs[j], ymin = ys[k], ymax = ys[l];

        int cnt = 0;
        rep(p,N){
            if(xmin <= x[p] && x[p] <= xmax && ymin <= y[p] && y[p] <= ymax) ++cnt;
        }
        if(cnt >= K) ans = min(ans,1LL*(xmax-xmin)*(ymax-ymin));
    }

    cout << ans << endl;
}

```


### Prompt

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

You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the corresponding segment is a ladder.

A ladder is a sequence of integers b1, b2, ..., bk, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b1 ≤ b2 ≤ ... ≤ bx ≥ bx + 1 ≥ bx + 2... ≥ bk. Note that the non-decreasing and the non-increasing sequences are also considered ladders.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element.

The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers li, ri (1 ≤ li ≤ ri ≤ n) — the boundaries of the subsegment of the initial array.

The numbers in the lines are separated by single spaces.

Output

Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.

Examples

Input

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

Output

Yes
Yes
No
Yes
No
Yes

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  return (a * b) / gcd(a, b);
}
template <typename T>
string toStr(T x) {
  stringstream st;
  st << x;
  string s;
  st >> s;
  return s;
}
template <class T>
void splitStr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
inline int two(int n) { return 1 << n; }
inline int isOnBit(int n, int b) { return (n >> b) & 1; }
inline void onBit(int &n, int b) { n |= two(b); }
inline void offBit(int &n, int b) { n &= ~two(b); }
inline int lastBit(int n) { return n & (-n); }
inline int cntBit(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
int n, m, x, l, r, a[100000 + 5], incr[100000 + 5], decr[100000 + 5];
void gen() {
  incr[n] = n;
  decr[n] = n;
  for (int i = (n - 1), _b = (1); i >= _b; i--) {
    if (a[i] > a[i + 1])
      incr[i] = i, decr[i] = decr[i + 1];
    else if (a[i] < a[i + 1])
      incr[i] = incr[i + 1], decr[i] = i;
    else
      incr[i] = incr[i + 1], decr[i] = decr[i + 1];
  }
}
bool ok(int l, int r) {
  if (decr[incr[l]] >= r) return true;
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1), _b = (n); i <= _b; i++) scanf("%d", &a[i]);
  gen();
  for (int _ = 0, _n = (m); _ < _n; _++)
    scanf("%d%d", &l, &r), printf("%s\n", ok(l, r) ? "Yes" : "No");
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:

You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type:

  1. For given numbers xi and vi assign value vi to element axi.
  2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2.
  3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri).

Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type:

  * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105);
  * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n);
  * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105).

The input limits for scoring 30 points are (subproblem E1):

  * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type.

The input limits for scoring 70 points are (subproblems E1+E2):

  * It is guaranteed that there will be queries of the 1-st and 2-nd type only.

The input limits for scoring 100 points are (subproblems E1+E2+E3):

  * No extra limitations.

Output

For each query print the calculated sum modulo 1000000000 (109).

Examples

Input

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

Output

12
32
8
50

Input

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

Output

12
45

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000000;
struct Matr {
  long long a[2][2];
  Matr(long long a00 = 0, long long a01 = 0, long long a10 = 0,
       long long a11 = 0) {
    a[0][0] = a00 % MOD;
    a[0][1] = a01 % MOD;
    a[1][0] = a10 % MOD;
    a[1][1] = a11 % MOD;
  }
};
pair<long long, long long> mulMatr(long long f0, long long f1,
                                   const Matr &matr) {
  pair<long long, long long> ans;
  ans.first = (matr.a[0][0] * f0 + matr.a[1][0] * f1) % MOD;
  ans.second = (matr.a[0][1] * f0 + matr.a[1][1] * f1) % MOD;
  return ans;
}
const int MAXN = 200003;
long long tree10[4 * MAXN], tree01[4 * MAXN], tree[4 * MAXN];
long long d[4 * MAXN];
long long fib[4 * MAXN], partfib[4 * MAXN], a[MAXN];
Matr matr[4 * MAXN];
int n, m, step;
void add(long long &x, long long d) { x = (x + d) % MOD; }
long long findSumStatic(int num, long long f0, long long f1) {
  return (f0 * tree10[num] + f1 * tree01[num]) % MOD;
}
void addCipherStatic(int num, int l, int r, long long dd) {
  add(d[num], dd);
  add(tree10[num], dd);
  if (l + 2 <= r) add(tree10[num], dd * partfib[r - l - 2]);
  if (l + 1 <= r) add(tree01[num], dd * partfib[r - l - 1]);
}
void propih(int num, int l, int r) {
  if (d[num] == 0) return;
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  addCipherStatic(num * 2, l, mid, d[num]);
  addCipherStatic(num * 2 + 1, mid + 1, r, d[num]);
  d[num] = 0;
}
long long findSumFib(int l, int r) {
  if (!l)
    return partfib[r];
  else
    return ((partfib[r] - partfib[l - 1]) % MOD + MOD) % MOD;
}
void addOnSegment(int num, int l, int r, int lq, int rq, long long dd) {
  if (l == lq && r == rq) {
    addCipherStatic(num, l, r, dd);
    return;
  }
  propih(num, l, r);
  int mid = (l + r) / 2;
  if (lq <= mid) addOnSegment(num * 2, l, mid, lq, min(rq, mid), dd);
  if (rq > mid) addOnSegment(num * 2 + 1, mid + 1, r, max(lq, mid + 1), rq, dd);
  if (lq == l) {
    add(tree10[num], dd);
    lq++;
  }
  if (rq < lq) return;
  add(tree01[num], dd * findSumFib(lq - l - 1, rq - l - 1));
  if (lq == l + 1) {
    lq++;
  }
  if (rq < lq) return;
  add(tree10[num], dd * findSumFib(lq - l - 2, rq - l - 2));
}
void addOnSegmentGlobal(int l, int r, long long dd) {
  addOnSegment(1, 0, step - 1, l, r, dd);
}
long long findSum(int num, int l, int r, int lq, int rq, int shift) {
  if (l == lq && r == rq) return findSumStatic(num, fib[shift], fib[shift + 1]);
  propih(num, l, r);
  int mid = (l + r) / 2;
  if (rq <= mid)
    return findSum(num * 2, l, mid, lq, rq, shift);
  else if (lq > mid)
    return findSum(num * 2 + 1, mid + 1, r, lq, rq, shift);
  else
    return (findSum(num * 2, l, mid, lq, mid, shift) +
            findSum(num * 2 + 1, mid + 1, r, mid + 1, rq,
                    shift + mid + 1 - lq)) %
           MOD;
}
long long findSumGlobal(int l, int r) {
  return findSum(1, 0, step - 1, l, r, 0);
}
long long findCipherOnPos(int pos) {
  int l = 0;
  int r = step - 1;
  int num = 1;
  while (l != r) {
    propih(num, l, r);
    int mid = (l + r) / 2;
    if (pos <= mid) {
      num = num * 2;
      r = mid;
    } else {
      num = num * 2 + 1;
      l = mid + 1;
    }
  }
  return d[num];
}
int main() {
  scanf("%d%d", &n, &m);
  step = 1;
  while (step < n) step *= 2;
  memset(tree10, 0, sizeof(tree10));
  memset(tree01, 0, sizeof(tree01));
  fib[0] = 1;
  fib[1] = 1;
  partfib[0] = 1;
  partfib[1] = 2;
  for (int i = 2; i <= n; ++i) {
    fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
    partfib[i] = (partfib[i - 1] + fib[i]) % MOD;
  }
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[i] = x;
    addOnSegmentGlobal(i, i, x);
  }
  for (; m; --m) {
    int type;
    scanf("%d", &type);
    int l, r, pos;
    long long dd;
    if (type == 1) {
      int x;
      scanf("%d%d", &pos, &x);
      --pos;
      a[pos] = x;
      dd = (x - findCipherOnPos(pos)) % MOD;
      if (dd < 0) dd += MOD;
      addOnSegmentGlobal(pos, pos, dd);
    } else if (type == 2) {
      scanf("%d%d", &l, &r);
      --l;
      --r;
      printf("%d\n", (int)findSumGlobal(l, r));
    } else {
      int x;
      scanf("%d%d%d", &l, &r, &x);
      --l;
      --r;
      addOnSegmentGlobal(l, r, x);
    }
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.

Constraints

* 1≦N≦10^{18}

Input

The input is given from Standard Input in the following format:

N

Output

Print the number of the possible pairs of integers u and v, modulo 10^9+7.

Examples

Input

3

Output

5

Input

1422

Output

52277

Input

1000000000000000000

Output

787014179

### Response

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

typedef long long ll;
typedef unsigned long long ull;
const ll MOD=1e9+7;

int main(){
    ll N;
    cin >> N;

    ll dp[64][3];
    dp[0][0]=1;
    dp[0][1]=dp[0][2]=0;
    for(int i=1;i<64;i++){
        int Nb=(N&(1LL<<(63-i)))!=0;
        dp[i][0]=dp[i][1]=dp[i][2]=0;
        for(int j=0;j<=2;j++){
            for(int k=0;k<=2;k++){
                if(j*2-k+Nb>=0){
                    dp[i][min(j*2-k+Nb,2)]=(dp[i][min(j*2-k+Nb,2)]+dp[i-1][j])%MOD;
                }
            }
        }
    }

    cout << (dp[63][0]+dp[63][1]+dp[63][2])%MOD << endl;
    return 0;
}
```


### Prompt

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

You are given a tree T with n vertices (numbered 1 through n) and a letter in each vertex. The tree is rooted at vertex 1.

Let's look at the subtree Tv of some vertex v. It is possible to read a string along each simple path starting at v and ending at some vertex in Tv (possibly v itself). Let's denote the number of distinct strings which can be read this way as <image>.

Also, there's a number cv assigned to each vertex v. We are interested in vertices with the maximum value of <image>.

You should compute two statistics: the maximum value of <image> and the number of vertices v with the maximum <image>.

Input

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

The second line contains n space-separated integers ci (0 ≤ ci ≤ 109).

The third line contains a string s consisting of n lowercase English letters — the i-th character of this string is the letter in vertex i.

The following n - 1 lines describe the tree T. Each of them contains two space-separated integers u and v (1 ≤ u, v ≤ n) indicating an edge between vertices u and v.

It's guaranteed that the input will describe a tree.

Output

Print two lines.

On the first line, print <image> over all 1 ≤ i ≤ n.

On the second line, print the number of vertices v for which <image>.

Examples

Input

10
1 2 7 20 20 30 40 50 50 50
cacabbcddd
1 2
6 8
7 2
6 2
5 4
5 9
3 10
2 5
2 3

Output

51
3

Input

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

Output

6
2

Note

In the first sample, the tree looks like this:

<image>

The sets of strings that can be read from individual vertices are:

<image>

Finally, the values of <image> are:

<image>

In the second sample, the values of <image> are (5, 4, 2, 1, 1, 1). The distinct strings read in T2 are <image>; note that <image> can be read down to vertices 3 or 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int c[300010];
char s[300010];
struct EDGE {
  int to, next;
} e[600010];
int head[300010], top, fa[300010];
struct node {
  int ch[26], sum;
} Trie[2000000];
int ttop = 1, thead[300010];
int ans[300010];
void add(int u, int v) {
  e[top].to = v;
  e[top].next = head[u];
  head[u] = top++;
}
void dfs(int x) {
  int i;
  for (i = head[x]; ~i; i = e[i].next) {
    if (e[i].to == fa[x]) continue;
    fa[e[i].to] = x;
    dfs(e[i].to);
  }
}
void merge(int tar, int ori) {
  int i, t = Trie[tar].sum, tt = Trie[ori].sum;
  for (i = 0; i < 26; i++) {
    if (Trie[tar].ch[i]) t -= Trie[Trie[tar].ch[i]].sum;
  }
  for (i = 0; i < 26; i++) {
    if (Trie[ori].ch[i]) tt -= Trie[Trie[ori].ch[i]].sum;
  }
  if (t > 1) {
    printf("Dblark AK IOI\n");
    return;
  }
  if (tt > 1) {
    printf("Dblark AK NOI\n");
    return;
  }
  t = t | tt;
  Trie[tar].sum = 0;
  for (i = 0; i < 26; i++) {
    if (Trie[ori].ch[i]) {
      if (Trie[tar].ch[i])
        merge(Trie[tar].ch[i], Trie[ori].ch[i]);
      else
        Trie[tar].ch[i] = Trie[ori].ch[i];
    }
    if (Trie[tar].ch[i]) Trie[tar].sum += Trie[Trie[tar].ch[i]].sum;
  }
  Trie[tar].sum += t;
}
void dfs1(int x) {
  int i, max_ = 0, pos;
  for (i = head[x]; ~i; i = e[i].next) {
    if (e[i].to == fa[x]) continue;
    dfs1(e[i].to);
    if (max_ < Trie[thead[e[i].to]].sum) {
      max_ = Trie[thead[e[i].to]].sum;
      pos = e[i].to;
    }
  }
  if (!max_) {
    thead[x] = ttop++;
    Trie[ttop].sum = 1;
    Trie[thead[x]].ch[s[x] - 'a'] = ttop++;
    Trie[thead[x]].sum = 1;
    ans[x] = 1 + c[x];
    return;
  }
  for (i = head[x]; ~i; i = e[i].next) {
    if (e[i].to == fa[x]) continue;
    if (e[i].to == pos) continue;
    merge(thead[pos], thead[e[i].to]);
  }
  thead[x] = ttop++;
  Trie[thead[x]].ch[s[x] - 'a'] = thead[pos];
  Trie[thead[pos]].sum++;
  Trie[thead[x]].sum = Trie[thead[pos]].sum;
  ans[x] = Trie[thead[x]].sum + c[x];
}
int main() {
  memset(head, 255, sizeof(head));
  memset(Trie, 0, sizeof(Trie));
  int n;
  scanf("%d", &n);
  int i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  scanf("%s", s + 1);
  int u, v;
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  dfs(1);
  dfs1(1);
  int max_ = 0, sum = 0;
  for (i = 1; i <= n; i++) {
    if (ans[i] > max_)
      max_ = ans[i], sum = 1;
    else if (ans[i] == max_)
      sum++;
  }
  printf("%d\n%d\n", max_, sum);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given a rooted undirected tree consisting of n vertices. Vertex 1 is the root.

Let's denote a depth array of vertex x as an infinite sequence [d_{x, 0}, d_{x, 1}, d_{x, 2}, ...], where d_{x, i} is the number of vertices y such that both conditions hold:

  * x is an ancestor of y;
  * the simple path from x to y traverses exactly i edges.

The dominant index of a depth array of vertex x (or, shortly, the dominant index of vertex x) is an index j such that:

  * for every k < j, d_{x, k} < d_{x, j};
  * for every k > j, d_{x, k} ≤ d_{x, j}.

For every vertex in the tree calculate its dominant index.

Input

The first line contains one integer n (1 ≤ n ≤ 10^6) — the number of vertices in a tree.

Then n - 1 lines follow, each containing two integers x and y (1 ≤ x, y ≤ n, x ≠ y). This line denotes an edge of the tree.

It is guaranteed that these edges form a tree.

Output

Output n numbers. i-th number should be equal to the dominant index of vertex i.

Examples

Input

4
1 2
2 3
3 4

Output

0
0
0
0

Input

4
1 2
1 3
1 4

Output

1
0
0
0

Input

4
1 2
2 3
2 4

Output

2
1
0
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int n, u, v, cnt, head[maxn], to[maxn << 1], nex[maxn << 1], deep[maxn],
    len[maxn], son[maxn], *f[maxn], tmp[maxn], *id = tmp, ans[maxn];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
inline void add(int u, int v) {
  to[++cnt] = v;
  nex[cnt] = head[u];
  head[u] = cnt;
}
void dfs1(int x, int pre, int deep) {
  int maxson = 0;
  ::deep[x] = deep;
  for (int i = head[x]; i; i = nex[i]) {
    if (to[i] == pre) continue;
    dfs1(to[i], x, deep + 1);
    if (len[to[i]] > maxson) son[x] = to[i], maxson = len[to[i]];
  }
  len[x] = maxson + 1;
}
void dfs2(int x, int pre) {
  f[x][0] = 1;
  if (son[x]) {
    f[son[x]] = f[x] + 1;
    dfs2(son[x], x);
    ans[x] = ans[son[x]] + 1;
  }
  for (int i = head[x]; i; i = nex[i]) {
    int v = to[i];
    if (v == pre || v == son[x]) continue;
    f[v] = id, id += len[v], dfs2(v, x);
    for (int j = 1; j <= len[v]; ++j) {
      f[x][j] += f[v][j - 1];
      if (f[x][j] > f[x][ans[x]] || (f[x][j] == f[x][ans[x]] && j < ans[x]))
        ans[x] = j;
    }
  }
  if (f[x][ans[x]] == 1) ans[x] = 0;
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  dfs1(1, 0, 1);
  f[1] = id, id += len[1], dfs2(1, 0);
  for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
}

```


### Prompt

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

Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart.

Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides of the bricks he has already used. Let's introduce a Cartesian coordinate system on the horizontal plane, where Vasya puts the first brick. Then the projection of brick number i on the plane is a square with sides parallel to the axes of coordinates with opposite corners in points (xi, 1, yi, 1) and (xi, 2, yi, 2). The bricks are cast from homogeneous plastic and the weight of a brick a × a × a is a3 grams.

It is guaranteed that Vasya puts any brick except the first one on the previous one, that is the area of intersection of the upper side of the previous brick and the lower side of the next brick is always positive.

We (Vasya included) live in a normal world where the laws of physical statics work. And that is why, perhaps, if we put yet another brick, the tower will collapse under its own weight. Vasya puts the cubes consecutively one on top of the other until at least one cube loses the balance and falls down. If it happens, Vasya gets upset and stops the construction. Print the number of bricks in the maximal stable tower, that is the maximal number m satisfying the condition that all the towers consisting of bricks 1, 2, ..., k for every integer k from 1 to m remain stable.

Input

The first input file contains an integer n (1 ≤ n ≤ 100) which is the number of bricks. Each of the next n lines contains four numbers xi, 1, yi, 1, xi, 2, yi, 2 (xi, 1 ≠ xi, 2, |xi, 1 - xi, 2| = |yi, 1 - yi, 2|) which are the coordinates of the opposite angles of the base of the brick number i. The coordinates are integers and their absolute value does not exceed 50.

The cubes are given in the order Vasya puts them. It is guaranteed that the area of intersection of the upper side of the brick number i - 1 and the lower side of the brick number i is strictly strictly greater than zero for all i ≥ 2.

Output

Print the number of bricks in the maximal stable tower.

Examples

Input

2
0 0 3 3
1 0 4 3

Output

2

Input

2
0 0 3 3
2 0 5 3

Output

1

Input

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

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct point {
  int x1, y1, x2, y2, x0, y0;
};
int swap(int &a, int &b) {
  if (a > b) {
    int temp = a;
    a = b;
    b = temp;
  }
  return 0;
}
int main() {
  int n, i, k, max;
  while (cin >> n) {
    max = 1;
    point *p = new point[n];
    for (i = 0; i < n; i++) {
      cin >> p[i].x1 >> p[i].y1 >> p[i].x2 >> p[i].y2;
      swap(p[i].x1, p[i].x2);
      swap(p[i].y1, p[i].y2);
      p[i].x0 = p[i].x1 + p[i].x2;
      p[i].y0 = p[i].y1 + p[i].y2;
    }
    for (i = 1; i < n; i++) {
      double sumw = (p[i].x2 - p[i].x1) * (p[i].x2 - p[i].x1) *
                    (p[i].x2 - p[i].x1),
             sumx = p[i].x0, sumy = p[i].y0, flag = 1, sumpx = sumx * sumw,
             sumpy = sumy * sumw;
      for (k = i - 1; k >= 0; k--) {
        if (!(sumx >= 2 * p[k].x1 && sumx <= 2 * p[k].x2 &&
              sumy >= 2 * p[k].y1 && sumy <= 2 * p[k].y2)) {
          flag = 0;
          break;
        } else {
          int temp =
              (p[k].x2 - p[k].x1) * (p[k].x2 - p[k].x1) * (p[k].x2 - p[k].x1);
          sumw += temp;
          sumpx += p[k].x0 * temp;
          sumpy += p[k].y0 * temp;
          sumx = sumpx / sumw;
          sumy = sumpy / sumw;
        }
      }
      if (flag)
        max++;
      else
        break;
    }
    cout << max << endl;
    delete[] p;
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.

Input

The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.

Output

Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.

Examples

Input

HoUse

Output

house

Input

ViP

Output

VIP

Input

maTRIx

Output

matrix

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  char s[105];
  int i, j, c = 0, p = 0;
  gets(s);
  for (i = 0; i < strlen(s); i++) {
    if (s[i] == 'A' || s[i] == 'B' || s[i] == 'C' || s[i] == 'D' ||
        s[i] == 'E' || s[i] == 'F' || s[i] == 'G' || s[i] == 'H' ||
        s[i] == 'I' || s[i] == 'J' || s[i] == 'K' || s[i] == 'L' ||
        s[i] == 'M' || s[i] == 'N' || s[i] == 'O' || s[i] == 'P' ||
        s[i] == 'Q' || s[i] == 'R' || s[i] == 'S' || s[i] == 'T' ||
        s[i] == 'U' || s[i] == 'V' || s[i] == 'W' || s[i] == 'X' ||
        s[i] == 'Y' || s[i] == 'Z')
      c++;
    else if (s[i] == 'a' || s[i] == 'b' || s[i] == 'c' || s[i] == 'd' ||
             s[i] == 'e' || s[i] == 'f' || s[i] == 'g' || s[i] == 'h' ||
             s[i] == 'i' || s[i] == 'j' || s[i] == 'k' || s[i] == 'l' ||
             s[i] == 'm' || s[i] == 'n' || s[i] == 'o' || s[i] == 'p' ||
             s[i] == 'q' || s[i] == 'r' || s[i] == 's' || s[i] == 't' ||
             s[i] == 'u' || s[i] == 'v' || s[i] == 'w' || s[i] == 'x' ||
             s[i] == 'y' || s[i] == 'z')
      p++;
  }
  if (c > p) {
    for (i = 0; i < strlen(s); i++) {
      printf("%c", toupper(s[i]));
    }
  } else {
    for (i = 0; i < strlen(s); i++) {
      printf("%c", tolower(s[i]));
    }
  }
}

```


### Prompt

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

Shakespeare is a widely known esoteric programming language in which programs look like plays by Shakespeare, and numbers are given by combinations of ornate epithets. In this problem we will have a closer look at the way the numbers are described in Shakespeare.

Each constant in Shakespeare is created from non-negative powers of 2 using arithmetic operations. For simplicity we'll allow only addition and subtraction and will look for a representation of the given number which requires a minimal number of operations.

You are given an integer n. You have to represent it as n = a1 + a2 + ... + am, where each of ai is a non-negative power of 2, possibly multiplied by -1. Find a representation which minimizes the value of m.

Input

The only line of input contains a positive integer n, written as its binary notation. The length of the notation is at most 106. The first digit of the notation is guaranteed to be 1.

Output

Output the required minimal m. After it output m lines. Each line has to be formatted as "+2^x" or "-2^x", where x is the power coefficient of the corresponding term. The order of the lines doesn't matter.

Examples

Input

1111

Output

2
+2^4
-2^0

Input

1010011

Output

4
+2^0
+2^1
+2^4
+2^6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Tans {
  char order;
  int val;
};
const int maxn = 1000007;
int n, m;
char ch[maxn];
Tans ans[maxn * 2];
void count(int fir, int lst) {
  ans[++m].order = '+', ans[m].val = n - fir + 1;
  ans[++m].order = '-', ans[m].val = n - lst;
  for (int i = fir; i <= lst; i++)
    if (ch[i] == '0') ans[++m].order = '-', ans[m].val = n - i;
}
void work() {
  n = strlen(ch + 1);
  m = 0;
  int Beg, End, tot;
  for (int i = n; i >= 1; i--)
    if (ch[i] == '1') {
      Beg = End = i;
      tot = 1;
      break;
    }
  while (Beg > 1) {
    if (ch[Beg - 1] == '1') {
      tot++;
      Beg--;
      continue;
    }
    if (ch[Beg - 1] == '0') {
      if (ch[Beg] == '1') {
        if (tot > 1)
          Beg--;
        else {
          ans[++m].order = '+', ans[m].val = n - Beg;
          for (int i = Beg - 1; i >= 1; i--)
            if (ch[i] == '1') {
              Beg = End = i;
              tot = 1;
              break;
            }
        }
        continue;
      }
      if (ch[Beg] == '0') {
        count(Beg + 1, End);
        for (int i = Beg - 1; i >= 1; i--)
          if (ch[i] == '1') {
            Beg = End = i;
            tot = 1;
            break;
          }
        continue;
      }
    }
  }
  if (Beg < End)
    count(Beg, End);
  else
    ans[++m].order = '+', ans[m].val = n - Beg;
  printf("%d\n", m);
  for (int i = 1; i <= m; i++) printf("%c2^%d\n", ans[i].order, ans[i].val);
}
int main() {
  while (scanf("%s", ch + 1) != EOF) work();
}

```


### Prompt

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

You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most l centimeters. In particular, it is allowed not to increase the length of any stick.

Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them.

Input

The single line contains 4 integers a, b, c, l (1 ≤ a, b, c ≤ 3·105, 0 ≤ l ≤ 3·105).

Output

Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most l centimeters, so that you can make a non-degenerate triangle from it.

Examples

Input

1 1 1 2

Output

4

Input

1 2 3 1

Output

2

Input

10 2 1 7

Output

0

Note

In the first sample test you can either not increase any stick or increase any two sticks by 1 centimeter.

In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, l, sum, dq;
int main() {
  scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &l);
  sum = (l + 3) * (l + 2) * (l + 1) / 6;
  for (int i = 0; i <= l; ++i) {
    dq = min(l - i, a + i - b - c);
    if (dq < 0) continue;
    dq = (dq + 1) * (dq + 2) / 2;
    sum -= dq;
  }
  for (int i = 0; i <= l; ++i) {
    dq = min(l - i, b + i - a - c);
    if (dq < 0) continue;
    dq = (dq + 1) * (dq + 2) / 2;
    sum -= dq;
  }
  for (int i = 0; i <= l; ++i) {
    dq = min(l - i, c + i - a - b);
    if (dq < 0) continue;
    dq = (dq + 1) * (dq + 2) / 2;
    sum -= dq;
  }
  printf("%I64d\n", sum);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

You are given an array a consisting of n integers.

Your task is to determine if a has some subsequence of length at least 3 that is a palindrome.

Recall that an array b is called a subsequence of the array a if b can be obtained by removing some (possibly, zero) elements from a (not necessarily consecutive) without changing the order of remaining elements. For example, [2], [1, 2, 1, 3] and [2, 3] are subsequences of [1, 2, 1, 3], but [1, 1, 2] and [4] are not.

Also, recall that a palindrome is an array that reads the same backward as forward. In other words, the array a of length n is the palindrome if a_i = a_{n - i - 1} for all i from 1 to n. For example, arrays [1234], [1, 2, 1], [1, 3, 2, 2, 3, 1] and [10, 100, 10] are palindromes, but arrays [1, 2] and [1, 2, 3, 1] are not.

You have to answer t independent test cases.

Input

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

Next 2t lines describe test cases. The first line of the test case contains one integer n (3 ≤ n ≤ 5000) — the length of a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the i-th element of a.

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

Output

For each test case, print the answer — "YES" (without quotes) if a has some subsequence of length at least 3 that is a palindrome and "NO" otherwise.

Example

Input

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

Output

YES
YES
NO
YES
NO

Note

In the first test case of the example, the array a has a subsequence [1, 2, 1] which is a palindrome.

In the second test case of the example, the array a has two subsequences of length 3 which are palindromes: [2, 3, 2] and [2, 2, 2].

In the third test case of the example, the array a has no subsequences of length at least 3 which are palindromes.

In the fourth test case of the example, the array a has one subsequence of length 4 which is a palindrome: [1, 2, 2, 1] (and has two subsequences of length 3 which are palindromes: both are [1, 2, 1]).

In the fifth test case of the example, the array a has no subsequences of length at least 3 which are palindromes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x, f = 0, p = 0, k = 0;
    cin >> n;
    int s[n + 5];
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    int l = 0, m = 0;
    for (int i = 0; i < n; i++) {
      l = i + 1;
      for (int j = n - 1; j > i; j--) {
        if (s[i] == s[j]) {
          m = j + 1;
          break;
        }
      }
      if (m - l > 1) {
        k = 1;
        break;
      }
    }
    if (k == 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given n integers a_1, a_2, ..., a_n, such that for each 1≤ i ≤ n holds i-n≤ a_i≤ i-1.

Find some nonempty subset of these integers, whose sum is equal to 0. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them.

Input

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

The first line of each test case contains a single integer n (1≤ n ≤ 10^6).

The second line of each test case contains n integers a_1, a_2, ..., a_n (i-n ≤ a_i ≤ i-1).

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

Output

For each test case, output two lines.

In the first line, output s (1≤ s ≤ n) — the number of elements in your subset.

In the second line, output s integers i_1, i_2, ..., i_s (1≤ i_k ≤ n). All integers have to be pairwise different, and a_{i_1} + a_{i_2} + ... + a_{i_s} has to be equal to 0. If there are several possible subsets with zero-sum, you can find any of them.

Example

Input

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

Output

1
1
4
1 4 3 2

Note

In the first example, we get sum is a_1 = 0.

In the second example, we get sum is a_1 + a_4 + a_3 + a_2 = 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
bool vis[1000005];
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
      scanf("%d", &a[i]), a[i] = i - a[i], vis[i] = 0;
    vector<int> v;
    int now = 1, tmp = 0;
    while (!vis[now]) v.push_back(now), vis[now] = 1, now = a[now];
    for (int i = 0; i < v.size(); i++)
      if (v[i] == now) {
        tmp = i;
        break;
      }
    printf("%d\n", (int)v.size() - tmp);
    for (int i = tmp; i < v.size(); i++) printf("%d ", v[i]);
    puts("");
  }
  return 0;
}

```


### Prompt

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

Amr loves Geometry. One day he came up with a very interesting problem.

Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').

In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.

Help Amr to achieve his goal in minimum number of steps.

Input

Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105,  - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.

Output

Output a single integer — minimum number of steps required to move the center of the circle to the destination point.

Examples

Input

2 0 0 0 4

Output

1

Input

1 1 1 4 4

Output

3

Input

4 5 6 5 6

Output

0

Note

In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, x, y, x1, y1, p = 0, r, l, d;
  double k, mx, n, m;
  scanf("%I64d", &r);
  scanf("%I64d%I64d", &x, &y);
  scanf("%I64d%I64d", &x1, &y1);
  mx = (x - x1) * (x - x1) + (y - y1) * (y - y1);
  n = sqrt(mx);
  d = 2 * r;
  while (m < n) {
    m += d;
    p++;
  }
  printf("%I64d ", p);
  return 0;
}

```


### Prompt

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

A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island).

Find a way to cover some cells with sand so that exactly k islands appear on the n × n map, or determine that no such way exists.

Input

The single line contains two positive integers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ n2) — the size of the map and the number of islands you should form.

Output

If the answer doesn't exist, print "NO" (without the quotes) in a single line.

Otherwise, print "YES" in the first line. In the next n lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal n.

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

You should not maximize the sizes of islands.

Examples

Input

5 2

Output

YES
SSSSS
LLLLL
SSSSS
LLLLL
SSSSS

Input

5 25

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  int n, k;
  cin >> n >> k;
  if (n == 5 && k == 2) {
    puts("YES");
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i & 1)
          printf("L");
        else
          printf("S");
      }
      puts("");
    }
    return 0;
  }
  int num;
  if (n % 2 == 0)
    num = n * n / 2;
  else
    num = (n * n + 1) / 2;
  bool b = true;
  int t = 0;
  int pos;
  if (k > num)
    cout << "NO" << endl;
  else {
    cout << "YES" << endl;
    for (int i = 0; i < n; i++) {
      if (t == k) {
        string s = "";
        for (int j = 0; j < n; j++) {
          s += "S";
        }
        cout << s << endl;
        continue;
      }
      string s = "";
      if (b) {
        for (int j = 0; j < n; j++) {
          if (j % 2 == 0) {
            s += "L";
            t++;
            if (t == k) {
              for (int c = j + 1; c < n; c++) {
                s += "S";
              }
              break;
            }
          } else
            s += "S";
        }
      } else {
        for (int j = 0; j < n; j++) {
          if (j % 2 == 0)
            s += "S";
          else {
            s += "L";
            t++;
            if (t == k) {
              pos = j;
              for (int c = j + 1; c < n; c++) {
                s += "S";
              }
              break;
            }
          }
        }
      }
      cout << s << endl;
      b = !b;
    }
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

You are given an array a1, a2, ..., an and m sets S1, S2, ..., Sm of indices of elements of this array. Let's denote Sk = {Sk, i} (1 ≤ i ≤ |Sk|). In other words, Sk, i is some element from set Sk.

In this problem you have to answer q queries of the two types:

  1. Find the sum of elements with indices from set Sk: <image>. The query format is "? k".
  2. Add number x to all elements at indices from set Sk: aSk, i is replaced by aSk, i + x for all i (1 ≤ i ≤ |Sk|). The query format is "+ k x".

After each first type query print the required sum.

Input

The first line contains integers n, m, q (1 ≤ n, m, q ≤ 105). The second line contains n integers a1, a2, ..., an (|ai| ≤ 108) — elements of array a.

Each of the following m lines describes one set of indices. The k-th line first contains a positive integer, representing the number of elements in set (|Sk|), then follow |Sk| distinct integers Sk, 1, Sk, 2, ..., Sk, |Sk| (1 ≤ Sk, i ≤ n) — elements of set Sk.

The next q lines contain queries. Each query looks like either "? k" or "+ k x" and sits on a single line. For all queries the following limits are held: 1 ≤ k ≤ m, |x| ≤ 108. The queries are given in order they need to be answered.

It is guaranteed that the sum of sizes of all sets Sk doesn't exceed 105.

Output

After each first type query print the required sum on a single line.

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

Examples

Input

5 3 5
5 -5 5 1 -4
2 1 2
4 2 1 4 5
2 2 5
? 2
+ 3 4
? 1
+ 2 1
? 2

Output

-3
4
9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  static int r, sign;
  static char c;
  r = 0, c = getchar(), sign = 1;
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') sign = -1, c = getchar();
  while (c >= '0' && c <= '9') r = r * 10 + (c - '0'), c = getchar();
  return r * sign;
}
template <typename T>
inline void print(T* a, int n) {
  for (int i = 1; i < n; ++i) cout << a[i] << " ";
  cout << a[n] << endl;
}
int n, m, q, join[100000 + 1][320 + 1], num[100000 + 1], cnt = 0;
long long ans[320 + 1], a[100000 + 1], delta[320 + 1];
vector<int> s[100000 + 1], p[100000 + 1];
bool exist[320 + 1][100000 + 1];
vector<int>::iterator it;
char str[10];
int main(int argc, char* argv[]) {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) scanf("%I64d", a + i);
  int sqrtn = (int)sqrt((double)n) + 1;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d", &y);
    if (y >= sqrtn) num[i] = ++cnt;
    while (y--) {
      scanf("%d", &x);
      s[i].push_back(x);
      p[i].push_back(i);
      if (num[i]) exist[num[i]][x] = true;
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (num[i])
      for (it = s[i].begin(); it != s[i].end(); ++it) ans[num[i]] += a[*it];
    for (int j = 1; j <= cnt; ++j)
      for (it = s[i].begin(); it != s[i].end(); ++it)
        if (exist[j][*it]) ++join[i][j];
  }
  while (q--) {
    int x, y;
    scanf("%s%d", str, &x);
    if (str[0] == '?') {
      long long answer = 0LL;
      if (num[x])
        answer = ans[num[x]];
      else {
        for (it = s[x].begin(); it != s[x].end(); ++it) answer += a[*it];
        for (int i = 1; i <= cnt; ++i)
          answer += delta[i] * (long long)join[x][i];
      }
      printf("%I64d\n", answer);
    } else {
      scanf("%d", &y);
      if (num[x])
        delta[num[x]] += (long long)y;
      else {
        for (it = s[x].begin(); it != s[x].end(); ++it) a[*it] += (long long)y;
      }
      for (int i = 1; i <= cnt; ++i) ans[i] += (long long)y * join[x][i];
    }
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}

```


### Prompt

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

Serega loves fun. However, everyone has fun in the unique manner. Serega has fun by solving query problems. One day Fedor came up with such a problem.

You are given an array a consisting of n positive integers and queries to it. The queries can be of two types:

  1. Make a unit cyclic shift to the right on the segment from l to r (both borders inclusive). That is rearrange elements of the array in the following manner:a[l], a[l + 1], ..., a[r - 1], a[r] → a[r], a[l], a[l + 1], ..., a[r - 1].
  2. Count how many numbers equal to k are on the segment from l to r (both borders inclusive).

Fedor hurried to see Serega enjoy the problem and Serega solved it really quickly. Let's see, can you solve it?

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of elements of the array. The second line contains n integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ n).

The third line contains a single integer q (1 ≤ q ≤ 105) — the number of queries. The next q lines contain the queries.

As you need to respond to the queries online, the queries will be encoded. A query of the first type will be given in format: 1 l'i r'i. A query of the second type will be given in format: 2 l'i r'i k'i. All the number in input are integer. They satisfy the constraints: 1 ≤ l'i, r'i, k'i ≤ n.

To decode the queries from the data given in input, you need to perform the following transformations:

li = ((l'i + lastans - 1) mod n) + 1; ri = ((r'i + lastans - 1) mod n) + 1; ki = ((k'i + lastans - 1) mod n) + 1.

Where lastans is the last reply to the query of the 2-nd type (initially, lastans = 0). If after transformation li is greater than ri, you must swap these values.

Output

For each query of the 2-nd type print the answer on a single line.

Examples

Input

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

Output

2
1
0
0

Input

8
8 4 2 2 7 7 8 8
8
1 8 8
2 8 1 7
1 8 1
1 7 3
2 8 8 3
1 1 4
1 2 7
1 4 5

Output

2
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 1e5 + 5;
const int INF = 1e18;
const int K = 320;
int n, a[N], cnt[K][N], q, l, r, ty;
deque<int> d[K];
void rebuild() {
  for (int i = 0; i < n; i++) {
    cnt[i / K][a[i]]++;
    d[i / K].push_back(a[i]);
  }
}
void upd(int l, int r) {
  int posr = r % K, posl = l % K, bl = l / K, br = r / K;
  if (bl == br) {
    int z = d[bl][posr];
    d[bl].erase(d[bl].begin() + posr);
    d[bl].insert(d[bl].begin() + posl, z);
    return;
  }
  int z = d[br][posr];
  d[br].erase(d[br].begin() + posr);
  cnt[br][z]--;
  for (int i = br; i > bl; i--) {
    int x = d[i - 1].back();
    d[i].push_front(x);
    d[i - 1].pop_back();
    cnt[i][x]++;
    cnt[i - 1][x]--;
  }
  d[bl].insert(d[bl].begin() + posl, z);
  cnt[bl][z]++;
}
int get(int l, int r, int x) {
  int posr = r % K, posl = l % K, bl = l / K, br = r / K;
  int res = 0;
  if (bl == br) {
    for (int i = posl; i <= posr; i++) {
      if (d[bl][i] == x) res++;
    }
    return res;
  }
  for (int i = posl; i < d[bl].size(); i++) {
    if (d[bl][i] == x) res++;
  }
  for (int i = bl + 1; i < br; i++) {
    res += cnt[i][x];
  }
  for (int i = 0; i <= posr; i++) {
    if (d[br][i] == x) res++;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  rebuild();
  int last = 0;
  cin >> q;
  for (int test = 1; test <= q; test++) {
    cin >> ty >> l >> r;
    l = (l + last - 1) % n;
    r = (r + last - 1) % n;
    if (l > r) swap(l, r);
    if (ty == 1) {
      upd(l, r);
    } else {
      int k;
      cin >> k;
      k = (last + k - 1) % n + 1;
      last = get(l, r, k);
      cout << last << "\n";
    }
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

In 2337, people are bored at daily life and have crazy desire of having extraordinary experience. These days,“Dungeon Adventure” is one of the hottest attractions, where brave adventurers risk their lives to kill the evil monsters and save the world.

You are a manager of one of such dungeons. Recently you have been receiving a lot of complaints from soldiers who frequently enter your dungeon; they say your dungeon is too easy and they do not want to enter again. You are considering making your dungeon more difficult by increasing the distance between the entrance and the exit of your dungeon so that more monsters can approach the adventurers.

The shape of your dungeon is a rectangle whose width is W and whose height is H. The dungeon is a grid which consists of W × H square rooms of identical size 1 × 1. The southwest corner of the dungeon has the coordinate (0; 0), and the northeast corner has (W, H). The outside of the dungeon is surrounded by walls, and there may be some more walls inside the dungeon in order to prevent adventurers from going directly to the exit. Each wall in the dungeon is parallel to either x-axis or y-axis, and both ends of each wall are at integer coordinates. An adventurer can move from one room to another room if they are adjacent vertically or horizontally and have no wall between.

You would like to add some walls to make the shortest path between the entrance and the exit longer. However, severe financial situation only allows you to build at most only one wall of a unit length. Note that a new wall must also follow the constraints stated above. Furthermore, you need to guarantee that there is at least one path from the entrance to the exit.

You are wondering where you should put a new wall to maximize the minimum number of steps between the entrance and the exit. Can you figure it out?

Input

W H N
sx0 sy0 dx0 dy0
sx1 sy1 dx1 dy1
.
.
.
ix iy
ox oy

The first line contains three integers: W, H and N (1 ≤ W, H ≤ 50, 0 ≤ N ≤ 1000). They are separated with a space.

The next N lines contain the specifications of N walls inside the dungeon. Each wall specification is a line containing four integers. The i-th specification contains sxi, syi, dxi and dyi, separated with a space. These integers give the position of the i-th wall: it spans from (sxi, syi) to (dxi, dyi).

The last two lines contain information about the locations of the entrance and the exit. The first line contains two integers ix and iy, and the second line contains two integers ox and oy. The entrance is located at the room whose south-west corner is (ix, iy), and the exit is located at the room whose southwest corner is (ox, oy).

Output

Print the maximum possible increase in the minimum number of required steps between the entrance and the exit just by adding one wall. If there is no good place to build a new wall, print zero.

Examples

Input

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

Output

6

Input

50 2 0
0 0
49 0

Output

2

Input

50 2 0
0 0
49 1

Output

0

### Response

```cpp
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

int walls[55][55][4];

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

struct aa {
	int x;
	int y;
	int time;
	vector<int>xs;
	vector<int>ys;
};
class Compare {
public:
	//aaが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
aa getway(const int fx, const int fy, const int tx, const int ty) {
	priority_queue<aa, vector<aa>, Compare>que;
	que.push(aa{ fx,fy,0,{},{} });
	int memo[100][100];
	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 100; ++j) {
			memo[i][j] = 99999999;
		}
	}
	memo[fy][fx] = 0;
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		if (atop.x == tx&&atop.y == ty) {
			return atop;
		}
		else {
			atop.xs.push_back(atop.x);
			atop.ys.push_back(atop.y);
		}
		vector<int> axs(atop.xs);
		vector<int> ays(atop.ys);
		for (int i = 0; i < 4; ++i) {
			int newx = atop.x + dx[i];
			int newy = atop.y + dy[i];
			if (!walls[atop.y][atop.x][i]) {
				if (memo[newy][newx]>atop.time + 1) {
					memo[newy][newx] = atop.time + 1;
					que.push(aa{ newx,newy,atop.time + 1,atop.xs,atop.ys });
				}
			}
		}
	}
	return aa{ -10000,0,0,{},{} };
}

int main() {
	int W, H,N; cin >> W >> H >> N;
	for (int i = 0; i < N; ++i) {
		int sx, sy, dx, dy; cin >> sx >> sy >> dx >> dy;
		sy = H - sy;
		dy = H - dy;
		if (sx == dx) {
			if (sy > dy)swap(sy, dy);
			for (int y = sy; y < dy; ++y) {
				if(sx-1>=0)walls[y][sx - 1][2] = true;
				if (sx < W)walls[y][sx][0] = true;
			}
		}
		else {
			if (sx > dx)swap(sx, dx);
			for (int x = sx; x < dx; ++x) {
				if(sy-1>=0)walls[sy-1][x][1] = true;
				if(sy<H)walls[sy][x][3] = true;
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			for (int k = 0; k < 4; ++k) {
				if (i + dy[k] < 0 || i + dy[k] >= H) {
					walls[i][j][k] = true;
				}
				if (j + dx[k] < 0 || j + dx[k] >= W) {
					walls[i][j][k] = true;

				}
			}
		}
	}
	int startx, starty, goalx, goaly; cin >> startx >> starty >> goalx >> goaly;
	starty = H - starty - 1;
	goaly = H - goaly - 1;

	aa fstway =getway(startx, starty, goalx, goaly);
	fstway.xs.push_back(goalx);
	fstway.ys.push_back(goaly);
	int fsttime = fstway.time;
	int ans = 0;
	if (!fstway.xs.empty()) {
		for (int i = 0; i < fstway.xs.size() - 1; ++i) {
			for (int j = 0; j < 4; ++j) {
				if (fstway.xs[i] + dx[j] == fstway.xs[i + 1] && fstway.ys[i] + dy[j] == fstway.ys[i + 1]) {
					walls[fstway.ys[i]][fstway.xs[i]][j] = true;
					walls[fstway.ys[i + 1]][fstway.xs[i + 1]][(2 + j) % 4] = true;
					aa nowway(getway(startx, starty, goalx, goaly));
					if (nowway.time) {
						ans = max(ans, nowway.time - fsttime);
					}
					walls[fstway.ys[i]][fstway.xs[i]][j] = false;
					walls[fstway.ys[i + 1]][fstway.xs[i + 1]][(2 + j) % 4] = false;
				}
			}
		}
	}

	cout << ans << endl;
	return 0;
}
```