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

 const int MAX = 1 << 20;
 bitset<MAX> dpgl, mv, dp[20];
 map<char, int> to;
 char rv[20];
 int cnt[20], le[20], ri[20], n, A, B, b;

 void solve(int ms) {
     int L = 1e9, R = -1, tot = 0;
     vector<int> tr, chr, oth;
     for(int i = 0; i < b; i++) {
         if(ms & (1 << i)) {
             L = min(L, le[i]);
             R = max(R, ri[i]);
             tot += cnt[i];
             chr.push_back(i);
             if(dp[i][ms ^ (1 << i)])
                 dp[i][ms] = dpgl[ms] = 1;
         }
         else
             oth.push_back(i);
     }

     if(tot >= ((R - L + 1) * A + B - 1) / B)
         mv[ms] = 1;

     if(oth.empty())
         return;

     sort(chr.begin(), chr.end(), [&](int a, int b){ return le[a] < le[b]; });
     int cms = 0;
     for(auto c : chr) {
         cms |= (1 << c);
         if(mv[cms] && dpgl[cms] && dp[oth[0]][ms ^ cms]) {
             for(auto tc : oth)
                 dp[tc][ms] = 1;
             return;
         }
     }
 }

 int main() {
     ios_base::sync_with_stdio(false);
     cin.tie(0);

     cin >> n >> A >> B;
     string s;
     cin >> s;

     for(auto &c : s) {
         if(!to.count(c)) {
             rv[b] = c;
             to[c] = b++;
         }
     }

     for(int i = 0; i < s.size(); i++) {
         cnt[to[s[i]]]++;
         ri[to[s[i]]] = i;
     }
     for(int i = s.size() - 1; i >= 0; i--)
         le[to[s[i]]] = i;

     dpgl[0] = mv[0] = 1;
     for(int i = 0; i < b; i++) {
         dp[i][0] = dp[i][1 << i] = 1;
         dpgl[1 << i] = 1;
     }

     for(int i = 1; i < (1 << b); i++)
         solve(i);

     vector<char> ans;

     for(int i = 0; i < b; i++)
         if(dp[i][(1 << b) - 1])
             ans.push_back(rv[i]);

     sort(ans.begin(), ans.end());

     cout << ans.size();
     for(auto &c : ans)
         cout << ' ' << c;
     cout << '
';

     /*for(int i = 0; i < (1 << b); i++) {
         for(int j = 0; j < b; j++)
             cout << bitset<4>(i) << ' ' << j << ' ' << dp[j][i] << '
';
     }

     cout << '
';*/
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1e9+7, M = (1e9+7), MAXN = 1 * 2e5;
 int A[MAXN], C[MAXN];

 int64_t modpow(int64_t a, int64_t b) {
     int64_t res = 1;
     for(; b; b >>= 1) {
         if(b&1)
             res=res*a%M;
         a=a*a%M;
     }
     return res;
 }
 void solve() {
     const int MOD = M;
     int N, M;
     cin >> N >> M;
     vector<string> G(N);
     for(int i = 0; i < N; i++)
         cin >> G[i];

     int cnt = 0;
     for(int i = 0; i < N; i++)
         cnt += count(G[i].begin(), G[i].end(), '#');
     cerr << 'Count: ' << cnt << endl;
     int64_t x = modpow(2, cnt);
     if(cnt == N * M) {
         cout << (x - 1 + MOD) % MOD << endl;
     } else {
         cout << modpow(2, cnt) << endl;
     }
 }
 int main() {
     cin.tie(0)->sync_with_stdio(0);
     int T; cin >> T;

     while(T--) {
         solve();
     }
 }


 #include <iostream>
 #include <fstream>
 #include <vector>
 #include <algorithm>
 #include <cmath>
 #include <iomanip>
 #include <cstring>

 std::ifstream fin('input.txt');
 std::ofstream fout('output.txt');

 int main(){
     std::ios_base::sync_with_stdio(false);
     std::cin.tie(NULL);
     std::cout.tie(NULL);
     std::cout << std::setprecision(6) << std::fixed << '
';
     int Q;
     std::cin >> Q;
     while(Q --){
         int n, m;
         std::cin >> n >> m;
         int x[n], pos;
         long double ans = 0;
         for(int i=0; i<n; i++) std::cin >> x[i];

         for(pos=n-1; pos>=0 and x[pos] == pos+1; pos--);

         if(pos == -1) ans = 1;

         while(m --){
             int p;
             long double prob;
             std::cin >> p >> prob; p--;
             if(p >= pos){
                 ans = 1.0 - (1.0 - ans) * (1.0 - prob);
             }
         }
         std::cout << ans << '
';
     }

     return 0;

 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100010;
 long long int A[N];
 vector<int> g[N];
 long long int dfs(int x, int p) {
   A[x] = 1;
   for (int i = 0; i < g[x].size(); ++i) {
     int y = g[x][i];
     if (y == p) continue;
     A[x] += dfs(y, x);
   }
   return A[x];
 }
 long double E[N];
 void solve(int x, int p) {
   long long int n = (long long int)g[x].size();
   for (int i = 0; i < g[x].size(); ++i) {
     int y = g[x][i];
     if (y == p) continue;
     E[y] = E[x] + 1;
     long double med = (A[x] - 1 - A[y]) / (long double)(n - 1);
     if (g[x].size() != 1) {
       E[y] += (med * (n - 1)) / (2.0);
     }
     solve(y, x);
   }
 }
 int main(void) {
   ios::sync_with_stdio(false);
   int n;
   cin >> n;
   for (int i = 2; i <= n; ++i) {
     int x;
     cin >> x;
     g[x].push_back(i);
     g[i].push_back(x);
   }
   E[1] = 1.0;
   dfs(1, -1);
   solve(1, -1);
   cout.precision(10);
   for (int i = 1; i <= n; ++i) {
     cout << fixed << E[i] << ' ';
   }
   cout << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 1200;
 int x, y;
 bool run() {
   bool fox = true;
   while (1) {
     if (fox) {
       if (x == 0) {
         if (y >= 22) {
           y -= 22;
         } else {
           return false;
         }
       } else if (x == 1) {
         if (y >= 12) {
           y -= 12;
         } else {
           return false;
         }
       } else {
         if (y >= 2) {
           x -= 2;
           y -= 2;
         } else {
           return false;
         }
       }
     } else {
       if (y >= 22) {
         y -= 22;
       } else if (y >= 12) {
         y -= 12;
         if (x == 0) {
           return true;
         } else {
           x--;
         }
       } else if (y >= 2) {
         y -= 2;
         if (x < 2) {
           return true;
         } else {
           x -= 2;
         }
       } else {
         return true;
       }
     }
     fox ^= 1;
   }
   return false;
 }
 int main() {
   scanf('%d%d', &x, &y);
   if (run()) {
     puts('Ciel');
   } else {
     puts('Hanako');
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e3 + 5;
 const int maxm = 1 << 13;
 int n;
 long long k;
 pair<int, long long> dp[maxn][maxm];
 int pre[maxn][maxm];
 long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
 vector<long long> v;
 void get_div(long long k) {
   for (long long i = 1; i * i <= k; i++) {
     if (k % i == 0) {
       long long j = k / i;
       v.push_back(i);
       if (i != j) v.push_back(j);
     }
   }
   sort(v.begin(), v.end());
 }
 long long a[maxn], c[maxn];
 int main() {
   scanf('%d%lld', &n, &k);
   get_div(k);
   for (int i = 1; i <= n; i++) {
     scanf('%lld', &a[i]);
     c[i] = gcd(a[i], k);
   }
   if (k == 1) {
     printf('1
');
     int p = 1;
     long long minn = a[1];
     for (int i = 2; i <= n; i++) {
       if (a[i] < minn) minn = a[i], p = i;
     }
     printf('%d
', p);
     return 0;
   }
   int m = v.size();
   for (int i = 0; i <= n; i++)
     for (int j = 0; j < m; j++) dp[i][j] = make_pair((int)1e9, (long long)1e16);
   dp[0][0] = make_pair(0, 0);
   for (int i = 1; i <= n; i++)
     for (int j = 0; j < m; j++) {
       if (dp[i][j] > dp[i - 1][j]) {
         dp[i][j] = dp[i - 1][j];
         pre[i][j] = j;
       }
       int t =
           lower_bound(v.begin(), v.end(), v[j] / gcd(v[j], c[i])) - v.begin();
       if (dp[i][j] >
           make_pair(dp[i - 1][t].first + 1, dp[i - 1][t].second + a[i])) {
         dp[i][j] =
             make_pair(dp[i - 1][t].first + 1, dp[i - 1][t].second + a[i]);
         pre[i][j] = t;
       }
     }
   if (dp[n][m - 1].first > n)
     printf('-1
');
   else {
     printf('%d
', dp[n][m - 1].first);
     int k = m - 1;
     bool first = true;
     for (int i = n; i >= 1; i--) {
       if (pre[i][k] != k) {
         if (first) {
           printf('%d', i);
           first = false;
         } else
           printf(' %d', i);
       }
       k = pre[i][k];
     }
   }
   printf('
');
   return 0;
 }


#include<bits/stdc++.h>
 #include<string.h>
 #define int long long
 #include<vector>
 #define rep(i,a,b)        for(int i=a;i<b;i++)
 #define pb                push_back
 #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 using namespace std;
 const int N=2e5+5;

 vector<int> v[N];
 int siz[N];
 int lvl[N];

 int forefather[N];

 int tim = 0, st[N], et[N];

 void dfs(int z,int p = -1,int ff = 0){
 	if(p == -1) lvl[z] = 0;
 	else lvl[z] = lvl[p] + 1;

 	if(lvl[z] == 1) ff = z;
 	forefather[z] = ff;

 	st[z] = tim++;

 	siz[z] = 1;
 	for(int x:v[z]){
 		if(x == p) continue;
 		dfs(x,z,ff);
 		siz[z] += siz[x];
 	}
 	et[z] = tim;
 }

 // x is ancestor of y
 bool ancestor(int x,int y){
 	if(st[y] > st[x] && et[y] <= et[x]){
 		return true;
 	}
 	return false;
 }

 int calc(int x,int y){
 	if(y == 0) swap(x,y);
 	if(x == 0){
 		return siz[y] * (siz[0] - siz[forefather[y]]);
 	}
 	return siz[x] * siz[y];
 }

 void solve(){
 	tim = 0;
 	int n;
 	cin >> n;
 	rep(i,0,n){
 		v[i].clear();
 		siz[i] = 0;
 		lvl[i] = 0;
 		forefather[i] = 0;
 	}
 	rep(i,1,n){
 		int x,y;
 		cin >> x >> y;
 		v[x].pb(y);
 		v[y].pb(x);
 	}

 	dfs(0);

 	int paths = n * (n - 1) / 2;
 	int donthavezero = 0;
 	rep(i,1,n){
 		if(lvl[i] != 1) continue;
 		donthavezero += siz[i] * (siz[i] - 1) / 2;
 	}
 	cout << donthavezero << ' ';
 	paths -= donthavezero;

 	int a = 0, b = 0;

 	rep(i,1,n){
 		if(paths == 0){
 			cout << 0 << ' ';
 			continue;
 		}
 		if(a == 0) swap(a,b);
 		if(ancestor(i,a) || ancestor(i,b)){
 			cout << 0 << ' ';
 			continue;
 		}
 		if(ancestor(a,i)){
 			a = i;
 			int wont_work = calc(a,b);
 			cout << paths - wont_work << ' ';
 			paths = wont_work;
 		}
 		else if(ancestor(b,i)){
 			if(forefather[i] == forefather[a]){
 				cout << paths << ' ';
 				paths = 0;
 				continue;
 			}
 			b = i;
 			int wont_work = calc(a,b);
 			cout << paths - wont_work << ' ';
 			paths = wont_work;
 		}
 		else{
 			cout << paths << ' ';
 			paths = 0;
 		}
 	}

 	cout << paths;

 	cout << '
';
 }
 signed main(){
 	ios_base::sync_with_stdio(false);
 	cin.tie(0);cout.tie(0);

 	int t=1;
 	cin>>t;
 	while(t--) solve();
 	return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long ans = -((long long)1 << 62);
 int n, u, r;
 int a[105];
 int b[105];
 int k[105];
 int p[105];
 void process(int m, int op) {
   if (((u - m) & 1) == 0) {
     long long an = 0;
     for (int i = 1; i <= n; i++) an += a[i] * k[i];
     ans = max(an, ans);
   }
   if (m == u) {
     return;
   }
   if (op == 0) {
     for (int i = 1; i <= n; i++) a[i] ^= b[i];
     process(m + 1, 1);
     for (int i = 1; i <= n; i++) a[i] ^= b[i];
   }
   vector<int> a1;
   a1.push_back(1);
   for (int i = 1; i <= n; i++) a1.push_back(a[i]);
   for (int i = 1; i <= n; i++) a[i] = a1[p[i]] + r;
   process(m + 1, 0);
   for (int i = 1; i <= n; i++) a[i] = a1[i];
 }
 int main() {
   scanf('%d %d %d', &n, &u, &r);
   for (int i = 1; i <= n; i++) scanf('%d', &a[i]);
   for (int i = 1; i <= n; i++) scanf('%d', &b[i]);
   for (int i = 1; i <= n; i++) scanf('%d', &k[i]);
   for (int i = 1; i <= n; i++) scanf('%d', &p[i]);
   process(0, 0);
   printf('%I64d', ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   int m;
   int k;
   vector<vector<int> > A;
   cin >> n >> m >> k;
   for (int i = 0; i < n; i++) {
     vector<int> X;
     for (int j = 0; j < m; j++) {
       int l;
       cin >> l;
       X.push_back(l);
     }
     A.push_back(X);
   }
   int totalSum = 0;
   int changes = 0;
   for (int j = 0; j < m; j++) {
     int maxSum = 0;
     vector<int> maxI;
     maxI.push_back(0);
     for (int i = 0; i < n; i++) {
       if (A[i][j] == 1) {
         int sum = 0;
         for (int z = i; z < min(i + k, n); z++) {
           sum += A[z][j];
         }
         if (sum > maxSum) {
           maxSum = sum;
           for (int elem = 0; elem < maxI.size(); elem++) {
             maxI[elem] = i;
           }
         } else if (sum == maxSum) {
           maxI.push_back(i);
         }
       }
     }
     int minimumChanges = 10000000;
     for (auto elem : maxI) {
       int toChange = 0;
       for (int i = 0; i < elem; i++) {
         if (A[i][j] == 1) {
           toChange++;
         }
       }
       if (toChange < minimumChanges) {
         minimumChanges = toChange;
       }
     }
     changes += minimumChanges;
     totalSum += maxSum;
   }
   cout << totalSum << ' ' << changes;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxh = 200 * 1000 + 5;
 struct item {
   int pos, hash;
   item(int pos, int hash) : pos(pos), hash(hash) {}
 };
 bool operator<(item a, item b) { return a.pos < b.pos; }
 int n, m, h;
 set<item> S[maxh];
 map<int, int> M;
 int pos[maxh];
 int Len[maxh];
 int Base[maxh];
 bool used[maxh];
 long long add(int x, int hash) {
   int base = Base[hash];
   set<item>::iterator it = S[base].lower_bound(item(pos[hash], hash));
   if (it == S[base].end()) {
     it = S[base].begin();
   }
   int nhash = it->hash;
   M[x] = nhash;
   S[base].erase(it);
   long long res = pos[nhash] - pos[hash];
   if (res < 0) {
     res += Len[base];
   }
   return res;
 }
 void del(int x) {
   int base = Base[M[x]];
   S[base].insert(item(pos[M[x]], M[x]));
 }
 int main() {
   scanf('%d%d%d', &h, &m, &n);
   for (int i = 0; i < h; ++i) {
     if (used[i]) {
       continue;
     }
     for (int j = i, p = 0; !used[j]; j += m, j %= h, ++p) {
       S[i].insert(item(p, j));
       pos[j] = p;
       Base[j] = i;
       used[j] = 1;
     }
     Len[i] = (int)S[i].size();
   }
   long long res = 0;
   for (int i = 0; i < n; ++i) {
     char op;
     int id;
     scanf('
%c %d', &op, &id);
     if (op == '+') {
       int hash;
       scanf('%d', &hash);
       res += add(id, hash);
     } else {
       del(id);
     }
   }
   printf('%I64d
', res);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long const MAXN = 5e1 + 8;
 long long const INF = 3e3 + 8;
 long long const delta = 1000000007;
 long long a[MAXN];
 long long dp[MAXN][MAXN][INF];
 double calc(long long t, long long n, long long b) {
   double ans = t;
   for (long long i = b + 1; i <= n; i++) ans /= (double)i;
   for (long long i = 1; i <= n - b; i++) ans *= (double)i;
   return ans;
 }
 int main() {
   std::ios::sync_with_stdio(0);
   ;
   cin.tie(0);
   cout.tie(0);
   long long n;
   cin >> n;
   for (long long i = 1; i <= n; i++) cin >> a[i];
   long long p;
   cin >> p;
   cout.precision(10);
   cout << fixed;
   double ans = 0;
   dp[0][0][0] = 1;
   for (long long i = 1; i <= n; i++) {
     for (long long j = 0; j <= n; j++) {
       for (long long k = 0; k < INF; k++) {
         dp[i][j][k] = dp[i - 1][j][k];
         if (j && k >= a[i]) dp[i][j][k] += dp[i - 1][j - 1][k - a[i]];
       }
     }
   }
   for (long long i = 1; i <= p; i++) {
     for (long long j = 1; j <= n; j++) ans += calc(dp[n][j][i], n, j);
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 5005;
 const int K = 100005;
 int n, m, k;
 int t, p;
 int l[N], c[N], x[K];
 int main() {
   scanf('%d%d%d', &n, &m, &k);
   x[0] = 0;
   for (int i = 1; i <= k; ++i) {
     scanf('%d%d%d', &t, &p, &x[i]);
     if (t == 1)
       l[--p] = i;
     else
       c[--p] = i;
   }
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) printf('%d ', x[max(l[i], c[j])]);
     printf('
');
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int N, K;
 long double ans, s;
 int R[1000010], data[100010];
 int v[1000010], c[1000010];
 int STv[20][1000010], STc[20][1000010];
 int calcv(int l, int r) {
   int delta = r - l + 1;
   int t = log(delta) / log(2);
   return max(STv[t][l], STv[t][r - (1 << t) + 1]);
 }
 int calcc(int l, int r) {
   int delta = r - l + 1;
   int t = log(delta) / log(2);
   return min(STc[t][l], STc[t][r - (1 << t) + 1]);
 }
 int main() {
   scanf('%d%d', &N, &K);
   for (int i = 1; i <= N; i++) scanf('%d', &v[i]), v[i] *= 100;
   for (int i = 1; i <= N; i++) scanf('%d', &c[i]);
   for (int i = 1; i <= N; i++) STv[0][i] = v[i], STc[0][i] = c[i];
   for (int step = 1; step <= 19; step++)
     for (int i = 1; i <= N; i++) {
       STv[step][i] = STv[step - 1][i];
       STc[step][i] = STc[step - 1][i];
       int x = i + (1 << (step - 1));
       if (x <= N) {
         STv[step][i] = max(STv[step][i], STv[step - 1][x]);
         STc[step][i] = min(STc[step][i], STc[step - 1][x]);
       }
     }
   R[0] = 1;
   for (int l = 1; l <= N; l++) {
     R[l] = R[l - 1];
     for (int r = max(R[l - 1], l); r <= N; r++)
       if (calcv(l, r) <= calcc(l, r))
         R[l] = r;
       else
         break;
   }
   for (int l = 1; l <= N; l++) {
     if (R[l] < N && min(calcv(l, R[l]), calcc(l, R[l])) <
                         min(calcv(l, R[l] + 1), calcc(l, R[l] + 1)))
       R[l]++;
     data[l] = min(calcv(l, R[l]), calcc(l, R[l]));
   }
   sort(data + 1, data + N + 1);
   s = double(K) / (N - K + 1);
   for (int l = 1; l + K - 1 <= N; l++) {
     s = s / (N - l + 1) * (N - K - l + 2);
     ans = ans + data[l] * s;
   }
   printf('%.15lf', double(ans));
 }


#include <bits/stdc++.h>
 int main() {
   int i;
   char a[1000];
   gets(a);
   for (i = 0; i < strlen(a); i++) {
     printf('%c', a[i]);
   }
   for (i = strlen(a) - 1; i >= 0; i--) {
     printf('%c', a[i]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 42, K = 11;
 int n, k, cnt, mark[N], nw[K];
 vector<long long> v[K], mask[K];
 void do_it(long long u, int x) {
   for (int i = 0; i < nw[x] + 1; i++) {
     int cnt = i + __builtin_popcountll(u & mask[x].back());
     v[x + 1].push_back((u & (1ll << n) - 1 - mask[x].back()) | mask[x][cnt]);
   }
 }
 int main() {
   cin >> n >> k;
   for (int i = 0; i < k; i++) {
     int x, u;
     long long msk = 0;
     mask[i].push_back(0);
     cin >> x;
     for (int j = 0; j < x; j++) {
       cin >> u;
       u--;
       msk |= (1ll << u);
       mask[i].push_back(msk);
       if (!mark[u]) {
         cnt++;
         nw[i]++;
         mark[u] = 1;
       }
     }
   }
   v[0].push_back(0);
   for (int i = 0; i < k; i++) {
     for (int j = 0; j < v[i].size(); j++) {
       do_it(v[i][j], i);
     }
   }
   if (n != cnt && n > 1) return cout << 'REJECTED' << endl, 0;
   for (int i = 0; i < v[k].size(); i++) {
     int cnt = __builtin_popcountll(v[k][i]);
     if ((1ll << cnt) - 1 != v[k][i]) return cout << 'REJECTED' << endl, 0;
   }
   cout << 'ACCEPTED' << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long PRIME = 1000000007;
 long long n, m, k;
 long long maxm = (long long)(-10e13);
 long long a[100005][6];
 long long max_in_range[100005][6][20];
 long long ans[6];
 long long times(long long length) {
   long long cnt = 0;
   while (length >= 2) {
     length /= 2;
     cnt++;
   }
   return cnt;
 }
 void calculate(long long index, long long length) {
   long long t = times(length);
   for (long long d = 1; d <= m; d++) {
     ans[d] = max(max_in_range[index][d][t],
                  max_in_range[index + length - (1 << t)][d][t]);
   }
 }
 long long query(long long index, long long length) {
   long long t = times(length);
   long long sum = 0;
   for (long long d = 1; d <= m; d++) {
     sum += max(max_in_range[index][d][t],
                max_in_range[index + length - (1 << t)][d][t]);
   }
   return sum;
 }
 long long search(long long index, long long startlength, long long endlength) {
   if (startlength == endlength) {
     return startlength;
   }
   if (endlength - startlength == 1) {
     if (query(index, endlength) <= k) {
       return endlength;
     }
     return startlength;
   }
   long long mid = (startlength + endlength) / 2;
   long long val = query(index, mid);
   if (val > k) {
     return search(index, startlength, mid - 1);
   } else {
     return search(index, mid, endlength);
   }
 }
 void solve() {
   cin >> n >> m >> k;
   for (long long i = 1; i <= n; i++) {
     for (long long j = 1; j <= m; j++) {
       cin >> a[i][j];
     }
   }
   long long maxallowed = 0;
   for (long long p = 0; p < 20; p++) {
     for (long long i = 1; i <= n; i++) {
       long long sum = 0;
       for (long long d = 1; d <= m; d++) {
         if (p == 0) {
           max_in_range[i][d][p] = a[i][d];
         } else if (i + (1 << p) - 1 > n) {
           max_in_range[i][d][p] = (long long)(10e13);
         } else {
           max_in_range[i][d][p] =
               max(max_in_range[i][d][p - 1],
                   max_in_range[i + (1 << (p - 1))][d][p - 1]);
         }
         sum += max_in_range[i][d][p];
       }
       if (sum <= k) {
         maxallowed = p;
       }
     }
   }
   for (long long i = 1; i <= n; i++) {
     long long sum = 0;
     for (long long d = 1; d <= m; d++) {
       sum += max_in_range[i][d][maxallowed];
     }
     if (sum > k) {
       continue;
     } else {
       long long l = search(i, (1 << maxallowed), (1 << (maxallowed + 1)) - 1);
       if (l >= maxm) {
         calculate(i, l);
         maxm = l;
       }
     }
   }
   for (long long d = 1; d <= m; d++) {
     cout << ans[d] << ' ';
   }
 }
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int max(long long int a, long long int b) {
   if (a >= b)
     return a;
   else
     return b;
 }
 long long int min(long long int a, long long int b) {
   if (a >= b)
     return b;
   else
     return a;
 }
 long long int diff(long long int a, long long int b) {
   if (a >= b)
     return a - b;
   else
     return b - a;
 }
 long long int mod(long long int a) {
   if (a >= 0)
     return a;
   else
     return -a;
 }
 void pairsort(int a[], int b[], int n) {
   pair<int, int> pairt[n];
   for (int i = 0; i < n; i++) {
     pairt[i].first = a[i];
     pairt[i].second = b[i];
   }
   sort(pairt, pairt + n);
   for (int i = 0; i < n; i++) {
     a[i] = pairt[i].first;
     b[i] = pairt[i].second;
   }
 }
 int gcd(int a, int b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   char c;
   cin >> c;
   string s1, s2;
   char s[9] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
   cin >> s1 >> s2;
   int ind1, ind2;
   if (s1[1] == s2[1]) {
     for (int i = 0; i < 9; i++)
       if (s[i] == s1[0]) ind1 = i;
     for (int i = 0; i < 9; i++)
       if (s[i] == s2[0]) ind2 = i;
     if (ind1 > ind2)
       cout << 'YES';
     else
       cout << 'NO';
   } else {
     if (s1[1] == c)
       cout << 'YES';
     else
       cout << 'NO';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct p {
   int x, y, z;
 };
 int c[102][102][102] = {0};
 bool ck(int x, int y, int z) {
   if (!c[x][y][z]) return false;
   if (c[x - 1][y][z] && c[x + 1][y][z]) return true;
   if (c[x][y - 1][z] && c[x][y + 1][z]) return true;
   if (c[x][y][z - 1] && c[x][y][z + 1]) return true;
   if (c[x - 1][y][z] && c[x][y + 1][z] && !c[x - 1][y + 1][z]) return true;
   if (c[x - 1][y][z] && c[x][y][z + 1] && !c[x - 1][y][z + 1]) return true;
   if (c[x][y - 1][z] && c[x + 1][y][z] && !c[x + 1][y - 1][z]) return true;
   if (c[x][y - 1][z] && c[x][y][z + 1] && !c[x][y - 1][z + 1]) return true;
   if (c[x][y][z - 1] && c[x + 1][y][z] && !c[x + 1][y][z - 1]) return true;
   if (c[x][y][z - 1] && c[x][y + 1][z] && !c[x][y + 1][z - 1]) return true;
   return false;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   int n, m, k;
   cin >> n >> m >> k;
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= m; ++j) {
       string r;
       cin >> r;
       for (int l = 1; l <= k; ++l) c[i][j][l] = r[l - 1] == '1' ? 1 : 0;
     }
   }
   int ans = 0;
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= m; ++j) {
       for (int l = 1; l <= k; ++l) {
         if (ck(i, j, l)) ans++;
       }
     }
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int BIT = (1 << 17), M = 110, N = 25;
 int n, m, cnt[BIT], a[M];
 long long f[BIT][N], b[N], p[N], year;
 void solve(int x) {
   memset(f, 0, sizeof(f));
   f[0][0] = 1;
   int maxb = (1 << n);
   for (int i = 0; i < maxb; i++) {
     for (int j = 0; j <= n; j++) {
       int y = cnt[i] + 1;
       if (b[y]) {
         if ((a[b[y]] & i) != a[b[y]]) continue;
         if ((1 << (b[y] - 1) & i) == (1 << b[y] - 1)) continue;
         f[i | (1 << b[y] - 1)][j] += f[i][j];
       } else {
         for (int k = 1; k <= n; k++) {
           if (!(i & (1 << k - 1))) {
             if ((a[k] & i) != a[k]) continue;
             if (k == x)
               f[i | (1 << k - 1)][y] += f[i][j];
             else
               f[i | (1 << k - 1)][j] += f[i][j];
           }
         }
       }
     }
   }
 }
 int main() {
   scanf('%d%lld%d', &n, &year, &m);
   year -= 2000;
   for (int i = 1; i < BIT; i++) cnt[i] = cnt[i ^ (i & (-i))] + 1;
   for (int i = 1; i <= m; i++) {
     int x, y;
     scanf('%d%d', &x, &y);
     a[y] |= (1 << x - 1);
   }
   for (int i = 1; i <= n; i++) {
     solve(i);
     long long sum = 0;
     for (int j = 1; j <= n; j++) {
       if (!b[j] && sum + f[(1 << n) - 1][j] >= year) {
         b[j] = i;
         p[i] = j;
         year -= sum;
         break;
       }
       sum += f[(1 << n) - 1][j];
     }
     if (!p[i]) {
       puts('The times have changed');
       return 0;
     }
   }
   for (int i = 1; i <= n; i++) printf('%lld ', p[i]);
   puts('');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 multiset<int> all[40];
 long long s[40];
 int getpos(int x) {
   int ret = 0;
   while ((1 << ret) < x) ret++;
   return ret;
 }
 void check() {
   long long tot = 0LL;
   int ret = 0;
   for (int i = 0; i <= 31; i++) {
     ret += all[i].size();
     ret -= (all[i].size() && *(all[i].begin()) > 2 * tot);
     tot += s[i];
   }
   cout << ret << '
';
 }
 int main() {
   int q;
   cin >> q;
   while (q--) {
     string op;
     int x;
     cin >> op >> x;
     int id = getpos(x);
     if (op == '+') {
       s[id] += x;
       all[id].insert(x);
     } else {
       s[id] -= x;
       all[id].erase(all[id].find(x));
     }
     check();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, c, r[200001], u, v, i, t, k;
 vector<long long> graph[200001], ans;
 bool dfs(long long x, long long p) {
   long long s = 0;
   for (auto i : graph[x])
     if (i != p) s += dfs(i, x);
   if (r[x] && !s) ans.push_back(x);
   return s + (long long)(r[x] && r[p]);
 }
 int main() {
   cin >> n;
   for (i = 0; i < n - 1; i++) {
     cin >> u >> v >> t, graph[u].push_back(v), graph[v].push_back(u);
     if (t == 2) r[u] = 1, r[v] = 1;
   }
   dfs(1, 0);
   for (cout << ans.size() << endl, i = 0; i < ans.size(); i++)
     cout << ans[i] << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int n0 = 1003, m = 1e5, mod = 998244353;
 int n, k, a[n0], dp[2][n0], b[n0];
 int calc(int gap) {
   for (int i = 1; i <= n; i++)
     b[i] = upper_bound(a + 1, a + n + 1, a[i] - gap) - a - 1;
   memset(&dp, 0, sizeof(dp));
   for (int j = 0; j <= n; j++) dp[0][j] = 1;
   for (int i = 1; i <= k; i++) {
     dp[i & 1][0] = 0;
     for (int j = 1; j <= n; j++) {
       int &x = dp[i & 1][j];
       x = dp[i & 1][j - 1] + dp[(i - 1) & 1][b[j]];
       x = (x >= mod) ? (x - mod) : x;
     }
   }
   return dp[k & 1][n];
 }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0);
   cin >> n >> k;
   for (int i = 1; i <= n; i++) cin >> a[i];
   sort(a + 1, a + n + 1);
   int res = 0;
   for (int gap = 1; gap <= m / (k - 1); gap++) {
     res += calc(gap);
     if (res >= mod) res -= mod;
   }
   cout << res;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Room {
   int length, width, height, total_length;
 } room[500];
 struct Wallpaper {
   int length, width, price;
 } wallpaper[500];
 int main() {
   int n, m, i, j, ans, tmp, price, ret;
   cin >> n;
   for (i = 0; i < n; ++i) {
     cin >> room[i].length >> room[i].width >> room[i].height;
     room[i].total_length = 2 * (room[i].length + room[i].width);
   }
   cin >> m;
   for (i = 0; i < m; ++i)
     cin >> wallpaper[i].length >> wallpaper[i].width >> wallpaper[i].price;
   for (ret = i = 0; i < n; ++i) {
     for (price = 500 * 500 * 500, ans = j = 0; j < m; ++j) {
       tmp = wallpaper[j].length / room[i].height;
       tmp *= wallpaper[j].width;
       if (tmp == 0) continue;
       ans = (room[i].total_length / tmp +
              (room[i].total_length % tmp == 0 ? 0 : 1)) *
             wallpaper[j].price;
       price = min(price, ans);
     }
     ret += price;
   }
   cout << ret << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m;
   cin >> n >> m;
   if (n == 1)
     cout << 1;
   else if (abs(n - m) > abs(m - 1)) {
     cout << m + 1;
   } else {
     cout << m - 1;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n, a, b, diff;
   cin >> n >> a >> b;
   vector<long long int> v;
   long long int arr[n];
   for (long long int i = 0; i < n; i++) {
     cin >> arr[i];
     v.push_back(arr[i]);
   }
   sort(v.begin(), v.end());
   diff = v[n - a] - v[b - 1];
   if (diff < 0) {
     cout << '0' << endl;
   } else {
     cout << diff << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, q, k;
 vector<int> v[1000010];
 int lastans = 0, res[1000010];
 void dfs(int np, int fath, int val) {
   res[np] = val;
   for (auto &x : v[np]) {
     if (x == fath) continue;
     dfs(x, np, min(val, x));
   }
 }
 int main() {
   scanf('%d%d', &n, &q);
   for (int i = 1, ti, tj; i < n; i++) {
     scanf('%d%d', &ti, &tj);
     v[ti].push_back(tj);
     v[tj].push_back(ti);
   }
   int a, b;
   scanf('%d%d', &a, &b);
   b = b % n + 1;
   dfs(b, 0, b);
   lastans = 0;
   k = b;
   for (int i = 2, ti, tj; i <= q; i++) {
     scanf('%d%d', &ti, &tj);
     tj = (tj + lastans) % n + 1;
     if (ti == 1)
       k = min(k, res[tj]);
     else
       printf('%d
', lastans = min(k, res[tj]));
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long a[100];
 long long b[100];
 vector<long long> pos[101];
 int main() {
   long long i, j, k, l, m, n, t;
   scanf('%lld', &n);
   scanf('%lld', &k);
   for (i = 0; i < n; i++) {
     scanf('%lld', &a[i]);
     pos[a[i]].push_back(i);
   }
   long long sum = 0, count = 0;
   long long flag = 0;
   for (i = 1; i <= 100; i++) {
     for (j = 0; j < pos[i].size(); j++) {
       sum = sum + a[pos[i][j]];
       if (sum > k) {
         flag = 1;
         break;
       }
       b[count++] = pos[i][j];
     }
     if (flag == 1) break;
   }
   cout << count << endl;
   for (j = 0; j < count; j++) cout << b[j] + 1 << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
 int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
 template <class T>
 inline T biton(T n, T pos) {
   return n | ((T)1 << pos);
 }
 template <class T>
 inline T bitoff(T n, T pos) {
   return n & ~((T)1 << pos);
 }
 template <class T>
 inline T ison(T n, T pos) {
   return (bool)(n & ((T)1 << pos));
 }
 template <class T>
 inline T gcd(T a, T b) {
   while (b) {
     a %= b;
     swap(a, b);
   }
   return a;
 }
 template <typename T>
 string NumberToString(T Number) {
   ostringstream second;
   second << Number;
   return second.str();
 }
 inline int nxt() {
   int aaa;
   scanf('%d', &aaa);
   return aaa;
 }
 inline long long int lxt() {
   long long int aaa;
   scanf('%lld', &aaa);
   return aaa;
 }
 inline double dxt() {
   double aaa;
   scanf('%lf', &aaa);
   return aaa;
 }
 template <class T>
 inline T bigmod(T p, T e, T m) {
   T ret = 1;
   for (; e > 0; e >>= 1) {
     if (e & 1) ret = (ret * p) % m;
     p = (p * p) % m;
   }
   return (T)ret;
 }
 int ar[1000010];
 long long F(long long int limit, long long int a, long long int b) {
   if (limit < a) return 1LL;
   long long int sum = 1LL;
   long long int x = 0;
   while (true) {
     if (x + a > limit) break;
     long long int temp = (limit - x) / a;
     sum += temp;
     long long int r = (a * temp) + x;
     if (r - b < 0) break;
     temp = (r + b - 1) / b;
     temp--;
     sum += temp;
     r -= temp * b;
     x = r;
     if (x % a == 0) break;
   }
   return sum;
 }
 long long int get(long long int st, long long int len) {
   long long int sum = (len * len + len) / 2LL;
   sum *= st;
   return sum;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   long long n, a, b;
   cin >> n >> a >> b;
   long long limit = min(a + b - 2, n);
   long long sum = 0;
   for (long long i = 0; i <= limit; i++) {
     sum += F(i, a, b);
   }
   limit++;
   long long int gc = gcd(a, b);
   while (limit <= n) {
     if (limit % gc == 0) break;
     sum += (limit / gc) + 1;
     limit++;
   }
   long long int upperLimit = n;
   while (upperLimit >= limit) {
     sum += (upperLimit / gc) + 1;
     if (upperLimit % gc == 0) break;
     upperLimit--;
   }
   if (upperLimit > limit) {
     long long int diff = (upperLimit - limit);
     sum += diff;
     diff /= gc;
     long long int chunk = limit * diff + get(gc, diff - 1);
     sum += chunk;
   }
   cout << sum << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k, A[2005], DP[2005];
 inline int ok(int X) {
   memset(DP, 0, sizeof(DP));
   int i, j;
   long long l1, r1, l2, r2;
   for (i = 1; i <= n; i++) DP[i] = i - 1;
   for (i = 2; i <= n; i++)
     if (abs(A[i] - A[i - 1]) <= X)
       DP[i] = 0;
     else
       break;
   for (i = 1; i <= n; i++)
     for (j = i + 1; j <= n; j++) {
       l1 = (long long)A[i] - (long long)X * (j - i - 1);
       r1 = (long long)A[i] + (long long)X * (j - i - 1);
       l2 = A[j] - X;
       r2 = A[j] + X;
       if (!(l2 > r1 || l1 > r2)) DP[j] = min(DP[j], DP[i] + j - i - 1);
     }
   for (i = 1; i <= n; i++)
     if (DP[i] + n - i <= k) return 1;
   return 0;
 }
 int cbin() {
   int i, step = (1 << 30);
   for (i = -1; step; step >>= 1)
     if (!ok(i + step)) i += step;
   return ++i;
 }
 int main() {
   scanf('%d%d', &n, &k);
   int i;
   for (i = 1; i <= n; i++) scanf('%d', &A[i]);
   printf('%d
', cbin());
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int size = 1007;
 const long long modulo = 1000000007;
 const long long oo = 1e18;
 const double EPS = 1e-13;
 const double PI = acos(-1.0);
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   vector<vector<int> > g(n);
   vector<long long> cost(n), v(n);
   for (int i = 0; i < n; i++) cin >> v[i];
   while (m--) {
     int a, b;
     cin >> a >> b;
     --a;
     --b;
     cost[a] += v[b];
     cost[b] += v[a];
     g[a].push_back(b);
     g[b].push_back(a);
   }
   vector<bool> was(n, false);
   long long ans = 0;
   for (int h = 0; h < n; h++) {
     int ver = -1;
     for (int i = 0; i < n; i++)
       if (!was[i] && (ver < 0 || v[ver] < v[i])) ver = i;
     was[ver] = true;
     ans += cost[ver];
     for (int i = 0; i < g[ver].size(); i++) {
       int to = g[ver][i];
       if (!was[to]) {
         cost[ver] -= v[to];
         cost[to] -= v[ver];
       }
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int test, a, sum = 0, wait = 0, counter = 0;
   priority_queue<int, vector<int>, greater<int> > q;
   queue<int> qqq;
   cin >> test;
   int num = test;
   while (test--) {
     cin >> a;
     sum += a;
     q.push(a);
     qqq.push(a);
   }
   while (!q.empty()) {
     int serve = q.top();
     if (serve >= wait)
       counter++;
     else {
       q.pop();
       continue;
     }
     wait += serve;
     q.pop();
   }
   cout << counter << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 3010;
 const int M = 11;
 const int INF = 1 << 30;
 const double EPS = 1e-8;
 const int MOD = 1000000007LL;
 int n, tot[N];
 vector<int> edge[N], edge2[N];
 int dfs(int u, int fa) {
   int num = 0, sz;
   sz = edge[u].size();
   for (int i = 0; i < sz; i++) {
     int v = edge[u][i];
     if (v == fa) {
       continue;
     }
     num += dfs(v, u);
   }
   sz = edge2[u].size();
   for (int i = 0; i < sz; i++) {
     int v = edge2[u][i];
     if (v == fa) {
       continue;
     }
     num += dfs(v, u) + 1;
   }
   return num;
 }
 void init() {
   memset(tot, 0, sizeof(tot));
   for (int i = 0; i < n; i++) {
     edge[i].clear();
     edge2[i].clear();
   }
   for (int i = 1; i < n; i++) {
     int u, v;
     scanf('%d %d', &u, &v);
     u--, v--;
     edge[u].push_back(v);
     edge2[v].push_back(u);
   }
   for (int u = 0; u < n; u++) {
     int sz;
     sz = edge[u].size();
     for (int i = 0; i < sz; i++) {
       int v = edge[u][i];
       int num = dfs(v, u);
       tot[u] += num;
     }
     sz = edge2[u].size();
     for (int i = 0; i < sz; i++) {
       int v = edge2[u][i];
       int num = dfs(v, u) + 1;
       tot[u] += num;
     }
   }
 }
 int dfs2(int u, int fa) {
   int sz, ret = tot[u];
   sz = edge[u].size();
   for (int i = 0; i < sz; i++) {
     int v = edge[u][i];
     if (v == fa) {
       continue;
     }
     ret = min(ret, dfs2(v, u));
   }
   sz = edge2[u].size();
   for (int i = 0; i < sz; i++) {
     int v = edge2[u][i];
     if (v == fa) {
       continue;
     }
     ret = min(ret, dfs2(v, u));
   }
   return ret;
 }
 void solve() {
   int ans = INF;
   for (int i = 0; i < n; i++) {
     ans = min(ans, tot[i]);
   }
   for (int i = 0; i < n; i++) {
     vector<int> p;
     int sz;
     sz = edge[i].size();
     for (int j = 0; j < sz; j++) {
       int v = edge[i][j];
       p.push_back(dfs2(v, i));
     }
     sz = edge2[i].size();
     for (int j = 0; j < sz; j++) {
       int v = edge2[i][j];
       p.push_back(dfs2(v, i));
     }
     if (p.size() <= 1) {
       continue;
     }
     sort(p.begin(), p.end());
     int tmp = p[0] + p[1] - tot[i];
     ans = min(ans, tmp);
   }
   cout << ans << endl;
 }
 int main() {
   while (cin >> n) {
     init();
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,a,b) for(int i = (a); i < b; ++i)
 #define rrep(i,a,b) for(int i = (b); i --> (a);)
 #define trav(x, v) for(auto &x : v)
 #define all(v) (v).begin(),(v).end()
 #define sz(v) (int)(v).size()

 bool que_big(int s, string x){
 	cout << s+1 << ' ' << x << endl;
 	string res;
 	cin >> res;
 	return res == 'yes';
 }

 int main(){
 	int n = 200, b = 200;
 	cin >> n >> b;

 	vector<string> ub(n, string(b, '1'));
 	string lb(b, '0');
 	deque<int> ko;
 	rep(i,0,n) ko.push_back(i);
 	string nxt = string(b, '1');
 	nxt[0] = '0';
 	while(true){
 		int s = ko.front();
 		if(ub[s] < lb){
 			ko.pop_front();
 			continue;
 		}
 		if(ub[s] == lb){
 			cout << 0 << ' ' << lb << endl;
 			return 0;
 		}
 		if(que_big(s, nxt)){
 			lb = nxt;
 			rrep(i,0,b){
 				if(lb[i]=='0'){
 					lb[i] = '1';
 					nxt[i] = '1';
 					break;
 				} else {
 					lb[i] = '0';
 				}
 			}
 		} else {
 			ub[s] = nxt;
 			ko.pop_front();
 			ko.push_back(s);
 			rep(i,0,b) if(nxt[i] > lb[i]){
 				nxt[i] = '0';
 				break;
 			}
 		}
 	}
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int con = 0;
 vector<pair<long long int, long long int> > v;
 long long int t[5000][5001];
 vector<vector<pair<long long int, long long int> > > ans(5001);
 bool istrue[5001];
 vector<long long int> a[5001];
 long long int dis[5001];
 int n;
 int ppp = 0;
 queue<int> q;
 void bfs(int src) {
   q.push(src);
   istrue[src] = true;
   dis[src] = 0;
   while (!q.empty()) {
     int p = q.front();
     q.pop();
     ans[con].push_back({(dis[p] + 1) % 2, p});
     for (auto u : a[p]) {
       if (!istrue[u]) {
         dis[u] = dis[p] + 1;
         if (dis[u] % 2)
           v[con].second++;
         else
           v[con].first++;
         istrue[u] = true;
         q.push(u);
       } else {
         if (dis[u] % 2 == dis[p] % 2) {
           cout << 'NO'
                << '
';
           ppp = 1;
           return;
         }
       }
     }
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int tt = 1;
   while (tt--) {
     long long int m;
     cin >> n >> m;
     long long int n1, n2, n3;
     cin >> n1 >> n2 >> n3;
     for (int i = 0; i < m; i++) {
       int x, y;
       cin >> x >> y;
       a[x].push_back(y);
       a[y].push_back(x);
     }
     for (int i = 1; i <= n; i++) {
       if (!istrue[i]) {
         v.push_back({1, 0});
         bfs(i);
         con++;
       }
       if (ppp == 1) return 0;
     }
     memset(t, -1, sizeof(t));
     if (v[0].first <= n2) t[0][v[0].first] = 0;
     if (v[0].second <= n2) t[0][v[0].second] = 0;
     for (int i = 1; i <= (long long int)v.size() - 1; i++) {
       for (int j = 0; j < n2 + 1; j++) {
         long long int vv = j - v[i].first;
         if (vv >= 0 && t[i - 1][vv] != -1) t[i][j] = vv;
         vv = j - v[i].second;
         if (vv >= 0 && t[i - 1][vv] != -1) t[i][j] = vv;
       }
     }
     char ss[n + 1];
     if (t[(long long int)v.size() - 1][n2] == -1)
       cout << 'NO'
            << '
';
     else {
       cout << 'YES'
            << '
';
       long long int i = (long long int)v.size() - 1, ind = n2;
       while (i != -1) {
         long long int pp = ind - t[i][ind], kk = 0;
         if (v[i].first == pp) kk = 1;
         for (auto u : ans[i]) {
           if (u.first == kk)
             ss[u.second] = '2';
           else
             ss[u.second] = '1';
         }
         ind = t[i][ind];
         i--;
       }
       for (int j = 1; j <= n; j++) {
         if (ss[j] == '1') {
           if (n1 == 0)
             ss[j] = '3';
           else
             n1--;
         }
         cout << ss[j];
       }
       cout << '
';
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   int n, m;
   cin >> n >> m;
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) {
       int k;
       cin >> k;
       if (k % 2 != (i + j) % 2) k++;
       cout << k << ' ';
     }
     cout << endl;
   }
 }
 int main() {
   int n;
   cin >> n;
   while (n--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MXN = 5e4 + 5;
 const int INF = 1e9;
 const long long P = 29;
 const long long MOD = 1e9 + 7;
 int t;
 int main() {
   srand(time(0));
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cout << fixed << setprecision(10);
   cin >> t;
   while (t--) {
     int n, x1, x2, x3;
     cin >> n;
     cin >> x1 >> x2;
     for (int i = 2; i < n; i++) {
       cin >> x3;
     }
     if (x1 + x2 <= x3)
       cout << 1 << ' ' << 2 << ' ' << n << '
';
     else
       cout << -1 << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename S, typename T>
 ostream& operator<<(ostream& out, pair<S, T> const& p) {
   out << '(' << p.first << ', ' << p.second << ')';
   return out;
 }
 template <typename T>
 ostream& operator<<(ostream& out, vector<T> const& v) {
   long long l = v.size();
   for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
   if (l > 0) out << v[l - 1];
   return out;
 }
 template <typename T>
 void trace(const char* name, T&& arg1) {
   cout << name << ' : ' << arg1 << '
';
 }
 template <typename T, typename... Args>
 void trace(const char* names, T&& arg1, Args&&... args) {
   const char* comma = strchr(names + 1, ',');
   cout.write(names, comma - names) << ' : ' << arg1 << ' | ';
   trace(comma + 1, args...);
 }
 const long long N = 3e5 + 100;
 long long MOD;
 long long power(long long x, long long t) {
   long long ans = 1;
   while (t > 0) {
     if (t & 1) ans = 1LL * ans * x % MOD;
     x = 1LL * x * x % MOD;
     t >>= 1;
   }
   return ans;
 }
 inline long long sub(long long a, long long b) {
   a %= MOD;
   b %= MOD;
   a = ((a - b) % MOD + MOD) % MOD;
   return a;
 }
 inline long long add(long long a, long long b) {
   a %= MOD;
   b %= MOD;
   a = (a + b) % MOD;
   return a;
 }
 inline long long mul(long long a, long long b) {
   a %= MOD;
   b %= MOD;
   a = (a * b) % MOD;
   return a;
 }
 inline long long inv(long long a) {
   a = a % MOD;
   a = power(a, MOD - 2);
   return a;
 }
 long long a[N], n, k;
 map<long long, long long> cnt;
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   cin >> n >> MOD >> k;
   for (long long i = 1; i <= n; i++) {
     long long temp;
     cin >> temp;
     long long kk = power(temp, 4);
     long long k2 = mul(k, temp);
     kk = sub(kk, k2);
     cnt[kk]++;
   }
   long long ans = 0;
   auto c2 = [](long long a) -> long long { return ((a * (a - 1)) / 2); };
   for (auto i : cnt) {
     ans += c2(i.second);
   }
   cout << ans << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 200000 + 10;
 const long long INF = 2e9 + 10;
 long long dic[N], idx[N];
 int main() {
   long long n, k, ii;
   scanf('%lld%lld', &n, &k);
   for (long long i = 0; i <= n; ++i) scanf('%lld', idx + i), dic[i] = idx[i];
   for (long long i = 1; i <= n + 1; ++i)
     dic[i] += dic[i - 1] / 2, dic[i - 1] %= 2;
   for (long long i = 0; i <= n + 1; ++i) {
     if (dic[i]) {
       ii = i;
       break;
     }
   }
   long long x = 0, ans = 0;
   for (long long i = n + 1; i >= 0; --i) {
     x = x * 2 + dic[i];
     if (abs(x) > INF) break;
     if (i > ii || i == n + 1 || (i == n && x == idx[i])) continue;
     if (abs(x - idx[i]) <= k) ++ans;
   }
   printf('%lld
', ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) {
   if (a.first < b.first) return true;
   return false;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long int n, m;
   cin >> n >> m;
   long long int hash[n + 1], col[4];
   memset(hash, 0, sizeof(hash));
   while (m--) {
     memset(col, 0, sizeof(col));
     long long int inp[3];
     for (long long int i = 0; i < 3; i++) {
       cin >> inp[i];
       col[hash[inp[i]]] = 1;
     }
     for (long long int i = 0; i < 3; i++) {
       long long int x = inp[i];
       if (hash[x] == 0) {
         for (long long int j = 1; j < 4; j++) {
           if (col[j] == 0) {
             hash[x] = j;
             col[hash[x]] = 1;
             break;
           }
         }
       } else {
         col[hash[x]] = 1;
       }
     }
   }
   for (long long int i = 1; i < n + 1; i++) cout << hash[i] << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n;
   cin >> n;
   vector<long long int> a(n), b(n);
   set<long long int> s;
   for (int i = 0; i < n; i++) {
     cin >> a[i];
     s.insert(a[i]);
   }
   for (int i = 0; i < n; i++) {
     cin >> b[i];
     s.insert(b[i]);
   }
   long long int count = 0;
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       long long int temp = a[i] ^ b[j];
       if (s.find(temp) != s.end()) count++;
     }
   }
   if (count % 2 != 0)
     cout << 'Koyomi' << endl;
   else
     cout << 'Karen' << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long a[100010];
 int main() {
   long long n, pos;
   while (cin >> n >> pos) {
     for (long long i = 0; i < n; i++) scanf('%I64d', &a[i]);
     sort(a, a + n);
     long long res1 = 0, res2, res;
     if (pos < a[0])
       res1 = a[n - 2] - pos;
     else if (a[0] <= pos && pos <= a[n - 2])
       res1 = min((pos - a[0]) * 2 + a[n - 2] - pos,
                  (a[n - 2] - pos) * 2 + pos - a[0]);
     else if (pos > a[n - 2])
       res1 = pos - a[0];
     if (pos < a[1])
       res2 = a[n - 1] - pos;
     else if (a[1] <= pos && pos <= a[n - 1])
       res2 = min((pos - a[1]) * 2 + a[n - 1] - pos,
                  (a[n - 1] - pos) * 2 + pos - a[1]);
     else if (pos > a[n - 1])
       res2 = pos - a[1];
     res = min(res1, res2);
     if (n == 1) res = 0;
     printf('%I64d
', res);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100010;
 const int M = 310;
 int n, m, s, e0, E;
 pair<int, int> dp[N][M];
 int a[N];
 vector<int> elAtB[N];
 inline int findj(int j0, int val) {
   if (j0 >= m) return -1;
   vector<int> &v = elAtB[val];
   if (v.size() == 0) return -1;
   vector<int>::iterator it = lower_bound(v.begin(), v.end(), j0);
   if (it == v.end())
     return -1;
   else
     return *it;
 }
 int main() {
   cin >> n >> m >> s >> e0;
   E = s / e0;
   int ost = s - E * e0;
   for (int i = 0; i < n; i++) {
     cin >> a[i];
   }
   for (int j = 0; j < m; j++) {
     int x;
     cin >> x;
     elAtB[x].push_back(j);
   }
   int ans = 0;
   for (int i = 0; i <= n; i++) {
     for (int e = 0; e <= E; e++) {
       dp[i][e] = make_pair(0, 0);
     }
   }
   for (int i = 0; i < n; i++) {
     for (int e = 1; e <= E; e++) {
       int dol = dp[i][e].first;
       int j0 = dp[i][e].second;
       int dolnxt = dp[i + 1][e].first;
       if (dol > dolnxt) {
         dp[i + 1][e] = make_pair(dol, j0);
       }
       int j = findj(j0, a[i]);
       if (j == -1)
         continue;
       else {
       }
       dolnxt = dp[i + 1][e - 1].first;
       int jnxt = dp[i + 1][e - 1].second;
       if (((dol + 1 > dolnxt) || (dol + 1 == dolnxt && j < jnxt)) &&
           ((i + 1 + j + 1) <= (e - 1) * e0 + ost)) {
         dp[i + 1][e - 1] = make_pair(dol + 1, j + 1);
         ans = max(ans, dol + 1);
       }
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   int i, j, k, n;
   scanf('%d', &n);
   k = sqrt(n);
   for (i = k; i >= 1; i--) {
     if (n % i == 0) {
       j = i;
       break;
     }
   }
   printf('%d %d', j, (n / j));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long maxn = 100005;
 long long n, d, b;
 long long a[maxn];
 bool f(long long x) {
   long long l = 1 + x;
   long long r = n - x;
   deque<pair<long long, long long>> dq;
   for (long long i = 1; i <= n; i++)
     if (a[i] != 0) dq.push_front({i, a[i]});
   long long t = 1 + x;
   while (l <= r) {
     long long left = b;
     while (left > 0) {
       if (dq.empty()) return false;
       pair<long long, long long> p = dq.back();
       dq.pop_back();
       long long amt = min(p.second, left);
       if (p.first - l > t * d) return false;
       p.second -= amt;
       left -= amt;
       if (p.second > 0) dq.push_back(p);
     }
     l++;
     if (l <= r) {
       long long right = b;
       while (right > 0) {
         if (dq.empty()) return false;
         pair<long long, long long> p = dq.front();
         dq.pop_front();
         long long amt = min(p.second, right);
         if (r - p.first > t * d) return false;
         p.second -= amt;
         right -= amt;
         if (p.second > 0) dq.push_front(p);
       }
       r--;
     }
     t++;
   }
   return true;
 }
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin >> n >> d >> b;
   for (long long i = 1; i <= n; i++) cin >> a[i];
   long long l = 0;
   long long r = n;
   while (r - l > 3) {
     long long mid = (r - l) / 2 + l;
     if (f(mid))
       r = mid;
     else
       l = mid;
   }
   for (long long i = l; i <= r; i++) {
     if (f(i)) {
       cout << i << '
';
       break;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma GCC optimize('O3')
 #pragma GCC target('avx')
 #pragma GCC optimize('Ofast')
 #pragma GCC optimize('unroll-loops')
 #pragma GCC target('sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native')
 const int MOD = 1000000007;
 const int INF = 1000000009;
 const int MAXN = 1000005;
 vector<string> split(const string& s, char c) {
   vector<string> v;
   stringstream ss(s);
   string x;
   while (getline(ss, x, c)) v.emplace_back(x);
   return move(v);
 }
 template <typename T, typename... Args>
 inline string arrStr(T arr, int n) {
   stringstream s;
   s << '[';
   for (int i = 0; i < n - 1; i++) s << arr[i] << ',';
   s << arr[n - 1] << ']';
   return s.str();
 }
 bool is_prime(long long n) {
   if (n < 2) return false;
   for (long long x = 2; x * x <= n; x++) {
     if (n % x == 0) return false;
   }
   return true;
 }
 vector<long long> get_prime_factors(long long n) {
   vector<long long> f;
   for (long long x = 2; x * x <= n; x++) {
     while (n % x == 0) {
       f.push_back(x);
       n /= x;
     }
   }
   if (n > 1) f.push_back(n);
   return f;
 }
 long long fpow(long long x, long long n) {
   long long res = 1;
   while (n) {
     if (n & 1) {
       res = (1LL * res * x) % MOD;
     }
     x = (1LL * x * x) % MOD;
     n >>= 1;
   }
   return (res % MOD);
 }
 vector<long long> fac, inv;
 void create_fac(long long n = MAXN) {
   fac.resize(n + 5);
   inv.resize(n + 5);
   fac[0] = 1;
   inv[0] = fpow(fac[0], MOD - 2);
   for (long long i = 1; i <= n; i++) {
     fac[i] = (fac[i - 1] % MOD * i % MOD) % MOD;
     inv[i] = fpow(fac[i], MOD - 2);
   }
 }
 long long binomial_coefficient(long long n, long long r) {
   long long res = 1;
   res = (res * (fac[n] % MOD)) % MOD;
   res = (res * (inv[r] % MOD)) % MOD;
   res = (res * (inv[n - r] % MOD)) % MOD;
   return res;
 }
 long long gcd(long long a, long long b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
 long long sceil(long long a, long long b) { return (a + b - 1) / b; }
 vector<long long> lp;
 vector<long long> pr;
 void sieve(long long n = MAXN) {
   lp.resize(n + 1);
   pr.clear();
   for (long long i = 2; i <= n; ++i) {
     if (lp[i] == 0) {
       lp[i] = i;
       pr.push_back(i);
     }
     for (long long j = 0;
          j < (long long)pr.size() && pr[j] <= lp[i] && i * pr[j] <= n; ++j)
       lp[i * pr[j]] = pr[j];
   }
 }
 long long extended_euclidean(long long a, long long b, long long& x,
                              long long& y) {
   if (b == 0) {
     x = 1;
     y = 0;
     return a;
   }
   long long x1, y1;
   long long d = extended_euclidean(b, a % b, x1, y1);
   x = y1;
   y = x1 - y1 * (a / b);
   return d;
 }
 int mod_inv(long long a, long long m) {
   long long x, y;
   long long g = extended_euclidean(a, m, x, y);
   if (g != 1) {
     return -1;
   } else {
     x = (x % m + m) % m;
     return x;
   }
 }
 long long solution() {
   long long n, k;
   cin >> n >> k;
   string s;
   cin >> s;
   long long ans = 0;
   if (k <= n) ans = k;
   vector<long long> f(26, 0);
   for (auto c : s) {
     f[c - 'a']++;
   }
   long long MX = *max_element(f.begin(), f.end());
   vector<long long> v(MX, 0);
   for (int times = MX; times > 0; times--) {
     for (int i = 0; i < 26; i++) {
       v[times - 1] += f[i] / times;
     }
   }
   reverse(v.begin(), v.end());
   42;
   for (long long i = 1; i <= k && i <= n; i++) {
     if (k % i == 0) {
       long long times = MX - (lower_bound(v.begin(), v.end(), i) - v.begin());
       42;
       42;
       ans = max(ans, times * i);
     }
   }
   return ans;
 }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int tt = 1;
   cin >> tt;
   while (tt--) {
     cout << solution() << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int iinf = 1e9 + 10;
 const long long inf = 1ll << 60;
 const long long mod = 1e9 + 7;
 void GG() {
   cout << '0
';
   exit(0);
 }
 long long mpow(long long a, long long n, long long mo = mod) {
   long long re = 1;
   while (n > 0) {
     if (n & 1) re = re * a % mo;
     a = a * a % mo;
     n >>= 1;
   }
   return re;
 }
 long long inv(long long b, long long mo = mod) {
   if (b == 1) return b;
   return (mo - mo / b) * inv(mo % b, mo) % mo;
 }
 const int maxn = 1e6 + 5;
 long long dp[2003][22];
 long long fac[200006], ifac[200006];
 inline long long CC(int a, int b) {
   a = a + b;
   return fac[a] * ifac[b] % mod * ifac[a - b] % mod;
 }
 int R[2003], C[2003];
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   ;
   fac[0] = ifac[0] = 1;
   for (int i = 1; i <= 200006; ++i) {
     fac[i] = fac[i - 1] * i % mod;
     ifac[i] = inv(fac[i]);
   }
   int n, m, k, second;
   cin >> n >> m >> k >> second;
   vector<pair<int, int> > v;
   v.push_back({1, 1});
   v.push_back({n, m});
   for (int i = 0; i < k; ++i) {
     int r, c;
     cin >> r >> c;
     v.push_back({r, c});
   }
   sort(v.begin(), v.end());
   for (int i = 1; i <= (int)v.size() - 1; ++i) {
     R[i] = v[i].first, C[i] = v[i].second;
     dp[i][0] = CC(R[i] - 1, C[i] - 1);
     for (int fk = 0; fk < 21; ++fk) {
       for (int j = 1; j <= i - 1; ++j) {
         if (R[j] <= R[i] && C[j] <= C[i]) {
           dp[i][fk] -= dp[j][fk] * CC(R[i] - R[j], C[i] - C[j]) % mod;
           if (dp[i][fk] < 0) dp[i][fk] += mod;
           dp[i][fk + 1] += dp[j][fk] * CC(R[i] - R[j], C[i] - C[j]) % mod;
           if (dp[i][fk + 1] >= mod) dp[i][fk + 1] -= mod;
         }
       }
     }
   }
   long long re = 0;
   for (int fk = 0; fk < 22; ++fk) {
     re += dp[(int)v.size() - 1][fk] * second % mod;
     second = (second + 1) / 2;
   }
   cout << re * inv(CC(n - 1, m - 1)) % mod << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 struct lem {
   long long m;
   long long v;
   int id;
   bool operator<(const lem& other) const {
     if (m > other.m) return true;
     if (m < other.m) return false;
     if (v > other.v) return true;
     if (v < other.v) return false;
     return id > other.id;
   }
 };
 int N, K, H;
 lem L[100010];
 int asst[100010];
 int tempa[100010];
 bool solve(long double t) {
   memset(tempa, 0, sizeof(tempa));
   int start = 0;
   for (int k = K; k >= 1; k--) {
     bool found = false;
     for (int i = (start); i <= (N - 1); i++) {
       long double time =
           ((long double)k) / ((long double)L[i].v) * ((long double)H);
       if (time <= t) {
         found = true;
         tempa[k] = i;
         start = i + 1;
         break;
       }
     }
     if (!found) return false;
   }
   return true;
 }
 int main() {
   cin >> N >> K >> H;
   for (int i = 0; i < N; i++) cin >> L[i].m;
   for (int i = 0; i < N; i++) cin >> L[i].v;
   for (int i = 0; i < N; i++) L[i].id = i + 1;
   sort(L, L + N);
   long double low = 0.l;
   long double high = 1000000000.l;
   int times = 100;
   while (times--) {
     long double t = (low + high) / 2.l;
     if (solve(t)) {
       for (int i = (1); i <= (K); i++) asst[i] = tempa[i];
       high = t;
     } else {
       low = t;
     }
   }
   for (int k = (1); k <= (K); k++) {
     if (k > 1) cout << ' ';
     cout << L[asst[k]].id;
   }
   cout << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 20;
 const int inf = 1e9;
 int dp[maxn][maxn][maxn];
 int vis[maxn][maxn][maxn];
 int path[maxn][maxn][maxn];
 int n, a, b;
 int h[maxn];
 int dfs(int i, int cur, int pre) {
   cur = cur < 0 ? 0 : cur;
   pre = pre < 0 ? 0 : pre;
   if (i == n) {
     if (cur == 0)
       return 0;
     else
       return inf;
   }
   if (vis[i][cur][pre]) return dp[i][cur][pre];
   vis[i][cur][pre] = 1;
   int &ans = dp[i][cur][pre];
   ans = inf;
   int lb = (pre + b - 1) / b,
       hb = max(lb, max((cur + a - 1) / a, (h[i + 1] + b) / b));
   int p;
   for (int j = lb; j <= hb; j++) {
     int tmp = j + dfs(i + 1, h[i + 1] + 1 - j * b, cur - j * a);
     if (ans > tmp) {
       ans = tmp;
       path[i][cur][pre] = j;
     }
   }
   return ans;
 }
 void print(int i, int cur, int pre) {
   cur = cur < 0 ? 0 : cur;
   pre = pre < 0 ? 0 : pre;
   if (i == n) return;
   int tmp = path[i][cur][pre], cnt = tmp;
   while (cnt--) printf('%d ', i);
   print(i + 1, h[i + 1] + 1 - tmp * b, cur - tmp * a);
 }
 int main() {
   cin >> n >> a >> b;
   for (int i = 1; i <= n; i++) cin >> h[i];
   memset(vis, 0, sizeof(vis));
   int ans = dfs(2, h[2] + 1, h[1] + 1);
   cout << ans << '
';
   print(2, h[2] + 1, h[1] + 1);
   puts('');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string s, s1, s2, s3;
 int sa[300010][20], lcp[300010], rnk[300010], root[300010], cnt[300010][4],
     col[300010], n;
 pair<pair<int, int>, int> q[300010];
 pair<int, pair<int, int> > lcp_pair[300010];
 vector<long long> ansvec;
 long long ans, mod = 1e9 + 7;
 int get(int x) { return root[x] = (x == root[x] ? x : get(root[x])); }
 void merge(int x, int y) {
   root[y] = x;
   ans -= (1LL * cnt[y][1] * cnt[y][2] * cnt[y][3]) % mod +
          (1LL * cnt[x][1] * cnt[x][2] * cnt[x][3]) % mod;
   while (ans < 0) ans += mod;
   for (int i = 1; i <= 3; ++i) cnt[x][i] += cnt[y][i];
   ans = (ans + 1LL * cnt[x][1] * cnt[x][2] * cnt[x][3]) % mod;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin >> s1 >> s2 >> s3;
   n = min(s1.size(), min(s2.size(), s3.size()));
   s = s1 + '1' + s2 + '2' + s3;
   for (int i = 0; i < s1.size(); ++i) col[i] = 1;
   for (int i = s1.size() + 1; i < s1.size() + 1 + s2.size(); ++i) col[i] = 2;
   for (int i = s.size() - s3.size(); i < s.size(); ++i) col[i] = 3;
   for (int i = 0; i < s.size(); ++i) sa[i][0] = s[i];
   for (int i = 1; i < 20; ++i) {
     for (int j = 0; j < s.size(); ++j)
       if (j + (1 << i - 1) < s.size())
         q[j] =
             make_pair(make_pair(sa[j][i - 1], sa[j + (1 << i - 1)][i - 1]), j);
       else
         q[j] = make_pair(make_pair(sa[j][i - 1], -1), j);
     sort(q, q + s.size());
     int cnt = 0;
     for (int j = 0; j < s.size(); ++j) {
       if (j && q[j].first != q[j - 1].first) ++cnt;
       sa[q[j].second][i] = cnt;
     }
   }
   for (int i = 0; i < s.size(); ++i) {
     rnk[sa[i][19]] = i;
     root[i] = i;
     cnt[i][col[i]] = 1;
   }
   int cnt = 0, index, ii = 0;
   for (int i = 0; i < s.size(); ++i) {
     index = sa[i][19];
     if (index == s.size() - 1) {
       cnt = 0;
       continue;
     }
     while (i + cnt < s.size() && rnk[index + 1] + cnt < s.size() &&
            s[i + cnt] == s[rnk[index + 1] + cnt])
       ++cnt;
     lcp[i] = cnt;
     lcp_pair[ii] = make_pair(lcp[i], make_pair(i, rnk[index + 1]));
     if (cnt) --cnt;
     ++ii;
   }
   sort(lcp_pair, lcp_pair + s.size() - 1);
   reverse(lcp_pair, lcp_pair + s.size() - 1);
   for (int i = n, j = 0; i >= 1; --i) {
     int x, y;
     while (j < s.size() - 1 && lcp_pair[j].first >= i) {
       x = get(lcp_pair[j].second.first);
       y = get(lcp_pair[j].second.second);
       merge(x, y);
       ++j;
     }
     ansvec.push_back(ans);
   }
   for (int i = ansvec.size() - 1; i >= 0; --i) cout << ansvec[i] << ' ';
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<string> v;
 string s;
 const int N = 1000001;
 int n;
 long long d, arr[N];
 unsigned long long gcd(long long x, long long y) {
   if (y == 0) {
     return x;
   }
   return gcd(y, x % y);
 }
 void gen(long long ind, string t) {
   if (ind == s.size()) {
     if (t.size() == 3) v.push_back(t);
     return;
   }
   gen(ind + 1, t + s[ind]);
   gen(ind + 1, t);
 }
 long long check() {
   long long res = 0;
   for (long long i = 0; i < v.size(); ++i) {
     if (((v[i][v[i].size() - 1] - '0') - (v[i][0] - '0')) <= d) {
       res++;
     }
   }
   return res;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n, l, r;
   bool lie = 0;
   cin >> n >> l >> r;
   int v[n], s[n];
   for (int i = 1; i <= n; ++i) {
     cin >> v[i];
   }
   for (int i = 1; i <= n; ++i) {
     cin >> s[i];
   }
   for (int i = 1; i < l; ++i) {
     if (v[i] != s[i]) {
       lie = 1;
       break;
     }
   }
   if (!lie) {
     for (int i = r + 1; i <= n; ++i) {
       if (v[i] != s[i]) {
         lie = 1;
         break;
       }
     }
   }
   if (lie) {
     cout << 'LIE
';
   } else {
     cout << 'TRUTH
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1 + 9e6;
 const int inf = 0x3f3f3f;
 vector<bool> dp[24];
 int n;
 int a[23];
 vector<pair<int, int> > pre[23];
 int ans;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie();
   cout.tie();
   cin >> n;
   for (int i = 0; i < n; ++i) {
     cin >> a[i];
   }
   for (int i = 0; i < 24; i++) dp[i].resize(1 << n);
   for (int i = 1; i < n; ++i) {
     for (int j = 0; j < i; ++j) {
       for (int k = j; k < i; ++k) {
         if (a[j] + a[k] == a[i]) {
           pre[i].push_back({j, k});
         }
       }
     }
   }
   dp[0][0] = 0;
   dp[0][1] = 1;
   for (int i = 0; i < n - 1; ++i) {
     for (int mask = 0; mask < (1 << n); ++mask) {
       if (dp[i][mask]) {
         for (int j = 0; j < pre[i + 1].size(); ++j) {
           int u = pre[i + 1][j].first;
           int v = pre[i + 1][j].second;
           if (((mask >> u) & 1) && ((mask >> v) & 1)) {
             int bit = mask + (1 << (i + 1));
             dp[i + 1][bit] = 1;
             for (int k = 0; k < i + 1; ++k) {
               if (((bit >> k) & 1)) {
                 dp[i + 1][bit ^ (1 << k)] = 1;
               }
             }
           }
         }
       }
     }
   }
   ans = inf;
   for (int mask = 0; mask < (1 << n); ++mask) {
     if (dp[n - 1][mask]) {
       ans = min(ans, (int)(__builtin_popcount(mask)));
     }
   }
   if (ans == inf)
     cout << -1;
   else
     cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string onezero(int n) {
   string s = '1';
   for (int i = 1; i < n; ++i) {
     s += '0';
   }
   return s;
 }
 string findSum(string str1, string str2) {
   if (str1.length() > str2.length()) swap(str1, str2);
   string str = '';
   int n1 = str1.length(), n2 = str2.length();
   reverse(str1.begin(), str1.end());
   reverse(str2.begin(), str2.end());
   int carry = 0;
   for (int i = 0; i < n1; i++) {
     int sum = ((str1[i] - '0') + (str2[i] - '0') + carry);
     str.push_back(sum % 10 + '0');
     carry = sum / 10;
   }
   for (int i = n1; i < n2; i++) {
     int sum = ((str2[i] - '0') + carry);
     str.push_back(sum % 10 + '0');
     carry = sum / 10;
   }
   if (carry) str.push_back(carry + '0');
   reverse(str.begin(), str.end());
   return str;
 }
 int main() {
   ios_base::sync_with_stdio(NULL);
   cin.tie(NULL);
   cout.tie(NULL);
   int l;
   string s, ans;
   cin >> l >> s;
   if (s.size() % l != 0) {
     string zero = onezero(l);
     for (int i = 0; i < s.size() / l + 1; ++i) {
       ans += zero;
     }
   } else {
     string temp = s.substr(0, l);
     for (int i = 0; i < s.size() / l; ++i) {
       ans += temp;
     }
     if (ans <= s) {
       ans = '';
       temp = findSum(temp, '1');
       if (temp.size() != l) {
         temp = onezero(l);
         ans = onezero(l);
       }
       for (int i = 0; i < s.size() / l; ++i) {
         ans += temp;
       }
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long int N = 1e5 + 1;
 long long int n, m, i, j, l, k, x, y, a, b, cnt[3], sum[3];
 void solve() {
   string s;
   cin >> s;
   long long int n = s.length();
   long long int lst = 0, maxi = -1;
   long long int val = 0;
   for (long long int i = 0; i < n; i++) {
     if (s[i] == 'L') {
       val++;
     } else {
       maxi = max(maxi, val);
       val = 0;
     }
   }
   maxi = max(maxi, val);
   cout << maxi + 1 << '
';
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long int t;
   cin >> t;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[1010], d[1010];
 int main() {
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
     d[a[i]]++;
   }
   int mx = 0, mxi = 0;
   for (int i = 1; i <= n; i++) {
     if (d[a[i]] > mx) mx = d[a[i]];
     if (d[a[i]] != 0) {
       mxi++;
       d[a[i]] = 0;
     }
   }
   cout << mx << ' ' << mxi;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   long long answer = 0;
   for (int i = s.length() - 1; i > 0; i--) {
     string temp = s.substr(i - 1, 2);
     if (stoi(temp) % 4 == 0) {
       answer += i;
     }
   }
   for (int i = 0; i < s.length(); i++) {
     if (stoi(s.substr(i, 1)) % 4 == 0) {
       answer++;
     }
   }
   cout << answer;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int read() {
   int ret = 0, flag = 1;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') flag = -1;
     c = getchar();
   }
   while (c >= '0' && c <= '9') ret = ret * 10 + (c ^ '0'), c = getchar();
   return flag * ret;
 }
 struct use {
   int x, dis;
 };
 const int N = 5e3 + 5;
 int T, n, d;
 vector<int> edge[N];
 int dad[N];
 int build(int x, int dis) {
   int sum = 0;
   if ((x << 1) <= n) {
     edge[x].push_back(x << 1);
     sum += dis + 1;
     sum += build(x << 1, dis + 1);
   }
   if ((x << 1 | 1) <= n) {
     edge[x].push_back(x << 1 | 1);
     sum += dis + 1;
     sum += build(x << 1 | 1, dis + 1);
   }
   return sum;
 }
 void bfs() {
   queue<use> q;
   q.push({1, 0});
   int now = 0;
   vector<int> p1, p2;
   while (q.empty() == 0) {
     int x = q.front().x, dis = q.front().dis;
     q.pop();
     if (now != dis) {
       now = dis, p1.clear(), p2.clear();
     }
     for (auto it = edge[x].begin(); it != edge[x].end(); it++) {
       int y = *it;
       if (edge[y].size() == 0) {
         p1.push_back(y);
         if (p2.size()) {
           edge[p2[0]].push_back(y);
           edge[x].erase(it);
           return;
         }
       }
       if (edge[y].size() != 2) p2.push_back(y);
       q.push({y, dis + 1});
     }
   }
 }
 int main() {
   T = read();
   while (T--) {
     n = read(), d = read();
     for (int i = 1; i <= n; i++) edge[i].clear();
     int mn = build(1, 0);
     int mx = (n - 1) * n / 2;
     if (!(mn <= d && d <= mx)) {
       printf('NO
');
       continue;
     }
     int now = mn;
     while (now < d) {
       bfs();
       now++;
     }
     for (int i = 1; i <= n; i++) {
       for (int j = 0; j < edge[i].size(); j++) dad[edge[i][j]] = i;
     }
     printf('YES
');
     for (int i = 2; i <= n; i++) printf('%d ', dad[i]);
     printf('
');
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 double ans, m;
 int n;
 double binpow(double a, int b) {
   if (b == 0)
     return 1;
   else if (b == 1)
     return a;
   else if (b % 2 == 0) {
     double t = binpow(a, b / 2);
     return t * t;
   } else
     return a * binpow(a, b - 1);
 }
 int main() {
   cin >> m >> n;
   for (double i = 1; i <= m; i++) {
     ans += i * binpow(i / m, n) * (1 - binpow((i - 1) / i, n));
   }
   cout << fixed << setprecision(15) << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   long long n;
   cin >> n;
   long long t = n;
   vector<pair<int, int> > laptop;
   for (int i = 0; i < n; i++) {
     long long temp1, temp2;
     cin >> temp1 >> temp2;
     laptop.push_back(make_pair(temp1, temp2));
   }
   sort(laptop.begin(), laptop.end());
   int cur = laptop[0].second;
   for (int i = 1; i < n; ++i) {
     if (cur > laptop[i].second) {
       cout << 'Happy Alex
';
       return 0;
     }
     cur = laptop[i].second;
   }
   cout << 'Poor Alex
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e6 + 7, M = 1e9 + 7;
 vector<int> primes;
 bool isp[N];
 void sieve() {
   fill(isp, isp + N, 1);
   isp[0] = isp[1] = 0;
   for (int i = 2; i * i < N; i++)
     if (isp[i])
       for (int j = i * i; j < N; j += i) isp[j] = 0;
   for (int i = 2; i < N; i++)
     if (isp[i]) primes.push_back(i);
 }
 vector<pair<int, int> > factorize(int x) {
   vector<pair<int, int> > ans;
   for (int i = 2; i * i <= x; i++) {
     int cnt = 0;
     while (x % i == 0) cnt++, x /= i;
     if (cnt) ans.push_back(make_pair(i, cnt));
   }
   if (x > 1) ans.push_back(make_pair(x, 1));
   return ans;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n;
   cin >> n;
   long long ans = 1;
   map<int, int> fac;
   map<int, int> cnt;
   vector<vector<pair<int, int> > > factors;
   int pp[n];
   for (int i = 0; i < n; i++) cin >> pp[i];
   sort(pp, pp + n);
   reverse(pp, pp + n);
   for (int i = 1; i <= n; i++) {
     int p = pp[i - 1];
     if (fac.count(p) == 0) {
       ans = (ans * p) % M;
       fac[p] = 1;
       cnt[p] = 1;
       vector<pair<int, int> > v;
       v.push_back(make_pair(p, 1));
       factors.push_back(v);
     } else {
       vector<pair<int, int> > pf = factorize(p - 1);
       factors.push_back(pf);
       for (auto pr : pf) {
         int p = pr.first;
         int e = pr.second;
         int dif = e - fac[p];
         if (dif < 0) continue;
         if (dif == 0) {
           cnt[p]++;
           continue;
         }
         fac[p] += dif;
         cnt[p] = 1;
         for (int i = 0; i < dif; i++) ans = (ans * p) % M;
       }
     }
   }
   for (auto pf : factors) {
     bool found = true;
     for (auto pr : pf) {
       int p = pr.first;
       int e = pr.second;
       int mx = fac[p];
       assert(e <= mx);
       if (e == mx && cnt[p] == 1) {
         found = false;
         break;
       }
     }
     if (found) {
       ans++;
       break;
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 unsigned long long n, k, b1, b2, b[200007], ans, dl, dll[200007], an[200007];
 map<unsigned long long, unsigned long long> a[11];
 int main() {
   ios::sync_with_stdio(0);
   cout.tie(0);
   cin.tie(0);
   cin >> n >> k;
   for (unsigned long long i = 1; i <= n; i++) {
     cin >> b[i];
     b1 = b[i];
     dl = 0;
     while (b1 > 0) {
       dl++;
       b1 = b1 / 10;
     }
     dll[i] = dl;
     b1 = b[i];
     a[dl][b[i] % k]++;
   }
   for (unsigned long long i = 1; i <= n; i++) {
     b1 = 1;
     for (unsigned long long j = 1; j <= 10; j++) {
       b1 *= 10;
       b2 = b[i] * b1;
       b2 %= k;
       b2 = k - b2;
       if (b2 == k) b2 = 0;
       if (a[j].find(b2) != a[j].end()) {
         ans += a[j][b2];
         if (dll[i] == j && b2 == b[i] % k) ans--;
       }
     }
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = int(1e6) + 100;
 const long long inf = 1e6;
 int n, m;
 int a[maxn], cnt[maxn], b[maxn];
 void read() {
   scanf('%d%d', &n, &m);
   for (int i = 1; i <= n; ++i) scanf('%d', &a[i]);
   for (int i = 1; i <= n; ++i) b[i] = a[i];
 }
 long long POW(long long num, int times) {
   long long ans = 1;
   while (times) {
     if (times & 1) ans = ans * num;
     num = num * num;
     if (ans >= inf) return inf;
     if (num >= inf) num = inf;
     times >>= 1;
   }
   return ans;
 }
 void solve() {
   long long ans = 0;
   for (int i = 1; i <= n; ++i) {
     int num = a[i];
     a[i] = 1;
     long long inv = 1;
     for (int j = 2; j * j <= num && num != 1; ++j)
       if (num % j == 0) {
         int k = 0;
         int x = a[i];
         while (num % j == 0) {
           k++;
           if (k == m) k = 0;
           if (k == 0)
             a[i] = x;
           else
             a[i] *= j;
           num /= j;
         }
         int tmp = POW(j, (m - k) % m);
         if (tmp == inf)
           inv = inf;
         else
           inv *= tmp;
         if (inv >= inf) inv = inf;
       }
     if (num != 1) a[i] *= num, inv *= POW(num, m - 1);
     if (inv < inf) ans += cnt[inv];
     ++cnt[a[i]];
   }
   printf('%lld
', ans);
 }
 int main() {
   read();
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MX = 300000;
 int n, arr[MX], bit[MX], ans = 0, lis;
 void update(int x, int V) {
   while (x <= n) {
     bit[x] = max(bit[x], V);
     x += x & -x;
   }
 }
 int get(int x) {
   int ret = 0;
   while (x > 0) {
     ret = max(ret, bit[x]);
     x -= x & -x;
   }
   return ret;
 }
 int main() {
   scanf('%d', &n);
   memset(bit, 0, sizeof(bit));
   for (int j = 1; j <= n; j++) {
     scanf('%d', &arr[j]);
     lis = get(arr[j]) + 1;
     update(arr[j] + 1, lis);
     ans = max(ans, lis);
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 priority_queue<long long, std::vector<long long>, std::greater<long long> > pqs;
 queue<long long> q;
 stack<long long> sta;
 set<long long> st;
 set<long long>::iterator P;
 long long i, j, n, m, t, k, a, b, c, x, mx, mn;
 string s, s1;
 char z;
 vector<pair<long long, long long> > v;
 map<pair<long long, long long>, long long> mp, pm;
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
   int T = 1;
   cin >> T;
   while (T--) {
     i = j = n = m = t = k = a = b = c = x = mx = mn = 0;
     cin >> n >> m;
     m += 2 * n;
     for (i = 1; i <= n && m; i++)
       for (j = i + 1; j <= n && m; j++) cout << i << ' ' << j << endl, m--;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Node {
   Node *arr[26];
   int state;
   bool isEnd = false;
   Node() {
     for (int i = 0; i < 26; i++) arr[i] = nullptr;
     isEnd = true;
   }
 };
 void insert(const string &s, Node *root) {
   Node *curr = root;
   for (char c : s) {
     if (curr->arr[c - 'a'] == nullptr) curr->arr[c - 'a'] = new Node();
     curr = curr->arr[c - 'a'];
   }
   curr->isEnd = true;
 }
 int find_state(Node *curr, bool leaf = true) {
   bool winning = false;
   int cnt = 0;
   for (int i = 0; i < 26; i++) {
     if (curr->arr[i] != nullptr) {
       cnt++;
       if (find_state(curr->arr[i], leaf) == 0) winning = true;
     }
   }
   if (cnt == 0) winning = leaf;
   return curr->state = winning ? 1 : 0;
 }
 int main() {
   int n, k;
   cin >> n >> k;
   Node *root = new Node();
   for (int i = 0; i < n; i++) {
     string s;
     cin >> s;
     insert(s, root);
   }
   int st1 = find_state(root, false);
   if (k == 1) {
     cout << (st1 == 1 ? 'First' : 'Second') << endl;
   } else {
     int st2 = find_state(root, true);
     if (st2 == 1 && st1 == 1) {
       cout << 'First' << endl;
     } else if (st2 == 1 && st1 == 0) {
       cout << 'Second' << endl;
     } else if (st2 == 0 && st1 == 1) {
       cout << (k % 2 == 0 ? 'Second' : 'First') << endl;
     } else {
       cout << 'Second' << endl << '
';
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[100005];
 int main() {
   int n;
   while (cin >> n) {
     int ans = 0;
     for (int i = 1; i < n; i++) {
       int x, y;
       cin >> x >> y;
       ans += a[x] + a[y];
       a[x]++, a[y]++;
     }
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = pow(10, 9) + 7;
 const long long MAX = LONG_LONG_MAX;
 void solve() {
   int n;
   cin >> n;
   vector<string> a(n, '');
   for (int i = 0; i < n; i += 1) cin >> a[i];
   for (int i = 0; i < n; i += 1) {
     for (int j = 0; j < n; j += 1) {
       if (a[i][j] == '1') {
         if (i == n - 1 || j == n - 1) {
           continue;
         }
         if (a[i + 1][j] == '1' || a[i][j + 1] == '1') {
           continue;
         } else {
           cout << 'NO';
           return;
         }
       }
     }
   }
   cout << 'YES';
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long t = 1;
   cin >> t;
   while (t > 0) {
     solve();
     t--;
     cout << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int8_t sign(int a, int b, int &c, int x, int y) {
   return a * 1LL * x + b * 1LL * y + c < 0LL ? -1 : 1;
 }
 void solve() {
   int x, y, x1, y1;
   cin >> x >> y >> x1 >> y1;
   int16_t ans = 0;
   int16_t n;
   cin >> n;
   for (int i = 0, u, v, c; i < n; i++) {
     cin >> u >> v >> c;
     ans += sign(u, v, c, x, y) != sign(u, v, c, x1, y1);
   }
   cout << ans;
 }
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int tkd = 1;
   while (tkd-- > 0) {
     solve();
   }
 }


#include <bits/stdc++.h>
 #pragma comment(linker, '/STACK:64777216')
 using namespace std;
 template <class T>
 inline T sqr(T x) {
   return x * x;
 }
 const double pi = acos(-1.0), eps = 1e-9;
 const int INF = 1000 * 1000 * 1000, MAXN = 1000005, MOD = 1000000007;
 const long long INFL = 1000000000000000000;
 long long n, m, cnt[MAXN][26];
 string x, y;
 void prepare(string s) {
   if ((int)s.size() != 0) {
     freopen((s + '.in').c_str(), 'r', stdin);
     freopen((s + '.out').c_str(), 'w', stdout);
   }
 }
 long long gcd(long long a, long long b) { return (b) ? gcd(b, a % b) : a; }
 long long lca(long long a, long long b) { return a / gcd(a, b) * b; }
 void get_data() { cin >> n >> m >> x >> y; }
 void solve() {
   long long L = lca((int)x.size(), (int)y.size());
   long long g = gcd((int)x.size(), (int)y.size());
   long long ans = L;
   for (int i = 0; i < (int)y.size(); ++i) cnt[i % g][y[i] - 'a']++;
   for (int j = 0; j < (int)x.size(); ++j) ans -= cnt[j % g][x[j] - 'a'];
   cout << ans * (n * (int)x.size() / L);
 }
 int main() {
   prepare('');
   get_data();
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char s[2004], temp[2004], e[2004], c, cnt;
 int n;
 int q[27];
 void f(int x) {
   cnt++;
   if (cnt != n * 3)
     printf('%d ', x);
   else
     printf('%d
', x);
   int i;
   for (i = n - x + 1; i <= n; i++) temp[n - i + 1] = s[i];
   for (i = 1; i < n - x + 1; i++) temp[i + x] = s[i];
   for (i = 1; i <= n; i++) s[i] = temp[i];
 }
 int main() {
   int t, i, j, k, x, l1, l2, flag, o;
   scanf('%d', &t);
   scanf('%s', s + 1);
   scanf('%s', e + 1);
   l1 = strlen(s + 1);
   l2 = strlen(e + 1);
   if (l1 != l2) {
     printf('-1
');
     return 0;
   }
   memset(q, 0, sizeof(q));
   for (i = 1; i <= l1; i++) {
     q[s[i] - 'a']++;
     q[e[i] - 'a']--;
   }
   flag = 1;
   for (i = 0; i < 26; i++) {
     if (q[i]) flag = 0;
   }
   if (flag == 0) {
     printf('-1
');
     return 0;
   }
   n = l1;
   printf('%d
', n * 3);
   cnt = 0;
   for (o = 0; o < n; o++) {
     f(n);
     c = e[n - o];
     for (i = n - o; i >= 0; i--) {
       if (s[i] == c) break;
     }
     f(n - i);
     f(1);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = 1e9 + 10, MAX = 7e5 + 1e4, MOD = 1e9 + 7, MAXL = 25;
 void OUT(long double o, int x) {
   cout << fixed << setprecision(x) << o;
   return;
 }
 long long sth[MAX], mah[MAX], reg[MAX], ti[MAX], en[MAX], he[MAX], hh[MAX],
     pa[MAX];
 long long la[MAX];
 pair<pair<long long, long long>, long long> so[MAX];
 set<long long> st;
 map<long long, long long> mp;
 vector<pair<pair<long long, long long>, long long> > v[MAX];
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long n, m, ans = 0, bo, da, in;
   bool inff = 0;
   cin >> n >> m >> bo >> in >> da;
   st.insert(0);
   for (int i = 1; i <= n; i++) {
     cin >> mah[i] >> sth[i] >> reg[i];
     if (mah[i] <= da) inff = 1;
     hh[i] = sth[i];
     if (hh[i] <= da && (reg[i] != 0 && mah[i] > da)) {
       st.insert((da - hh[i]) / reg[i]);
       st.insert(((da - hh[i]) / reg[i]) + 1);
     }
   }
   for (int i = 1; i <= m; i++) {
     cin >> ti[i] >> en[i] >> he[i];
     so[i] = {{ti[i], en[i]}, he[i]};
   }
   so[0].first.first = -1;
   sort(so + 1, so + m + 1);
   for (int i = 1; i <= m; i++) {
     hh[so[i].first.second] = so[i].second;
     st.insert(so[i].first.first);
     st.insert(so[i].first.first - 1);
     if (so[i].second <= da &&
         (reg[so[i].first.second] != 0 && mah[so[i].first.second] > da)) {
       st.insert(so[i].first.first +
                 ((da - so[i].second) / reg[so[i].first.second]));
       st.insert(1 + so[i].first.first +
                 ((da - so[i].second) / reg[so[i].first.second]));
     }
   }
   for (int i = 1; i <= n; i++) {
     if (reg[i] == 0 && hh[i] <= da) inff = 1;
   }
   if (inff == 1 && in != 0) return cout << -1, 0;
   long long cnt = 0, x = 0;
   for (int u : st) {
     mp[u] = cnt;
     cnt++;
   }
   for (int i = 1; i <= n; i++) {
     hh[i] = sth[i];
     la[i] = -1;
     if (hh[i] <= da)
       x++;
     else
       la[i] = -2;
     if (hh[i] <= da && (reg[i] != 0 && mah[i] > da)) {
       pa[mp[1 + ((da - hh[i]) / reg[i])]]--;
       la[i] = ((da - hh[i]) / reg[i]);
     }
   }
   for (int i = 1; i <= m; i++) {
     v[mp[ti[i]]].push_back({{ti[i], en[i]}, he[i]});
   }
   for (int u : st) {
     for (pair<pair<long long, long long>, long long> w : v[mp[u]]) {
       hh[w.first.second] = w.second;
       if (la[w.first.second] == -1 || la[w.first.second] >= u) {
         if (la[w.first.second] != -1) pa[mp[la[w.first.second] + 1]]++;
         if (hh[w.first.second] > da)
           x--;
         else {
           if ((reg[w.first.second] != 0 && mah[w.first.second] > da)) {
             pa[mp[1 + u + ((da - hh[w.first.second]) / reg[w.first.second])]]--;
             la[w.first.second] =
                 u + ((da - hh[w.first.second]) / reg[w.first.second]);
           }
         }
       } else {
         if (hh[w.first.second] <= da) {
           x++;
           if (reg[w.first.second] > 0) {
             pa[mp[u + 1 + ((da - hh[w.first.second]) / reg[w.first.second])]]--;
             la[w.first.second] =
                 u + ((da - hh[w.first.second]) / reg[w.first.second]);
           } else
             la[w.first.second] = -1;
         }
       }
     }
     x += pa[mp[u]];
     ans = max(ans, (x * bo) + (x * in * u));
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n, k;
   cin >> n >> k;
   long long int res = 1;
   if (k == 1) {
     cout << n;
   } else {
     while (res <= n) res = (long long)(res * 2);
     cout << res - 1;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double PI = acos(-1);
 const int inf = 99999999;
 int n;
 char c[20];
 int r[20];
 int b[20];
 int dp[1 << 16][123];
 int main() {
   int n;
   cin >> n;
   int maxi = 0;
   int ans1 = 0;
   int ans2 = 0;
   for (int i = 0; i < n; i++) {
     cin >> c[i] >> r[i] >> b[i];
     maxi += i;
     ans1 += r[i];
     ans2 += b[i];
   }
   memset(dp, -1, sizeof(dp));
   dp[0][0] = 0;
   for (int i = 1; i < 1 << n; i++) {
     for (int j = 0; j < n; j++) {
       if (i >> j & 1) {
         int R = 0;
         int B = 0;
         for (int k = 0; k < n; k++) {
           if (k != j && i >> k & 1) {
             R += c[k] == 'R';
             B += c[k] == 'B';
           }
         }
         R = min(R, r[j]);
         B = min(B, b[j]);
         for (int k = 0; k <= maxi; k++) {
           if (dp[i ^ (1 << j)][k] != -1) {
             dp[i][k + R] = max(dp[i][k + R], dp[i ^ (1 << j)][k] + B);
           }
         }
       }
     }
   }
   int ans = max(ans1, ans2);
   for (int i = 0; i <= maxi; i++) {
     if (dp[(1 << n) - 1][i] != -1) {
       ans = min(ans, max(ans2 - dp[(1 << n) - 1][i], ans1 - i));
     }
   }
   cout << ans + n;
   return 0;
 }


#include <bits/stdc++.h>
 void output1(int n) {
   for (int i = 0; i < n; ++i) {
     printf('10');
   }
   printf('
');
 }
 void output2(int m) {
   --m;
   for (int i = 0; i < m; ++i) {
     printf('01');
   }
   printf('0
');
 }
 void output3(int n, int m) {
   if (n == m + 1) {
     --n;
     for (int i = 0; i < n; ++i) {
       printf('10');
     }
     printf('1
');
     return;
   }
   int tmp = n - m - 1;
   int up = m + 1;
   up--;
   for (int i = 0; i < up; ++i) {
     printf('1');
     if (tmp) {
       printf('1');
       --tmp;
     }
     printf('0');
   }
   printf('1');
   if (tmp) {
     printf('1');
   }
   printf('
');
 }
 int main() {
   int n, m;
   while (scanf('%d%d', &m, &n) != EOF) {
     if (m == n) {
       output1(n);
     } else if (m == n + 1) {
       output2(m);
     } else if (n > m && n <= 2 * m + 2) {
       output3(n, m);
     } else {
       printf('-1
');
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize('O3')
 #pragma GCC target('sse4')
 const char nl = '
';
 using namespace std;
 using ll = long long;
 using vi = vector<int>;
 using vl = vector<ll>;
 using pii = pair<int, int>;
 using pll = pair<ll, ll>;
 using str = string;
 str to_string(char c) { return str(1, c); }
 str to_string(bool b) { return b ? 'true' : 'false'; }
 str to_string(const char* second) { return (str)second; }
 str to_string(str second) { return second; }
 template <class A>
 str to_string(complex<A> c) {
   stringstream ss;
   ss << c;
   return ss.str();
 }
 str to_string(vector<bool> v) {
   str res = '{';
   for (int i = 0; i < (int)v.size(); i++) res += char('0' + v[i]);
   res += '}';
   return res;
 }
 template <size_t SZ>
 str to_string(bitset<SZ> b) {
   str res = '';
   for (int i = 0; i < b.size(); i++) res += char('0' + b[i]);
   return res;
 }
 template <class A, class B>
 str to_string(pair<A, B> p);
 template <class T>
 str to_string(T v) {
   bool fst = 1;
   str res = '{';
   for (const auto& x : v) {
     if (!fst) res += ', ';
     fst = 0;
     res += to_string(x);
   }
   res += '}';
   return res;
 }
 template <class A, class B>
 str to_string(pair<A, B> p) {
   return '(' + to_string(p.first) + ', ' + to_string(p.second) + ')';
 }
 void DBG() { cerr << ']' << endl; }
 template <class H, class... T>
 void DBG(H h, T... t) {
   cerr << to_string(h);
   if (sizeof...(t)) cerr << ', ';
   DBG(t...);
 }
 string c;
 int n;
 int dp[26][26];
 signed main() {
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);
   cin >> n;
   for (int i = 0; i < 26; i++) {
     for (int j = 0; j < 26; j++) {
       dp[i][j] = -1e9;
     }
   }
   int ans = 0;
   for (int i = 0; i < n; i++) {
     cin >> c;
     int m = c.length();
     int a = c[0] - 'a';
     int b = c[m - 1] - 'a';
     for (int j = 0; j < 26; j++) {
       dp[j][b] = max(dp[j][b], dp[j][a] + m);
     }
     dp[a][b] = max(dp[a][b], m);
   }
   for (int i = 0; i < 26; i++) {
     ans = max(ans, dp[i][i]);
   }
   cout << ans << nl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 5100;
 const long long M = 15;
 const long long mod = 1e9 + 7;
 const long long MOD = 998244353;
 const long long P = 1336;
 const long double eps = 0.000000001;
 const long long inf = 1e9;
 mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
 long long w[N], b[N], a[N], dp[N], u[N];
 vector<long long> nom[N];
 int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   srand(time(0));
   long long n, k, V;
   cin >> n >> k >> V;
   long long sum = 0;
   if (V == 0) {
     cout << 'YES' << '
';
     cout << inf << ' 1 2';
     return 0;
   }
   for (long long i = 0; i < n; i++) {
     cin >> w[i];
     sum += w[i];
     b[i] = w[i] % k;
     a[i] = w[i] - b[i];
     if (a[i] > V) a[i] = V / k * k;
   }
   if (sum < V) {
     cout << 'NO';
     return 0;
   }
   dp[0] = 1;
   for (long long i = 0; i < n; i++) {
     for (long long j = k; j >= 0; j--) {
       if (dp[j] != 1) continue;
       long long per = (j + b[i]) % k;
       if (per == 0) per = k;
       if (dp[per]) continue;
       dp[per] = 2;
       for (auto to : nom[j]) {
         nom[per].push_back(to);
       }
       nom[per].push_back(i);
     }
     for (long long j = k; j >= 0; j--) {
       if (dp[j] == 2) dp[j] = 1;
     }
   }
   for (long long i = 0; i < n; i++) {
     long long need = (V - a[i]) % k;
     if (need == 0) need = k;
     if (!dp[need] && need != k) continue;
     long long no = -1;
     vector<pair<long long, pair<long long, long long> > > g;
     for (long long j = 0; j < n; j++) {
       u[j] = 0;
     }
     for (auto to : nom[need]) {
       u[to] = 1;
     }
     if (u[i] == 0 && need != k) continue;
     long long s = 0;
     for (auto to : nom[need]) {
       u[to] = 1;
       if (to == i) {
         s += w[i];
         continue;
       }
       g.push_back({inf, {to, i}});
       s += w[to];
     }
     long long e = -1;
     for (long long j = 0; j < n; j++) {
       if (u[j]) continue;
       e = j;
     }
     if (s < V) {
       need = (V - s) / k;
       for (long long j = 0; j < n; j++) {
         if (u[j] || j == e) continue;
         long long c = w[j] / k;
         if (w[j] % k) c++;
         if (c) g.push_back({c, {j, e}});
         w[e] += w[j];
       }
       long long c = w[e] / k;
       if (c < need) continue;
       g.push_back({need, {e, i}});
     }
     if (s > V) {
       need = (s - V) / k;
       if (i)
         g.push_back({need, {i, 0}});
       else
         g.push_back({need, {i, 1}});
     }
     cout << 'YES' << '
';
     for (auto to : g) {
       cout << to.first << ' ' << to.second.first + 1 << ' '
            << to.second.second + 1 << '
';
     }
     return 0;
   }
   cout << 'NO';
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 2e5 + 10;
 int n, a[maxn], cnt[maxn], mx = 0, last[maxn * 2], ans = 0;
 void solve1(int x) {
   for (int i = 1; i <= n; i++) last[n - i] = last[n + i] = -1;
   last[n] = 0;
   int cur = 0;
   for (int i = 1; i <= n; i++) {
     if (a[i] == x)
       cur++;
     else if (a[i] == mx)
       cur--;
     if (last[n + cur] == -1)
       last[n + cur] = i;
     else
       ans = max(ans, i - last[n + cur]);
   }
 }
 void solve2(int x) {
   for (int i = 1; i <= n; i++) cnt[i] = 0;
   int l = 1, equal = 0;
   cnt[a[l]]++;
   if (cnt[a[l]] == x) equal++;
   for (int i = 2; i <= n; i++) {
     cnt[a[i]]++;
     if (cnt[a[i]] == x)
       equal++;
     else if (cnt[a[i]] > x) {
       while (cnt[a[i]] > x) {
         cnt[a[l]]--;
         if (cnt[a[l]] == x - 1) equal--;
         l++;
       }
     }
     if (equal >= 2) ans = max(ans, i - l + 1);
   }
 }
 int main() {
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
     cnt[a[i]]++;
     mx = cnt[mx] < cnt[a[i]] ? a[i] : mx;
   }
   int limt = sqrt(n);
   for (int i = 1; i <= n; i++)
     if (cnt[i] >= limt && i != mx) solve1(i);
   for (int i = 1; i < limt; i++) solve2(i);
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int arr[6];
   for (int i = 0; i < 6; i++) {
     cin >> arr[i];
   }
   sort(arr, arr + 6);
   int tracker[10];
   for (int i = 0; i < 10; i++) {
     tracker[i] = 0;
   }
   for (int i = 0; i < 6; i++) {
     tracker[arr[i]]++;
   }
   int legs = -1;
   for (int i = 0; i < 10; i++) {
     if (tracker[i] >= 4) {
       legs = i;
       break;
     }
   }
   if (legs != -1) {
     int head1 = -1, head2;
     int taken[6];
     int takenCounter = 0;
     for (int i = 0; i < 6; i++) {
       taken[i] = 0;
     }
     for (int i = 0; i < 6; i++) {
       if (arr[i] == legs) {
         taken[i] = 1;
         takenCounter++;
       }
       if (takenCounter == 4) {
         break;
       }
     }
     for (int i = 0; i < 6; i++) {
       if (taken[i] == 0) {
         if (head1 == -1) {
           head1 = arr[i];
         } else {
           head2 = arr[i];
         }
       }
     }
     if (head1 != head2) {
       cout << 'Bear';
     } else {
       cout << 'Elephant';
     }
   } else {
     cout << 'Alien';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 string s;
 int n, a, b, ans, nr1, nr0, minD;
 int main() {
   cin >> n >> a >> b;
   cin >> s;
   a--;
   b--;
   minD = (int)1e8;
   nr1 = (int)1e8;
   nr0 = (int)1e8;
   for (int i = 0; i < s.size(); i++) {
     if (s[i] == s[a]) {
       nr1 = i;
       if (abs(nr1 - nr0) < minD) minD = abs(nr1 - nr0);
     }
     if (s[i] == s[b]) {
       nr0 = i;
       if (abs(nr0 - nr1) < minD) minD = abs(nr0 - nr1);
     }
   }
   cout << minD;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 void minn(T& a, T b) {
   if (a > b) a = b;
 }
 template <class T>
 void maxx(T& a, T b) {
   if (a < b) a = b;
 }
 void debug() { return; }
 template <class H, class... T>
 void debug(H a, T... b) {
   cerr << a;
   debug(b...);
 }
 void is() { return; }
 template <class H, class... T>
 void is(H& a, T&... b) {
   cin >> a;
   is(b...);
 }
 void os() { return; }
 template <class H, class... T>
 void os(H a, T... b) {
   cout << a;
   os(b...);
 }
 const int mod = 1e9 + 7;
 const int N = 2e5 + 5;
 int n, q;
 int nx[N], pr[N], nx100[N];
 void sw(int x, int y) {
   swap(nx[x], nx[y]);
   pr[nx[x]] = x;
   pr[nx[y]] = y;
   int k = x;
   for (int i = 1; i <= 100; i++) k = pr[k];
   for (int i = 1; i <= 105; i++) {
     nx100[k] = x;
     x = nx[x];
     k = nx[k];
   }
   k = y;
   for (int i = 1; i <= 100; i++) k = pr[k];
   for (int i = 1; i <= 105; i++) {
     nx100[k] = y;
     y = nx[y];
     k = nx[k];
   }
 }
 void solve() {
   is(n, q);
   for (int i = 1; i <= n; i++) {
     is(nx[i]);
     pr[nx[i]] = i;
   }
   for (int i = 1; i <= n; i++) {
     int k = i;
     for (int j = 1; j <= 100; j++) {
       k = nx[k];
     }
     nx100[i] = k;
   }
   while (q--) {
     int t, x, y;
     is(t, x, y);
     if (t == 2) {
       int k = x;
       while (y >= 100) {
         y -= 100;
         k = nx100[k];
       }
       while (y--) k = nx[k];
       os(k, '
');
     } else {
       sw(x, y);
     }
   }
 }
 signed main() {
   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   int T = 1;
   while (T--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 5;
 const int mod = 1e9 + 7;
 int n, m, a[N], t[N], r[N], second[N];
 pair<int, int> T[2][N * 4];
 pair<int, int> get_max(int l, int r, int v = 1, int tl = 1, int tr = n) {
   if (tl > r || tr < l) return make_pair(-mod, 0);
   if (l <= tl && tr <= r) return T[0][v];
   int tm = (tl + tr) / 2;
   return max(get_max(l, r, v * 2, tl, tm),
              get_max(l, r, v * 2 + 1, tm + 1, tr));
 }
 pair<int, int> get_min(int l, int r, int v = 1, int tl = 1, int tr = n) {
   if (tl > r || tr < l) return make_pair(mod, 0);
   if (l <= tl && tr <= r) return T[1][v];
   int tm = (tl + tr) / 2;
   return min(get_min(l, r, v * 2, tl, tm),
              get_min(l, r, v * 2 + 1, tm + 1, tr));
 }
 void upd(int p, int v = 1, int tl = 1, int tr = n) {
   if (tl == tr) {
     T[0][v] = T[1][v] = make_pair(a[p], p);
     return;
   }
   int tm = (tl + tr) / 2;
   if (p <= tm)
     upd(p, v * 2, tl, tm);
   else
     upd(p, v * 2 + 1, tm + 1, tr);
   T[0][v] = max(T[0][v * 2], T[0][v * 2 + 1]);
   T[1][v] = min(T[1][v * 2], T[1][v * 2 + 1]);
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n >> m;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
     upd(i);
   }
   for (int i = 1; i <= m; i++) cin >> t[i] >> r[i];
   for (int i = m; i; i--) second[i] = max(second[i + 1], r[i]);
   for (int i = 1; i <= m; i++) {
     if (r[i] > second[i + 1]) {
       if (t[i] == 1) {
         for (int j = r[i]; j > second[i + 1]; j--) {
           pair<int, int> x = get_max(1, j);
           swap(a[x.second], a[j]);
           upd(x.second);
           upd(j);
         }
       } else {
         for (int j = r[i]; j > second[i + 1]; j--) {
           pair<int, int> x = get_min(1, j);
           swap(a[x.second], a[j]);
           upd(x.second);
           upd(j);
         }
       }
     }
   }
   for (int i = 1; i <= n; i++) cout << a[i] << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MOD = 1e6 + 3;
 const int INFI = 1e9 * 2;
 const long long LINFI = 1e17;
 const double pi = acos(-1.0);
 const int N = 111;
 const int M = 222222;
 const int move[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};
 int a[N][N];
 int main() {
   int n, m;
   while (scanf('%d', &n) != EOF) {
     for (int i = 0; i < n; i++)
       for (int j = 0; j < n; j++) scanf('%d', &a[i][j]);
     if (n == 1)
       printf('%d
', 0);
     else {
       for (int i = 0; i < n; i++) {
         m = 0;
         for (int j = 0; j < n; j++)
           if (i != j) m |= a[i][j];
         printf('%d ', m);
       }
       printf('
');
     }
   }
   return 0;
 }