#include <bits/stdc++.h>
 const bool debug = false;
 int triple[1 << 12][3];
 int use[1 << 12];
 int cost[1 << 12];
 std::vector<int> gen_masks(int L) {
   std::vector<int> masks;
   masks.push_back(0);
   for (int i = 0; i < L; i++) {
     for (int j = 1; j < L; j++) {
       if (i + j * 2 >= L) continue;
       masks.push_back((1 << i) | (1 << (i + j)) | (1 << (i + 2 * j)));
     }
   }
   return masks;
 }
 int as[100005];
 int main() {
   std::vector<int> masks = gen_masks(12);
   for (int u : masks) {
     for (int v : masks) {
       for (int w : masks) {
         int res = (u ^ v ^ w) & ((1 << 9) - 1);
         triple[res][0] = u;
         triple[res][1] = v;
         triple[res][2] = w;
       }
     }
   }
   std::vector<std::array<int, 3> > moves;
   int NN;
   scanf( d , &NN);
   int N = NN;
   for (int i = 1; i <= N; i++) {
     scanf( d , &as[i]);
   }
   while (N >= 12) {
     int M = 0;
     for (int i = 0; i < 9; i++) {
       M |= (as[N - i] << i);
     }
     for (int t = 0; t < 3; t++) {
       std::array<int, 3> move;
       int index = 0;
       for (int i = 0; i < 12; i++) {
         if (triple[M][t] & (1 << i)) {
           as[N - i] ^= 1;
           move[index++] = N - i;
         }
       }
       if (index) {
         assert(index == 3);
         moves.push_back(move);
       }
     }
     N -= 9;
   }
   N = std::min(NN, 12);
   masks = gen_masks(N);
   for (int i = 1; i < (1 << N); i++) {
     cost[i] = 1e9;
   }
   for (int mask : masks) {
     for (int i = 0; i < (1 << N); i++) {
       if (cost[i ^ mask] > cost[i] + 1) {
         cost[i ^ mask] = cost[i] + 1;
         use[i ^ mask] = mask;
       }
     }
   }
   if (debug) {
     int worst = 0;
     for (int i = 0; i < (1 << N); i++) {
       if (cost[i] < 1e9) worst = std::max(worst, cost[i]);
       printf( d:  , i);
       for (int k = 0; k < N; k++) {
         printf( d , (use[i] >> k) & 1);
       }
       printf(
 );
     }
     printf( WORST: d
 , worst);
   }
   while (true) {
     int M = 0;
     for (int i = 0; i < N; i++) {
       M |= (as[N - i] << i);
     }
     if (M == 0) break;
     std::array<int, 3> move;
     int index = 0;
     for (int i = 0; i < 12; i++) {
       if (use[M] & (1 << i)) {
         as[N - i] ^= 1;
         move[index++] = N - i;
       }
     }
     if (index == 0) {
       printf( NO
 );
       return 0;
     }
     assert(index == 3);
     moves.push_back(move);
   }
   for (int i = 0; i < N; i++) {
     assert(as[i] == 0);
   }
   printf( YES
 );
   printf( d
 , (int)moves.size());
   for (auto move : moves) {
     printf( d d d
 , move[0], move[1], move[2]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k, a[100010], b[100010], c[100010];
 void nhap() {
   scanf( dd , &n, &k);
   for (int i = 1; i <= n; i++) scanf( d , &c[i]);
   int dem = 1;
   a[1] = c[1];
   for (int i = 2; i <= n; i++)
     if (c[i] != a[dem]) {
       dem++;
       a[dem] = c[i];
     }
   n = dem;
 }
 void xuli() {
   a[0] = 0;
   a[n + 1] = 0;
   memset(b, 0, sizeof b);
   for (int i = 1; i <= n; i++)
     if (a[i - 1] == a[i + 1])
       b[a[i]] += 2;
     else
       b[a[i]]++;
   int dem = 0, kq;
   for (int i = 1; i <= k; i++)
     if (dem < b[i]) dem = b[i], kq = i;
   cout << kq;
 }
 int main() {
   if (0) {
     freopen( input.txt ,  r , stdin);
     freopen( output.txt ,  w , stdout);
   };
   nhap();
   xuli();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main(void) {
   long n, m, l, r;
   vector<long> a(100005);
   map<long, vector<long> >::iterator mi;
   vector<long>::iterator vi1, vi2;
   map<long, vector<long> > hash;
   scanf( ld ld , &n, &m);
   for (long i = 0; i < n; i++) {
     scanf( ld , &a[i]);
     if (hash.find(a[i]) != hash.end())
       hash[a[i]].push_back(i);
     else {
       vector<long> v;
       v.push_back(i);
       hash[a[i]] = v;
     }
   }
   mi = hash.begin();
   while (mi != hash.end()) {
     if (mi->first > mi->second.size()) {
       long temp = mi->first;
       mi++;
       hash.erase(hash.find(temp));
     } else
       mi++;
   }
   long diff = r - l + 1, count = 0;
   long first, last;
   for (long i = 0; i < m; i++) {
     scanf( ld ld , &l, &r);
     diff = r - l + 1, count = 0;
     mi = hash.begin();
     while (mi->first <= diff && mi != hash.end()) {
       vi1 = upper_bound(mi->second.begin(), mi->second.end(), r - 1);
       vi2 = lower_bound(
           mi->second.begin(),
           mi->second.end() - ((mi->first - 3 > 0) ? (mi->first - 3) : 0),
           l - 1);
       last = vi1 - mi->second.begin(), first = vi2 - mi->second.begin();
       if (last - first == mi->first) count++;
       mi++;
     }
     printf( ld
 , count);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int __SIZE = 1 << 18;
 char ibuf[__SIZE], *iS, *iT;
 template <typename T>
 inline void read(T &x) {
   char ch, t = 0;
   x = 0;
   while (!isdigit(ch = (iS == iT
                             ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                                (iS == iT ? EOF : *iS++))
                             : *iS++)))
     t |= ch == '-';
   while (isdigit(ch))
     x = x * 10 + (ch ^ 48),
     ch = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                    : *iS++);
   x = t ? -x : x;
 }
 inline int read_int() {
   int x;
   return read(x), x;
 }
 inline long long read_ll() {
   long long x;
   return read(x), x;
 }
 template <typename T>
 inline void chkmin(T &a, T b) {
   a = a < b ? a : b;
 }
 template <typename T>
 inline void chkmax(T &a, T b) {
   a = a > b ? a : b;
 }
 const int MAXN = 150010;
 const int mod = 998244353;
 inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
 inline int Mod(int x) { return x >= mod ? x - mod : x; }
 inline int fsp(int x, int k = mod - 2) {
   int s = 1;
   while (k) {
     if (k & 1) s = 1LL * s * x  mod;
     x = 1LL * x * x  mod, k >>= 1;
   }
   return s;
 }
 inline long long S(long long x, long long k) { return (x + x + k - 1) * k / 2; }
 inline long long find(long long x, long long k) {
   if (!x) return k * (k + 1) >> 1;
   long long p = find(x / k, k), rest = x  k;
   long long st = (x / k) * (k * k + 1) + rest * k + 1;
   if (st + k <= p)
     return S(st, k);
   else
     return S(st, k) + min(k, st + k - p);
 }
 inline void Solve() {
   long long n = read_ll(), k = read_int(), bel = (n - 1) / (k * k + 1);
   long long p = find(bel, k);
   if (p == n)
     cout << (bel + 1) * (k + 1) << endl;
   else {
     long long pos = n - bel - 1 + (n < p);
     long long t = (n - 1)  (k * k + 1) + 1;
     long long cnt = bel * k + (t - 1 - (n >= p)) / k;
     cout << pos + cnt << endl;
   }
 }
 int main() {
   int Case = read_int();
   while (Case--) Solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, x, y;
   cin >> n;
   int mx = 0;
   for (int i = 0; i < n; i++) {
     cin >> x >> y;
     mx = max(mx, (x + y));
   }
   cout << mx << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   scanf( d , &n);
   int arr[n];
   int unos = 0;
   for (int i = 0; i < n; i++) {
     scanf( d , &arr[i]);
     if (arr[i]) unos++;
   }
   int fin = 0;
   for (int i = 0; i < n; i++) {
     int total = unos;
     for (int j = i; j < n; j++) {
       if (arr[j])
         total--;
       else
         total++;
       fin = max(fin, total);
     }
   }
   printf( d , fin);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 unsigned int n, i, f, p, s, rez;
 int main() {
   cin >> n;
   f = 1;
   for (i = 1; i <= n; i++) f = ((unsigned long long)f * i)  998244353;
   f = ((unsigned long long)f * n)  998244353;
   p = 1;
   s = 0;
   for (i = n; i >= 2; i--) {
     p = ((unsigned long long)p * i)  998244353;
     s = (s + p)  998244353;
   }
   rez = (f - s + 998244353)  998244353;
   cout << rez;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long calc_2(int s) {
   if (s < 0) return 0;
   return 1LL * (s + 1) * (s + 2) / 2;
 }
 long long calc_3(int s) {
   if (s < 0) return 0;
   long long ans = 0;
   for (int i = 0; i <= s; i++) ans += calc_2(s - i);
   return ans;
 }
 int val[5];
 int main() {
   int a, b, c, L;
   scanf( dddd , &a, &b, &c, &L);
   val[1] = a - b - c, val[2] = b - a - c, val[3] = c - a - b;
   long long ans = calc_3(L);
   for (int i = 1; i <= 3; i++) {
     for (int z = 0; z <= L; z++) {
       int ed = min(L - z, val[i] + z);
       ans -= calc_2(ed);
     }
   }
   printf( extra
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int nmax = 26;
 int cost[nmax][3];
 const int l = 0, m = 1, w = 2;
 map<pair<int, int>, pair<string, int> > myMap;
 pair<string, long long> global;
 bool ok = 0;
 void firstHalf(int a, int b, int c, string s) {
   if (myMap.count({a - b, b - c}) == 0 || myMap[{a - b, b - c}].second < a) {
     myMap[{a - b, b - c}] = {s, a};
   }
 }
 void findMatch(int a, int b, int c, string s) {
   if (myMap.count({b - a, c - b}) != 0) {
     int ans = myMap[{b - a, c - b}].second + a;
     string fin = myMap[{b - a, c - b}].first + s;
     if (ans > global.second) {
       ok = 1;
       global = {fin, ans};
     }
   }
 }
 void solve(int i, const int stop, void (*op)(int, int, int, string), int a,
            int b, int c, string s) {
   if (i == stop + 1) {
     op(a, b, c, s);
     return;
   }
   solve(i + 1, stop, op, a + cost[i][l], b + cost[i][m], c, s +  LM
 );
   solve(i + 1, stop, op, a + cost[i][l], b, c + cost[i][w], s +  LW
 );
   solve(i + 1, stop, op, a, b + cost[i][m], c + cost[i][w], s +  MW
 );
 }
 int main() {
   int n;
   cin >> n;
   for (int i = 1; i <= n; ++i) cin >> cost[i][l] >> cost[i][m] >> cost[i][w];
   global.second = -26 * 10e7;
   string pl;
   solve(1, n / 2, &firstHalf, 0, 0, 0, pl);
   solve(n / 2 + 1, n, &findMatch, 0, 0, 0, pl);
   if (ok)
     cout << global.first;
   else
     cout <<  Impossible ;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int t;
   cin >> t;
   for (int i = 0; i < t; i++) {
     int n;
     cin >> n;
     long long mn = 1e9, mx = -1e9;
     long long a[n];
     for (int j = 0; j < n; j++) {
       cin >> a[j];
       mn = min(a[j], mn);
       mx = max(a[j], mx);
     }
     long long x = mn * mx;
     int ans = 1;
     set<long long> s;
     for (int j = 2; j <= sqrt(x); j++) {
       if (x  j == 0) {
         s.insert(j);
         s.insert(x / j);
       }
     }
     int cnt = 0;
     for (int j = 0; j < n; j++) {
       if (x  a[j] == 0) {
         cnt++;
       } else {
         cnt = -1;
         break;
       }
     }
     if (cnt != s.size()) {
       cout << -1 << endl;
     } else
       cout << x << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 class IntTree {
  public:
   IntTree(int size) : nodes_(4 * size + 10, 0), size_(size) {}
   void Set(int pos, char ch) { Set(0, 1, size_, pos, ch); }
   int Count(int left, int right) {
     int mask = Mask(0, 1, size_, left, right);
     return CountBits(mask);
   }

  private:
   static int Left(int node) { return 2 * node + 1; }
   static int Right(int node) { return 2 * node + 2; }
   static int CountBits(int num);
   void Set(int node, int left, int right, int pos, char ch);
   int Mask(int node, int left, int right, int x, int y);
   vector<int> nodes_;
   int size_;
 };
 int IntTree::CountBits(int num) {
   int count = 0;
   while (num > 0) {
     count += 1;
     num -= (num & -num);
   }
   return count;
 }
 void IntTree::Set(int node, int left, int right, int pos, char ch) {
   if (left == right) {
     nodes_[node] = (1 << (ch - 'a'));
     return;
   }
   int mid = left + (right - left) / 2;
   if (pos <= mid) {
     Set(Left(node), left, mid, pos, ch);
   } else {
     Set(Right(node), mid + 1, right, pos, ch);
   }
   nodes_[node] = (nodes_[Left(node)] | nodes_[Right(node)]);
 }
 int IntTree::Mask(int node, int left, int right, int x, int y) {
   if (x <= left && right <= y) {
     return nodes_[node];
   }
   int mask = 0;
   int mid = left + (right - left) / 2;
   if (x <= mid) {
     mask |= Mask(Left(node), left, mid, x, y);
   }
   if (mid < y) {
     mask |= Mask(Right(node), mid + 1, right, x, y);
   }
   return mask;
 }
 int main() {
   string str;
   getline(cin, str);
   IntTree tree(str.size());
   for (size_t i = 0; i < str.size(); i += 1) {
     tree.Set(i + 1, str[i]);
   }
   int queries;
   cin >> queries;
   for (int i = 0; i < queries; i += 1) {
     int type, x, y;
     char ch;
     cin >> type;
     if (type == 1) {
       cin >> x >> ch;
       tree.Set(x, ch);
     } else {
       cin >> x >> y;
       cout << tree.Count(x, y) <<
 ;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using LL = long long;
 constexpr int N = 155;
 int in[N][N];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= n; j++) {
       cin >> in[i][j];
     }
   }
   vector<int> ans(N);
   for (int v = 1; v < n; v++) {
     for (int i = 1; i <= n; i++) {
       bool f1 = false;
       bool f2 = true;
       for (int j = 1; j <= n; j++) {
         if (in[i][j] == v)
           f1 = true;
         else {
           if (in[i][j] != -1 and in[i][j] != 0) f2 = false;
         }
       }
       if (f1 && f2) {
         ans[i] = v;
         for (int j = 1; j <= n; j++) in[i][j] = in[j][i] = -1;
         break;
       }
     }
   }
   for (int i = 1; i <= n; i++) cout << (ans[i] == 0 ? n : ans[i]) << ' ';
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1e5 + 9;
 int n;
 int mp[9];
 bool done[109];
 vector<pair<long long, pair<long long, long long> > > v[109];
 void dfs(int node) {
   done[node] = 1;
   for (int i = 0; i < v[node].size(); i++) {
     int u = v[node][i].first;
     int e = v[node][i].second.first;
     int f = v[node][i].second.second;
     if (done[u]) continue;
     mp[f] += e, dfs(u);
   }
 }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cin >> n;
   for (int i = 0; i < n; i++) {
     int a, b, c;
     cin >> a >> b >> c;
     a--;
     b--;
     v[a].push_back({b, {c, 1}});
     v[b].push_back({a, {c, 0}});
   }
   dfs(0);
   mp[1 - v[0][1].second.second] += v[0][1].second.first;
   cout << min(mp[1], mp[0]) << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 200000 + 10;
 const long long INF = 1e18;
 int n, q;
 struct Edge {
   int u, v;
   long long w;
   Edge(int _u = 0, int _v = 0, long long _w = 0) : u(_u), v(_v), w(_w) {}
 };
 vector<Edge> E;
 int E_size;
 vector<int> G[N];
 int ptr[2 * N];
 void adjListInit(int l, int r) {
   E.clear();
   E_size = 0;
   for (int i = l; i <= r; i++) G[i].clear();
 }
 void addEdge(int u, int v, long long w, int i) {
   E.push_back(Edge(u, v, w));
   E_size++;
   ptr[i] = E_size - 1;
   G[u].push_back(E_size - 1);
 }
 vector<Edge> Eback;
 int Gback[N];
 int Eback_size;
 long long dist[N];
 int in[N], out[N];
 int peg[N];
 int dfs_clock;
 inline void dfsInit() {
   dist[1] = 0;
   dfs_clock = 0;
 }
 void dfs(int u, int pre) {
   in[u] = ++dfs_clock;
   peg[in[u]] = u;
   for (int i = 0; i < G[u].size(); i++) {
     Edge e = E[G[u][i]];
     int v = e.v;
     if (v == pre) continue;
     dist[v] = dist[u] + e.w;
     dfs(v, u);
   }
   out[u] = dfs_clock;
 }
 struct Node {
   int l, r;
   long long val, lazy;
   void update(long long x) { val += x, lazy += x; }
 } node[N << 2];
 inline void pushdown(int rt) {
   if (node[rt].lazy) {
     node[rt << 1].update(node[rt].lazy);
     node[rt << 1 | 1].update(node[rt].lazy);
     node[rt].lazy = 0;
   }
 }
 inline void pushup(int rt) {
   node[rt].val = min(node[rt << 1].val, node[rt << 1 | 1].val);
 }
 void build(int root, int l, int r) {
   node[root].l = l;
   node[root].r = r;
   node[root].val = 0;
   node[root].lazy = 0;
   if (l == r) {
     int p = peg[l];
     node[root].val = dist[p] + Eback[Gback[p]].w;
   } else {
     int mid = l + (r - l) / 2;
     build(root * 2, l, mid);
     build(root * 2 + 1, mid + 1, r);
     pushup(root);
   }
 }
 void update(int root, int st, int ed, int val) {
   if (st > node[root].r || ed < node[root].l) return;
   if (st <= node[root].l && node[root].r <= ed)
     node[root].update(val);
   else {
     pushdown(root);
     update(root * 2, st, ed, val);
     update(root * 2 + 1, st, ed, val);
     pushup(root);
   }
 }
 long long query(int root, int st, int ed) {
   if (ed < node[root].l || node[root].r < st) return INF;
   if (st <= node[root].l && node[root].r <= ed)
     return node[root].val;
   else {
     pushdown(root);
     long long lson = query(root * 2, st, ed);
     long long rson = query(root * 2 + 1, st, ed);
     pushup(root);
     return min(lson, rson);
   }
 }
 int main() {
   cin >> n >> q;
   adjListInit(1, n);
   for (int i = 1; i <= n - 1; i++) {
     int a, b;
     long long c;
     scanf( ddextra , &a, &b, &c);
     addEdge(a, b, c, i);
   }
   dfsInit();
   dfs(1, -1);
   Eback.clear();
   Eback_size = 0;
   for (int i = n, a, b, c; i <= 2 * n - 2; i++) {
     scanf( ddd , &a, &b, &c);
     Eback.push_back(Edge(a, b, c));
     Eback_size++;
     ptr[i] = Eback_size - 1;
     Gback[a] = Eback_size - 1;
   }
   Eback.push_back(Edge(1, 1, 0));
   Eback_size++;
   Gback[1] = Eback_size - 1;
   build(1, 1, n);
   for (int i = 1, type; i <= q; i++) {
     scanf( d , &type);
     if (type == 1) {
       int id;
       long long w;
       scanf( dextra , &id, &w);
       if (id < n) {
         Edge &e = E[ptr[id]];
         update(1, in[e.v], out[e.v], w - e.w);
         e.w = w;
       } else {
         Edge &e = Eback[ptr[id]];
         update(1, in[e.u], in[e.u], w - e.w);
         e.w = w;
       }
     }
     if (type == 2) {
       int u, v;
       scanf( dd , &u, &v);
       if (in[u] <= in[v] && in[v] <= out[u]) {
         long long du = query(1, in[u], in[u]) - Eback[Gback[u]].w;
         long long dv = query(1, in[v], in[v]) - Eback[Gback[v]].w;
         printf( extra
 , dv - du);
       } else {
         long long ans = query(1, in[u], out[u]);
         long long du = query(1, in[u], in[u]) - Eback[Gback[u]].w;
         long long dv = query(1, in[v], in[v]) - Eback[Gback[v]].w;
         ans -= du;
         ans += dv;
         printf( extra
 , ans);
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<long long int> a[100004];
 int p[100004];
 int v[100004];
 long long int c[100004];
 struct sajal {
   long long int add, sub, d;
 };
 sajal d[100004];
 int main() {
   long n;
   cin >> n;
   long x, y;
   for (long i = 1; i < n; i++) {
     cin >> x >> y;
     a[x].push_back(y);
     a[y].push_back(x);
   }
   queue<long> q;
   q.push(1);
   p[1] = 1;
   while (!q.empty()) {
     long f = q.front();
     q.pop();
     v[f] = 1;
     for (long i = 0; i < a[f].size(); i++) {
       if (v[a[f][i]] == 0) {
         v[a[f][i]] = 1;
         q.push(a[f][i]);
         p[a[f][i]] = f;
       }
     }
   }
   for (long i = 1; i <= n; i++) {
     cin >> c[i];
     d[i].add = 0;
     d[i].sub = 0;
     d[i].d = a[i].size();
     if (a[i].size() == 1 && i != 1) {
       q.push(i);
     }
   }
   long long int add = 0;
   long long int sub = 0;
   long cur = 1;
   while (!q.empty()) {
     long f = q.front();
     q.pop();
     long long int e = d[f].add - d[f].sub;
     long long int h = -c[f] - e;
     long long int w = p[f];
     if (h >= 0) {
       d[f].add = d[f].add + h;
     } else {
       h = -h;
       d[f].sub = h + d[f].sub;
     }
     if (d[f].sub > sub) sub = d[f].sub;
     if (d[f].add > add) add = d[f].add;
     if (d[w].sub < d[f].sub) d[w].sub = d[f].sub;
     if (d[w].add < d[f].add) d[w].add = d[f].add;
     d[w].d--;
     if (d[w].d == 1 && w != 1) {
       q.push(w);
     }
   }
   c[1] = c[1] + d[1].add - d[1].sub;
   c[1] = -c[1];
   if (c[1] >= 0) {
     d[1].add = d[1].add + c[1];
   } else {
     c[1] = -c[1];
     d[1].sub = d[1].sub + c[1];
   }
   if (add < d[1].add) add = d[1].add;
   if (sub < d[1].sub) sub = d[1].sub;
   cout << add + sub << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, l, r, x;
 string s;
 int main() {
   cin >> n >> m;
   r = 0;
   l = n + 1;
   for (int i = 0; i < m; ++i) {
     cin >> s;
     cin >> s;
     cin >> s;
     if (s ==  left ) {
       cin >> s >> x;
       l = min(l, x);
     } else {
       cin >> s >> x;
       r = max(r, x);
     }
   }
   if (l - r - 1 <= 0)
     cout << -1 << endl;
   else
     cout << l - r - 1 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   string intial, code;
   cin >> intial >> code;
   int res = 0;
   for (int i = 0; i < n; i++) {
     int a = (((intial[i] - '0') - (code[i] - '0')) + 10)  10;
     int b = (((code[i] - '0') - (intial[i] - '0')) + 10)  10;
     res += min(a, b);
   }
   cout << res;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int e[100010];
 int main() {
   int n, u, i, j = 3;
   double ans = 0;
   scanf( dd , &n, &u);
   for (i = 1; i <= n; i++) scanf( d , &e[i]);
   for (i = 1; i <= n; i++) {
     while (j <= n && e[j] - e[i] <= u) j++;
     j--;
     if (j > i + 1) ans = max(ans, (e[j] - e[i + 1] + 0.0) / (e[j] - e[i]));
   }
   if (ans == 0)
     cout << -1 << endl;
   else {
     cout.precision(19);
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int t;
   cin >> t;
   while (t--) {
     long long int temperature;
     long long int a12, b11;
     long long int solution;
     cin >> a12 >> b11;
     if (b11 == a12) {
       solution = 0;
     } else if (b11 > a12) {
       temperature = b11 - a12;
       if (temperature & 1) {
         solution = 1;
       } else {
         solution = 2;
       }
     } else {
       temperature = a12 - b11;
       if (temperature & 1) {
         solution = 2;
       } else {
         solution = 1;
       }
     }
     cout << solution <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 int a[26];
 int w[256];
 int n;
 int LIMIT = 1;
 int su[26], sv[26], sk[26];
 int go(int lev) {
   if (a[lev] == n) {
     printf( d
 , lev);
     for (int i = 0; i < lev; i++)
       if (su[i] == -1) {
         printf( lea ecx, [d*ecx]
 , 'a' + i + 1, 1 << sk[i], 'a' + sv[i]);
       } else if (sk[i] == 0)
         printf( lea ecx, [ecx + ecx]
 , 'a' + i + 1, 'a' + su[i],
                'a' + sv[i]);
       else
         printf( lea ecx, [ecx + d*ecx]
 , 'a' + i + 1, 'a' + su[i],
                1 << sk[i], 'a' + sv[i]);
     return 1;
   }
   if (lev >= LIMIT) return 0;
   int &i = su[lev], &j = sv[lev], &k = sk[lev];
   i = -1;
   for (j = 0; j <= lev; j++)
     for (k = 0; k <= 3; k++) {
       int v = (a[j] << k);
       if (v > a[lev] && v <= n) {
         a[lev + 1] = v;
         if (go(lev + 1)) return 1;
         a[lev + 1] = 0;
       }
     }
   for (i = 0; i <= lev; i++)
     for (j = 0; j <= lev; j++) {
       for (k = 0; k <= 3; k++) {
         int v = a[i] + (a[j] << k);
         if (v > a[lev] && v <= n) {
           a[lev + 1] = v;
           if (go(lev + 1)) return 1;
           a[lev + 1] = 0;
         }
       }
     }
   return 0;
 }
 int main(void) {
   scanf( d , &n);
   if (n == 1) {
     printf( 0
 );
     return 0;
   }
   a[0] = 1;
   w[1] = 1;
   for (LIMIT = 1;; LIMIT++) {
     if (go(0)) {
       break;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin >> n;
   long long ans = 0;
   for (int i = 2; i <= n; i++)
     for (int j = i + i; j <= n; j += i) ans += j / i;
   cout << ans * 4 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int64_t INF = INT64_MAX / 4;
 const int64_t NINF = -INF;
 map<pair<int64_t, uint32_t>, int64_t> dp;
 int64_t grundy(int64_t pile, uint32_t pattern) {
   if (pile == 0) {
     return 0;
   }
   pair<int64_t, uint32_t> key = {pile, pattern};
   auto fd = dp.find(key);
   if (fd != dp.end()) {
     return fd->second;
   }
   bitset<32> bs(pattern);
   set<int64_t> res;
   for (int64_t i = 0; i < pile; i++) {
     if (!bs[i]) {
       bs[i] = true;
       res.insert(grundy(pile - (i + 1), bs.to_ulong()));
       bs[i] = false;
     }
   }
   int64_t ans = 0;
   while (res.find(ans) != res.end()) {
     ans++;
   }
   dp.insert({key, ans});
   return ans;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int64_t n;
   cin >> n;
   int64_t ans = 0;
   for (int64_t i = 0; i < n; i++) {
     int64_t pile;
     cin >> pile;
     ans ^= grundy(pile, 0);
   };
   if (ans == 0) {
     cout <<  YES ;
   } else {
     cout <<  NO ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long p, q, b, t, g;
 long long gcd(long long a, long long b) {
   if (a < b) swap(a, b);
   while (b != 0) {
     a = b;
     swap(a, b);
   }
   return a;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cin >> t;
   while (t--) {
     cin >> p >> q >> b;
     g = gcd(p, q);
     q /= g;
     while (true) {
       g = gcd(b, q);
       if (g == 1) break;
       while (q  g == 0) q /= g;
     }
     if (q == 1)
       cout <<  Finite ;
     else
       cout <<  Infinite ;
     cout << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC target( avx )
 #pragma GCC optimize( O3 )
 #pragma GCC optimize( unroll-loops )
 using namespace std;
 int dx[4] = {1, 0, -1, 0};
 int dy[4] = {0, 1, 0, -1};
 int main() {
   long long A, B, C, D, E, F, N, K, M, Z, sum = 0, num = 0, flag = 0;
   string S, T;
   cin >> Z;
   queue<long long> que;
   while (Z--) {
     cin >> S;
     vector<long long> P(0, 0);
     num = 0;
     S += '0';
     for (long long int i = 0; i < S.size(); i++) {
       if (S[i] == '1')
         num++;
       else {
         P.push_back(num);
         num = 0;
       }
     }
     sort(P.begin(), P.end());
     reverse(P.begin(), P.end());
     sum = 0;
     for (long long int i = 0; i < P.size(); i++) {
       sum += P[i];
       i++;
     }
     que.push(sum);
   }
   while (!que.empty()) {
     cout << que.front() << endl;
     que.pop();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int k, n;
   cin >> n >> k;
   int x[n];
   for (int i = 0; i < n; i++) {
     cin >> x[i];
   }
   double m = -1, sum = 0;
   int c = 0;
   for (int i = 0; i < n; i++) {
     for (int j = i; j < n; j++) {
       c++;
       sum += x[j];
       if (c >= k && (sum / c) > m) {
         m = sum / c;
       }
     }
     c = 0;
     sum = 0;
   }
   cout << setprecision(15) << fixed << m << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long powm(long long base, long long exp, long long mod = 1000000009) {
   long long ans = 1;
   while (exp) {
     if (exp & 1) ans = (ans * base)  mod;
     exp >>= 1, base = (base * base)  mod;
   }
   return ans;
 }
 long long ctl(char x, char an = 'a') { return (long long)(x - an); }
 char ltc(long long x, char an = 'a') { return (char)(x + an); }
 long long first[300005], pref[300005], pref_fib[300005], a[300005];
 long long get_fibo_sum(long long l, long long r) {
   return (pref_fib[r] - (l ? pref_fib[l - 1] : 0) + 1000000009)  1000000009;
 }
 long long get_fibo(long long st1, long long st2, long long i) {
   if (i == 0)
     return st1;
   else if (i == 1)
     return st2;
   else {
     long long ret = ((first[i - 1] * st2)  1000000009 +
                      (first[i - 2] * st1)  1000000009)
                     1000000009;
     return ret;
   }
 }
 long long get_fibo_sum(long long st1, long long st2, long long i) {
   if (i == 0)
     return st1;
   else if (i == 1)
     return (st1 + st2)  1000000009;
   else {
     long long ans = (st2 * get_fibo_sum(1, i - 1))  1000000009;
     ans = (ans + (st1 * get_fibo_sum(0, i - 2))  1000000009)  1000000009;
     ans = (ans + st1)  1000000009;
     ans = (ans + st2)  1000000009;
     return ans;
   }
 }
 const pair<long long, long long> khali = make_pair(0LL, 0LL);
 struct lazySegTree {
   long long tree[4 * 300005], x, y, val;
   pair<long long, long long> lazy[4 * 300005];
   void push(long long low, long long high, long long pos) {
     if (lazy[pos] != khali) {
       tree[pos] +=
           get_fibo_sum(lazy[pos].first, lazy[pos].second, (high - low));
       if (low != high) {
         pair<long long, long long> tmp;
         tmp = lazy[pos];
         lazy[2 * pos + 1].first =
             (lazy[2 * pos + 1].first + tmp.first)  1000000009;
         lazy[2 * pos + 1].second =
             (lazy[2 * pos + 1].second + tmp.second)  1000000009;
         tmp.first = get_fibo(lazy[pos].first, lazy[pos].second,
                              (low + high) / 2 - low + 1);
         tmp.second = get_fibo(lazy[pos].first, lazy[pos].second,
                               (low + high) / 2 - low + 2);
         lazy[2 * pos + 2].first =
             (lazy[2 * pos + 2].first + tmp.first)  1000000009;
         lazy[2 * pos + 2].second =
             (lazy[2 * pos + 2].second + tmp.second)  1000000009;
       }
       lazy[pos] = khali;
     }
   }
   long long query(long long low, long long high, long long pos) {
     push(low, high, pos);
     if (x <= low and y >= high) return tree[pos];
     if (x > high || y < low) return 0;
     long long mid = (high + low) / 2;
     return (query(low, mid, 2 * pos + 1) + query(mid + 1, high, 2 * pos + 2))
            1000000009;
   }
   void update(long long low, long long high, long long pos) {
     push(low, high, pos);
     if (x > high || y < low) return;
     if (x <= low and y >= high) {
       lazy[pos].first = first[low - x];
       lazy[pos].second = first[low - x + 1];
       push(low, high, pos);
       return;
     }
     long long mid = (low + high) / 2;
     update(low, mid, 2 * pos + 1), update(mid + 1, high, 2 * pos + 2);
     tree[pos] = (tree[2 * pos + 1] + tree[2 * pos + 2])  1000000009;
   }
 } lst;
 int main() {
   first[0] = 1, first[1] = 1;
   for (long long i = 2; i < 300005; i++)
     first[i] = (first[i - 1] + first[i - 2])  1000000009;
   for (long long i = 0; i < 4 * 300005; i++) lst.lazy[i] = khali;
   long long type, l, r, n, q;
   cin >> n >> q;
   for (long long i = 1; i < n + 1; i++) cin >> a[i];
   pref_fib[0] = 1;
   for (long long i = 1; i < 300005; i++)
     pref_fib[i] = (pref_fib[i - 1] + first[i])  1000000009;
   pref[1] = a[1];
   for (long long i = 1; i < 300005; i++)
     pref[i] = (pref[i - 1] + a[i])  1000000009;
   while (q--) {
     cin >> type >> l >> r;
     lst.x = l, lst.y = r;
     if (type == 1) {
       lst.update(1, n, 0);
     } else {
       long long ans = lst.query(1, n, 0);
       ans = (ans + pref[r])  1000000009;
       ans = (ans - pref[l - 1] + 1000000009)  1000000009;
       cout << ans << '
';
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 void solve() {
   int n;
   std::cin >> n;
   std::stack<int> q;
   int a = 0;
   int cur = 1;
   n += n;
   while (n--) {
     std::string s;
     std::cin >> s;
     if (s[0] == 'r') {
       if (!q.empty() && q.top() != cur) {
         while (!q.empty()) q.pop();
         ++a;
       }
       if (!q.empty()) q.pop();
       ++cur;
     } else {
       int x;
       std::cin >> x;
       q.push(x);
     }
   }
   std::cout << a;
 }
 int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(nullptr);
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline bool smin(T &a, const T &b) {
   return b < a ? a = b, 1 : 0;
 }
 template <typename T>
 inline bool smax(T &a, const T &b) {
   return a < b ? a = b, 1 : 0;
 }
 const long long N = 1e5 + 100, lg = 22;
 long long n, k, add[N], h[N];
 vector<pair<long long, long long> > adj[N];
 long long par[N][lg];
 void dfs(long long v = 1, long long p = -1, long long dep = 0) {
   if (v != 1) {
     par[v][0] = p;
     for (long long i = 1; i < lg; i++) par[v][i] = par[par[v][i - 1]][i - 1];
   } else {
     for (long long i = 0; i < lg; i++) par[v][i] = v;
   }
   h[v] = dep;
   for (auto u : adj[v])
     if (u.first != p) dfs(u.first, v, dep + 1);
 }
 long long getPar(long long v, long long k) {
   for (long long i = lg - 1; i >= 0; i--)
     if (k >> i & 1) v = par[v][i];
   return v;
 }
 long long lca(long long u, long long v) {
   if (h[u] > h[v]) swap(u, v);
   v = getPar(v, h[v] - h[u]);
   if (u == v) return v;
   for (long long i = lg - 1; i >= 0; i--) {
     if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
   }
   return par[v][0];
 }
 long long ans[N];
 long long calc(long long v = 1, long long p = -1, long long want = -1) {
   long long res = add[v];
   for (auto u : adj[v]) {
     if (u.first == p) continue;
     res += calc(u.first, v, u.second);
   }
   if (want != -1) ans[want] = res;
   return res;
 }
 int32_t main() {
   cin >> n;
   for (long long i = 0; i < n - 1; i++) {
     long long u, v;
     cin >> u >> v;
     adj[v].push_back({u, i}), adj[u].push_back({v, i});
   }
   dfs();
   cin >> k;
   while (k--) {
     long long u, v;
     cin >> u >> v;
     long long l = lca(u, v);
     add[u]++, add[v]++, add[l] -= 2;
   };
   calc();
   for (long long i = 0; i < n - 1; i++) cout << ans[i] << ' ';
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n;
   cin >> n;
   int arr[n][4];
   multiset<int> s[4];
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < 4; j++) {
       cin >> arr[i][j];
       s[j].insert(arr[i][j]);
     }
   }
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < 4; j++) {
       auto temp = s[j].find(arr[i][j]);
       s[j].erase(temp);
     }
     if (*s[0].rbegin() <= *s[2].begin() && *s[1].rbegin() <= *s[3].begin()) {
       cout << *s[0].rbegin() <<     << *s[1].rbegin() << endl;
       break;
     }
     for (int j = 0; j < 4; j++) s[j].insert(arr[i][j]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   long long n, m, k;
   cin >> n >> m >> k;
   long long p[m];
   for (long long int i = 0; i < m; i++) cin >> p[i];
   sort(p, p + m);
   long long an = 0, x = 0, c = 0, cp = 1;
   while (1) {
     long long y = x, pg = ceil((long double)(p[x] - x) / (k));
     while (y < m && ceil((long double)(p[y] - x) / (k)) == pg) y++;
     if (y == m) {
       cout << an + 1;
       return;
     }
     an++;
     x = y;
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long TESTS = 1;
   while (TESTS--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int requestNum;
   cin >> requestNum;
   vector<pair<int, pair<int, int>>> vect(requestNum);
   for (int i = 0; i < requestNum; i++) {
     int num, money;
     cin >> num >> money;
     vect.push_back(make_pair(money, make_pair(num, i + 1)));
   }
   sort(vect.rbegin(), vect.rend());
   int tablesNum;
   cin >> tablesNum;
   vector<pair<int, int>> maxPeople(tablesNum);
   for (int i = 0; i < tablesNum; i++) {
     cin >> maxPeople[i].first;
     maxPeople[i].second = i + 1;
   }
   sort(maxPeople.begin(), maxPeople.end());
   vector<bool> tablesFull(tablesNum, false);
   long long int totalMoney = 0;
   vector<pair<long, long>> result;
   for (int i = 0; i < requestNum; i++) {
     for (int j = 0; j < tablesNum; j++) {
       if (vect[i].second.first <= maxPeople[j].first && !tablesFull[j]) {
         result.push_back(make_pair(vect[i].second.second, maxPeople[j].second));
         totalMoney += vect[i].first;
         tablesFull[j] = true;
         break;
       }
     }
   }
   cout << result.size() <<     << totalMoney << endl;
   for (int i = 0; i < result.size(); i++) {
     cout << result[i].first <<     << result[i].second << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7;
 const double PI = 3.1415926536;
 int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 bool is_prime(long long n) {
   for (long long i = 2; i * i <= n; ++i) {
     if (n  i == 0) {
       return false;
     }
   }
   return true;
 }
 inline long long getPow(long long a, long long b) {
   long long res = 1ll, tp = a;
   while (b) {
     if (b & 1ll) {
       res *= tp;
     }
     tp *= tp;
     b >>= 1ll;
   }
   return res;
 }
 long long vec_mult(const pair<long long, long long> &t1,
                    const pair<long long, long long> &t2,
                    const pair<long long, long long> &t3) {
   const long long &x1 = t1.first, y1 = t1.second;
   const long long &x2 = t2.first, y2 = t2.second;
   const long long &x3 = t3.first, y3 = t3.second;
   return ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));
 }
 void ok() {
   cout <<  YES  << endl;
   exit(0);
 }
 void no() {
   cout <<  NO  << endl;
   exit(0);
 }
 inline long long nxt() {
   long long x;
   cin >> x;
   return x;
 }
 long long otr(long long num) {
   long long cur = 0;
   long long ct = 1;
   while (num) {
     cur += ct * (9 - num  10);
     num /= 10;
     ct *= 10;
   }
   return cur;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   long long l = nxt(), r = nxt();
   long long t = 1ll;
   long long ans = -1;
   while (t <= r) {
     long long left = max(l, t);
     long long right = min(r, 10ll * t - 1);
     while (right - left > 2) {
       long long len = (right - left + 1) / 3;
       long long t1 = left + len;
       long long t2 = right - len;
       if (t1 * otr(t1) >= t2 * otr(t2)) {
         right = t2;
       } else {
         left = t1;
       }
     }
     while (left <= right) {
       ans = max(ans, left * otr(left));
       left++;
     }
     t *= 10ll;
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void faster() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
 }
 string s, x, t, ans;
 long long q, n, a[456789], b[456789], sum, prefa[456789], prefb[456789], k, l,
     r, mx;
 bool ok;
 void dii() {
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
   }
   k = 1;
   for (int i = 1; i <= n; i++) {
     if (a[i] <= 2 * a[i - 1]) {
       k++;
     } else {
       k = 1;
     }
     if (k > mx) {
       mx = k;
     }
   }
   cout << mx;
 }
 int main() {
   faster();
   q = 1;
   while (q--) {
     dii();
   }
   return 0;
 }


#include <bits/stdc++.h>
 const int INF = 1 << 29;
 int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(NULL);
   ;
   int n;
   std::cin >> n;
   std::vector<int> v(n);
   for (int &it : v) std::cin >> it;
   int alice = v[0];
   int sum = std::accumulate(v.begin(), v.end(), 0);
   int target = sum / 2 + 1;
   std::vector<int> ans;
   ans.push_back(1);
   int cur = alice;
   for (int i = 0; i < n; i++) {
     if (alice < v[i] * 2) continue;
     cur += v[i];
     ans.push_back(i + 1);
     if (cur >= target) break;
   }
   if (cur < target) {
     std::cout << 0;
     exit(0);
   } else {
     std::cout << ans.size() << '
';
     for (int it : ans) std::cout << it << ' ';
   }
   return 0;
 }


#include <bits/stdc++.h>
 void dfs(int64_t node, int64_t from,
          const std::vector<std::vector<int64_t> > &g,
          std::vector<bool> &visited, int64_t &count, bool &cycle, bool &self) {
   if (visited[node]) {
     return;
   }
   visited[node] = 1;
   ++count;
   for (int64_t p = 0; p < g[node].size(); p++) {
     int64_t u = g[node][p];
     if (u == from) {
       continue;
     } else if (u == node) {
       self = true;
     } else if (visited[u]) {
       cycle = true;
     } else {
       dfs(u, node, g, visited, count, cycle, self);
     }
   }
   return;
 }
 int main() {
   const int64_t MOD = 1000000007;
   int64_t n;
   scanf( lld , &n);
   std::vector<std::vector<int64_t> > g(2 * n);
   for (int64_t p = 0; p < n; p++) {
     int64_t x, y;
     scanf( lld lld , &x, &y);
     --x;
     --y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   std::vector<bool> visited(2 * n, false);
   int64_t total(1);
   for (int64_t p = 0; p < 2 * n; p++) {
     if (visited[p]) {
       continue;
     }
     int64_t count(0);
     bool cycle(false), self(false);
     dfs(p, -1, g, visited, count, cycle, self);
     if (self) {
       count = 1;
     } else if (cycle) {
       count = 2;
     }
     total *= count;
     total = MOD;
   }
   printf( lld
 , total);
   return 0;
 }


#include <bits/stdc++.h>
 const int N = 1010, M = 2010;
 int las[M], nxt[M], to[M], cnt;
 int l[M], r[M], siz[M], mx[N][N], f[N];
 inline void add(int u, int v) {
   cnt++;
   to[cnt] = v;
   nxt[cnt] = las[u];
   las[u] = cnt;
 }
 int n, m;
 inline void fmin(int &a, int b) {
   if (a > b) a = b;
 }
 inline void fmax(int &a, int b) {
   if (a < b) a = b;
 }
 void dfs(int now) {
   int i;
   siz[now] = now != 1;
   if (las[now]) l[now] = n, r[now] = 0;
   for (i = las[now]; i; i = nxt[i])
     dfs(to[i]), siz[now] += siz[to[i]], fmin(l[now], l[to[i]]),
         fmax(r[now], r[to[i]]);
   fmax(mx[l[now]][r[now]], siz[now]);
 }
 int main() {
   int i, j, x;
   scanf( d , &n);
   scanf( d , &m);
   for (i = 2; i <= m; i++) scanf( d , &x), add(x, i);
   for (i = 1; i <= n; i++) scanf( d , &x), l[x] = r[x] = i;
   dfs(1);
   cnt = 0;
   memset(las, 0, sizeof las);
   scanf( d , &m);
   for (i = 2; i <= m; i++) scanf( d , &x), add(x, i);
   for (i = 1; i <= n; i++) scanf( d , &x), l[x] = r[x] = i;
   dfs(1);
   for (i = 1; i <= n; i++)
     for (j = 1; j <= i; j++)
       if (mx[j][i]) fmax(f[i], f[j - 1] + mx[j][i]);
   printf( d
 , f[n]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100010;
 int n, ans[N], an;
 struct edge {
   int to, nx, id, dl;
 } ee[N];
 int eq[N], en = 1;
 void dfs(int d) {
   for (int j = eq[d], k; k = ee[j].to, j; j = ee[j].nx)
     if (!ee[j].dl) {
       ee[j].dl = 1;
       dfs(k);
       ans[--an] = ee[j].id;
     }
 }
 int main() {
   scanf( d , &n);
   if (n & 1) {
     printf( -1
 );
     return 0;
   }
   for (int x = 0, t1, t2; x < n; x++) {
     t1 = (x * 2 + 0)  n;
     t2 = (x * 2 + 1)  n;
     ee[++en] = (edge){((t1) / 2 + 1), eq[((x) / 2 + 1)], x, 0},
     eq[((x) / 2 + 1)] = en;
   }
   an = n;
   dfs(1);
   for (int s = 0; s < n; s++)
     if (ans[s] == 0) {
       for (int i = 0; i < n; i++) printf( d  , ans[(s + i)  n]);
       printf( 0
 );
       return 0;
     }
 }


#include <bits/stdc++.h>
 using namespace std;
 void _print(long long t) { cerr << t; }
 void _print(int t) { cerr << t; }
 void _print(string t) { cerr << t; }
 void _print(char t) { cerr << t; }
 void _print(long double t) { cerr << t; }
 void _print(double t) { cerr << t; }
 void _print(unsigned long long t) { cerr << t; }
 template <class T, class V>
 void _print(pair<T, V> p);
 template <class T>
 void _print(vector<T> v);
 template <class T>
 void _print(set<T> v);
 template <class T, class V>
 void _print(map<T, V> v);
 template <class T>
 void _print(multiset<T> v);
 template <class T, class V>
 void _print(pair<T, V> p) {
   cerr <<  { ;
   _print(p.first);
   cerr <<  , ;
   _print(p.second);
   cerr <<  } ;
 }
 template <class T>
 void _print(vector<T> v) {
   cerr <<  [  ;
   for (T i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T>
 void _print(set<T> v) {
   cerr <<  [  ;
   for (T i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T>
 void _print(multiset<T> v) {
   cerr <<  [  ;
   for (T i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T, class V>
 void _print(map<T, V> v) {
   cerr <<  [  ;
   for (auto i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T, class V>
 void _print(unordered_map<T, V> v) {
   cerr <<  [  ;
   for (auto i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T>
 void _print(list<T> v) {
   cerr <<  [  ;
   for (T i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int tc = 0, T;
   cin >> T;
   while (++tc <= T) {
     int N;
     cin >> N;
     cout << (int)sqrt(N) + (int)cbrt(N) - (int)sqrt((int)cbrt(N)) << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MOD = 1e9 + 7;
 const double pi = acos(-1);
 const double EPS = 1e-9;
 long long binpowmod(long long a, long long b) {
   a = MOD;
   long long ret = 1;
   while (b) {
     if (b & 1) ret = ret * a  MOD;
     a = a * a  MOD;
     b >>= 1;
   }
   return ret  MOD;
 }
 long long gcd(long long a, long long b) {
   if (!b) return a;
   return gcd(b, a  b);
 }
 const int N = 1 << 18;
 const int E = N * 2;
 bool good(long long n) {
   long long t = n;
   int sumofdigits = 0;
   while (n) {
     sumofdigits += n  10;
     n /= 10;
   }
   return (gcd(t, sumofdigits) > 1);
 }
 int n, m, ans;
 vector<vector<int> > a;
 bool good(int i, int j) {
   for (int k = 0; k < m; ++k) {
     if (a[i][k] != a[j][k]) return false;
   }
   return true;
 }
 void solveit(int l = 0, int r = n - 1, int c = 1) {
   int len = r - l + 1;
   if (len  2) return;
   int i = l, j = r;
   while (i < j) {
     if (!good(i, j)) return;
     i++;
     j--;
   }
   ans = min(ans, n / (1 << c));
   int mid = (l + r) / 2;
   solveit(l, mid, c + 1);
   solveit(mid + 1, r, c + 1);
 }
 void solve() {
   cin >> n >> m;
   ans = n;
   a.assign(n, vector<int>(m));
   for (int i = 0; i < n; ++i)
     for (int j = 0; j < m; ++j) cin >> a[i][j];
   solveit();
   cout << ans << '
';
 }
 int main(void) {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int tc = 1;
   while (tc--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, k;
   scanf( dd , &n, &k);
   long long ans1 = 1, ans2 = 1;
   for (int i = 1; i <= k - 1; i++) ans1 = ans1 * k  1000000007;
   for (int i = 1; i <= n - k; i++) ans2 = ans2 * (n - k)  1000000007;
   printf( extra
 , ans1 * ans2  1000000007);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 25, mod = 1e9 + 7;
 int a[N][N], used[N][N], cur, first, n, m, k;
 long long ans;
 int count(int x) {
   int ans = 0;
   for (; x; x -= x & -x) ans++;
   return ans;
 }
 void dfs(int x, int y) {
   if (x == n) {
     int p = count(cur & ~first), q = count(((1 << k) - 1) & ~first);
     long long curans = 1;
     while (p--) {
       curans = (curans * q)  mod;
       q--;
     }
     ans = (ans + curans)  mod;
     return;
   }
   int nx = x, ny = y + 1;
   if (ny == m) {
     nx++;
     ny = 0;
   }
   if (a[x][y]) {
     dfs(nx, ny);
     return;
   } else {
     bool flag = true;
     int can = (1 << k) - 1;
     can &= ~used[x][y];
     for (int i = 0; (1 << i) <= can; i++) {
       if (!((can >> i) & 1)) continue;
       bool preused[N][N], preusedcur;
       preusedcur = true;
       memset(preused, false, sizeof(preused));
       if (!((cur >> i) & 1)) {
         if (flag)
           flag = false;
         else
           continue;
         preusedcur = false;
       }
       cur |= 1 << i;
       for (int px = x; px < n; px++)
         for (int py = y; py < m; py++) {
           if ((used[px][py] >> i) & 1)
             preused[px][py] = true;
           else
             used[px][py] |= 1 << i;
         }
       dfs(nx, ny);
       if (!preusedcur) cur &= ~(1 << i);
       for (int px = x; px < n; px++)
         for (int py = y; py < m; py++) {
           if (!preused[px][py]) used[px][py] &= ~(1 << i);
         }
     }
   }
 }
 int main() {
   scanf( ddd , &n, &m, &k);
   if (n + m - 1 > k) {
     printf( 0
 );
     return 0;
   }
   for (int i = 0; i < n; i++)
     for (int j = 0; j < m; j++) {
       scanf( d , &a[i][j]);
       if (a[i][j]) {
         first |= 1 << a[i][j] - 1;
         if ((used[i][j] >> a[i][j] - 1) & 1) {
           printf( 0
 );
           return 0;
         }
         for (int r = 0; r < n; r++)
           for (int c = 0; c < m; c++) {
             if (r <= i && c <= j || r >= i && c >= j)
               used[r][c] |= 1 << a[i][j] - 1;
           }
       }
     }
   cur = first;
   dfs(0, 0);
   printf( d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int p1, p2, p3, p4, a, b;
   cin >> p1 >> p2 >> p3 >> p4 >> a >> b;
   int m = min(min(min(p1, p2), p3), p4);
   cout << max(0, min(b + 1, m) - a) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 const int inf = (1 << 30) - 1;
 const double eps = 1e-9;
 using namespace std;
 int a[111111], n, k, mx = 0, aa;
 long long s[111111];
 int main() {
   scanf( dd , &n, &k);
   for (int i = 1; i <= n; i++) scanf( d , &a[i]);
   sort(a + 1, a + n + 1);
   for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
   for (int i = 1; i <= n; i++) {
     int l = 1, r = i;
     while (r > l) {
       int m = (l + r) / 2;
       long long ss = s[i] - s[m - 1];
       if (1ll * a[i] * (i - m + 1) - ss > k)
         l = m + 1;
       else
         r = m;
     }
     if (i - r + 1 > mx) {
       mx = i - r + 1;
       aa = a[i];
     }
   }
   cout << (mx) <<    ;
   cout << (aa) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int pr[] = {2, 3, 5, 7, 11, 13, 17, 19};
 int big[50000005];
 int c[10];
 int ans[10100];
 int main() {
   int k;
   scanf( d , &k);
   big[1] = 0;
   for (int i = 0; i < 7; i++) big[pr[i]] = i + 1;
   for (int i = 2; i <= 2 * k * k; i++) {
     if (big[i] == 0) continue;
     for (int j = 0; j < 7; j++) {
       if (i * pr[j] <= 2 * k * k) {
         big[i * pr[j]] = max(big[i], j + 1);
       }
     }
     for (int j = big[i] - 1; j < 7; j++) c[j]++;
   }
   for (int j = 0; j < 7; j++)
     if (c[j] >= k) {
       int sz = 0;
       for (int i = 2 * k * k; i >= 0; i--)
         if (big[i] != 0 && big[i] - 1 <= j &&
             big[i / pr[big[i] - 1]] - 1 < big[i] - 1) {
           ans[sz++] = i;
           if (sz == k) break;
         }
       if (sz < k) continue;
       for (int i = sz - 1; i >= 0; i--) printf( d  , ans[i]);
       printf(
 );
       return 0;
     }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e7 + 5;
 int s[maxn];
 int a[maxn];
 int main() {
   int n;
   scanf( d , &n);
   long long ans = 0;
   for (int i = 1; i <= n; i++) {
     scanf( d , &s[i]);
   }
   sort(s + 1, s + n + 1);
   for (int i = 1; i <= n / 2; i++) {
     a[i] = s[i] + s[n + 1 - i];
     ans += a[i] * a[i];
   }
   printf( lld
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 const long double EPS = 1e-9;
 long long Power(long long a, long long b) {
   if (b == 0) return 1;
   long long p = Power(a, b / 2);
   p = (p * p);
   if (b & 1) {
     p = (p * a);
   }
   return p;
 }
 long long Gcd(long long a, long long b) {
   if (b == 0) return a;
   if (a < b) return Gcd(b, a);
   return Gcd(b, a  b);
 }
 void Solve() {
   int n, m;
   long long l;
   cin >> n >> m >> l;
   vector<long long> arr(n), seg(n, -1);
   for (int i = 0; i < n; i++) cin >> arr[i];
   int curr = 0, prev = -1;
   for (int i = 0; i < n; i++) {
     if (arr[i] > l) {
       seg[i] = 0;
       if (prev == -1) {
         curr++;
       }
       prev = 0;
     } else {
       prev = -1;
       seg[i] = -1;
     }
   }
   while (m--) {
     int t;
     cin >> t;
     if (t == 0) {
       cout << curr << '
';
     } else {
       int p;
       long long d;
       cin >> p >> d;
       p--;
       arr[p] += d;
       if (seg[p] == -1 && arr[p] > l) {
         seg[p] = 0;
         if (p == 0) {
           if (p + 1 < n && seg[p + 1] == -1) {
             curr++;
           } else if (n == 1) {
             curr++;
           }
         } else if (p == n - 1) {
           if (p - 1 >= 0 && seg[p - 1] == -1) {
             curr++;
           } else if (n == 1) {
             curr++;
           }
         } else {
           if (seg[p - 1] == 0 && seg[p + 1] == 0) {
             curr--;
           } else if (seg[p - 1] == -1 && seg[p + 1] == -1) {
             curr++;
           }
         }
       }
     }
   }
 }
 int main() {
   int t = 1;
   while (t--) {
     Solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e4 + 5;
 char s[N];
 int dp[10][N];
 int ans[N];
 int len;
 int dfs(int num, int idx) {
   if (~dp[num][idx]) return dp[num][idx];
   if (idx == len)
     return 1;
   else if (idx > len)
     return 0;
   int &ret = dp[num][idx];
   ret = dfs(num ^ 1, idx + num);
   bool flag = false;
   for (int i = idx; i < idx + num; ++i) {
     if (s[i] != s[i + num]) {
       flag = true;
       break;
     }
   }
   if (flag) {
     ret = max(ret, dfs(num, idx + num));
   }
   return ret;
 }
 const int B = 333;
 int cal(char a, char b, char c) { return a * B * B + b * B + c; }
 int cal(char a, char b) { return a * B * B + b * B; }
 void prt(int x) {
   printf( c , x / (B * B));
   printf( c , x  (B * B) / B);
   if (x  B) {
     printf( c , x  B);
   }
   puts(  );
 }
 int main() {
   while (~scanf( s , s)) {
     memset(dp, -1, sizeof(dp));
     int cnt = 0;
     len = strlen(s);
     for (int i = len - 2; i >= 5; --i) {
       if (dfs(2, i) == 1) {
         ans[cnt++] = (cal(s[i], s[i + 1]));
       }
       if (dfs(3, i) == 1) {
         ans[cnt++] = (cal(s[i], s[i + 1], s[i + 2]));
       }
     }
     sort(ans, ans + cnt);
     cnt = unique(ans, ans + cnt) - ans;
     printf( d
 , cnt);
     for (int i = 0; i < cnt; ++i) {
       prt(ans[i]);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = 1e18;
 const int mod = 1e9 + 7;
 const int N = 100 + 10;
 inline int add(int x, int y) {
   x += y;
   if (x >= mod) x -= mod;
   return x;
 }
 inline int mul(int x, int y) {
   x = (1LL * x * y)  mod;
   return x;
 }
 vector<pair<int, int> > G[N];
 int dp[N][N][30][2];
 int f(int i, int j, int last, int turn) {
   int &ret = dp[i][j][last][turn];
   if (~ret) return ret;
   ret = 0;
   if (turn == 1) {
     for (auto it : G[i]) {
       int nxt = it.first;
       int ed = it.second;
       if (ed >= last) {
         int x = f(nxt, j, ed, 0);
         if (x == 0) return ret = 1;
       }
     }
   } else {
     for (auto it : G[j]) {
       int nxt = it.first;
       int ed = it.second;
       if (ed >= last) {
         int x = f(i, nxt, ed, 1);
         if (x == 0) return ret = 1;
       }
     }
   }
   return ret;
 }
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   memset(dp, -1, sizeof(dp));
   int n, m;
   cin >> n >> m;
   for (int i = 0; i <= m - 1; ++i) {
     int u, v;
     cin >> u >> v;
     char c;
     cin >> c;
     int x = c - 'a';
     G[u].push_back({v, x});
   }
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= n; ++j) {
       int curr = f(i, j, 0, 1);
       if (curr == 0)
         cout << 'B';
       else
         cout << 'A';
     }
     cout <<
 ;
   }
   return 0;
 }


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

 const int N = 1e5 + 5;

 struct query {
 	int i, type, l, r, k, p, x;
 };

 int n, m;
 vector<int> a, _a;
 query q[N];
 int queryCnt;
 int block_size;
 int ans[N];
 int freqA[N];
 int freqL[N], freqR[N], freqV[N];

 void increaseFreq(int f) {
 	freqR[f]++, freqL[f - 1]++, freqV[freqR[f] - 1] = f;
 }

 void decreaseFreq(int f) {
 	freqR[f]--, freqL[f - 1]--, freqV[freqR[f]] = f - 1;
 }

 void include(int i) {
 	increaseFreq(++freqA[a[i]]);
 }

 void remove(int i) {
 	decreaseFreq(freqA[a[i]]--);
 }

 void go(int& fromL, int& fromR, int toL, int toR) {
 	// debug() << name(fromL) name(fromR) name(toL) name(toR);
 	while (fromL > toL) include(--fromL);
 	while (fromR < toR) include(fromR++);
 	while (fromL < toL) remove(fromL++);
 	while (fromR > toR) remove(--fromR);
 }

 void update(int qi, int L, int R) {
 	if (L <= q[qi].p && q[qi].p < R) remove(q[qi].p);
 	a[q[qi].p] = q[qi].x;
 	if (L <= q[qi].p && q[qi].p < R) include(q[qi].p);
 }

 int answer(int k) {
 	vector<pair<int, int>> v;
 	for (int at = freqV[1]; at != 0; ) {
 		v.push_back({at, freqR[at] - freqL[at]});
 		at = freqV[freqR[at]];
 	}
 	reverse(v.begin(), v.end());

 	int ret = -1;
 	for (int l = 0, r = 0, cnt = 0; l < v.size(); cnt -= v[l++].second) {
 		r = max(l, r);
 		while (r < v.size() && cnt < k) cnt += v[r++].second;
 		if (cnt >= k) {
 			int _ret = v[r - 1].first - v[l].first;
 			ret = ret == -1 ? _ret : min(ret, _ret);
 		}
 	}
     // debug() << name(k) name(v) name(ret);

 	return ret;
 }

 int main() {
 	scanf( d d , &n, &m);
 	_a.resize(n + 1);
 	for (int i = 1; i <= n; i++) scanf( d , &_a[i]); a = _a;
 	for (int i = 1; i <= m; i++) {
 		q[i].i = i;
 		scanf( d , &q[i].type);
 		if (q[i].type == 1) scanf( d d d , &q[i].l, &q[i].r, &q[i].k);
 		else scanf( d d , &q[i].p, &q[i].x);
 		queryCnt += q[i].type == 1;
 	}

 	block_size = ceil(cbrt((long double)2 * n * n));

 	sort(q + 1, q + m + 1, [](const query& q1,const query& q2) {
 		int l1 = (q1.l - 1) / block_size, r1 = (q1.r - 1) / block_size;
 		int l2 = (q2.l - 1) / block_size, r2 = (q2.r - 1) / block_size;
 		auto p1 = make_pair(l1, r1);
 		auto p2 = make_pair(l2, r2);

 		if (q1.type == 1) {
 			if (q2.type == 1) return make_pair(p1, q1.i) < make_pair(p2, q2.i);
 			else return true;
 		} else {
 			if (q2.type == 1) return false;
 			else return q1.i < q2.i;
 		}
 	});

 	// for (int i = 1; i <= m; i++) debug() << name(i) name(q[i].type) name(q[i].i);

 	fill(ans, ans + N, -2);
 	fill(freqL, freqL + N, 1);
 	fill(freqR, freqR + N, 1);
 	freqR[0] = N;

 	pair<int, int> qp = {-1, -1};
 	int qAt;
 	int L = 1, R = 1;
 	for (int i = 1; i <= m && q[i].type == 1; i++) {
 		int ql = (q[i].l - 1) / block_size, qr = (q[i].r - 1) / block_size;
 		pair<int, int> _qp = {ql, qr};
 		if (qp != _qp) {
 			go(L, R, block_size * ql + 1, block_size * ql + 1);
 			a = _a;
 			qAt = queryCnt + 1;
 			qp = _qp;
 		}

 		while (qAt <= m && q[qAt].i < q[i].i) {
 			update(qAt, L, R);
 			qAt++;
 		}

 		go(L, R, q[i].l, q[i].r + 1);

 		// debug() << name(q[i].i);
 		ans[q[i].i] = answer(q[i].k);
 	}

 	for (int i = 1; i <= m; i++) if (ans[i] >= -1) printf( d
 , ans[i]);

 	return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 pair<long long, pair<long long, long long> > stree[4000005];
 char sa[1000005];
 void build(long long node, long long start, long long end) {
   if (start == end) {
     stree[node].first = 0;
     stree[node].second.first = 0;
     stree[node].second.second = 0;
     if (sa[start] == '(')
       stree[node].second.first = 1;
     else if (sa[start] == ')')
       stree[node].second.second = 1;
   } else {
     long long mid = (start + end) / 2;
     build(2 * node, start, mid);
     build(2 * node + 1, mid + 1, end);
     long long com =
         min(stree[2 * node].second.first, stree[2 * node + 1].second.second);
     long long left =
         stree[2 * node].second.first + stree[2 * node + 1].second.first - com;
     long long right =
         stree[2 * node].second.second + stree[2 * node + 1].second.second - com;
     stree[node].first = stree[2 * node].first + stree[2 * node + 1].first + com;
     stree[node].second.first = left;
     stree[node].second.second = right;
   }
 }
 pair<long long, pair<long long, long long> > query(long long node,
                                                    long long start,
                                                    long long end, long long l,
                                                    long long r) {
   if (l > end || start > r) return make_pair(0, make_pair(0, 0));
   if (l <= start && r >= end) return stree[node];
   long long mid = (start + end) / 2;
   pair<long long, pair<long long, long long> > p1 =
       query(2 * node, start, mid, l, r);
   pair<long long, pair<long long, long long> > p2 =
       query(2 * node + 1, mid + 1, end, l, r);
   long long a = min(p1.second.first, p2.second.second);
   long long b = p1.second.first + p2.second.first - a;
   long long c = p1.second.second + p2.second.second - a;
   return make_pair(p1.first + p2.first + a, make_pair(b, c));
 }
 int main() {
   string str;
   cin >> str;
   long long n, q;
   n = str.length();
   cin >> q;
   for (long long i = 1; i <= n; i++) sa[i] = str[i - 1];
   build(1, 1, n);
   while (q-- != 0) {
     long long x, y;
     cin >> x >> y;
     long long ans = 2 * query(1, 1, n, x, y).first;
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s, t, ss, tt;
   int bc;
   vector<int> res;
   cin >> bc >> s >> t;
   ss = s;
   tt = t;
   sort(ss.begin(), ss.end());
   sort(tt.begin(), tt.end());
   if (ss != tt) {
     cout << -1;
     return 0;
   }
   if (!is_permutation(s.begin(), s.end(), t.begin())) return cout << -1, 0;
   for (int i = 0; i < t.size(); ++i) {
     for (int j = i; j < s.size(); ++j)
       if (t[t.size() - i - 1] == s[j]) {
         res.insert(res.end(), {(int)s.size(), j, 1});
         reverse(s.begin() + j, s.end());
         rotate(s.begin(), s.begin() + s.size() - 1, s.end());
         break;
       }
   }
   cout << res.size() << '
';
   for (int i = 0; i < res.size(); i++) {
     cout << res[i] <<    ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 typename T::value_type arr_sum(const T& v, int n) {
   typename T::value_type sum = 0;
   for (int i = 0; i < n; ++i) sum += v[i];
   return sum;
 }
 struct Sync_stdio {
   Sync_stdio() {
     cin.tie(NULL);
     ios_base::sync_with_stdio(false);
   }
 } _sync_stdio;
 int n, m;
 vector<string> w(n);
 void print_square(int x1, int x2, int y1, int y2) {
   for (int i = x1; i < x2 + 1; ++i) {
     if (w[i][y1] != 'w') {
       w[i][y1] = '+';
     }
     if (w[i][y2] != 'w') {
       w[i][y2] = '+';
     }
   }
   for (int i = y1; i < y2 + 1; ++i) {
     if (w[x1][i] != 'w') {
       w[x1][i] = '+';
     }
     if (w[x2][i] != 'w') {
       w[x2][i] = '+';
     }
   }
   for (auto i : w) {
     cout << i <<
 ;
   }
   exit(0);
 }
 void check1(vector<pair<int, int> >& v) {
   int max1 = -1, min1 = 100001;
   int max2 = -1, min2 = 100001;
   for (int i = 0; i < v.size(); ++i) {
     max1 = max(max1, v[i].first);
     min1 = min(min1, v[i].first);
     max2 = max(max2, v[i].second);
     min2 = min(min2, v[i].second);
   }
   int left = 0, up = 0, right = 0, down = 0;
   for (int i = 0; i < v.size(); ++i) {
     if (v[i].first == min1 && min2 < v[i].second && v[i].second < max2) {
       up = 1;
     }
     if (v[i].first == max1 && min2 < v[i].second && v[i].second < max2) {
       down = 1;
     }
     if (v[i].second == min2 && min1 < v[i].first && v[i].first < max1) {
       left = 1;
     }
     if (v[i].second == max2 && min1 < v[i].first && v[i].first < max1) {
       right = 1;
     }
     if (min1 < v[i].first && v[i].first < max1 && min2 < v[i].second &&
         v[i].second < max2) {
       cout << -1;
       exit(0);
     }
   }
   if (max1 == min1) {
     up = 0;
     down = 0;
   }
   if (min2 == max2) {
     left = 0;
     right = 0;
   }
   if (max1 - min1 == max2 - min2) {
     print_square(min1, max1, min2, max2);
   }
   if (up && down && left && right) {
     cout << -1;
     exit(0);
   }
   int diff = (max1 - min1) - (max2 - min2);
   if (diff > 0) {
     if (!left && max2 + (min1 - max1) >= 0) {
       print_square(min1, max1, max2 + (min1 - max1), max2);
     }
     if (!right && min2 + (max1 - min1) < m) {
       print_square(min1, max1, min2, min2 + (max1 - min1));
     }
     if (!left && !right && max1 - min1 < m) {
       print_square(min1, max1, 0, max1 - min1);
     }
   }
   if (diff < 0) {
     if (!up && max1 + (min2 - max2) >= 0) {
       print_square(max1 + (min2 - max2), max1, min2, max2);
     }
     if (!down && min1 + (max2 - min2) < n) {
       print_square(min1, min1 + (max2 - min2), min2, max2);
     }
     if (!up && !down && max2 - min2 < n) {
       print_square(0, max2 - min2, min2, max2);
     }
   }
   cout << -1;
   exit(0);
 }
 int main() {
   cin >> n >> m;
   vector<pair<int, int> > v;
   for (int i = 0; i < n; ++i) {
     string t;
     cin >> t;
     w.push_back(t);
     for (int j = 0; j < m; ++j) {
       if (t[j] == 'w') {
         v.push_back({i, j});
       }
     }
   }
   check1(v);
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int q;
   cin >> q;
   while (q--) {
     ll a, b, m;
     cin >> a >> b >> m;
     if (a == b) {
       cout << 1 <<     << a <<
 ;
       continue;
     }
     bool f = false;
     for (int k = 1; k <= 49 && (1ll << (k - 1)) <= b / a; k++) {
       ll t = (1ll << (k - 1)) * a;
       ll b_tmp = b - t;
       vector<ll> rs(k + 1);
       rs[0] = a;
       for (int cur = 1; cur <= k; cur++) {
         ll pw = (cur == k) ? 1 : (1ll << (k - cur - 1));
         rs[cur] = 1;
         b_tmp -= pw * rs[cur];
       }
       if (b_tmp < 0) {
         continue;
       }
       for (int cur = 1; cur <= k; cur++) {
         ll pw = (cur == k) ? 1 : (1ll << (k - cur - 1));
         ll now = min(m - 1, b_tmp / pw);
         b_tmp -= pw * now;
         rs[cur] += now;
       }
       if (b_tmp == 0) {
         f = true;
         cout << k + 1 <<    ;
         vector<ll> ans;
         for (int i = 0; i <= k; i++) {
           ll cur = rs[i];
           for (int j = i - 1; j >= 0; j--) {
             cur += ans[j];
           }
           ans.push_back(cur);
           cout << cur <<    ;
         }
         cout <<
 ;
         break;
       }
     }
     if (!f) cout << -1 <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool check(string s) {
   string t = s;
   reverse(t.begin(), t.end());
   return (s == t);
 }
 int main() {
   string s;
   cin >> s;
   int l = 0, r = ((int)s.length()) - 1;
   set<char> all;
   while (l < r) {
     all.insert(s[l]);
     all.insert(s[r]);
     l++;
     r--;
   }
   if (all.size() <= 1) {
     cout <<  Impossible  << endl;
     return 0;
   }
   for (int i = 0; i < ((int)s.length()) - 1; i++) {
     string fi =   , se =   ;
     for (int j = 0; j <= i; j++) fi += s[j];
     for (int j = i + 1; j < (int)s.length(); j++) se += s[j];
     if (check(se + fi) && (se + fi != s)) {
       cout << 1 << endl;
       return 0;
     }
   }
   cout << 2 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline T MAX(T a, T b) {
   if (a > b) return a;
   return b;
 }
 template <class T>
 inline T MIN(T a, T b) {
   if (a < b) return a;
   return b;
 }
 template <class T>
 inline T ABS(T x) {
   if (x < 0) return -x;
   return x;
 }
 inline void OPEN(const string &s) {
   freopen((s +  .in ).c_str(),  r , stdin);
   freopen((s +  .out ).c_str(),  w , stdout);
 }
 const static int inf = 1000000000;
 int n, m, x, y, z, p;
 int a, b;
 vector<pair<int, int> > cek;
 void rotate90(int &a, int &b, int &r, int &c) {
   int tempa = a;
   int tempb = b;
   a = tempb;
   b = r - tempa + 1;
   swap(r, c);
 }
 void flipH(int &a, int &b, int &r, int &c) { b = c - b + 1; }
 void rotate(int &a, int &b, int &r, int &c) {
   int tempa = a;
   int tempb = b;
   a = c - tempb + 1;
   b = tempa;
   swap(r, c);
 }
 int main() {
   scanf( dddddd , &n, &m, &x, &y, &z, &p);
   for (int(i) = (0); (i) < (p); ++(i)) {
     scanf( dd , &a, &b);
     cek.push_back(make_pair(a, b));
   }
   x = 4;
   z = 4;
   y = 2;
   for (int(i) = (0); (i) < (cek.size()); ++(i)) {
     a = cek[i].first;
     b = cek[i].second;
     int r = n, c = m;
     for (int(j) = (0); (j) < (x); ++(j)) rotate90(a, b, r, c);
     for (int(j) = (0); (j) < (y); ++(j)) flipH(a, b, r, c);
     for (int(j) = (0); (j) < (z); ++(j)) rotate(a, b, r, c);
     printf( d d
 , a, b);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1};
 const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
 int n, pre = 0;
 int a[1005], b[1005], p[1005];
 vector<int> num;
 bool vis[1005];
 bool valid() {
   int na = 0;
   set<int> st;
   for (int j = 0; j < n; ++j) {
     if (a[j] == p[j]) ++na;
     st.insert(p[j]);
   }
   return ((st.size()) == n && na == n - 1);
 }
 int main() {
   int v;
   scanf( d , &n);
   for (int i = 0; i < n; ++i) scanf( d , &a[i]);
   for (int i = 0; i < n; ++i) {
     scanf( d , &b[i]);
     p[i] = b[i];
     if (vis[p[i]]) v = p[i];
     vis[p[i]] = 1;
   }
   vis[v] = 0;
   for (int i = 0; i < n; ++i)
     if (b[i] == v) num.push_back(i);
   int tmp1 = p[num[0]], tmp2 = p[num[1]];
   for (int j = 1; j <= n; ++j) {
     if (!vis[j]) {
       vis[j] = 1;
       p[num[0]] = j;
       for (int k = 1; k <= n; ++k) {
         if (!vis[k]) {
           vis[k] = 1;
           p[num[1]] = k;
           break;
         }
       }
       if (valid())
         break;
       else {
         vis[p[num[0]]] = vis[p[num[1]]] = 0;
         p[num[0]] = tmp1;
         p[num[1]] = tmp2;
       }
     }
   }
   for (int i = 0; i < n; ++i) printf( d  , p[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   string s;
   cin >> s;
   if (n  2 == 0) {
     for (int i = 0; i < n - 2; i++) {
       cout << s[i];
       if (i  2) {
         cout <<  - ;
       }
     }
     cout << s[n - 2] << s[n - 1];
   }
   if (n  2) {
     for (int i = 0; i < n - 3; i++) {
       cout << s[i];
       if (i  2) {
         cout <<  - ;
       }
     }
     cout << s[n - 3] << s[n - 2] << s[n - 1];
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 vector<int> g[100001], vc;
 int judge(int x) {
   vc.clear();
   int need = x - g[0].size(), ans = 0;
   for (int i = 1; i < 100001; i++) {
     for (int j = 0; j < g[i].size(); j++) {
       if (g[i].size() - j >= x) {
         need--;
         ans += g[i][j];
       } else
         vc.push_back(g[i][j]);
     }
   }
   sort(vc.begin(), vc.end());
   for (int i = 0; i < need; i++) ans += vc[i];
   return ans;
 }
 int main() {
   scanf( d , &n);
   int a, b;
   for (int i = 0; i < n; i++) {
     scanf( dd , &a, &b);
     g[a].push_back(b);
   }
   for (int i = 1; i < 100001; i++) {
     sort(g[i].begin(), g[i].end());
   }
   int l = g[0].size(), r = n;
   while (l < r) {
     int mid = (l + l + r) / 3, mmid = (l + r + r) / 3;
     if (judge(mid) > judge(mmid)) {
       if (l == mid)
         break;
       else
         l = mid;
     } else {
       if (r == mmid)
         break;
       else
         r = mmid;
     }
   }
   int ans = 0x3f3f3f3f;
   for (int i = l; i <= r; i++) ans = min(ans, judge(i));
   printf( d
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, x, y, z;
   int sum1 = 0, sum2 = 0, sum3 = 0;
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> x >> y >> z;
     sum1 += x;
     sum2 += y;
     sum3 += z;
   }
   if ((sum1 == 0) && (sum2 == 0) && (sum3 == 0)) {
     cout <<  YES  << endl;
   } else {
     cout <<  NO  << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int i, j, n;
 void solve() {
   int n;
   long long l;
   cin >> n >> l;
   long long a[n];
   for (i = 0; i < n; i++) cin >> a[i];
   ;
   sort(a, a + n);
   long long m = 2 * max(a[0], l - a[n - 1]);
   for (i = 0; i < n - 1; i++) {
     m = max(m, a[i + 1] - a[i]);
   }
   long double d = 1.0 * m / 2;
   cout << setprecision(9) << d;
 }
 int main() {
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 100005;
 const int maxd = 205;
 struct Node {
   int l, d;
 } leg[maxn];
 bool operator<(const Node &a, const Node &b) { return a.l > b.l; }
 int n, tot[maxd], td = 0, md = 0;
 int Solve(int st, int ed) {
   int cnt = ed - st;
   int res = td;
   for (int i = md; i >= 0 && cnt > 0; i--) {
     res -= min(cnt, tot[i]) * i;
     cnt -= min(cnt, tot[i]);
   }
   return res;
 }
 int main() {
   cin >> n;
   for (int i = 0; i < n; i++) cin >> leg[i].l;
   for (int i = 0; i < n; i++) cin >> leg[i].d;
   for (int i = 0; i < n; i++) md = max(md, leg[i].d);
   sort(leg, leg + n);
   for (int i = 0; i < n; i++) {
     tot[leg[i].d]++;
     td += leg[i].d;
   }
   int p = 0;
   int res = INT_MAX, tot_d = 0;
   while (p < n) {
     int p1 = p + 1;
     while (p1 < n && leg[p1].l == leg[p].l) p1++;
     p1--;
     for (int i = p; i <= p1; i++) {
       tot[leg[i].d]--;
       td -= leg[i].d;
     }
     int tmp = tot_d + Solve(p, p1);
     res = min(tmp, res);
     for (int i = p; i <= p1; i++) tot_d += leg[i].d;
     p = p1 + 1;
   }
   cout << res << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline long long read() {
   register long long x = 0, f = 1;
   char ch = getchar();
   while (!isdigit(ch)) {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (isdigit(ch)) {
     x = (x << 1) + (x << 3) + (ch ^ 48);
     ch = getchar();
   }
   return x * f;
 }
 const long long N = 1e5 + 10;
 long long n, m, k, p;
 long long h[N], a[N];
 long long c[N];
 struct node {
   long long t, id;
   bool operator<(const node& x) const { return t > x.t; }
 };
 priority_queue<node> q;
 bool check(long long x) {
   while (!q.empty()) q.pop();
   memset(c, 0, sizeof c);
   for (long long i = 1; i <= n; i++)
     if (x - a[i] * m < h[i]) q.push((node){x / a[i], i});
   for (long long i = 1; !q.empty() && i <= m; i++)
     for (long long j = 1; !q.empty() && j <= k; j++) {
       node u = q.top();
       q.pop();
       if (u.t < i) return 0;
       ++c[u.id];
       if (x + c[u.id] * p - a[u.id] * m < h[u.id])
         q.push((node){(x + c[u.id] * p) / a[u.id], u.id});
     }
   return q.empty();
 }
 signed main() {
   n = read(), m = read(), k = read(), p = read();
   for (long long i = 1; i <= n; i++) h[i] = read(), a[i] = read();
   long long l = 0, r = 1e15, ans;
   while (l <= r) {
     long long mid = l + r >> 1;
     if (check(mid))
       ans = mid, r = mid - 1;
     else
       l = mid + 1;
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct data {
   int idx, val;
   bool operator<(const data &a1) const {
     if (a1.val == val) {
       return a1.idx < idx;
     }
     return val > a1.val;
   }
   data(int t, int w) : idx(t), val(w) {}
 };
 set<data> coastline;
 set<data>::iterator it, it2;
 int main() {
   int N;
   scanf( d , &N);
   string ans[N];
   int a;
   for (int i = 0; i < N; i++) {
     scanf( d , &a);
     if (a == 0) {
       int sz = coastline.size();
       if (sz == 0) {
         ans[i] =  0 ;
       } else if (sz == 1) {
         ans[i] =  1 popStack ;
         it = coastline.begin();
         ans[it->idx] =  pushStack ;
       } else if (sz == 2) {
         ans[i] =  2 popStack popQueue ;
         it = coastline.begin();
         ans[it->idx] =  pushQueue ;
         it++;
         ans[it->idx] =  pushStack ;
         it++;
       } else {
         ans[i] =  3 popStack popQueue popFront ;
         it = coastline.begin();
         ans[it->idx] =  pushFront ;
         it++;
         ans[it->idx] =  pushQueue ;
         it++;
         ans[it->idx] =  pushStack ;
         it++;
       }
       coastline.clear();
     } else {
       coastline.insert(data(i, a));
     }
   }
   for (int i = 0; i < N; i++) {
     if (ans[i].size() == 0) {
       cout <<  pushBack  << endl;
     } else
       cout << ans[i] << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 #define ll long long
 #define mod 1000000007
 using namespace std;

 ll dp[10][200001];
 string s =  abcdefghijklmnopqrstuvwxyz ;
 ll findgcd(ll a, ll b) {
     if (b == 0) {
         return a;
     }
     return findgcd(b, a  b);
 }

 bool ispalindrome(string s) {
     int n = s.length();
     bool flag = true;
     for (int i = 0; i < n / 2; i++) {
         if (s[i] != s[n - 1 - i]) {
             flag = false;
             break;
         }
     }
     return flag;
 }

 ll factorial(ll n) {
     vector<ll> v(n + 1);
     for (ll i = 0; i <= n; i++) {
         if (i == 0 || i == 1) {
             v[i] = 1;
         }
         else {
             v[i] = (i * v[i - 1])  mod;
         }
     }
     return v[n];
 }

 void calculatedp() {
     for (ll i = 0; i <= 9; i++) {
         ll temp = 10 - i;
         for (ll j = 0; j <= 200000; j++) {
             if (j < temp) {
                 dp[i][j] = 1;
             }
             else if (j == temp) {
                 dp[i][j] = 2;
             }
             else {
                 break;
             }
         }
     }
     dp[1][10] = 2;
     for (ll i = 11; i <= 200000; i++) {
         int temp1 = i - 10;
         int temp2 = i - 9;
         dp[0][i] = (dp[0][temp1] + dp[1][temp1])  mod;
         dp[1][i] = (dp[0][temp2] + dp[1][temp2])  mod;
     }
     for (ll i = 2; i <= 9; i++) {
         ll temp = 10 - i;
         for (ll j = temp + 1; j <= 200000; j++) {
             dp[i][j] = (dp[0][j - temp] + dp[1][j - temp])  mod;
         }
     }
 }

 void solve() {
     // ll m;
     // cin >> s;
     // cin >> m;
     // ll ans = 0;
     // for (int i = 0; i < s.length(); i++) {
     //     ans = (ans + (dp[s[i] - '0'][m]))  mod;
     // }
     // cout << ans <<
 ;
     int n, k;
     cin >> n >> k;

     string ans =   ;

     for (int i = 0 ; i < k ; i++) {
         ans += s[i];
         for (int j = i + 1 ; j < k ; j++) {
             ans += s[i];
             ans += s[j];
         }
     }

     if (n < ans.size()) {
         cout << ans.substr(0, n) << endl;
     }
     else {
         int j = ans.length();
         int i = 0;
         while (j < n) {
             ans += ans[i];
             i++;
             j++;
         }

         cout << ans << endl;
     }
 }
 int main() {
 #ifndef ONLINE_JUDGE
     //for getting input from input.txt
     freopen( input.txt ,  r , stdin);
     //for writing output to output.txt
     freopen( output.txt ,  w , stdout);
 #endif
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
     // calculatedp();
     // for (int i = 0; i <= 10; i++) {
     //     for (int j = 0; j <= 10; j++) {
     //         cout << dp[i][j] <<    ;
     //     }
     //     cout <<
 ;
     // }
     int t;
     t = 1;
     // cin >> t;
     while (t--) {
         solve();
     }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline int popcount(T t) {
   if (std::numeric_limits<T>::digits <=
       std::numeric_limits<unsigned int>::digits) {
     return __builtin_popcount(t);
   } else {
     return __builtin_popcountll(t);
   }
 }
 const long double EPS = 1e-8;
 const long double PI = acosl(0.0) * 2;
 void solve() {
   int n;
   cin >> n;
   vector<int> a(n);
   for (int i = 0; i < int(n); ++i) cin >> a[i];
   for (int i = 30; i >= 0; --i) {
     vector<int> b;
     int mask = (1 << i) - 1;
     for (int x : a) {
       if ((x >> i) & 1) {
         b.push_back(x);
         mask &= x;
       }
     }
     if (!mask) {
       cout << b.size() << endl;
       for (int x : b) {
         cout << x <<    ;
       }
       cout << endl;
       return;
     }
   }
   assert(false);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n1, n2, n3, n4;
   long long ans;
   unordered_map<char, int> m;
   string s;
   while (cin >> n1 >> n2 >> n3 >> n4) {
     ans = 0;
     m['1'] = n1;
     m['2'] = n2;
     m['3'] = n3;
     m['4'] = n4;
     cin >> s;
     for (int i = 0; i < s.size(); i++) {
       ans += m[s[i]];
     }
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool cmp(double a, double b) { return a > b; }
 int n;
 double a[110], x, sum, ans;
 int main() {
   scanf( d , &n);
   for (int i = 0; i < n; i++) scanf( lf , &a[i]);
   sort(a, a + n, cmp);
   ans = 0;
   for (int i = 1; i <= n; i++) {
     sum = 0;
     for (int j = 0; j < i; j++) {
       x = a[j];
       for (int k = 0; k < i; k++) {
         if (j != k) x *= 1 - a[k];
       }
       sum += x;
     }
     ans = max(sum, ans);
   }
   printf( .12lf
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int a[200][3];
 int main() {
   ios ::sync_with_stdio(false);
   cin.tie(0);
   ;
   long long int i, k, l, n, j;
   cin >> n;
   for (i = 0; i <= n - 1; i++) cin >> a[i][0] >> a[i][1];
   cin >> j;
   for (i = 0; i <= n - 1; i++)
     if (j >= a[i][0] && j <= a[i][1]) {
       cout << n - i << endl;
       return 0;
     }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int N, K;
 string S;
 int vis[5050][5050];
 vector<pair<int, int>> nex[26];
 void dfs(int cur, int mask) {
   if (vis[cur][mask] || cur + 1 + mask > N) return;
   vis[cur][mask] = 1;
   int i;
   nex[S[cur] - 'a'].push_back({cur + 1, mask});
   for (i = 0; i < (K); i++)
     if (mask & (1 << i)) dfs(cur + (1 << i), mask ^ (1 << i));
 }
 void solve() {
   int i, j, k, l, r, x, y;
   string s;
   cin >> S;
   N = S.size();
   while (1 << (K + 1) <= N) K++;
   vector<pair<int, int>> now;
   now.push_back({0, (1 << K) - 1});
   while (now.size()) {
     for (i = 0; i < (26); i++) nex[i].clear();
     for (auto& n : now) dfs(n.first, n.second);
     char c = 'z' + 1;
     for (i = 25; i >= 0; i--)
       if (nex[i].size()) c = 'a' + i;
     if (c == 'z' + 1) break;
     cout << c;
     swap(now, nex[c - 'a']);
   }
   cout << endl;
 }
 int main(int argc, char** argv) {
   string s;
   int i;
   if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
   for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '
';
   for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
   cout.tie(0);
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 pair<double, double> get_vec_rotate(pair<double, double> nv, double fi) {
   return make_pair(nv.first * cos(fi) - nv.second * sin(fi),
                    nv.second * cos(fi) + nv.first * sin(fi));
 }
 pair<double, double> get_normal(pair<double, double> vec) {
   double len = sqrt(vec.first * vec.first + vec.second * vec.second);
   vec.first /= len;
   vec.second /= len;
   return vec;
 }
 pair<double, double> end_p(pair<double, double> start_p,
                            pair<double, double> nv, double len) {
   nv.first *= len;
   nv.second *= len;
   return make_pair(nv.first + start_p.first, nv.second + start_p.second);
 }
 double a, b, c, d;
 pair<double, double> p, v, ToWrite;
 pair<double, double> len_fi[7];
 int main() {
   cin >> p.first >> p.second >> v.first >> v.second >> a >> b >> c >> d;
   v = get_normal(v);
   len_fi[0].first = b;
   len_fi[0].second = 0;
   len_fi[1].first = a / 2;
   len_fi[1].second = M_PI / 2;
   len_fi[2].first = c / 2;
   len_fi[2].second = M_PI / 2;
   len_fi[3].first = sqrt(c * c + 4 * d * d) / 2;
   len_fi[3].second = M_PI / 2 + atan(2 * d / c);
   len_fi[4].first = sqrt(c * c + 4 * d * d) / 2;
   len_fi[4].second = 3 * M_PI / 2 - atan(2 * d / c);
   len_fi[5].first = c / 2;
   len_fi[5].second = 3 * M_PI / 2;
   len_fi[6].first = a / 2;
   len_fi[6].second = 3 * M_PI / 2;
   cout.precision(10);
   for (int i = 0; i < 7; i++) {
     ToWrite = end_p(p, get_vec_rotate(v, len_fi[i].second), len_fi[i].first);
     cout << fixed << ToWrite.first << ' ' << ToWrite.second << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 int T;
 int n, m;
 bool get() {
   char ch = getchar();
   while (ch != 'O' && ch != 'X') ch = getchar();
   return (ch == 'X');
 }
 int map[21][21], con[4001][2], top, cnt[4001], head[401], nxt[100001],
     b[100001], k = 1, dis[4001], pre[4001];
 char ans[41][41];
 int q[4001], h, t;
 void push(int s, int t) {
   nxt[++k] = head[s];
   head[s] = k;
   b[k] = t;
 }
 bool iscut[4001], chosen[4001], lim[4001], good[4001][4001];
 std::vector<int> vec[4001];
 int Cnt;
 int hash(int i, int j) { return (i - 1) * m + j; }
 void dfs(int x, bool *vis) {
   if (vis[x]) return;
   ++Cnt;
   vis[x] = 1;
   for (int i = head[x]; i; i = nxt[i])
     if (!chosen[i >> 1]) dfs(b[i], vis);
 }
 int main() {
   scanf( d , &T);
   for (int fd = 1; fd <= T; fd++) {
     scanf( dd , &n, &m);
     int all = 0;
     top = 0;
     memset(chosen, 0, sizeof chosen);
     memset(lim, 0, sizeof lim);
     memset(head, 0, sizeof head);
     k = 1;
     for (int i = 1; i <= n; i++)
       for (int j = 1; j <= m; j++) map[i][j] = get(), all += (!map[i][j]);
     for (int i = 1; i < n; i++)
       for (int j = 1; j <= m; j++)
         if (!map[i][j] && !map[i + 1][j]) {
           ++top;
           con[top][0] = hash(i, j);
           con[top][1] = hash(i + 1, j);
           push(hash(i, j), hash(i + 1, j));
           push(hash(i + 1, j), hash(i, j));
         }
     for (int i = 1; i <= n; i++)
       for (int j = 1; j < m; j++)
         if (!map[i][j] && !map[i][j + 1]) {
           ++top;
           con[top][0] = hash(i, j);
           con[top][1] = hash(i, j + 1);
           push(hash(i, j), hash(i, j + 1));
           push(hash(i, j + 1), hash(i, j));
         }
     for (int i = 1; i <= n; i++)
       for (int j = 1; j <= m; j++)
         if ((i + j)  2 == 0 && (i > 1 || j > 1)) lim[hash(i, j)] = 1;
     memset(cnt, 0, sizeof cnt);
     for (int i = 1; i <= top; i++) {
       ++cnt[con[i][0]], ++cnt[con[i][1]];
     }
     bool cando = 1;
     for (int i = 1; i <= n; i++)
       for (int j = 1; j <= m; j++)
         if (lim[hash(i, j)] && cnt[hash(i, j)] <= 1 && !map[i][j]) {
           cando = 0;
         }
     memset(good[0], 0, sizeof good[0]);
     Cnt = 0;
     dfs(1, good[0]);
     if (Cnt < all) cando = 0;
     if (!cando)
       puts( NO );
     else {
       for (;;) {
         memset(cnt, 0, sizeof cnt);
         for (int i = 1; i <= top; i++)
           if (!chosen[i]) {
             if (lim[con[i][0]])
               ++cnt[con[i][0]];
             else
               ++cnt[con[i][1]];
             Cnt = 0;
             chosen[i] = 1;
             memset(good[i], 0, sizeof good[i]);
             dfs(1, good[i]);
             iscut[i] = (Cnt < all);
             chosen[i] = 0;
           }
         for (int i = 1; i <= top; i++) vec[i].clear();
         for (int i = 1; i <= top; i++)
           if (chosen[i])
             for (int j = 1; j <= top; j++)
               if (!chosen[j]) {
                 int u = (lim[con[i][0]] ? con[i][0] : con[i][1]),
                     v = (lim[con[j][0]] ? con[j][0] : con[j][1]);
                 if (u == v || cnt[v] >= 3) {
                   vec[j].push_back(i);
                 }
                 if (!iscut[j] || good[j][con[i][0]] != good[j][con[i][1]]) {
                   vec[i].push_back(j);
                 }
               }
         h = t = 0;
         for (int i = 1; i <= top; i++) {
           dis[i] = 0x7f7f7f7f;
           pre[i] = 0;
           if (!chosen[i] && !iscut[i]) dis[i] = 0, q[++t] = i;
         }
         while (h < t) {
           ++h;
           for (int i = 0; i < vec[q[h]].size(); i++)
             if (dis[vec[q[h]][i]] == 0x7f7f7f7f) {
               dis[vec[q[h]][i]] = dis[q[h]] + 1;
               q[++t] = vec[q[h]][i];
               pre[vec[q[h]][i]] = q[h];
             }
         }
         int p = 0;
         for (int i = 1; i <= top; i++) {
           if (!chosen[i] && (cnt[con[i][0]] >= 3 || !lim[con[i][0]]) &&
               (cnt[con[i][1]] >= 3 || !lim[con[i][1]]) &&
               dis[i] != 0x7f7f7f7f) {
             if (!p || dis[p] > dis[i]) p = i;
           }
         }
         if (!p) break;
         while (p) {
           chosen[p] ^= 1;
           p = pre[p];
         }
       }
       Cnt = 0;
       for (int i = 1; i <= top; i++) Cnt += (!chosen[i]);
       if (Cnt != all - 1)
         puts( NO );
       else {
         puts( YES );
         for (int i = 1; i <= (n << 1); i++)
           for (int j = 1; j <= (m << 1); j++) ans[i][j] = ' ';
         for (int i = 1; i <= n; i++)
           for (int j = 1; j <= m; j++)
             ans[(i << 1) - 1][(j << 1) - 1] = (map[i][j]) ? 'X' : 'O';
         for (int i = 1; i <= top; i++)
           if (!chosen[i]) {
             int u = con[i][0], v = con[i][1];
             if (v == u + 1)
               ans[(((u - 1) / m + 1) << 1) - 1][((u - 1)  m + 1) << 1] = 'O';
             else
               ans[(((u - 1) / m + 1) << 1)][(((u - 1)  m + 1) << 1) - 1] = 'O';
           }
         for (int i = 1; i < (n << 1); i++, putchar('
'))
           for (int j = 1; j < (m << 1); j++) putchar(ans[i][j]);
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 struct node {
   int active;
   set<int> prev, next;
   node() : active(1) {}
 };
 int main() {
   int n, k, m, i, j;
   int a, b;
   cin >> n >> m;
   int cnt = 1;
   set<int> sh;
   set<int>::iterator it;
   for (i = 0; i < n; i++) sh.insert(i);
   node* graf = new node[n];
   for (i = 0; i < m; i++) {
     cin >> a >> b;
     a--, b--;
     if (graf[a].active == 0) continue;
     if (graf[b].prev.size() == 0) sh.erase(b);
     graf[a].next.insert(b);
     graf[b].prev.insert(a);
     while (sh.size() == 1) {
       k = *sh.begin();
       cnt++;
       if (cnt == n) {
         cout << i + 1 << endl;
         return 0;
       }
       for (it = graf[k].next.begin(); it != graf[k].next.end(); it++) {
         j = *it;
         graf[j].prev.erase(k);
         if (graf[j].prev.size() == 0) sh.insert(j);
       }
       sh.erase(k);
       graf[k].active = 0;
     }
   }
   cout << -1 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long maxn = 2e5 + 7;
 struct Node {
   long long x, y;
 } node[maxn];
 bool cmp(Node a, Node b) { return a.x < b.x; }
 long long n, k;
 long long len[maxn];
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   int t;
   cin >> t;
   while (t--) {
     cin >> n >> k;
     for (int i = 0; i < n; i++) cin >> node[i].x;
     for (int i = 0; i < n; i++) cin >> node[i].y;
     sort(node, node + n, cmp);
     long long tarl, tarr;
     for (tarr = tarl = 0; tarr < n; tarr++) {
       while (node[tarl].x < node[tarr].x - k) tarl++;
       len[tarr] = tarr - tarl + 1;
     }
     long long ans = 0, Max = 0;
     for (tarr = tarl = 0; tarr < n; tarr++) {
       while (node[tarl].x < node[tarr].x - k) {
         Max = max(Max, len[tarl]);
         tarl++;
       }
       ans = max(Max + len[tarr], ans);
     }
     cout << ans << endl;
     for (int i = 0; i < n; i++) len[i] = 0;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma GCC target( avx2 )
 #pragma GCC optimization( unroll-loops )
 #pragma GCC optimize( O2 )
 constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
 constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
 constexpr long long INF = 1999999999999999997;
 constexpr int inf = INT_MAX;
 constexpr int MAXSIZE = int(1e6) + 5;
 constexpr auto PI = 3.14159265358979323846L;
 constexpr auto oo = numeric_limits<int>::max() / 2 - 2;
 constexpr auto eps = 1e-6;
 constexpr auto mod = 1000000007;
 constexpr auto MOD = 1000000007;
 constexpr auto MOD9 = 1000000009;
 constexpr auto maxn = 100006;
 template <typename T, size_t N>
 int SIZE(const T (&t)[N]) {
   return N;
 }
 template <typename T>
 int SIZE(const T &t) {
   return t.size();
 }
 string to_string(string s, int x1 = 0, int x2 = 1e9) {
   return ' ' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) + ' ';
 }
 string to_string(const char *s) { return to_string((string)s); }
 string to_string(bool b) { return (b ?  true  :  false ); }
 string to_string(char c) { return string({c}); }
 template <size_t N>
 string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) {
   string t =   ;
   for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);
        __iii__ <= __jjj__; ++__iii__) {
     t += b[__iii__] + '0';
   }
   return ' ' + t + ' ';
 }
 template <typename A, typename... C>
 string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords);
 int l_v_l_v_l = 0, t_a_b_s = 0;
 template <typename A, typename B>
 string to_string(pair<A, B> &p) {
   l_v_l_v_l++;
   string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;
   l_v_l_v_l--;
   return res;
 }
 template <typename A, typename... C>
 string to_string(A(&v), int x1, int x2, C... coords) {
   int rnk = rank<A>::value;
   string tab(t_a_b_s, ' ');
   string res =   ;
   bool first = true;
   if (l_v_l_v_l == 0) res += '
';
   res += tab +  [ ;
   x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
   auto l = begin(v);
   advance(l, x1);
   auto r = l;
   advance(r, (x2 - x1) + (x2 < SIZE(v)));
   for (auto e = l; e != r; e = next(e)) {
     if (!first) {
       res +=  ,  ;
     }
     first = false;
     l_v_l_v_l++;
     if (e != l) {
       if (rnk > 1) {
         res += '
';
         t_a_b_s = l_v_l_v_l;
       };
     } else {
       t_a_b_s = 0;
     }
     res += to_string(*e, coords...);
     l_v_l_v_l--;
   }
   res +=  ] ;
   if (l_v_l_v_l == 0) res += '
';
   return res;
 }
 void dbgs() { ; }
 template <typename Heads, typename... Tails>
 void dbgs(Heads H, Tails... T) {
   cout << to_string(H) <<   |  ;
   dbgs(T...);
 }
 int main() {
   int n, d;
   cin >> n >> d;
   int m;
   cin >> m;
   while (m--) {
     int x, y;
     cin >> x >> y;
     if (x + y - d >= 0 && y + x - 2 * n + d <= 0 && y - x - d <= 0 &&
         x - y - d <= 0)
       cout <<  YES
            <<
 ;
     else {
       cout <<  NO
            <<
 ;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mxN = 2e5 + 10;
 vector<int> a[mxN];
 int main() {
   int n, k;
   cin >> n >> k;
   for (int i = 0; i < n; i++) {
     int cnt = 0, x;
     cin >> x;
     while (true) {
       a[x].push_back(cnt);
       if (!x) break;
       x >>= 1;
       cnt++;
     }
   }
   int ans = 1e9;
   for (int i = 0; i < mxN; i++) {
     if (a[i].size() >= k) {
       sort(a[i].begin(), a[i].end());
       int cnt = 0;
       for (int j = 0; j < k; j++) cnt += a[i][j];
       ans = min(ans, cnt);
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long inf = 1LL << 28;
 const long long mod = 1LL;
 vector<int> adj[30];
 long long b_search(int val, int indx) {
   int lo, hi, mid;
   long long ans = 1e12;
   lo = 0;
   hi = (int)adj[indx].size() - 1;
   while (lo <= hi) {
     mid = (lo + hi) / 2;
     if (adj[indx][mid] == val) return 0;
     if (adj[indx][mid] < val)
       lo = mid + 1;
     else
       hi = mid - 1;
     ans = min(ans, (long long)abs(val - adj[indx][mid]));
   }
   return ans;
 }
 int main() {
   int n, k, i, j;
   long long l;
   string s, c;
   while (scanf( d d , &n, &k) == 2) {
     for (i = 0; i < 26; i++) adj[i].clear();
     cin >> s;
     for (i = 0; i < s.length(); i++) {
       adj[s[i] - 'a'].push_back(i);
     }
     while (n--) {
       l = 0;
       cin >> c;
       for (i = 0; i < c.length(); i++) {
         if ((int)adj[c[i] - 'a'].size() == 0)
           l += (int)c.size();
         else
           l += b_search(i, c[i] - 'a');
       }
       printf( extra
 , l);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 bool umin(T& a, T b) {
   if (a > b) {
     a = b;
     return 1;
   }
   return 0;
 }
 template <class T>
 bool umax(T& a, T b) {
   if (a < b) {
     a = b;
     return 1;
   }
   return 0;
 }
 long long dp[200009][2], a, par[200009];
 priority_queue<long long> bg;
 priority_queue<long long, vector<long long>, greater<long long> > sm;
 void upd(long long type, long long x) {
   if (!type)
     sm.push(x);
   else
     bg.push(x);
 }
 long long tap(long long type) {
   if (!type) return sm.top();
   return bg.top();
 }
 int main() {
   memset(dp, -1, sizeof dp);
   scanf( lld , &a);
   for (long long i = 1; i <= a; i++) {
     long long x;
     scanf( lld , &x);
     par[i] = par[i - 1] + x;
   }
   long long ans = -100000000924052357;
   upd(0, -par[a]);
   upd(1, par[a]);
   for (long long i = a; i >= 3; i--) {
     dp[i][0] = tap(1);
     dp[i][1] = tap(0);
     upd(0, dp[i][0] - par[i - 1]);
     upd(1, dp[i][1] + par[i - 1]);
     umax(ans, dp[i][1] + par[i - 1]);
   }
   printf( lld
 , max(ans, par[a]));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long SZ = 1e5 + 4;
 const double EPS = 1e-7;
 const long long mod = 1e9 + 7;
 const long long hashpow = 2;
 const long long inf = 2e9;
 struct custom_hash {
   static uint64_t splitmix64(uint64_t x) {
     x += 0x9e3779b97f4a7c15;
     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
     x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
     return x ^ (x >> 31);
   }
   size_t operator()(uint64_t x) const {
     static const uint64_t FIXED_RANDOM =
         chrono::steady_clock::now().time_since_epoch().count();
     return splitmix64(x + FIXED_RANDOM);
   }
 };
 long long n;
 void read() {
   cin >> n;
   --n;
 }
 void solve() {
   long long x = 1;
   long long m = n  3;
   n /= 3;
   long long cnt = 0;
   while (n >= x) {
     n -= x;
     x *= 4;
     ++cnt;
   }
   long long a = 1;
   long long b = 2;
   long long c = 3;
   vector<long long> y;
   while (n) {
     y.push_back(n  4);
     n /= 4;
   }
   while (y.size() < cnt) {
     y.push_back(0);
   }
   for (long long i = (long long)(y.size()) - 1; i >= 0; --i) {
     a *= 4;
     b *= 4;
     c *= 4;
     if (y[i] == 1) {
       a += 1;
       b += 2;
       c += 3;
     } else if (y[i] == 2) {
       a += 2;
       b += 3;
       c += 1;
     } else if (y[i] == 3) {
       a += 3;
       b += 1;
       c += 2;
     }
   }
   if (m == 0) {
     cout << a <<
 ;
   } else if (m == 1) {
     cout << b <<
 ;
   } else {
     cout << c <<
 ;
   }
 }
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   long long t;
   cin >> t;
   for (long long i = 0; i < t; ++i) {
     read();
     solve();
   }
   return 0;
 }