### Prompt

Please formulate a cpp solution to the following problem:

In Berland each feudal owns exactly one castle and each castle belongs to exactly one feudal.

Each feudal, except one (the King) is subordinate to another feudal. A feudal can have any number of vassals (subordinates).

Some castles are connected by roads, it is allowed to move along the roads in both ways. Two castles have a road between them if and only if the owner of one of these castles is a direct subordinate to the other owner.

Each year exactly one of these two events may happen in Berland.

  1. The barbarians attacked castle c. The interesting fact is, the barbarians never attacked the same castle twice throughout the whole Berlandian history.
  2. A noble knight sets off on a journey from castle a to castle b (provided that on his path he encounters each castle not more than once).

Let's consider the second event in detail. As the journey from a to b is not short, then the knight might want to stop at a castle he encounters on his way to have some rest. However, he can't stop at just any castle: his nobility doesn't let him stay in the castle that has been desecrated by the enemy's stench. A castle is desecrated if and only if it has been attacked after the year of y. So, the knight chooses the k-th castle he encounters, starting from a (castles a and b aren't taken into consideration), that hasn't been attacked in years from y + 1 till current year.

The knights don't remember which castles were attacked on what years, so he asked the court scholar, aka you to help them. You've got a sequence of events in the Berland history. Tell each knight, in what city he should stop or else deliver the sad news — that the path from city a to city b has less than k cities that meet his requirements, so the knight won't be able to rest.

Input

The first input line contains integer n (2 ≤ n ≤ 105) — the number of feudals.

The next line contains n space-separated integers: the i-th integer shows either the number of the i-th feudal's master, or a 0, if the i-th feudal is the King.

The third line contains integer m (1 ≤ m ≤ 105) — the number of queries.

Then follow m lines that describe the events. The i-th line (the lines are indexed starting from 1) contains the description of the event that occurred in year i. Each event is characterised by type ti (1 ≤ ti ≤ 2). The description of the first type event looks as two space-separated integers ti ci (ti = 1; 1 ≤ ci ≤ n), where ci is the number of the castle that was attacked by the barbarians in the i-th year. The description of the second type contains five space-separated integers: ti ai bi ki yi (ti = 2; 1 ≤ ai, bi, ki ≤ n; ai ≠ bi; 0 ≤ yi < i), where ai is the number of the castle from which the knight is setting off, bi is the number of the castle to which the knight is going, ki and yi are the k and y from the second event's description.

You can consider the feudals indexed from 1 to n. It is guaranteed that there is only one king among the feudals. It is guaranteed that for the first type events all values ci are different.

Output

For each second type event print an integer — the number of the castle where the knight must stay to rest, or -1, if he will have to cover the distance from ai to bi without a rest. Separate the answers by whitespaces.

Print the answers in the order, in which the second type events are given in the input.

Examples

Input

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

Output

2
-1
-1
2

Input

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

Output

5
-1

Note

In the first sample there is only castle 2 on the knight's way from castle 1 to castle 3. When the knight covers the path 1 - 3 for the first time, castle 2 won't be desecrated by an enemy and the knight will stay there. In the second year the castle 2 will become desecrated, so the knight won't have anywhere to stay for the next two years (as finding a castle that hasn't been desecrated from years 1 and 2, correspondingly, is important for him). In the fifth year the knight won't consider the castle 2 desecrated, so he will stay there again.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:36777216")
template <class T>
inline void RD(T &);
template <class T>
inline void OT(const T &);
inline long long RD() {
  long long x;
  RD(x);
  return x;
}
template <class T>
inline T &_RD(T &x) {
  RD(x);
  return x;
}
inline void RC(char &c) { scanf(" %c", &c); }
inline char RC() {
  char c;
  RC(c);
  return c;
}
inline char _RC(char &c) {
  RC(c);
  return c;
}
inline void RF(double &x) { scanf("%lf", &x); };
inline double RF() {
  double x;
  RF(x);
  return x;
}
inline double _RF(double &x) {
  RD(x);
  return x;
}
inline void RS(char *s) { scanf("%s", s); }
inline char *_RS(char *s) {
  scanf("%s", s);
  return s;
}
template <class T0, class T1>
inline void RD(T0 &x0, T1 &x1) {
  RD(x0), RD(x1);
}
template <class T0, class T1, class T2>
inline void RD(T0 &x0, T1 &x1, T2 &x2) {
  RD(x0), RD(x1), RD(x2);
}
template <class T0, class T1, class T2, class T3>
inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {
  RD(x0), RD(x1), RD(x2), RD(x3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
  RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {
  RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {
  RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);
}
template <class T0, class T1>
inline void OT(T0 &x0, T1 &x1) {
  OT(x0), OT(x1);
}
template <class T0, class T1, class T2>
inline void OT(T0 &x0, T1 &x1, T2 &x2) {
  OT(x0), OT(x1), OT(x2);
}
template <class T0, class T1, class T2, class T3>
inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {
  OT(x0), OT(x1), OT(x2), OT(x3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
  OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {
  OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {
  OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);
}
inline void RF(double &a, double &b) { RF(a), RF(b); }
inline void RF(double &a, double &b, double &c) { RF(a), RF(b), RF(c); }
inline void RS(char *s1, char *s2) { RS(s1), RS(s2); }
inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); }
template <class T>
inline void RST(T &A) {
  memset(A, 0, sizeof(A));
}
template <class T0, class T1>
inline void RST(T0 &A0, T1 &A1) {
  RST(A0), RST(A1);
}
template <class T0, class T1, class T2>
inline void RST(T0 &A0, T1 &A1, T2 &A2) {
  RST(A0), RST(A1), RST(A2);
}
template <class T0, class T1, class T2, class T3>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {
  RST(A0), RST(A1), RST(A2), RST(A3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {
  RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {
  RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {
  RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);
}
template <class T>
inline void CLR(priority_queue<T, vector<T>, less<T> > &Q) {
  while (!Q.empty()) Q.pop();
}
template <class T>
inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q) {
  while (!Q.empty()) Q.pop();
}
template <class T>
inline void CLR(T &A) {
  A.clear();
}
template <class T0, class T1>
inline void CLR(T0 &A0, T1 &A1) {
  CLR(A0), CLR(A1);
}
template <class T0, class T1, class T2>
inline void CLR(T0 &A0, T1 &A1, T2 &A2) {
  CLR(A0), CLR(A1), CLR(A2);
}
template <class T0, class T1, class T2, class T3>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);
}
template <class T>
inline void CLR(T &A, int n) {
  for (int i = 0; i < int(n); ++i) CLR(A[i]);
}
template <class T>
inline void FLC(T &A, int x) {
  memset(A, x, sizeof(A));
}
template <class T0, class T1>
inline void FLC(T0 &A0, T1 &A1, int x) {
  FLC(A0, x), FLC(A1, x);
}
template <class T0, class T1, class T2>
inline void FLC(T0 &A0, T1 &A1, T2 &A2) {
  FLC(A0), FLC(A1), FLC(A2);
}
template <class T0, class T1, class T2, class T3>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {
  FLC(A0), FLC(A1), FLC(A2), FLC(A3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {
  FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {
  FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {
  FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);
}
template <class T>
inline void SRT(T &A) {
  sort(A.begin(), A.end());
}
template <class T, class C>
inline void SRT(T &A, C B) {
  sort(A.begin(), A.end(), B);
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double OO = 1e15;
const double PI = acos(-1.0);
template <class T>
inline void checkMin(T &a, const T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkMax(T &a, const T b) {
  if (b > a) a = b;
}
template <class T, class C>
inline void checkMin(T &a, const T b, C c) {
  if (c(b, a)) a = b;
}
template <class T, class C>
inline void checkMax(T &a, const T b, C c) {
  if (c(a, b)) a = b;
}
template <class T>
inline T min(T a, T b, T c) {
  return min(min(a, b), c);
}
template <class T>
inline T max(T a, T b, T c) {
  return max(max(a, b), c);
}
template <class T>
inline T min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
template <class T>
inline T max(T a, T b, T c, T d) {
  return max(max(a, b), max(c, d));
}
template <class T>
inline T sqr(T a) {
  return a * a;
}
template <class T>
inline T cub(T a) {
  return a * a * a;
}
int Ceil(int x, int y) { return (x - 1) / y + 1; }
inline bool _1(int x, int i) { return x & 1 << i; }
inline bool _1(long long x, int i) { return x & 1LL << i; }
inline long long _1(int i) { return 1LL << i; }
inline long long _U(int i) { return _1(i) - 1; };
template <class T>
inline T low_bit(T x) {
  return x & -x;
}
template <class T>
inline T high_bit(T x) {
  T p = low_bit(x);
  while (p != x) x -= p, p = low_bit(x);
  return p;
}
template <class T>
inline T cover_bit(T x) {
  T p = 1;
  while (p < x) p <<= 1;
  return p;
}
inline int count_bits(int x) {
  x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
  x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
  x = (x & 0x0f0f0f0f) + ((x & 0xf0f0f0f0) >> 4);
  x = (x & 0x00ff00ff) + ((x & 0xff00ff00) >> 8);
  x = (x & 0x0000ffff) + ((x & 0xffff0000) >> 16);
  return x;
}
inline int count_bits(long long x) {
  x = (x & 0x5555555555555555LL) + ((x & 0xaaaaaaaaaaaaaaaaLL) >> 1);
  x = (x & 0x3333333333333333LL) + ((x & 0xccccccccccccccccLL) >> 2);
  x = (x & 0x0f0f0f0f0f0f0f0fLL) + ((x & 0xf0f0f0f0f0f0f0f0LL) >> 4);
  x = (x & 0x00ff00ff00ff00ffLL) + ((x & 0xff00ff00ff00ff00LL) >> 8);
  x = (x & 0x0000ffff0000ffffLL) + ((x & 0xffff0000ffff0000LL) >> 16);
  x = (x & 0x00000000ffffffffLL) + ((x & 0xffffffff00000000LL) >> 32);
  return x;
}
int reverse_bits(int x) {
  x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);
  x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);
  x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);
  x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);
  x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000);
  return x;
}
long long reverse_bits(long long x) {
  x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);
  x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);
  x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);
  x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);
  x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL);
  x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL);
  return x;
}
inline void INC(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
inline int sum(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
inline void DEC(int &a, int b) {
  a -= b;
  if (a < 0) a += MOD;
}
inline int dff(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
inline void MUL(int &a, int b) { a = (long long)a * b % MOD; }
inline int pdt(int a, int b) { return (long long)a * b % MOD; }
inline int sum(int a, int b, int c) { return sum(sum(a, b), c); }
inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); }
inline int pow(int a, long long b) {
  int c(1);
  while (b) {
    if (b & 1) MUL(c, a);
    MUL(a, a), b >>= 1;
  }
  return c;
}
template <class T>
inline T pow(T a, long long b) {
  T c(1);
  while (b) {
    if (b & 1) c *= a;
    a *= a, b >>= 1;
  }
  return c;
}
inline int _I(int b) {
  int a = MOD, x1 = 0, x2 = 1, q;
  while (true) {
    q = a / b, a %= b;
    if (!a) return (x2 + MOD) % MOD;
    DEC(x1, pdt(q, x2));
    q = b / a, b %= a;
    if (!b) return (x1 + MOD) % MOD;
    DEC(x2, pdt(q, x1));
  }
}
inline void DIA(int &a, int b) { MUL(a, _I(b)); }
inline int qtt(int a, int b) { return pdt(a, _I(b)); }
inline int phi(int n) {
  int res = n;
  for (int i = 2; sqr(i) <= n; ++i)
    if (!(n % i)) {
      DEC(res, qtt(res, i));
      do {
        n /= i;
      } while (!(n % i));
    }
  if (n != 1) DEC(res, qtt(res, n));
  return res;
}
inline int rand32() {
  return (bool(rand() & 1) << 30) | (rand() << 15) + rand();
}
inline int random32(int l, int r) { return rand32() % (r - l + 1) + l; }
inline int random(int l, int r) { return rand() % (r - l + 1) + l; }
int dice() { return rand() % 6; }
bool coin() { return rand() % 2; }
template <class T>
inline void RD(T &x) {
  char c;
  for (c = getchar(); c < '0'; c = getchar())
    ;
  x = c - '0';
  for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
}
int ____Case;
template <class T>
inline void OT(const T &x) {
  printf("%d ", x);
}
const int N = 100009, L = 17, NN = N * L * 10;
int n, m, root;
int fa[N][20], dep[N];
vector<int> adj[N];
int a[N], beg[N], en[N], cnt;
int destroy[N];
int l[NN], r[NN], c[NN], total;
int T[N], Null;
int Insert(int y, int p) {
  int x = ++total, root = x;
  c[x] = c[y] + 1;
  int ll = 1, rr = n;
  while (ll <= rr) {
    if (p <= ((ll + rr) >> 1)) {
      l[x] = ++total, r[x] = r[y];
      x = l[x], y = l[y], rr = ((ll + rr) >> 1);
    } else {
      l[x] = l[y], r[x] = ++total;
      x = r[x], y = r[y], ll = ((ll + rr) >> 1) + 1;
    }
    c[x] = c[y] + 1;
  }
  return root;
}
inline int Sum(int x, int p) {
  int ll = 1, rr = n, res = 0;
  while (ll <= rr) {
    res += c[x];
    if (p <= ((ll + rr) >> 1))
      x = l[x], rr = ((ll + rr) >> 1);
    else
      x = r[x], ll = ((ll + rr) >> 1) + 1;
  }
  return res;
}
inline int Sum(int x, int l, int r) { return Sum(x, r) - Sum(x, l); }
struct Tnode {
  Tnode *l, *r;
  int segl, segr, val;
  Tnode(int _segl = 0, int _segr = 0, int _val = 0)
      : l(0), r(0), segl(_segl), segr(_segr), val(_val) {}
} pool[N * 20], *cur = pool, *tree[N];
void insert(Tnode *&root, int segl, int segr, int ql, int qr, int plus) {
  *cur = Tnode(segl, segr);
  if (root) *cur = *root;
  root = cur++;
  if (ql <= segl && segr <= qr) {
    root->val += plus;
    return;
  }
  int smid = (segl + segr) / 2;
  if (ql <= smid) insert(root->l, segl, smid, ql, qr, plus);
  if (qr > smid) insert(root->r, smid + 1, segr, ql, qr, plus);
}
int getval(Tnode *t1, int id) {
  if (!t1) return 0;
  if (id <= (t1->segl + t1->segr) / 2)
    return getval(t1->l, id) + t1->val;
  else
    return getval(t1->r, id) + t1->val;
}
int move_up(int x, int t) {
  for (int i = 0; i < L && t; ++i, t >>= 1)
    if (t & 1) x = fa[x][i];
  return x;
}
inline int lca(int x, int y) {
  if (dep[x] > dep[y])
    x = move_up(x, dep[x] - dep[y]);
  else
    y = move_up(y, dep[y] - dep[x]);
  if (x == y)
    return x;
  else {
    for (int i = int(L - 1); i >= int(0); --i)
      if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
    return fa[x][0];
  }
}
int count(int o, int A, int B, int Y) {
  return (getval(tree[o], beg[A]) - (beg[B] ? getval(tree[o], beg[B]) : 0)) -
         (getval(tree[Y], beg[A]) - (beg[B] ? getval(tree[Y], beg[B]) : 0));
}
void dfs(int u = root) {
  a[beg[u] = ++cnt] = u;
  for (int i = 0; i < int(int(adj[u].size())); ++i) {
    dep[adj[u][i]] = dep[u] + 1;
    for (int lv = int(1); lv < int(L); ++lv) {
      fa[adj[u][i]][lv] = fa[fa[adj[u][i]][lv - 1]][lv - 1];
      if (!fa[adj[u][i]][lv]) break;
    }
    dfs(adj[u][i]);
  }
  en[u] = cnt;
}
int main() {
  for (int n____ = int(_RD(n)), i = 1; i <= n____; ++i) {
    if (!_RD(fa[i][0]))
      root = i;
    else
      adj[fa[i][0]].push_back(i);
  }
  dep[root] = 1, dfs();
  for (int n____ = int(_RD(m)), o = 1; o <= n____; ++o) {
    int option, A, B, K, Y, C;
    scanf("%d", &option);
    tree[o] = tree[o - 1];
    if (option == 1) {
      scanf("%d", &C);
      insert(tree[o], 1, n, beg[C], en[C], 1);
      destroy[C] = o;
    } else {
      RD(A, B, K, Y);
      int _A = A, _B = B;
      C = lca(A, B);
      int cnt_AC = (dep[A] - dep[C] + 1) - count(o, A, fa[C][0], Y),
          cnt_CB = (dep[B] - dep[C]) - count(o, B, C, Y);
      if (destroy[A] <= Y) K++;
      if (cnt_AC + cnt_CB < K) {
        puts("-1");
        continue;
      }
      if (cnt_AC >= K) {
        B = C;
      } else {
        A = B;
        B = C;
        K = cnt_AC + cnt_CB - K + 1;
      }
      for (int i = int(L - 1); i >= int(0); --i) {
        B = fa[A][i];
        int cnt = (dep[A] - dep[B]) - count(o, A, B, Y);
        if (cnt < K) {
          K -= cnt;
          A = B;
        }
      }
      if (A == _B)
        puts("-1");
      else
        printf("%d\n", A);
    }
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Fedor runs for president of Byteland! In the debates, he will be asked how to solve Byteland's transport problem. It's a really hard problem because of Byteland's transport system is now a tree (connected graph without cycles). Fedor's team has found out in the ministry of transport of Byteland that there is money in the budget only for one additional road. In the debates, he is going to say that he will build this road as a way to maximize the number of distinct simple paths in the country. A simple path is a path which goes through every vertex no more than once. Two simple paths are named distinct if sets of their edges are distinct.

But Byteland's science is deteriorated, so Fedor's team hasn't succeeded to find any scientists to answer how many distinct simple paths they can achieve after adding exactly one edge on the transport system?

Help Fedor to solve it.

An edge can be added between vertices that are already connected, but it can't be a loop.

In this problem, we consider only simple paths of length at least two.

Input

The first line contains one integer n (2 ≤ n ≤ 500\ 000) — number of vertices in Byteland's transport system.

Each of the following n - 1 lines contains two integers v_i and u_i (1 ≤ v_i, u_i ≤ n). It's guaranteed that the graph is tree.

Output

Print exactly one integer — a maximal number of simple paths that can be achieved after adding one edge.

Examples

Input

2
1 2

Output

2

Input

4
1 2
1 3
1 4

Output

11

Input

6
1 2
1 3
3 4
3 5
4 6

Output

29

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
struct line {
  long long k, b;
  line() = default;
  line(long long kk, long long bb) {
    k = kk;
    b = bb;
  }
  long long eval(long long first) { return k * first + b; }
};
long double inter(line f, line s) { return 1.0 * (s.b - f.b) / (f.k - s.k); }
int siz, it;
line hull[maxn];
void add(line a) {
  while (siz >= 2 &&
         inter(hull[siz - 1], hull[siz - 2]) >= inter(hull[siz - 2], a))
    siz--;
  hull[siz++] = a;
}
long long get(long long first) {
  while (it + 1 < siz && hull[it].eval(first) < hull[it + 1].eval(first)) it++;
  return hull[it].eval(first);
}
int n;
long long dp[maxn], sub[maxn];
vector<int> adj[maxn];
long long c2(int N) { return 1ll * N * (N - 1) / 2; }
long long ans = 1e18;
void dfs(int v, int p) {
  sub[v] = 1;
  int ch = 0;
  for (int to : adj[v])
    if (to != p) {
      dfs(to, v);
      ch++;
      sub[v] += sub[to];
    }
  if (ch == 0) return;
  dp[v] = 1e18;
  for (int to : adj[v]) {
    if (to != p)
      dp[v] =
          min(dp[v], dp[to] + sub[v] - 1 - sub[to] + c2(sub[v] - 1 - sub[to]));
  }
  siz = 0, it = 0;
  sort(adj[v].begin(), adj[v].end(),
       [&](int a, int b) { return sub[a] > sub[b]; });
  long long S = n - 1;
  for (int to : adj[v]) {
    if (to != p) {
      long long a = sub[to];
      if (siz != 0)
        ans = min(ans, get(a) + (S * S - S + a * a + a - 2 * S * a) / 2 + S +
                           dp[to] - a);
      add(line(a, (a * a + a - 2 * S * a) / 2 + dp[to] - a));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  ans = min(ans, dp[1]);
  cout << 1ll * n * (n - 1) - ans << "\n";
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given string S and T consisting of lowercase English letters.

Determine if S equals T after rotation.

That is, determine if S equals T after the following operation is performed some number of times:

Operation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.

Here, |X| denotes the length of the string X.

Constraints

* 2 \leq |S| \leq 100
* |S| = |T|
* S and T consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

If S equals T after rotation, print `Yes`; if it does not, print `No`.

Examples

Input

kyoto
tokyo

Output

Yes

Input

abc
arc

Output

No

Input

aaaaaaaaaaaaaaab
aaaaaaaaaaaaaaab

Output

Yes

### Response

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

int main() {
  string S,T;
  string ans="No";
  cin >> S >> T;
  string a,b;
  int s=S.size();
  int i,j,n,q;
  for(i=0;i<s;i++){
    if(S==T){ans="Yes";}
    S=S.substr(1)+S.at(0);
  }
  cout << ans << endl;
}
```


### Prompt

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

You are given n sequences. Each sequence consists of positive integers, not exceeding m. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the i-th sequence is ki.

Each second integers in each of the sequences are shifted by one to the left, i.e. integers at positions i > 1 go to positions i - 1, while the first integers becomes the last.

Each second we take the first integer of each sequence and write it down to a new array. Then, for each value x from 1 to m we compute the longest segment of the array consisting of element x only.

The above operation is performed for 10100 seconds. For each integer from 1 to m find out the longest segment found at this time.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of sequences and the maximum integer that can appear in the sequences.

Then follow n lines providing the sequences. Each of them starts with an integer ki (1 ≤ ki ≤ 40) — the number of integers in the sequence, proceeded by ki positive integers — elements of the sequence. It's guaranteed that all integers in each sequence are pairwise distinct and do not exceed m.

The total length of all sequences doesn't exceed 200 000.

Output

Print m integers, the i-th of them should be equal to the length of the longest segment of the array with all its values equal to i during the first 10100 seconds.

Examples

Input

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

Output

2
1
3
2

Input

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

Output

3
1
4
0
1

Input

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

Output

0
0
2
1
1
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 123;
int n, m;
struct data {
  int x, k, id;
};
vector<data> con[maxn];
int gcd(int x, int y) {
  while (x && y)
    if (x >= y)
      x %= y;
    else
      y %= x;
  return x + y;
}
int preG[50][50];
void ReadData() {
  cin >> n >> m;
  for (int i = 1, _b = n; i <= _b; ++i) {
    int k;
    cin >> k;
    for (int j = 0, _b = k - 1; j <= _b; ++j) {
      int u;
      cin >> u;
      con[u].push_back((data){j, k, i});
    }
  }
}
int cntLen[50];
int rem[50];
bool possible() {
  for (int i = 1, _b = 40; i <= _b; ++i)
    if (cntLen[i])
      for (int j = i + 1, _b = 40; j <= _b; ++j)
        if (cntLen[j]) {
          if (rem[i] % preG[i][j] != rem[j] % preG[i][j]) return false;
        }
  return true;
}
int smallSolve(vector<data> &a) {
  int j = 0;
  int res = 0;
  memset(cntLen, 0, sizeof(cntLen));
  memset(rem, 0, sizeof(rem));
  for (int i = 0, _n = ((int)a.size()); i < _n; ++i) {
    while (j < i && cntLen[a[i].k] && rem[a[i].k] != a[i].x) {
      cntLen[a[j].k]--;
      j++;
    }
    cntLen[a[i].k]++;
    rem[a[i].k] = a[i].x;
    while (j < i && !possible()) {
      cntLen[a[j].k]--;
      j++;
    }
    res = max(res, i - j + 1);
  }
  return res;
}
int Solve(vector<data> &a) {
  if (!((int)a.size())) return 0;
  int j = 0;
  vector<data> b;
  int res = 0;
  for (int i = 0, _n = ((int)a.size()); i < _n; ++i) {
    while (j < i && a[i].id - a[j].id != i - j) j++;
    if (i == ((int)a.size()) - 1 || a[i].id + 1 != a[i + 1].id) {
      b.clear();
      for (int f = j, _b = i; f <= _b; ++f) b.push_back(a[f]);
      res = max(res, smallSolve(b));
    }
  }
  return res;
}
int res[maxn];
void Process() {
  for (int i = 1, _b = 40; i <= _b; ++i)
    for (int j = 1, _b = 40; j <= _b; ++j) preG[i][j] = gcd(i, j);
  for (int i = 1, _b = m; i <= _b; ++i) res[i] = Solve(con[i]);
  for (int i = 1, _b = m; i <= _b; ++i) cout << res[i] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ReadData();
  Process();
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0, d), (d, 0), (n, n - d) and (n - d, n).

<image> An example of a cornfield with n = 7 and d = 2.

Vasya also knows that there are m grasshoppers near the field (maybe even inside it). The i-th grasshopper is at the point (x_i, y_i). Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

Help Vasya! For each grasshopper determine if it is inside the field (including the border).

Input

The first line contains two integers n and d (1 ≤ d < n ≤ 100).

The second line contains a single integer m (1 ≤ m ≤ 100) — the number of grasshoppers.

The i-th of the next m lines contains two integers x_i and y_i (0 ≤ x_i, y_i ≤ n) — position of the i-th grasshopper.

Output

Print m lines. The i-th line should contain "YES" if the position of the i-th grasshopper lies inside or on the border of the cornfield. Otherwise the i-th line should contain "NO".

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

Examples

Input

7 2
4
2 4
4 1
6 3
4 5

Output

YES
NO
NO
YES

Input

8 7
4
4 4
2 8
8 1
6 1

Output

YES
NO
YES
YES

Note

The cornfield from the first example is pictured above. Grasshoppers with indices 1 (coordinates (2, 4)) and 4 (coordinates (4, 5)) are inside the cornfield.

The cornfield from the second example is pictured below. Grasshoppers with indices 1 (coordinates (4, 4)), 3 (coordinates (8, 1)) and 4 (coordinates (6, 1)) are inside the cornfield.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, m;
  cin >> n >> d >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    bool d1 = (y >= (x - d)), d2 = (y <= (x + d)), d3 = (x + y >= d),
         d4 = (x + y <= 2 * n - d);
    if (d1 && d2 && d3 && d4)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

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

Tonio has a keyboard with only two letters, "V" and "K".

One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.

Input

The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.

Output

Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.

Examples

Input

VK

Output

1

Input

VV

Output

1

Input

V

Output

0

Input

VKKKKKKKKKVVVVVVVVVK

Output

3

Input

KVKV

Output

1

Note

For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.

For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.

For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
inline int sum() {
  int i, re = 0;
  for (i = 0; i < s.size() - 1; i++) {
    if (s.substr(i, 2) == "VK") re++;
  }
  return re;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s;
  int i, mx = -135;
  mx = max(mx, sum());
  for (i = 0; i < s.size(); i++) {
    if (s[i] == 'V') {
      s[i] = 'K';
      mx = max(mx, sum());
      s[i] = 'V';
    } else {
      s[i] = 'V';
      mx = max(mx, sum());
      s[i] = 'K';
    }
  }
  cout << mx << endl;
  return 0;
}

```


### Prompt

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

In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.

After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.

Input

The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants

Output

Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.

You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

Examples

Input

1 3 2 1 2 1

Output

YES

Input

1 1 1 1 1 99

Output

NO

Note

In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.

In the second sample, score of participant number 6 is too high: his team score will be definitely greater.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[6];
  double sum = 0;
  for (int i = 0; i < 6; i++) cin >> a[i], sum += a[i];
  for (int i = 0; i < 6; i++)
    for (int j = i + 1; j < 6; j++)
      for (int k = j + 1; k < 6; k++)
        if (a[i] + a[j] + a[k] == (sum / 2)) return cout << "YES" << endl, 0;
  return cout << "NO" << endl, 0;
}

```


### Prompt

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

Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.

The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

Input

The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Output

Print one integer — the number of times Kolya will have to empty the waste section.

Examples

Input

2 7 10
5 6

Output

1

Input

1 5 10
7

Output

0

Input

3 10 10
5 7 7

Output

1

Input

1 1 1
1

Output

0

Note

In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.

In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, d, sum = 0, k = 0;
  cin >> n >> h >> d;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = 0; i < n; i++) {
    if (ar[i] <= h) {
      sum = sum + ar[i];
      if (sum > d) {
        sum = 0;
        k++;
      } else
        continue;
    } else
      continue;
  }
  cout << k << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Let's call beauty of an array b_1, b_2, …, b_n (n > 1) — min_{1 ≤ i < j ≤ n} |b_i - b_j|.

You're given an array a_1, a_2, … a_n and a number k. Calculate the sum of beauty over all subsequences of the array of length exactly k. As this number can be very large, output it modulo 998244353.

A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements.

Input

The first line contains integers n, k (2 ≤ k ≤ n ≤ 1000).

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

Output

Output one integer — the sum of beauty over all subsequences of the array of length exactly k. As this number can be very large, output it modulo 998244353.

Examples

Input

4 3
1 7 3 5

Output

8

Input

5 5
1 10 100 1000 10000

Output

9

Note

In the first example, there are 4 subsequences of length 3 — [1, 7, 3], [1, 3, 5], [7, 3, 5], [1, 7, 5], each of which has beauty 2, so answer is 8.

In the second example, there is only one subsequence of length 5 — the whole array, which has the beauty equal to |10-1| = 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)2e9;
const long long md = 1000000007;
long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
long long power(long long a, long long p, long long md) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans *= a;
    p /= 2;
    a *= a;
    ans %= md;
    a %= md;
  }
  return ans;
}
long long mdinv(long long a) { return power(a, md - 2, md); }
long long arr[1003];
long long n, k;
long long DP[1003][1003];
long long last[1003];
signed main() {
  const long long mm = 998244353;
  cin >> n >> k;
  for (long long i = 0; i < (long long)n; i++) cin >> arr[i];
  sort(arr, arr + n);
  long long ans = 0;
  for (long long diff = 1; diff <= (arr[n - 1]) / (k - 1) + 2; diff++) {
    long long first = 0, second = 0;
    for (; second < n; second++) {
      while (arr[second] - arr[first] >= diff) first++;
      last[second] = first - 1;
    }
    for (long long i = 0; i < (long long)1003; i++) DP[0][i] = 0;
    DP[0][1] = 1;
    for (long long i = 1; i < n; i++) {
      DP[i][1] = i + 1;
      for (long long len = 2; len <= k; len++) {
        DP[i][len] = DP[i - 1][len];
        if (last[i] >= 0) DP[i][len] += DP[last[i]][len - 1];
        DP[i][len] %= mm;
      }
    }
    ans += DP[n - 1][k];
    ans %= mm;
  }
  cout << ans;
}

```


### Prompt

Create a solution in Cpp for the following problem:

A: A-Z-

problem

There is a circular board of 26 squares, each square with one capital letter of the alphabet written clockwise in alphabetical order. That is, the clockwise side of the'A'square is the'B' square, the next side of the'B'square is the'C'square, and ..., the clockwise side of the'Z'square is the'A'. It's a square.

<image>

Also, the board has one piece in the'A'square.

You receive the string S and manipulate the pieces by looking at each character from the beginning of S. The i-th operation is as follows.

* At that point, move the pieces clockwise one by one, aiming at the square of the letter i of the letter S from the square with the piece. At this time, at least one square is assumed to move. So, for example, when moving from an'A'square to an'A' square, you have to go around the board once.

As a result of the above operation, please answer how many times the piece stepped on the'A'square. "Stepping on the'A'square" means advancing the piece from the'Z'square to the'A' square.

Input format

Input is given on one line.

S

S represents the string you receive.

Constraint

* 1 \ leq | S | \ leq 100
* S consists of uppercase letters only.

Output format

Output in one line how many times you stepped on the'A'square.

Input example 1

AIZU

Output example 1

2

* A-> A (once here)
* A-> I (once so far)
* I-> Z (once so far)
* Z-> U (twice so far)

Input example 2

HOKKAIDO

Output example 2

Four

Example

Input

AIZU

Output

2

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int sum=0;
  cin>>s;
  for(int i=0; i<(int)s.size(); i++){
    int a='A';
    if(i)a=s[i-1];
    int ju = s[i] - a;
    if(ju<=0)ju+=26;
    sum+=ju;
    //cout<<sum<<endl;
  }
  cout<<sum/26<<endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.

Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers.

Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa.

The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second.

The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first.

All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice.

It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number.

Output

If you can deduce the shared number with certainty, print that number.

If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0.

Otherwise print -1.

Examples

Input

2 2
1 2 3 4
1 5 3 4

Output

1

Input

2 2
1 2 3 4
1 5 6 4

Output

0

Input

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

Output

-1

Note

In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1.

In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart.

In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> v1;
vector<pair<int, int>> v2;
int connect(int i, int j) {
  int ans = 0;
  if (v1[i].first == v2[j].first) {
    ans++;
  }
  if (v1[i].first == v2[j].second) {
    ans++;
  }
  if (v1[i].second == v2[j].first) {
    ans++;
  }
  if (v1[i].second == v2[j].second) {
    ans++;
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  v1.resize(n);
  v2.resize(m);
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &v1[i].first, &v1[i].second);
  }
  for (int j = 0; j < m; j++) {
    scanf("%d %d", &v2[j].first, &v2[j].second);
  }
  int possible1 = 0;
  for (int i = 0; i < n; i++) {
    int temp = 0;
    bool h1 = false;
    bool h2 = false;
    for (int j = 0; j < m; j++) {
      if (connect(i, j) == 2 || connect(i, j) == 0) continue;
      if (v1[i].first == v2[j].first || v1[i].first == v2[j].second)
        h1 = true;
      else
        h2 = true;
    }
    if (h1 && h2) {
      printf("-1");
      return 0;
    }
    if (h1) {
      ans.push_back(v1[i].first);
    } else if (h2)
      ans.push_back(v1[i].second);
  }
  for (int j = 0; j < m; j++) {
    int temp = 0;
    bool h1 = false, h2 = false;
    for (int i = 0; i < n; i++) {
      if (connect(i, j) == 2 || connect(i, j) == 0) continue;
      if (v2[j].first == v1[i].first || v2[j].first == v1[i].second)
        h1 = true;
      else
        h2 = true;
    }
    if (h1 && h2) {
      printf("-1");
      return 0;
    }
    if (h1) {
      ans.push_back(v2[j].first);
    } else if (h2)
      ans.push_back(v2[j].second);
  }
  for (int i = 1; i < ans.size(); i++) {
    if (ans[i] != ans[i - 1]) {
      printf("0");
      return 0;
    }
  }
  printf("%d", ans[0]);
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

We have a grid with H rows and W columns, where all the squares are initially white.

You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions:

* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column black.

At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.

Constraints

* 1 \leq H \leq 100
* 1 \leq W \leq 100
* 1 \leq N \leq H \times W
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

H
W
N

Output

Print the minimum number of operations needed.

Examples

Input

3
7
10

Output

2

Input

14
12
112

Output

8

Input

2
100
200

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
  #define int long long
  int h,w,n;
  float t;
  cin>>h>>w>>n;
  t = max(h,w);
  cout<< ceil(n/t);
}

```


### Prompt

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

Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:

a_{1} ≤ a_{2},

a_{n} ≤ a_{n-1} and

a_{i} ≤ max(a_{i-1},    a_{i+1}) for all i from 2 to n-1.

Ivan does not remember the array and asks to find the number of ways to restore it. Restored elements also should be integers from 1 to 200. Since the number of ways can be big, print it modulo 998244353.

Input

First line of input contains one integer n (2 ≤ n ≤ 10^{5}) — size of the array.

Second line of input contains n integers a_{i} — elements of array. Either a_{i} = -1 or 1 ≤ a_{i} ≤ 200. a_{i} = -1 means that i-th element can't be read.

Output

Print number of ways to restore the array modulo 998244353.

Examples

Input

3
1 -1 2

Output

1

Input

2
-1 -1

Output

200

Note

In the first example, only possible value of a_{2} is 2.

In the second example, a_{1} = a_{2} so there are 200 different values because all restored elements should be integers between 1 and 200.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long power(long long a, long long b) {
  long long x = 1;
  a = a % 998244353LL;
  while (b) {
    if (b & 1) x = (x * a) % 998244353LL;
    a = (a * a) % 998244353LL;
    b >>= 1;
  }
  return x;
}
inline long long inv(long long a) { return power(a, 998244353LL - 2); }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
const int N = 1e5 + 5;
long long dp[2][205][2];
long long n, a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n == 2) {
    if (a[0] == a[1]) {
      if (a[0] == -1)
        cout << "200\n";
      else
        cout << "1\n";
      return 0;
    } else if (a[0] == -1 || a[1] == -1) {
      cout << "1\n";
      return 0;
    } else {
      cout << "0\n";
      return 0;
    }
  }
  if (a[0] != -1 && a[1] != -1) {
    if (a[0] > a[1]) {
      cout << "0\n";
      return 0;
    }
  }
  if (a[n - 1] != -1 && a[n - 2] != -1) {
    if (a[n - 1] > a[n - 2]) {
      cout << "0\n";
      return 0;
    }
  }
  for (int i = 1; i < n - 1; i++) {
    if (a[i - 1] != -1 && a[i + 1] != -1 && a[i] != -1) {
      if (max(a[i - 1], a[i + 1]) < a[i]) {
        cout << "0\n";
        return 0;
      }
    }
  }
  if (a[0] != -1)
    dp[0][a[0]][1] = 1;
  else {
    for (int i = 1; i <= 200; i++) dp[0][i][1] = 1;
  }
  for (int i = 1; i < n; i++) {
    long long sum = 0, sum1 = 0;
    for (int j = 1; j <= 200; j++) {
      sum1 += (dp[0][j][1] + dp[0][j][0]);
      sum += dp[0][j][0];
      sum1 %= 998244353LL;
      sum %= 998244353LL;
    }
    for (int j = 200; j > 0; j--) {
      sum1 = (sum1 - dp[0][j][1] - dp[0][j][0] + 998244353LL + 998244353LL) %
             998244353LL;
      dp[1][j][1] = sum1;
    }
    for (int j = 1; j <= 200; j++) {
      dp[1][j][0] = (sum + dp[0][j][1]) % 998244353LL;
      sum = (sum + 998244353LL - dp[0][j][0]) % 998244353LL;
    }
    if (a[i] == -1) {
      for (int j = 1; j <= 200; j++) {
        dp[0][j][0] = dp[1][j][0];
        dp[0][j][1] = dp[1][j][1];
      }
    } else {
      for (int j = 1; j <= 200; j++) {
        dp[0][j][0] = 0;
        dp[0][j][1] = 0;
      }
      dp[0][a[i]][0] = dp[1][a[i]][0];
      dp[0][a[i]][1] = dp[1][a[i]][1];
    }
    for (int j = 1; j <= 200; j++) {
      dp[1][j][0] = 0;
      dp[1][j][1] = 0;
    }
  }
  long long ans = 0;
  for (int j = 1; j <= 200; j++) {
    ans += dp[0][j][0];
    if (ans >= 998244353LL) ans -= 998244353LL;
  }
  ans %= 998244353LL;
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n - 1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex i is vertex pi, the parent index is always less than the index of the vertex (i.e., pi < i).

The depth of the vertex is the number of nodes on the path from the root to v along the edges. In particular, the depth of the root is equal to 1.

We say that vertex u is in the subtree of vertex v, if we can get from u to v, moving from the vertex to the parent. In particular, vertex v is in its subtree.

Roma gives you m queries, the i-th of which consists of two numbers vi, hi. Let's consider the vertices in the subtree vi located at depth hi. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 500 000) — the number of nodes in the tree and queries, respectively.

The following line contains n - 1 integers p2, p3, ..., pn — the parents of vertices from the second to the n-th (1 ≤ pi < i).

The next line contains n lowercase English letters, the i-th of these letters is written on vertex i.

Next m lines describe the queries, the i-th line contains two numbers vi, hi (1 ≤ vi, hi ≤ n) — the vertex and the depth that appear in the i-th query.

Output

Print m lines. In the i-th line print "Yes" (without the quotes), if in the i-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes).

Examples

Input

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

Output

Yes
No
Yes
Yes
Yes

Note

String s is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome.

Clarification for the sample test.

In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z".

In the second query vertices 5 and 6 satisfy condititions, they contain letters "с" and "d" respectively. It is impossible to form a palindrome of them.

In the third query there exist no vertices at depth 1 and in subtree of 4. We may form an empty palindrome.

In the fourth query there exist no vertices in subtree of 6 at depth 1. We may form an empty palindrome.

In the fifth query there vertices 2, 3 and 4 satisfying all conditions above, they contain letters "a", "c" and "c". We may form a palindrome "cac".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> G[500005];
vector<int> level[500005];
int dp[29][2 * 500005], cnt;
int st[500005], ed[500005], memo[2 * 500005], demo[2 * 500005], val[500005],
    LV[500005];
int ar[33];
char str[500005];
void dfs(int x, int lvl) {
  st[x] = cnt++;
  LV[x] = lvl;
  level[lvl].push_back(st[x]);
  for (int i = 0; i < G[x].size(); i++) {
    int v = G[x][i];
    dfs(v, lvl + 1);
  }
  ed[x] = cnt - 1;
}
int main() {
  int n, q, ok = 0;
  scanf("%d%d", &n, &q);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
    if (i == 5 && p == 3) ok = 1;
  }
  scanf("%s", str);
  for (int i = 1; i <= n; i++) {
    val[i] = (str[i - 1] - 'a') + 1;
  }
  cnt = 1;
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    memo[ed[i]] = i;
    demo[st[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    int sz = level[i].size();
    if (sz == 0) break;
    for (int j = 1; j <= 26; j++)
      dp[j][level[i][0]] = (val[demo[level[i][0]]] == j);
    for (int j = 1; j < sz; j++) {
      for (int k = 1; k <= 26; k++) {
        dp[k][level[i][j]] =
            dp[k][level[i][j - 1]] + (val[demo[level[i][j]]] == k);
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int v, h;
    scanf("%d%d", &v, &h);
    int d = h - LV[v];
    if (d < 0 || (int)level[h].size() == 0) {
      puts("Yes");
      continue;
    }
    int vv =
        lower_bound(level[h].begin(), level[h].end(), st[v]) - level[h].begin();
    if (vv == level[h].size()) vv--;
    if (level[h][vv] < st[v]) vv++;
    int ee =
        lower_bound(level[h].begin(), level[h].end(), ed[v]) - level[h].begin();
    if (ee == level[h].size()) ee--;
    if (level[h][ee] > ed[v]) ee--;
    if (vv > ee) {
      puts("Yes");
      continue;
    }
    vv = level[h][vv];
    ee = level[h][ee];
    for (int j = 1; j <= 26; j++) {
      ar[j] = 0;
      ar[j] = dp[j][ee] - dp[j][vv];
    }
    ar[val[demo[vv]]]++;
    int odd = 0;
    for (int j = 1; j <= 26; j++) {
      odd += (ar[j] & 1);
    }
    if (odd > 1)
      puts("No");
    else
      puts("Yes");
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Ivan Anatolyevich's agency is starting to become famous in the town.

They have already ordered and made n TV commercial videos. Each video is made in a special way: the colors and the soundtrack are adjusted to the time of the day and the viewers' mood. That's why the i-th video can only be shown within the time range of [li, ri] (it is not necessary to use the whole segment but the broadcast time should be within this segment).

Now it's time to choose a TV channel to broadcast the commercial. Overall, there are m TV channels broadcasting in the city, the j-th one has cj viewers, and is ready to sell time [aj, bj] to broadcast the commercial.

Ivan Anatolyevich is facing a hard choice: he has to choose exactly one video i and exactly one TV channel j to broadcast this video and also a time range to broadcast [x, y]. At that the time range should be chosen so that it is both within range [li, ri] and within range [aj, bj].

Let's define the efficiency of the broadcast as value (y - x)·cj — the total sum of time that all the viewers of the TV channel are going to spend watching the commercial. Help Ivan Anatolyevich choose the broadcast with the maximum efficiency!

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of commercial videos and channels, respectively.

Each of the following n lines contains two integers li, ri (0 ≤ li ≤ ri ≤ 109) — the segment of time when it is possible to show the corresponding video.

Each of the following m lines contains three integers aj, bj, cj (0 ≤ aj ≤ bj ≤ 109, 1 ≤ cj ≤ 109), characterizing the TV channel.

Output

In the first line print an integer — the maximum possible efficiency of the broadcast. If there is no correct way to get a strictly positive efficiency, print a zero.

If the maximum efficiency is strictly positive, in the second line also print the number of the video i (1 ≤ i ≤ n) and the number of the TV channel j (1 ≤ j ≤ m) in the most effective broadcast.

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

Examples

Input

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

Output

4
2 1

Input

1 1
0 0
1 1 10

Output

0

Note

In the first sample test the most optimal solution is to show the second commercial using the first TV channel at time [2, 4]. The efficiency of such solution is equal to (4 - 2)·2 = 4.

In the second sample test Ivan Anatolievich's wish does not meet the options of the TV channel, the segments do not intersect, so the answer is zero.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 400005;
struct SegmentTree {
  int offset;
  vector<pair<int, int> > v;
  vector<vector<pair<int, int> > > vals;
  void initialize(int n) {
    v.clear();
    vals.clear();
    for (offset = 1; offset < n; offset <<= 1)
      ;
    v.resize(2 * offset, make_pair(-1, -1));
    vals.resize(offset);
    for (int i = 0; i < offset; i++) {
      vals[i].push_back(make_pair(-1, -1));
    }
  }
  void update(int x, int val, int idx) {
    vals[x].push_back(make_pair(val, idx));
    v[x + offset] = max(v[x + offset], make_pair(val, idx));
    for (int i = (x + offset) >> 1; i > 0; i >>= 1) {
      v[i] = max(v[i * 2], v[i * 2 + 1]);
    }
  }
  void ssort() {
    for (int i = 0; i < offset; i++) {
      sort(vals[i].begin(), vals[i].end());
    }
  }
  void erase(int x, int val, int idx) {
    vals[x].pop_back();
    v[x + offset] = *vals[x].rbegin();
    for (int i = (x + offset) >> 1; i > 0; i >>= 1) {
      v[i] = max(v[i * 2], v[i * 2 + 1]);
    }
  }
  pair<int, int> query(int x, int lo, int hi, int a, int b) {
    if (lo >= b || hi <= a) {
      return make_pair(-1, -1);
    } else if (lo >= a && hi <= b) {
      return v[x];
    }
    return max(query(x * 2, lo, (lo + hi) / 2, a, b),
               query(x * 2 + 1, (lo + hi) / 2, hi, a, b));
  }
  pair<int, int> query(int a, int b) { return query(1, 0, offset, a, b + 1); }
};
struct Rol {
  int x, y;
  Rol(int _x = 0, int _y = 0) : x(_x), y(_y) {}
};
struct Can {
  int x, y;
  long long c;
  Can(int _x = 0, int _y = 0, long long _c = 0) : x(_x), y(_y), c(_c) {}
};
int n, m;
vector<int> vals;
Rol rol[MAX_N], trol[MAX_N];
Can can[MAX_N], tcan[MAX_N];
vector<int> rols[2 * MAX_N], cans[2 * MAX_N];
SegmentTree t, t2;
Can solve() {
  vals.clear();
  for (int i = 0; i < n; i++) {
    vals.push_back(rol[i].x);
    vals.push_back(rol[i].y);
  }
  for (int i = 0; i < m; i++) {
    vals.push_back(can[i].x);
    vals.push_back(can[i].y);
  }
  sort(vals.begin(), vals.end());
  vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
  t.initialize(vals.size());
  for (int i = 0; i < n; i++) {
    rol[i].x = lower_bound(vals.begin(), vals.end(), rol[i].x) - vals.begin();
    rol[i].y = lower_bound(vals.begin(), vals.end(), rol[i].y) - vals.begin();
    t.update(rol[i].x, rol[i].y, i);
  }
  long long ans = 0;
  int ii = -1, jj = -1;
  for (int i = 0; i < m; i++) {
    can[i].x = lower_bound(vals.begin(), vals.end(), can[i].x) - vals.begin();
    can[i].y = lower_bound(vals.begin(), vals.end(), can[i].y) - vals.begin();
    pair<int, int> q = t.query(0, can[i].x);
    if (q.first >= can[i].x) {
      q.first = min(q.first, can[i].y);
      if ((long long)(vals[q.first] - vals[can[i].x]) * can[i].c > ans) {
        ans = (long long)(vals[q.first] - vals[can[i].x]) * can[i].c;
        jj = i;
        ii = q.second;
      }
    }
  }
  return Can(ii, jj, ans);
}
Can maxx(Can a, Can b) {
  if (a.c > b.c) {
    return a;
  }
  return b;
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> rol[i].x >> rol[i].y;
    trol[i] = rol[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> can[i].x >> can[i].y >> can[i].c;
    tcan[i] = can[i];
  }
  Can a = solve();
  for (int i = 0; i < n; i++) {
    rol[i] = trol[i];
  }
  for (int i = 0; i < m; i++) {
    can[i] = tcan[i];
  }
  for (int i = 0; i < n; i++) {
    rol[i].x *= -1;
    rol[i].y *= -1;
    swap(rol[i].x, rol[i].y);
  }
  for (int i = 0; i < m; i++) {
    can[i].x *= -1;
    can[i].y *= -1;
    swap(can[i].x, can[i].y);
  }
  Can b = solve();
  long long ans = 0;
  int ii = -1, jj = -1;
  t2.initialize(vals.size());
  for (int i = 0; i < n; i++) {
    t2.update(rol[i].y, vals[rol[i].y] - vals[rol[i].x], i);
  }
  for (int i = 0; i < n; i++) {
    rols[rol[i].x].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    cans[can[i].x].push_back(i);
  }
  t2.ssort();
  for (int i = 0; i < vals.size(); i++) {
    for (int j = 0; j < cans[i].size(); j++) {
      int cur = cans[i][j];
      pair<int, int> q = t2.query(can[cur].x, can[cur].y);
      if (q.first >= 0 && (long long)q.first * can[cur].c > ans) {
        ans = (long long)q.first * can[cur].c;
        ii = q.second;
        jj = cur;
      }
    }
    for (int j = 0; j < rols[i].size(); j++) {
      int cur = rols[i][j];
      t2.erase(rol[cur].y, vals[rol[cur].y] - vals[rol[cur].x], cur);
    }
  }
  Can c = maxx(a, maxx(b, Can(ii, jj, ans)));
  if (c.c) {
    cout << c.c << endl << c.x + 1 << " " << c.y + 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

```


### Prompt

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

A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.

Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.

He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.

Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?

Input

The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

Output

Print the minimum possible sum of numbers written on remaining cards.

Examples

Input

7 3 7 3 20

Output

26

Input

7 9 3 1 8

Output

28

Input

10 10 10 10 10

Output

20

Note

In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.

  * Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
  * Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
  * Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.

You are asked to minimize the sum so the answer is 26.

In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.

In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  map<int, int> m;
  map<int, int>::iterator it;
  int a, sum = 0;
  vector<int> s;
  for (int i = 0; i < 5; i++) {
    cin >> a;
    sum += a;
    m[a]++;
  }
  for (it = m.begin(); it != m.end(); it++) {
    if (it->second == 2 || it->second == 3)
      s.push_back(sum - (it->first * it->second));
    else if (it->second == 4)
      s.push_back(sum - (it->first * 3));
    else if (it->second == 5)
      s.push_back(sum - (it->first * 3));
    else
      s.push_back(sum);
  }
  cout << *min_element(s.begin(), s.end());
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation:

* Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical" or "horizontal".
* If we choose "vertical", insert one row at the top of the grid, resulting in an (a+1) \times b grid.
* If we choose "horizontal", insert one column at the right end of the grid, resulting in an a \times (b+1) grid.
* Then, paint one of the added squares black, and the other squares white.

Assume the grid eventually has C horizontal rows and D vertical columns. Find the number of ways in which the squares can be painted in the end, modulo 998244353.

Constraints

* 1 \leq A \leq C \leq 3000
* 1 \leq B \leq D \leq 3000
* A, B, C, and D are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of ways in which the squares can be painted in the end, modulo 998244353.

Examples

Input

1 1 2 2

Output

3

Input

2 1 3 4

Output

65

Input

31 41 59 265

Output

387222020

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const long long md=998244353;
long long a,b,c,d,dp[2][3030][3030];
int main()
{
	cin>>a>>b>>c>>d;
	dp[0][a][b]=1;
	for(int i=a;i<=c;i++)
	{
		for(int j=b;j<=d;j++)
		{
			if(i==a && j==b)
			{
				continue;
			}
			dp[0][i][j]=dp[0][i-1][j]*j+dp[1][i-1][j];
			dp[0][i][j]%=md;
			dp[1][i][j]=dp[0][i][j-1]*i+dp[1][i][j-1]*i;
			dp[1][i][j]%=md;
		}
	}
	cout<<(dp[0][c][d]+dp[1][c][d])%md<<endl;
	return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

This is an interactive problem. Don't forget to flush output after printing queries using cout.flush() or fflush(stdout) in C++ or similar functions in other programming languages.

There are n gift boxes in a row, numbered from 1 to n from left to right. It's known that exactly k of them contain valuable gifts — other boxes contain just lucky stones. All boxes look the same and differ only in weight. All boxes with stones have the same weight and are strictly heavier than boxes with valuable items. But valuable gifts may be different, so the boxes with valuable items may have different weights.

You can ask no more than 50 queries (printing an answer doesn't count). By each query you can compare total weights of two non-intersecting subsets of boxes a_1, a_2, ..., a_{k_a} and b_1, b_2, ..., b_{k_b}. In return you'll get one of four results:

  * FIRST, if subset a_1, a_2, ..., a_{k_a} is strictly heavier;
  * SECOND, if subset b_1, b_2, ..., b_{k_b} is strictly heavier;
  * EQUAL, if subsets have equal total weights;
  * WASTED, if the query is incorrect or the limit of queries is exceeded.

Using such queries (or, maybe, intuition) find the box with a valuable gift with the minimum index.

Input

The input consists of several cases. In the beginning, you receive the integer T (1 ≤ T ≤ 500) — the number of test cases.

At the beginning of each test case, you receive two integers n and k (2 ≤ n ≤ 1000, 1 ≤ k ≤ n/2) — the number of boxes in a row and the number of boxes with valuable gifts.

It's guaranteed that the order of boxes is fixed beforehand and that the sum of n in one test doesn't exceed 1000.

Output

For each test case print the minimum index among all boxes with a valuable gift in the following format: "! x" where x (1 ≤ x ≤ n) — the index of the box.

Interaction

Print each query in three lines. In the first line print the sizes of subset in the following format: "? k_a k_b" where k_a and k_b (1 ≤ k_a, k_b ≤ n; k_a + k_b ≤ n) — the corresponding sizes.

In the second line print k_a integers a_1, a_2, ..., a_{k_a} (1 ≤ a_i ≤ n; a_i ≠ a_j if i ≠ j) — indexes of boxes in the first subset.

In the third line print k_b integers b_1, b_2, ..., b_{k_b} (1 ≤ b_i ≤ n; b_i ≠ b_j if i ≠ j) — indexes of boxes in the second subset.

The subsets shouldn't intersect, i. e. a_i ≠ b_j for all i and j.

You'll receive one of four responses described above. In the case of WASTED stop your program to avoid getting random verdict instead of Wrong Answer.

Example

Input

2
2 1
-
-
-
FIRST
-
5 2
-
-
-
FIRST
-
-
-
SECOND
-
-
-
EQUAL
-

Output

-
-
? 1 1
1
2
-
! 2
-
? 1 1
1
2
-
? 2 3
4 2
1 3 5
-
? 1 1
4
5
-
! 1

Note

Additional separators "–" in the sample are used only to increase the readability of the sample. Don't print any unnecessary symbols or line breaks in your solution when you send it to the system.

Hacks are forbidden in this task.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int get() {
  char c;
  while (c = getchar(), c != '-' && (c < '0' || c > '9'))
    ;
  bool flag = (c == '-');
  if (flag) c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return flag ? -x : x;
}
const int MAXN = 1000;
const int MAXQ = 50;
bool flag[MAXN + 1];
int lis[MAXN];
int main() {
  int test;
  cin >> test;
  while (test--) {
    int n, k;
    cin >> n >> k;
    int num = 0, s = 1;
    while (s * 2 <= n - k) {
      s *= 2;
      num++;
    }
    num = min(MAXQ - num * 2, n - 1);
    int stone = rand() % n + 1;
    memset(flag, 0, sizeof(flag));
    flag[stone] = true;
    for (int i = 0; i < num; i++) {
      int x;
      while (x = rand() % n + 1, flag[x])
        ;
      flag[x] = true;
      printf("? 1 1\n%d\n%d\n", stone, x);
      fflush(stdout);
      string s;
      cin >> s;
      if (s == "WASTED") return 0;
      if (s == "SECOND") stone = x;
    }
    lis[0] = stone;
    for (int i = 1, cur = 1; i <= n; i++)
      if (i != stone) lis[cur++] = i;
    num = 1;
    int l = -1, r = -1;
    while (l == -1) {
      string s;
      if (num * 2 > n - k)
        s = "FIRST";
      else {
        printf("? %d %d\n", num, num);
        for (int i = 0; i < num; i++)
          printf("%d%c", lis[i], (i == num - 1) ? '\n' : ' ');
        for (int i = 0; i < num; i++)
          printf("%d%c", lis[num + i], (i == num - 1) ? '\n' : ' ');
        fflush(stdout);
        cin >> s;
        if (s == "WASTED" || s == "SECOND") return 0;
      }
      if (s == "EQUAL")
        num *= 2;
      else {
        l = num;
        r = min(num * 2 - 1, n - 1);
      }
    }
    while (l < r) {
      int len = (r - l + 1) / 2;
      printf("? %d %d\n", len, len);
      for (int i = 0; i < len; i++)
        printf("%d%c", lis[i], (i == len - 1) ? '\n' : ' ');
      for (int i = 0; i < len; i++)
        printf("%d%c", lis[l + i], (i == len - 1) ? '\n' : ' ');
      fflush(stdout);
      string s;
      cin >> s;
      if (s == "WASTED" || s == "SECOND") return 0;
      if (s == "EQUAL")
        l += len;
      else
        r -= len;
    }
    printf("! %d\n", lis[l]);
    fflush(stdout);
  }
  return 0;
}

```


### Prompt

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

You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)).

An inversion in the b array is a pair of integers i and j such that 1 ≤ i < j ≤ n and b_i > b_j.

You should choose x in such a way that the number of inversions in b is minimized. If there are several options for x — output the smallest one.

Input

First line contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of elements in a.

Second line contains n space-separated integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.

Output

Output two integers: the minimum possible number of inversions in b, and the minimum possible value of x, which achieves those number of inversions.

Examples

Input

4
0 1 3 2

Output

1 0

Input

9
10 7 9 10 7 5 5 3 5

Output

4 14

Input

3
8 10 3

Output

0 8

Note

In the first sample it is optimal to leave the array as it is by choosing x = 0.

In the second sample the selection of x = 14 results in b: [4, 9, 7, 4, 9, 11, 11, 13, 11]. It has 4 inversions:

  * i = 2, j = 3;
  * i = 2, j = 4;
  * i = 3, j = 4;
  * i = 8, j = 9.

In the third sample the selection of x = 8 results in b: [0, 2, 11]. It has no inversions.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const long long INF(0x3f3f3f3f3f3f3f3fll);
const long long inf(0x3f3f3f3f);
template <typename T>
void read(T &res) {
  bool flag = false;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
  for (res = ch - 48; isdigit(ch = getchar());
       res = (res << 1) + (res << 3) + ch - 48)
    ;
  flag && (res = -res);
}
template <typename T>
void Out(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) Out(x / 10);
  putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow_mod(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long fact_pow(long long n, long long p) {
  long long res = 0;
  while (n) {
    n /= p;
    res += n;
  }
  return res;
}
long long mult(long long a, long long b, long long p) {
  a %= p;
  b %= p;
  long long r = 0, v = a;
  while (b) {
    if (b & 1) {
      r += v;
      if (r > p) r -= p;
    }
    v <<= 1;
    if (v > p) v -= p;
    b >>= 1;
  }
  return r;
}
long long quick_pow(long long a, long long b, long long p) {
  long long r = 1, v = a % p;
  while (b) {
    if (b & 1) r = mult(r, v, p);
    v = mult(v, v, p);
    b >>= 1;
  }
  return r;
}
bool CH(long long a, long long n, long long x, long long t) {
  long long r = quick_pow(a, x, n);
  long long z = r;
  for (long long i = 1; i <= t; i++) {
    r = mult(r, r, n);
    if (r == 1 && z != 1 && z != n - 1) return true;
    z = r;
  }
  return r != 1;
}
bool Miller_Rabin(long long n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (!(n & 1)) return false;
  long long x = n - 1, t = 0;
  while (!(x & 1)) {
    x >>= 1;
    t++;
  }
  srand(time(NULL));
  long long o = 8;
  for (long long i = 0; i < o; i++) {
    long long a = rand() % (n - 1) + 1;
    if (CH(a, n, x, t)) return false;
  }
  return true;
}
long long exgcd1(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long long t = exgcd1(b, a % b, y, x);
  y -= a / b * x;
  return t;
}
long long get_inv(long long a, long long mod) {
  long long x, y;
  long long d = exgcd1(a, mod, x, y);
  return d == 1 ? (x % mod + mod) % mod : -1;
}
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, x, y);
  long long t = x;
  x = y, y = t - (a / b) * y;
}
long long INV(long long a, long long b) {
  long long x, y;
  return exgcd(a, b, x, y), (x % b + b) % b;
}
long long crt(long long x, long long p, long long mod) {
  return INV(p / mod, mod) * (p / mod) * x;
}
long long FAC(long long x, long long a, long long b) {
  if (!x) return 1;
  long long ans = 1;
  for (long long i = 1; i <= b; i++)
    if (i % a) ans *= i, ans %= b;
  ans = pow_mod(ans, x / b, b);
  for (long long i = 1; i <= x % b; i++)
    if (i % a) ans *= i, ans %= b;
  return ans * FAC(x / a, a, b) % b;
}
long long C(long long n, long long m, long long a, long long b) {
  long long N = FAC(n, a, b), M = FAC(m, a, b), Z = FAC(n - m, a, b), sum = 0,
            i;
  for (i = n; i; i = i / a) sum += i / a;
  for (i = m; i; i = i / a) sum -= i / a;
  for (i = n - m; i; i = i / a) sum -= i / a;
  return N * pow_mod(a, sum, b) % b * INV(M, b) % b * INV(Z, b) % b;
}
long long exlucas(long long n, long long m, long long p) {
  long long t = p, ans = 0, i;
  for (i = 2; i * i <= p; i++) {
    long long k = 1;
    while (t % i == 0) {
      k *= i, t /= i;
    }
    ans += crt(C(n, m, i, k), p, k), ans %= p;
  }
  if (t > 1) ans += crt(C(n, m, t, t), p, t), ans %= p;
  return ans % p;
}
const long long N = 3e5 + 10;
struct Edge {
  long long nex, to;
} edge[N << 1];
long long head[N], TOT;
void add_edge(long long u, long long v) {
  edge[++TOT].nex = head[u];
  edge[TOT].to = v;
  head[u] = TOT;
}
long long cnt[N][2], a[N];
vector<long long> vec;
void dfs(vector<long long> vec, long long i) {
  if (i < 0) return;
  long long res1 = 0, res2 = 0, cnt1 = 0, cnt2 = 0;
  for (auto j : vec) {
    long long x = j >> i & 1 ^ 1;
    if (!x)
      res1 += cnt1;
    else
      res2 += cnt2;
    if (x)
      cnt1++;
    else
      cnt2++;
  }
  cnt[i][0] += res2, cnt[i][1] += res1;
  vector<long long> vec1, vec2;
  for (auto j : vec) {
    if (j >> i & 1)
      vec1.push_back(j);
    else
      vec2.push_back(j);
  }
  if (vec1.size()) dfs(vec1, i - 1);
  if (vec2.size()) dfs(vec2, i - 1);
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long n, ans = 0, tot = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i], vec.push_back(a[i]);
  dfs(vec, 31);
  for (long long i = 31; i >= 0; i--) {
    if (cnt[i][0] > cnt[i][1])
      ans += 1LL << i, tot += cnt[i][1];
    else
      tot += cnt[i][0];
  }
  cout << tot << " " << ans << '\n';
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Carving the cake 2 (Cake 2)

JOI-kun and IOI-chan are twin brothers and sisters. JOI has been enthusiastic about making sweets lately, and JOI tried to bake a cake and eat it today, but when it was baked, IOI who smelled it came, so we decided to divide the cake. became.

The cake is round. We made radial cuts from a point, cut the cake into N pieces, and numbered the pieces counterclockwise from 1 to N. That is, for 1 ≤ i ≤ N, the i-th piece is adjacent to the i − 1st and i + 1st pieces (though the 0th is considered to be the Nth and the N + 1st is considered to be the 1st). The size of the i-th piece was Ai, but I was so bad at cutting that all Ai had different values.

<image>
Figure 1: Cake example (N = 5, A1 = 2, A2 = 8, A3 = 1, A4 = 10, A5 = 9)

I decided to divide these N pieces by JOI-kun and IOI-chan. I decided to divide it as follows:

1. First, JOI chooses and takes one of N.
2. After that, starting with IOI-chan, IOI-chan and JOI-kun alternately take the remaining pieces one by one. However, if you can only take a piece that has already been taken at least one of the pieces on both sides, and there are multiple pieces that can be taken, IOI will choose the largest one and JOI will take it. You can choose what you like.

JOI wants to maximize the total size of the pieces he will finally take.

Task

Given the number N of cake pieces and the size information of N pieces, create a program to find the maximum value of the total size of pieces that JOI can take.

input

Read the following input from standard input.

* The integer N is written on the first line, which means that the cake is cut into N pieces.
* The integer Ai is written on the i-th line (1 ≤ i ≤ N) of the following N lines, which indicates that the size of the i-th piece is Ai.

output

Output an integer representing the maximum value of the total size of pieces that JOI can take to the standard output on one line.

Limits

All input data satisfy the following conditions.

* 1 ≤ N ≤ 20000.
* 1 ≤ Ai ≤ 1 000 000 000.
* Ai are all different.

Input / output example

Input example 1

Five
2
8
1
Ten
9

Output example 1

18

JOI is best to take the pieces as follows.

1. JOI takes the second piece. The size of this piece is 8.
2. IOI takes the first piece. The size of this piece is 2.
3. JOI takes the 5th piece. The size of this piece is 9.
4. IOI takes the 4th piece. The size of this piece is 10.
5. JOI takes the third piece. The size of this piece is 1.

Finally, the total size of the pieces taken by JOI is 8 + 9 + 1 = 18.

Input example 2

8
1
Ten
Four
Five
6
2
9
3

Output example 2

26

Input example 3

15
182243672
10074562
977552215
122668426
685444213
3784162
463324752
560071245
134465220
21447865
654556327
183481051
20041805
405079805
564327789

Output example 3

3600242976

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

Example

Input

5
2
8
1
10
9

Output

18

### Response

```cpp
#include <cstdio>
#include <algorithm>
#include <vector>
#include <deque>
#include <cstdint>

int main() {
  int N;
  scanf("%d", &N);

  std::vector<intmax_t> A(N);
  for (int i=0; i<N; ++i)
    scanf("%jd", &A[i]);

  if (N == 1) {
    printf("%jd\n", A[0]);
    return 0;
  } else if (N == 2) {
    printf("%jd\n", std::max(A[0], A[1]));
    return 0;
  }

  std::vector<std::vector<intmax_t>> dp(N, std::vector<intmax_t>(N));
  for (int i=0; i<N; ++i) {
    dp[i][i] = A[i];
  }

  // XXX half-open interval is better than this...
  for (int i=1; i<N; ++i) {
    for (int j=0; j<N; ++j) {
      // dp[j][(i+j)%N]; haba: i, hidari: j
      // l_next, [l_cur, ..., r_cur], r_next
      int l_cur=j, r_cur=(l_cur+i+N-1)%N;
      int l_next=(l_cur-1+N)%N, r_next=(r_cur+1)%N;
      if (l_cur == r_next) {
        continue;
      }
      if (i % 2 == 0) {
        // JOI
        dp[l_cur][r_next] = std::max(dp[l_cur][r_next], dp[l_cur][r_cur]+A[r_next]);
        dp[l_next][r_cur] = std::max(dp[l_next][r_cur], dp[l_cur][r_cur]+A[l_next]);
      } else {
        // IOI
        if (A[l_next] > A[r_next]) {
          // ... eats A[l_next]
          dp[l_next][r_cur] = std::max(dp[l_next][r_cur], dp[l_cur][r_cur]);
        } else {
          dp[l_cur][r_next] = std::max(dp[l_cur][r_next], dp[l_cur][r_cur]);
        }
      }
    }
  }

#if 0
  for (int i=0; i<N; ++i) {
    for (int j=0; j<N; ++j) {
      printf("%jd%c", dp[j][(j+i)%N], j+1<N? ' ':'\n');
    }
  }
#endif

  intmax_t res=0;
  for (int i=0; i<N; ++i)
    res = std::max(res, *std::max_element(dp[i].begin(), dp[i].end()));

  printf("%jd\n", res);
  return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element and the digit of the sum at that position are the same. If that holds for every position, then the multiset is balanced. Otherwise it's unbalanced.

For example, multiset \{20, 300, 10001\} is balanced and multiset \{20, 310, 10001\} is unbalanced:

<image>

The red digits mark the elements and the positions for which these elements have the same digit as the sum. The sum of the first multiset is 10321, every position has the digit required. The sum of the second multiset is 10331 and the second-to-last digit doesn't appear in any number, thus making the multiset unbalanced.

You are given an array a_1, a_2, ..., a_n, consisting of n integers.

You are asked to perform some queries on it. The queries can be of two types:

  * 1~i~x — replace a_i with the value x;
  * 2~l~r — find the unbalanced subset of the multiset of the numbers a_l, a_{l + 1}, ..., a_r with the minimum sum, or report that no unbalanced subset exists.

Note that the empty multiset is balanced.

For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of elements in the array and the number of queries, respectively.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i < 10^9).

Each of the following m lines contains a query of one of two types:

  * 1~i~x (1 ≤ i ≤ n, 1 ≤ x < 10^9) — replace a_i with the value x;
  * 2~l~r (1 ≤ l ≤ r ≤ n) — find the unbalanced subset of the multiset of the numbers a_l, a_{l + 1}, ..., a_r with the lowest sum, or report that no unbalanced subset exists.

It is guaranteed that there is at least one query of the second type.

Output

For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.

Example

Input

4 5
300 10001 20 20
2 1 3
1 1 310
2 1 3
2 3 3
2 3 4

Output

-1
330
-1
40

Note

All the subsets of multiset \{20, 300, 10001\} are balanced, thus the answer is -1.

The possible unbalanced subsets in the third query are \{20, 310\} and \{20, 310, 10001\}. The lowest sum one is \{20, 310\}. Note that you are asked to choose a subset, not a subsegment, thus the chosen elements might not be adjancent in the array.

The fourth query includes only the empty subset and subset \{20\}. Both of them are balanced.

The last query includes the empty subset and the subsets \{20\}, \{20\} and \{20, 20\}. Only \{20, 20\} is unbalanced, its sum is 40. Note that you are asked to choose a multiset, thus it might include equal elements.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 1e9 + 10;
pair<int, int> seg[2 * N][10];
int n, q, x, typ, l, r;
const pair<int, int> def = {inf, inf};
pair<int, int> merge(pair<int, int>& a, pair<int, int>& b) {
  pair<int, int> res = def;
  res.first = min(a.first, b.first);
  if (a.first < b.first)
    res.second = min(a.second, b.first);
  else
    res.second = min(b.second, a.first);
  return res;
}
int query(int L, int R) {
  pair<int, int> final = def;
  for (int i = 0; i < 10; i++) {
    pair<int, int> ans = def;
    for (int lh = L + n, rh = R + n; lh < rh; lh >>= 1, rh >>= 1) {
      if (lh & 1) ans = merge(ans, seg[lh++][i]);
      if (rh & 1) ans = merge(ans, seg[--rh][i]);
    }
    if (ans.first >= inf || ans.second >= inf) continue;
    if (ans.first + ans.second < final.first + final.second) final = ans;
  }
  if (final.first >= inf || final.second >= inf) return -1;
  return (final.first + final.second);
}
void update(int id, int val) {
  int cop = val, len = 0;
  vector<int> digit(10, 0);
  id += n;
  while (cop) {
    digit[len++] = cop % 10;
    cop /= 10;
  }
  for (int i = 0; i < 10; i++) {
    seg[id][i] = def;
    if (digit[i] > 0) seg[id][i].first = val;
    for (int j = id; j >= 1; j >>= 1)
      seg[j >> 1][i] = merge(seg[j][i], seg[j ^ 1][i]);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> x;
    update(i, x);
  }
  while (q--) {
    cin >> typ >> l >> r;
    if (typ == 1)
      update(l - 1, r);
    else
      cout << query(l - 1, r) << "\n";
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun.

We have a 4x4 board and 8 pairs of cards (denoted by `A' to `H') for the concentration game:

+---+---+---+---+
|   |   |   |   |   A A B B
+---+---+---+---+   C C D D
|   |   |   |   |   E E F F
+---+---+---+---+   G G H H
|   |   |   |   |
+---+---+---+---+
|   |   |   |   |
+---+---+---+---+

To start the game, it is necessary to arrange all 16 cards face down on the board. For example:

+---+---+---+---+
| A | B | A | B |
+---+---+---+---+
| C | D | C | D |
+---+---+---+---+
| E | F | G | H |
+---+---+---+---+
| G | H | E | F |
+---+---+---+---+

The purpose of the concentration game is to expose as many cards as possible by repeatedly performing the following procedure: (1) expose two cards, (2) keep them open if they match or replace them face down if they do not.

Since the arrangements should be simple, every pair of cards on the board must obey the following condition: the relative position of one card to the other card of the pair must be one of 4 given relative positions. The 4 relative positions are different from one another and they are selected from the following 24 candidates:

(1, 0), (2, 0), (3, 0),
(-3, 1), (-2, 1), (-1, 1), (0, 1), (1, 1), (2, 1), (3, 1),
(-3, 2), (-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (3, 2),
(-3, 3), (-2, 3), (-1, 3), (0, 3), (1, 3), (2, 3), (3, 3).

Your job in this problem is to write a program that reports the total number of board arrangements which satisfy the given constraint. For example, if relative positions (-2, 1), (-1, 1), (1, 1), (1, 2) are given, the total number of board arrangements is two, where the following two arrangements satisfy the given constraint:

X0  X1  X2  X3             X0  X1  X2  X3
+---+---+---+---+          +---+---+---+---+
Y0 | A | B | C | D |       Y0 | A | B | C | D |
+---+---+---+---+          +---+---+---+---+
Y1 | B | A | D | C |       Y1 | B | D | E | C |
+---+---+---+---+          +---+---+---+---+
Y2 | E | F | G | H |       Y2 | F | A | G | H |
+---+---+---+---+          +---+---+---+---+
Y3 | F | E | H | G |       Y3 | G | F | H | E |
+---+---+---+---+          +---+---+---+---+
the relative positions:    the relative positions:
A:(1, 1),  B:(-1, 1)       A:(1, 2),  B:(-1, 1)
C:(1, 1),  D:(-1, 1)       C:(1, 1),  D:(-2, 1)
E:(1, 1),  F:(-1, 1)       E:(1, 2),  F:( 1, 1)
G:(1, 1),  H:(-1, 1)       G:(-2, 1), H:(-1, 1)

Arrangements of the same pattern should be counted only once. Two board arrangements are said to have the same pattern if they are obtained from each other by repeatedly making any two pairs exchange their positions. For example, the following two arrangements have the same pattern:

X0  X1  X2  X3           X0  X1  X2  X3
+---+---+---+---+        +---+---+---+---+
Y0 | H | G | F | E |     Y0 | A | B | C | D |
+---+---+---+---+        +---+---+---+---+
Y1 | G | E | D | F |     Y1 | B | D | E | C |
+---+---+---+---+        +---+---+---+---+
Y2 | C | H | B | A |     Y2 | F | A | G | H |
+---+---+---+---+        +---+---+---+---+
Y3 | B | C | A | D |     Y3 | G | F | H | E |
+---+---+---+---+        +---+---+---+---+

where (1) `A' and `H', (2) `B' and `G', (3) `C' and `F', and (4) `D' and `E' exchange their positions respectively.

Input

The input contains multiple data sets, each representing 4 relative positions. A data set is given as a line in the following format.

x1| y1 | x2| y2 | x3| y3 | x4| y4
---|---|---|---|---|---|---|---

The i-th relative position is given by (xi, yi). You may assume that the given relative positions are different from one another and each of them is one of the 24 candidates.

The end of input is indicated by the line which contains a single number greater than 4.

Output

For each data set, your program should output the total number of board arrangements (or more precisely, the total number of patterns).

Each number should be printed in one line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.

Examples

Input

Output

Input

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

Output

2
15

### Response

```cpp
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <string,string> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

int tx[4],ty[4];

int dfs(int stage,int c){
	if(c==8) return 1;

	int res = 0;
	int sx = -1;
	int sy = -1;
	for(int y=0;y<4;y++){
		for(int x=0;x<4;x++){
			if(~stage & (1<<(y*4+x))){
				sx = x;
				sy = y;
				goto found;
			}
		}
	}
found:;

	if(sx == -1) return 0;

	for(int i=0;i<4;i++){
		int dx = sx + tx[i];
		int dy = sy + ty[i];
		if(dx < 0 || dx >= 4 || dy < 0 || dy >= 4) continue;
		if(stage & (1<<(dy*4+dx))) continue;

		stage |= (1<<(dy*4+dx));
		stage |= (1<<(sy*4+sx));
		res += dfs(stage,c+1);
		stage &= ~(1<<(dy*4+dx));
		stage &= ~(1<<(sy*4+sx));
	}

	return res;
}

int main(){

	while(~scanf("%d",tx+0)){
		if(tx[0] >= 5) break;
		scanf("%d %d %d %d %d %d %d",ty+0,tx+1,ty+1,tx+2,ty+2,tx+3,ty+3);
		printf("%d\n",dfs(0,0));
	}
}
```


### Prompt

Create a solution in CPP for the following problem:

Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.

For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that:

  * there wouldn't be a pair of any side-adjacent cards with zeroes in a row;
  * there wouldn't be a group of three consecutive cards containing numbers one.

Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.

Input

The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.

Output

In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.

Examples

Input

1 2

Output

101

Input

4 8

Output

110110110101

Input

4 10

Output

11011011011011

Input

1 5

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double pi = 3.1415926536;
const int oo = (int)1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int di[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dj[] = {1, -1, 0, 0, 1, -1, 1, -1};
int arr[1000001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  bool check = true;
  string s;
  int counter = 0;
  while (n--) {
    if (check && m >= 2)
      s += "101", m -= 2, check = false;
    else if (m && !check)
      s += "01", m -= 1;
    else if (!n)
      s += '0';
    else
      counter++;
  }
  check = true;
  if (counter > 1) check = false;
  if (m < 0) {
    check = false;
  }
  bool enter = true;
  string final_answer;
  if (counter) final_answer += '0';
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (m && enter) final_answer += '1', m--, enter = false;
    final_answer += s[i];
    if (s[i] == '0') enter = true;
  }
  if (m > 0) check = false;
  if (!check) {
    cout << -1;
  } else
    cout << final_answer;
}

```


### Prompt

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

You are given an array s of n non-negative integers.

A 5-tuple of integers (a, b, c, d, e) is said to be valid if it satisfies the following conditions:

  * 1 ≤ a, b, c, d, e ≤ n
  * (sa | sb) & sc & (sd ^ se) = 2i for some integer i
  * sa & sb = 0

Here, '|' is the bitwise OR, '&' is the bitwise AND and '^' is the bitwise XOR operation.

Find the sum of f(sa|sb) * f(sc) * f(sd^se) over all valid 5-tuples (a, b, c, d, e), where f(i) is the i-th Fibonnaci number (f(0) = 0, f(1) = 1, f(i) = f(i - 1) + f(i - 2)).

Since answer can be is huge output it modulo 109 + 7.

Input

The first line of input contains an integer n (1 ≤ n ≤ 106).

The second line of input contains n integers si (0 ≤ si < 217).

Output

Output the sum as described above, modulo 109 + 7

Examples

Input

2
1 2

Output

32

Input

3
7 4 1

Output

3520

Input

10
1 3 0 7 3 7 6 5 7 5

Output

1235424

Input

10
50 9 11 44 39 40 5 39 23 7

Output

113860062

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int B = 17;
const int N = 1 << B;
const long long int M = (int)1e9 + 7;
const long long int inv2 = (int)5e8 + 4;
int n;
long long int cnt[N], fib[N], ab[N], Xor[N], And[N];
void transform_xor(long long int x[], bool inv = 0) {
  for (int mid = 1, i = 2; i <= N; mid = i, i <<= 1)
    for (int j = 0, lo = 0; lo < N; j + 1 == mid ? (lo += i, j = 0) : ++j) {
      long long int tw1 = x[lo + j], tw2 = x[lo + j + mid];
      if (inv) {
        x[lo + j] = (tw1 + tw2) % M * inv2 % M;
        x[lo + j + mid] = (tw1 - tw2 + M) % M * inv2 % M;
      } else {
        x[lo + j] = tw1 + tw2;
        if (x[lo + j] >= M) x[lo + j] -= M;
        x[lo + j + mid] = tw1 - tw2;
        if (x[lo + j + mid] < 0) x[lo + j + mid] += M;
      }
    }
}
void transform_and(long long int p[], bool inv = 0) {
  for (int len = 1; (len << 1) <= N; len <<= 1)
    for (int i = 0; i < N; i += (len << 1))
      for (int j = 0; j < len; ++j) {
        long long int tw1 = p[i + j];
        long long int tw2 = p[i + len + j];
        if (!inv) {
          p[i + j] = tw2;
          p[i + len + j] = tw1 + tw2;
          if (p[i + len + j] >= M) p[i + len + j] -= M;
        } else {
          p[i + j] = tw2 - tw1;
          if (p[i + j] < 0) p[i + j] += M;
          p[i + len + j] = tw1;
        }
      }
}
void solve(std::istream &in, std::ostream &out) {
  fib[0] = 0, fib[1] = 1;
  for (int i = 2; i < N; ++i) {
    fib[i] = fib[i - 1] + fib[i - 2];
    if (fib[i] >= M) fib[i] -= M;
  }
  in >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    in >> x;
    ++cnt[x];
  }
  for (int i = 0; i < N; ++i) {
    ab[i] = 0;
    for (int j = (i - 1) & i; j > 0; j = (j - 1) & i) {
      ab[i] += cnt[j] * cnt[j ^ i] % M;
      if (ab[i] >= M) ab[i] -= M;
    }
    if (cnt[0] && cnt[i]) {
      ab[i] += cnt[0] * cnt[i] * 2 % M;
      if (ab[i] >= M) ab[i] -= M;
    }
  }
  memcpy(Xor, cnt, sizeof cnt);
  transform_xor(Xor);
  for (int i = 0; i < N; ++i) Xor[i] = Xor[i] * Xor[i] % M;
  transform_xor(Xor, 1);
  for (int i = 0; i < N; ++i)
    Xor[i] = Xor[i] * fib[i] % M, ab[i] = ab[i] * fib[i] % M,
    cnt[i] = cnt[i] * fib[i] % M;
  transform_and(Xor);
  transform_and(ab);
  transform_and(cnt);
  for (int i = 0; i < N; ++i) And[i] = Xor[i] * ab[i] % M * cnt[i] % M;
  transform_and(And, 1);
  long long int ans = 0;
  for (int i = 1; i < N; i <<= 1) ans = (ans + And[i]) % M;
  out << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  solve(cin, cout);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

$N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours.

Constraints

* $ 1 \leq N \leq 10^5 $
* $ 1 \leq T \leq 10^5 $
* $ 0 \leq l_i < r_i \leq T $

Input

The input is given in the following format.

$N$ $T$
$l_1$ $r_1$
$l_2$ $r_2$
:
$l_N$ $r_N$

Output

Print the maximum number of persons in a line.

Examples

Input

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

Output

4

Input

2 2
0 1
1 2

Output

1

### Response

```cpp
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001

using namespace std;
#define ll long long
#define dbg if(0)

int main(){
    int n,t;
    ll ans=-1;
    cin>>n>>t;
    vector<ll> data(t,0);

    for(int i=0;i<n;i++){
        int in,out;
        cin>> in>>out;
        data[in]+=1;
        data[out]-=1;
    }
    ll rui[t+1];
    rui[0]=0;
    for(int i=1;i<=t;i++){
        rui[i]=rui[i-1]+data[i-1];
        dbg cout<<rui[i]<<" ";
        ans=max(rui[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}

```