#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = 1e9 + 7;
 const int iinf = 1 << 29;
 const long long llinf = 1ll << 60;
 const double PI = 3.14159265;
 mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 long long mrand(long long B) { return (unsigned long long)rng() % B; }
 long long cross(pair<long long, long long> p1, pair<long long, long long> p2) {
   return p1.first * p2.second - p2.first * p1.second;
 }
 bool online(pair<long long, long long> a, pair<long long, long long> b,
             pair<long long, long long> c) {
   pair<long long, long long> p1{b.first - a.first, b.second - a.second};
   pair<long long, long long> p2{c.first - a.first, c.second - a.second};
   return cross(p1, p2) == 0;
 }
 void z_func(vector<int> &z, vector<int> &s, int n) {
   int L = 0, R = 0;
   for (int i = 1; i < n; i++) {
     if (i > R) {
       L = R = i;
       while (R < n && s[R - L] == s[R]) R++;
       z[i] = R - L;
       R--;
     } else {
       int k = i - L;
       if (z[k] < R - i + 1)
         z[i] = z[k];
       else {
         L = i;
         while (R < n && s[R - L] == s[R]) R++;
         z[i] = R - L;
         R--;
       }
     }
   }
 }
 const int MXN = 400;
 long long ans;
 int n, m;
 int v[MXN][MXN], up[MXN][MXN], down[MXN][MXN], leftt[MXN][MXN],
     rightt[MXN][MXN], ul[MXN][MXN], ur[MXN][MXN], lol[MXN][MXN], lr[MXN][MXN];
 void populate() {
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) {
       if (!v[i][j]) continue;
       if (i && v[i - 1][j]) up[i][j] = 1 + up[i - 1][j];
       if (j && v[i][j - 1]) leftt[i][j] = 1 + leftt[i][j - 1];
       if (i && j && v[i - 1][j - 1]) ul[i][j] = 1 + ul[i - 1][j - 1];
       if (i && j != m - 1 && v[i - 1][j + 1]) ur[i][j] = 1 + ur[i - 1][j + 1];
     }
   }
   for (int i = n - 1; i >= 0; --i) {
     for (int j = m - 1; j >= 0; --j) {
       if (!v[i][j]) continue;
       if (i != n - 1 && v[i + 1][j]) down[i][j] = 1 + down[i + 1][j];
       if (j != m - 1 && v[i][j + 1]) rightt[i][j] = 1 + rightt[i][j + 1];
       if (i != n - 1 && j != m - 1 && v[i + 1][j + 1])
         lr[i][j] = 1 + lr[i + 1][j + 1];
       if (i != n - 1 && j && v[i + 1][j - 1]) lol[i][j] = 1 + lol[i + 1][j - 1];
     }
   }
 }
 void do_lower_leftt(int x, int y) {
   for (int i = x + 1, j = y - 1; i < n && j >= 0 && v[i][j]; ++i, --j) {
     ans += down[x][y] >= 2 * (i - x) && lr[i][j] >= i - x;
     ans += down[x][y] >= i - x && rightt[i][j] >= y - j;
     ans += lr[x][y] >= i - x && rightt[i][j] >= 2 * (y - j);
   }
 }
 void do_down(int x, int y) {
   for (int i = x + 1; i < n && v[i][y]; ++i) {
     ans += lr[x][y] >= i - x && rightt[i][y] >= i - x;
     ans += rightt[x][y] >= i - x && ur[i][y] >= i - x;
     ans +=
         (i - x) % 2 == 0 && lr[x][y] >= (i - x) / 2 && ur[i][y] >= (i - x) / 2;
   }
 }
 void do_lower_rightt(int x, int y) {
   for (int i = x + 1, j = y + 1; i < n && j < m && v[i][j]; ++i, ++j) {
     ans += rightt[x][y] >= j - y && up[i][j] >= i - x;
     ans += rightt[x][y] >= 2 * (j - y) && ur[i][j] >= i - x;
   }
 }
 void work() {
   cin >> n >> m;
   for (int i = 0; i < n; ++i)
     for (int j = 0; j < m; ++j) {
       char c;
       cin >> c;
       while (c != '0' && c != '1') cin >> c;
       v[i][j] = c == '0' ? 1 : 0;
     }
   populate();
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) {
       if (!v[i][j]) continue;
       do_lower_leftt(i, j);
       do_down(i, j);
       do_lower_rightt(i, j);
     }
   }
   cout << ans << endl;
 }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   work();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n, i, x, sum = 0;
   long long int c[100009];
   scanf( %lld %lld , &n, &x);
   for (i = 0; i < n; i++) {
     scanf( %lld , &c[i]);
   }
   sort(c, c + n);
   for (i = 0; i < n; i++) {
     sum = sum + c[i] * x;
     x--;
     if (x == 0) x++;
   }
   printf( %lld
 , sum);
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long inf = 2147383647;
 const double pi = 2 * acos(0.0);
 const double eps = 1e-9;
 struct debugger {
   template <typename T>
   debugger& operator,(const T& v) {
     cerr << v <<    ;
     return *this;
   }
 } dbg;
 inline long long gcd(long long a, long long b) {
   a = ((a) < 0 ? -(a) : (a));
   b = ((b) < 0 ? -(b) : (b));
   while (b) {
     a = a % b;
     swap(a, b);
   }
   return a;
 }
 int ext_gcd(int a, int b, int& x, int& y) {
   if (a == 0) {
     x = 0;
     y = 1;
     return b;
   }
   int x1, y1;
   int d = ext_gcd(b % a, a, x1, y1);
   x = y1 - (b / a) * x1;
   y = x1;
   return d;
 }
 inline long long modInv(int a, int m) {
   int x, y;
   ext_gcd(a, m, x, y);
   if (x < 0) x += m;
   return x;
 }
 inline long long power(long long a, long long p) {
   long long res = 1, x = a;
   while (p) {
     if (p & 1) res = (res * x);
     x = (x * x);
     p >>= 1;
   }
   return res;
 }
 inline long long bigmod(long long a, long long p, long long m) {
   long long res = 1, x = a % m;
   while (p) {
     if (p & 1) res = (res * x) % m;
     x = (x * x) % m;
     p >>= 1;
   }
   return res;
 }
 bool ispalin(string s) {
   string s2 = s;
   reverse(s2.begin(), s2.end());
   if (s == s2)
     return true;
   else
     return false;
 }
 int main() {
   string s, t, x;
   cin >> s;
   int len = s.size();
   for (int i = (0); i <= (len); ++i) {
     for (int j = ('a'); j <= ('z'); ++j) {
       t = s;
       x = j;
       t.insert(i, x);
       if (ispalin(t)) {
         cout << t << endl;
         return 0;
       }
     }
   }
   cout <<  NA  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long t = 1;
 void solve() {
   long long n, x, y, cnt = 0, p = 1;
   cin >> n;
   vector<long long> arr(n + 1), vis(n + 1, 0);
   vector<vector<long long> > v(n + 1);
   for (long long i = 0; i < n - 1; i += 1) {
     cin >> x >> y;
     v[x].push_back(y);
     v[y].push_back(x);
   }
   queue<long long> q1, q;
   for (long long i = 0; i < n; i += 1) {
     cin >> x;
     arr[i] = x;
     q1.push(x);
   }
   q.push(1);
   q1.pop();
   while (!q.empty()) {
     x = q.front();
     vector<long long> vv;
     set<long long> s;
     cnt = 0;
     for (long long i = 0; i < int((v[x]).size()); i += 1) {
       if (vis[v[x][i]] == 0) {
         cnt++;
         vv.push_back(v[x][i]);
       }
     }
     vis[q.front()] = 1;
     q.pop();
     for (long long i = p; i < p + cnt; i += 1) {
       s.insert(arr[i]);
       q.push(arr[i]);
       vis[arr[i]] = 1;
     }
     for (long long i = 0; i < int((vv).size()); i += 1) {
       if (((s).find(vv[i]) != (s).end())) {
         s.erase(vv[i]);
       } else {
         cout <<  No ;
         return;
       }
     }
     p = p + cnt;
   }
   cout <<  Yes ;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   while (t--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 pair<int, int> point[100];
 double ang[100];
 double dp[10000000];
 int i, j, k, N, M, K, l, r;
 void clear() {}
 void init() {
   scanf( %d%d%d , &N, &l, &r);
   for (i = 0; i <= N - 1; i++) {
     int first;
     scanf( %d%d%d , &point[i].first, &point[i].second, &first);
     ang[i] = (first * 1.0) * 3.1415926535 / 180.0;
   }
 }
 double func(int a, int h, double ang, double st) {
   double alpha = atan(fabs(a - st) / h);
   if (a > st) {
     double beta = alpha - ang;
     if (beta > 0) {
       double q = h * tan(beta);
       return min(1.0 * r, a - q);
     } else {
       beta *= -1;
       return min(1.0 * r, a + h * tan(beta));
     }
   } else {
     if (alpha + ang > 3.1415926535 / 2) {
       return 1.0 * r;
     } else {
       double beta = alpha + ang;
       return min(1.0 * r, h * tan(beta) + a);
     }
   }
 }
 void calc() {
   for (i = 0; i <= (1 << N) - 1; i++) {
     dp[i] = l * 1.0;
   }
   for (i = 0; i <= (1 << N) - 1; i++) {
     for (j = 0; j <= N - 1; j++) {
       if (!(i & (1 << j)))
         dp[i | (1 << j)] =
             max(dp[i | (1 << j)],
                 func(point[j].first, point[j].second, ang[j], dp[i]));
     }
   }
   printf( %.8f
 , dp[(1 << N) - 1] - l);
 }
 int main() {
   clear();
   init();
   calc();
 }


#include <bits/stdc++.h>
 using namespace std;
 int vis[100005], n, m, x, y, mi, eg, re;
 char t;
 vector<vector<pair<int, int> > > adj;
 vector<vector<int> > re1;
 vector<int> t0, t1;
 void dfs(int u, int ty) {
   if (vis[u] == -1) {
     vis[u] = ty;
     if (ty == 0)
       t0.push_back(u);
     else
       t1.push_back(u);
     for (int j = 0; j < adj[u].size(); j++) {
       pair<int, int> te = adj[u][j];
       if (te.second == eg)
         dfs(te.first, ty);
       else
         dfs(te.first, 1 - ty);
     }
   } else if (vis[u] != ty) {
     mi = -1;
     return;
   }
 }
 int main() {
   cin >> n >> m;
   adj.assign(n + 1, vector<pair<int, int> >(0));
   re1.assign(2, vector<int>(0));
   for (int i = 0; i < m; i++) {
     cin >> x >> y >> t;
     adj[x].push_back(pair<int, int>(y, t == 'B'));
     adj[y].push_back(pair<int, int>(x, t == 'B'));
   }
   memset(vis, -1, sizeof(vis));
   mi = 0;
   eg = 1;
   for (int i = 1; i <= n; i++) {
     t0.clear();
     t1.clear();
     if (vis[i] == -1) dfs(i, 0);
     if (mi == -1) break;
     if (t0.size() < t1.size()) {
       mi += t0.size();
       for (int j = 0; j < t0.size(); j++) re1[0].push_back(t0[j]);
     } else {
       mi += t1.size();
       for (int j = 0; j < t1.size(); j++) re1[0].push_back(t1[j]);
     }
   }
   re = mi;
   memset(vis, -1, sizeof(vis));
   mi = 0;
   eg = 0;
   for (int i = 1; i <= n; i++) {
     t0.clear();
     t1.clear();
     if (vis[i] == -1) dfs(i, 0);
     if (mi == -1) break;
     if (t0.size() < t1.size()) {
       mi += t0.size();
       for (int j = 0; j < t0.size(); j++) re1[1].push_back(t0[j]);
     } else {
       mi += t1.size();
       for (int j = 0; j < t1.size(); j++) re1[1].push_back(t1[j]);
     }
   }
   if (mi == -1) {
     if (re == -1)
       cout << -1 << endl;
     else {
       cout << re << endl;
       for (int i = 0; i < re1[0].size(); i++) cout << re1[0][i] <<    ;
       cout << endl;
     }
   } else if (re == -1) {
     cout << mi << endl;
     for (int i = 0; i < re1[1].size(); i++) cout << re1[1][i] <<    ;
     cout << endl;
   } else {
     if (mi < re) {
       cout << mi << endl;
       for (int i = 0; i < re1[1].size(); i++) cout << re1[1][i] <<    ;
       cout << endl;
     } else {
       cout << re << endl;
       for (int i = 0; i < re1[0].size(); i++) cout << re1[0][i] <<    ;
       cout << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int hashCh = 31;
 struct HashCh {
   string code;
   int number;
 };
 long long getHash(string text) {
   long long hash = 0;
   int size = text.size();
   for (int i = 0; i < size; i++) {
     int ch = static_cast<int>(text[i]);
     hash += pow(hashCh, i) * ch;
   }
   return hash;
 }
 int main() {
   vector<string> password;
   map<long long, HashCh> numbers;
   char buf[80];
   string oneNumber;
   for (int i = 0; i < 80; i++) {
     char ch;
     cin >> ch;
     oneNumber += ch;
     if ((i % 10) == 9) {
       password.push_back(oneNumber);
       oneNumber =   ;
     }
   }
   for (int i = 0; i < 10; i++) {
     string number;
     cin >> number;
     HashCh ch = HashCh();
     ch.code = number;
     ch.number = i;
     long long hash = getHash(number);
     numbers[hash] = ch;
   }
   vector<int> result;
   for (int i = 0; i < 8; i++) {
     auto it = numbers.find(getHash(password[i]));
     if (it != numbers.end() && it->second.code == password[i]) {
       result.push_back(it->second.number);
     }
   }
   for (auto i = result.begin(); i != result.end(); i++) {
     cout << *i;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct fastIO {
   fastIO() { ios_base::sync_with_stdio(0); }
 };
 const int MAXN = 1e6 * 2;
 long long n, a[MAXN], x, ans = MAXN, b;
 int main() {
   fastIO();
   cin >> n;
   for (long long i = 0; i < n; i++) cin >> a[i];
   for (x = 0; x < n; x++) {
     b = 0;
     for (long long i = 0; i < n; i++) {
       b += (abs(x - i) + i + x) * a[i] * 2;
     }
     if (0) cerr << ans << endl;
     ans = min(ans, b);
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   while (t--) {
     int n, k, x;
     cin >> n >> k;
     char s;
     string str;
     int p = n / k, q = n % k;
     for (int i = 0; i < k; ++i) {
       x = i + 97;
       s = x;
       if (i == k - 1) p = p + q;
       for (int j = 0; j < p; ++j) str += s;
     }
     cout << str << endl;
   }
 }


#include<bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 const int maxn=405;
 const int P=998244353;
 ll dp[2][maxn][maxn][3][3],sum[maxn][maxn];
 int cur,las,n,c[26];
 void add(ll &dpp,ll add) {
 	add%=P;
 	while(add<0) add+=P;
 	dpp+=add;
 	while(dpp>=P) dpp-=P;
 }
 int main() {
 	scanf( %d ,&n);
 	for(int i=0;i<26;++i)
 		scanf( %d ,&c[i]);
 	dp[0][0][0][0][0]=1;
 	las=1;cur=0;
 	for(int i=1;i<=n;++i) {
 		swap(las,cur);
 		for(int j=0;j<=i;++j)
 			for(int k=0;k<=i;++k)
 				for(int l=0;l<3;++l)
 					for(int m=0;m<3;++m)
 						dp[cur][j][k][l][m]=0;
 		for(int j=0;j<=i;++j)
 			for(int k=0;k<=i;++k)
 				for(int l=0;l<3;++l)
 					for(int m=0;m<3;++m) {
 						if(!dp[las][j][k][l][m])continue;
 						add(dp[cur][j][k][m][0],1LL*dp[las][j][k][l][m]*((l||(i<=2))?24:23)%P);
 						if(l!=1) add(dp[cur][j+1][k][m][1],dp[las][j][k][l][m]);
 						if(l!=2) add(dp[cur][j][k+1][m][2],dp[las][j][k][l][m]);
 					}
 	}
 	for(int i=0;i<=n;++i)
 		for(int j=0;j<=n;++j)
 			for(int k=0;k<3;++k)
 				for(int kk=0;kk<3;++kk)
 					add(sum[i][j],dp[cur][i][j][k][kk]);
 	for(int i=n;i>=0;--i)
 		for(int j=n;j>=0;--j)
 			add(sum[i][j],sum[i+1][j]+sum[i][j+1]-sum[i+1][j+1]);
 	ll res=1;
 	for(int i=1;i<=n;++i)
 		res=res*((i<=2)?26:25)%P;
 	for(int i=0;i<26;++i)
 		add(res,-sum[c[i]+1][0]);
 	for(int i=0;i<26;++i)
 		for(int j=i+1;j<26;++j)
 			add(res,sum[c[i]+1][c[j]+1]);
 	res+=P;
 	res%=P;
 	printf( %lld
 ,res);
 }


#include <bits/stdc++.h>
 using namespace std;
 long long gcd(long long a, long long b) {
   a = abs(a), b = abs(b);
   if (a < b) swap(a, b);
   return b ? gcd(b, a % b) : a;
 }
 vector<vector<int> > adj;
 set<int> st;
 const int dx[] = {0, 0, -1, 1};
 const int dy[] = {-1, 1, 0, 0};
 long long n, ary[300000 + 5] = {4, 8, 15, 16, 23, 42}, dp[300000 + 5];
 int main(void) {
   ios::sync_with_stdio(false), cin.tie(NULL);
   cin >> n;
   for (int i = 0, j, x; i < n; ++i) {
     cin >> x;
     j = lower_bound(ary, ary + 6, x) - ary;
     if (j == 0)
       dp[0] += 1;
     else if (dp[j - 1]) {
       dp[j - 1] -= 1;
       dp[j] += 1;
     }
   }
   cout << n - dp[5] * 6;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> v[100001];
 int n, cost[100001];
 int gr, nod, gr2;
 void DFS(int x, int t, int val) {
   for (int i = 1; i <= v[x][0]; i++) {
     if (v[x][i] != t) {
       if (val == 0) {
         DFS(v[x][i], x, cost[v[x][i]]);
       } else {
         if (val != cost[v[x][i]]) {
           gr++;
           if (nod != x) gr2++;
           nod = x;
         }
         DFS(v[x][i], x, cost[v[x][i]]);
       }
     }
   }
 }
 int main() {
   int a, b, i, j;
   cin >> n;
   for (i = 1; i <= n; i++) {
     v[i].push_back(0);
   }
   for (i = 1; i < n; i++) {
     cin >> a >> b;
     v[a][0]++;
     v[b][0]++;
     v[a].push_back(b);
     v[b].push_back(a);
   }
   for (i = 1; i <= n; i++) cin >> cost[i];
   DFS(1, 0, 0);
   if (gr2 <= 2) {
     if (gr == 0) {
       cout <<  YES
            <<

            << 1;
     } else {
       gr = 0;
       DFS(nod, 0, 0);
       if (gr != 0) {
         cout <<  NO ;
       } else {
         cout <<  YES ;
         cout <<
  << nod;
       }
     }
   } else {
     cout <<  NO ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int Ans[1001], A[1001], B[1001], C[1001], D[1001], E[1001];
 int value(int Arr[], int i, int j, int k) {
   return (Arr[j] - Arr[i]) * (Arr[k] - Arr[i]);
 }
 int main() {
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];
   }
   int index = 0;
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       if (j != i) {
         for (int k = 0; k < n; k++) {
           if (k != i && k != j) {
             if ((value(A, i, j, k) + value(B, i, j, k) + value(C, i, j, k) +
                  value(D, i, j, k) + value(E, i, j, k)) > 0) {
               Ans[i] = -1;
               break;
             }
           }
         }
       }
     }
   }
   int count = 0;
   for (int i = 0; i < n; i++) {
     if (Ans[i] != -1) {
       count++;
     }
   }
   cout << count << endl;
   for (int i = 0; i < n; i++) {
     if (Ans[i] != -1) {
       cout << i + 1 << endl;
       count++;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   int T;
   cin >> T;
   while (T--) {
     int N;
     cin >> N;
     vector<int> a(N);
     ;
     for (int& x : a) cin >> x;
     int ans = (a[0] == 1);
     for (int i = 1; i < N; ++i) {
       if (a[i] == 0) continue;
       int j = i;
       while (j < N && a[j] == 1) ++j;
       ans += (j - i) / 3;
       i = j - 1;
     }
     cout << ans << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 using Vi = vector<int>;
 using Pii = pair<int, int>;
 int uplg(int n) { return 32 - __builtin_clz(n); }
 int uplg(ll n) { return 64 - __builtin_clzll(n); }
 void run();
 int main() {
   cin.sync_with_stdio(0);
   cin.tie(0);
   cout << fixed << setprecision(12);
   run();
   cout << flush;
   _Exit(0);
 }
 ll ch2(ll n) { return n * (n - 1) / 2; }
 ll ch3(ll n) { return n * (n - 1) * (n - 2) / 6; }
 void run() {
   int n;
   double p;
   cin >> n >> p;
   constexpr ll SCALE = 10000;
   ll pScaled = llround(p * SCALE);
   ll low = pScaled * ch3(n) * 2;
   for (int a = (0); a < (n + 1); a++) {
     ll cur = (ch3(a) * 2 + ch2(a) * (n - a) * 2 + a * ch2(n - a)) * SCALE;
     if (cur >= low) {
       cout << a << '
';
       return;
     }
   }
   assert(0);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string q[41];
   long long n, p, i, count = 1, check = 1;
   cin >> n >> p;
   for (i = 0; i < n; i++) cin >> q[i];
   for (i = n - 2; i >= 0; i--) {
     if (q[i] ==  halfplus ) {
       count = count * 2 + 1;
       check++;
     } else
       count = count * 2;
   }
   cout << p * count - (p / 2) * check << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve();
 const int N = 10000005;
 long long i, j, n, s;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t = 1;
   while (t--) {
     solve();
     cout <<
 ;
   }
   return 0;
 }
 void solve() {
   cin >> n;
   for (i = 1; i <= n; i = i * 10) {
     s += n - i + 1;
   }
   cout << s;
 }


#include <bits/stdc++.h>
 using namespace std;
 int par[100005], val[100005];
 int lefm[100005], rim[100005];
 int root = 0;
 vector<vector<int> > adjl;
 int n;
 void pre(int node) {
   if (adjl[node].size() == 0) {
     lefm[node] = val[node];
     rim[node] = val[node];
     return;
   }
   for (int i = (0); i < (adjl[node].size()); ++i) {
     pre(adjl[node][i]);
     if (val[adjl[node][i]] < val[node])
       lefm[node] = lefm[adjl[node][i]];
     else
       rim[node] = rim[adjl[node][i]];
   }
 }
 double res[100005];
 pair<int, int> qu[100005];
 void query(int node, int left, int right, long long cost, int dep) {
   if (adjl[node].size() == 0) {
     for (int i = (left); i < (right); ++i) res[qu[i].second] += cost * 1. / dep;
     return;
   }
   int ind = lower_bound(qu + left, qu + right, make_pair(val[node], 0)) - qu;
   if (ind > left && adjl[node].size() == 2)
     query(adjl[node][0], left, ind, cost + lefm[adjl[node][1]], dep + 1);
   if (ind < right && adjl[node].size() == 2)
     query(adjl[node][1], ind, right, cost + rim[adjl[node][0]], dep + 1);
 }
 int main() {
   int x, y, k;
   scanf( %d , &n);
   adjl.clear();
   adjl.resize(n);
   for (int i = (0); i < (n); ++i) {
     scanf( %d %d , &x, &y);
     x--;
     val[i] = y;
     par[i] = x;
     if (x >= 0) adjl[x].push_back(i);
     if (x < 0) root = i;
   }
   for (int i = (0); i < (adjl.size()); ++i) {
     if (adjl[i].size() == 2)
       if (val[adjl[i][0]] > val[adjl[i][1]]) swap(adjl[i][0], adjl[i][1]);
     if (adjl[i].size() == 1) throw 2;
   }
   pre(root);
   scanf( %d , &k);
   for (int i = (0); i < (k); ++i) scanf( %d , &qu[i].first), qu[i].second = i;
   sort(qu, qu + k);
   query(root, 0, k, 0, 0);
   for (int i = (0); i < (k); ++i) printf( %.12lf
 , res[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long double judge1(long long k, long long d, long long t) {
   long double ans;
   long double unit = k + (d - k) * 1.0 / 2;
   ans = floor(t / unit) * d;
   long double res = t * 1.0 - floor(t / unit) * unit;
   if (res <= k) {
     ans += res;
     return ans;
   } else {
     ans += k;
     res -= k;
   }
   ans += (res * 2);
   return ans;
 }
 long double judge2(long long k, long long d, long long t) {
   long double ans;
   ans = t;
   return ans;
 }
 long double judge3(long long k, long long d, long long t) {
   long double ans;
   long double unitt = (k / d + 1) * d * 1.0;
   long double unitw = k + (unitt - k) / 2.0;
   ans += floor(t / unitw) * unitt;
   long double res = t - floor(t / unitw) * unitw;
   if (fabs(res - k) <= 1e-9 || res < k) {
     ans += res;
     return ans;
   } else {
     ans += k;
     res -= k;
   }
   ans += (res * 2.0);
   return ans;
 }
 int main() {
   ios::sync_with_stdio(false);
   long long k, d, t;
   while (cin >> k >> d >> t) {
     long double ans;
     if (k < d)
       ans = judge1(k, d, t);
     else if (k % d == 0)
       ans = judge2(k, d, t);
     else
       ans = judge3(k, d, t);
     cout << fixed << setprecision(1) << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 310;
 int n, a[maxn];
 int main() {
   scanf( %d , &n);
   for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);
   for (int i = (1); i <= (n - 1); ++i) {
     for (int j = (1); j <= (a[i]); ++j) printf( PRL );
     printf( R );
   }
   for (int j = (1); j <= (a[n]); ++j) printf( LRP );
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, h, ok;
 long long cal(long long dep, long long pos, int tag) {
   if (ok) return 0;
   if (dep == 0) {
     ok = 1;
     return 0;
   }
   long long tmp;
   if (!tag) {
     if (pos > (1LL << (dep - 1)))
       tmp = (1LL << dep) + cal(dep - 1, pos - (1LL << (dep - 1)), 0);
     else
       tmp = 1LL + cal(dep - 1, pos, 1);
   } else {
     if (pos > (1LL << (dep - 1)))
       tmp = 1LL + cal(dep - 1, pos - (1LL << (dep - 1)), 0);
     else
       tmp = (1LL << dep) + cal(dep - 1, pos, 1);
   }
   return tmp;
 }
 int main() {
   while (cin >> h >> n) {
     ok = 0;
     cout << cal(h, n, 0) << endl;
   }
 }


#include <bits/stdc++.h>
 long long a[100][100];
 using namespace std;
 struct DynamicDisjointSetDS {
   std::unordered_map<int, int> parent, degree;
   int N;
   DynamicDisjointSetDS(int n) { N = n; }
   int getParent(int vertex) {
     if (parent.find(vertex) != parent.end()) {
       if (parent[vertex] != vertex) {
         parent[vertex] = getParent(parent[vertex]);
         return parent[vertex];
       }
     } else {
       parent.insert(make_pair(vertex, vertex));
       degree.insert(make_pair(vertex, 1));
     }
     return vertex;
   }
   void Union(int vertexA, int vertexB) {
     int x = getParent(vertexA);
     int y = getParent(vertexB);
     if (x == y) return;
     if (degree[x] > degree[y]) {
       parent[y] = x;
       degree[x] = degree[x] + degree[y];
     } else {
       parent[x] = y;
       degree[y] = degree[y] + degree[x];
     }
   }
   int GetTotalComponent() {
     unordered_set<int> total;
     for (auto itr = parent.begin(); itr != parent.end(); itr++) {
       total.insert(getParent(itr->first));
     }
     return N - parent.size() + total.size();
   }
 };
 int main() {
   using namespace std;
   long long n, m, q;
   cin >> n >> m >> q;
   unordered_set<long long> s, s2;
   for (long long i = 1; i <= n; i++) {
     s.insert(i);
   }
   for (long long i = 1; i <= m; i++) {
     s2.insert(i);
   }
   DynamicDisjointSetDS ds(m + 1);
   vector<vector<long long>> v(m + 1);
   while (q--) {
     long long r, c;
     cin >> r >> c;
     v[c].push_back(r);
     s.erase(r);
     s2.erase(c);
   }
   for (vector<long long> v2 : v) {
     for (long long i = 1; i < v2.size(); i++) {
       ds.Union(v2[i], v2[i - 1]);
     }
   }
   unordered_set<long long> sc;
   for (long long i = 1; i <= n; i++) {
     sc.insert(ds.getParent(i));
   }
   cout << (s2.size() + sc.size() - 1) << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int read() {
   int f = 1, x = 0;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') f = -f;
     c = getchar();
   }
   while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
   return f * x;
 }
 inline int lowbit(int x) { return x & (-x); }
 inline int modadd(int x, int y) {
   return (x + y >= 1000000007 ? x + y - 1000000007 : x + y);
 }
 inline int sgn(int x) { return (x < 0 ? -1 : (x > 0 ? 1 : 0)); }
 template <typename T>
 T gcd(T a, T b) {
   return (!b) ? a : gcd(b, a % b);
 }
 int poww(int a, int b) {
   int res = 1;
   while (b > 0) {
     if (b & 1) res = 1ll * res * a % 1000000007;
     a = 1ll * a * a % 1000000007, b >>= 1;
   }
   return res;
 }
 const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
 const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1},
           ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
 int n, a[100005];
 void init() {
   n = read();
   for (int i = 1; i <= n; ++i) a[i] = read();
 }
 bool check1() {
   long long tot = 0;
   for (int i = n - 1; i >= 1; --i) {
     if (a[i] < tot) return false;
     if (a[i] > a[i + 1]) tot += a[i] - a[i + 1];
   }
   return true;
 }
 bool check2() {
   long long tot = 0;
   for (int i = 2; i <= n; ++i) {
     if (a[i] < tot) return false;
     if (a[i] > a[i - 1]) tot += a[i] - a[i - 1];
   }
   return true;
 }
 void solve() {
   if (check1())
     printf( YES
 );
   else if (check2())
     printf( YES
 );
   else
     printf( NO
 );
 }
 int main() {
   int T = read();
   while (T--) {
     init();
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct grp {
   long long to, wt, edgeCode;
   char type;
 };
 struct Node {
   long long x, dis;
 };
 struct comp {
   inline bool operator()(const Node& n1, const Node& n2) const {
     if (n1.dis != n2.dis) return n1.dis < n2.dis;
     return n1.x < n2.x;
   }
 };
 void dijkstra(long long n, vector<vector<grp> >& edges, vector<long long>& dis,
               vector<bool>& visited, vector<pair<long long, long long> >& par) {
   set<Node, comp> myset;
   for (long long i = 1; i <= n; ++i) {
     Node node;
     node.x = i, node.dis = dis[i];
     myset.insert(node);
   }
   while (myset.size()) {
     set<Node>::iterator it = myset.begin();
     Node node = *it;
     myset.erase(it);
     visited[node.x] = true;
     for (long long i = 0; i < edges[node.x].size(); ++i) {
       grp& edge = edges[node.x][i];
       if (visited[edge.to]) {
         continue;
       }
       long long newDis = dis[node.x] + edge.wt;
       if (newDis < dis[edge.to] ||
           (newDis == dis[edge.to] && edge.type == 'r')) {
         Node prevNode, newNode;
         prevNode.x = edge.to, prevNode.dis = dis[edge.to];
         newNode.x = edge.to, newNode.dis = newDis;
         dis[edge.to] = newDis;
         par[edge.to] = {node.x, edge.edgeCode};
         myset.erase(myset.find(prevNode));
         myset.insert(newNode);
       }
     }
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   long long n, m, k;
   cin >> n >> m >> k;
   vector<vector<grp> > edges(n + 1);
   long long edgeCode = 0;
   for (long long i = 0; i < m; i++) {
     long long x, y, w;
     cin >> x >> y >> w;
     grp g;
     g.to = y, g.wt = w, g.type = 'r', g.edgeCode = edgeCode++;
     edges[x].push_back(g);
     g.to = x, g.edgeCode = edgeCode++;
     edges[y].push_back(g);
   }
   vector<pair<long long, long long> > trainPaths(k);
   for (long long i = 0; i < k; ++i) {
     long long y, w;
     cin >> y >> w;
     trainPaths[i] = {y, edgeCode};
     grp g;
     g.to = y, g.wt = w, g.type = 't', g.edgeCode = edgeCode++;
     edges[1].push_back(g);
   }
   vector<long long> dis(n + 1, 100000000000000000);
   vector<bool> visited(n + 1, false);
   vector<pair<long long, long long> > par(n + 1, {-1, -1});
   dis[1] = 0;
   dijkstra(n, edges, dis, visited, par);
   long long ans = 0;
   for (long long i = 0; i < k; ++i) {
     long long dest = trainPaths[i].first, edgeCode = trainPaths[i].second;
     if (par[dest].first == 1 && par[dest].second == edgeCode) {
       continue;
     }
     ++ans;
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 long long int power(long long int x, long long int b) {
   long long int p = 1;
   while (b > 0) {
     if (b & 1) {
       p = p * x;
       p %= 1000000007;
     }
     b >>= 1;
     x *= x;
     x %= 1000000007;
   }
   return p % 1000000007;
 }
 using namespace std;
 struct lex_compare {
   bool operator()(
       const pair<long long int, pair<long long int, long long int> > p1,
       const pair<long long int, pair<long long int, long long int> > p2) {
     return (p1.first == p2.first) ? p1.second.first < p2.second.first
                                   : p1.first > p2.first;
   }
 };
 long long int n, m, b, mo;
 long long int dp[2][500 + 1][500 + 1];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ;
   long long int w, m;
   cin >> w >> m;
   bool f = 1;
   map<long long int, long long int> coeff;
   long long int term = 1;
   while (m >= term && term <= 10000000000) {
     long long int x = (term * (m / term) - (w * term) * (m / (w * term)));
     x /= term;
     if (x <= 1) {
       term *= w;
     } else {
       if (x != (w - 1)) {
         f = 0;
         break;
       } else {
         m += (w * term - term);
       }
       term *= w;
     }
   }
   if (f)
     cout <<  YES
          <<
 ;
   else
     cout <<  NO
          <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> di[100003];
 struct trie {
   trie *zero, *one;
   int val;
   trie() {
     zero = one = NULL;
     val = 100003;
   }
 } * root[100003];
 void add(trie *cur, int a) {
   int i, ck;
   for (i = 20; i >= 0; i--) {
     ck = (1 << i & a);
     if (ck == 0) {
       cur->val = min(cur->val, a);
       if (cur->zero == NULL) cur->zero = new trie();
       cur = cur->zero;
       cur->val = min(cur->val, a);
     } else {
       cur->val = min(cur->val, a);
       if (cur->one == NULL) cur->one = new trie();
       cur = cur->one;
       cur->val = min(cur->val, a);
     }
   }
 }
 int query(trie *cur, int a, int lim) {
   int i, ck, ans;
   for (i = 20; i >= 0; i--) {
     ck = (1 << i & a);
     if (ck == 0) {
       if (cur->one != NULL && cur->one->val + a <= lim)
         cur = cur->one;
       else if (cur->zero != NULL)
         cur = cur->zero;
       ans = cur->val;
     } else {
       if (cur->zero != NULL && cur->zero->val + a <= lim)
         cur = cur->zero;
       else if (cur->one != NULL)
         cur = cur->one;
       ans = cur->val;
     }
   }
   return ans;
 }
 void pre() {
   for (int i = 1; i < 100003; i++) {
     for (int j = i; j < 100003; j += i) di[j].push_back(i);
     root[i] = new trie();
   }
 }
 int main() {
   pre();
   int q, a, k, s, v, ty;
   scanf( %d , &q);
   while (q--) {
     scanf( %d , &ty);
     if (ty == 1) {
       scanf( %d , &a);
       for (int x : di[a]) {
         add(root[x], a);
       }
     } else {
       scanf( %d %d %d , &v, &k, &s);
       if (root[k]->val + v > s || root[k]->val == 0 || v % k)
         printf( -1
 );
       else
         printf( %d
 , query(root[k], v, s));
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool isPrime(int n) {
   if (n <= 1) return false;
   for (int i = 2; i < n; i++)
     if (n % i == 0) return false;
   return true;
 }
 int main() {
   long long int t;
   cin >> t;
   while (t--) {
     long long int n;
     cin >> n;
     vector<long long int> v;
     for (long long int i = 0; i < n; i++) {
       long long int x;
       cin >> x;
       v.push_back(x);
     }
     if (v[0] + v[1] <= v[n - 1]) {
       cout << 1 <<     << 2 <<     << n <<
 ;
     } else {
       cout << -1 <<
 ;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char bb[111][111];
 int in[111][111];
 int main() {
   int n, m;
   cin >> n >> m;
   for (int i = 0; i < n; i++) scanf( %s , bb[i]);
   vector<pair<pair<int, int>, int>> stars;
   for (int i = 1; i < n - 1; i++) {
     for (int j = 1; j < m - 1; j++) {
       if (bb[i][j] != '*') continue;
       int l, r, u, d;
       l = r = i;
       u = d = j;
       for (int k = i; k < n; k++)
         if (bb[k][j] == '*')
           r = k;
         else
           break;
       for (int k = i; k >= 0; k--)
         if (bb[k][j] == '*')
           l = k;
         else
           break;
       for (int k = j; k < m; k++)
         if (bb[i][k] == '*')
           d = k;
         else
           break;
       for (int k = j; k >= 0; k--)
         if (bb[i][k] == '*')
           u = k;
         else
           break;
       int starLevel = min(min(r - i, i - l), min(d - j, j - u));
       if (starLevel) {
         for (int k = i - starLevel; k <= i + starLevel; k++) in[k][j] = 1;
         for (int k = j - starLevel; k <= j + starLevel; k++) in[i][k] = 1;
         stars.push_back({{i + 1, j + 1}, starLevel});
       }
     }
   }
   for (int i = 0; i < n; i++)
     for (int j = 0; j < m; j++)
       if ((bb[i][j] == '*' && in[i][j] == 0) ||
           (in[i][j] == 1 && bb[i][j] == '.'))
         return puts( -1 );
   cout << stars.size() << endl;
   for (auto u : stars) {
     printf( %d %d %d
 , u.first.first, u.first.second, u.second);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 500;
 const int LN = 21;
 const long long mod = 1e9 + 7;
 const long long INF = 1LL << 57;
 long long n, m, u, v, k, t, q, a, x, d;
 int tree[4 * N];
 int sum[4 * N];
 int lim = 1e6 + 2;
 int arr[N], brr[N];
 bool print = false;
 void modify(int i, int l, int r, int index, int val) {
   if (l == r) {
     tree[i] += val;
     sum[i] = tree[i];
     return;
   }
   int mid = (l + r) / 2;
   if (index <= mid)
     modify(i + 1 + i, l, mid, index, val);
   else
     modify(i + 2 + i, mid + 1, r, index, val);
   tree[i] = max(tree[i + 2 + i], tree[i + 1 + i] + sum[i + 2 + i]);
   sum[i] = sum[i + 1 + i] + sum[i + 2 + i];
 }
 int find(int i, int l, int r, int sumx) {
   if (l == r) return l;
   int mid = (l + r) / 2;
   if (tree[i + 2 + i] + sumx > 0) {
     return find(i + 2 + i, mid + 1, r, sumx);
   } else
     return find(i + 1 + i, l, mid, sumx + sum[i + 2 + i]);
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> n >> m;
   for (int i = 1; i <= n; ++i) {
     cin >> arr[i];
   }
   for (int i = 1; i <= m; ++i) cin >> brr[i];
   for (int i = 1; i <= n; ++i) {
     modify(0, 0, lim, arr[i], 1);
   }
   for (int i = 1; i <= m; ++i) {
     modify(0, 0, lim, brr[i], -1);
   }
   cin >> q;
   while (q--) {
     int type;
     cin >> type;
     if (type == 1) {
       int i, x;
       cin >> i >> x;
       modify(0, 0, lim, arr[i], -1);
       modify(0, 0, lim, x, 1);
       arr[i] = x;
       int price = find(0, 0, lim, 0);
       if (price == 0)
         cout << -1 << '
';
       else
         cout << price << '
';
     } else {
       int i, x;
       cin >> i >> x;
       modify(0, 0, lim, brr[i], 1);
       modify(0, 0, lim, x, -1);
       brr[i] = x;
       int price = find(0, 0, lim, 0);
       if (price == 0)
         cout << -1 << '
';
       else
         cout << price << '
';
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 void read(T &a) {
   T x = 0, f = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (ch >= '0' && ch <= '9') {
     x = (x << 1) + (x << 3) + (ch ^ 48);
     ch = getchar();
   }
   a = x * f;
 }
 template <typename T, typename... Args>
 void read(T &t, Args &...args) {
   read(t);
   read(args...);
 }
 long long n, k, a[100005];
 struct node {
   long long len, k;
   bool operator<(const node &x) const {
     long long tmp1 = (len / k) * (len / k) * (k - len % k) +
                      (len / k + 1) * (len / k + 1) * (len % k);
     long long tmp2 = (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) +
                      (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k);
     long long kk = k + 1;
     long long tmpp1 = (len / kk) * (len / kk) * (kk - len % kk) +
                       (len / kk + 1) * (len / kk + 1) * (len % kk);
     kk = x.k + 1;
     long long tmpp2 = (x.len / kk) * (x.len / kk) * (kk - x.len % kk) +
                       (x.len / kk + 1) * (x.len / kk + 1) * (x.len % kk);
     tmp1 -= tmpp1;
     tmp2 -= tmpp2;
     if (k == len) tmp1 = 0;
     if (x.k == x.len) tmp2 = 0;
     return tmp1 < tmp2;
   }
 };
 priority_queue<node> q;
 void update(long long &ans, node &x) {
   ans -= (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) +
          (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k);
   x.k++;
   ans += (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) +
          (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k);
 }
 signed main() {
   read(n, k);
   long long ans = 0;
   for (long long i = 1; i <= n; i++) {
     read(a[i]);
     node tmp;
     tmp.len = a[i];
     tmp.k = 1;
     q.push(tmp);
   }
   for (long long i = 1; i <= n; i++) ans += a[i] * a[i];
   k -= n;
   while (k) {
     k += 19260817;
     node x = q.top();
     q.pop();
     update(ans, x);
     q.push(x);
     k -= 19260818;
   }
   printf( %lld
 , ans + 'O' - 'O');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, l, v1, v2, k;
 long double dn, dl, dv1, dv2, dk;
 long long times;
 long double x;
 double T;
 int main() {
   scanf( %lld%lld%lld%lld%lld , &n, &l, &v1, &v2, &k);
   dn = n;
   dl = l;
   dv1 = v1;
   dv2 = v2;
   dk = k;
   times = (n - 1) / k + 1;
   x = l / (v2 * times - (dv2 - dv1) / (dv2 + dv1) * dv2 * (times - 1));
   T = x * (times + (dv2 - dv1) / (dv2 + dv1) * (times - 1));
   printf( %lf
 , T);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int const N = 3e5;
 int n, p1[N], p2[N], p3[N], num1[N], num2[N], F[N][2], T[N * 4];
 void buildT(int v, int tl, int tr) {
   if (tl == tr) {
     T[v] = 1;
   } else {
     int tm = (tl + tr) / 2;
     buildT(v * 2, tl, tm);
     buildT(v * 2 + 1, tm + 1, tr);
     T[v] = T[v * 2] + T[v * 2 + 1];
   }
 }
 void updT(int v, int tl, int tr, int p) {
   if (tl == tr) {
     T[v] = 0;
   } else {
     int tm = (tl + tr) / 2;
     if (tm >= p)
       updT(v * 2, tl, tm, p);
     else
       updT(v * 2 + 1, tm + 1, tr, p);
     T[v] = T[v * 2] + T[v * 2 + 1];
   }
 }
 int getT(int v, int tl, int tr, int k) {
   if (tl == tr) {
     return tl;
   } else {
     int tm = (tl + tr) / 2;
     if (T[v * 2] >= k)
       return getT(v * 2, tl, tm, k);
     else
       return getT(v * 2 + 1, tm + 1, tr, k - T[v * 2]);
   }
 }
 void upd(int x, int t) {
   while (x < n) {
     ++F[x][t];
     x |= (x + 1);
   }
 }
 int get(int x, int t) {
   int r = 0;
   while (x >= 0) {
     r += F[x][t];
     x = (x & (x + 1)) - 1;
   }
   return r;
 }
 int main() {
   scanf( %d , &n);
   for (int i = 0; i < n; ++i) scanf( %d , &p1[i]);
   for (int i = 0; i < n; ++i) scanf( %d , &p2[i]);
   for (int i = 0; i < n; ++i) {
     num1[i] = p1[i] - get(p1[i], 0);
     upd(p1[i] + 1, 0);
     num2[i] = p2[i] - get(p2[i], 1);
     upd(p2[i] + 1, 1);
   }
   for (int i = n - 1; i >= 0; --i) {
     num1[i] += num2[i];
     if (i) num1[i - 1] += num1[i] / (n - i);
     num1[i] %= (n - i);
   }
   buildT(1, 0, n - 1);
   for (int i = 0; i < n; ++i) {
     int need = num1[i] + 1;
     int val = getT(1, 0, n - 1, need);
     p3[i] = val;
     updT(1, 0, n - 1, val);
   }
   for (int i = 0; i < n; ++i) printf( %d  , p3[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<long long> v;
 long long x, y, z, a, b, c, sum, ans, total, t, cnt, n, m, k, p, kase;
 string s1, s2;
 map<long long, long long> mp;
 set<long long> s;
 map<long long, long long>::iterator itr1, ptr1;
 set<long long>::iterator itr, ptr;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   cin >> t;
   while (t--) {
     long long x1, x2, y1, y2;
     cin >> x1 >> y1 >> x2 >> y2;
     ans = abs(x1 - x2);
     ans *= abs(y1 - y2);
     cout << ans + 1 << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 3e5 + 10;
 long long n, sum, n1, pick, ans, t, a[N], b[N], f[N], f1[N], m, t1;
 int main() {
   scanf( %lld , &n);
   for (int i = 1; i <= 8; i++) {
     scanf( %lld , &a[i]);
     sum = sum + a[i] * i;
   }
   if (sum <= n) return printf( %lld
 , sum), 0;
   n1 = std::max((long long)0, n - 840), n = n - n1;
   for (int i = 1; i <= 8; i++) {
     if (a[i] < n1 / i)
       pick = a[i];
     else
       pick = n1 / i;
     if (a[i] - pick < 10) pick = std::max((long long)0, a[i] - 10);
     ans = ans + pick * i, n1 = n1 - pick * i, a[i] = a[i] - pick;
   }
   n += n1;
   for (int i = 1; i <= 8; i++) {
     t = 1;
     while (a[i] > 0) {
       t1 = std::min(t, a[i]);
       a[i] = a[i] - t1;
       f[++m] = t1 * i;
       t <<= 1;
     }
   }
   for (long long i = 1; i <= m; i++)
     for (long long j = n; j >= f[i]; j--)
       f1[j] = std::max(f1[j], f1[j - f[i]] + f[i]);
   printf( %lld
 , ans + f1[n]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string st[5050];
 int fr[27];
 int main() {
   memset(fr, 0, sizeof(fr));
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n, k;
   cin >> k >> n;
   for (int i = 0; i < k; i++) {
     cin >> st[i];
   }
   string res = st[0];
   memset(fr, 0, sizeof(fr));
   bool du = false;
   for (int i = 0; i < n; i++) {
     fr[res[i] - 'a']++;
     if (fr[res[i] - 'a'] > 1) {
       du = true;
     }
   }
   int ma = 0;
   int mi = 0;
   bool po = true;
   for (int i = 1; i < k; i++) {
     int df = 0;
     int ct[27] = {0};
     for (int j = 0; j < n; j++) {
       ct[st[i][j] - 'a']++;
       if (st[i][j] != res[j]) {
         df++;
       }
     }
     if (df > 4) {
       po = false;
       break;
     }
     for (int j = 0; j < 27; j++) {
       if (ct[j] != fr[j]) {
         po = false;
         break;
       }
     }
     if (df > ma) {
       ma = df;
       mi = i;
     }
   }
   if (!po) {
     cout << -1 << '
';
     return 0;
   }
   if (ma == 0) {
     swap(res[0], res[1]);
     cout << res << '
';
     return 0;
   }
   if (ma == 2) {
     if (!du) {
       cout << -1 << '
';
       return 0;
       cout << -1 << '
';
       return 0;
     }
     cout << res << '
';
     return 0;
   }
   int q[4];
   int ctr = 0;
   for (int i = 0; i < n; i++) {
     if (res[i] != st[mi][i]) {
       q[ctr++] = i;
     }
   }
   po = false;
   int tr[2] = {0, 0};
   for (int id = 0; id < 3; id++) {
     if (ma < 4) {
       q[3] = q[id];
     } else if (id > 0)
       break;
     for (int i = 0; i < 4; i++) {
       for (int j = 0; j < 4; j++) {
         if (po) break;
         int md = 0;
         swap(res[q[i]], res[q[j]]);
         for (int c = 1; c < k; c++) {
           int df = 0;
           for (int l = 0; l < n; l++) {
             if (res[l] != st[c][l]) {
               df++;
             }
           }
           md = max(md, df);
         }
         swap(res[q[i]], res[q[j]]);
         if (md == 2) {
           po = true;
           tr[0] = i;
           tr[1] = j;
         }
       }
     }
   }
   if (po) {
     swap(res[q[tr[0]]], res[q[tr[1]]]);
     cout << res << '
';
   } else {
     cout << -1 << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 string multiply(string num1, string num2) {
   int len1 = num1.size();
   int len2 = num2.size();
   if (len1 == 0 || len2 == 0) return  0 ;
   vector<int> result(len1 + len2, 0);
   int i_n1 = 0;
   int i_n2 = 0;
   for (int i = len1 - 1; i >= 0; i--) {
     int carry = 0;
     int n1 = num1[i] - '0';
     i_n2 = 0;
     for (int j = len2 - 1; j >= 0; j--) {
       int n2 = num2[j] - '0';
       int sum = n1 * n2 + result[i_n1 + i_n2] + carry;
       carry = sum / 10;
       result[i_n1 + i_n2] = sum % 10;
       i_n2++;
     }
     if (carry > 0) result[i_n1 + i_n2] += carry;
     i_n1++;
   }
   int i = result.size() - 1;
   while (i >= 0 && result[i] == 0) i--;
   if (i == -1) return  0 ;
   string s =   ;
   while (i >= 0) s += std::to_string(result[i--]);
   return s;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int T;
   cin >> T;
   while (T--) {
     long int n;
     cin >> n;
     n = n / 2;
     string n1, n2, n3, ans1, ans;
     int temp;
     if (n % 3 == 0) {
       temp = 4 * n / 3;
       n1 = to_string(temp);
       n2 = to_string(n + 1);
       n3 = to_string(2 * n + 1);
       ans1 = multiply(n1, n2);
       ans = multiply(ans1, n3);
     } else if (n % 3 == 2) {
       temp = 4 * (n + 1) / 3;
       n1 = to_string(temp);
       n2 = to_string(n);
       n3 = to_string(2 * n + 1);
       ans1 = multiply(n1, n2);
       ans = multiply(ans1, n3);
     } else {
       temp = 4 * (2 * n + 1) / 3;
       n1 = to_string(temp);
       n2 = to_string(n + 1);
       n3 = to_string(n);
       ans1 = multiply(n1, n2);
       ans = multiply(ans1, n3);
     }
     cout << ans << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100010;
 int n, x[N], y[N], xs[N], ys[N], cnt[2][2];
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( %d%d , &x[i], &y[i]);
     xs[i] = x[i], ys[i] = y[i];
   }
   sort(xs + 1, xs + n + 1);
   sort(ys + 1, ys + n + 1);
   int m = (n + 1) / 2;
   int cx = xs[m], cy = ys[m];
   int dx = xs[m + 1] - xs[m], dy = ys[m + 1] - ys[m];
   if (n & 1) {
     dx = min(dx, xs[m] - xs[m - 1]);
     dy = min(dy, ys[m] - ys[m - 1]);
   }
   long long ans = 0;
   bool flag = 0;
   for (int i = 1; i <= n; i++) {
     ans += abs(x[i] - cx) + abs(y[i] - cy);
     ++cnt[x[i] <= cx][y[i] <= cy];
     if (x[i] == cx && y[i] == cy) flag = 1;
   }
   if (cnt[0][0] && cnt[0][1] && cnt[1][1] && cnt[1][0]) {
     if (n % 2 == 0 || flag) ans -= min(dx, dy);
   }
   printf( %lld
 , ans * 2);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   cout << fixed;
   double d, L, v1, v2;
   cin >> d >> L >> v1 >> v2;
   cout << setprecision(8) << (L - d) / (v1 + v2) << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long scan_d() {
   char t = getchar();
   long long you = 0;
   while (t > '9' || t < '0') t = getchar();
   while (t <= '9' && t >= '0') {
     you *= 10;
     you += t - '0';
     t = getchar();
   }
   return you;
 }
 long long dp[1050][1050];
 long long op[1001];
 int main() {
   for (int i = 0; i <= 1010; i++) dp[1][i] = 1;
   for (int i = 2; i <= 1010; i++)
     for (int o = i - 1; o <= 1010; o++) {
       dp[i][o] = dp[i - 1][o - 1] + dp[i][o - 1];
       dp[i][o] %= 1000000007;
     }
   long long y;
   y = scan_d();
   long long sum = 0;
   for (int i = 1; i <= y; i++) {
     op[i] = scan_d();
   }
   long long ans = 1;
   for (int i = 1; i <= y; i++) {
     sum += op[i];
     ans *= dp[op[i]][sum - 1];
     ans %= 1000000007;
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = 1e18;
 const long long mod = 1e9 + 7;
 const long long N = 1e5 + 10;
 inline long long add(long long x, long long y) {
   x += y;
   if (x >= mod) x -= mod;
   return x;
 }
 inline long long mul(long long x, long long y) {
   x = (1LL * x * y) % mod;
   return x;
 }
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   long long n;
   cin >> n;
   n--;
   cout <<  0 0  << endl;
   fflush(stdout);
   if (n == 0) {
     cout <<  1 0 1 1 ;
     fflush(stdout);
     return 0;
   }
   string prev;
   cin >> prev;
   long long l = 0;
   long long r = 1e9;
   long long i = 1;
   while (i <= n) {
     long long m = (l + r) / 2;
     cout << m <<
          <<  0  << endl;
     fflush(stdout);
     string s;
     cin >> s;
     if (s == prev) {
       l = m;
     } else {
       r = m;
     }
     i++;
   }
   if (r - l < 2) {
     cout << r <<   1   << (r + 1) <<     << (2 * (r + 1) - 2 * l - 1);
     fflush(stdout);
     return 0;
   }
   long long m = (l + r) / 2;
   cout << m <<   0   << m <<   1 ;
   fflush(stdout);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> c;
 vector<bool> used;
 void dfs(int u, vector<vector<int>>& v) {
   used[u] = 1;
   for (int i = 0; i < v[u].size(); i++) {
     if (c[u] == c[v[u][i]] && !used[v[u][i]]) {
       dfs(v[u][i], v);
     }
   }
 }
 int main() {
   int n;
   cin >> n;
   vector<vector<int>> v(n);
   c.resize(n);
   used.resize(n, 0);
   vector<int> cnt(110000);
   for (int i = 0; i < n - 1; i++) {
     int a, b;
     cin >> a >> b;
     a--;
     b--;
     v[a].push_back(b);
     v[b].push_back(a);
   }
   for (int i = 0; i < n; i++) {
     cin >> c[i];
   }
   for (int i = 0; i < n; i++) {
     if (!used[i]) {
       cnt[c[i]]++;
       dfs(i, v);
     }
   }
   multiset<int> data;
   for (int i = 0; i < 100010; i++) {
     for (int j = 0; j < cnt[i]; j++) {
       data.insert(i);
     }
   }
   for (int i = 0; i < n; i++) {
     bool check = 0;
     multiset<int> tmp;
     for (int j = 0; j < v[i].size(); j++) {
       if (c[v[i][j]] == c[i]) {
         check = 1;
       }
       tmp.insert(c[v[i][j]]);
     }
     if (!check) {
       tmp.insert(c[i]);
     }
     if (tmp == data) {
       cout <<  YES  << endl;
       cout << i + 1 << endl;
       return 0;
     }
   }
   cout <<  NO  << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x3f3f3f3f;
 struct node {
   double x, y;
 } po[1010];
 double dis(node a, node b) {
   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
 }
 node mark;
 double cha(node a, node b, node c) {
   return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
 }
 double get(node a, node b, node c) {
   return abs(cha(a, b, c)) / dis(a, b) / 2.0;
 }
 int main() {
   int n;
   cin >> n;
   double ans = 1e9;
   for (int i = (0); i < (n); ++i) cin >> po[i].x >> po[i].y;
   for (int i = (0); i < (n); ++i) {
     ans = min(ans, get(po[(i - 1 + n) % n], po[(i + 1) % n], po[i]));
   }
   cout << fixed << setprecision(10) << ans << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, x, c, cnt;
 vector<long long> v1, v2;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> n;
   while (n--) {
     cin >> x;
     if (x > 0)
       v1.push_back(x), c += x;
     else
       v2.push_back(abs(x)), cnt += abs(x);
   }
   if (c > cnt) {
     cout <<  first
 ;
     return 0;
   }
   if (cnt > c) {
     cout <<  second
 ;
     return 0;
   }
   bool a = 0;
   for (int i = 0; i < min(v1.size(), v2.size()); i++) {
     if (v1[i] > v2[i]) {
       cout <<  first
 ;
       return 0;
     } else if (v1[i] < v2[i]) {
       cout <<  second
 ;
       return 0;
     }
   }
   if (x < 0)
     cout <<  second  << endl;
   else
     cout <<  first  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX_N = 1001;
 int dp2[MAX_N][MAX_N], dp5[MAX_N][MAX_N];
 int n;
 string findPath(int (*p)[MAX_N]) {
   int i = n - 1, j = n - 1;
   string path =   ;
   while (i != 0 && j != 0) {
     if (p[i - 1][j] > p[i][j - 1]) {
       path.insert(0,  R );
       j--;
     } else {
       path.insert(0,  D );
       i--;
     }
   }
   if (i == 0) {
     while (j != 0) {
       path.insert(0,  R );
       j--;
     }
   } else {
     while (i != 0) {
       path.insert(0,  D );
       i--;
     }
   }
   return path;
 }
 int main() {
   std::ios::sync_with_stdio(false);
   cin >> n;
   int temp1, temp2, zeroI = -1;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < n; j++) {
       cin >> temp1;
       if (!temp1) {
         zeroI = i;
         continue;
       }
       temp2 = temp1;
       while (!(temp1 & 1)) {
         dp2[i][j]++;
         temp1 >>= 1;
       }
       while (!(temp2 % 5)) {
         dp5[i][j]++;
         temp2 /= 5;
       }
     }
   for (int i = 1; i < n; i++) {
     dp2[i][0] += dp2[i - 1][0];
     dp5[i][0] += dp5[i - 1][0];
     dp2[0][i] += dp2[0][i - 1];
     dp5[0][i] += dp5[0][i - 1];
   }
   for (int i = 1; i < n; i++) {
     for (int j = 1; j < n; j++) {
       dp2[i][j] += min(dp2[i - 1][j], dp2[i][j - 1]);
       dp5[i][j] += min(dp5[i - 1][j], dp5[i][j - 1]);
     }
   }
   int(*p)[MAX_N] = (dp2[n - 1][n - 1] < dp5[n - 1][n - 1]) ? dp2 : dp5;
   if ((~zeroI) && p[n - 1][n - 1] > 1) {
     cout <<  1  << endl;
     for (int i = 0; i < zeroI; i++) cout <<  D  << flush;
     for (int j = 1; j < n; j++) cout <<  R  << flush;
     for (int i = zeroI + 1; i < n; i++) cout <<  D  << flush;
     return 0;
   } else {
     cout << p[n - 1][n - 1] << endl;
     cout << findPath(p) << flush;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int B, n, m;
 int li[500008], ri[500008], mx[500008], tag[500008];
 short g[480][100008];
 int bel[500008], de[500008], ai[500008], pa[500008];
 short size[500008];
 int find(int x) {
   if (pa[x] == x) return x;
   return pa[x] = find(pa[x]);
 }
 void link(int x, int y) {
   if (x == y) return;
   if (size[x] > size[y]) swap(x, y);
   pa[x] = y;
   size[y] += size[x];
 }
 int tot;
 int lst[500008], stamp[500008];
 void makeup(int id) {
   ++tot;
   mx[id] = 0;
   for (int i = li[id]; i <= ri[id]; i++) pa[i] = i, size[i] = 1;
   for (int i = li[id]; i <= ri[id]; i++) {
     int x = ai[i];
     mx[id] = max(mx[id], x);
     if (stamp[x] != tot)
       stamp[x] = tot, g[id][x] = lst[x] = i - li[id];
     else
       link(i, g[id][x] + li[id]), g[id][x] = find(g[id][x] + li[id]) - li[id];
   }
 }
 void pushdown(int id) {
   for (int i = li[id]; i <= ri[id]; i++) g[id][ai[i]] = -1;
   for (int i = li[id]; i <= ri[id]; i++) {
     g[id][ai[i] + de[i]] = -1;
     if (find(i) == i) ai[i] = ai[i] + de[i] - tag[id];
     de[i] = 0;
   }
   for (int i = li[id]; i <= ri[id]; i++) ai[i] = ai[find(i)];
   tag[id] = 0;
 }
 void refresh(int id) {
   while (-1 == g[id][mx[id]]) mx[id]--;
 }
 int cnt = 0;
 void subtract(int id, int x) {
   if (mx[id] - tag[id] <= x) return;
   if (mx[id] - tag[id] > x * 2 + 1 and 1) {
     for (int i = tag[id] + 1; i <= x + tag[id]; i++)
       if (g[id][i] != -1) {
         int j = i + x;
         de[g[id][i] + li[id]] += x;
         if (g[id][j] != -1)
           link(g[id][i] + li[id], g[id][j] + li[id]),
               g[id][j] = find(g[id][j] + li[id]) - li[id];
         else
           g[id][j] = g[id][i];
         g[id][i] = -1;
       }
     tag[id] += x;
   } else {
     for (int i = x + 1 + tag[id]; i <= mx[id]; i++)
       if (g[id][i] != -1) {
         int j = i - x;
         de[g[id][i] + li[id]] -= x;
         if (g[id][j] != -1)
           link(g[id][j] + li[id], g[id][i] + li[id]),
               g[id][j] = find(g[id][j] + li[id]) - li[id];
         else
           g[id][j] = g[id][i];
         g[id][i] = -1;
       }
     refresh(id);
   }
 }
 int ask(int id, int x) {
   if (x + tag[id] > 100001) return 0;
   if (g[id][x + tag[id]] == -1) return 0;
   g[id][x + tag[id]] = find(g[id][x + tag[id]] + li[id]) - li[id];
   return size[g[id][x + tag[id]] + li[id]];
 }
 signed main() {
   memset(g, -1, sizeof g);
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= n; i++) scanf( %d , &ai[i]);
   B = sqrt(n);
   B = max(B, n / 475);
   memset(li, 0x3f, sizeof li);
   for (int i = 1; i <= n; i++) {
     bel[i] = i / B;
     li[bel[i]] = min(li[bel[i]], i);
     ri[bel[i]] = i;
   }
   for (int i = 0; i <= n / B; i++) makeup(i);
   while (m--) {
     int op, l, r, x;
     scanf( %d%d%d%d , &op, &l, &r, &x);
     if (op == 1) {
       if (bel[l] == bel[r]) {
         pushdown(bel[l]);
         for (int i = l; i <= r; i++)
           if (ai[i] > x) ai[i] -= x;
         makeup(bel[l]);
       } else {
         pushdown(bel[l]);
         for (int i = l; i <= ri[bel[l]]; i++)
           if (ai[i] > x) ai[i] -= x;
         pushdown(bel[r]);
         for (int i = li[bel[r]]; i <= r; i++)
           if (ai[i] > x) ai[i] -= x;
         makeup(bel[l]);
         makeup(bel[r]);
         for (int i = bel[l] + 1; i < bel[r]; i++) subtract(i, x);
       }
     } else {
       int ans = 0;
       if (bel[l] == bel[r]) {
         pushdown(bel[l]);
         for (int i = l; i <= r; i++)
           if (ai[i] == x) ans++;
         makeup(bel[l]);
         printf( %d
 , ans);
       } else {
         pushdown(bel[l]);
         for (int i = l; i <= ri[bel[l]]; i++) ans += (ai[i] == x);
         pushdown(bel[r]);
         for (int i = li[bel[r]]; i <= r; i++) ans += (ai[i] == x);
         makeup(bel[l]);
         makeup(bel[r]);
         for (int i = bel[l] + 1; i < bel[r]; i++) ans += ask(i, x);
         printf( %d
 , ans);
       }
     }
     ++cnt;
     if (cnt < -7) {
       for (int i = 0; i <= n / B; i++) pushdown(i);
       for (int i = 1; i <= n; i++) cout << ai[i] <<    ;
       cout << g[2][30] <<  :

 ;
       for (int i = 0; i <= n / B; i++) makeup(i);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100010;
 long long a[N];
 int n;
 bool check(long long x) {
   long long sum = 0;
   for (int i = 2; i <= n; ++i) {
     if (x - a[i] < 0) return false;
     sum += x - a[i];
   }
   return (sum >= a[1]);
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]);
   sort(a + 1, a + n + 1);
   long long l = 0, r = (long long)1e14 + 1;
   while (l + 1 < r) {
     long long mid = (l + r) / 2;
     if (check(mid))
       r = mid;
     else
       l = mid;
   }
   if (check(l))
     printf( %I64d , l);
   else
     printf( %I64d , r);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool isPowerOfTwo(int n) {
   if (n == 0) return false;
   return (ceil(log2(n)) == floor(log2(n)));
 }
 void asquare() {
   long long n, c = 0, ans = LONG_LONG_MAX;
   cin >> n;
   string sn;
   if (isPowerOfTwo(n) == true)
     cout <<  0
 ;
   else {
     long long j = 0, k = 0, nn = 1;
     string s = to_string(n);
     for (int i = 0; i <= 60; i++) {
       nn = (long long)pow(2, i);
       sn = to_string(nn);
       c = 0, j = 0, k = 0;
       bool bb;
       while (j != s.length() && k != sn.length()) {
         if (s[j] == sn[k]) {
           j++;
           k++;
           bb = true;
         } else {
           j++;
           c++;
           bb = false;
         }
       }
       if (bb = true) {
         if (j == s.length()) {
           k--;
           c += sn.length() - k - 1;
         } else if (k == sn.length()) {
           j--;
           c += s.length() - j - 1;
         }
       } else {
         k--;
         c += sn.length() - k - 1;
       }
       if (c == 1) {
         ans = 1;
         break;
       } else
         ans = min(ans, c);
     }
     cout << ans <<
 ;
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long t;
   cin >> t;
   while (t--) {
     asquare();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int x, y;
   cin >> x >> y;
   int ans = 0;
   int d = max(abs(x), abs(y));
   if (d == 0) {
     cout << 0 <<
 ;
     return 0;
   } else
     ans = (d - 1) * 4;
   if (x == d && y != -1 * (d - 1) && y != -1 * (d)) ans++;
   if (y == d && x != d) ans += 2;
   if (x == -1 * d && y != d) ans += 3;
   if (y == -1 * d && x != -1 * d) ans += 4;
   cout << ans <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Aho {
   Aho *son[26];
   Aho *fail;
   int cntstr, faildp;
   Aho() {
     for (int i = 0; i < 26; ++i) son[i] = NULL;
     fail = NULL;
     cntstr = 0;
     faildp = -1;
   }
 };
 void insert(Aho *x, int i, const string &str) {
   if (i < str.size()) {
     if (x->son[str[i] - 'a'] == NULL) {
       x->son[str[i] - 'a'] = new Aho();
     }
     insert(x->son[str[i] - 'a'], i + 1, str);
   } else {
     x->cntstr++;
   }
 }
 void calcFailEdges(Aho *root) {
   deque<Aho *> q;
   root->fail = root;
   q.push_back(root);
   while (!q.empty()) {
     Aho *x = q.front();
     q.pop_front();
     for (int i = 0; i < 26; ++i) {
       if (x->son[i] != NULL) {
         q.push_back(x->son[i]);
         Aho *pnt = x->fail;
         if (x == root)
           x->son[i]->fail = root;
         else {
           while (pnt != root && pnt->son[i] == NULL) {
             pnt = pnt->fail;
           }
           if (pnt->son[i] != NULL)
             x->son[i]->fail = pnt->son[i];
           else
             x->son[i]->fail = root;
         }
       }
     }
   }
 }
 int getDp(Aho *t) {
   if (t->faildp == -1) {
     t->faildp = t->cntstr;
     t->faildp += getDp(t->fail);
   }
   return t->faildp;
 }
 const int MAX_N = 200000;
 Aho *state[1 + MAX_N];
 Aho *advance(Aho *t, char ch) {
   while (t->fail != t && t->son[ch - 'a'] == NULL) t = t->fail;
   if (t->son[ch - 'a'] == NULL) return t;
   return t->son[ch - 'a'];
 }
 Aho *state1[MAX_N], *state2[MAX_N];
 void doStuff(int n, Aho **state, const string &str, const vector<string> &vec) {
   Aho *T = new Aho();
   for (int i = 0; i < n; ++i) insert(T, 0, vec[i]);
   T->faildp = T->cntstr;
   calcFailEdges(T);
   Aho *pnt = T;
   for (int i = 1; i <= str.size(); ++i) {
     pnt = advance(pnt, str[i - 1]);
     state[i] = pnt;
   }
 }
 int main() {
   int n;
   string str;
   cin >> str >> n;
   vector<string> vec;
   for (int i = 0; i < n; ++i) {
     string p;
     cin >> p;
     vec.push_back(p);
   }
   doStuff(n, state1, str, vec);
   for (int i = 0; i < n; ++i) reverse(vec[i].begin(), vec[i].end());
   reverse(str.begin(), str.end());
   doStuff(n, state2, str, vec);
   long long rez = 0LL;
   for (int i = 1; i < str.size(); ++i)
     rez = (long long)getDp(state1[i]) * getDp(state2[str.size() - i]) + rez;
   printf( %lld , rez);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x3f3f3f3f;
 const int MOD = 1e9 + 7;
 const int base = 101;
 inline void chmax(int& x, int y) {
   if (x < y) x = y;
 }
 inline void chmin(int& x, int y) {
   if (x > y) x = y;
 }
 inline int LSB(int i) { return (i & -i); }
 int n, m, dp[10005];
 char s[10005], str[10005];
 map<long long, string> mp;
 vector<string> v;
 inline long long Hash(int a, int b) { return (1LL * a * base + b) % MOD; }
 int main() {
   scanf( %d%s%d , &n, &s, &m);
   for (int i = 0; i < m; i++) {
     scanf( %s , &str);
     long long h = 1;
     for (int j = 0; j < strlen(str); j++) {
       h = Hash(h, tolower(str[j]));
     }
     mp[h] = str;
   }
   fill(dp, dp + n, -1);
   dp[0] = 0;
   for (int i = 0; i < n; i++) {
     long long h = 1;
     for (int j = i; j >= 0; j--) {
       h = Hash(h, s[j]);
       if (dp[j] != -1 && mp.find(h) != mp.end()) {
         dp[i + 1] = h;
         break;
       }
     }
   }
   int p = n;
   while (p > 0) {
     v.push_back(mp[dp[p]]);
     p -= mp[dp[p]].length();
   }
   reverse(v.begin(), v.end());
   for (string& i : v) printf( %s  , &i[0]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long p = 1e9 + 7;
 int mk[705][705][3][3];
 char s[705];
 long long ck(int l, int r, int lc, int rc) {
   if (l > r) return !lc || !rc || lc != rc;
   if (mk[l][r][lc][rc]) return mk[l][r][lc][rc];
   for (int i = l, cnt = 0;; i++) {
     if (s[i] == ')')
       cnt++;
     else
       cnt--;
     if (!cnt) {
       long long m = ck(l + 1, i - 1, 0, 1) * ck(i + 1, r, 1, rc) % p +
                     ck(l + 1, i - 1, 0, 2) * ck(i + 1, r, 2, rc);
       if (lc != 1) m += ck(l + 1, i - 1, 1, 0) * ck(i + 1, r, 0, rc);
       if (lc != 2) m += ck(l + 1, i - 1, 2, 0) * ck(i + 1, r, 0, rc);
       return mk[l][r][lc][rc] = m % p;
     }
   }
 }
 int main() {
   scanf( %s , s + 1);
   printf( %lld , ck(1, strlen(s + 1), 0, 0));
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC target( avx,avx2,fma )
 using namespace std;
 using ll = long long;
 using ull = unsigned long long;
 template <typename T>
 void print(vector<T> v) {
   for (T i : v) cout << i <<    ;
   cout << '
';
 }
 template <typename T>
 void print(vector<vector<T>>& v) {
   for (vector<T>& vv : v) {
     for (T& i : vv) cout << i <<    ;
     cout << '
';
   }
 }
 template <typename T>
 void print(T&& t) {
   cout << t << '
';
 }
 template <typename T, typename... Args>
 void print(T&& t, Args&&... args) {
   cout << t <<    ;
   print(forward<Args>(args)...);
 }
 template <typename T>
 istream& operator>>(istream& is, vector<T>& v) {
   for (auto& i : v) is >> i;
   return is;
 }
 template <typename T>
 ostream& operator<<(ostream& os, vector<T>& v) {
   for (auto& i : v) os << i << ' ';
   return os;
 }
 void __print(int x) { cerr << x; }
 void __print(long x) { cerr << x; }
 void __print(long long x) { cerr << x; }
 void __print(unsigned x) { cerr << x; }
 void __print(unsigned long x) { cerr << x; }
 void __print(unsigned long long x) { cerr << x; }
 void __print(float x) { cerr << x; }
 void __print(double x) { cerr << x; }
 void __print(long double x) { cerr << x; }
 void __print(char x) { cerr << '\' << x << '\'; }
 void __print(const char* x) { cerr << '\' << x << '\'; }
 void __print(const string& x) { cerr << '\' << x << '\'; }
 void __print(bool x) { cerr << (x ?  true  :  false ); }
 template <typename T, typename V>
 void __print(const pair<T, V>& x) {
   cerr << '{';
   __print(x.first);
   cerr << ',';
   __print(x.second);
   cerr << '}';
 }
 template <typename T>
 void __print(const T& x) {
   int f = 0;
   cerr << '{';
   for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);
   cerr <<  } ;
 }
 void _print() { cerr <<  ]
 ; }
 template <typename T, typename... V>
 void _print(T t, V... v) {
   __print(t);
   if (sizeof...(v)) cerr <<  ,  ;
   _print(v...);
 }
 void loop() {
   ll n;
   cin >> n;
   vector<ll> a(n);
   cin >> a;
   if (n == 1) {
     print( Alice );
     return;
   }
   vector<ll> inc, dec;
   inc.push_back(a[0]);
   for (ll i = 0; i < n - 1; i++) {
     if (a[i] < a[i + 1]) {
       inc.push_back(a[i + 1]);
     } else
       break;
   }
   dec.push_back(a[n - 1]);
   for (ll i = n - 1; i > 0; i--) {
     if (a[i] < a[i - 1]) {
       dec.push_back(a[i - 1]);
     } else
       break;
   }
   if (dec.size() % 2) {
     print( Alice );
     return;
   } else if ((inc.size() - 1 + dec.size()) % 2 == 0) {
     print( Alice );
     return;
   }
   print( Bob );
 }
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ll t;
   t = 1;
   while (t--) {
     loop();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e5 + 10;
 const int INF = 0x3f3f3f3f;
 int n, m, a[maxn], b[maxn], f[maxn], g[maxn], l[maxn], p[maxn], ans[maxn];
 bool vis[maxn];
 int main() {
   scanf( %d , &n);
   for (int i = (1), _end_ = (n); i <= _end_; ++i) scanf( %d , &a[i]);
   a[++n] = INF;
   scanf( %d , &m);
   for (int i = (1), _end_ = (m); i <= _end_; ++i) scanf( %d , &b[i]);
   sort(b + 1, b + m + 1);
   for (int i = (1), _end_ = (n + 1); i <= _end_; ++i) f[i] = INF;
   for (int i = (1), _end_ = (n); i <= _end_; ++i)
     if (a[i] != -1) {
       int L = 1, R = n, pos = 0;
       while (L <= R) {
         int Mid = L + R >> 1;
         if (f[Mid] < a[i]) {
           pos = Mid;
           L = Mid + 1;
         } else
           R = Mid - 1;
       }
       f[pos + 1] = a[i];
       g[pos + 1] = i;
       l[i] = pos + 1;
       p[i] = g[pos];
     } else {
       int pos = n;
       for (int j = m; j >= 1; --j) {
         while (f[pos] >= b[j]) --pos;
         f[pos + 1] = b[j];
         g[pos + 1] = i;
       }
     }
   for (int len = l[n], pos = n, val = a[n]; len >= 1; --len)
     if (a[pos] != -1) {
       if (a[p[pos]] != -1) {
         pos = p[pos];
         val = a[pos];
       } else {
         int t = lower_bound(b + 1, b + m + 1, val) - b - 1;
         vis[t] = true;
         pos = p[pos];
         val = ans[pos] = b[t];
       }
     } else {
       for (int i = pos - 1; i >= 1; --i)
         if (a[i] != -1 && l[i] == len - 1 && a[i] < val) {
           pos = i;
           val = a[i];
           goto Next;
         }
       for (int i = pos - 1; i >= 1; --i)
         if (a[i] == -1) {
           int t = lower_bound(b + 1, b + m + 1, val) - b - 1;
           vis[t] = true;
           pos = i;
           val = ans[pos] = b[t];
           goto Next;
         }
     Next:;
     }
   int pos = 1;
   for (int i = (1), _end_ = (n - 1); i <= _end_; ++i)
     if (a[i] != -1)
       ans[i] = a[i];
     else if (!ans[i]) {
       while (vis[pos]) ++pos;
       ans[i] = b[pos];
       ++pos;
     }
   for (int i = (1), _end_ = (n - 1); i <= _end_; ++i) printf( %d  , ans[i]);
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int getChar(char c) {
   if (c == '+') return 1;
   return 0;
 }
 string s;
 stack<int> mystack;
 int main() {
   cin >> s;
   int n = s.size();
   int temp;
   for (int i = 0; i < n; i++) {
     temp = getChar(s[i]);
     if (mystack.empty())
       mystack.push(temp);
     else {
       if (mystack.top() == temp)
         mystack.pop();
       else
         mystack.push(temp);
     }
   }
   if (mystack.empty()) {
     cout <<  Yes  << endl;
     return 0;
   }
   cout <<  No  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 2000000000;
 const double eps = 1e-9, Pi = 2 * acos(0);
 int main() {
   ifstream fin( input.txt );
   ofstream fout( output.txt );
   string s;
   cin >> s;
   map<string, int> make_pair;
   for (int i = 0; i <= 9; i++) {
     string x;
     cin >> x;
     make_pair[x] = i;
   }
   for (int i = 0; i < 8; i++) {
     string x =   ;
     for (int j = i * 10; j < (i + 1) * 10; j++) x += s[j];
     cout << make_pair[x];
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int N, memo[1 << 25];
 pair<int, int> arr[30];
 int dist(int a, int n) {
   int k1 = arr[n].first - arr[a].first;
   int k2 = arr[n].second - arr[a].second;
   return k1 * k1 + k2 * k2;
 }
 int dp(int mask) {
   if (__builtin_popcount(mask) == N) {
     return 0;
   }
   if (memo[mask] != 0) return memo[mask];
   int res = 1e9;
   for (int i = 1; i <= N; i++) {
     if (!((mask >> (i - 1) & 1))) {
       res = min(res, dp(mask | (1 << (i - 1))) + 2 * dist(i, 0));
       for (int j = i + 1; j <= N; j++) {
         if (!(mask >> (j - 1) & 1) and i != j) {
           res = min(res, dp(mask | (1 << (i - 1)) | (1 << (j - 1))) +
                              dist(i, 0) + dist(i, j) + dist(j, 0));
         }
       }
       break;
     }
   }
   memo[mask] = res;
   return res;
 }
 void backtrack(int mask) {
   if (__builtin_popcount(mask) == N) {
     return;
   }
   for (int i = 1; i <= N; i++) {
     if (!((mask >> (i - 1) & 1))) {
       if (dp(mask | (1 << (i - 1))) + 2 * dist(i, 0) == dp(mask)) {
         cout << 0 <<     << i <<    ;
         backtrack(mask | (1 << (i - 1)));
         return;
       }
       for (int j = i + 1; j <= N; j++) {
         if (!(mask >> (j - 1) & 1) and i != j) {
           if (dp(mask | (1 << (i - 1)) | (1 << (j - 1))) + dist(i, 0) +
                   dist(i, j) + dist(j, 0) ==
               dp(mask)) {
             cout << 0 <<     << i <<     << j <<    ;
             backtrack(mask | (1 << (i - 1)) | (1 << (j - 1)));
             return;
           }
         }
       }
       break;
     }
   }
   return;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0), cout.tie(0);
   cin >> arr[0].first >> arr[0].second;
   cin >> N;
   for (int i = 1; i <= N; i++) cin >> arr[i].first >> arr[i].second;
   cout << dp(0) << endl;
   backtrack(0);
   cout << 0 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 char str[2][400000 + 10];
 int n;
 void sortstr(int t, int l, int r) {
   if ((r - l + 1) & 1) return;
   int md = (l + r) / 2;
   sortstr(t, l, (l + r) / 2), sortstr(t, (l + r) / 2 + 1, r);
   bool needswap = false;
   for (int i = l, j = md + 1; i <= md; i++, j++) {
     if (str[t][i] < str[t][j]) break;
     if (str[t][i] > str[t][j]) {
       needswap = true;
       break;
     }
   }
   if (needswap) {
     for (int i = l, j = md + 1; i <= md; i++, j++) swap(str[t][i], str[t][j]);
   }
 }
 int main() {
   for (int i = 0; i < 2; i++)
     scanf( %s , str[i]), n = strlen(str[i]), sortstr(i, 0, n - 1);
   bool equ = true;
   for (int i = 0; i < n; i++)
     if (str[0][i] != str[1][i]) equ = false;
   printf( %s
 , equ ?  YES  :  NO );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, gxx;
 pair<int, int> a[411111];
 int p[411111];
 int Gxx[411111], bb[411111];
 int degree[411111];
 int h, t;
 void make_ans(int x, int y, int tot) {
   int now_x = degree[x] - 1 - tot;
   int need_x = max(h - now_x, 0);
   int now_y = degree[y] - 1 - tot;
   int need_y = max(t - now_y, 0);
   for (int i = p[x]; i < p[x + 1]; i++) Gxx[a[i].second] = 1;
   for (int i = p[y]; i < p[y + 1]; i++)
     if (Gxx[a[i].second] == 1) bb[a[i].second] = 1;
   printf( YES
 );
   printf( %d %d
 , x, y);
   bool bo = false;
   for (int i = p[x]; i < p[x + 1]; i++)
     if ((bb[a[i].second] == 0 || need_x) && a[i].second != y && h) {
       h--;
       if (bb[a[i].second]) {
         bb[a[i].second] = -1;
         need_x--;
       }
       if (bo) printf(   );
       bo = true;
       printf( %d , a[i].second);
     }
   printf(
 );
   bo = false;
   for (int i = p[y]; i < p[y + 1]; i++)
     if ((bb[a[i].second] == 0 || need_y) && a[i].second != x && t &&
         bb[a[i].second] != -1) {
       t--;
       if (bb[a[i].second]) need_y--;
       if (bo) printf(   );
       bo = true;
       printf( %d , a[i].second);
     }
   printf(
 );
 }
 int find(int x, int y) {
   int ans = 0;
   for (int i = p[x]; i < p[x + 1]; i++)
     if (a[i].second != y) {
       int t =
           lower_bound(a + p[y], a + p[y + 1], make_pair(y, a[i].second)) - a;
       if (a[t].second == a[i].second) ans++;
     }
   return ans;
 }
 int main() {
   scanf( %d%d%d%d , &n, &m, &h, &t);
   for (int i = 1; i <= m; i++) {
     scanf( %d%d , &a[i].first, &a[i].second);
     degree[a[i].first]++;
     degree[a[i].second]++;
     a[i + m].second = a[i].first;
     a[i + m].first = a[i].second;
   }
   int M = m * 2;
   sort(a + 1, a + M + 1);
   a[0].first = 0;
   a[M + 1].first = n + 1;
   int now = 0;
   for (int i = 1; i <= M + 1; i++)
     while (now != a[i].first) {
       now++;
       p[now] = i;
     }
   p[0] = 0;
   for (int i = 1; i <= M; i++)
     if (degree[a[i].first] > h && degree[a[i].second] > t) {
       int t1 = a[i].first;
       int t2 = a[i].second;
       int tot = 0;
       if (t1 < t2)
         tot = find(t1, t2);
       else
         tot = find(t2, t1);
       if (degree[t1] + degree[t2] - 2 - tot >= h + t) {
         make_ans(t1, t2, tot);
         return 0;
       }
     }
   printf( NO
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k;
 int v[100000 + 1];
 int mx, rez;
 pair<int, int> rz[100000 + 1];
 int stkLen;
 int stkLen2;
 int stk[100000 + 1];
 int stk2[100000 + 1];
 int s, s2;
 void readFile() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie();
   cin >> n >> k;
   for (int i = 1; i <= n; i++) cin >> v[i];
 }
 int cautBin(int nr, int stk[], int stkLen) {
   int i = 0;
   int pas = 1 << 16;
   while (pas != 0) {
     if (i + pas <= stkLen && abs(v[stk[i + pas]] - nr) > k) i += pas;
     pas >>= 1;
   }
   return stk[i] + 1;
 }
 bool verif(int st, int dr) {
   while (s < stkLen && stk[s] < st) s++;
   while (s2 < stkLen2 && stk2[s2] < st) s2++;
   return (abs(v[stk[s]] - v[stk2[s2]]) <= k);
 }
 void solve() {
   stkLen = 0;
   int st = 1;
   s = s2 = 1;
   for (int i = 1; i <= n; i++) {
     while (stkLen >= s && v[i] >= v[stk[stkLen]]) stkLen--;
     stk[++stkLen] = i;
     while (stkLen2 >= s2 && v[i] <= v[stk2[stkLen2]]) stkLen2--;
     stk2[++stkLen2] = i;
     while (st < i && verif(st, i) == 0) st++;
     int len = i - st + 1;
     if (len > mx) {
       mx = len;
       rez = 0;
     }
     if (len == mx) rz[++rez] = {st, i};
   }
 }
 void printFile() {
   cout << mx <<     << rez <<
 ;
   for (int i = 1; i <= rez; i++)
     cout << rz[i].first <<     << rz[i].second <<
 ;
 }
 int main() {
   readFile();
   solve();
   printFile();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long ar[200010];
 void solve() {
   long long a, b, c = 0, i, j, t, k, lie, m, n, o, x, y, z;
   long long p = 0, sm = 0, cnt = 0;
   scanf( %lld , &n);
   string s;
   cin >> s;
   if (n == 1) {
     printf( Yes
 );
     return;
   }
   for (i = 0; i < n; i++) ar[s[i] - 'a']++;
   for (i = 0; i < 26; i++) {
     if (ar[i] > 1) {
       printf( Yes
 );
       return;
     }
   }
   printf( No
 );
 }
 int main() {
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps = 1e-8;
 const int mod = 1e9 + 7;
 const int N = 1e6 + 10;
 const int inf = 1e9;
 int t, n, k;
 char s[N];
 int cnt[N];
 int a[N], b[N];
 int main() {
   ios::sync_with_stdio(false);
   cin >> t;
   while (t--) {
     cin >> n >> k;
     cin >> s + 1;
     for (int i = 1; i <= n; i++) {
       cnt[i] = cnt[i - 1];
       if (s[i] == '1') cnt[i]++;
     }
     int ans = inf;
     for (int i = 1; i <= k; i++) {
       int ret = 0, mn = inf, tp = inf, l = 0;
       vector<int> q;
       q.push_back(0);
       for (int j = i; j <= n; j += k) {
         int tmp = cnt[j - 1] - cnt[l];
         ret += tmp;
         q.push_back(cnt[j] - cnt[j - 1]);
         l = j;
       }
       ret += cnt[n] - cnt[l];
       int sz = q.size() - 1;
       for (int i = 1; i <= sz; i++) {
         a[i] = a[i - 1];
         b[i] = b[i - 1];
         if (q[i] == 1)
           a[i]++;
         else
           b[i]++;
       }
       tp = a[sz];
       for (int i = sz; i >= 1; i--) {
         mn = min(mn, b[i] - a[i] + a[sz]);
         tp = min(tp, a[i - 1] - b[i - 1] + mn);
       }
       ans = min(ans, ret + tp);
     }
     cout << ans << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using std::string;
 using std::vector;
 namespace Template {
 struct IN {
   template <class T>
   void fr(T& a) {
     T s = 0;
     int w = 1;
     char ch = getchar();
     while (ch < '0' || ch > '9') {
       if (ch == '-') w = -1;
       ch = getchar();
     }
     while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
     a = w * s;
   }
   template <class T>
   T fr() {
     T a;
     fr(a);
     return a;
   }
   IN& operator>>(long long& x) { return fr(x), *this; }
   IN& operator>>(signed& x) { return fr(x), *this; }
   IN& operator>>(unsigned& x) { return fr(x), *this; }
   IN& operator>>(char& c) {
     while (isspace(c = getchar()))
       ;
     return *this;
   }
   IN& operator>>(string& str) {
     char ch;
     while (isspace(ch = getchar()))
       ;
     str = ch;
     while (!isspace(ch = getchar())) str += ch;
     return *this;
   }
 } cin;
 struct OUT {
   char D[1 << 27], *A = D - 1;
   ~OUT() { fwrite(D, 1, A - D + 1, stdout); }
   template <class T>
   void fw(T x) {
     static char C[20];
     static int f;
     x < 0 ? * ++A = '-', x = -x : 0;
     while (C[++f] = 48 + x % 10, x /= 10)
       ;
     while (*++A = C[f], --f)
       ;
   }
   OUT& operator<<(char c) { return *++A = c, *this; }
   OUT& operator<<(string str) {
     int len = str.length();
     for (int i = 0; i < len; i++) *++A = str[i];
     return *this;
   }
   OUT& operator<<(long long x) { return fw(x), *this; }
   OUT& operator<<(signed x) { return fw(x), *this; }
   OUT& operator<<(unsigned x) { return fw(x), *this; }
 } cout;
 char endl = '
';
 int DEBUG = 0;
 template <class T>
 T sqr(T a) {
   return a * a;
 }
 template <class T>
 T abs(T a) {
   return a < 0 ? -a : a;
 }
 template <class T>
 T cmin(T a, T b) {
   return a < b ? a : b;
 }
 template <class T>
 T cmax(T a, T b) {
   return a > b ? a : b;
 }
 template <class T>
 void cswp(T& a, T& b) {
   T t = a;
   a = b;
   b = t;
 }
 }  // namespace Template
 using namespace Template;
 const int N = 1e5;
 int n, blo, tot = 0, fa[N + 10], len[N + 10], arr[N + 10];
 vector<int> E[N + 10];
 void adde(int u, int v) { E[u].push_back(v); }
 void dfs(int u, int f) {
   fa[u] = f, arr[++tot] = u;
   for (int v : E[u])
     if (v != f) dfs(v, u);
 }
 int calc(int k) {
   int ret = 0;
   for (int i = 1; i <= n; i++) len[i] = 1;
   for (int i = n; i > 1; i--) {
     int u = arr[i], f = fa[u];
     if (len[f] != -1 && len[u] != -1) {
       if (len[f] + len[u] >= k)
         ret++, len[f] = -1;
       else
         len[f] = cmax(len[f], len[u] + 1);
     }
   }
   return ret;
 }
 int main() {
   cin >> n;
   blo = sqrt(n * log2(n));
   for (int i = 1; i < n; ++i) {
     int u, v;
     cin >> u >> v;
     adde(u, v), adde(v, u);
   }
   dfs(1, 0), cout << n << endl;
   for (int i = 2; i <= blo; i++) cout << calc(i) << endl;
   for (int i = blo + 1; i <= n;) {
     int f = calc(i), l = i, r = n, pos = 0;
     while (l <= r) {
       int mid = (l + r) >> 1;
       if (calc(mid) == f)
         l = mid + 1, pos = mid;
       else
         r = mid - 1;
     }
     for (; i <= pos; i++) cout << f << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 template <typename T>
 void MACRO_VAR_Scan(T& t) {
   std::cin >> t;
 }
 template <typename First, typename... Rest>
 void MACRO_VAR_Scan(First& first, Rest&... rest) {
   std::cin >> first;
   MACRO_VAR_Scan(rest...);
 }
 template <typename T>
 void MACRO_VEC_ROW_Init(int n, T& t) {
   t.resize(n);
 }
 template <typename First, typename... Rest>
 void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {
   first.resize(n);
   MACRO_VEC_ROW_Init(n, rest...);
 }
 template <typename T>
 void MACRO_VEC_ROW_Scan(int p, T& t) {
   std::cin >> t[p];
 }
 template <typename First, typename... Rest>
 void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {
   std::cin >> first[p];
   MACRO_VEC_ROW_Scan(p, rest...);
 }
 template <class T>
 inline T CHMAX(T& a, const T b) {
   return a = (a < b) ? b : a;
 }
 template <class T>
 inline T CHMIN(T& a, const T b) {
   return a = (a > b) ? b : a;
 }
 template <class T>
 using V = std::vector<T>;
 template <class T>
 using VV = V<V<T>>;
 template <typename S, typename T>
 std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
   os <<  (  << p.first <<  ,   << p.second <<  ) ;
   return os;
 }
 using ll = long long;
 using ull = unsigned long long;
 using ld = long double;
 using PAIR = std::pair<ll, ll>;
 using PAIRLL = std::pair<ll, ll>;
 constexpr ll INFINT = 1 << 30;
 constexpr ll INFINT_LIM = (1LL << 31) - 1;
 constexpr ll INFLL = 1LL << 60;
 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
 constexpr double EPS = 1e-6;
 constexpr ll MOD = 1000000007;
 constexpr double PI = 3.141592653589793238462643383279;
 template <class T, size_t N>
 void FILL(T (&a)[N], const T& val) {
   for (auto& x : a) x = val;
 }
 template <class ARY, size_t N, size_t M, class T>
 void FILL(ARY (&a)[N][M], const T& val) {
   for (auto& b : a) FILL(b, val);
 }
 template <class T>
 void FILL(std::vector<T>& a, const T& val) {
   for (auto& x : a) x = val;
 }
 template <class ARY, class T>
 void FILL(std::vector<std::vector<ARY>>& a, const T& val) {
   for (auto& b : a) FILL(b, val);
 }
 struct Trie {
   std::vector<std::vector<ll>> g;
   ll p;
   Trie() : p(0) {
     g.emplace_back(std::vector<ll>(2, -1));
     ++p;
   }
   void add(const std::string& s) {
     size_t par = 0;
     for (size_t i = 0; i < s.size(); ++i) {
       ll t = s[i] - '0';
       if (g[par][t] == -1) {
         g.emplace_back(std::vector<ll>(2, -1));
         g[par][t] = p++;
       }
       par = g[par][t];
     }
   }
   ll next(size_t par, char c) {
     ll t = c - '0';
     return g[par][t];
   }
 };
 bool ng(std::string s) {
   return s ==  1100  || s ==  1010  || s ==  0111  || s ==  1111 ;
 }
 signed main() {
   std::ios::sync_with_stdio(false);
   std::cin.tie(0);
   ;
   ll n;
   MACRO_VAR_Scan(n);
   ;
   std::string s;
   for (ll i = 0; i < ll(n); ++i) {
     char c;
     MACRO_VAR_Scan(c);
     ;
     s += c;
   }
   Trie tr;
   std::vector<ll> c(n, 0);
   for (ll i = 0; i < ll(n); ++i) {
     auto S = s.substr(0, i + 1);
     std::reverse((S).begin(), (S).end());
     std::vector<ll> dp(S.size() + 1, 0);
     dp[0] = 1;
     for (ll j = 0; j < ll(S.size()); ++j) {
       for (ll k = 0; k < ll(4); ++k) {
         if (j < k) break;
         if (k == 3) {
           if (ng(S.substr(j - 3, 4))) continue;
         }
         (dp[j + 1] += dp[j - k]) %= MOD;
       }
     }
     ll p = 0;
     ll len = 0;
     for (ll j = 0; j < ll(S.size()); ++j) {
       ll ne = tr.next(p, S[j]);
       if (ne == -1) break;
       p = ne;
       dp[++len] = 0;
     }
     tr.add(S);
     for (ll j = (1); j < (S.size() + 1); ++j) {
       (c[i] += dp[j]) %= MOD;
     }
   }
   for (ll i = 0; i < ll(n - 1); ++i) (c[i + 1] += c[i]) %= MOD;
   for (ll i = 0; i < ll(n); ++i) {
     std::cout << (c[i]);
     std::cout <<
 ;
     ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename A, typename B, typename C>
 struct triple {
   A X;
   B Y;
   C Z;
   triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {}
 };
 template <typename A, typename B, typename C>
 triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {
   return triple<A, B, C>(a, b, c);
 }
 template <typename A, typename B, typename C>
 bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {
   if (a.X != b.X) return a.X < b.X;
   if (a.Y != b.Y) return a.Y < b.Y;
   return a.Z < b.Z;
 }
 template <typename T, typename SS>
 ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {
   ofs <<  (   << p.first <<   ,   << p.second <<   ) ;
   return ofs;
 }
 template <typename T>
 void print(T a) {
   for (auto i : a) cout << i << ' ';
   cout << '
';
 }
 template <typename T>
 T max(T a, T b, T c) {
   return max(a, max(b, c));
 }
 template <typename T>
 T min(T a, T b, T c) {
   return min(a, min(b, c));
 }
 template <typename T, typename D>
 D min(T a) {
   return *min_element(a.begin(), a.end());
 }
 template <typename T, typename D>
 D max(T a) {
   return *max_element(a.begin(), a.end());
 }
 struct custom_hash {
   static uint64_t splitmix64(uint64_t x) {
     x += 0x9e3779b97f4a7c15;
     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
     x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
     return x ^ (x >> 31);
   }
   size_t operator()(uint64_t x) const {
     static const uint64_t FIXED_RANDOM =
         chrono::steady_clock::now().time_since_epoch().count();
     return splitmix64(x + FIXED_RANDOM);
   }
 };
 void solve() {
   string s;
   cin >> s;
   if ((long long)(s.size()) & 1) s =  0  + s;
   long long n = (long long)(s.size());
   for (long long i = 0; i < (n); i++) s[i] -= '0';
   reverse(s.begin(), s.end());
   vector<vector<long long> > dp(n / 2 + 1, vector<long long>(4));
   dp[0][0] = 1;
   for (long long i = 0; i < (n / 2); i++)
     for (long long j = 0; j < (4); j++) {
       long long x = 2 * i, y = x + 1;
       long long dx = j & 1, dy = j >> 1;
       for (long long d11 = 0; d11 < (10); d11++)
         for (long long d12 = 0; d12 < (10); d12++) {
           long long sx = d11 + d12 + dx;
           if (sx % 10 != s[x]) continue;
           long long nmask = (sx >= 10);
           for (long long d21 = 0; d21 < (10); d21++)
             for (long long d22 = 0; d22 < (10); d22++) {
               long long sy = d21 + d22 + dy;
               if (sy % 10 != s[y]) continue;
               if (sy >= 10) nmask |= 2;
               dp[i + 1][nmask] += dp[i][j];
             }
         }
     }
   cout << dp[n / 2][0] - 2 << '
';
 };
 signed main() {
   if (0) {
     freopen(
          a
          .in ,
          r , stdin);
     freopen(
          a
          .out ,
          w , stdout);
   }
   srand(time(NULL));
   cin.tie(0);
   cout.tie(0);
   ios_base::sync_with_stdio(false);
   long long t = 1;
   cin >> t;
   for (long long _ = 0; _ < (t); _++) solve();
 }


#include <bits/stdc++.h>
 using namespace std;
 const double pi = acos(-1.0);
 const int MAXN = 200005;
 int n, x[MAXN];
 long long a[MAXN], t;
 long long b[MAXN];
 void solve() {
   for (int i = 0; i + 1 < n; i++) {
     if (x[i] > x[i + 1]) {
       cout <<  No  << endl;
       return;
     }
   }
   for (int i = 0; i < n; i++) {
     if (i > x[i]) {
       cout <<  No  << endl;
       return;
     }
   }
   for (int i = 0; i < n;) {
     int pos = x[i];
     int j = i;
     while (j < n && x[j] == pos) {
       j++;
     }
     if (j < x[i] + 1) {
       cout <<  No  << endl;
       return;
     }
     long long num = a[j - 1];
     for (int k = i; k + 1 < j; k++) {
       b[k] = a[k + 1] + t;
     }
     b[j - 1] = a[j - 1] + t + (j - i > 1);
     if (j < n && b[j - 1] >= a[j] + t) {
       cout <<  No  << endl;
       return;
     }
     i = j;
   }
   cout <<  Yes  << endl;
   for (int i = 0; i < n; i++) {
     cout << b[i] << ' ';
   }
   cout << endl;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   while (cin >> n >> t) {
     for (int i = 0; i < n; i++) {
       cin >> a[i];
     }
     for (int i = 0; i < n; i++) {
       cin >> x[i];
       x[i]--;
     }
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int N, Q, C, Rt, L[200005], R[200005], G[200005], F[200005], ch[200005][2];
 struct Nod {
   int Now, Max, Min, Laz;
   Nod() {
     Min = 1 << 30;
     Max = -Min;
   }
 } T[200005];
 vector<int> son[200005];
 void Upd(int x, int k) {
   if (x) T[x].Now += k, T[x].Max += k, T[x].Min += k, T[x].Laz += k;
 }
 void Up(int x) {
   int l = ch[x][0], r = ch[x][1];
   T[x].Max = max(T[x].Now, max(T[l].Max, T[r].Max));
   T[x].Min = min(T[x].Now, min(T[l].Min, T[r].Min));
 }
 void Dn(int x) {
   int k = T[x].Laz;
   if (k) Upd(ch[x][0], k), Upd(ch[x][1], k), T[x].Laz = 0;
 }
 void Rot(int x) {
   int y = F[x], z = F[y], k = ch[y][0] == x, t;
   if (t = ch[y][!k] = ch[x][k]) F[t] = y;
   if (F[x] = z) ch[z][ch[z][1] == y] = x;
   ch[F[y] = x][k] = y;
   Up(y);
 }
 void Splay(int x, int Aim) {
   for (Dn(x); F[x] ^ Aim; Rot(x)) {
     int y = F[x], z = F[y];
     Dn(z);
     Dn(y);
     Dn(x);
     if (F[y] ^ Aim) (ch[z][0] == y ^ ch[y][0] == x) ? Rot(x) : Rot(y);
   }
   Up(x);
   if (!Aim) Rt = x;
 }
 void DFS(int u, int d) {
   L[u] = ++C;
   G[C] = u;
   T[C].Now = d;
   for (int i = 1, lim = son[u].size(); i <= lim; i++) DFS(son[u][i - 1], d + 1);
   R[u] = ++C;
   G[C] = u;
   T[C].Now = d;
 }
 void Build(int& u, int l, int r, int fa) {
   F[u = l + r >> 1] = fa;
   if (l < u) Build(ch[u][0], l, u - 1, u);
   if (u < r) Build(ch[u][1], u + 1, r, u);
   Up(u);
 }
 int Find(int x, int k) {
   int l = ch[x][0], r = ch[x][1];
   Dn(x);
   if (T[r].Min <= k && k <= T[r].Max) return Find(r, k);
   return T[x].Now == k ? x : Find(l, k);
 }
 int Pre(int x) {
   Splay(x, 0);
   x = ch[x][0];
   for (; ch[x][1]; x = ch[x][1]) Dn(x);
   return x;
 }
 int Suf(int x) {
   Splay(x, 0);
   x = ch[x][1];
   for (; ch[x][0]; x = ch[x][0]) Dn(x);
   return x;
 }
 void Get(int x, int y) {
   Splay(x, 0);
   Splay(y, x);
 }
 int main() {
   scanf( %d%d , &N, &Q);
   for (int i = 1, lim = N; i <= lim; i++) {
     int x, t;
     scanf( %d , &x);
     for (; x--;) scanf( %d , &t), son[i].push_back(t);
   }
   C++;
   DFS(1, 1);
   C++;
   Build(Rt, 1, C, 0);
   for (int k, x, y, z, l, r, w, t; Q--;) {
     scanf( %d , &k);
     if (k == 1) {
       scanf( %d%d , &x, &y);
       if (x == y)
         puts( 0 );
       else {
         x = L[x];
         y = L[y];
         Get(x, y);
         z = (ch[x][0] == y ? T[ch[y][1]] : T[ch[y][0]]).Min;
         printf( %d
 ,
                T[x].Now + T[y].Now - 2 * min(z - 1, min(T[x].Now, T[y].Now)));
       }
     } else if (k == 2) {
       scanf( %d%d , &x, &y);
       Get(1, L[x]);
       w = G[Find(ch[L[x]][0], T[L[x]].Now - y)];
       l = Pre(L[x]);
       r = Suf(R[x]);
       Get(l, r);
       t = ch[r][0];
       ch[r][0] = 0;
       Up(r);
       Up(l);
       r = R[w];
       l = Pre(r);
       Get(l, r);
       ch[r][0] = t;
       F[t] = r;
       Upd(t, -y + 1);
       Splay(t, 0);
     } else
       scanf( %d , &x), printf( %d
 , G[Find(Rt, x + 1)]);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 112, INF = 1e18;
 long long t, n, m, a[N];
 long long B10(string s) {
   reverse(s.begin(), s.end());
   long long ret = 0;
   for (long long i = 0; i < s.size(); i++) {
     if (s[i] == '1') ret += (1ll << i);
   }
   return ret;
 }
 string B2(long long a) {
   string ret;
   for (long long i = 0; i < m; i++) {
     if (a & (1ll << i))
       ret += '1';
     else
       ret += '0';
   }
   reverse(ret.begin(), ret.end());
   return ret;
 }
 long long BS() {
   long long low = 0, high = (1ll << m);
   while (high - low > 1) {
     long long mid = (low + high) >> 1;
     long long v1 = mid - (lower_bound(a, a + n, mid) - a);
     long long v2 = ((1ll << m) - n - 1) / 2;
     if (v1 <= v2)
       low = mid;
     else
       high = mid;
   }
   return low;
 }
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> t;
   while (t--) {
     cin >> n >> m;
     for (long long i = 0; i < n; i++) {
       string s;
       cin >> s;
       a[i] = B10(s);
     }
     sort(a, a + n);
     cout << B2(BS()) << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int p[100100];
 int main() {
   int n, a, b, t, cn = 1;
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> a;
     p[i] = a;
   }
   sort(p, p + n);
   int ans = 0;
   vector<int> v;
   for (int i = 0; i < n; i++) {
     int j = 0;
     for (j = 0; j < v.size(); j++) {
       if (p[i] >= v[j]) {
         v[j]++;
         break;
       }
     }
     if (j == v.size()) {
       v.push_back(1);
     }
   }
   cout << v.size() << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char buf[25];
 struct node {
   long long x, y;
   bool operator<(node tp) const {
     if (x != tp.x) return x < tp.x;
     return y < tp.y;
   }
 };
 map<long long, long long> h1, h2;
 map<node, long long> t, q;
 const long long inf = 1e17;
 const long long maxn = 200010;
 long long L1[maxn], R1[maxn], l1[maxn], r1[maxn], s1[maxn], a[maxn];
 long long L2[maxn], R2[maxn], l2[maxn], r2[maxn], s2[maxn];
 long long n, m, sum1, sum2;
 long long ans;
 long long read() {
   long long x = 0, f = 0;
   char ch;
   do {
     ch = getchar();
     if (ch == '-') f = 1;
   } while (ch < '0' || ch > '9');
   while (ch >= '0' && ch <= '9') {
     x = (x << 1) + (x << 3) + (ch ^ 48);
     ch = getchar();
   }
   return f ? -x : x;
 }
 void write(long long x) {
   if (x < 0) {
     putchar('-');
     x = -x;
   }
   if (!x) {
     putchar('0');
     return;
   }
   long long cnt = 0;
   while (x) {
     buf[++cnt] = '0' + x % 10;
     x /= 10;
   }
   for (long long i = cnt; i >= 1; --i) putchar(buf[i]);
 }
 signed main() {
   srand(19267180);
   n = read();
   m = read();
   for (long long i = 1; i <= n; ++i) {
     h1[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;
     h2[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;
     sum1 = h1[i] ^ sum1;
     sum2 = h2[i] ^ sum2;
   }
   for (long long i = 1; i <= n; ++i) {
     long long l = read(), r = read();
     ++a[l];
     --a[r + 1];
     s1[l] ^= h1[i];
     s1[r + 1] ^= h1[i];
     L1[l - 1] ^= h1[i];
     R1[r + 1] ^= h1[i];
     s2[l] ^= h2[i];
     s2[r + 1] ^= h2[i];
     L2[l - 1] ^= h2[i];
     R2[r + 1] ^= h2[i];
   }
   for (long long i = m - 1; i >= 1; --i) L1[i] ^= L1[i + 1], L2[i] ^= L2[i + 1];
   for (long long i = 2; i <= m; ++i) {
     R1[i] ^= R1[i - 1], s1[i] ^= s1[i - 1];
     R2[i] ^= R2[i - 1], s2[i] ^= s2[i - 1];
   }
   for (long long i = 2; i <= m; ++i) s1[i] ^= s1[i - 1], s2[i] ^= s2[i - 1];
   for (long long i = 1; i <= m; ++i) {
     l1[i] = s1[i - 1] ^ R1[i], r1[i] = s1[i] ^ L1[i];
     l2[i] = s2[i - 1] ^ R2[i], r2[i] = s2[i] ^ L2[i];
   }
   for (long long i = m; i >= 1; --i) {
     t[(node){r1[i], r2[i]}] += 1;
     q[(node){r1[i], r2[i]}] += i;
     long long x_1 = sum1 ^ l1[i], x_2 = sum2 ^ l2[i];
     ans += q[(node){x_1, x_2}] - 1ll * t[(node){x_1, x_2}] * (i - 1);
   }
   for (long long i = 1; i <= m; ++i) a[i] += a[i - 1];
   long long x = 0;
   for (long long i = 1; i <= m; ++i) {
     if (a[i] == 0)
       ++x;
     else
       x = 0;
     if (x)
       if (i == m || a[i + 1] != 0)
         for (long long j = 1; j <= x; ++j) ans -= 1ll * j * (x - j + 1);
   }
   write(ans);
   return 0;
 }