#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 5e4 + 2;
 int head[N], grp_edge[N][30], max1[N][30], grp[N], level[N], okfine = 0, sum[N],
                                                              dem = 0;
 char edge[N];
 bool cac = true;
 vector<pair<int, char> > adj[N];
 vector<int> adj_grp[N];
 stack<pair<int, char> > lis;
 void dfs(int x) {
   int i = 0, j;
   if (adj[x].size() == 0) {
     if (!okfine) {
       okfine = level[x];
     }
     if (okfine != level[x]) {
       cac = false;
     }
     while (lis.size()) {
       i = lis.top().first;
       if (lis.top().second != '?') {
         grp_edge[x][(int)(lis.top().second - 'a' + 1)]++;
       }
       grp[i] = x;
       lis.pop();
     }
     if (i) {
       adj_grp[head[i]].push_back(x);
       head[x] = head[i];
     }
   }
   if (adj[x].size() == 1) {
     level[adj[x][0].first] = level[x] + 1;
     lis.push({adj[x][0].first, edge[adj[x][0].first]});
     dfs(adj[x][0].first);
   }
   if (adj[x].size() == 2) {
     while (lis.size()) {
       i = lis.top().first;
       if (lis.top().second != '?') {
         grp_edge[x][(int)(lis.top().second - 'a' + 1)]++;
       }
       grp[i] = x;
       lis.pop();
     }
     if (i) {
       adj_grp[head[i]].push_back(x);
       head[x] = head[i];
     }
     level[adj[x][0].first] = level[x] + 1;
     lis.push({adj[x][0].first, edge[adj[x][0].first]});
     dfs(adj[x][0].first);
     level[adj[x][1].first] = level[x] + 1;
     lis.push({adj[x][1].first, edge[adj[x][1].first]});
     dfs(adj[x][1].first);
   }
 }
 void dfs1(int x) {
   int i, j;
   for (i = 0; i < adj_grp[x].size(); i++) {
     dfs1(adj_grp[x][i]);
     for (j = 1; j <= 26; j++) {
       max1[x][j] =
           max(max1[x][j], max1[adj_grp[x][i]][j] + grp_edge[adj_grp[x][i]][j]);
     }
   }
   for (j = 1; j <= 26; j++) {
     sum[x] += max1[x][j];
   }
   if (sum[x] > okfine - level[x]) {
     dem++;
   }
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, i, j, k, l, q, ans, ans1;
   char x, x1;
   cin >> n >> q;
   for (i = 2; i <= n; i++) {
     cin >> head[i] >> edge[i];
     adj[head[i]].push_back({i, edge[i]});
   }
   dfs(1);
   dfs1(1);
   head[1] = 0;
   for (i = 1; i <= q; i++) {
     if (!cac) {
       cout <<  Fou
 ;
       continue;
     }
     cin >> j >> x;
     x1 = edge[j];
     if (edge[j] != '?') {
       grp_edge[grp[j]][(int)(edge[j] - 'a' + 1)]--;
     }
     edge[j] = x;
     if (edge[j] != '?') {
       grp_edge[grp[j]][(int)(edge[j] - 'a' + 1)]++;
     }
     k = grp[j];
     while (k != 1) {
       if (adj_grp[head[k]].size() == 2) {
         if (sum[head[k]] > okfine - level[head[k]]) {
           if (x1 != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x1 - 'a' + 1)];
             max1[head[k]][(int)(x1 - 'a' + 1)] =
                 max(max1[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)],
                     max1[adj_grp[head[k]][1]][(int)(x1 - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][1]][(int)(x1 - 'a' + 1)]);
             sum[head[k]] += max1[head[k]][(int)(x1 - 'a' + 1)];
           }
           if (x != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x - 'a' + 1)];
             max1[head[k]][(int)(x - 'a' + 1)] =
                 max(max1[adj_grp[head[k]][0]][(int)(x - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][0]][(int)(x - 'a' + 1)],
                     max1[adj_grp[head[k]][1]][(int)(x - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][1]][(int)(x - 'a' + 1)]);
             sum[head[k]] += max1[head[k]][(int)(x - 'a' + 1)];
           }
           if (sum[head[k]] <= okfine - level[head[k]]) {
             dem--;
           }
         } else {
           if (x1 != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x1 - 'a' + 1)];
             max1[head[k]][(int)(x1 - 'a' + 1)] =
                 max(max1[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)],
                     max1[adj_grp[head[k]][1]][(int)(x1 - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][1]][(int)(x1 - 'a' + 1)]);
             sum[head[k]] += max1[head[k]][(int)(x1 - 'a' + 1)];
           }
           if (x != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x - 'a' + 1)];
             max1[head[k]][(int)(x - 'a' + 1)] =
                 max(max1[adj_grp[head[k]][0]][(int)(x - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][0]][(int)(x - 'a' + 1)],
                     max1[adj_grp[head[k]][1]][(int)(x - 'a' + 1)] +
                         grp_edge[adj_grp[head[k]][1]][(int)(x - 'a' + 1)]);
             sum[head[k]] += max1[head[k]][(int)(x - 'a' + 1)];
           }
           if (sum[head[k]] > okfine - level[head[k]]) {
             dem++;
           }
         }
       } else {
         if (sum[head[k]] > okfine - level[head[k]]) {
           if (x1 != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x1 - 'a' + 1)];
             max1[head[k]][(int)(x1 - 'a' + 1)] =
                 max1[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)] +
                 grp_edge[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)];
             sum[head[k]] += max1[head[k]][(int)(x1 - 'a' + 1)];
           }
           if (x != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x - 'a' + 1)];
             max1[head[k]][(int)(x - 'a' + 1)] =
                 max1[adj_grp[head[k]][0]][(int)(x - 'a' + 1)] +
                 grp_edge[adj_grp[head[k]][0]][(int)(x - 'a' + 1)];
             sum[head[k]] += max1[head[k]][(int)(x - 'a' + 1)];
           }
           if (sum[head[k]] <= okfine - level[head[k]]) {
             dem--;
           }
         } else {
           if (x1 != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x1 - 'a' + 1)];
             max1[head[k]][(int)(x1 - 'a' + 1)] =
                 max1[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)] +
                 grp_edge[adj_grp[head[k]][0]][(int)(x1 - 'a' + 1)];
             sum[head[k]] += max1[head[k]][(int)(x1 - 'a' + 1)];
           }
           if (x != '?') {
             sum[head[k]] -= max1[head[k]][(int)(x - 'a' + 1)];
             max1[head[k]][(int)(x - 'a' + 1)] =
                 max1[adj_grp[head[k]][0]][(int)(x - 'a' + 1)] +
                 grp_edge[adj_grp[head[k]][0]][(int)(x - 'a' + 1)];
             sum[head[k]] += max1[head[k]][(int)(x - 'a' + 1)];
           }
           if (sum[head[k]] > okfine - level[head[k]]) {
             dem++;
           }
         }
       }
       k = head[k];
     }
     if (dem) {
       cout <<  Fou
 ;
     } else {
       ans = 0;
       ans1 = 0;
       for (j = 1; j <= 26; j++) {
         ans += max1[1][j] * j;
         ans1 += max1[1][j];
       }
       cout <<  Shi   << ans + (okfine - ans1) * 27 * 13 << endl;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   while (scanf( %d , &n) == 1) {
     string s;
     cin >> s;
     s =  #  + s;
     bool used[n + 1];
     memset(used, 0, sizeof used);
     int d[n + 1];
     for (int i = 1; i <= n; i++) {
       scanf( %d , d + i);
     }
     int pos = 1;
     bool ok = false;
     while (!used[pos]) {
       used[pos] = true;
       if (s[pos] == '<') {
         pos -= d[pos];
       } else {
         pos += d[pos];
       }
       if (pos <= 0 || pos > n) {
         ok = true;
         break;
       }
     }
     if (ok) {
       puts( FINITE );
     } else {
       puts( INFINITE );
     }
   }
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native )
 #pragma GCC optimize( unroll-loops )
 using namespace std;
 template <typename T, typename U>
 inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
   _out << _p.first << ' ' << _p.second;
   return _out;
 }
 template <typename T, typename U>
 inline istream &operator>>(istream &_in, pair<T, U> &_p) {
   _in >> _p.first >> _p.second;
   return _in;
 }
 template <typename T>
 inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
   if (_v.empty()) {
     return _out;
   }
   _out << _v.front();
   for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
     _out << ' ' << *_it;
   }
   return _out;
 }
 template <typename T>
 inline istream &operator>>(istream &_in, vector<T> &_v) {
   for (auto &_i : _v) {
     _in >> _i;
   }
   return _in;
 }
 const long long MAXN = 3604;
 const long long MAXM = MAXN / 2;
 const long long INF = 1e9;
 const long long MOD = 998244353;
 long long sum(long long a, long long b) {
   if (a + b >= MOD) {
     return a + b - MOD;
   }
   return a + b;
 }
 long long mul(long long a, long long b) {
   if (a * b >= MOD) {
     return (a * b) % MOD;
   }
   return a * b;
 }
 long long sqr(long long a) { return (a * a) % MOD; }
 long long bin_pow(long long a, long long b) {
   if (b == 0) {
     return 1;
   }
   if (b % 2) {
     return mul(a, bin_pow(a, b - 1));
   }
   return sqr(bin_pow(a, b / 2));
 }
 long long fact[MAXN];
 long long rfact[MAXN];
 long long dp[2][MAXM][MAXN];
 bool connected[MAXN];
 long long dp1[MAXM];
 long long dp2[MAXN][MAXM];
 inline long long c(long long n, long long k) {
   return mul(fact[n], mul(rfact[k], rfact[n - k]));
 }
 class FSbalansirovannieRaspolozheniyaDomino {
  public:
   void solve(std::istream &in, std::ostream &out) {
     fact[0] = 1;
     for (long long i = 1; i < MAXN; i++) {
       fact[i] = mul(i, fact[i - 1]);
     }
     rfact[MAXN - 1] = bin_pow(fact[MAXN - 1], MOD - 2);
     for (long long j = MAXN - 1; j >= 1; j--) {
       rfact[j - 1] = mul(rfact[j], j);
     }
     long long h, w;
     in >> h >> w;
     long long n;
     in >> n;
     vector<pair<pair<long long, long long>, pair<long long, long long>>> a(n);
     in >> a;
     {
       for (long long i = 0; i <= h; i++) {
         for (long long j = 0; j < MAXM; j++) {
           dp2[i][j] = 0;
           dp[0][j][i] = 0;
         }
         connected[i] = 0;
       }
       for (long long j = 0; j < MAXM; j++) {
         dp1[j] = 0;
       }
       for (auto v : a) {
         connected[v.first.first - 1] = 1;
         connected[v.second.first - 1] = 1;
       }
       long long counts = 0;
       for (long long j = 0; j < h; j++) {
         counts += !connected[j];
       }
       dp1[0] = 1;
       for (long long i = 0; i <= h; i++) {
         for (long long j = 0; j < MAXM; j++) {
           dp1[j] = sum(dp1[j], dp2[i][j]);
         }
         if (i + 1 < h && connected[i] == 0 && connected[i + 1] == 0) {
           for (long long j = 0; j + 1 < MAXM; j++) {
             dp2[i + 2][j + 1] = dp1[j];
           }
         }
       }
       for (long long i = 0; i < MAXM; i++) {
         for (long long j = 0; j <= counts - 2 * i; j++) {
           dp[0][i][j] =
               mul(dp1[i], mul(fact[counts - 2 * i],
                               mul(fact[i], rfact[counts - 2 * i - j])));
         }
       }
     }
     {
       for (long long i = 0; i <= w; i++) {
         for (long long j = 0; j < MAXM; j++) {
           dp2[i][j] = 0;
           dp[1][j][i] = 0;
         }
         connected[i] = 0;
       }
       for (long long j = 0; j < MAXM; j++) {
         dp1[j] = 0;
       }
       for (auto v : a) {
         connected[v.first.second - 1] = 1;
         connected[v.second.second - 1] = 1;
       }
       long long counts = 0;
       for (long long j = 0; j < w; j++) {
         counts += !connected[j];
       }
       dp1[0] = 1;
       for (long long i = 0; i <= w; i++) {
         for (long long j = 0; j < MAXM; j++) {
           dp1[j] = sum(dp1[j], dp2[i][j]);
         }
         if (i + 1 < w && connected[i] == 0 && connected[i + 1] == 0) {
           for (long long j = 0; j + 1 < MAXM; j++) {
             dp2[i + 2][j + 1] = dp1[j];
           }
         }
       }
       for (long long i = 0; i < MAXM; i++) {
         for (long long j = 0; j <= counts - 2 * i; j++) {
           dp[1][i][j] = mul(dp1[i], c(counts - 2 * i, j));
         }
       }
     }
     long long ans = 0;
     for (long long i = 0; 2 * i <= h; i++) {
       for (long long j = 0; 2 * j <= w; j++) {
         ans += dp[0][i][j] * dp[1][j][i];
         if (ans >= MOD * MOD) {
           ans -= MOD * MOD;
         }
       }
     }
     ans %= MOD;
     out << ans;
   }
 };
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   FSbalansirovannieRaspolozheniyaDomino solver;
   std::istream &in(std::cin);
   std::ostream &out(std::cout);
   solver.solve(in, out);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char _;
 int num_rectangles;
 pair<pair<int, int>, pair<int, int> > rectangles[135000], pre[135000],
     suff[135000];
 pair<pair<int, int>, pair<int, int> > intersection(
     pair<pair<int, int>, pair<int, int> > first,
     pair<pair<int, int>, pair<int, int> > second) {
   if (first.first.first == INT_MIN || second.first.first == INT_MIN)
     return {{INT_MIN, INT_MIN}, {INT_MIN, INT_MIN}};
   int tx = max(first.first.first, second.first.first),
       bx = min(first.second.first, second.second.first);
   int ty = max(first.first.second, second.first.second),
       by = min(first.second.second, second.second.second);
   if (bx < tx || by < ty) return {{INT_MIN, INT_MIN}, {INT_MIN, INT_MIN}};
   return {{tx, ty}, {bx, by}};
 }
 int main() {
   scanf( %d , &num_rectangles);
   for (int i = 0; i < num_rectangles; i++)
     scanf(  %d %d %d %d , &rectangles[i].first.first,
           &rectangles[i].first.second, &rectangles[i].second.first,
           &rectangles[i].second.second);
   sort(rectangles, rectangles + num_rectangles);
   pre[0] = rectangles[0];
   suff[num_rectangles - 1] = rectangles[num_rectangles - 1];
   for (int i = 1; i < num_rectangles; i++) {
     pre[i] = intersection(pre[i - 1], rectangles[i]);
     suff[num_rectangles - i - 1] = intersection(
         suff[num_rectangles - i], rectangles[num_rectangles - i - 1]);
   }
   for (int i = 0; i < num_rectangles; i++) {
     if (i == 0) {
       if (suff[1].first.first != INT_MIN) {
         printf( %d %d
 , suff[1].first.first, suff[1].first.second);
         return 0;
       }
     } else if (i == num_rectangles - 1) {
       if (pre[num_rectangles - 2].first.first != INT_MIN) {
         printf( %d %d
 , pre[num_rectangles - 2].first.first,
                pre[num_rectangles - 2].first.second);
         return 0;
       }
     } else {
       pair<pair<int, int>, pair<int, int> > first = pre[i - 1],
                                             second = suff[i + 1],
                                             intersect =
                                                 intersection(first, second);
       if (intersect.first.first != INT_MIN) {
         printf( %d %d
 , intersect.first.first, intersect.first.second);
         return 0;
       }
     }
   }
   if (pre[num_rectangles - 1].first.first != INT_MIN) {
     printf( %d %d
 , pre[num_rectangles - 1].first.first,
            pre[num_rectangles - 1].first.second);
     return 0;
   }
   printf( -1
 );
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e6, maxm = 1e6;
 unsigned int degree[maxn + 10], blk[maxn + 10];
 namespace find {
 unsigned int fa[maxn + 10], siz[maxn + 10];
 inline void Init(const unsigned int n) {
   iota(fa, fa + n + 1, 0);
   fill(siz, siz + n + 1, 1);
 }
 unsigned int GetFather(const unsigned int x) {
   return fa[x] == x ? x : fa[x] = GetFather(fa[x]);
 }
 inline void Merge(const unsigned int x, const unsigned int y) {
   unsigned int fx = GetFather(x), fy = GetFather(y);
   if (fx == fy) return;
   if (siz[fx] < siz[fy]) swap(fx, fy);
   fa[fy] = fx;
   siz[fx] += siz[fy];
 }
 }  // namespace find
 int main() {
   ios_base::sync_with_stdio(false);
   unsigned int n, m;
   cin >> n >> m;
   find::Init(n);
   for (unsigned int i = 0; i < m; ++i) {
     unsigned int a, b;
     cin >> a >> b;
     find::Merge(a, b);
     ++degree[a];
     ++degree[b];
   }
   unsigned long long ans = 0;
   const unsigned int r = find::GetFather(1);
   bool fl = true;
   for (unsigned int i = 1; i <= n; ++i) {
     if (degree[i] & 0x01) ++blk[find::GetFather(i)];
     if (degree[i] && find::GetFather(i) != r) fl = false;
   }
   if (fl && !blk[r]) {
     cout <<  0  << endl;
     return 0;
   }
   for (unsigned int i = 1; i <= n; ++i)
     if (find::GetFather(i) == i) {
       ans += blk[i] / 2;
       if (degree[i] && !blk[i]) ++ans;
     }
   if (!degree[1] && find::siz[1] == 1 && find::GetFather(1) == 1) ++ans;
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   int count = 0, count1 = 0;
   cin >> s;
   for (int i = 0; i < s.size(); i++) {
     if (s[i] >= 97 && s[i] <= 122)
       count++;
     else
       count1++;
   }
   if (count >= count1) {
     for (int i = 0; i < s.size(); i++) {
       if (isupper(s[i])) s[i] = s[i] + 32;
     }
   } else {
     for (int i = 0; i < s.size(); i++) {
       if (islower(s[i])) s[i] = s[i] - 32;
     }
   }
   cout << s;
 }


#include <bits/stdc++.h>
 using namespace std;
 int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
 int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
 vector<string> vec_splitter(string s) {
   s += ',';
   vector<string> res;
   while (!s.empty()) {
     res.push_back(s.substr(0, s.find(',')));
     s = s.substr(s.find(',') + 1);
   }
   return res;
 }
 void debug_out(vector<string> __attribute__((unused)) args,
                __attribute__((unused)) int idx,
                __attribute__((unused)) int LINE_NUM) {
   cerr << endl;
 }
 template <typename Head, typename... Tail>
 void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
   if (idx > 0)
     cerr <<  ,  ;
   else
     cerr <<  Line(  << LINE_NUM <<  )  ;
   stringstream ss;
   ss << H;
   cerr << args[idx] <<   =   << ss.str();
   debug_out(args, idx + 1, LINE_NUM, T...);
 }
 int const lmt = 2e5 + 5;
 int a[lmt];
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   while (t--) {
     long long n;
     cin >> n;
     for (long long i = 0; i < n; i++) cin >> a[i];
     if (a[0] + a[1] <= a[n - 1]) {
       cout << 1 <<    ;
       cout << 2 <<    ;
       cout << n <<
 ;
     } else {
       cout << -1 <<
 ;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[300005], p[300005], out[300005];
 long long f[300005];
 bool v[300005];
 int n, m, cnt;
 void work(int p) {
   int t = min(a[p], a[p + 1]);
   if (t) out[++m] = p;
   a[p] -= t;
   a[p + 1] -= t;
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( %d , &a[i]);
     long long O = f[max(i - 2, 0)] + a[i];
     long long E = f[max(i - 3, 0)] + max(a[i], a[i - 1]);
     f[i] = min(O, E);
     v[i] = (f[i] != O);
   }
   long long ans = min(f[n - 1], f[n]);
   for (int i = n - (ans == f[n - 1]); i > 0; i -= 2 + v[i]) p[++cnt] = i;
   reverse(p + 1, p + cnt + 1);
   for (int i = 1; i <= cnt; i++) {
     int pre = p[i - 1], now = p[i];
     if (v) work(now - 1);
     work(pre + 1);
     work(now);
   }
   printf( %d
 , m);
   for (int i = 1; i <= m; i++) printf( %d
 , out[i]);
 }


#include <bits/stdc++.h>
 int main() {
   int n, mxpos = 0, mx = 0, temp, i;
   scanf( %d , &n);
   int p[n];
   for (i = 0; i < n; i++) {
     scanf( %d , &p[i]);
     if (mx < p[i]) {
       mx = p[i];
       mxpos = i;
     }
   }
   int loopno = 0, j;
   int notsorted = 1;
   while (notsorted) {
     notsorted = 0;
     for (j = 0; j < n - loopno - 1; j++) {
       if (p[j] > p[j + 1]) {
         temp = p[j];
         p[j] = p[j + 1];
         p[j + 1] = temp;
         notsorted = 1;
       }
     }
     loopno++;
   }
   printf( %d %d , mxpos + 1, p[n - 2]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 32000;
 const int mod = 1000000007;
 const int inf = 2 * mod;
 int dp[5001][5001];
 pair<long long, long long> hashVal[5001];
 pair<long long, long long> powVal[5001];
 const long long base1 = 37;
 const long long base2 = 2017;
 const long long mod1 = 1e9 + 7;
 const long long mod2 = 1e9 + 297;
 int ans[50001];
 string s;
 inline int ceil(int p, int q) { return (p + q - 1) / q; }
 int call(int l, int r) {
   if (l > r) return 0;
   if (l == r) return 1;
   if (l == r - 1) return (s[l] == s[r] ? 2 : 0);
   if (dp[l][r] != -1) return dp[l][r];
   int ret;
   if (s[l] != s[r] || call(l + 1, r - 1) == 0)
     ret = 0;
   else
     ret = 1 + call(l, ceil(l + r, 2) - 1);
   return dp[l][r] = ret;
 }
 int main() {
   cin >> s;
   int len = s.length();
   memset(dp, -1, sizeof(dp));
   for (int i = 0; i < len; i++) {
     for (int j = 0; j < len; j++) {
       ans[call(i, j)]++;
     }
   }
   for (int i = len - 1; i >= 1; i--) ans[i] += ans[i + 1];
   for (int i = 1; i <= len; i++) {
     cout << ans[i] <<    ;
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = LLONG_MAX;
 const long long mod = 1e9 + 7;
 inline long long power(long long n, long long k, long long mod = INF) {
   long long ans = 1;
   while (k > 0) {
     if (k & 1) ans = (ans * n) % mod;
     n = (n * n) % mod;
     k >>= 1;
   }
   return ans;
 }
 void sum() {
   string s;
   cin >> s;
   long long n = (long long)s.size();
   long long pre[n + 1];
   long long suf[n + 2];
   pre[1] = s[0] - '0';
   suf[n] = s[n - 1] - '0';
   suf[n + 1] = 0;
   suf[0] = 0;
   pre[0] = 0;
   long long st = pre[1];
   long long en = suf[n];
   long long t = 1;
   long long ans = 0;
   for (long long i = 1; i < n; ++i) {
     t = (t * 10) % mod;
     st = (st * 10 + s[i] - '0') % mod;
     pre[i + 1] = (pre[i] % mod + st) % mod;
     en = (en + t * (s[n - i - 1] - '0')) % mod;
     suf[n - i] = en;
   }
   for (long long i = 2; i <= n + 1; ++i) {
     long long temp = i - 1;
     temp %= mod;
     ans += (((pre[i - 2] * t) % mod) + (((temp)*suf[i]) % mod)) % mod;
     ans %= mod;
     t = ((t % mod) * power(10, mod - 2, mod)) % mod;
   }
   cout << (ans) % mod <<
 ;
 }
 int32_t main() {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   sum();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int arr[1000] = {0};
 int main() {
   int n, m, i, j, k;
   cin >> n;
   for (i = 0; i < n; i++) cin >> arr[i];
   if (n % 2 == 0) {
     cout <<  No  << endl;
     return 0;
   } else {
     if (arr[0] % 2 == 1 && arr[n - 1] % 2 == 1) {
       cout <<  Yes  << endl;
     } else
       cout <<  No  << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   int pages, readPages[7];
   scanf( %d , &pages);
   for (int i = 0; i < 7; i++) scanf( %d , &readPages[i]);
   int day = 1, i = 0;
   while (pages > 0) {
     if (day == 8) day = 1;
     if (i == 7) i = 0;
     pages -= readPages[i];
     day++, i++;
   }
   printf( %d
 , day - 1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX_N = 3000 + 50;
 const int MAX_D = 15;
 struct DP {
   int d1;
   int d2;
   int d3;
   int v1;
   int v2;
   int v3;
 };
 bool operator<(const DP& l, const DP& r) {
   return l.v1 < r.v1 || (l.v1 == r.v1 && l.v2 < r.v2) ||
          (l.v1 == r.v1 && l.v2 == r.v2 && l.v3 < r.v3);
 }
 class SparseTable {
  public:
   SparseTable(vector<pair<int, int> >& vals) {
     N = vals.size();
     depths.assign(MAX_N, -1);
     table.assign(N, vector<pair<int, int> >(MAX_D));
     init();
     build(vals);
   }
   void init() {
     for (int i = 1; i < MAX_N; ++i) {
       depths[i] = depths[i - 1];
       if ((i & (i - 1)) == 0) {
         ++depths[i];
       }
     }
   }
   void build(vector<pair<int, int> >& vals) {
     for (int i = 0; i < N; ++i) {
       table[i][0] = vals[i];
     }
     for (int d = 1; d <= depths[N] + 1; ++d) {
       for (int i = 0; i < N; ++i) {
         int left = i;
         int right = min(N - 1, left + (1 << (d - 1)));
         table[i][d] = max(table[left][d - 1], table[right][d - 1]);
       }
     }
   }
   pair<int, int> getMax(int left, int right) {
     int len = right - left + 1;
     int d = depths[len];
     return max(table[left][d], table[left + len - (1 << d)][d]);
   }

  private:
   vector<vector<pair<int, int> > > table;
   vector<int> depths;
   int N = 0;
 };
 int main() {
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   vector<int> vec(n);
   vector<pair<int, int> > vec_with_index(n);
   for (int i = 0; i < n; ++i) {
     cin >> vec[i];
     vec_with_index[i].first = vec[i];
     vec_with_index[i].second = i;
   }
   sort(vec_with_index.begin(), vec_with_index.end());
   vector<pair<int, int> > vals;
   vals.push_back({vec_with_index[0].first, 0});
   for (int i = 1; i < vec_with_index.size(); ++i) {
     vals.push_back({vec_with_index[i].first - vec_with_index[i - 1].first, i});
   }
   SparseTable st(vals);
   DP ret;
   ret.v1 = -1;
   ret.v2 = -1;
   ret.v3 = -1;
   for (int d1 = n - 1; d1 >= 0; --d1) {
     for (int d2 = d1 - 1; d2 >= 0; --d2) {
       int len1 = n - 1 - d1 + 1;
       int len2 = d1 - 1 - d2 + 1;
       if (len1 > 2 * len2 || len2 > 2 * len1) {
         continue;
       }
       int min_len3 = max({1, (len1 + 1) / 2, (len2 + 1) / 2});
       int max_len3 = min({d2, 2 * len1, 2 * len2});
       if (min_len3 > max_len3) {
         continue;
       }
       int min_d3 = d2 - max_len3;
       int max_d3 = d2 - min_len3;
       pair<int, int> max_val = st.getMax(min_d3, max_d3);
       DP temp;
       temp.d1 = d1;
       temp.d2 = d2;
       temp.d3 = max_val.second;
       temp.v1 = vec_with_index[d1].first - vec_with_index[d1 - 1].first;
       temp.v2 = vec_with_index[d2].first - vec_with_index[d2 - 1].first;
       temp.v3 = max_val.first;
       if (ret < temp) {
         ret = temp;
       }
     }
   }
   vector<int> ret_vec(n);
   for (int i = 0; i < ret.d3; ++i) {
     ret_vec[vec_with_index[i].second] = -1;
   }
   for (int i = ret.d3; i < ret.d2; ++i) {
     ret_vec[vec_with_index[i].second] = 3;
   }
   for (int i = ret.d2; i < ret.d1; ++i) {
     ret_vec[vec_with_index[i].second] = 2;
   }
   for (int i = ret.d1; i < n; ++i) {
     ret_vec[vec_with_index[i].second] = 1;
   }
   for (auto item : ret_vec) {
     cout << item <<    ;
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Node {
   long long l, r;
   mutable long long val;
   Node(long long l = 0, long long r = 0, long long v = 0)
       : l(l), r(r), val(v) {}
   bool operator<(const Node& rv) const { return l < rv.l; }
 };
 long long n, m;
 set<Node> t;
 long long a[100005];
 long long seed;
 long long vmax;
 long long qpow(long long x, long long p, long long m) {
   long long ans = 1;
   long long base = x;
   while (p) {
     if (p & 1) ans = (ans * base) % m;
     base = (base * base) % m;
     p >>= 1;
   }
   return ans;
 }
 long long rnd() {
   long long ans = seed;
   seed = (seed * 7 + 13) % 1000000007;
   return ans;
 }
 set<Node>::iterator split(long long p) {
   set<Node>::iterator it = t.lower_bound(Node(p));
   if (it != t.end() && it->l == p) {
     return it;
   }
   --it;
   long long l = it->l, r = it->r, val = it->val;
   t.erase(it);
   t.insert(Node(l, p - 1, val));
   return t.insert(Node(p, r, val)).first;
 }
 void assign(long long l, long long r, long long v) {
   set<Node>::iterator end = split(r + 1);
   set<Node>::iterator begin = split(l);
   t.erase(begin, end);
   t.insert(Node(l, r, v));
 }
 void add(long long l, long long r, long long k) {
   set<Node>::iterator end = split(r + 1);
   set<Node>::iterator begin = split(l);
   for (set<Node>::iterator it = begin; it != end; ++it) {
     it->val += k;
   }
 }
 long long kth(long long l, long long r, long long k) {
   vector<pair<long long, long long> > v;
   set<Node>::iterator end = split(r + 1);
   set<Node>::iterator begin = split(l);
   for (set<Node>::iterator it = begin; it != end; ++it) {
     v.push_back(make_pair(it->val, it->r - it->l + 1));
   }
   sort(v.begin(), v.end());
   for (long long i = 0; i < v.size(); ++i) {
     k -= v[i].second;
     if (k <= 0) return v[i].first;
   }
   return -1;
 }
 long long power(long long l, long long r, long long k, long long mod) {
   set<Node>::iterator end = split(r + 1);
   set<Node>::iterator begin = split(l);
   long long ans = 0;
   for (set<Node>::iterator it = begin; it != end; ++it) {
     ans = (ans +
            (((qpow(it->val % mod, k, mod) % mod) * (it->r - it->l + 1 % mod)) %
             mod)) %
           mod;
   }
   return ans % mod;
 }
 signed main() {
   ios::sync_with_stdio(false);
   cin >> n >> m >> seed >> vmax;
   for (long long i = 1; i <= n; ++i) {
     a[i] = (rnd() % vmax) + 1;
     t.insert(Node(i, i, a[i]));
   }
   for (long long i = 1; i <= m; ++i) {
     long long opt = (rnd() % 4) + 1, l = (rnd() % n) + 1, r = (rnd() % n) + 1,
               x, y;
     if (l > r) swap(l, r);
     if (opt == 3)
       x = (rnd() % (r - l + 1)) + 1;
     else
       x = (rnd() % vmax) + 1;
     if (opt == 4) y = (rnd() % vmax) + 1;
     if (opt == 1) {
       add(l, r, x);
     } else if (opt == 2) {
       assign(l, r, x);
     } else if (opt == 3) {
       cout << kth(l, r, x) << endl;
     } else {
       cout << power(l, r, x, y) << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxp = 22;
 const long double EPS = 1e-18;
 const long long INF = 1e18;
 const int MOD = 1e9 + 7;
 const int N = 2e5 + 1;
 void yesno(bool a) {
   if (a) {
     cout <<  YES  << '
';
   } else {
     cout <<  NO  << '
';
   }
 }
 long long power(long long x, long long n, long long m) {
   if (n == 0) return 1;
   long long u = power(x, n / 2, m);
   u = (u * u) % m;
   if (n % 2) u = (u * x) % m;
   return u;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   int n;
   cin >> n;
   long long i, arr[n];
   for (i = 0; i < n; i++) cin >> arr[i];
   if (n == 1) {
     cout << 1 <<     << 1 << '
';
     cout << -arr[0] << '
';
     cout << 1 <<     << 1 << '
';
     cout << 0 << '
';
     cout << 1 <<     << 1 << '
';
     cout << 0 << '
';
     return 0;
   }
   cout << 1 <<     << n - 1 << '
';
   for (i = 0; i < n - 1; i++) {
     long long num = arr[i] % n;
     cout << num * (n - 1) <<    ;
     arr[i] += num * (n - 1);
   }
   cout << '
';
   cout << n <<     << n << '
';
   long long num = arr[n - 1] % n;
   cout << (n - num) << '
';
   arr[n - 1] += n - num;
   cout << 1 <<     << n << '
';
   for (i = 0; i < n; i++) cout << -arr[i] <<    ;
   cout << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long n;
   cin >> n;
   char c[n][n];
   for (long long i = 0; i < n; i++) {
     for (long long j = 0; j < n; j++) {
       cin >> c[i][j];
     }
   }
   bool re = 1, ce = 1;
   for (long long i = 0; i < n; i++) {
     re = 1;
     for (long long j = 0; j < n; j++) {
       if (c[i][j] != 'E') {
         re = 0;
       }
     }
     if (re == 1) {
       break;
     }
   }
   for (long long j = 0; j < n; j++) {
     ce = 1;
     for (long long i = 0; i < n; i++) {
       if (c[i][j] != 'E') {
         ce = 0;
       }
     }
     if (ce == 1) {
       break;
     }
   }
   if (re == 1 && ce == 1) {
     cout <<  -1 ;
     return 0;
   }
   if (re == 1) {
     for (long long j = 0; j < n; j++) {
       for (long long i = 0; i < n; i++) {
         if (c[i][j] != 'E') {
           cout << i + 1 <<     << j + 1 <<
 ;
           break;
         }
       }
     }
   } else {
     for (long long i = 0; i < n; i++) {
       for (long long j = 0; j < n; j++) {
         if (c[i][j] != 'E') {
           cout << i + 1 <<     << j + 1 <<
 ;
           break;
         }
       }
     }
   }
 }


#include <bits/stdc++.h>
 int main() {
   int n;
   std::string s;
   std::cin >> n >> s;
   int cnt = 0;
   for (int i = 0; i < s.length(); i++) {
     if (s[i] == '1')
       cnt++;
     else {
       std::cout << cnt;
       cnt = 0;
     }
   }
   std::cout << cnt;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long f[105][105][2];
 struct seg {
   int a;
   long long len;
   bool operator<(const seg &p) const { return a < p.a; }
 } a[105];
 int main() {
   int n;
   scanf( %d , &n);
   for (int i = 1; i <= n; ++i) {
     scanf( %d%lld , &a[i].a, &a[i].len);
   }
   sort(a + 1, a + n + 1);
   long long ans = 0;
   a[0].a = -2e9;
   for (int i = 0; i <= n; ++i)
     for (int j = 0; j <= i; ++j) {
       for (int k = 0; k <= 1; ++k) {
         ans = max(ans, f[i][j][k]);
         int pr = a[j].a + k * a[j].len;
         int R, x;
         for (int p = i + 1, mx = -2e9; p <= n; ++p) {
           for (int q = 0; q <= 1; ++q) {
             int r = a[p].a + q * a[p].len;
             if (r > mx) mx = r, R = p, x = q;
             f[p][R][x] =
                 max(f[p][R][x],
                     f[i][j][k] + min(a[p].len, (long long)r - pr) + (mx - r));
           }
         }
       }
     }
   printf( %lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( O2 )
 using namespace std;
 const int maxn = 1e5 + 10, lg = 18;
 int n, m, q, cid[maxn], csize = 0, H[maxn], low[maxn], ok[maxn], par[maxn][lg],
                         comp[maxn], c1;
 bool dp[maxn][lg];
 vector<int> G[maxn];
 bool mark[maxn];
 void dfs1(int a, int p) {
   par[a][0] = p;
   for (int i = 1; i < lg; i++) {
     par[a][i] = par[par[a][i - 1]][i - 1];
   }
   low[a] = H[a];
   mark[a] = 1;
   for (int b : G[a]) {
     if (!mark[b]) {
       H[b] = H[a] + 1;
       comp[b] = comp[a];
       dfs1(b, a);
       low[a] = min(low[a], low[b]);
     } else if (b != p) {
       low[a] = min(low[a], H[b]);
     }
   }
 }
 void dfs2(int a) {
   mark[a] = 1;
   for (int b : G[a]) {
     if (!mark[b]) {
       if (low[b] >= H[a]) {
         cid[b] = csize++;
       } else {
         cid[b] = cid[a];
       }
       dfs2(b);
     } else if (H[a] > H[b]) {
       int dis = H[a] - H[b];
       if ((dis & 1) == 0) {
         ok[cid[a]] = 1;
       }
     }
   }
 }
 void dfs3(int a) {
   mark[a] = 1;
   dp[a][0] = (ok[cid[a]]);
   for (int b : G[a]) {
     if (!mark[b]) {
       dfs3(b);
     }
   }
 }
 bool lca(int a, int b) {
   bool ans = 0;
   if (H[a] > H[b]) swap(a, b);
   for (int i = lg - 1; i >= 0; i--) {
     if (H[par[b][i]] >= H[a]) {
       ans |= dp[b][i];
       b = par[b][i];
     }
   }
   if (a == b) {
     return ans;
   }
   for (int i = lg - 1; i >= 0; i--) {
     if (par[b][i] != par[a][i]) {
       ans |= dp[a][i];
       ans |= dp[b][i];
       a = par[a][i];
       b = par[b][i];
     }
   }
   ans |= dp[a][0];
   ans |= dp[b][0];
   return ans;
 }
 int32_t main() {
   scanf( %d%d , &n, &m);
   for (int i = 0; i < m; i++) {
     int a, b;
     scanf( %d%d , &a, &b);
     a--, b--;
     G[a].push_back(b);
     G[b].push_back(a);
   }
   for (int i = 0; i < n; i++) {
     if (!mark[i]) {
       comp[i] = c1++;
       dfs1(i, i);
     }
   }
   fill(mark, mark + n, 0);
   for (int i = 0; i < n; i++) {
     if (!mark[i]) {
       cid[i] = csize++;
       dfs2(i);
     }
   }
   fill(mark, mark + n, 0);
   for (int i = 0; i < n; i++) {
     if (!mark[i]) {
       dfs3(i);
     }
   }
   for (int j = 0; j < lg - 1; j++) {
     for (int i = 0; i < n; i++) {
       dp[i][j + 1] = dp[i][j] | dp[par[i][j]][j];
     }
   }
   scanf( %d , &q);
   while (q--) {
     int a, b;
     scanf( %d%d , &a, &b);
     a--, b--;
     if (H[a] > H[b]) swap(a, b);
     if (a == b || comp[a] != comp[b]) {
       printf( No
 );
       continue;
     }
     if ((H[b] - H[a]) & 1) {
       printf( Yes
 );
       continue;
     }
     bool ans = lca(a, b);
     printf(ans ?  Yes
  :  No
 );
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, k;
   cin >> n >> k;
   int a[n];
   int count[5005] = {0};
   for (int i = 0; i < n; i++) {
     cin >> a[i];
     count[a[i]]++;
   }
   int c[n];
   int d = 1;
   for (int i = 1; i <= 5000; i++) {
     if (count[i] > k) {
       cout <<  NO
            <<
 ;
       return 0;
     }
   }
   cout <<  YES
        <<
 ;
   if (k == 1) {
     for (int i = 0; i < n; i++) {
       cout <<  1
            <<    ;
     }
   } else {
     for (int i = 1; i <= 5000; i++) {
       for (int j = 0; j < n; j++) {
         if (a[j] == i) {
           c[j] = d;
           d++;
         }
         if (d > k) d = d % k;
       }
     }
     for (int i = 0; i < n; i++) {
       cout << c[i] <<    ;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1e9 + 10;
 const long long int LINF = 1LL * INF * INF;
 const int MAXN = 2e5 + 10;
 const int MAXM = 5e3 + 10;
 priority_queue<int> pq;
 vector<vector<int> > graph;
 queue<int> que;
 pair<int, int> A[20];
 long long int dp[20][(1 << 20)];
 long long int sum[(1 << 20)];
 long long int solve(int here, int cur, int n) {
   if (dp[here][cur] != -1) return dp[here][cur];
   long long int res = 0;
   for (int i = 0; i < n; i++) {
     if (i == here) continue;
     if ((1 << i) & cur) {
       if (A[i].second == A[here].second) continue;
       res += solve(i, cur ^ (1 << here), n);
       res %= 1000000007;
     }
   }
   return dp[here][cur] = res;
 }
 int main() {
   int n, m, k, a, b, x, y;
   int cnt = 0;
   int mx = 0;
   int mn = INF;
   int cur = 0, idx = -1;
   int T;
   cin >> n >> T;
   for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < (1 << n); j++) dp[i][j] = -1;
   for (int i = 0; i < n; i++) dp[i][(1 << i)] = 1;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < (1 << n); j++) solve(i, j, n);
   for (int i = 0; i < (1 << n); i++)
     for (int j = 0; j < n; j++)
       if ((1 << j) & i) sum[i] += (long long int)A[j].first;
   long long int res = 0;
   for (int i = 0; i < (1 << n); i++) {
     if (sum[i] != T) continue;
     for (int j = 0; j < n; j++)
       if ((1 << j) & i) {
         res += (long long int)dp[j][i];
         res %= 1000000007;
       }
   }
   cout << res;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int q[1000005];
 long long i, j, t, tot, C, cnt;
 long long loc[10005], op[10005];
 long long n, m, k, H, x, y, ans, tmp;
 long long a[100005], w[100005], e[25], dis[10005], heap[10005];
 bool used[100005], f[10005];
 map<long long, long long> A;
 map<long long, long long>::iterator it;
 void Spfa(long long s) {
   long long i, head, tail, x, v;
   for (i = 1; i <= k; i++) {
     dis[i] = 1999999999999999999LL;
     f[i] = false;
   }
   dis[s + 1] = 1;
   f[s + 1] = true;
   q[1] = s + 1;
   head = 1;
   tail = 2;
   while (head != tail) {
     x = q[head];
     f[x] = false;
     for (i = 1; i <= tot; i++)
       if (dis[x] + e[i] < dis[(dis[x] + e[i]) % k + 1]) {
         v = (dis[x] + e[i]) % k + 1;
         dis[v] = dis[x] + e[i];
         if (!f[v]) {
           q[tail] = v;
           f[v] = true;
           tail++;
         }
       }
     head++;
   }
 }
 int main() {
   scanf( %I64d%I64d%I64d%I64d , &H, &n, &m, &k);
   for (i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i], &w[i]);
   tot = 0;
   memset(used, false, sizeof used);
   x = 1 % k;
   for (i = 1; i <= n; i++) {
     if (a[i] % k == x) {
       used[i] = true;
       it = A.find(w[i]);
       if (it == A.end())
         A.insert(make_pair(w[i], 1));
       else
         A[w[i]]++;
     }
   }
   for (t = 1; t <= m; t++) {
     scanf( %I64d , &C);
     if (C == 1) {
       scanf( %I64d , &x);
       e[++tot] = x;
       Spfa(1 % k);
       for (i = 1; i <= n; i++)
         if (dis[a[i] % k + 1] <= a[i]) {
           if (!used[i]) {
             used[i] = true;
             it = A.find(w[i]);
             if (it == A.end())
               A.insert(make_pair(w[i], 1));
             else
               A[w[i]]++;
           }
         }
     } else if (C == 2) {
       scanf( %I64d%I64d , &x, &y);
       if (used[x]) {
         it = A.find(w[x]);
         tmp = it->second;
         if (tmp == 1)
           A.erase(w[x]);
         else
           A[w[x]]--;
         w[x] -= y;
         it = A.find(w[x]);
         if (it != A.end())
           A[w[x]]++;
         else
           A.insert(make_pair(w[x], 1));
       } else
         w[x] -= y;
     } else {
       if (A.size() == 0) {
         printf( 0
 );
         continue;
       }
       it = A.end();
       it--;
       ans = it->first;
       printf( %I64d
 , ans);
       tmp = it->second;
       if (tmp == 1)
         A.erase(ans);
       else
         A[ans]--;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long arr[100000], arr1[100000], n, x, z, co = 0, co1 = 0, k, m,
                                                 fin = 1000000;
   map<long long, long long> left;
   map<long long, long long> right;
   cin >> n;
   if (n % 2 == 0)
     k = n / 2;
   else
     k = (n / 2) + 1;
   for (int i = 0; i < n; i++) {
     cin >> x >> z;
     if (x == z) {
       if (left[x] == 0) {
         arr[co++] = x;
         left[x]++;
       } else
         left[x]++;
     } else {
       if (left[x] == 0) {
         arr[co++] = x;
         left[x]++;
       } else
         left[x]++;
       if (right[z] == 0) {
         arr1[co1++] = z;
         right[z]++;
       } else
         right[z]++;
     }
   }
   for (int i = 0; i < co; i++) {
     m = 1000001;
     if ((left[arr[i]] + right[arr[i]]) >= k) {
       m = k - left[arr[i]];
       if (m < 0) {
         cout <<  0 ;
         exit(0);
       }
     }
     if (m < fin) {
       fin = m;
     }
   }
   if (fin == 1000000) {
     for (int i = 0; i < co1; i++) {
       if (right[arr1[i]] >= k) {
         cout << k;
         exit(0);
       }
     }
   }
   if (fin == 1000000)
     cout <<  -1 ;
   else
     cout << fin;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N6 = 1e6 + 6;
 using namespace std;
 long long n, m, x, y, sum1, sum2, ans1, ans2;
 int main() {
   cin >> n >> x >> y;
   if (n > y) {
     cout << -1;
     return 0;
   }
   sum1 = y - n + 1;
   sum1 *= sum1;
   sum1 += (n - 1);
   if (sum1 >= x) {
     for (int i = 1; i < n; ++i) {
       cout << 1 << ' ';
     }
     cout << y - n + 1;
   } else
     cout << -1;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1050;
 int dp[maxn][9], nxt[maxn][9][maxn], a[maxn], n, cnt[9];
 inline int ask(int k) { return (1 << (k - 1)); }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= 8; ++j) cnt[j] = 0;
     for (int j = 1; j <= 8; ++j)
       for (int k = 1; k <= n; ++k) nxt[i][j][k] = 1e9;
     for (int j = i; j <= n; ++j) nxt[i][a[j]][++cnt[a[j]]] = j;
   }
   int ans = 0;
   for (int num = 0; num * 8 <= n; ++num) {
     for (int i = 0; i < 256; ++i)
       for (int k = 0; k <= 8; ++k) dp[i][k] = 1e9;
     dp[0][0] = 1;
     for (int i = 0; i < 256; ++i)
       for (int j = 0; j <= 8; ++j)
         for (int k = 1; k <= 8; ++k) {
           if (dp[i][j] > n || ask(k) & i) continue;
           dp[i ^ ask(k)][j] = min(dp[i ^ ask(k)][j], nxt[dp[i][j]][k][num] + 1);
           dp[i ^ ask(k)][j + 1] =
               min(dp[i ^ ask(k)][j + 1], nxt[dp[i][j]][k][num + 1] + 1);
         }
     for (int i = 0; i <= 8; ++i)
       if (dp[255][i] <= n + 1) ans = max(ans, 8 * num + i);
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using lint = long long;
 using ldouble = long double;
 void solve() {
   int n, d;
   std::cin >> n >> d;
   std::vector<int> vs(n, 1);
   int diff = n * (n - 1) / 2 - d;
   if (diff < 0) {
     std::cout <<  NO  << std::endl;
     return;
   }
   int head = 1;
   for (int v = n - 1; v > head; --v) {
     int to = std::max(v - diff, head);
     --vs[v];
     ++vs[to];
     diff -= v - to;
     if (diff == 0) break;
     while (vs[head] == (1 << head)) ++head;
   }
   if (diff > 0) {
     std::cout <<  NO  << std::endl;
     return;
   }
   std::cout <<  YES  << std::endl;
   int p = 1;
   for (int i = 1; i < n; ++i) {
     int v = p, ch = 0;
     for (int j = 0; j < vs[i]; ++j) {
       std::cout << v <<    ;
       if (++ch == 2) {
         ++v;
         ch = 0;
       }
     }
     p += vs[i - 1];
   }
   std::cout << std::endl;
 }
 int main() {
   std::cin.tie(nullptr);
   std::cout.tie(nullptr);
   std::ios::sync_with_stdio(false);
   int q;
   std::cin >> q;
   while (q--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1e9 + 7;
 const long long inf = 1e18;
 int main(void) {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   while (t--) {
     long long n, k;
     cin >> n >> k;
     k++;
     long long A[n];
     for (long long i = 0; i < n; i++) {
       cin >> A[i];
       long long t = 1;
       while (A[i]--) {
         t *= 10;
       }
       A[i] = t;
     }
     long long ans = 0;
     for (long long i = 0; i < n; i++) {
       long long cnt = k;
       if (i != n - 1) {
         cnt = min(cnt, A[i + 1] / A[i] - 1);
       }
       ans += A[i] * 1LL * cnt;
       k -= cnt;
       if (k == 0) break;
     }
     cout << ans << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 void r(int b, int p, int f, int h, int c);
 int main() {
   int b, p, f, h, c, t;
   cin >> t;
   while (t--) {
     cin >> b >> p >> f >> h >> c;
     r(b, p, f, h, c);
   }
 }
 void r(int b, int p, int f, int h, int c) {
   int i, j, k, t = 0;
   i = b / 2;
   if (i == 0) {
     cout << 0 << endl;
   } else {
     if (i >= (p + f)) {
       t = (p * h) + (c * f);
       cout << t << endl;
     } else {
       if (h >= c) {
         if (p >= i) {
           t = (i * h);
           cout << t << endl;
         } else {
           t = (h * p);
           i = i - p;
           t = t + (i * c);
           cout << t << endl;
         }
       } else {
         if (f >= i) {
           t = (i * c);
           cout << t << endl;
         } else {
           t = (c * f);
           i = i - f;
           t = t + (i * h);
           cout << t << endl;
         }
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 ;
 clock_t start;
 mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
 const long long N = 501, lmx = 11;
 long long mx[N][N][lmx][lmx], n, m, q, col[4][N][N], logg[N];
 long long sum(long long k, long long r1, long long c1, long long r2,
               long long c2) {
   return col[k][r2][c2] - col[k][r2][c1] - col[k][r1][c2] + col[k][r1][c1];
 }
 void sparse() {
   for (long long i = 2; i < N; i++) logg[i] = logg[i / 2] + 1;
   for (long long lgi = 1; lgi < lmx; lgi++) {
     for (long long i = 1; i <= n; i++) {
       for (long long j = 1; j <= m; j++) {
         if (i + (1 << (lgi - 1)) <= n)
           mx[i][j][lgi][0] = max(mx[i][j][lgi - 1][0],
                                  mx[i + (1 << (lgi - 1))][j][lgi - 1][0]);
       }
     }
   }
   for (long long lgi = 0; lgi < lmx; lgi++) {
     for (long long lgj = 1; lgj < lmx; lgj++) {
       for (long long i = 1; i <= n; i++) {
         for (long long j = 1; j <= m; j++) {
           long long k = lgj - 1;
           if (j + (1 << k) <= m)
             mx[i][j][lgi][lgj] =
                 max(mx[i][j][lgi][k], mx[i][j + (1 << k)][lgi][k]);
         }
       }
     }
   }
 }
 long long query(long long r1, long long c1, long long r2, long long c2) {
   if (r1 > r2 || c1 > c2) return 0;
   long long k1 = logg[r2 - r1 + 1], k2 = logg[c2 - c1 + 1];
   long long m1 = max(mx[r1][c1][k1][k2], mx[r2 - (1 << k1) + 1][c1][k1][k2]);
   long long m2 = max(mx[r1][c2 - (1 << k2) + 1][k1][k2],
                      mx[r2 - (1 << k1) + 1][c2 - (1 << k2) + 1][k1][k2]);
   return max(m1, m2);
 }
 void solve() {
   string s, ss =  RGYB ;
   cin >> n >> m >> q;
   for (long long i = 0; i < n; i++) {
     cin >> s;
     for (long long j = 0; j < m; j++) {
       for (long long k = 0; k < 4; k++)
         if (ss[k] == s[j]) col[k][i + 1][j + 1] = 1;
     }
   }
   for (long long k = 0; k < 4; k++) {
     for (long long i = 1; i <= n; i++)
       for (long long j = 1; j <= m; j++)
         col[k][i][j] +=
             col[k][i - 1][j] + col[k][i][j - 1] - col[k][i - 1][j - 1];
   }
   for (long long i = 1; i <= n; i++) {
     for (long long j = 1; j <= m; j++) {
       long long lim = min(min(i, j), min(n - i, m - j));
       for (long long len = 1; len <= lim; len++) {
         if (sum(0, i - len, j - len, i, j) != len * len) break;
         if (sum(1, i - len, j, i, j + len) != len * len) break;
         if (sum(2, i, j - len, i + len, j) != len * len) break;
         if (sum(3, i, j, i + len, j + len) != len * len) break;
         mx[i][j][0][0] = len * len;
       }
     }
   }
   sparse();
   while (q--) {
     long long r1, c1, r2, c2, ans = 0;
     cin >> r1 >> c1 >> r2 >> c2;
     long long s = 1, e = min(r2 - r1 + 1, c2 - c1 + 1);
     while (s <= e) {
       long long mid = (s + e) / 2;
       if (query(r1 + mid - 1, c1 + mid - 1, r2 - mid, c2 - mid) >= mid * mid) {
         s = mid + 1, ans = mid;
       } else
         e = mid - 1;
     }
     cout << 4 * ans * ans << '
';
   }
 }
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long t = 1;
   start = clock();
   cout << fixed << setprecision(15);
   while (t--) {
     solve();
   }
   double time_taken = double(clock() - start) / double(CLOCKS_PER_SEC);
   cerr << time_taken;
 }


#include <bits/stdc++.h>
 using namespace std;
 int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
 bool is_simple(int a) {
   for (int i = 2; i < a; ++i) {
     if (a % i == 0) return false;
   }
   return true;
 }
 int elems[200009] = {0};
 int addings[200009] = {0};
 int removes[200009] = {0};
 vector<string> orders;
 int main() {
   int n;
   double current_mean = 0.;
   long long cur_num = 1;
   scanf( %d , &n);
   char buf[100];
   gets(buf);
   orders.reserve(n);
   for (int i = 1; i < n + 1; ++i) {
     gets(buf);
     orders.push_back(string(buf));
     int t = orders[i - 1][0] - '0';
     addings[i] = addings[i - 1];
     removes[i] = removes[i - 1];
     if (t == 2) addings[i]++;
     if (t == 3) removes[i]++;
   }
   for (int i = 0; i < n; ++i) {
     stringstream ss(orders[i]);
     int t;
     ss >> t;
     if (t == 1) {
       int x, a;
       ss >> a >> x;
       double ttt = current_mean * cur_num;
       ttt += a * x;
       current_mean = ttt / cur_num;
       int start_change = cur_num - (removes[n] - removes[i]);
       if (start_change < 0) start_change = 0;
       for (int i = start_change; i < a && i < cur_num; ++i) elems[i] += x;
     }
     if (t == 2) {
       int k;
       ss >> k;
       elems[cur_num] = k;
       cur_num++;
       double ttt = current_mean * (cur_num - 1);
       ttt += k;
       current_mean = ttt / cur_num;
     }
     if (t == 3) {
       double ttt = current_mean * (cur_num);
       ttt -= elems[cur_num - 1];
       cur_num--;
       current_mean = ttt / cur_num;
     }
     printf( %.6f
 , current_mean);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline void chkmin(T &a, T b) {
   if (a > b) a = b;
 }
 template <class T>
 inline void chkmax(T &a, T b) {
   if (a < b) a = b;
 }
 long long sum[30];
 char fir[210000], sec[210000];
 int main() {
   int len, i;
   double ans, cnt;
   scanf( %d , &len);
   scanf( %s%s , fir, sec);
   cnt = 1LL * len * (len + 1) * (2 * len + 1) / 6;
   ans = 0;
   memset(sum, 0, sizeof(sum));
   for (i = len - 1; i >= 0; i--) {
     sum[fir[i] - 'A'] += len - i;
     ans += sum[sec[i] - 'A'] * (i + 1) / cnt;
   }
   memset(sum, 0, sizeof(sum));
   for (i = len - 1; i >= 0; i--) {
     ans += sum[fir[i] - 'A'] * (i + 1) / cnt;
     sum[sec[i] - 'A'] += len - i;
   }
   printf( %.15lf
 , 1.0 * ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 5;
 int n, m, k, ans[5];
 char s[N];
 void solve(int l, int r) {
   while (l != r) {
     int mid = l + r >> 1;
     printf( 1 %d %d
 , mid, mid + 1);
     fflush(stdout);
     scanf( %s , s);
     if (!strcmp(s,  NIE ))
       l = mid + 1;
     else
       r = mid;
   }
   ans[++m] = l;
 }
 int main() {
   scanf( %d%d , &n, &k);
   solve(1, n);
   if (ans[1] > 1) solve(1, ans[1] - 1);
   if (ans[1] < n) solve(ans[1] + 1, n);
   if (m == 2) {
     printf( 2 %d %d
 , ans[1], ans[2]);
     exit(0);
   }
   printf( 1 %d %d
 , ans[2], ans[3]);
   fflush(stdout);
   scanf( %s , s);
   if (!strcmp(s,  NIE )) ans[2] = ans[3];
   printf( 2 %d %d
 , ans[1], ans[2]);
   return 0;
 }


#include <bits/stdc++.h>
 const int N = 2e5 + 5;
 const int highestboolN = 1e9;
 const long long unsigned inf = 1234568901234567890;
 const long double pi = 3.141592653589793;
 const int md = 1e9 + 7;
 using namespace std;
 int here = 1;
 void force_break() {
   here++;
   if (here >= (N * 100)) {
     cout <<

	 Infinite loop

 ;
     exit(1);
   }
   return;
 }
 int board[105][105];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   scanf( %d , &n);
   memset(board, 0, sizeof(board));
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       if (board[i][j]) continue;
       char temp;
       if ((i + j) % 2) {
         board[i][j] = 1;
         temp = 2;
       } else {
         board[i][j] = 2;
         temp = 1;
       }
       if (i + 2 < n and j + 1 < n) board[i + 2][j + 1] = temp;
       if (i + 1 < n and j + 2 < n) board[i + 1][j + 2] = temp;
       if (i + 2 < n and j - 1 >= 0) board[i + 2][j - 1] = temp;
       if (i + 1 < n and j - 2 >= 0) board[i + 1][j - 2] = temp;
     }
   }
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       if (board[i][j] == 1)
         cout << 'B';
       else if (board[i][j] == 2)
         cout << 'W';
     }
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long arr[1010], brr[1010];
 int main() {
   long long n, i, j, x, y, ans;
   cin >> n;
   for (i = 1; i <= n; i++) cin >> arr[i];
   for (i = 1; i <= n; i++) cin >> brr[i];
   ans = 0;
   for (i = 1; i <= n; i++) {
     x = arr[i];
     y = brr[i];
     ans = max(ans, x + y);
     for (j = i + 1; j <= n; j++) {
       x = (x | arr[j]);
       y = (y | brr[j]);
       ans = max(ans, x + y);
     }
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 long long dp[26][2][2];
 long long need;
 bool hasone = 0;
 int ans[55];
 inline void upd(long long &a, long long b) { a += b; }
 inline long long getval(int p, int v) {
   memset(dp, 0, sizeof(dp));
   dp[0][0][0] = 1;
   for (int i = 0; i < (n + 1) / 2; i++) {
     for (int x = 0; x < 2; x++) {
       for (int y = 0; y < 2; y++) {
         if (!dp[i][x][y]) continue;
         for (int a = 0; a < 2; a++) {
           if (!i && a) continue;
           if (i <= p && a != ans[i]) continue;
           for (int b = 0; b < 2; b++) {
             if ((n - 1 - i) <= p && b != ans[n - 1 - i]) continue;
             if (i == n - 1 - i && a != b) continue;
             if (a > b && !x) continue;
             if (a > !b && !y) continue;
             upd(dp[i + 1][x | (a < b)][y | (a < !b)], dp[i][x][y]);
           }
         }
       }
     }
   }
   return dp[(n + 1) / 2][0][0] + dp[(n + 1) / 2][0][1] + dp[(n + 1) / 2][1][0] +
          dp[(n + 1) / 2][1][1] - !hasone;
 }
 int main() {
   cin >> n >> need;
   dp[0][0][0] = 1;
   for (int i = 0; i < (n + 1) / 2; i++) {
     for (int x = 0; x < 2; x++) {
       for (int y = 0; y < 2; y++) {
         if (!dp[i][x][y]) continue;
         for (int a = 0; a < 2; a++) {
           if (!i && a) continue;
           for (int b = 0; b < 2; b++) {
             if (i == n - 1 - i && a != b) continue;
             if (a > b && !x) continue;
             if (a > !b && !y) continue;
             upd(dp[i + 1][x | (a < b)][y | (a < !b)], dp[i][x][y]);
           }
         }
       }
     }
   }
   long long all = dp[(n + 1) / 2][0][0] + dp[(n + 1) / 2][0][1] +
                   dp[(n + 1) / 2][1][0] + dp[(n + 1) / 2][1][1];
   all--;
   if (all < need) {
     printf( -1
 );
     return 0;
   }
   for (int i = 0; i < n; i++) {
     ans[i] = 0;
     long long num = getval(i, ans[i]);
     if (num < need || (i == n - 1 && !hasone)) {
       ans[i] = 1;
       need -= num;
       hasone = 1;
     }
   }
   for (int i = 0; i < n; i++) printf( %d , ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline void read(T& x) {
   int f = 0, c = getchar();
   x = 0;
   while (!isdigit(c)) f |= c == '-', c = getchar();
   while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
   if (f) x = -x;
 }
 template <typename T, typename... Args>
 inline void read(T& x, Args&... args) {
   read(x);
   read(args...);
 }
 template <typename T>
 void write(T x) {
   if (x < 0) x = -x, putchar('-');
   if (x > 9) write(x / 10);
   putchar(x % 10 + 48);
 }
 template <typename T>
 void writes(T x) {
   write(x);
   putchar(' ');
 }
 template <typename T>
 void writeln(T x) {
   write(x);
   puts(  );
 }
 template <typename T>
 inline bool chkmin(T& x, const T& y) {
   return y < x ? (x = y, true) : false;
 }
 template <typename T>
 inline bool chkmax(T& x, const T& y) {
   return x < y ? (x = y, true) : false;
 }
 const int maxn = (int)3e5 + 10;
 const long long inf = (long long)1e18;
 const int mod = (int)1e9 + 7;
 int n, a[maxn];
 long long ans;
 vector<int> v[maxn];
 int main() {
   read(n);
   for (int i = (1); i < (2 * n + 1); i++) read(a[i]);
   for (int i = (1); i < (2 * n + 1); i++) {
     v[a[i]].push_back(i);
   }
   int now = 1;
   for (int i = (1); i < (n + 1); i++) {
     ans += abs(v[i][0] - now);
     now = v[i][0];
   }
   now = 1;
   for (int i = (1); i < (n + 1); i++) {
     ans += abs(v[i][1] - now);
     now = v[i][1];
   }
   write(ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 const bool debug = 1;
 int xl = 1 << 30, xr = -(1 << 30), yl = 1 << 30, yr = -(1 << 30), zl = 1 << 30,
     zr = -(1 << 30);
 bool getpod(pair<int, int> p, int s) {
   int pzl = p.first - p.second - s;
   int pzr = p.first - p.second + s;
   int pxl = p.first - s;
   int pxr = p.first + s;
   int pyl = p.second - s;
   int pyr = p.second + s;
   if (pzl <= zl && pzr >= zr && pyl <= yl && pyr >= yr && pxl <= xl &&
       pxr >= xr)
     return 1;
   return 0;
 }
 int main() {
   if (!debug) {
     cin.tie(0);
     cout.tie(0);
     ios::sync_with_stdio(0);
   }
   int n;
   cin >> n;
   vector<pair<int, int>> pt(n, {0, 0});
   for (int i = 0; i < n; i++) {
     string s;
     cin >> s;
     for (int j = 0; j < s.size(); j++)
       if (s[j] == 'B')
         pt[i].first++;
       else
         pt[i].second++;
   }
   for (int i = 0; i < n; i++) {
     xl = min(pt[i].first, xl);
     xr = max(pt[i].first, xr);
     yl = min(pt[i].second, yl);
     yr = max(pt[i].second, yr);
     zl = min(pt[i].first - pt[i].second, zl);
     zr = max(pt[i].first - pt[i].second, zr);
   }
   vector<pair<int, int>> p(12);
   vector<int> s(12);
   {
     int l = -1, r = 1 << 23;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {zr + yl, yl + c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[0] = r;
     p[0] = {zr + yl, yl + s[0]};
   }
   {
     int l = -1, r = 1 << 23;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xl + c, xl - zl};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[1] = r;
     p[1] = {xl + s[1], xl - zl};
   }
   {
     int l = -1, r = 1 << 23;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {zl + yr, yr - c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[2] = r;
     p[2] = {zl + yr, yr - s[2]};
   }
   {
     int l = -1, r = 1 << 23;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xr - c, xr - zr};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[3] = r;
     p[3] = {xr - s[3], xr - zr};
   }
   {
     int l = -1, r = 1 << 23;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xr - c, yr - c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[4] = r;
     p[4] = {xr - s[4], yr - s[4]};
   }
   {
     int l = -1, r = 1 << 23;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xl + c, yl + c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[5] = r;
     p[5] = {xl + s[5], yl + s[5]};
   }
   {
     int l = -1, r = zl - xl + yr;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xl + c, yr - c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[6] = r;
     p[6] = {xl + s[6], yr - s[6]};
   }
   {
     int l = -1, r = xr - yl - zr;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xr - c, yl + c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[7] = r;
     p[7] = {xr - s[7], yl + s[7]};
   }
   {
     int l = -1, r = xr - zl - yr;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xr - c, xr - zl - 2 * c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[8] = r;
     p[8] = {xr - s[8], xr - zl - 2 * s[8]};
   }
   {
     int l = -1, r = zr + yr - xr;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {zr + yr - 2 * c, yr - c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[9] = r;
     p[9] = {zr + yr - 2 * s[9], yr - s[9]};
   }
   {
     int l = -1, r = yl + zr - xl;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {xl + c, xl - zr + 2 * c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[10] = r;
     p[10] = {xl + s[10], xl - zr + 2 * s[10]};
   }
   {
     int l = -1, r = xl - zl - yl;
     while (l + 1 < r) {
       int c = (l + r) / 2;
       pair<int, int> p = {zl + yl + 2 * c, yl + c};
       if (getpod(p, c))
         r = c;
       else
         l = c;
     }
     s[11] = r;
     p[11] = {zl + yl + 2 * s[11], yl + s[11]};
   }
   int iout = 0;
   for (int i = 0; i < 12; i++)
     if (s[i] < s[iout] && getpod(p[i], s[i])) iout = i;
   cout << s[iout] << '
';
   for (int i = 0; i < p[iout].first; i++) cout << 'B';
   for (int i = 0; i < p[iout].second; i++) cout << 'N';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, x, a1, a2;
 int main() {
   scanf( %lld , &n);
   for (int i = 1; i <= n; ++i) {
     scanf( %lld , &x);
     if (i % 2 == 0) {
       a1 += (x + 1) / 2;
       a2 += x / 2;
     } else {
       a1 += x / 2;
       a2 += (x + 1) / 2;
     }
   }
   printf( %lld
 , min(a1, a2));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
   int a, b, c;
   cin >> a >> b >> c;
   cout << ((a + c - 1) * (b + c - 1) - c * (c - 1)) <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1e9 + 7;
 long long dx[] = {-1, 0, 1, 0};
 long long dy[] = {0, -1, 0, 1};
 vector<long long> p(10000005, -1);
 void f(long long n = 10000005) {
   p[2] = 2;
   for (long long i = 4; i < n; i += 2) {
     p[i] = 2;
   }
   for (long long i = 3; i < n; i += 2) {
     if (p[i] == -1) {
       p[i] = i;
       for (long long j = i * i; j < n; j += i) {
         if (p[j] == -1) p[j] = i;
       }
     }
   }
 }
 void find(long long x, vector<long long>& v) {
   while (x != 1) {
     v.push_back(p[x]);
     x /= p[x];
   }
 }
 void solve() {
   long long n, m;
   cin >> n >> m;
   vector<vector<long long>> v(n, vector<long long>(m));
   map<long long, vector<long long>> z;
   for (long long i = 0; i < n; i++) {
     for (long long j = 0; j < m; j++) {
       cin >> v[i][j];
       z[i + j].push_back(v[i][j]);
     }
   }
   long long f = 0, r = n + m - 2;
   long long ans = 0;
   while (f < r) {
     map<long long, long long> p;
     for (auto x : z[f]) p[x]++;
     for (auto x : z[r]) p[x]++;
     long long t = 0, mx = 0;
     for (auto x : p) {
       t += x.second;
       mx = max(mx, x.second);
     }
     ans += t - mx;
     f++;
     r--;
   }
   cout << ans <<
 ;
 }
 int32_t main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long t;
   cin >> t;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 char str[100005];
 int cnt[250];
 int main() {
   scanf( %s , &str);
   int len = strlen(str);
   set<char> myset;
   for (int i = 0; i < len; i++) {
     myset.insert(str[i]);
     cnt[str[i]]++;
   }
   if (myset.size() == 1 || myset.size() > 4) {
     printf( NO );
     return 0;
   }
   if (myset.size() == 4) {
     printf( YES );
     return 0;
   }
   if (myset.size() == 3) {
     if (len == 3) {
       printf( NO );
       return 0;
     } else {
       printf( YES );
       return 0;
     }
   }
   if (myset.size() == 2) {
     for (int i = 'a'; i <= 'z'; i++) {
       if (cnt[i] == 1) {
         printf( NO );
         return 0;
       }
     }
     printf( YES );
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX_N = 100005;
 int n, m;
 int t[MAX_N], x[MAX_N];
 int nxt;
 int idx[MAX_N];
 int res[MAX_N];
 bool mycmp(const int a, const int b) {
   if (x[a] != x[b]) return x[a] < x[b];
   return a < b;
 }
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = 0; i < n; ++i) scanf( %d%d , &t[i], &x[i]);
   int time = 0;
   for (int step = 0; step < n; step += m) {
     nxt = 0;
     for (int i = step; i < min(step + m, n); ++i) idx[nxt++] = i;
     time += max(0, t[idx[nxt - 1]] - time);
     sort(idx, idx + nxt, mycmp);
     for (int i = 0; i < nxt;) {
       int j = i;
       for (; j < nxt && x[idx[i]] == x[idx[j]]; ++j)
         ;
       time += x[idx[i]];
       if (i > 0) time -= x[idx[i - 1]];
       for (int k = i; k < j; ++k) res[idx[k]] = time;
       time += 1 + (j - i) / 2;
       i = j;
     }
     time += x[idx[nxt - 1]];
   }
   printf( %d , res[0]);
   for (int i = 1; i < n; ++i) printf(  %d , res[i]);
   printf(
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 2e5 + 7;
 const int mod = 1e9 + 7;
 const long long INF = 1e18;
 string a[30], b[30], ans[407];
 void rua() {
   int n, m;
   cin >> n >> m;
   for (int i = 0; i < n; i++) cin >> a[i];
   for (int i = 0; i < m; i++) cin >> b[i];
   int cnt = 0, s1 = -1, s2 = -1;
   while (cnt < n * m) {
     s1 = (s1 + 1) % n;
     s2 = (s2 + 1) % m;
     ans[cnt++] = a[s1] + b[s2];
   }
   int q;
   cin >> q;
   while (q--) {
     int x;
     cin >> x;
     cout << ans[(x - 1) % (n * m)] << endl;
   }
 }
 int main() {
   rua();
   return 0;
 }


#include <bits/stdc++.h>
 int main(int argc, char *argv[]) {
   int n, i, a, b, c, d;
   long int s;
   scanf( %d , &n);
   s = 0;
   for (i = 1; i <= n; i++) {
     scanf( %d %d %d %d , &a, &b, &c, &d);
     s = s + (1 + abs(a - c)) * (1 + abs(b - d));
   }
   printf( %ld , s);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int gcd(int a, int b) {
   if (b == 0)
     return a;
   else
     return gcd(b, a % b);
 }
 long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
 int main() {
   ios_base::sync_with_stdio(false);
   int n, m;
   cin >> n >> m;
   vector<vector<int> > edges(n + 10, vector<int>());
   for (int i = 0; i < m; i++) {
     int x, y;
     cin >> x >> y;
     edges[x].push_back(y);
     edges[y].push_back(x);
   }
   map<int, int> not_first;
   map<int, int> not_second;
   map<int, int> not_third;
   set<int> first;
   set<int> second;
   set<int> third;
   for (int i = 1; i < n + 1; i++) {
     if (not_first.find(i) == not_first.end()) {
       first.insert(i);
       for (int j = 0; j < edges[i].size(); j++) {
         not_first[edges[i][j]]++;
       }
     } else if (not_second.find(i) == not_second.end()) {
       second.insert(i);
       for (int j = 0; j < edges[i].size(); j++) {
         not_second[edges[i][j]]++;
       }
     } else if (not_third.find(i) == not_third.end()) {
       third.insert(i);
       for (int j = 0; j < edges[i].size(); j++) {
         not_third[edges[i][j]]++;
       }
     } else {
       cout << -1;
       return 0;
     }
   }
   if (second.size() == 0 or third.size() == 0) {
     cout << -1;
   } else {
     for (auto i = not_first.begin(); i != not_first.end(); i++) {
       if (i->second != first.size()) {
         cout << -1;
         return 0;
       }
     }
     for (auto i = not_second.begin(); i != not_second.end(); i++) {
       if (i->second != second.size()) {
         cout << -1;
         return 0;
       }
     }
     for (auto i = not_third.begin(); i != not_third.end(); i++) {
       if (i->second != third.size()) {
         cout << -1;
         return 0;
       }
     }
     vector<int> cols(n + 1, 0);
     for (auto i = first.begin(); i != first.end(); i++) {
       cols[*i] = 1;
     }
     for (auto i = second.begin(); i != second.end(); i++) {
       cols[*i] = 2;
     }
     for (auto i = third.begin(); i != third.end(); i++) {
       cols[*i] = 3;
     }
     for (int i = 1; i < n + 1; i++) {
       cout << cols[i] <<    ;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimization( unroll-loops )
 #pragma GCC optimize( Ofast )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4 )
 using namespace std;
 const int BASE = 1000000;
 char what[1 << 20];
 pair<int, int> nxt[10][1 << 20];
 pair<long long, int> to[10][10];
 inline long long Calc(long long x) {
   long long suff = x / BASE, pref = x % BASE;
   long long ans = suff;
   while (suff > 0) {
     ans += nxt[what[suff]][pref].first;
     pref = nxt[what[suff]][pref].second;
     pref += BASE - max(what[suff], what[pref]);
     --suff;
   }
   return ans + nxt[0][pref].first;
 }
 inline long long Process(long long x) {
   long long suff = x / (1LL * BASE * BASE), psuff = x / BASE % BASE,
             pref = x % BASE;
   if (suff == 0) {
     return Calc(x);
   }
   long long ans = 0;
   while (psuff >= 0) {
     ans += nxt[max(what[psuff], what[suff])][pref].first + 1;
     pref = nxt[max(what[psuff], what[suff])][pref].second;
     pref += BASE - max(what[psuff], max(what[suff], what[pref]));
     --psuff;
   }
   --suff;
   while (suff > 0) {
     ans += to[what[suff]][BASE - pref].first;
     pref = to[what[suff]][BASE - pref].second;
     --suff;
   }
   return ans + Calc(1LL * (BASE - 1) * BASE + pref);
 }
 int main() {
   for (int i = 1; i <= BASE; ++i) {
     what[i] = i % 10 > what[i / 10] ? i % 10 : what[i / 10];
     for (int d = 0; d < 10; ++d) {
       char r = what[i] < d ? d : what[i];
       if (i >= r) {
         nxt[d][i] = make_pair(nxt[d][i - r].first + 1, nxt[d][i - r].second);
       } else {
         nxt[d][i] = make_pair(0, i);
       }
     }
   }
   for (char d = 1; d < 10; ++d) {
     for (int l = 0; l < 10; ++l) {
       int suff = BASE - 1, pref = BASE - l;
       to[d][l].first = BASE;
       while (suff >= 0) {
         char r = (d < what[suff] ? what[suff] : d);
         to[d][l].first += nxt[r][pref].first;
         pref = nxt[r][pref].second;
         pref += BASE - (r < what[pref] ? what[pref] : r);
         --suff;
       }
       to[d][l].second = pref;
     }
   }
   long long n;
   cin >> n;
   cout << Process(n) << '
';
   return 0;
 }


#include <bits/stdc++.h>
 const int MAXN = 200000 + 10;
 const int INF = 0x7fffffff;
 using namespace std;
 struct EDGE {
   int u, v, w;
   bool operator<(const EDGE &b) const { return w > b.w; }
 };
 int fa[MAXN + MAXN];
 int n, m, vis[MAXN];
 int Min[MAXN];
 vector<EDGE> edge;
 int Find(int x) { return fa[x] < 0 ? x : fa[x] = Find(fa[x]); }
 int main() {
   edge.clear();
   scanf( %d%d , &n, &m);
   memset(fa, -1, sizeof(fa));
   memset(vis, 0, sizeof(vis));
   for (int i = 1; i <= m; i++) {
     int a, b, w;
     scanf( %d%d%d , &a, &b, &w);
     edge.push_back((EDGE){a, b, w});
   }
   sort(edge.begin(), edge.end());
   long long Ans = 0ll;
   for (int i = 0; i < m; i++) {
     int u = edge[i].u, v = edge[i].v;
     u = Find(u);
     v = Find(v);
     if (u == v) {
       if (fa[u] == -2) continue;
       fa[u] = -2;
       Ans += (long long)edge[i].w;
       continue;
     }
     if (fa[u] == -2 && fa[v] == -2) continue;
     fa[v] = min(fa[v], fa[u]);
     Ans += (long long)edge[i].w;
     fa[u] = v;
   }
   printf( %lld
 , Ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int intervalo[200010];
 int aparicoes[200010];
 int aceito[200010];
 int main() {
   int n, k, q;
   cin >> n >> k >> q;
   int l, r;
   for (int i = 0; i < n; i++) {
     cin >> l >> r;
     intervalo[l] += 1;
     intervalo[r + 1] -= 1;
   }
   int x = 0;
   for (int i = 1; i <= 200000; i++) {
     x += intervalo[i];
     aparicoes[i] = x;
   }
   for (int i = 1; i <= 200000; i++) {
     if (aparicoes[i] >= k)
       aceito[i] = 1;
     else
       aceito[i] = 0;
     aceito[i] += aceito[i - 1];
   }
   for (int i = 0; i < q; i++) {
     cin >> l >> r;
     cout << aceito[r] - aceito[l - 1] << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string a, b;
   cin >> a;
   b = a;
   for (string::reverse_iterator itr = a.rbegin(); itr != a.rend(); itr++)
     b += *itr;
   cout << b << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using lint = long long;
 const int inf = 1000000007;
 const int MOD = 1000000007;
 int f(int x) {
   int res = 0;
   while (x > 0) {
     res += x % 10;
     x /= 10;
   }
   return res;
 }
 bool calc(int n, int k) {
   int sm = 0;
   for (int i = 0; i < k; ++i) {
     sm += f(i);
   }
   for (int i = k; i <= 100000; ++i) {
     sm += f(i);
     if (sm == n) {
       cout << i - k <<
 ;
       return true;
     }
     sm -= f(i - k);
   }
   if (n <= 45) {
     cout << -1 <<
 ;
     return true;
   }
   return false;
 }
 void solve() {
   int n, k;
   cin >> n >> k;
   if (calc(n, k)) return;
   n -= k * (k + 1) / 2;
   if (n < 0) {
     cout << -1 <<
 ;
     return;
   }
   int top = 0;
   string mid;
   int last = 0;
   int cnt = 0;
   while (n % (k + 1) != 0) {
     n += 9;
     cnt++;
     if (cnt > 9) {
       cout << -1 <<
 ;
       return;
     }
   }
   if (n - cnt * 9 < (k - cnt) * 9) {
     cout << -1 <<
 ;
     return;
   }
   last = 9 - (k - cnt);
   n /= (k + 1);
   n -= last;
   while (n > 9) {
     n -= 9;
     mid += '9';
   }
   top = n;
   if (cnt > 0) {
     int l = mid.length();
     if (l != 0) {
       mid[l - 1] = '8';
       top++;
     }
   }
   string hoge;
   while (top > 9) {
     top -= 9;
     hoge += '9';
   }
   if (top > 0) cout << top;
   cout << hoge << mid << last <<
 ;
 }
 signed main() {
   int t;
   cin >> t;
   for (int i = 0; i < t; ++i) solve();
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( O3,no-stack-protector,unroll-loops,fast-math )
 using namespace std;
 struct coor {
   long long x, y, x1, y1;
 };
 vector<struct coor> v;
 struct coor ldp[200005], rdp[200005];
 struct coor inter(struct coor l, struct coor r) {
   struct coor res = {INT_MIN, INT_MIN, INT_MIN, INT_MIN};
   if (min(l.x1, r.x1) < max(r.x, l.x) || min(l.y1, r.y1) < max(r.y, l.y))
     return res;
   res.x = max(l.x, r.x);
   res.x1 = min(l.x1, r.x1);
   res.y = max(l.y, r.y);
   res.y1 = min(l.y1, r.y1);
   return res;
 }
 bool check(struct coor l) { return (l.x != INT_MIN); }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q;
   cin >> n;
   for (i = 0; i < n; i++) {
     cin >> a >> b >> c >> d;
     v.push_back({a, b, c, d});
   }
   ldp[0] = v[0];
   for (i = 1; i < n; i++) {
     ldp[i] = inter(ldp[i - 1], v[i]);
   }
   rdp[n - 1] = v[n - 1];
   for (i = n - 2; i >= 0; i--) {
     rdp[i] = inter(rdp[i + 1], v[i]);
   }
   if (check(ldp[n - 2])) {
     cout << ldp[n - 2].x << ' ' << ldp[n - 2].y << '
';
   } else if (check(rdp[1])) {
     cout << rdp[1].x << ' ' << rdp[1].y << '
';
   } else {
     for (i = 1; i < n - 1; i++) {
       struct coor fin = inter(ldp[i - 1], rdp[i + 1]);
       if (check(fin)) {
         cout << fin.x << ' ' << fin.y << '
';
         return 0;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t, n, a, b, c, d;
   cin >> t;
   while (t--) {
     cin >> n >> a >> b >> c >> d;
     int mi = (a - b) * n, ma = (a + b) * n;
     if ((mi > c + d) || (ma < c - d))
       cout <<  NO  << endl;
     else
       cout <<  YES  << endl;
   }
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 using namespace std;
 const long long mod = 1000000007;
 void solve() {
   int n, m, u, v;
   cin >> n >> m;
   vector<int> adj[n + 1];
   for (int i = 0; i < m; i++) {
     cin >> u >> v;
     adj[u].push_back(v);
     adj[v].push_back(u);
   }
   vector<pair<long long, long long> > hash, hash_orig;
   hash.reserve(n);
   long long p1 = 31, p2 = 53, h1, h2;
   long long pow_p1[n + 1], pow_p2[n + 1];
   pow_p1[0] = pow_p2[0] = 1;
   for (int i = 1; i <= n; i++) {
     pow_p1[i] = pow_p1[i - 1] * p1 % mod;
     pow_p2[i] = pow_p2[i - 1] * p2 % mod;
   }
   for (int i = 1; i <= n; i++) {
     h1 = 0;
     h2 = 0;
     for (int &j : adj[i]) {
       h1 += pow_p1[j];
       h2 += pow_p2[j];
     }
     hash.push_back({h1, h2});
   }
   hash_orig = hash;
   sort((hash).begin(), (hash).end());
   long long ans = 0;
   int cnt = 1;
   for (int i = 1; i < n; i++) {
     if (hash[i] != hash[i - 1]) {
       ans += 1ll * cnt * (cnt - 1) / 2;
       cnt = 1;
     } else
       cnt++;
   }
   ans += 1ll * cnt * (cnt - 1) / 2;
   for (int i = 1; i <= n; i++) {
     hash_orig[i - 1].first += pow_p1[i];
     hash_orig[i - 1].second += pow_p2[i];
   }
   for (int i = 1; i <= n; i++) {
     for (int &j : adj[i]) {
       if (j < i || adj[i].size() != adj[j].size()) continue;
       if (hash_orig[i - 1] == hash_orig[j - 1]) ans++;
     }
   }
   cout << ans <<
 ;
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int t = 1;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace std;
 typedef long long int ll;
 typedef unsigned long long int ull;
 inline void smax(int &x, int y) { x = max(x, y); }
 inline void smin(int &x, int y) { x = min(x, y); }
 ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
 const double PI = acos(-1.0l);
 vector<long long> rev;
 vector<complex<double> > omega;
 void calc_rev(long long n, long long log_n) {
   rev.resize(n);
   omega.resize(n);
   for (long long i = 0; i < n; i++) {
     rev[i] = 0;
     for (long long j = 0; j < log_n; j++) {
       if ((i >> j) & 1) rev[i] |= 1 << (log_n - j - 1);
     }
   }
 }
 void fft(vector<complex<double> > &A, long long n, bool invert) {
   for (long long i = 0; i < n; i++) {
     if (i < rev[i]) swap(A[i], A[rev[i]]);
   }
   for (long long len = 2; len <= n; len <<= 1) {
     double ang = 2 * PI / len * (invert ? -1 : +1);
     long long half = (len >> 1);
     complex<double> curomega(cos(ang), sin(ang));
     omega[0] = complex<double>(1, 0);
     for (long long i = 1; i < half; i++) omega[i] = omega[i - 1] * curomega;
     for (long long i = 0; i < n; i += len) {
       complex<double> t;
       long long pu = i, pv = i + half, pu_end = i + half, pw = 0;
       for (; pu != pu_end; pu++, pv++, pw++) {
         t = A[pv] * omega[pw];
         A[pv] = A[pu] - t;
         A[pu] += t;
       }
     }
   }
   if (invert)
     for (long long i = 0; i < n; i++) A[i] /= n;
 }
 void multiply(long long n, vector<complex<double> > &A,
               vector<complex<double> > &B, vector<long long> &C) {
   fft(A, n, false);
   fft(B, n, false);
   for (long long i = 0; i < n; i++) A[i] *= B[i];
   fft(A, n, true);
   for (long long i = 0; i < n; i++) {
     C[i] = (long long)(A[i].real() + 0.5);
     C[i] = min(C[i], 1LL);
   }
 }
 void Solve(long long n, vector<long long> &coeffA, vector<long long> &coeffB,
            vector<long long> &result) {
   vector<complex<double> > A(n), B(n);
   for (long long i = 0; i < n; i++) A[i] = coeffA[i];
   for (long long i = 0; i < n; i++) B[i] = coeffB[i];
   multiply(n, A, B, result);
 }
 void do_FFT(vector<long long> &A, vector<long long> &B,
             vector<long long> &result) {
   long long n = 1, bits = 0;
   while (n < 2 * A.size() || n < 2 * B.size()) n <<= 1, bits++;
   result.resize(n, 0);
   calc_rev(n, bits);
   vector<long long> tempA(A.begin(), A.end());
   vector<long long> tempB(B.begin(), B.end());
   tempA.resize(n);
   tempB.resize(n);
   Solve(n, tempA, tempB, result);
 }
 vector<ll> polpow(vector<ll> &arr, long long k) {
   vector<ll> sol;
   while (k > 0) {
     if (k % 2) {
       if (sol.size() == 0)
         for (__typeof(arr.size()) i = (0) - ((0) > (arr.size()));
              i != (arr.size()) - ((0) > (arr.size()));
              i += 1 - 2 * ((0) > (arr.size())))
           sol.push_back(arr[i]);
       else
         do_FFT(sol, arr, sol);
     }
     do_FFT(arr, arr, arr);
     k = k / 2;
   }
   return sol;
 }
 int32_t main() {
   long long n, k;
   cin >> n >> k;
   vector<long long> v(n);
   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
        i += 1 - 2 * ((0) > (n)))
     cin >> v[i];
   vector<ll> arr(1001);
   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
        i += 1 - 2 * ((0) > (n))) {
     arr[v[i]] = 1;
   }
   while (arr.back() == 0) {
     arr.pop_back();
   }
   vector<ll> res = polpow(arr, k);
   for (__typeof(res.size()) i = (1) - ((1) > (res.size()));
        i != (res.size()) - ((1) > (res.size()));
        i += 1 - 2 * ((1) > (res.size()))) {
     if (res[i] > 0) cout << i <<    ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m = 0;
   cin >> n;
   int last;
   for (int(i) = 0; (i) < (n); ++(i)) {
     cin >> last;
     m += last;
   }
   cout << ((n - m == 1 && n > 1) || (n == 1 && m == 1) ?  YES
  :  NO
 );
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 5;
 int t, id, n, m, x, y, k, c, p, dif, ans, sum, pre, rem, cur, tmp, tot, r, l, u,
     d, xx, yy;
 int a[N], vis[N], f[N], b[N], cu[N];
 vector<int> v, adj[N];
 bool fl, ok;
 int dp[N];
 int mem[N];
 int sol(int i = n) {
   int &ret = mem[i];
   if (~ret) return ret;
   if (!i) return ret = 0;
   ret = sol(i - 1) + 20;
   int B90 = upper_bound(a + 1, a + n + 1, a[i] - 90) - (a + 1);
   ret = min(ret, sol(B90) + 50);
   int Bday = upper_bound(a + 1, a + n + 1, a[i] - 1440) - (a + 1);
   ret = min(ret, sol(Bday) + 120);
   return ret;
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= (int)n; ++i) scanf( %d , &a[i]);
   memset(mem, -1, sizeof mem);
   ;
   sol();
   for (int i = 1; i <= (int)n; ++i) printf( %d
 , sol(i) - sol(i - 1));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void task();
 int main() {
   task();
   return 0;
 }
 const int N = 2e5 + 10;
 const long long int MOD = (long long int)1e9 + 7;
 const int INF = 0x3f3f3f3f;
 const long long int LINF = (long long int)4e18 + 100;
 const int BUF_SIZE = (int)1e6 + 10;
 const double PI = acos(-1);
 pair<int, int> a[N];
 double u[N], ad[N], bd[N];
 long long int sq_dist(long long int x1, long long int y1, long long int x2,
                       long long int y2) {
   return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
 }
 double dist(long long int x1, long long int y1, long long int x2,
             long long int y2) {
   return sqrt(sq_dist(x1, y1, x2, y2));
 }
 double dp[N][2][2];
 void task() {
   int ai, aj, bi, bj, ui, uj;
   cin >> ai >> aj >> bi >> bj >> ui >> uj;
   int n;
   cin >> n;
   for (int i = 0; i < n; ++i) {
     cin >> a[i].first >> a[i].second;
   }
   for (int i = 0; i < n; ++i) {
     u[i] = dist(ui, uj, a[i].first, a[i].second);
     (void(1));
     ;
   }
   for (int i = 0; i < n; ++i) {
     ad[i] = dist(ai, aj, a[i].first, a[i].second) + u[i];
     (void(1));
     ;
   }
   for (int i = 0; i < n; ++i) {
     bd[i] = dist(bi, bj, a[i].first, a[i].second) + u[i];
     (void(1));
     ;
   }
   fill(dp[0][0], dp[0][0] + N * 2 * 2, LINF);
   dp[0][1][1] = 0;
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < 2; ++j) {
       for (int k = 0; k < 2; ++k) {
         (void(1));
         ;
         if (j == 1) {
           dp[i + 1][j - 1][k] = min(dp[i][j][k] + ad[i], dp[i + 1][j - 1][k]);
         }
         if (k == 1) {
           dp[i + 1][j][k - 1] = min(dp[i][j][k] + bd[i], dp[i + 1][j][k - 1]);
         }
         dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k] + 2 * u[i]);
       }
     }
   }
   double ans = LINF;
   for (int i = 0; i < 2; ++i) {
     for (int j = 0; j < 2; ++j)
       if (!(i == 1 && j == 1)) {
         (void(1));
         ;
         ans = min(ans, dp[n][i][j]);
       }
   }
   cout << fixed << setprecision(12) << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     int f = 1;
     int s = 0;
     vector<int> A;
     for (int i = 0; i < n; i++) {
       int a;
       cin >> a;
       A.push_back(a);
     }
     if (A.size() == 1) {
       cout <<  First  << endl;
       continue;
     }
     if (n == 2) {
       if (A[0] != 1) {
         cout <<  First  << endl;
         continue;
       } else {
         cout <<  Second  << endl;
         continue;
       }
     }
     for (int i = 0; i < n - 2; i++) {
       if (A[i] != 1 && A[i + 1] != 1) {
         if (f == 1) {
           f = 1;
           s = 0;
         } else {
           s = 1;
           f = 0;
         }
       } else if (A[i] != 1 && A[i + 1] == 1) {
         int count = 0;
         int j = i + 1;
         while (A[j] == 1 && j <= n - 2) {
           count++;
           j++;
         }
         if (count % 2 == 1) {
           if (f == 1) {
             s = 1;
             f = 0;
           } else {
             f = 1;
             s = 0;
           }
         } else {
           if (f == 1) {
             f = 1;
             s = 0;
           } else {
             s = 1;
             f = 0;
           }
         }
       } else if (A[i] == 1) {
         if (f == 1) {
           s = 1;
           f = 0;
         } else {
           f = 1;
           s = 0;
         }
       }
     }
     if (A[n - 2] != 1 && f == 1) {
       cout <<  First  << endl;
       continue;
     } else if (A[n - 2] == 1 && f == 1) {
       cout <<  Second  << endl;
       continue;
     } else if (A[n - 2] != 1 && s == 1) {
       cout <<  Second  << endl;
       continue;
     } else if (A[n - 2] == 1 && s == 1) {
       cout <<  First  << endl;
       continue;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 500100;
 multiset<pair<long long, long long> > intervals;
 long long n, k;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cin >> n >> k;
   for (int i = 0; i < k; i++) intervals.insert(make_pair(0, i));
   long long s, d;
   for (int i = 0; i < n; i++) {
     cin >> s >> d;
     auto x = intervals.begin();
     long long stx = (*x).first;
     long long idx = (*x).second;
     if (stx < s) stx = s;
     stx += d;
     cout << stx <<
 ;
     intervals.erase(x);
     intervals.insert(make_pair(stx, idx));
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct node {
   int x, y;
 };
 vector<node> q;
 int n, m, sum[2020][2020];
 char g[2020][2020];
 void init() {
   for (int i = 0; i < (n); i++)
     for (int j = 0; j < (m); j++)
       if (g[i][j] == 'w') q.push_back((node){i, j});
   for (int i = 0; i < (n); i++)
     for (int j = 0; j < (m); j++)
       if (g[i][j] == 'w') sum[i][j] = 1;
   for (int i = 0; i < (n); i++)
     for (int j = 0; j < (m); j++)
       if (j - 1 >= 0) sum[i][j] = sum[i][j - 1] + sum[i][j];
   for (int i = 0; i < (m); i++)
     for (int j = 0; j < (n); j++)
       if (j - 1 >= 0) sum[j][i] = sum[j - 1][i] + sum[j][i];
 }
 bool cmpx(node a, node b) { return a.x < b.x; }
 bool cmpy(node a, node b) { return a.y < b.y; }
 int getlen() {
   int res = -1;
   sort(q.begin(), q.end(), cmpx);
   res = max(res, abs(q[0].x - q[q.size() - 1].x) + 1);
   sort(q.begin(), q.end(), cmpy);
   res = max(res, abs(q[0].y - q[q.size() - 1].y) + 1);
   return res;
 }
 int getarea(int x1, int y1, int x2, int y2) {
   if (x1 > x2 || y1 > y2) return 0;
   int res = sum[x2][y2];
   if (x1 - 1 >= 0) res -= sum[x1 - 1][y2];
   if (y1 - 1 >= 0) res -= sum[x2][y1 - 1];
   if (x1 - 1 >= 0 && y1 - 1 >= 0) res += sum[x1 - 1][y1 - 1];
   return res;
 }
 bool check(int x, int y, int len) {
   int x2 = x - len + 1;
   int y2 = y - len + 1;
   int in = getarea(x2 + 1, y2 + 1, x - 1, y - 1);
   int out = getarea(0, 0, n - 1, m - 1) - getarea(x2, y2, x, y);
   if (in || out)
     return false;
   else
     return true;
 }
 void filling(int x, int y, int x2, int y2) {
   for (int i = x; i <= x2; i++)
     for (int j = y; j <= y2; j++)
       if (i == x || i == x2 || j == y || j == y2)
         g[i][j] = (g[i][j] == '.') ? '+' : 'w';
 }
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = 0; i < (n); i++) scanf( %s , g[i]);
   init();
   int len = getlen();
   bool flg = 0;
   for (int i = 0; i < (n); i++)
     for (int j = 0; j < (m); j++)
       if (i + 1 >= len && j + 1 >= len) {
         if (flg) break;
         if (check(i, j, len)) {
           flg = true;
           filling(i - len + 1, j - len + 1, i, j);
           break;
         }
       }
   if (flg)
     for (int i = 0; i < (n); i++) printf( %s
 , g[i]);
   else
     printf( -1
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T, class U>
 void maximize(T &x, U y) {
   if (x < y) x = y;
 }
 template <class T, class U>
 void minimize(T &x, U y) {
   if (x > y) x = y;
 }
 template <class T>
 T Abs(T x) {
   return (x < (T)0 ? -x : x);
 }
 template <class T>
 T safe_sqrt(T x) {
   return sqrt(max((T)0, x));
 }
 template <class T, class U, class V>
 T addmod(T x, U k, V mod) {
   return ((x + k) % mod + mod) % mod;
 }
 template <class T, class U, class V>
 T submod(T x, U k, V mod) {
   return ((x - k) % mod + mod) % mod;
 }
 template <class T, class U, class V>
 T mulmod(T x, U k, V mod) {
   return (int64_t)x * k % mod;
 }
 namespace task {
 int64_t dp[11][100][1200];
 int b;
 int64_t l, r;
 vector<int> digits;
 vector<int> trans(int64_t x, int b) {
   vector<int> vec;
   while (x > 0) vec.push_back(x % b), x /= b;
   return vec;
 }
 int64_t calc(int base, int idx, int mask, bool flag) {
   if (idx == -1) return (mask == 0);
   if (~dp[base][idx][mask] and flag) return dp[base][idx][mask];
   int64_t ret = 0;
   int k = flag ? b - 1 : digits[idx];
   for (int i = 0; i <= k; ++i)
     ret += calc(base, idx - 1, mask ^ ((1LL) << (i)), flag | (i < k));
   if (flag) dp[base][idx][mask] = ret;
   return ret;
 }
 int64_t f(int64_t x) {
   if (!x) return 0ll;
   digits.clear();
   digits = trans(x, b);
   int64_t ret = 0;
   for (int i = 0; i < ((digits).size()); ++i) {
     int up = (i == ((digits).size()) - 1 ? digits[i] : b - 1);
     for (int j = 1; j <= up; ++j)
       ret +=
           calc(b, i - 1, ((1LL) << (j)), (i < ((digits).size()) - 1 or j < up));
   }
   return ret;
 }
 void solve() {
   int q;
   scanf( %d , &q);
   memset(dp, -1ll, sizeof(dp));
   while (q--) {
     scanf( %d%I64d%I64d , &b, &l, &r);
     int64_t x = f(r);
     int64_t y = f(l - 1);
     int64_t ans = f(r) - f(l - 1);
     printf( %I64d
 , ans);
   }
 }
 }  // namespace task
 int main(void) { task::solve(); }


#include <bits/stdc++.h>
 using namespace std;
 int n, a[1050];
 int main() {
   cin >> n;
   for (int i = 0; i < n; i++) cin >> a[i];
   int tens = a[0];
   set<int> answer;
   for (int rem = 0; rem < 10000000; rem++) {
     double fuel = tens * 10 + static_cast<double>(rem) / 1000000;
     double addend = fuel;
     bool isValid = true;
     for (int i = 0; isValid and i < n; i++) {
       fuel -= (a[i] - (i == 0 ? 0 : a[i - 1])) * 10;
       if (fuel < 0 or fuel >= 10 - 1e-6) {
         isValid = false;
       }
       fuel += addend;
     }
     if (isValid) {
       answer.insert(static_cast<int>(fuel) / 10 + a[n - 1]);
     }
   }
   if (answer.size() > 1)
     cout <<  not unique  << endl;
   else
     cout <<  unique  << endl << *answer.begin() << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = (int)2e5 + 10;
 vector<pair<int, int> > a, b;
 vector<int> L;
 int n, m, q[MAXN], id[MAXN], Tohka[MAXN], l[MAXN], r[MAXN], t[MAXN], fa[MAXN],
     T[MAXN];
 bool cmp(int first, int second) { return q[first] < q[second]; }
 bool cmp1(int first, int second) { return t[first] < t[second]; }
 int Getp(int a) { return lower_bound(L.begin(), L.end(), a) - L.begin(); }
 int getf(int first) {
   if (fa[first] == first) return first;
   fa[first] = getf(fa[first]);
   return fa[first];
 }
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= m; ++i) {
     scanf( %d%d%d , &l[i], &r[i], &t[i]);
     L.push_back(l[i]), L.push_back(r[i]);
     id[i] = i;
   }
   sort(L.begin(), L.end());
   L.erase(unique(L.begin(), L.end()), L.end());
   for (int i = 0; i < ((int)(L).size()); ++i) fa[i] = i;
   sort(id + 1, id + m + 1, cmp1);
   memset(T, -1, sizeof(T));
   for (int i = 1; i <= m; ++i) {
     int tl = Getp(l[id[i]]), tr = Getp(r[id[i]]), tT = t[id[i]];
     for (tl = getf(tl); tl < tr; T[tl] = tT, fa[tl] = tl + 1, tl = getf(tl))
       ;
   }
   for (int i = 0; i + 1 < ((int)(L).size()); ++i) {
     int l = L[i], r = L[i + 1], t = T[i];
     if (T[i] == -1) continue;
     a.push_back(make_pair(t - r, 1)), a.push_back(make_pair(t - l, -1));
     b.push_back(make_pair(t - r, -(t - r))),
         b.push_back(make_pair(t - l, (t - r)));
     b.push_back(make_pair(t - l, (r - l)));
   }
   sort(a.begin(), a.end());
   sort(b.begin(), b.end());
   for (int i = 1; i <= n; ++i) scanf( %d , &q[i]), id[i] = i;
   sort(id + 1, id + n + 1, cmp);
   long long s1 = 0, s2 = 0;
   for (int i = 1, p1 = 0, p2 = 0; i <= n; ++i) {
     for (; p1 < ((int)(a).size()) && a[p1].first <= q[id[i]];
          s1 += a[p1].second, ++p1)
       ;
     for (; p2 < ((int)(b).size()) && b[p2].first <= q[id[i]];
          s2 += b[p2].second, ++p2)
       ;
     Tohka[id[i]] = s1 * q[id[i]] + s2;
   }
   for (int i = 1; i <= n; ++i) printf( %d
 , Tohka[i]);
   fclose(stdin);
   fclose(stdout);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m, q;
   scanf( %d %d %d , &n, &m, &q);
   int log_n = 0;
   while (1 << log_n <= n) {
     ++log_n;
   }
   int jump_small = pow(n, 1.0 / 3), jump_large = pow(n, 2.0 / 3);
   vector<vector<int>> rmq_min(log_n, vector<int>(n)),
       rmq_max(log_n, vector<int>(n));
   vector<int> a(n), next(n), jump(n), times(n), now_min(n), now_max(n);
   priority_queue<pair<int, int>> heap;
   for (int i = 0; i < n; ++i) {
     scanf( %d , &a[i]);
     rmq_min[0][i] = rmq_max[0][i] = a[i];
     next[i] = i + 1;
     jump[i] = min(i + jump_small, n);
     times[i] = jump[i] - i;
   }
   for (int i = 0; i < n - 1; ++i) {
     now_min[i] = min(a[i], a[i + 1]);
     now_max[i] = max(a[i], a[i + 1]);
     heap.push(make_pair(now_min[i] - now_max[i], i));
   }
   for (int i = 1; i < log_n; ++i) {
     for (int j = 0; j + (1 << i) <= n; ++j) {
       rmq_min[i][j] = min(rmq_min[i - 1][j], rmq_min[i - 1][j + (1 << i - 1)]);
       rmq_max[i][j] = max(rmq_max[i - 1][j], rmq_max[i - 1][j + (1 << i - 1)]);
     }
   }
   vector<int> last(n);
   vector<bool> visit(n);
   auto update = [&](int x, int limit) {
     while (next[x] < n && next[x] - x <= jump_large &&
            now_max[x] - now_min[x] <= limit) {
       ++next[x];
       if (next[x] < n) {
         now_max[x] = max(now_max[x], a[next[x]]);
         now_min[x] = min(now_min[x], a[next[x]]);
       }
     }
     if (next[x] < n && next[x] - x <= jump_small) {
       heap.push(make_pair(now_min[x] - now_max[x], x));
     }
     vector<int> stack;
     jump[x] = x;
     times[x] = 0;
     stack.push_back(jump[x]);
     while (jump[x] < n && next[jump[x]] - x <= jump_small) {
       jump[x] = next[jump[x]];
       ++times[x];
       stack.push_back(jump[x]);
     }
     last[x] = stack.size();
     visit[x] = true;
     for (int i = x - 1; i >= x - jump_small && ~i; --i) {
       if (next[i] < n && visit[next[i]]) {
         while (stack.back() - i > jump_small) {
           stack.pop_back();
         }
         jump[i] = stack.back();
         times[i] = times[next[i]] + 1 + stack.size() - last[next[i]];
         last[i] = stack.size();
         visit[i] = true;
       }
     }
     for (int i = x; i >= x - jump_small && ~i; --i) {
       visit[i] = false;
     }
   };
   auto query = [&](int limit) {
     while (!heap.empty() && -heap.top().first <= limit) {
       int x = heap.top().second;
       heap.pop();
       update(x, limit);
     }
     int answer = -1, x = 0;
     while (x < n) {
       int dist = next[x] - x;
       if (dist <= jump_small) {
         answer += times[x];
         x = jump[x];
       } else {
         while (next[x] < n && next[x] - x <= jump_large &&
                now_max[x] - now_min[x] <= limit) {
           ++next[x];
           if (next[x] < n) {
             now_max[x] = max(now_max[x], a[next[x]]);
             now_min[x] = min(now_min[x], a[next[x]]);
           }
         }
         dist = next[x] - x;
         if (dist <= jump_large) {
           ++answer;
           x = next[x];
         } else {
           ++answer;
           int current_min = a[x], current_max = a[x];
           for (int i = log_n - 1; ~i; --i) {
             if (x + (1 << i) <= n) {
               int next_min = min(current_min, rmq_min[i][x]);
               int next_max = max(current_max, rmq_max[i][x]);
               if (next_max - next_min <= limit) {
                 current_min = next_min;
                 current_max = next_max;
                 x += 1 << i;
               }
             }
           }
         }
       }
     }
     return answer;
   };
   vector<pair<int, int>> queries(q);
   vector<int> answer(q);
   for (int i = 0; i < q; ++i) {
     scanf( %d , &queries[i].first);
     queries[i].first = m - queries[i].first;
     queries[i].second = i;
   }
   sort(queries.begin(), queries.end());
   for (auto p : queries) {
     answer[p.second] = query(p.first);
   }
   for (int i = 0; i < q; ++i) {
     printf( %d
 , answer[i]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long int n, i;
   cin >> n;
   long long int a[n];
   for (i = 0; i < n; i++) {
     cin >> a[i];
   }
   if (n == 1) {
     cout << a[0];
     return 0;
   }
   sort(a, a + n);
   long long int sum = 0;
   if (a[0] >= 0) {
     sum = -1 * a[0];
     for (i = 1; i < n; i++) {
       sum += a[i];
     }
   } else if (a[n - 1] < 0) {
     sum = a[n - 1];
     for (i = 0; i < n - 1; i++) {
       sum -= a[i];
     }
   } else {
     for (i = 0; i < n; i++) {
       if (a[i] < 0) {
         sum -= a[i];
       } else {
         sum += a[i];
       }
     }
   }
   cout << sum << endl;
   return 0;
 }