#include <bits/stdc++.h>
 using namespace std;
 template <typename T1, typename T2>
 inline T1 max(T1 a, T2 b) {
   return a < b ? b : a;
 }
 template <typename T1, typename T2>
 inline T1 min(T1 a, T2 b) {
   return a < b ? a : b;
 }
 const char lf = '
';
 namespace ae86 {
 const int bufl = 1 << 15;
 char buf[bufl], *s = buf, *t = buf;
 inline int fetch() {
   if (s == t) {
     t = (s = buf) + fread(buf, 1, bufl, stdin);
     if (s == t) return EOF;
   }
   return *s++;
 }
 inline int ty() {
   int a = 0;
   int b = 1, c = fetch();
   while (!isdigit(c)) b ^= c == '-', c = fetch();
   while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
   return b ? a : -a;
 }
 }  // namespace ae86
 using ae86::ty;
 const int _ = 100007, __ = _ << 1;
 const long long linf = 0x3f3f3f3f3f3f3f3f;
 int to[__], ne[__], he[_] = {0}, ecnt = 1;
 inline void adde(int a, int b) {
   to[++ecnt] = b, ne[ecnt] = he[a], he[a] = ecnt;
 }
 inline void addde(int a, int b) { adde(a, b), adde(b, a); }
 int n, m, qn;
 int fa[_] = {0}, dep[_] = {0}, sz[_] = {0}, mxch[_] = {0};
 void dfs(int x, int ff) {
   fa[x] = ff, dep[x] = dep[ff] + 1, sz[x] = 1, mxch[x] = 0;
   for (int i = he[x]; i; i = ne[i]) {
     int b = to[i];
     if (b == ff) continue;
     dfs(b, x), sz[x] += sz[b];
     if (sz[mxch[x]] < sz[b]) mxch[x] = b;
   }
 }
 int dfn[_] = {0}, rdfn[_] = {0}, ndf[_] = {0}, top[_] = {0}, dcnt = 0;
 void dfs2(int x, int tp) {
   dfn[x] = ++dcnt, rdfn[dcnt] = x, top[x] = tp;
   if (mxch[x]) dfs2(mxch[x], tp);
   for (int i = he[x]; i; i = ne[i]) {
     int b = to[i];
     if (b == fa[x] || b == mxch[x]) continue;
     dfs2(b, b);
   }
   ndf[x] = dcnt;
 }
 vector<int> hav[_];
 struct cxk {
   int x;
   long long v;
   cxk(int x_ = 0, long long v_ = linf) { x = x_, v = v_; }
   friend bool operator<(cxk a, cxk b) {
     if (a.v != b.v) return a.v < b.v;
     return a.x < b.x;
   }
 };
 const int _t = _ << 2;
 cxk t[_t];
 long long tadd[_t];
 void up(int x) { t[x] = min(t[(x << 1)], t[(x << 1 | 1)]); }
 void putadd(int x, long long d) { t[x].v += d, tadd[x] += d; }
 void dwn(int x) {
   if (tadd[x])
     putadd((x << 1), tadd[x]), putadd((x << 1 | 1), tadd[x]), tadd[x] = 0;
 }
 void plant(int x, int l, int r) {
   tadd[x] = 0;
   if (l == r) {
     t[x] = hav[l].empty() ? cxk() : cxk(l, hav[l].back());
     return;
   }
   plant((x << 1), l, ((l + r) >> 1)),
       plant((x << 1 | 1), ((l + r) >> 1) + 1, r), up(x);
 }
 void change(int x, int l, int r, int tl, int tr, long long dlt) {
   if (tl <= l && r <= tr) {
     putadd(x, dlt);
     return;
   }
   dwn(x);
   if (tl <= ((l + r) >> 1)) change((x << 1), l, ((l + r) >> 1), tl, tr, dlt);
   if (tr > ((l + r) >> 1))
     change((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr, dlt);
   up(x);
 }
 void dating(int x, int l, int r, int tar) {
   if (l == r) {
     if (!hav[l].empty()) hav[l].pop_back();
     t[x] = hav[l].empty() ? cxk() : cxk(l, hav[l].back() + tadd[x]);
     return;
   }
   dwn(x);
   if (tar <= ((l + r) >> 1))
     dating((x << 1), l, ((l + r) >> 1), tar);
   else
     dating((x << 1 | 1), ((l + r) >> 1) + 1, r, tar);
   up(x);
 }
 cxk finder(int x, int l, int r, int tl, int tr) {
   if (tl <= l && r <= tr) return t[x];
   dwn(x);
   if (tr <= ((l + r) >> 1)) return finder((x << 1), l, ((l + r) >> 1), tl, tr);
   if (tl > ((l + r) >> 1))
     return finder((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr);
   return min(finder((x << 1), l, ((l + r) >> 1), tl, tr),
              finder((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr));
 }
 cxk founder(int a, int b) {
   cxk ans;
   while (top[a] != top[b]) {
     if (dep[top[a]] < dep[top[b]]) swap(a, b);
     ans = min(ans, finder(1, 1, n, dfn[top[a]], dfn[a])), a = fa[top[a]];
   }
   if (dep[a] > dep[b]) swap(a, b);
   return min(ans, finder(1, 1, n, dfn[a], dfn[b]));
 }
 int main() {
   ios::sync_with_stdio(0), cout.tie(nullptr);
   n = ty(), m = ty(), qn = ty();
   for (int i = 1, a, b; i < n; i++) a = ty(), b = ty(), addde(a, b);
   dfs(1, 0), dfs2(1, 1);
   for (int i = 1; i <= m; i++) hav[dfn[ty()]].emplace_back(i);
   for (int i = 1; i <= n; i++)
     sort(hav[i].begin(), hav[i].end(), greater<int>());
   plant(1, 1, n);
   for (int qq = 1; qq <= qn; qq++) {
     int op = ty();
     if (op == 1) {
       int a = ty(), b = ty(), lim = ty();
       vector<int> ans;
       while (lim--) {
         int ret = founder(a, b).x;
         if (ret <= 0) break;
         ans.emplace_back(hav[ret].back()), dating(1, 1, n, ret);
       }
       cout << ans.size();
       for (auto i : ans) cout << ' ' << i;
       cout << lf;
     }
     if (op == 2) {
       int a = ty(), b = ty();
       change(1, 1, n, dfn[a], ndf[a], b);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 1010;
 int n;
 int a[MAX], c[MAX];
 void init() { cin >> n; }
 void process() {
   memset(a, 63, sizeof(a));
   vector<pair<int, int> > ques;
   ques.push_back(make_pair(1, n));
   while (!ques.empty()) {
     vector<pair<int, int> > newQues;
     for (int i = 0; i < ques.size(); i++) {
       if (ques[i].first != ques[i].second) {
         int l = ques[i].first, r = ques[i].second, mid = (l + r) / 2;
         newQues.push_back(make_pair(l, mid));
         newQues.push_back(make_pair(mid + 1, r));
       }
     }
     vector<int> b;
     for (int i = 0; i < newQues.size(); i += 2) {
       for (int j = newQues[i].first; j <= newQues[i].second; j++)
         b.push_back(j);
     }
     if (b.size() > 0) {
       cout << b.size() << '
';
       for (int i = 0; i < b.size(); i++) cout << b[i] <<    ;
       cout << '
';
       fflush(stdout);
       for (int i = 1; i <= n; i++) cin >> c[i];
       for (int i = 1; i <= n; i++) {
         bool check = true;
         for (int j = 0; j < b.size(); j++) {
           if (b[j] == i) {
             check = false;
             break;
           }
         }
         if (check) a[i] = min(a[i], c[i]);
       }
     }
     b.resize(0);
     for (int i = 1; i < newQues.size(); i += 2) {
       for (int j = newQues[i].first; j <= newQues[i].second; j++)
         b.push_back(j);
     }
     if (b.size() > 0) {
       cout << b.size() << '
';
       for (int i = 0; i < b.size(); i++) cout << b[i] <<    ;
       cout << '
';
       fflush(stdout);
       for (int i = 1; i <= n; i++) cin >> c[i];
       for (int i = 1; i <= n; i++) {
         bool check = true;
         for (int j = 0; j < b.size(); j++) {
           if (b[j] == i) {
             check = false;
             break;
           }
         }
         if (check) a[i] = min(a[i], c[i]);
       }
     }
     ques = newQues;
   }
   cout << -1 << '
';
   for (int i = 1; i <= n; i++) cout << a[i] <<    ;
   cout << '
';
   fflush(stdout);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   init();
   process();
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 300;
 long long orign[MAXN], str[2 * MAXN];
 int radius[2 * MAXN];
 int n, m;
 int mp[MAXN][MAXN];
 int num[MAXN][26];
 long long hashv[MAXN];
 long long base[30];
 int siz[MAXN];
 bool check(int x, int y) {
   for (int i = 0; i < 26; i++) {
     if (num[x][i] != num[y][i]) return false;
   }
   return true;
 }
 void Manacher(int len, int mark = 0) {
   for (int i = 0; i < len; i++) {
     str[2 * i + 1] = orign[i];
     str[2 * i] = mark;
   }
   str[2 * len] = mark;
   len = 2 * len + 1;
   int max_right = 0, pos = 0;
   for (int i = 0; i < len; i++) {
     if (i < max_right)
       radius[i] = min(radius[2 * pos - i], max_right - i);
     else
       radius[i] = 1;
     while (i - radius[i] >= 0 && i + radius[i] < len &&
            str[i - radius[i]] > -1 && str[i + radius[i]] > -1 &&
            check(str[i - radius[i]], str[i + radius[i]])) {
       radius[i]++;
     }
     if (i + radius[i] >= max_right) {
       max_right = i + radius[i];
       pos = i;
     }
   }
 }
 int main() {
   std::ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> n >> m;
   base[0] = 1;
   for (int i = 1; i <= 26; i++) base[i] = base[i - 1] * 2;
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= m; j++) {
       char ch;
       cin >> ch;
       mp[i][j] = ch - 'a';
     }
   }
   long long ans = 0;
   for (int l = 1; l <= m; l++) {
     memset(num, 0, sizeof(num));
     memset(hashv, 0, sizeof(hashv));
     memset(siz, 0, sizeof(siz));
     for (int r = l; r <= m; r++) {
       for (int i = 1; i <= n; i++) {
         int id = mp[i][r];
         num[i][id]++;
         hashv[i] += base[id];
         if (num[i][id] & 1)
           siz[i]++;
         else
           siz[i]--;
         if (siz[i] > 1)
           orign[i - 1] = -i;
         else
           orign[i - 1] = i;
       }
       Manacher(n);
       for (int i = 0; i < 2 * n + 1; i++) {
         if (str[i] > -1) ans += radius[i] / 2;
       }
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 10000010;
 int p[N], num, last[N];
 bool flag[N];
 int cnt[N], n, m;
 void make_prime() {
   for (int i = 2; i < N; ++i)
     if (!flag[i]) {
       p[num++] = i;
       last[i] = i;
       for (int j = i + i; j < N; j += i) flag[j] = true, last[j] = i;
     }
 }
 int main() {
   make_prime();
   scanf( %d , &n);
   for (int i = 0, x; i < n; ++i) {
     scanf( %d , &x);
     int s = -1;
     while (x != 1) {
       if (last[x] != s) cnt[last[x]]++;
       s = last[x];
       x /= last[x];
     }
   }
   for (int i = 1; i < N; ++i) cnt[i] += cnt[i - 1];
   scanf( %d , &m);
   for (int i = 0, x, y; i < m; ++i) {
     scanf( %d %d , &x, &y);
     if (x >= N)
       puts( 0 );
     else {
       y = min(y, N - 1);
       printf( %d
 , cnt[y] - cnt[x - 1]);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 0x3f3f3f3f;
 const int N = 2005;
 const int M = 730;
 int Head[M * 10], Next[M * 100], vet[M * 100];
 int a[N], b[N], d[M * 10], vis[15], p[M][5], dis[M], Dis[M], P[10], len[M],
     U[M][12], D[M][12];
 int n, cnt, edgenum;
 pair<int, int> c[M];
 queue<int> q;
 inline int F(int x, int y) { return (x - 1) * cnt + y; }
 inline void addedge(int u, int v) {
   edgenum++;
   vet[edgenum] = v;
   Next[edgenum] = Head[u];
   Head[u] = edgenum;
 }
 int main() {
   scanf( %d , &n);
   int ans = INF;
   for (int i = 1; i <= n; i++) scanf( %d%d , &a[i], &b[i]);
   len[cnt = 1] = 0;
   for (int i = 1; i <= 9; i++) {
     len[++cnt] = 1;
     p[cnt][1] = i;
     for (int j = i; j <= 9; j++) {
       len[++cnt] = 2;
       p[cnt][1] = i, p[cnt][2] = j;
       for (int k = j; k <= 9; k++) {
         len[++cnt] = 3;
         p[cnt][1] = i, p[cnt][2] = j, p[cnt][3] = k;
         for (int t = k; t <= 9; t++)
           len[++cnt] = 4, p[cnt][1] = i, p[cnt][2] = j, p[cnt][3] = k,
           p[cnt][4] = t;
       }
     }
   }
   for (int i = 2; i <= cnt; i++) {
     memset(vis, 0, sizeof(vis));
     for (int j = 1; j <= len[i]; j++) vis[p[i][j]] = 1;
     for (int j = 1; j <= 9; j++) {
       if (!vis[j]) continue;
       int res = j, cur = 0;
       for (int k = 1; k <= len[i]; k++)
         if (p[i][k] == res)
           res = -1;
         else
           P[++cur] = p[i][k];
       for (int k = 1; k <= cnt; k++) {
         if (len[k] != cur) continue;
         bool flag = 1;
         for (int t = 1; t <= cur; t++) flag &= (P[t] == p[k][t]);
         if (flag) {
           D[i][j] = k;
           U[k][j] = i;
           break;
         }
       }
     }
   }
   memset(dis, 0x3f, sizeof(dis));
   dis[1] = a[1] - 1;
   for (int j = 1; j < 9; j++)
     for (int k = 1; k <= cnt; k++)
       addedge(F(j, k), F(j + 1, k)), addedge(F(j + 1, k), F(j, k));
   for (int j = 1; j <= 9; j++)
     for (int k = 1; k <= cnt; k++)
       if (D[k][j]) addedge(F(j, k), F(j, D[k][j]));
   for (int i = 1; i <= n; i++) {
     memset(Dis, 0x3f, sizeof(Dis));
     for (int j = 1; j <= cnt; j++)
       if (U[j][b[i]]) Dis[U[j][b[i]]] = min(Dis[U[j][b[i]]], dis[j] + 1);
     for (int j = 1; j <= cnt; j++) dis[j] = Dis[j];
     memset(d, 0x3f, sizeof(d));
     for (int j = 1; j <= cnt; j++)
       d[F(a[i], j)] = dis[j], c[j] = make_pair(dis[j], j);
     sort(c + 1, c + 1 + cnt);
     for (int j = 1; j <= cnt; j++)
       if (c[j].first != INF) q.push(F(a[i], c[j].second));
     while (!q.empty()) {
       int u = q.front();
       q.pop();
       for (int e = Head[u]; e; e = Next[e]) {
         int v = vet[e];
         if (d[v] > d[u] + 1) d[v] = d[u] + 1, q.push(v);
       }
     }
     if (i == n)
       for (int j = 1; j <= 9; j++) ans = min(ans, d[F(j, 1)]);
     else
       for (int j = 1; j <= cnt; j++) dis[j] = d[F(a[i + 1], j)];
   }
   printf( %d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 3003 * 6006;
 const int qwq = 303030;
 const int inf = 0x3f3f3f3f;
 int n, m, k;
 int f[N], fa[N], st[123], cnt;
 int ans;
 int ff[] = {1, 1, 1, 0, -1, -1, -1, 0};
 int gg[] = {1, 0, -1, -1, -1, 0, 1, 1};
 inline int read() {
   int sum = 0, f = 1;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') f = -1;
     c = getchar();
   }
   while (c >= '0' && c <= '9') {
     sum = sum * 10 + c - '0';
     c = getchar();
   }
   return sum * f;
 }
 inline int dian(int x, int y) {
   if (y == 0) y = 2 * m;
   if (y == 2 * m + 1) y = 1;
   return (x - 1) * (m << 1) + y;
 }
 int find(int u) {
   while (fa[u] != u) u = fa[u];
   return u;
 }
 int Splay(int u) { return fa[u] == u ? u : fa[u] = Splay(fa[u]); }
 int main() {
   int x, y;
   n = read();
   m = read();
   k = read();
   if (m == 1) {
     cout << 0;
     return 0;
   }
   for (int i = 1; i <= n * m * 2; i++) fa[i] = i;
   while (k--) {
     cnt = 0;
     x = read();
     y = read();
     for (int i = 0; i <= 8; i++) {
       if (x + ff[i] < 1 || x + ff[i] > n) continue;
       int u = dian(x + ff[i], y + gg[i]);
       if (!f[u]) continue;
       int aa = find(u);
       int bb = find(dian(x, y));
       if (aa == bb) continue;
       st[++cnt] = bb;
       fa[bb] = aa;
     }
     y += m;
     for (int i = 0; i < 8; i++) {
       if (x + ff[i] < 1 || x + ff[i] > n) continue;
       int u = dian(x + ff[i], y + gg[i]);
       if (!f[u]) continue;
       int aa = find(u);
       int bb = find(dian(x, y));
       if (aa == bb) continue;
       st[++cnt] = bb;
       fa[bb] = aa;
     }
     y -= m;
     if (find(dian(x, y)) != find(dian(x, y + m))) {
       ans++;
       for (int i = 0; i < 8; i++) {
         if (x + ff[i] < 1 || x + ff[i] > n) continue;
         Splay(dian(x + ff[i], y + gg[i]));
       }
       y += m;
       for (int i = 0; i < 8; i++) {
         if (x + ff[i] < 1 || x + ff[i] > n) continue;
         Splay(dian(x + ff[i], y + gg[i]));
       }
       y -= m;
       f[dian(x, y)] = f[dian(x, y + m)] = 1;
     } else {
       for (int i = 1; i <= cnt; i++) fa[st[i]] = st[i];
     }
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, sum;
 int main() {
   cin >> n;
   while (n != 0) {
     if (n % 8 == 1) sum++;
     n /= 8;
   }
   cout << sum;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1 << 29;
 const int MOD = 1000000007;
 bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
 void fastio() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
 }
 const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
 int main() {
   fastio();
   int t = 1;
   while (t--) {
     int n;
     cin >> n;
     string s;
     cin >> s;
     int ans = 0;
     for (int i = 0; i < (s.length()); i++) {
       int x = int(s[i]) - 48;
       if (x % 2 == 0) ans += (i + 1);
     }
     cout << ans <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 map<long long, int> mp;
 int n;
 int main() {
   scanf( %d , &n);
   int t;
   long long s = 0;
   for (int i = 1; i <= n; i++) {
     scanf( %d , &t);
     s += t;
     mp[s]++;
   }
   int ans = 0;
   map<long long, int>::iterator it;
   for (it = mp.begin(); it != mp.end(); it++) {
     ans = max(ans, it->second);
   }
   printf( %d
 , n - ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> edge[100005];
 int v[100005];
 bool cycle = false;
 int mx = -1, last;
 void dfs(int u, int dis = 0) {
   v[u] = 1;
   if (dis > mx) {
     mx = dis;
     last = u;
   }
   for (int i = 0; i <= (int)((int)edge[u].size() - 1); i++) {
     int first = edge[u][i];
     if (!v[first]) dfs(first, dis + 1);
   }
 }
 int main() {
   int T, n, m, a, b;
   scanf( %d , &n);
   scanf( %d , &m);
   for (int i = 1; i <= (int)(m); i++) {
     scanf( %d%d , &a, &b);
     edge[a].push_back(b);
     edge[b].push_back(a);
   }
   dfs(1);
   memset(v, 0, sizeof(v));
   mx = -1;
   dfs(last);
   printf( %d , mx);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1 << 29;
 const double EPS = 1e-10;
 vector<int> G[50010];
 vector<int> chil[50010];
 int cnt[50010][510];
 void dfs(int pos, int par) {
   for (int i = 0; i < (int)G[pos].size(); i++) {
     if (G[pos][i] != par) {
       chil[pos].push_back(G[pos][i]);
       dfs(G[pos][i], pos);
     }
   }
 }
 void init(int n) {
   memset(cnt, 0, sizeof(cnt));
   dfs(0, -1);
 }
 void calc(int v, int k, long long &sum) {
   for (int i = 0; i < (int)chil[v].size(); i++) {
     int c = chil[v][i];
     calc(c, k, sum);
     for (int j = 0; j < k; j++) {
       sum += (long long)cnt[c][j] * cnt[v][k - j - 1];
     }
     for (int j = 0; j < k; j++) {
       cnt[v][j + 1] += cnt[c][j];
     }
   }
   cnt[v][0] = 1;
   sum += (long long)cnt[v][0] * cnt[v][k];
 }
 int main() {
   int n, k, a, b;
   cin >> n >> k;
   for (int i = 0; i < n - 1; i++) {
     cin >> a >> b;
     a--, b--;
     G[a].push_back(b);
     G[b].push_back(a);
   }
   init(n);
   long long res = 0;
   calc(0, k, res);
   cout << res << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct P {
   int x, y;
   bool operator<(const P &p) {
     if (x != p.x)
       return x < p.x;
     else
       return y < p.y;
   }
 };
 int main() {
   int T;
   cin >> T;
   for (int t = 0; t < T; ++t) {
     int n;
     cin >> n;
     int bsz = n / 3;
     vector<int> buf(bsz);
     for (int i = 0; i < n / 3; ++i) {
       cout <<  ?   << 3 * i + 1 <<     << 3 * i + 2 <<     << 3 * i + 3 << endl;
       cout.flush();
       cin >> buf[i];
       if (buf[i] == -1) {
         break;
       }
     }
     int ind0, ind1;
     for (int i = 0; i < bsz; ++i) {
       int indl = i;
       int indr = (i + 1) % bsz;
       if (buf[indl] != buf[indr]) {
         vector<int> tbuf(6);
         tbuf[0] = buf[indl];
         for (int j = 1; j <= 5; ++j) {
           int v1 = (3 * indl + j) % n + 1;
           int v2 = (3 * indl + j + 1) % n + 1;
           int v3 = (3 * indl + j + 2) % n + 1;
           cout <<  ?   << v1 <<     << v2 <<     << v3 << endl;
           cout.flush();
           cin >> tbuf[j];
           if (tbuf[j] == -1) {
             break;
           }
           if (tbuf[j - 1] != tbuf[j]) {
             if (tbuf[j - 1] == 0) {
               ind0 = (3 * indl + j - 1) % n + 1;
               ind1 = v3;
             } else {
               ind1 = (3 * indl + j - 1) % n + 1;
               ind0 = v3;
             }
             break;
           }
         }
         break;
       }
     }
     vector<int> mapping(n);
     mapping[ind1 - 1] = 1;
     int tmp;
     for (int i = 0; i < bsz; ++i) {
       int v1 = 3 * i + 1;
       int v2 = 3 * i + 2;
       int v3 = 3 * i + 3;
       if (buf[i] == 0) {
         if (v1 == ind1) {
           cout <<  ?   << ind1 <<     << ind0 <<     << v2 << endl;
         } else if (v2 == ind1) {
           cout <<  ?   << ind1 <<     << v1 <<     << ind0 << endl;
         } else {
           cout <<  ?   << ind1 <<     << v1 <<     << v2 << endl;
         }
         cout.flush();
         cin >> tmp;
         if (tmp == 0) {
           mapping[v1 - 1] = 0;
           mapping[v2 - 1] = 0;
           if (v3 == ind0) {
             tmp = 0;
           } else if (v3 == ind1) {
             tmp = 1;
           } else {
             cout <<  ?   << ind0 <<     << ind1 <<     << v3 << endl;
             cout.flush();
             cin >> tmp;
           }
           mapping[v3 - 1] = tmp;
         } else {
           mapping[v3 - 1] = 0;
           if (ind0 == v1) {
             tmp = 0;
           } else if (ind1 == v1) {
             tmp = 1;
           } else {
             cout <<  ?   << ind0 <<     << ind1 <<     << v1 << endl;
             cout.flush();
             cin >> tmp;
           }
           mapping[v1 - 1] = tmp;
           mapping[v2 - 1] = 1 - tmp;
         }
       } else {
         if (v1 == ind0) {
           cout <<  ?   << ind0 <<     << ind1 <<     << v2 << endl;
         } else if (v2 == ind0) {
           cout <<  ?   << ind0 <<     << v1 <<     << ind1 << endl;
         } else {
           cout <<  ?   << ind0 <<     << v1 <<     << v2 << endl;
         }
         cout.flush();
         cin >> tmp;
         if (tmp == 1) {
           mapping[v1 - 1] = 1;
           mapping[v2 - 1] = 1;
           if (v3 == ind0) {
             tmp = 0;
           } else if (v3 == ind1) {
             tmp = 1;
           } else {
             cout <<  ?   << ind0 <<     << ind1 <<     << v3 << endl;
             cout.flush();
             cin >> tmp;
           }
           mapping[v3 - 1] = tmp;
         } else {
           mapping[v3 - 1] = 1;
           if (v1 == ind0) {
             tmp = 0;
           } else if (v1 == ind1) {
             tmp = 1;
           } else {
             cout <<  ?   << ind0 <<     << ind1 <<     << v1 << endl;
             cout.flush();
             cin >> tmp;
           }
           mapping[v1 - 1] = tmp;
           mapping[v2 - 1] = 1 - tmp;
         }
       }
     }
     vector<int> fake;
     for (int i = 0; i < n; ++i) {
       if (mapping[i] == 0) {
         fake.push_back(i + 1);
       }
     }
     cout <<  !   << fake.size();
     for (int i = 0; i < fake.size(); ++i) {
       cout <<     << fake[i];
     }
     cout << endl;
     cout.flush();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, k, a, b, c, d;
   scanf( %d%d%d%d%d%d , &n, &k, &a, &b, &c, &d);
   if (n <= 4 || k < n + 1) {
     puts( -1 );
     return 0;
   }
   printf( %d %d , a, c);
   for (int i = 1; i <= n; i++) {
     if (i != a && i != b && i != c && i != d) printf(  %d , i);
   }
   printf(  %d %d
 , d, b);
   printf( %d %d , c, a);
   for (int i = 1; i <= n; i++) {
     if (i != a && i != b && i != c && i != d) printf(  %d , i);
   }
   printf(  %d %d
 , b, d);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 const int N = 2e5 + 10;
 const long long inf = 1e18;
 const int maxm = 1005;
 vector<vector<char>> matrix(maxm, vector<char>(maxm));
 struct event {
   int x, y, size;
 };
 int dx[] = {0, 0, 1, -1};
 int dy[] = {-1, 1, 0, 0};
 class even {
  public:
   int a, b, c;
 };
 class evenl {
  public:
   int a, b, c, ind;
 };
 struct myComp {
   constexpr bool operator()(evenl f, evenl s) const noexcept {
     int z = f.b - f.a;
     int z2 = s.b - s.a;
     z -= f.c;
     z2 -= s.c;
     return z < z2;
   }
 };
 long long poww(long long a, long long b, long long m) {
   if (b == 0) return 1ll;
   if (b % 2 == 1) return a * poww(a, b - 1, m) % m;
   long long rs = poww(a, b / 2, m);
   rs = rs * rs % m;
   return rs;
 }
 long long fact[N];
 long long ncr(long long n, long long r) {
   long long num = fact[n];
   long long deno = fact[n - r] * fact[r] % mod;
   deno = poww(deno, mod - 2, mod);
   num = num * deno;
   num = num % mod;
   return num;
 }
 long long convert(long long a, long long b) {
   string s;
   while (a > 0) {
     long long p = a % b;
     s += p + '0';
     a = a / b;
   }
   reverse(s.begin(), s.end());
   long long res = stoi(s);
   return res;
 }
 long long make(long long a, long long b, long long c) {
   while (a < b) a *= c;
   return a % b;
 }
 long long frog_jump(long long pos, long long n) {
   while (pos % 2 == 0) {
     pos = pos + (n - pos / 2);
   }
   return (pos + 1) / 2;
 }
 void solve() {
   long long n, q;
   cin >> n >> q;
   for (int i = 0; i < q; i++) {
     long long x;
     cin >> x;
     if (x % 2 != 0) {
       cout << (x + 1) / 2 <<
 ;
       continue;
     }
     long long z = frog_jump(x, n);
     cout << z <<
 ;
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   solve();
 }


#include <bits/stdc++.h>
 double aa[12];
 int sign[12];
 int compare(const void *a, const void *b) {
   int i = *(int *)a;
   int j = *(int *)b;
   if (sign[i] != sign[j]) return sign[j] - sign[i];
   if (sign[i] == 0) return i - j;
   return aa[i] == aa[j] ? i - j : aa[i] > aa[j] ? -sign[i] : sign[i];
 }
 void power(int i, double x, double y, double z) {
   if (x == 1)
     sign[i] = 0;
   else if (x > 1) {
     sign[i] = 1;
     aa[i] = z * log(y) + log(log(x));
   } else {
     sign[i] = -1;
     aa[i] = z * log(y) + log(-log(x));
   }
 }
 void power_(int i, double x, double yz) {
   if (x == 1)
     sign[i] = 0;
   else if (x > 1) {
     sign[i] = 1;
     aa[i] = log(yz) + log(log(x));
   } else {
     sign[i] = -1;
     aa[i] = log(yz) + log(-log(x));
   }
 }
 int main() {
   static char ss[12][16] = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,
                              y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,
                              z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };
   static int ii[12];
   double x, y, z;
   int i;
   scanf( %lf%lf%lf , &x, &y, &z);
   power(0, x, y, z);
   power(1, x, z, y);
   power_(2, x, y * z);
   power_(3, x, y * z);
   power(4, y, x, z);
   power(5, y, z, x);
   power_(6, y, x * z);
   power_(7, y, x * z);
   power(8, z, x, y);
   power(9, z, y, x);
   power_(10, z, x * y);
   power_(11, z, x * y);
   for (i = 0; i < 12; i++) ii[i] = i;
   qsort(ii, 12, sizeof *ii, compare);
   printf( %s
 , ss[ii[0]]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   int n, m;
   cin >> n >> m;
   vector<int> a(n);
   for (int i = 0; i < n; ++i) {
     cin >> a[i];
   }
   vector<int> rightInc(n), leftInc(n);
   int end = 0, cur_count = 1;
   for (int i = 0; i < n; ++i) {
     if (end < i) {
       end = i, cur_count = 1;
     }
     while (end + 1 < n && a[end + 1] >= a[end]) {
       end++, cur_count++;
     }
     rightInc[i] = end - i + 1, cur_count--;
   }
   reverse(a.begin(), a.end());
   end = 0, cur_count = 1;
   for (int i = 0; i < n; ++i) {
     if (end < i) {
       end = i, cur_count = 1;
     }
     while (end + 1 < n && a[end + 1] >= a[end]) {
       end++, cur_count++;
     }
     leftInc[i] = end - i + 1, cur_count--;
   }
   reverse(leftInc.begin(), leftInc.end());
   while (m--) {
     int l, r;
     cin >> l >> r;
     --l, --r;
     if (rightInc[l] + leftInc[r] >= r - l + 1)
       cout <<  Yes
 ;
     else
       cout <<  No
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 3e6 + 7;
 const int INF = 0x7fffffff;
 int n, m;
 struct DATA {
   int strid;
   int index;
 };
 vector<DATA> vec;
 string str[maxn];
 char ans[maxn];
 bool cmp(DATA a, DATA b) { return a.index < b.index; }
 int main() {
   while (cin >> n) {
     memset(ans, 0, sizeof(ans));
     vec.clear();
     for (int i = 0; i < n; i++) {
       int num;
       cin >> str[i];
       scanf( %d , &num);
       for (int j = 0; j < num; j++) {
         int k;
         scanf( %d , &k);
         k--;
         DATA t;
         t.strid = i;
         t.index = k;
         vec.push_back(t);
       }
     }
     int last = -1;
     sort(vec.begin(), vec.end(), cmp);
     for (int i = 0; i < vec.size(); i++) {
       for (int j = max(last + 1, vec[i].index);
            j < vec[i].index + str[vec[i].strid].size(); j++) {
         ans[j] = str[vec[i].strid][j - vec[i].index];
         last = max(last, j);
       }
     }
     for (int i = 0; i <= last; i++) {
       if (ans[i] != 0)
         printf( %c , ans[i]);
       else {
         printf( a );
       }
     }
     puts(  );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   scanf( %d , &n);
   long long int arr[100];
   for (int i = 0; i < n; i++) cin >> arr[i];
   long long int cnt[5];
   long long int p[5];
   for (int i = 0; i < 5; i++) cin >> p[i];
   long long int min = 1000000009;
   for (int i = 0; i < 5; i++)
     if (p[i] < min) min = p[i];
   for (int i = 0; i < 5; i++) cnt[i] = 0;
   long long int ps = 0;
   for (int i = 0; i < n; i++) {
     ps = ps + arr[i];
     while (ps >= min) {
       long long int pp;
       for (int j = 4; j >= 0; j--) {
         if (ps < min) break;
         pp = ps / p[j];
         ps = ps - pp * p[j];
         cnt[j] += pp;
       }
     }
   }
   for (int i = 0; i < 5; i++) cout << cnt[i] <<    ;
   cout <<
  << ps << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long t, n, m, cap, lis[200500], high, low;
 long long f(long long x) {
   long long res = 0, cnt = 0, buf = 0;
   for (int i = (0); i <= ((int)(n)-1); i++)
     if (lis[i] <= x) {
       if (!cnt) {
         res += buf;
         buf = 0;
       }
       cnt++;
       buf += lis[i];
       res += lis[i];
       if (cnt == m) {
         cnt = 0;
       }
     }
   return res;
 }
 long long g(long long x) {
   long long res = 0, task = 0, cnt = 0, buf = 0;
   for (int i = (0); i <= ((int)(n)-1); i++)
     if (lis[i] <= x) {
       if (!cnt) {
         res += buf;
         buf = 0;
       }
       if (res + lis[i] > cap) break;
       res += lis[i];
       cnt++;
       buf += lis[i];
       task++;
       if (cnt == m) {
         cnt = 0;
       }
     }
   return task;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin >> t;
   while (t--) {
     cin >> n >> m >> cap;
     for (int i = (0); i <= ((int)(n)-1); i++) cin >> lis[i];
     high = cap, low = 1;
     while (high > low) {
       long long chs = (high + low) / 2;
       if (f(chs) > cap)
         high = chs;
       else
         low = chs + 1;
     }
     long long gh = g(high), gh1 = g(high - 1);
     if (gh > gh1 || high == 1)
       cout << gh << ' ' << high << endl;
     else
       cout << gh1 << ' ' << high - 1 << endl;
   }
 }


#include <bits/stdc++.h>
 const long long int MOD = 1e9 + 7;
 const long long int INF = 1011111111;
 const long long int LLINF = 1000111000111000111LL;
 const long double EPS = 1e-10;
 const long double PI = 3.14159265358979323;
 using namespace std;
 long long int power(int x, int n) {
   if (n == 0)
     return 1;
   else if (n % 2 == 0)
     return power((x * x), n / 2);
   else
     return x * power((x * x), (n - 1) / 2);
 }
 long long int dp[5005][5005];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long int n, m, i, j, k;
   cin >> n >> k;
   vector<long long int> v(n);
   for (i = 0; i < n; i++) cin >> v[i];
   sort(v.begin(), v.end());
   vector<pair<pair<long long int, long long int>, long long int> > check;
   vector<long long int>::iterator it;
   for (i = 0; i < n; i++) {
     long long int idx;
     it = upper_bound(v.begin(), v.end(), v[i] + 5);
     if (it == v.end())
       idx = n - 1;
     else {
       idx = it - v.begin();
       idx--;
     }
     check.push_back({{i, idx}, idx - i + 1});
   }
   long long int ans = 0;
   for (i = 0; i < n; i++) {
     for (j = 0; j <= k; j++) {
       dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
       if (j + 1 <= k)
         dp[i + check[i].second][j + 1] =
             max(dp[i + check[i].second][j + 1], dp[i][j] + check[i].second);
     }
   }
   cout << dp[n][k];
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 5, oo = 0x3f3f3f3f, mod = 1e9 + 7;
 int a[N], n, tree[N], srt[N], ans[N];
 void update(int a, int val) {
   while (a <= n) {
     tree[a] = max(val, tree[a]);
     a += a & -a;
   }
 }
 int query(int a) {
   int mx = 0;
   while (a > 0) {
     mx = max(tree[a], mx);
     a -= a & -a;
   }
   return mx;
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( %d , a + i);
     srt[i] = a[i];
   }
   sort(srt + 1, srt + n + 1);
   for (int i = n; i >= 1; i--) {
     int idx = lower_bound(srt + 1, srt + n + 1, a[i]) - srt;
     update(idx, i);
     ans[i] = query(idx - 1);
     if (ans[i] == 0)
       ans[i]--;
     else
       ans[i] -= i + 1;
   }
   for (int i = 1; i <= n; i++) printf( %d  , ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 2e5 + 9;
 int n, maxx;
 struct p {
   int lei, num, x;
 } a[maxn];
 int da[maxn], b[maxn], vis[maxn];
 int main() {
   cin >> n;
   for (int i = 1; i <= n; i++) cin >> b[i];
   int w;
   cin >> w;
   for (int i = 1; i <= w; i++) {
     cin >> a[i].lei;
     if (a[i].lei == 1) {
       cin >> a[i].num >> a[i].x;
       vis[a[i].num] = i;
       b[a[i].num] = a[i].x;
     } else {
       cin >> a[i].x;
       maxx = max(maxx, a[i].x);
     }
   }
   for (int i = w; i >= 1; i--) {
     if (a[i].lei == 1)
       da[i] = da[i + 1];
     else
       da[i] = max(da[i + 1], a[i].x);
   }
   for (int i = 1; i <= n; i++) {
     if (vis[i] == 0)
       cout << max(b[i], maxx) <<    ;
     else {
       int xu = vis[i];
       cout << max(b[i], da[xu]) <<    ;
     }
   }
 }


#include <bits/stdc++.h>
 const int INF = 0x3f3f3f3f;
 const int N = 579;
 const long long P = 1000000007;
 int n, b[N];
 long long d[N][N];
 long long solve(int l, int r) {
   if (l == r) return 1;
   static bool used[N][N];
   static long long ans[N][N];
   if (used[l][r]) return ans[l][r];
   used[l][r] = true;
   ++l;
   ++r;
   d[l][0] = 1;
   for (int i = 0; i < r - l; ++i) {
     if (d[l][i + 1] != -1) continue;
     int c = l + i;
     d[l][i + 1] = 0;
     for (int j = 0; j <= i; ++j)
       if (b[j + l] < b[c + 1]) (d[l][i + 1] += d[l][j] * solve(j + l, c)) %= P;
   }
   long long res = 0;
   for (int j = 0; j <= r - l - 1; ++j)
     (res += d[l][j] * solve(j + l, r - 1)) %= P;
   --l;
   --r;
   return ans[l][r] = res;
 }
 int main() {
   memset(d, -1, sizeof(d));
   std::cin >> n;
   for (int i = 0; i < n; ++i) std::cin >> b[i];
   if (b[0] == 1)
     std::cout << solve(0, n - 1) <<
 ;
   else
     std::cout << 0 <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a[4];
   for (int i = 0; i < 4; i++) cin >> a[i];
   int sumtotal = a[0] + a[1] + a[2] + a[3];
   if (sumtotal % 2 != 0) {
     cout <<  NO ;
     return 0;
   }
   for (int i = 0; i < 4; i++) {
     if (a[i] == sumtotal - a[i]) {
       cout <<  YES ;
       return 0;
     } else
       for (int j = 0; j < 4; j++) {
         if (i != j)
           if ((a[i] + a[j]) == (sumtotal - a[i] - a[j])) {
             cout <<  YES ;
             return 0;
           }
       }
   }
   cout <<  NO ;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<pair<int, double>> ans[52];
 int main() {
   int n, w, m;
   cin >> n >> w >> m;
   double s = (n * w) / (m * 1.0), c = w, b = 1, k = 0;
   for (int i = 0; i < m; i++) {
     double ne = s;
     while (1) {
       if (ne + 10e-7 > c) {
         ans[i].push_back(make_pair(b, c));
         ne -= c;
         c = w;
         b++;
         if (++k > 2) {
           cout <<  NO ;
           return 0;
         }
         k = 0;
         if (abs(ne) < 10e-7) break;
       } else {
         ans[i].push_back(make_pair(b, ne));
         c -= ne;
         k++;
         break;
       }
     }
   }
   cout <<  YES
 ;
   for (int i = 0; i < m; i++) {
     for (auto it : ans[i])
       cout << fixed << setprecision(0) << it.first <<     << setprecision(6)
            << it.second <<    ;
     cout <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void quickly_quickly_kro() {
   long long n;
   cin >> n;
   vector<long long> v(n);
   for (long long i = 0; i < n; i++) cin >> v[i];
   ;
   map<long long, long long> M, N, I;
   for (long long i = 0; i < n; i++) {
     if (v[i] != 0)
       M[v[i]]++;
     else
       I[i]++;
   }
   for (long long i = 1; i < n + 1; i++) {
     if (M[i] == 0) {
       N[i]++;
     }
   }
   for (auto k : I) {
     if ((N.find(k.first + 1) != N.end())) {
       auto it = N.find(k.first + 1);
       if (it != N.begin())
         it--;
       else
         it++;
       v[k.first] = it->first;
       N.erase(it);
     }
   }
   for (long long i = 0; i < n; i++) {
     if (v[i] == 0) {
       auto it = N.begin();
       pair<long long, long long> p = *it;
       v[i] = p.first;
       N.erase(it);
     }
   }
   for (long long i = 0; i < n; i++) cout << v[i] <<    ;
 }
 signed main() {
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long t;
   t = 1;
   while (t--) {
     quickly_quickly_kro();
     cout <<
 ;
     ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct HashMap {
   vector<pair<int, int> > g[1000007];
   void ins(int x, int y) {
     int id = ((long long)x * 1000000007 + y) % 1000007;
     g[id].push_back(make_pair(x, y));
   }
   bool get(int x, int y) {
     int id = ((long long)x * 1000000007 + y) % 1000007;
     for (int i = 0; i < g[id].size(); i++)
       if (g[id][i].first == x && g[id][i].second == y) return true;
     return false;
   }
 };
 int n;
 HashMap mp;
 vector<int> row[100011];
 vector<int> rateB;
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     int x, y;
     scanf( %d%d , &x, &y);
     row[y].push_back(x);
     mp.ins(x, y);
   }
   int di = (int)sqrt(n);
   long long int ans = 0;
   for (int a = 0; a <= 100000; a++) {
     if (row[a].size() != 0) {
       sort(row[a].begin(), row[a].end());
       if (row[a].size() <= di) {
         for (int i = 0; i < row[a].size(); i++) {
           for (int j = i + 1; j < row[a].size(); j++) {
             int x1 = row[a][i];
             int x2 = row[a][j];
             int dis = x2 - x1;
             if (mp.get(x1, a + dis) && mp.get(x2, a + dis)) ans++;
             if (a - dis >= 0 && row[a - dis].size() > di &&
                 (mp.get(x1, a - dis) && mp.get(x2, a - dis)))
               ans++;
           }
         }
       } else
         rateB.push_back(a);
     }
   }
   for (int i = 0; i < rateB.size(); i++) {
     for (int j = i + 1; j < rateB.size(); j++) {
       int a = rateB[i];
       int b = rateB[j];
       int u = 0, p = 0;
       int dis = b - a;
       while (u < row[a].size() && p < row[b].size()) {
         if (row[a][u] < row[b][p])
           u++;
         else if (row[a][u] > row[b][p])
           p++;
         else {
           int x1 = row[a][u];
           if (mp.get(x1 + dis, a) && mp.get(x1 + dis, b)) ans++;
           u++;
           p++;
         }
       }
     }
   }
   printf( extra
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = (int)1.01e9;
 const double eps = 1e-9;
 const int maxn = (int)2e5 + 10;
 set<int> S;
 int main() {
   int n, k, a;
   scanf( %d%d%d , &n, &k, &a);
   int cur = (n + 1) / (a + 1);
   assert(cur >= k);
   int m;
   scanf( %d , &m);
   for (int i = 0; (i) < (m); ++i) {
     int x;
     scanf( %d , &x);
     set<int>::iterator it = S.lower_bound(x);
     int left = 0;
     int right = n + 1;
     if (it != S.end()) {
       right = *it;
     }
     if (it != S.begin()) {
       --it;
       left = *it;
     }
     cur -= (right - left) / (a + 1);
     cur += (x - left) / (a + 1);
     cur += (right - x) / (a + 1);
     if (cur < k) {
       printf( %d
 , i + 1);
       return 0;
     }
     S.insert(x);
   }
   printf( -1
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Segment {
   int l, r, x, ls, rs, fa;
 } seg[2000100];
 int n, k, p[100100], cnt, pnt, b[2000100], w, ans[100100], res;
 int Dfs(int &id, int l, int r) {
   id = ++cnt;
   seg[id].l = l, seg[id].r = r;
   seg[id].x = 1;
   if (r - l == 1) return 1;
   int mid = (l + r) >> 1;
   seg[id].x += Dfs(seg[id].ls, l, mid);
   seg[id].x += Dfs(seg[id].rs, mid, r);
   return seg[id].x;
 }
 void Vis(int x) {
   if (!x) return;
   b[x] = 1;
   Vis(seg[x].ls);
   Vis(seg[x].rs);
 }
 bool cmp(int x, int y) { return seg[x].l < seg[y].l; }
 void Solve(int x) {
   if (!x) return;
   if (b[x]) {
     for (int i = seg[x].l; i < seg[x].r; i++) ans[i] = res++;
     return;
   }
   Solve(seg[x].rs);
   Solve(seg[x].ls);
 }
 int main() {
   scanf( %d%d , &n, &k);
   Dfs(w, 0, n);
   k = seg[1].x - k;
   for (int i = 1; i <= cnt; i++)
     if (!b[i]) {
       if (k >= seg[i].x - 1 && seg[i].x > 1) {
         k -= seg[i].x - 1;
         p[++pnt] = i;
         Vis(i);
         if (!k) break;
       }
     }
   if (k)
     printf( -1 );
   else {
     res = 1;
     Solve(1);
     for (int i = n - 1; i >= 0; i--) ans[i] = ans[i] ? ans[i] : res++;
     for (int i = 0; i < n; i++) printf( %d  , ans[i]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string s[1100];
 int vis[1100];
 int num[100];
 int main() {
   ios::sync_with_stdio(false);
   int n, len, k;
   cin >> n >> len >> k;
   string st;
   cin >> st;
   for (int i = 0; i < st.size(); i++) {
     num[st[i] - 'a']++;
   }
   int l = 0, r = 25;
   for (int i = k + 1; i <= n; i++) {
     for (int j = 1; j <= len; j++) {
       while (!num[r] && r > l) r--;
       s[i] += (char)(r + 'a');
       num[r]--;
     }
   }
   int now = 0;
   int pos = 0;
   while (1) {
     for (int i = 1; i <= k; i++) {
       if (vis[i]) continue;
       if (pos >= 1 && i != k && (int)(s[i][pos - 1] - 'a') < now) {
         for (int j = pos + 1; j <= len; j++) {
           while (!num[r] && r > l) r--;
           s[i] += (char)(r + 'a');
           num[r]--;
         }
         vis[i] = 1;
         continue;
       }
       while (!num[l] && r > l) l++;
       s[i] += (char)(l + 'a');
       num[l]--;
       if (i == k) {
         now = l;
       }
     }
     pos++;
     if (pos == len) break;
   }
   sort(s + 1, s + 1 + n);
   for (int i = 1; i <= n; i++) cout << s[i] << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int T, n, m, nw, a[110][110], id[110][110], pos[110], p[110];
 char ch;
 bool cmp(int i, int j) { return a[m][i] < a[m][j]; }
 queue<int> q;
 void find(int x) {
   p[x] = 0;
   int y = id[x][pos[x]];
   pos[x]--;
   if (!p[y])
     p[y] = x, p[x] = y;
   else if (a[y][x] > a[y][p[y]]) {
     p[p[y]] = 0, q.push(p[y]);
     p[y] = x, p[x] = y;
   }
   if (!p[x]) q.push(x);
 }
 void work() {
   for (int i = 1; i <= 2 * n; i++) {
     for (int j = 1; j <= n; j++) id[i][j] = (i <= n) * n + j;
     m = i;
     sort(id[i] + 1, id[i] + n + 1, cmp);
     p[i] = 0;
   }
   for (int i = 1; i <= n; i++) pos[i] = n, q.push(i);
   while (!q.empty()) {
     int u = q.front();
     q.pop();
     find(u);
   }
   for (int i = 1; i <= n; i++) assert(p[i]);
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= n; j++)
       assert(!(a[p[i]][i] < a[p[i]][j] && a[j][p[i]] > a[j][p[j]]));
 }
 void solve() {
   bool falg = 0;
   scanf( %d , &n);
   memset(a, 0, sizeof(a)), memset(id, 0, sizeof(id));
   for (int i = 1; i <= n; i++)
     for (int j = n + 1; j <= 2 * n; j++)
       scanf( %d , &a[i][j]), a[j][i] = -a[i][j];
   puts( B ), fflush(stdout);
   scanf(  %c%d , &ch, &nw);
   if (ch == 'I') falg ^= 1;
   if (nw > n) falg ^= 1;
   if (falg)
     for (int i = 1; i <= 2 * n; i++)
       for (int j = 1; j <= 2 * n; j++) a[i][j] = -a[i][j];
   work();
   printf( %d
 , p[nw]), fflush(stdout);
   while (~scanf( %d , &nw)) {
     if (nw == -1) return;
     printf( %d
 , p[nw]), fflush(stdout);
   }
 }
 int main() {
   scanf( %d , &T);
   while (T--) solve();
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 9;
 vector<int> getBorder(const string str) {
   int n = str.size();
   vector<int> border(n, -1);
   for (int i = 1, j = -1; i < n; i++) {
     while (j >= 0 && str[i] != str[j + 1]) {
       j = border[j];
     }
     if (str[i] == str[j + 1]) j++;
     border[i] = j;
   }
   return border;
 }
 int matchPattern(string txt, string pat, const vector<int> border) {
   int freq = 0;
   for (int i = 0, j = -1; i < (int)txt.size(); i++) {
     while (j >= 0 && txt[i] != pat[j + 1]) {
       j = border[j];
     }
     if (txt[i] == pat[j + 1]) {
       j++;
     }
     if (j + 1 == (int)pat.size()) {
       freq++;
       j = border[j];
     }
   }
   return freq;
 }
 string cut(string s, int p, bool pref = true) {
   if (!pref) {
     reverse(s.begin(), s.end());
   }
   while ((int)s.size() >= p) s.pop_back();
   if (!pref) {
     reverse(s.begin(), s.end());
   }
   return s;
 }
 const int ms = 210;
 string pref[ms], suf[ms];
 long long trans[ms];
 int bk = 14;
 long long getFreq(int n, string pat, long long k) {
   std::vector<long long> f(n + 1, 0);
   if (pat ==  0 ) f[0]++;
   if (pat ==  1 ) f[1]++;
   auto border = getBorder(pat);
   for (int i = 2; i <= n; i++) {
     long long cur = trans[i - 2];
     if (i < bk + 4) {
       string curString = cut(suf[i - 2], (int)pat.size(), false) +
                          cut(pref[i - 1], (int)pat.size());
       cur = matchPattern(curString, pat, border);
     }
     f[i] = f[i - 1] + f[i - 2] + cur;
     if (f[i] > k) return k + 1;
     trans[i] = cur;
   }
   return min(f[n], k + 1);
 }
 int main() {
   pref[0] = suf[0] =  0 ;
   pref[1] = suf[1] =  1 ;
   for (int i = 2; i < ms; i++) {
     pref[i] = cut(pref[i - 2] + pref[i - 1], ms);
     suf[i] = cut(suf[i - 2] + suf[i - 1], ms, false);
   }
   int n, m;
   long long k;
   cin >> n >> k >> m;
   if (n == 0) {
     cout <<  0
 ;
     return 0;
   }
   if (n == 1) {
     cout <<  1
 ;
     return 0;
   }
   string ans;
   k--;
   while (k >= 0 && (int)ans.size() < m) {
     if (ans.size() > 0 &&
         suf[n].substr(suf[n].size() - ans.size(), ans.size()) == ans) {
       k--;
     }
     if (k < 0) break;
     ans += '0';
     long long got = getFreq(n, ans, k);
     if (got <= k) {
       ans.back() = '1';
       k -= got;
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int tag[10];
 int main() {
   string a, b;
   while (cin >> a >> b) {
     memset(tag, 0, sizeof(tag));
     ;
     int len = a.size();
     int len1 = b.size();
     for (int i = 0; i < len1; i++) {
       int num = b[i] - '0';
       tag[num]++;
     }
     for (int i = 0; i < len; i++) {
       int p = a[i] - '0';
       int j = 9;
       while (j > p) {
         if (!tag[j]) j--;
         if (tag[j] && j > p) {
           a[i] = j + '0';
           tag[j]--;
           break;
         }
       }
     }
     for (int i = 0; i < len; i++) cout << a[i];
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1000000007;
 int n, k;
 bool d[1001];
 long long dp[1001][2][1001];
 int cnt[10001];
 long long DP(int i, bool f, int j) {
   if (i == n) return cnt[j] == k;
   if (dp[i][f][j] != -1) return dp[i][f][j];
   long long ret = 0;
   if (d[i] == 1)
     ret = (ret + DP(i + 1, f, j + 1)) % mod;
   else if (d[i] == 0 and f)
     ret = (ret + DP(i + 1, f, j + 1)) % mod;
   ret = (ret + DP(i + 1, f | (d[i] == 1), j)) % mod;
   return dp[i][f][j] = ret;
 }
 int main() {
   for (int i = 1; i <= 1000; i++) {
     cnt[i] = 1 + cnt[__builtin_popcount(i)];
   }
   string s;
   cin >> s;
   n = s.size();
   cin >> k;
   int i = 0;
   for (char c : s) d[i++] = c - '0';
   memset(dp, -1, sizeof dp);
   cout << DP(0, 0, 0) - (k == 1);
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long int INF = 1e18, N = 2e6 + 3, BASE = 130;
 int main() {
   long long int n, k;
   cin >> n >> k;
   vector<int> arr(n), up(n);
   for (int i = 0; i < n; i++) {
     cin >> arr[i];
   }
   for (int i = n - 2; i >= 0; i--) {
     if (arr[i + 1] == 1) {
       up[i] = up[i + 1] + 1;
     } else {
       up[i] = 0;
     }
   }
   long long int ans = 0;
   for (int i = 0; i < n; i++) {
     int ind = i;
     long long int p = 1;
     long long int sum = 0;
     int cnt = 0;
     while (ind < n && cnt <= 20) {
       if (p > INF / arr[ind]) {
         break;
       }
       p *= arr[ind];
       sum += arr[ind];
       cnt++;
       if (p % sum == 0 && p / sum == k) {
         ans++;
       }
       if (up[ind]) {
         if (p % k == 0) {
           long long int num = p / k;
           if (sum + 1 <= num && num <= sum + up[ind]) {
             ans++;
           }
         }
       }
       sum += up[ind];
       ind = ind + 1 + up[ind];
     }
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 void PLAY() {
   cout << fixed << setprecision(10);
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long n, m;
   cin >> n >> m;
   vector<string> x(n), y(m), ans;
   for (int i = 0; i < n; i++) {
     cin >> x[i];
   }
   for (int i = 0; i < m; i++) {
     cin >> y[i];
   }
   long long q;
   cin >> q;
   while (q--) {
     long long a;
     cin >> a;
     a--;
     cout << x[a % n] + y[a % m] << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /stack:64000000 )
 using namespace std;
 const double PI = 2 * acos(0.0);
 const double eps = 1e-9;
 template <class T>
 T jog(T a, T b) {
   return a + b;
 }
 template <class T>
 T bog(T a, T b) {
   return a - b;
 }
 template <class T>
 T gon(T a, T b) {
   return a * b;
 }
 template <class T>
 T sq(T x) {
   return x * x;
 }
 template <class T>
 T gcd(T a, T b) {
   return b == 0 ? a : gcd(b, a % b);
 }
 template <class T>
 T lcm(T a, T b) {
   return (a / gcd(a, b)) * b;
 }
 template <class T>
 T power(T a, T p) {
   T res = 1, x = a;
   while (p) {
     if (p & 1) res = res * x;
     x = x * x;
     p >>= 1;
   }
   return res;
 }
 template <class T>
 T cordinatlenth(T a, T b, T c, T d) {
   return sqrt(sq(a - c) + sq(b - d));
 }
 template <class T>
 string toString(T n) {
   ostringstream oss;
   oss << n;
   oss.flush();
   return oss.str();
 }
 int toInt(string s) {
   int r = 0;
   istringstream sin(s);
   sin >> r;
   return r;
 }
 long long bigmod(long long a, long long p, long long mod) {
   long long res = 1, x = a;
   while (p) {
     if (p & 1) res = (res * x) % mod;
     x = (x * x) % mod;
     p >>= 1;
   }
   return res;
 }
 int diraction1[] = {-1, 0, 0, 1, 1, -1, -1, 1};
 int diraction2[] = {0, -1, 1, 0, 1, -1, 1, -1};
 int horsed1[] = {-2, -2, -1, 1, 2, 2, 1, -1};
 int horsed2[] = {1, -1, -2, -2, -1, 1, 2, 2};
 void input();
 const int INF = 2147483647;
 const long long LINF = 9223372036854775807ll;
 int n, in[1000010];
 int main() {
   input();
   return 0;
 }
 void input() {
   memset(in, 0, sizeof(in));
   cin >> n;
   for (int i = 0, tmp; i < n; i++) {
     scanf( %d , &tmp);
     in[tmp]++;
   }
   long long ans = 0;
   for (int i = 0; i < 1000005; i++) {
     if (in[i] == 0 || in[i] == 1) continue;
     while (in[i] > 1) {
       ans++;
       in[i + 1]++;
       in[i]--;
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 int changed;
 int answer1, answer2 = 1023;
 int main() {
   cin >> n;
   int i;
   for (i = 0; i < n; i++) {
     char tp;
     cin >> tp;
     if (tp == '|') {
       int number;
       cin >> number;
       answer1 |= number;
       answer2 |= number;
       changed |= number;
     } else if (tp == '&') {
       int number;
       cin >> number;
       answer1 &= number;
       answer2 &= number;
       number = 1023 - number;
       changed |= number;
     } else {
       int number;
       cin >> number;
       answer1 ^= number;
       answer2 ^= number;
     }
   }
   int answer11 = 0;
   int answer22 = 0;
   int answer33 = 0;
   for (i = 0; i < 10; i++) {
     if ((answer1 & (1 << i)) && (answer2 & (1 << i))) {
       answer11 += 1 << i;
     } else {
       if ((answer1 & (1 << i)) && (!(answer2 & (1 << i)))) {
         answer33 += 1 << i;
         answer22 += 1 << i;
       }
       if ((!(answer1 & (1 << i))) && (answer2 & (1 << i))) {
         answer22 += 1 << i;
       }
     }
   }
   cout << 3 << endl;
   cout <<  &   << answer22 << endl;
   cout <<  |   << answer11 << endl;
   cout <<  ^   << answer33 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 1;
 string s, t;
 char c[N];
 int cs[2][N], ct[2][N], q;
 int main() {
   scanf(  %s , c);
   s = c;
   scanf(  %s , c);
   t = c;
   int at = 0;
   for (auto &i : s) {
     at++;
     if (i == 'C' || i == 'B') {
       i = 'B';
       cs[1][at] = cs[1][at - 1] + 1;
     } else {
       cs[1][at] = cs[1][at - 1];
       cs[0][at] = cs[0][at - 1] + 1;
     }
   }
   at = 0;
   for (auto &i : t) {
     at++;
     if (i == 'C' || i == 'B') {
       i = 'B';
       ct[1][at] = ct[1][at - 1] + 1;
     } else {
       ct[1][at] = ct[1][at - 1];
       ct[0][at] = ct[0][at - 1] + 1;
     }
   }
   scanf( %d , &q);
   for (int i = 0, a, b, c, d; i < q; i++) {
     scanf( %d%d%d%d , &a, &b, &c, &d);
     int difs = cs[1][b] - cs[1][a - 1];
     int dift = ct[1][d] - ct[1][c - 1];
     bool thereis = 0;
     int need = dift - difs;
     int trails = min(b - a + 1, cs[0][b]);
     int trailt = min(d - c + 1, ct[0][d]);
     if (need & 1) {
       printf( 0 );
       continue;
     }
     if (need < 0) {
       printf( 0 );
       continue;
     }
     if (!need) {
       if (trails < trailt || (trails - trailt) % 3) {
         printf( 0 );
         continue;
       }
       printf( 1 );
       continue;
     }
     if (need && trails > trailt) {
       trails = trailt;
       thereis = 1;
     }
     if ((trails - trailt) % 3 || trails < trailt) {
       printf( 0 );
       continue;
     }
     thereis |= difs;
     if (!thereis && need) {
       printf( 0 );
       continue;
     }
     printf( 1 );
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline T maxi(T a, T b) {
   return a > b ? a : b;
 }
 template <typename T>
 inline T mini(T a, T b) {
   return a < b ? a : b;
 }
 template <typename T>
 inline T absl(T a) {
   return a > 0 ? a : -a;
 }
 template <typename T>
 inline T gcd(T a, T b) {
   T t;
   if (a < b) {
     while (a) {
       t = a;
       a = b % a;
       b = t;
     }
     return b;
   } else {
     while (b) {
       t = b;
       b = a % b;
       a = t;
     }
     return a;
   }
 }
 template <typename T>
 inline T ceiling(T a, T b) {
   if (b < 0) {
     a *= -1;
     b *= -1;
   }
   if ((double)a / (double)b < 0) return 0;
   {
     if (a % b == 0) return (a / b);
     return ((a / b) + 1);
   }
 }
 vector<int> adj[500000];
 map<pair<int, int>, int> m;
 vector<pair<int, int> > v(500000);
 vector<bool> visited(500000, false);
 int d;
 void dfs(int u, int c) {
   visited[u] = true;
   for (auto it : adj[u]) {
     if (!visited[it]) {
       m[{u, it}] = c % d;
       ++c;
       dfs(it, c);
     }
   }
 }
 void input() {
   int n, k;
   cin >> n >> k;
   for (int i = 0; i < n - 1; ++i) {
     int s, d;
     cin >> s >> d;
     --s;
     --d;
     adj[s].push_back(d);
     adj[d].push_back(s);
     v[i].first = s;
     v[i].second = d;
   }
   int b[n];
   for (int i = 0; i < n; ++i) {
     b[i] = adj[i].size();
   }
   sort(b, b + n, greater<int>());
   d = b[k];
   cout << d << endl;
   dfs(0, 0);
   for (int i = 0; i < n - 1; ++i) {
     cout << maxi(m[v[i]], m[{v[i].second, v[i].first}]) + 1 <<    ;
   }
 }
 int main() {
   input();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e5 + 5;
 struct node {
   int l, r, sum;
 } hjt[maxn * 40];
 int a[maxn], root[maxn], cnt;
 int last[maxn];
 void insert(int l, int r, int pre, int &now, int p, int v) {
   hjt[++cnt] = hjt[pre];
   now = cnt;
   hjt[now].sum = hjt[pre].sum + v;
   if (l == r) return;
   int m = (l + r) >> 1;
   if (p <= m)
     insert(l, m, hjt[pre].l, hjt[now].l, p, v);
   else
     insert(m + 1, r, hjt[pre].r, hjt[now].r, p, v);
 }
 int query(int now, int l, int r, int k) {
   if (l == r) {
     if (hjt[now].sum <= k) return l;
     return l - 1;
   }
   int mid = (l + r) >> 1;
   int tmp = hjt[hjt[now].l].sum;
   if (tmp > k)
     return query(hjt[now].l, l, mid, k);
   else
     return query(hjt[now].r, mid + 1, r, k - tmp);
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) cin >> a[i];
   for (int i = n; i >= 1; i--) {
     if (last[a[i]]) {
       insert(1, n, root[i + 1], root[i], last[a[i]], -1);
       insert(1, n, root[i], root[i], i, 1);
     } else
       insert(1, n, root[i + 1], root[i], i, 1);
     last[a[i]] = i;
   }
   for (int i = 1; i <= n; i++) {
     int ans = 0, l = 1, r = 0;
     while (l <= n) {
       r = query(root[l], 1, n, i);
       l = r + 1;
       ans++;
     }
     cout << ans;
     if (i == n)
       cout << '
';
     else
       cout << ' ';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, k;
 int num = 0;
 int e[21][21];
 int flag[21];
 int dfs(int x, int sum, int mid) {
   if (x > n) {
     num = num + 1;
   } else {
     mid = dfs(x + 1, sum, mid);
     for (int y = 1; y <= n; y++) {
       if (num >= k) {
         break;
       }
       if (flag[y] == 0 && e[x][y] != 0 && sum + e[x][y] <= mid) {
         flag[y] = 1;
         mid = dfs(x + 1, sum + e[x][y], mid);
         flag[y] = 0;
       }
     }
   }
   return mid;
 }
 int main() {
   int u, v, w;
   cin >> n >> m >> k;
   for (int i = 0; i <= 20; i++) {
     for (int j = 0; j <= 20; j++) {
       e[i][j] = 0;
     }
   }
   int l = 0;
   int h = n * 1000;
   int mid = 0;
   for (int i = 0; i < m; i++) {
     cin >> u >> v >> w;
     e[u][v] = w;
   }
   while (l < h) {
     num = 0;
     mid = (l + h) / 2;
     mid = dfs(1, 0, mid);
     if (num < k) {
       l = mid + 1;
     } else {
       h = mid;
     }
   }
   cout << h << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 50005;
 const int MAXD = 55;
 const int MOD = 1e9 + 7;
 template <typename T>
 inline void read(T &AKNOI) {
   T x = 0, flag = 1;
   char ch = getchar();
   while (!isdigit(ch)) {
     if (ch == '-') flag = -1;
     ch = getchar();
   }
   while (isdigit(ch)) {
     x = x * 10 + ch - '0';
     ch = getchar();
   }
   AKNOI = flag * x;
 }
 namespace ModCalculator {
 inline void Inc(int &x, int y) {
   x += y;
   if (x >= MOD) x -= MOD;
 }
 inline void Dec(int &x, int y) {
   x -= y;
   if (x < 0) x += MOD;
 }
 inline int Add(int x, int y) {
   Inc(x, y);
   return x;
 }
 inline int Sub(int x, int y) {
   Dec(x, y);
   return x;
 }
 inline int Mul(int x, int y) { return 1LL * x * y % MOD; }
 }  // namespace ModCalculator
 using namespace ModCalculator;
 char s[MAXN], sx[MAXD], sy[MAXD];
 int n, d, dg[MAXD];
 int tot, ch[MAXN][10], fail[MAXN], ed[MAXN], q[MAXN];
 int dp[MAXD][MAXN];
 void Insert(int l, int r) {
   int p = 0;
   for (int i = l; i <= r; ++i) {
     int x = s[i] - '0';
     if (!ch[p][x]) ch[p][x] = ++tot;
     p = ch[p][x];
   }
   ed[p] = 1;
 }
 void GetFail() {
   int head = 1, tail = 0;
   for (int i = 0; i < 10; ++i) {
     if (ch[0][i]) {
       q[++tail] = ch[0][i];
     }
   }
   while (head <= tail) {
     int u = q[head++];
     for (int i = 0; i < 10; ++i) {
       if (ch[u][i]) {
         fail[ch[u][i]] = ch[fail[u]][i];
         q[++tail] = ch[u][i];
       } else {
         ch[u][i] = ch[fail[u]][i];
       }
     }
   }
 }
 int DP(int i, int j, bool full) {
   if (i > d) return 1;
   if (!full && dp[i][j] != -1) return dp[i][j];
   int ret = 0, r = (full ? dg[i] : 9);
   for (int k = 0; k <= r; ++k) {
     if (ed[ch[j][k]]) continue;
     Inc(ret, DP(i + 1, ch[j][k], full && (k == r)));
   }
   if (!full) dp[i][j] = ret;
   return ret;
 }
 int Calc(char *ss) {
   int ret = 0;
   for (int i = 1; i <= d; ++i) {
     ret = Add(Mul(ret, 10), (dg[i] = ss[i] - '0'));
   }
   return Sub(ret, DP(1, 0, 1));
 }
 void init() {
   scanf( %s , s + 1);
   n = strlen(s + 1);
   scanf( %s , sx + 1);
   scanf( %s , sy + 1);
   d = strlen(sx + 1);
   int d2 = d / 2;
   for (int i = 1; i + d2 - 1 <= n; ++i) {
     Insert(i, i + d2 - 1);
   }
   GetFail();
 }
 void solve() {
   int p = d;
   for (; sx[p] == '0'; sx[p--] = '9')
     ;
   sx[p] -= 1;
   memset(dp, -1, sizeof(dp));
   printf( %d
 , Sub(Calc(sy), Calc(sx)));
 }
 int main() {
   init();
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long mdin(long long a, long long m) {
   long long r1 = m, r2 = a, t1 = 0, t2 = 1;
   while (r2 > 0) {
     long long q = r1 / r2;
     long long r = r1 % r2;
     r1 = r2;
     r2 = r;
     long long t = (t1 - q * t2) % m;
     t1 = t2;
     t2 = t;
   }
   return (t1 + m) % m;
 }
 long long ex(long long a, long long n, long long m) {
   if (n == 0) return 1;
   long long ans = ex((a * a) % m, n / 2, m);
   if (n % 2) ans = (a * ans) % m;
   return ans;
 }
 void bfs(int r, vector<int> adj[], int n) {
   queue<int> q, l;
   vector<int> vis(n + 1, 0);
   q.push(r);
   l.push(1);
   while (!q.empty()) {
     int nd = q.front();
     q.pop();
     int lv = l.front();
     l.pop();
     for (auto it : adj[nd]) {
       if (vis[it] == 0) {
         vis[it] = 1;
         q.push(it);
         l.push(lv + 1);
       }
     }
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long t = 1;
   while (t--) {
     long long n, k;
     cin >> n >> k;
     if (k > n - 1) {
       cout << 0;
       return 0;
     }
     long long f[n + 1], inf[n + 1];
     f[0] = 1;
     inf[0] = 1;
     for (long long i = 1; i <= n; i++) {
       f[i] = (i * f[i - 1]) % 998244353;
       inf[i] = mdin(f[i], 998244353);
     }
     if (k == 0) {
       cout << f[n] << endl;
     } else {
       long long ans = (((f[n] * inf[n - k]) % 998244353) * inf[k]) % 998244353;
       k = n - k;
       long long ml = 0;
       int s = 1;
       for (long long i = 0; i <= k - 1; i++) {
         long long cm = (((f[k] * inf[i]) % 998244353) * inf[k - i]) % 998244353;
         long long t = k - i;
         long long et = ex(t, n, 998244353);
         ml = (ml + (cm * et * s) % 998244353 + 998244353) % 998244353;
         s *= -1;
       }
       ans = (((ml * ans) % 998244353) * 2) % 998244353;
       cout << ans << endl;
     }
   }
   return 0;
 }


#include<bits/stdc++.h>
 using namespace std;
 #define mod        1000000007
 #define pb         push_back
 #define mp         make_pair
 #define rep(n)     for(int i=0;i<n;i++)
 #define repit(x)   for(auto it : x)
 #define ll         long long
 #define vi         vector<int>
 #define vc         vector<char>
 #define vs         vector<string>
 #define mii        map<int ,int>
 #define mci        map<char ,int>
 /* bool prime[100001];
  const int N=100000;
  void sieve() {
  int i,j;
 for(i=2;i<=N;i++)
 prime[i]=true;
  prime[0]=prime[1]=false;
 for(i=2;i*i<=N;i++){
 if(prime[i]){
 for(j=i*i;j<=N;j+=i)
 prime[j]=false;
 }
 }
 }*/
 int gcd(int a,int b){
 if(b==0)
 return a;
 else
 return gcd(b,a%b);
 }
 void swap(int *x,int *y){
 int temp=*x;
 *x=*y;
 *y=temp;
 }
 int main()
 {

 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 int t;
 cin>>t;
 while(t--){
 int i,n,c=0,j;
 cin>>n;
 string s,s2;
 cin>>s;
 map<string,int>m;
 for(i=97;i<=122;i++){
     string s1;
     s1.push_back(i);
     m.insert(make_pair(s1,0));
 }
 for(i=0;i<n;i++){
     string s1;
     s1.push_back(s[i]);
     m[s1]++;
 }
 for(auto it=m.begin();it!=m.end();it++){
     if(it->second==0){
         c=1;
         s2=it->first;
         break;
     }
 }
 if(c){
     cout<<s2<<
 ;
 }
 else{
     m.clear();
     for(i=97;i<=122;i++){
         for(j=97;j<=122;j++){
             string s1;
             s1.push_back(i);
             s1.push_back(j);
             m.insert(make_pair(s1,0));
         }
     }
     for(i=0;i<n-1;i++){
         string s1;
         s1.push_back(s[i]);
         s1.push_back(s[i+1]);
         m[s1]++;
     }
     for(auto it=m.begin();it!=m.end();it++){
         if(it->second==0){
             c=1;
             s2=it->first;
             break;
         }
     }
     if(c)
     cout<<s2<<
 ;
     else{
         m.clear();
         for(i=97;i<=122;i++){
             for(j=97;j<=122;j++){
                 for(int k=97;k<=122;k++){
                     string s1;
                     s1.push_back(i);
                     s1.push_back(j);
                     s1.push_back(k);
                     m.insert(make_pair(s1,0));
                 }
             }
         }
         for(i=0;i<n-2;i++){
             string s1;
             s1.push_back(s[i]);
             s1.push_back(s[i+1]);
             s1.push_back(s[i+2]);
             m[s1]++;

         }
         for(auto it=m.begin();it!=m.end();it++){
             if(it->second==0){
                 c=1;
                 s2=it->first;
                 break;
             }
         }
         cout<<s2<<
 ;
     }
 }
 }
 return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 int table[1000][1000];
 int main() {
   int k = 0;
   scanf( %d %d %d , &n, &m, &k);
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) {
       scanf( %d , &table[i][j]);
     }
   }
   while (k) {
     char command;
     int x, y;
     scanf(  %c %d %d , &command, &x, &y);
     if (command == 'g')
       printf( %d
 , table[x - 1][y - 1]);
     else if (command == 'c')
       for (int i = 0; i < n; ++i) swap(table[i][x - 1], table[i][y - 1]);
     else
       for (int i = 0; i < m; ++i) swap(table[x - 1][i], table[y - 1][i]);
     k--;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 ifstream Cin( input.txt );
 ofstream Cout( output.txt );
 int main() {
   long long i, n4 = 0, n7 = 0, n;
   string a, b;
   cin >> a >> b;
   for (i = 0; i < a.length(); i++)
     if (a[i] != b[i]) {
       if (a[i] == '4')
         n4++;
       else
         n7++;
     }
   cout << n4 + n7 - min(n4, n7);
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 ll min(ll a, ll b) {
   if (a < b) return a;
   return b;
 }
 void solve() {
   ll testCases;
   cin >> testCases;
   while (testCases--) {
     ll n;
     cin >> n;
     vector<ll> arr(n);
     vector<ll> res(n, 1);
     for (int i = 0; i < n; i++) cin >> arr[i];
     int i = 0;
     for (i = 0; i < n; i++) {
       if (arr[i] != arr[(i + 1) % n]) break;
     }
     if (i == n) {
       cout <<  1
 ;
       for (i = 0; i < n; i++) cout << 1 <<    ;
       cout <<
 ;
       continue;
     }
     if (n % 2 == 0) {
       cout <<  2
 ;
       for (i = 0; i < n; i++) cout << (i % 2) + 1 <<    ;
       cout <<
 ;
       continue;
     } else {
       bool isTwo = 0;
       for (i = 0; i < n; i++) {
         if (arr[i] == arr[(i + 1) % n]) {
           for (int j = 0, k = i + 1; k < n; k++, j ^= 1) res[k] = j + 1;
           for (int j = 0, k = i; k >= 0; k--, j ^= 1) res[k] = j + 1;
           cout <<  2
 ;
           for (auto e : res) cout << e <<    ;
           cout <<
 ;
           isTwo = 1;
           break;
         }
       }
       if (!isTwo) {
         cout <<  3
 ;
         for (i = 0; i < n - 1; i++) cout << i % 2 + 1 <<    ;
         cout <<  3
 ;
       }
     }
   }
 }
 int main() {
   {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
   };
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxN = 3000 + 1;
 pair<int, int> a[maxN];
 pair<int, int> b[maxN];
 int nx[maxN], pr[maxN], v[maxN];
 int r, c, n;
 inline int gg(int i) {
   pair<int, int> x = {a[i].second, a[i].first};
   return lower_bound(b, b + n + 2, x) - b;
 }
 inline int ff(int i) { return b[i].first; }
 int nex(int i) {
   if (v[nx[i]]) return nx[i];
   return nx[i] = nex(nx[i]);
 }
 int prev(int i) {
   if (v[pr[i]]) return pr[i];
   return pr[i] = prev(pr[i]);
 }
 int L[11], R[11];
 int main() {
   cin >> r >> c >> n;
   int k;
   cin >> k;
   for (int i = 0; i < n; i++) {
     cin >> a[i].first >> a[i].second;
     b[i] = {a[i].second, a[i].first};
   }
   b[n] = {0, 0}, b[n + 1] = {c + 1, 0};
   sort(a, a + n);
   sort(b, b + n + 2);
   v[0] = v[n + 1] = 1;
   pr[0] = 0, nx[n + 1] = n + 1;
   long long ans = 0;
   for (int i = 1; i <= r; i++) {
     int ind = 0;
     for (; ind < n && a[ind].first < i; ind++)
       ;
     if (ind == n) break;
     for (int j = ind; j < n; j++) v[gg(j)] = 1;
     for (int j = 1; j <= n; j++) {
       nx[j] = j + 1;
       pr[j] = j - 1;
     }
     int curr = 0;
     for (int j = 1; j <= n; j++)
       if (v[j]) {
         int x = j;
         for (int t = 1; t < k; t++, x = nex(x))
           ;
         curr += (ff(j) - ff(prev(j))) * (c + 1 - ff(x));
       }
     int ptr = n;
     for (int i2 = r; i2 >= i; i2--) {
       ans += curr;
       for (; ptr > ind && a[ptr - 1].first >= i2; ptr--) {
         L[0] = R[0] = gg(ptr - 1);
         for (int t = 1; t < k; t++) {
           L[t] = prev(L[t - 1]);
           R[t] = nex(R[t - 1]);
         }
         for (int t = 0; t < k; t++) {
           int left = L[t];
           int right = R[k - t - 1];
           curr -= (ff(left) - ff(prev(left))) * (ff(nex(right)) - ff(right));
         }
         v[L[0]] = 0;
       }
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int arr[500005], brr[500005];
 pair<int, int> tree[500005 * 4];
 vector<int> vv[500005];
 vector<pair<int, int> > qr[500005];
 int ans[500005];
 void build(int node, int b, int e) {
   if (b == e) {
     tree[node] = make_pair(500000000, 500000000);
     return;
   }
   int left = 2 * node, right = left + 1, mid = (b + e) / 2;
   build(left, b, mid);
   build(right, mid + 1, e);
   tree[node] = tree[left];
 }
 void update(int node, int b, int e, int i, int v) {
   if (e < i || b > i) return;
   if (b == e && b == i) {
     tree[node] = make_pair(v, arr[b]);
     return;
   }
   int left = 2 * node, right = left + 1, mid = (b + e) / 2;
   update(left, b, mid, i, v);
   update(right, mid + 1, e, i, v);
   if (tree[left].first <= tree[right].first) {
     tree[node] = tree[left];
   } else
     tree[node] = tree[right];
 }
 pair<int, int> query(int node, int b, int e, int l, int r) {
   if (b > r || e < l) return make_pair(500000000, 500000000);
   if (b >= l && e <= r) return tree[node];
   int left = 2 * node, right = left + 1, mid = (b + e) / 2;
   pair<int, int> p = query(left, b, mid, l, r);
   pair<int, int> q = query(right, mid + 1, e, l, r);
   if (p.first <= q.first) return p;
   return q;
 }
 int main() {
   int n;
   scanf( %d , &n);
   int mx = 0;
   for (int i = 1; i <= n; i++) {
     scanf( %d , &arr[i]);
     vv[arr[i]].push_back(i);
     mx = max(mx, arr[i]);
   }
   int q;
   scanf( %d , &q);
   for (int i = 1; i <= q; i++) {
     int l, r;
     scanf( %d %d , &l, &r);
     qr[r].push_back(make_pair(l, i));
   }
   build(1, 1, n);
   for (int i = 1; i <= n; i++) {
     int id = lower_bound(vv[arr[i]].begin(), vv[arr[i]].end(), i) -
              vv[arr[i]].begin();
     int v;
     if (id == 0) {
       v = 1;
       brr[arr[i]] = i;
     } else {
       v = vv[arr[i]][id - 1] + 1;
       update(1, 1, n, brr[arr[i]], 500000000);
       brr[arr[i]] = i;
     }
     update(1, 1, n, i, v);
     for (int j = 0; j < qr[i].size(); j++) {
       pair<int, int> ret = query(1, 1, n, qr[i][j].first, i);
       if (qr[i][j].first >= ret.first) ans[qr[i][j].second] = ret.second;
     }
   }
   for (int i = 1; i <= q; i++) printf( %d
 , ans[i]);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 10;
 const int MAXN = 200000;
 int n, tot;
 bool bz[N];
 vector<int> g[N], edge[N];
 int e[N * 2][2], gg[N];
 int sz;
 long long ans[N];
 void add(int x, int y) {
   e[++tot][0] = y;
   e[tot][1] = gg[x];
   gg[x] = tot;
 }
 void dfs(int x) {
   bz[x] = 0;
   sz++;
   for (int i = gg[x]; i; i = e[i][1])
     if (bz[e[i][0]]) dfs(e[i][0]);
   gg[x] = 0;
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     int x;
     scanf( %d , &x);
     for (int j = 1; 1ll * j * j <= x; j++)
       if ((x % j) == 0) {
         g[j].push_back(i);
         if (j * j != x) g[x / j].push_back(i);
       }
   }
   for (int i = 1; i < n; i++) {
     int x, y;
     scanf( %d %d , &x, &y);
     edge[x].push_back(y);
     edge[y].push_back(x);
   }
   for (int i = 1; i <= MAXN; i++)
     if (g[i].size()) {
       tot = 0;
       for (auto u : g[i]) bz[u] = 1;
       for (auto u : g[i])
         for (auto v : edge[u])
           if (bz[v]) add(u, v);
       for (auto u : g[i])
         if (bz[u]) {
           sz = 0;
           dfs(u);
           ans[i] += 1ll * sz * (sz - 1) / 2 + sz;
         }
     }
   for (int i = MAXN; i; i--)
     for (int j = 2; 1ll * j * i <= MAXN; j++) ans[i] -= ans[i * j];
   for (int i = 1; i <= MAXN; i++)
     if (ans[i]) printf( %d %lld
 , i, ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int k, n;
   scanf( %d%d , &n, &k);
   vector<int> a(n), b(n), distributed(n), p(n);
   vector<vector<int> > cart(k);
   for (int i = 0; i < n; ++i) {
     scanf( %d%d , &a[i], &b[i]);
     distributed[i] = 0;
     p[i] = i;
   }
   for (int i = 0; i < n; ++i) {
     for (int j = i + 1; j < n; ++j) {
       if (a[p[i]] < a[p[j]]) {
         swap(p[i], p[j]);
       }
     }
   }
   int cart_ptr = 0;
   for (int i = 0; i < n && cart_ptr < k; ++i) {
     if (b[p[i]] == 1) {
       distributed[p[i]] = 1;
       cart[cart_ptr].push_back(p[i]);
       ++cart_ptr;
     }
   }
   deque<int> available;
   for (int i = 0; i < n; ++i) {
     if (!distributed[p[i]]) {
       available.push_back(p[i]);
     }
   }
   while (cart_ptr < k) {
     cart[cart_ptr].push_back(available.front());
     available.pop_front();
     ++cart_ptr;
   }
   while (!available.empty()) {
     cart[k - 1].push_back(available.front());
     available.pop_front();
   }
   long long ans = 0;
   for (int i = 0; i < k; ++i) {
     int min_cost = 2000000000;
     for (int j = 0; j < (int)cart[i].size(); ++j) {
       ans += a[cart[i][j]] * 2;
       min_cost = min(min_cost, a[cart[i][j]]);
     }
     if (b[cart[i][0]] == 1) {
       ans -= min_cost;
     }
   }
   cout << ans / 2;
   if (ans % 2 == 0) {
     cout <<  .0  << endl;
   } else {
     cout <<  .5  << endl;
   }
   for (int i = 0; i < k; ++i) {
     cout << cart[i].size();
     for (int j = 0; j < (int)cart[i].size(); ++j) {
       cout << ' ' << cart[i][j] + 1;
     }
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = (int)1e9;
 const int mod = (int)1e9 + 7;
 const double pi = acos(-1.0);
 const double eps = 1e-9;
 const int maxn = (int)2e6 + 11;
 long long n;
 long long a[maxn];
 long long sum[maxn];
 int main() {
   cin >> n;
   a[1] = 2;
   sum[1] = 2;
   for (int i = 2; i <= 2000000; i++) {
     a[i] = a[i - 1] + 3;
     sum[i] = sum[i - 1] + a[i];
   }
   int ans = 0;
   for (int i = 1; sum[i] <= n; i++) {
     if ((n - sum[i]) % 3 == 0) ans++;
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 map<long long, long long> mp[12];
 long long a[200005], dig[200005];
 long long state[200005][12];
 int main() {
   long long n, k;
   scanf( %lld %lld , &n, &k);
   for (int i = 0; i < n; i++) scanf( %lld , &a[i]);
   for (int i = 0; i < n; i++) {
     dig[i] = log10(a[i]) + 1;
   }
   for (int i = 0; i < n; i++) {
     long long x = a[i];
     long long tencnt = 1;
     while (tencnt < 11) {
       x = (x * 10LL) % k;
       mp[tencnt][x]++;
       state[i][tencnt] = x;
       tencnt++;
     }
   }
   long long ans = 0;
   for (int i = 0; i < n; i++) {
     long long len = dig[i];
     long long m = (k - (a[i] % k)) % k;
     if (mp[len].count(m) == 0) continue;
     ans += mp[len][m];
   }
   for (int i = 0; i < n; i++) {
     long long len = dig[i];
     long long x = state[i][len];
     if ((x + a[i]) % k == 0) {
       ans--;
     }
   }
   printf( %lld
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long LINF = ~0ULL >> 1;
 const int N = 1e3 + 7;
 const int INF = 2e8 + 7;
 const int MOD = 1e9 + 7;
 const double PI = acos(-1.0);
 const double EPS = 1e-8;
 int n;
 long long calc(long long A, long long B, long long C) {
   return (A + 1) * (B + 2) * (C + 2);
 }
 void solve() {
   long long mn = LINF, mx = -LINF, tmp;
   for (int i = 1; 1ll * i * i * i <= n; ++i) {
     if (n % i) continue;
     for (int j = i, J = n / i; 1ll * j * j <= J; ++j) {
       if (J % j) continue;
       int k = n / i / j;
       tmp = calc(i, j, k);
       mn = min(mn, tmp), mx = max(mx, tmp);
       tmp = calc(j, i, k);
       mn = min(mn, tmp), mx = max(mx, tmp);
       tmp = calc(k, i, j);
       mn = min(mn, tmp), mx = max(mx, tmp);
     }
   }
   cout << mn - n <<     << mx - n << endl;
 }
 int main() {
   std::ios_base::sync_with_stdio(false);
   cin >> n;
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, x, r[100000], pos[100000], flag = 1, flag2;
 pair<int, int> a[100000];
 vector<int> ans, ans2;
 int l(int n) {
   if (!n) return 1;
   if (n % 10 == 4 || n % 10 == 7) return l(n / 10);
   return 0;
 }
 int main() {
   scanf( %d , &n);
   for (int i = 0; i < n; i++) {
     scanf( %d , &x);
     a[i] = pair<int, int>(x, i);
   }
   sort(a, a + n);
   for (int i = 0; i < n; i++) {
     r[a[i].second] = i;
     pos[i] = a[i].second;
     if (a[i].second != i) flag = 0;
     if (!flag2 && l(a[i].first)) x = i, flag2 = 1;
   }
   if (flag) {
     cout << 0 << endl;
     return 0;
   }
   if (!flag2) {
     cout << -1 << endl;
     return 0;
   }
   for (int i = 0; i < n; i++)
     if (i != x) {
       if (pos[i] == i) continue;
       if (pos[x] != i) {
         ans.push_back(pos[x]), ans2.push_back(i);
         int temp = pos[x];
         swap(pos[x], pos[r[i]]);
         swap(r[temp], r[i]);
       }
       ans.push_back(pos[x]), ans2.push_back(pos[i]);
       swap(pos[x], pos[i]);
       swap(r[pos[x]], r[pos[i]]);
     }
   cout << ans.size() << endl;
   for (int i = 0; i < ans.size(); i++)
     cout << ans[i] + 1 <<     << ans2[i] + 1 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 1e3 + 10;
 const int MOD = 998244353;
 const int INF = 10;
 int fact[MAXN], invfact[MAXN];
 int add(int a, int b) {
   int sum = a + b;
   return (sum >= MOD ? sum -= MOD : (sum < 0 ? sum += MOD : sum));
 }
 int mul(int a, int b) { return 1LL * a * b % MOD; }
 int pwr(int a, int b) {
   return (!b ? 1
              : (b & 1 ? 1LL * a * pwr(1LL * a * a % MOD, b >> 1) % MOD
                       : pwr(1LL * a * a % MOD, b >> 1) % MOD));
 }
 int inv(int x) { return pwr(x, MOD - 2); }
 void first() {
   fact[0] = 1;
   for (int i = 1; i < MAXN; i++) fact[i] = mul(fact[i - 1], i);
   for (int i = 0; i < MAXN; i++) invfact[i] = inv(fact[i]);
 }
 int C(int n, int k) { return mul(mul(fact[n], invfact[k]), invfact[n - k]); }
 int P(int n, int k) { return mul(fact[n], invfact[n - k]); }
 int n, a[MAXN], dp[MAXN];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   first();
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> a[i];
   }
   dp[n] = 1;
   for (int i = n - 1; i >= 0; i--) {
     if (a[i] <= 0 || a[i] + i - 1 > n - 1) {
       continue;
     }
     for (int j = n - 1; j >= a[i] + i; j--) {
       dp[i] = add(dp[i], mul(dp[j + 1], C(j - i, a[i])));
     }
   }
   int ans = 0;
   for (int i = 0; i < n; i++) {
     ans = add(ans, dp[i]);
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   int* m = new int[n];
   int* r = new int[n];
   for (int i = 0; i < n; i++) {
     cin >> m[i];
   }
   for (int i = 0; i < n; i++) {
     cin >> r[i];
   }
   double total = 0;
   for (int i = 0; i < 1000000; i++) {
     for (int j = 0; j < n; j++) {
       if (i % m[j] == r[j]) {
         total++;
         break;
       }
     }
   }
   double percentage = total / 1000000;
   cout << fixed << setprecision(6) << percentage << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int dx[] = {1, 1, -1, -1};
 int dy[] = {1, -1, -1, 1};
 long long int n, k, d1, d2, rem;
 bool _solve(long long int w1, long long int w2, long long int w3) {
   long long int tar = n / 3;
   if (w1 < 0 || w2 < 0 || w3 < 0) return false;
   if (tar >= w1 && tar >= w2 && tar >= w3 && abs(w1 - w2) == d1 &&
       abs(w2 - w3) == d2)
     return true;
   return false;
 }
 bool solve() {
   long long int _d1, w1, w2, w3, _d2;
   for (int i = 0; i < 4; i++) {
     _d1 = d1 * dx[i];
     _d2 = d2 * dy[i];
     w1 = (k + 2 * _d1 + _d2) / 3;
     w2 = w1 - _d1;
     w3 = w2 - _d2;
     if (w1 + w2 + w3 != k) continue;
     if (_solve(w1, w2, w3)) return true;
   }
   return false;
 }
 int main() {
   ios_base ::sync_with_stdio(false);
   cin.tie(0);
   int t;
   cin >> t;
   while (t--) {
     cin >> n >> k >> d1 >> d2;
     if (n % 3 == 0) {
       if (solve())
         cout <<  yes  << endl;
       else
         cout <<  no  << endl;
     } else
       cout <<  no  << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1.01e9;
 const double eps = 1e-9;
 const int N = 1010;
 char s[N][N];
 char res[N * N];
 int resc = 0;
 char ch[4] = {'D', 'L', 'R', 'U'};
 int dx[4] = {1, 0, 0, -1};
 int dy[4] = {0, -1, 1, 0};
 pair<int, int> q[N * N];
 int st = 0, en = 0;
 int d[N][N];
 int n, m;
 void bfs(int x, int y) {
   for (int i = 0; (i) < (n); ++i)
     for (int j = 0; (j) < (m); ++j) d[i][j] = inf;
   d[x][y] = 0;
   q[en++] = {x, y};
   while (st < en) {
     x = q[st].first;
     y = q[st].second;
     st++;
     for (int i = 0; (i) < (4); ++i) {
       int xx = x + dx[i];
       int yy = y + dy[i];
       if (0 <= xx && xx < n && 0 <= yy && yy < m && s[xx][yy] == '.' &&
           d[xx][yy] == inf) {
         d[xx][yy] = d[x][y] + 1;
         q[en++] = {xx, yy};
       }
     }
   }
 }
 int main() {
   int k;
   scanf( %d%d%d , &n, &m, &k);
   if (k & 1) {
     printf( IMPOSSIBLE
 );
     return 0;
   }
   for (int i = 0; (i) < (n); ++i) scanf( %s , s[i]);
   int px = -1, py = -1;
   for (int i = 0; (i) < (n); ++i)
     for (int j = 0; (j) < (m); ++j)
       if (s[i][j] == 'X') {
         px = i;
         py = j;
         s[i][j] = '.';
       }
   bfs(px, py);
   int x = px, y = py;
   for (int it = 0; (it) < (k); ++it) {
     int ok = 0;
     for (int i = 0; (i) < (4); ++i) {
       int xx = x + dx[i];
       int yy = y + dy[i];
       if (0 <= xx && xx < n && 0 <= yy && yy < m && d[xx][yy] <= k - it - 1) {
         res[resc++] = ch[i];
         x = xx;
         y = yy;
         ok = 1;
         break;
       }
     }
     if (!ok) {
       printf( IMPOSSIBLE
 );
       return 0;
     }
   }
   printf( %s
 , res);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char s[100010], a[110], b[110];
 int pa[110], pb[110];
 int main() {
   scanf( %s%s%s , s, a, b);
   int i, j;
   j = -1;
   pa[0] = -1;
   int lena = strlen(a);
   for (i = 1; i < lena; i++) {
     while (j > -1 && a[j + 1] != a[i]) j = pa[j];
     if (a[j + 1] == a[i]) j++;
     pa[i] = j;
   }
   j = -1;
   pb[0] = -1;
   int lenb = strlen(b);
   for (i = 1; i < lenb; i++) {
     while (j > -1 && b[j + 1] != b[i]) j = pb[j];
     if (b[j + 1] == b[i]) j++;
     pb[i] = j;
   }
   int len = strlen(s);
   int minn = len + 1;
   j = -1;
   for (i = 0; i < len; i++) {
     while (j > -1 && a[j + 1] != s[i]) j = pa[j];
     if (a[j + 1] == s[i]) j++;
     if (j == lena - 1) {
       minn = i;
       break;
     }
   }
   bool flag1 = false, flag2 = false;
   j = -1;
   for (i = minn + 1; i < len; i++) {
     while (j > -1 && b[j + 1] != s[i]) j = pb[j];
     if (b[j + 1] == s[i]) j++;
     if (j == lenb - 1) {
       flag1 = true;
       break;
     }
   }
   for (i = 0; i < len / 2; i++) swap(s[i], s[len - i - 1]);
   j = -1;
   minn = len;
   for (i = 0; i < len; i++) {
     while (j > -1 && a[j + 1] != s[i]) j = pa[j];
     if (a[j + 1] == s[i]) j++;
     if (j == lena - 1) {
       minn = i;
       break;
     }
   }
   j = -1;
   for (i = minn + 1; i < len; i++) {
     while (j > -1 && b[j + 1] != s[i]) j = pb[j];
     if (b[j + 1] == s[i]) j++;
     if (j == lenb - 1) {
       flag2 = true;
       break;
     }
   }
   if (flag1 && flag2)
     printf( both
 );
   else if (flag1)
     printf( forward
 );
   else if (flag2)
     printf( backward
 );
   else
     printf( fantasy
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long N, a[100010], s[100100], cnt[100010];
 void update(long long *t, long long pos, long long val) {
   for (; pos <= N; pos += pos & (-pos)) t[pos] += val;
 }
 long long query(long long *t, long long r) {
   long long res = 0;
   for (; r > 0; r -= r & (-r)) res += t[r];
   return res;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cin >> N;
   int i;
   long long nr, sum;
   long double res = 0;
   for (i = 1; i <= N; i++) {
     cin >> a[i];
     update(cnt, a[i], 1);
     update(s, a[i], i);
   }
   for (i = 1; i <= N; i++) {
     nr = query(cnt, a[i] - 1);
     sum = query(s, a[i] - 1);
     res += nr - (1.0 * i * (nr * (N + 1) - sum)) / (N * (N + 1));
     nr = N - i - nr;
     sum = query(s, N) - sum - i;
     res += (1.0 * i * (nr * (N + 1) - sum)) / (N * (N + 1));
     update(cnt, a[i], -1);
     update(s, a[i], -i);
   }
   cout << fixed << setprecision(15) << res <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 const int N = 1e6 + 10;
 const long long INF = 1e18;
 const long double EPS = 1e-12;
 int a[300005];
 map<int, int> mi;
 int l_, r_;
 long long pre[300005];
 int b[300005];
 int main() {
   int n;
   scanf( %d , &n);
   for (int i = (int)1; i < (int)n + 1; i++) {
     scanf( %d , &a[i]);
   }
   for (int i = (int)1; i < (int)n + 1; i++) {
     if (mi[a[i]] == 0) mi[a[i]] = i;
   }
   for (int i = (int)1; i < (int)n + 1; i++) {
     pre[i] = pre[i - 1];
     if (a[i] >= 0) pre[i] += (long long)(a[i]);
   }
   long long ans = -(long long)(1e12);
   l_ = 0;
   r_ = 0;
   for (int i = n; i >= 1; i--) {
     int x = a[i];
     int l = mi[x];
     if (i == mi[x]) continue;
     long long net = pre[i - 1] - pre[l];
     net += 2LL * (long long)(x);
     if (net > ans) {
       ans = net;
       l_ = l;
       r_ = i;
     }
   }
   int cnt = 0;
   for (int i = 0; i < (int)n + 1; i++) b[i] = 0;
   for (int i = (int)1; i < (int)n + 1; i++) {
     if (i == l_ || i == r_) {
       b[i] = 1;
       continue;
     }
     if (l_ < i && i < r_ && a[i] > 0) {
       b[i] = 1;
     } else {
       b[i] = 0;
       cnt++;
     }
   }
   cout << ans <<     << cnt << endl;
   for (int i = (int)1; i < (int)n + 1; i++) {
     if (b[i] == 0) {
       printf( %d  , i);
     }
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int Read() {
   int x = 0, f = 1, c = getchar();
   for (; !isdigit(c); c = getchar())
     if (c == '-') f = -1;
   for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
   return x * f;
 }
 const int MAXN = 300005;
 int n, m, a[MAXN], f[MAXN], g[MAXN];
 inline bool Chk(int d) {
   f[0] = g[0] = 1;
   for (int i = 1, j = 1; i <= n; i++) {
     while (a[i] - a[j] > d) j++;
     if (i >= m && g[i - m] - (j == 1 ? 0 : g[j - 2]) > 0)
       f[i] = 1;
     else
       f[i] = 0;
     g[i] = g[i - 1] + f[i];
   }
   return f[n];
 }
 int main() {
   n = Read(), m = Read();
   for (int i = 1; i <= n; i++) a[i] = Read();
   sort(a + 1, a + n + 1);
   int l = 0, r = a[n], ret = 0;
   while (l <= r) {
     int mid = l + r >> 1;
     if (Chk(mid))
       ret = mid, r = mid - 1;
     else
       l = mid + 1;
   }
   return printf( %d
 , ret), 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int t;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin >> t;
   while (t--) {
     int m;
     int n;
     cin >> m >> n;
     vector<int> a[500];
     vector<int> b[500];
     for (int i = 0; i < m; i++) {
       for (int j = 0; j < n; j++) {
         int temp;
         cin >> temp;
         a[i].push_back(temp);
       }
     }
     for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
         int temp;
         cin >> temp;
         b[i].push_back(temp);
       }
     }
     pair<int, int> place;
     for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
         if (a[0][0] == b[i][j]) {
           place = make_pair(i, j);
         }
       }
     }
     map<int, int> rows;
     for (int i = 0; i < m; i++) {
       rows.insert({a[i][0], i});
     }
     for (int i = 0; i < m; i++) {
       for (int j = 0; j < n; j++) {
         cout << a[rows[b[place.first][i]]][j] <<    ;
       }
       cout <<
 ;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 signed main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int t;
   cin >> t;
   auto solve = []() {
     int n;
     cin >> n;
     vector<pair<int, int>> a(n);
     for (int i = 0; i < n; i++) {
       cin >> a[i].first;
       a[i].first--;
     }
     vector<int> ans(n + n);
     vector<int> used(n + n);
     for (int i = 0; i < n; i++) {
       ans[i * 2] = a[i].first;
       a[i].second = i * 2;
       used[a[i].first] = 1;
     }
     for (int i = 1; i < n + n; i += 2) {
       int x = ans[i - 1];
       int j;
       for (j = x + 1; j < n + n && used[j]; j++)
         ;
       if (j == n + n) {
         cout << -1 << '
';
         return 0;
       }
       used[j] = 1;
       ans[i] = j;
     }
     for (int i = 0; i < n + n; i++) {
       if (i > 0) cout <<    ;
       cout << ans[i] + 1;
     }
     cout << '
';
   };
   while (t--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int res(long long int x) {
   long long int ans = 0;
   if (x > 0) ans = (x * (x - 1)) / 2;
   return ans;
 }
 int main() {
   long int n;
   long long int d;
   cin >> n >> d;
   vector<long long int> vect;
   long long int x;
   for (long int i = 0; i < n; i++) {
     cin >> x;
     vect.push_back(x);
   }
   vector<long long int>::iterator it, it2;
   long long int ans = 0;
   for (long int i = 2; i < n; i++) {
     it = lower_bound(vect.begin(), vect.end(), vect[i] - d);
     if (it != vect.end()) {
       ans = ans + res(i - (it - vect.begin()));
     }
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
 int Set(int N, int pos) { return (N | (1 << pos)); }
 long long BigMod(long long B, long long P, long long M) {
   long long R = 1;
   while (P > 0) {
     if (P % 2 == 1) {
       R = (R * B) % M;
     }
     P /= 2;
     B = (B * B) % M;
   }
   return R;
 }
 int n, m;
 vector<pair<double, int> > v;
 int dp[5005][5005][2];
 inline int call(int pos, int got, int stat) {
   if (got > m) return 10000;
   if (pos == n) {
     if (got == m)
       return 0;
     else
       return 10000;
   }
   if (dp[pos][got][stat] != -1) return dp[pos][got][stat];
   int ret = 0;
   int g = 0;
   if (v[pos].second != got and stat == 0) g = 1;
   ret = min(call(pos + 1, got, 0), call(pos, got + 1, 1));
   return dp[pos][got][stat] = ret + g;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(nullptr);
   memset(dp, -1, sizeof(dp));
   cin >> n >> m;
   v.resize(n);
   for (int i = 0; i < n; i++) {
     cin >> v[i].second >> v[i].first;
   }
   sort(v.begin(), v.end());
   int mx = 10000;
   for (int i = 0; i < m; i++) {
     mx = min(mx, call(0, i + 1, 0));
   }
   cout << mx;
 }


#include <bits/stdc++.h>
 using namespace std;
 char bd[1100][1100];
 int n, m;
 int rt[1100][1100];
 int down[1100][1100];
 int cnt[1100][1100];
 int check(int width, int height, int x, int y) {
   int filled = 0;
   bool first = true;
   while (true) {
     int godown = down[x][y] - height;
     if (godown < 0) break;
     if (cnt[x][y] - cnt[x][y + width] - cnt[x + down[x][y]][y] +
             cnt[x + down[x][y]][y + width] ==
         width * down[x][y]) {
       if (first) {
         filled += width * down[x][y];
         first = false;
       } else {
         filled += height + width * godown;
       }
     } else
       break;
     if ((y + 1) + width <= m) {
       y++;
       x += godown;
     } else
       break;
   }
   return filled;
 }
 int main() {
   scanf( %d %d , &n, &m);
   for (int i = 0; i < n; i++) scanf( %s , bd[i]);
   for (int i = n - 1; i >= 0; i--) {
     for (int j = m - 1; j >= 0; j--) {
       if (bd[i][j] == '.') {
         rt[i][j] = down[i][j] = 0;
       } else {
         rt[i][j] = 1 + rt[i][j + 1];
         down[i][j] = 1 + down[i + 1][j];
       }
     }
   }
   int tlx = -1;
   int tly = -1;
   int tot = 0;
   for (int i = n - 1; i >= 0; i--) {
     for (int j = m - 1; j >= 0; j--) {
       if (bd[i][j] == 'X') {
         tlx = i;
         tly = j;
         tot++;
       }
       cnt[i][j] =
           (bd[i][j] == 'X') + cnt[i + 1][j] + cnt[i][j + 1] - cnt[i + 1][j + 1];
     }
   }
   int best = 1000000000;
   for (int height = 1; height <= down[tlx][tly]; height++) {
     int width = rt[tlx][tly];
     int filled = check(width, height, tlx, tly);
     if (filled == tot) best = min(best, width * height);
   }
   for (int width = 1; width <= rt[tlx][tly]; width++) {
     int height = down[tlx][tly];
     int filled = check(width, height, tlx, tly);
     if (filled == tot) best = min(best, width * height);
   }
   printf( %d
 , best == 1000000000 ? -1 : best);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1 << 30;
 const int N = 100100;
 char a[N], b[N];
 int n, m, k, p[27];
 int Par(int i) { return p[i] = (i == p[i]) ? i : Par(p[i]); }
 bool same(int i, int j) { return Par(i) == Par(j); }
 int comp[27];
 void mrg(int i, int j) {
   if (same(i, j)) return;
   i = Par(i);
   j = Par(j);
   p[i] = p[j];
   comp[i] += comp[j];
 }
 vector<pair<char, char> > v;
 int main() {
   scanf( %d , &n);
   scanf( %s , a);
   scanf( %s , b);
   for (int i = 0; i < 26; i++) {
     p[i] = i;
     comp[i] = 1;
   }
   for (int i = 0; i < n; i++) {
     if (same(b[i] - 'a', a[i] - 'a')) continue;
     mrg(b[i] - 'a', a[i] - 'a');
     v.push_back({a[i], b[i]});
   }
   printf( %d
 , v.size());
   for (auto x : v) printf( %c %c
 , x.first, x.second);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 double pi = acos(-1);
 struct point {
   int x, y;
 } p[2005];
 vector<double> v;
 int main() {
   int n;
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) scanf( %d%d , &p[i].x, &p[i].y);
   long long ans = 0;
   for (int i = 1; i <= n; i++) {
     v.clear();
     for (int j = 1; j <= n; j++)
       if (j != i) v.push_back(atan2(p[j].y - p[i].y, p[j].x - p[i].x));
     sort(v.begin(), v.end());
     int k = 0;
     int now = 0;
     for (int j = 0; j < v.size(); j++) {
       while (v[k] + now * pi < v[j] + pi) {
         k++;
         if (k >= v.size()) k = 0, now += 2;
       }
       int w = (j - k >= 0 ? j - k : k - j - 1);
       ans += 1ll * w * (w - 1) / 2 * (n - w - 2) * (n - w - 3) / 2;
     }
   }
   printf( %lld
 , ans / 2);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 6, MAX = 2e5 + 5, OO = 1000000009;
 long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
 long long lcm(long long x, long long y) { return (x * y / gcd(x, y)); }
 long long fact(long long z) { return (z <= 1) ? 1 : z * fact(z - 1); }
 int a, b, aa, bb, ans;
 void Check(int p) {
   while (a % p == 0) {
     a /= p;
     aa++;
   }
   while (b % p == 0) {
     b /= p;
     bb++;
   }
   ans += abs(aa - bb);
   aa = bb = 0;
 }
 int main() {
   scanf( %d %d , &a, &b);
   Check(2);
   Check(3);
   Check(5);
   return printf( %d , a == b ? ans : -1), 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MOD = 1000 * 1000 * 1000 + 7;
 const int INF = 2000 * 1000 * 1000;
 const double EPS = 1e-9;
 const double pi = acos(-1.0);
 const int maxn = 100010;
 inline long long sqr(int n) { return n * 1ll * n; }
 struct Point {
   int x, y;
   Point() {}
   inline bool operator<(const Point& p) const { return y < p.y; }
   inline long long dist_to(const Point& p) const {
     return sqr(x - p.x) + sqr(y - p.y);
   }
 };
 Point a[maxn];
 int n, x, sum;
 long long minans = INF * 1ll * INF;
 inline void update(const Point& p1, const Point& p2) {
   minans = min(minans, p1.dist_to(p2));
 }
 inline void go(int l, int r) {
   if (r - l <= 3) {
     for (int i = l; i <= r; i++)
       for (int j = i + 1; j <= r; j++) update(a[i], a[j]);
     sort(a + l, a + r + 1);
     return;
   }
   int mid = (l + r) >> 1;
   int midx = a[mid].x;
   int buf_size = 0;
   go(l, mid - 1);
   go(mid, r);
   static Point buf[maxn];
   merge(a + l, a + mid, a + mid, a + r + 1, buf);
   copy(buf, buf + (r - l + 1), a + l);
   for (int i = l; i <= r; i++) {
     if (sqr(abs(a[i].x - midx)) < minans) {
       for (int j = buf_size - 1; j >= 0 && sqr(a[i].y - buf[j].y) < minans; j--)
         update(a[i], buf[j]);
       buf[buf_size++] = a[i];
     }
   }
 }
 int main() {
   scanf( %d , &n);
   for (int i = 0; i < n; i++) {
     scanf( %d , &x);
     sum += x;
     a[i].x = i + 1;
     a[i].y = sum;
   }
   go(0, n - 1);
   printf( extra , minans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   long long n, m;
   cin >> n >> m;
   vector<long long> col(m);
   for (long long i = 0; i < m; i++) {
     cin >> col[i];
   }
   vector<long long> suf(m, 0);
   suf[m - 1] = 0;
   for (long long i = m - 2; i >= 0; i--) {
     suf[i] = suf[i + 1] + col[i + 1];
   }
   vector<long long> ans;
   for (long long i = 0, cur = 0, r = 0; i < m; i++) {
     ans.push_back(cur);
     r = cur + col[i];
     if (r > n) {
       cout <<  -1  << endl;
       return 0;
     }
     cur++;
     if (suf[i] < n - r) {
       cout <<  -1  << endl;
       return 0;
     } else if (suf[i] < n - cur) {
       long long pos = n - suf[i];
       for (long long j = i + 1; j < m; j++) {
         ans.push_back(pos);
         pos += col[j];
       }
       break;
     }
   }
   for (long long i = 0; i < m; i++) {
     cout << ans[i] + 1 <<    ;
   }
   cout << endl;
   return 0;
 }