#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     int n, m, w, a, b, v;     cin >> n >> m >> a >> b >> v;     set<int> s;     set<int> l;     for (int i = 0; i < a; ++i) {       int x;       cin >> x;       s.insert(x);     }     for (int i = 0; i < b; ++i) {       int x;       cin >> x;       l.insert(x);     }     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (y1 > y2) {         swap(y1, y2);       }       if (x1 > x2) {         swap(x1, x2);       }       int ans = INF;       if (x1 == x2) {         ans = y2 - y1;       }       auto it = s.lower_bound(y1);       if (it != s.end()) {         int y = *it;         ans = min(ans, x2 - x1 + abs(y1 - y) + abs(y2 - y));       }       if (it != s.begin()) {         --it;         int y = *it;         ans = min(ans, x2 - x1 + abs(y1 - y) + abs(y2 - y));       }       it = l.lower_bound(y1);       if (it != l.end()) {         int y = *it;         ans = min(ans, abs(y1 - y) + abs(y2 - y) + (x2 - x1 + v - 1) / v);       }       if (it != l.begin()) {         --it;         int y = *it;         ans = min(ans, abs(y1 - y) + abs(y2 - y) + (x2 - x1 + v - 1) / v);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1);   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 1e6 + 5;   const double eps = 1e-9;   using namespace std;   double xp, yp, vp, x, y, v, r, R;   double P, len, L;   pair<double, double> pos[2];   double f(double dphi) {     if (dphi > pi) dphi = 2 * pi - dphi;     if (dphi > P) return ((dphi - P) * r + L) / v;     return sqrt(len * len + R * R - 2 * len * R * cos(dphi)) / v;   }   int main() {     scanf( %lf %lf %lf %lf %lf %lf %lf , &xp, &yp, &vp, &x, &y, &v, &r);     double lo = 0, hi = 1e18;     R = hypot(xp, yp);     double omega = vp / R;     double phi0 = 0;     if (x * yp == xp * y) {       if (x * xp < 0 || y * yp < 0) phi0 = pi;     } else {       phi0 = acos((x * xp + y * yp) / (hypot(xp, yp) * hypot(x, y)));       if (x * yp < xp * y) phi0 = 2 * pi - phi0;     }     len = hypot(x, y);     L = sqrt(len * len - r * r) + sqrt(R * R - r * r);     P = acos(r / len) + acos(r / R);     hi = fabs(R - len) / v + 2 * pi * R / vp;     while (abs(hi - lo) > eps) {       double T = (lo + hi) / 2.;       double dphi = fmod(omega * T + phi0, 2 * pi);       if (dphi < 0) dphi += 2 * pi;       if (f(dphi) < T)         hi = T;       else         lo = T;     }     printf( %.20f n , lo);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> perm;   void generate(vector<int>& curr, int n) {     if (n == 4)       perm.push_back(curr);     else {       for (int i = n; i < 4; i++) {         swap(curr[n], curr[i]);         generate(curr, n + 1);         swap(curr[n], curr[i]);       }     }   }   bool yes(vector<string>& s, int i, int j, string& dir, int ind,            vector<int>& num) {     int m = s.size(), n = s[0].length();     if (i < 0 || j < 0 || i >= m || j >= n) return false;     if (s[i][j] ==  E ) return true;     if (s[i][j] ==  # ) return false;     if (ind == dir.length()) return false;     int val = dir[ind] -  0 ;     if (num[val] == 0) return yes(s, i + 1, j, dir, ind + 1, num);     if (num[val] == 1) return yes(s, i, j - 1, dir, ind + 1, num);     if (num[val] == 2) return yes(s, i - 1, j, dir, ind + 1, num);     if (num[val] == 3) return yes(s, i, j + 1, dir, ind + 1, num);     return false;   }   int main() {     vector<int> curr = {0, 1, 2, 3};     generate(curr, 0);     int m, n;     cin >> m;     cin >> n;     vector<string> s(m,   );     for (int i = 0; i < m; i++) cin >> s[i];     string dir;     cin >> dir;     int count = 0, xi, xj;     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++)         if (s[i][j] ==  S ) {           xi = i;           xj = j;           break;         }     for (int i = 0; i < 24; i++) {       if (yes(s, xi, xj, dir, 0, perm[i])) count++;     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int64_t, int> mp1, mp2;   int fnc(int n) {     int ans = n + 1;     for (auto i = mp1.begin(); i != mp1.end(); i++) {       if (i->second >= (n + 1) / 2) return 0;       if (i->second + mp2[i->first] >= ((n + 1) / 2))         ans = min(ans, (n + 1) / 2 - i->second);     }     if (ans < n) return ans;     for (auto i = mp2.begin(); i != mp2.end(); i++) {       if (i->second >= (n + 1) / 2) return (n + 1) / 2;     }     if (ans > n) return -1;     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int m;     cin >> m;     int64_t a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       mp1[a]++;       if (a != b) mp2[b]++;     }     cout << fnc(m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10, MAXM = 2e6 + 10, INF = INT_MAX;   const int MOD = 1e9 + 7, mod = 998244353;   char s[MAXN];   char p[] =  twone ;   char k[] =  two ;   char z[] =  one ;   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %s , s + 1);       vector<int> ans;       int sz = strlen(s + 1);       for (int i = 1; i <= sz; i++) {         if (s[i] ==  o ) {           if (i > 2 && i < sz - 1) {             bool f = 0;             for (int j = 0; j < 5; j++) {               if (s[i - 2 + j] != p[j]) f = 1;             }             if (!f) {               ans.push_back(i);               continue;             }           }           if (i < sz - 1) {             bool f = 0;             for (int j = 0; j < 3; j++)               if (s[i + j] != z[j]) f = 1;             if (!f) {               ans.push_back(i + 1);               continue;             }           }           if (i > 2) {             bool f = 0;             for (int j = 0; j < 3; j++)               if (s[i - 2 + j] != k[j]) f = 1;             if (!f) {               ans.push_back(i - 1);               continue;             }           }         }       }       printf( %d n , (int)ans.size());       for (auto j : ans) printf( %d  , j);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 100 + 19;   long long d[M][M][M], n, m, k;   char c;   struct tuplee {     long long x, y, z;   };   vector<tuplee> v1, v2;   long long go(long long x1, long long y1, long long z1, long long x2,                long long y2, long long z2) {     if (x1 > x2 || y1 > y2 || z1 > z2 || d[x1][y1][z1] == 0) return 0;     if (x1 == x2 && y1 == y2 && z1 == z2) return 1;     return go(x1 + 1, y1, z1, x2, y2, z2) + go(x1, y1 + 1, z1, x2, y2, z2) +            go(x1, y1, z1 + 1, x2, y2, z2);   }   inline bool is_bad(long long x, long long y, long long z) {     tuplee T;     v1.clear();     v2.clear();     if (d[x - 1][y][z]) T.x = x - 1, T.y = y, T.z = z, v1.push_back(T);     if (d[x][y - 1][z]) T.x = x, T.y = y - 1, T.z = z, v1.push_back(T);     if (d[x][y][z - 1]) T.x = x, T.y = y, T.z = z - 1, v1.push_back(T);     if (d[x + 1][y][z]) T.x = x + 1, T.y = y, T.z = z, v2.push_back(T);     if (d[x][y + 1][z]) T.x = x, T.y = y + 1, T.z = z, v2.push_back(T);     if (d[x][y][z + 1]) T.x = x, T.y = y, T.z = z + 1, v2.push_back(T);     if (v1.empty() || v2.empty()) return false;     for (long long i = (0); i <= (v1.size() - 1); i++) {       for (long long j = (0); j <= (v2.size() - 1); j++) {         if (go(v1[i].x, v1[i].y, v1[i].z, v2[j].x, v2[j].y, v2[j].z) == 1)           return true;       }     }     return false;   }   int main() {     ios::sync_with_stdio(false);     scanf( %lld%lld%lld , &n, &m, &k);     long long ct = 0;     for (long long i1 = (1); i1 <= (n); i1++)       for (long long i2 = (1); i2 <= (m); i2++)         for (long long i3 = (1); i3 <= (k); i3++)           scanf(  %c , &c), d[i1][i2][i3] = (c -  0 );     for (long long i1 = (1); i1 <= (n); i1++)       for (long long i2 = (1); i2 <= (m); i2++)         for (long long i3 = (1); i3 <= (k); i3++) {           if (d[i1][i2][i3] && is_bad(i1, i2, i3)) ct++;         }     printf( %lld , ct);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2000005;   const int inf = 1000000009;   int c, Len, Ans, id;   char String[N], s[N];   int D[N], num[N], n, Q[N], h, t, x;   vector<int> e[N];   vector<char> v[N];   void getstr(char *s, int &l) {     l = 0;     while (String[c] !=  ,  && c < Len) s[l++] = String[c], c++;     c++;     s[l] = 0;     return;   }   void getdig(int &x) {     x = 0;     while (String[c] !=  ,  && c < Len) x = x * 10 + String[c] - 48, c++;     c++;     return;   }   void Dfs(int x, int y, int dep) {     Ans = max(Ans, dep);     D[x] = dep;     for (int i = ((int)1); i <= ((int)y); i++) {       getstr(s, n);       id++;       for (int i = ((int)0); i <= ((int)n - 1); i++) v[id].push_back(s[i]);       e[x].push_back(id);       getdig(num[id]);       Dfs(id, num[id], dep + 1);     }   }   void write(int x) {     for (int i = ((int)0); i <= ((int)v[x].size() - 1); i++) putchar(v[x][i]);     putchar(32);     return;   }   int main() {     scanf( %s , String);     Len = strlen(String) - 1;     while (c < Len) {       getstr(s, n);       id++;       e[0].push_back(id);       for (int i = ((int)0); i <= ((int)n - 1); i++) v[id].push_back(s[i]);       getdig(num[id]);       Dfs(id, num[id], 1);     }     printf( %d , Ans);     Q[t = 1] = 0;     h = 0;     while (h < t) {       x = Q[++h];       if (D[x] != D[Q[h - 1]]) puts(  );       if (x != 0) write(x);       for (int j = ((int)0); j <= ((int)e[x].size() - 1); j++) Q[++t] = e[x][j];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, x, y, z;     cin >> t;     while (t--) {       cin >> x >> y >> z;       if ((x != y && y != z && x != z) ||           ((x == y && x < z) || (y == z && y < x) || (z == x && z < y))) {         cout <<  NO n ;         continue;       } else {         cout <<  YES n ;         if (x == y && y == z) {           cout << x <<     << x <<     << x <<   n ;         } else {           if (x == y) {             cout << x <<     << z <<     << z <<   n ;           } else if (y == z) {             cout << y <<     << x <<     << x <<   n ;           } else {             cout << z <<     << y <<     << y <<   n ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   const int mod = 998244353, g = 3, _g = 332748118, maxn = 2e5 + 9;   inline int Pow(int base, int b) {     int ret(1);     while (b) {       if (b & 1) ret = 1ll * ret * base % mod;       base = 1ll * base * base % mod;       b >>= 1;     }     return ret;   }   int r[maxn], W[maxn];   inline int Fir(int n) {     int limit(1), len(0), up(n << 1);     while (limit < up) {       limit <<= 1;       ++len;     }     for (int i = 0; i < limit; ++i)       r[i] = (r[i >> 1] >> 1) | ((i & 1) << len - 1);     return limit;   }   inline void NTT(int *a, int n, int type) {     for (int i = 0; i < n; ++i)       if (i < r[i]) std::swap(a[i], a[r[i]]);     for (int mid = 1; mid < n; mid <<= 1) {       int wn(Pow(type ? g : _g, (mod - 1) / (mid << 1)));       W[0] = 1;       for (int i = 1; i < mid; ++i) W[i] = 1ll * W[i - 1] * wn % mod;       for (int R = mid << 1, j = 0; j < n; j += R)         for (int k = 0; k < mid; ++k) {           int x(a[j + k]), y(1ll * W[k] * a[j + mid + k] % mod);           a[j + k] = 1ll * (x + y) % mod;           a[j + mid + k] = 1ll * (x - y + mod) % mod;         }     }   }   int T[maxn], F[maxn], H[maxn], G[maxn], fac[maxn], fav[maxn], tmp[maxn],       sum[maxn], B[maxn];   inline int Mul(int n, int *a, int *b, int *ans) {     int limit(Fir(n));     NTT(a, limit, 1);     NTT(b, limit, 1);     for (int i = 0; i < limit; ++i) ans[i] = 1ll * a[i] * b[i] % mod;     NTT(ans, limit, 0);     for (int i = ((n - 1) << 1) + 1; i < limit; ++i) a[i] = b[i] = 0;     return Pow(limit, mod - 2);   }   inline void Solve(int n, int *a) {     if (!n) {       a[0] = 1;       return;     }     if (n == 1) {       a[1] = 1;       return;     }     int len(n / 2);     Solve(len, a);     for (int i = 0; i <= len; ++i) {       F[i] = 1ll * Pow(len, i) * fav[i] % mod;       H[i] = 1ll * fac[i] * a[i] % mod;     }     for (int i = 0; i <= (len >> 1); ++i) std::swap(H[i], H[len - i]);     int limit(Fir(len + 1));     for (int i = len + 1; i < limit; ++i) F[i] = H[i] = 0;     NTT(F, limit, 1);     NTT(H, limit, 1);     for (int i = 0; i < limit; ++i) G[i] = 1ll * F[i] * H[i] % mod;     NTT(G, limit, 0);     int ty(Pow(limit, mod - 2));     for (int i = 0; i <= len; ++i)       tmp[i] = 1ll * G[len - i] * ty % mod * Pow(fac[i], mod - 2) % mod;     int val(Mul(len + 1, a, tmp, B));     for (int i = 0; i <= (len << 1); ++i) a[i] = 1ll * B[i] * val % mod;     if (n & 1) {       for (int i = 0; i < n; ++i) T[i] = a[i];       for (int i = 1; i <= n; ++i)         a[i] = 1ll * (T[i - 1] + 1ll * (n - 1) * T[i] % mod) % mod;     }   }   inline int Get_c(int n, int m) {     return 1ll * fac[n] * fav[m] % mod * fav[n - m] % mod;   }   int n, a, b;   int ans[maxn];   int main() {     scanf( %d%d%d , &n, &a, &b);     fac[0] = fac[1] = 1;     for (int i = 2; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;     fav[n] = Pow(fac[n], mod - 2);     for (int i = n; i >= 1; --i) fav[i - 1] = 1ll * fav[i] * i % mod;     Solve(n - 1, ans);     printf( %d n , 1ll * ans[a + b - 2] * Get_c(a + b - 2, a - 1) % mod);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int d, k, a, b, t;     cin >> d >> k >> a >> b >> t;     long long int res = 0;     if (d > k) {       if (t + a * k > b * k) {         res = k * a + (d - k) * b;       } else {         long long int x =             ((d % k) * b < (d % k) * a + t ? (d % k) * b : ((d % k) * a + t));         res = k * a + (d / k - 1) * (t + k * a) + x;       }     } else {       res = a * d;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[100005];   int main() {     int n;     while (cin >> n) {       int i, tag = 0, num = 0;       for (i = 5;; i += 5) {         int x = i;         while (x % 5 == 0 && x) {           num++;           x /= 5;         }         if (num == n) {           tag = 1;           break;         } else if (num > n)           break;       }       if (tag) {         cout <<  5  << endl;         for (int p = 0; p < 5; p++) cout << i + p <<    ;         cout << endl;       } else         cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   void qread(int &x) {     int neg = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     x *= neg;   }   const int maxn = 500005;   int n;   char s[maxn];   int dp[maxn];   namespace Sgt {   int sz;   int t[maxn * 4];   void init() {     for (sz = 1; sz <= n; sz <<= 1)       ;     for (int(i) = 0; (i) < sz << 1; i++) t[i] = 0;   }   void upd(int v, int val) {     v += sz;     t[v] = val;     for (v >>= 1; v; v >>= 1) t[v] = max(t[v << 1], t[v << 1 | 1]);   }   int qry(int l, int r) {     int res = 0;     for (l += sz, r += sz; l <= r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, t[l]), l++;       if ((r + 1) & 1) res = max(res, t[r]), r--;     }     return res;   }   }  // namespace Sgt   namespace St {   const int mlog = 20;   int mn[maxn][mlog];   void init(int *a) {     for (int(i) = 0; (i) < n; i++) mn[i][0] = a[i];     for (int(j) = 1; (j) <= mlog - 1; j++)       for (int(i) = 0; (i) < n; i++) {         if (i + (1 << j - 1) >= n)           mn[i][j] = 1e9;         else           mn[i][j] = min(mn[i][j - 1], mn[i + (1 << j - 1)][j - 1]);       }   }   pair<int, int> getval(int p, int len) {     int l = p, r = p;     for (int i = mlog - 1; i >= 0; i--) {       if (l - (1 << i) >= 0 && mn[l - (1 << i) + 1][i] >= len) l -= (1 << i);       if (r + (1 << i) < n && mn[r + 1][i] >= len) r += (1 << i);     }     return make_pair(l, r);   }   }  // namespace St   namespace Sa {   pair<int, int> cur[maxn];   int tmp[maxn], sum[maxn], sa[maxn], rk[maxn], lcp[maxn];   void rsort() {     int mx = 0;     for (int(i) = 0; (i) < n; i++)       sum[cur[i].second]++, mx = max(mx, cur[i].second);     for (int(i) = 1; (i) <= mx; i++) sum[i] += sum[i - 1];     for (int i = n - 1; i >= 0; i--) tmp[--sum[cur[i].second]] = i;     for (int(i) = 0; (i) < mx + 1; i++) sum[i] = 0;     mx = 0;     for (int(i) = 0; (i) < n; i++)       sum[cur[tmp[i]].first]++, mx = max(mx, cur[tmp[i]].first);     for (int(i) = 1; (i) <= mx; i++) sum[i] += sum[i - 1];     for (int i = n - 1; i >= 0; i--) sa[--sum[cur[tmp[i]].first]] = tmp[i];     for (int(i) = 0; (i) < mx + 1; i++) sum[i] = 0;     rk[sa[0]] = 0;     for (int(i) = 1; (i) <= n - 1; i++)       rk[sa[i]] = rk[sa[i - 1]] + (cur[sa[i]] != cur[sa[i - 1]]);   }   void init() {     for (int(i) = 0; (i) < n; i++) cur[i] = make_pair(s[i], s[i]);     rsort();     for (int m = 1; m <= n; m <<= 1) {       for (int(i) = 0; (i) < n; i++)         cur[i] = make_pair(rk[i] + 1, i + m < n ? (rk[i + m] + 1) : 0);       rsort();     }     int h = 0;     for (int(i) = 0; (i) < n; i++) {       if (rk[i] == 0) continue;       int j = sa[rk[i] - 1];       if (h) h--;       while (i + h < n && j + h < n && s[i + h] == s[j + h]) h++;       lcp[rk[i]] = h;     }     St::init(lcp);   }   }  // namespace Sa   int main() {     scanf( %d%s , &n, s);     Sgt::init();     Sa::init();     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       dp[i] = dp[i + 1] + 1;       for (;;) {         bool ok = false;         pair<int, int> cur = St::getval(Sa::rk[i], dp[i] - 1);         ok |= (Sgt::qry(cur.first, cur.second) >= dp[i] - 1);         if (i + 1 < n) {           cur = St::getval(Sa::rk[i + 1], dp[i] - 1);           ok |= (Sgt::qry(cur.first, cur.second) >= dp[i] - 1);         }         if (ok) break;         if (i + dp[i] - 1 < n) Sgt::upd(Sa::rk[i + dp[i] - 1], dp[i + dp[i] - 1]);         dp[i]--;       }       ans = max(ans, dp[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int k, t;   int a[11];   long long b[16], c[11], ele[11], hash_val;   map<pair<int, long long>, long long> vis;   void add(int i) {     c[b[i]]--;     hash_val -= ele[b[i]];     b[i]++;     c[b[i]]++;     hash_val += ele[b[i]];   }   void remove(int i) {     c[b[i]]--;     hash_val -= ele[b[i]];     b[i]--;     c[b[i]]++;     hash_val += ele[b[i]];   }   long long find(int ind) {     if (ind == 11) return 1;     pair<int, long long> mp = make_pair(ind, hash_val);     if (vis.find(mp) != vis.end()) return vis[mp];     long long ans = 0;     for (int i = 0; i < 16; i++) {       if (b[i] >= t) continue;       add(i);       ans += find(ind + 1);       remove(i);     }     vis[mp] = ans;     return ans;   }   int main() {     scanf( %d%d , &k, &t);     ele[0] = 1;     for (int i = 1; i < 11; i++) ele[i] = 17 * ele[i - 1];     if (t == 10) {       printf( %x n , k);       return 0;     }     c[0] = 16;     hash_val = 16;     int fir = 10;     add(1);     for (int i = 10; i > 0; i--) {       long long x = 15ll * find(i + 1);       if (k <= x) {         fir = i;         break;       } else         k -= x;     }     remove(1);     for (int i = fir; i <= 10; i++) {       for (int j = 0; j < 16; j++) {         if (j == 0 and i == fir) continue;         if (b[j] == t) continue;         add(j);         long long x = find(i + 1);         if (k > x) {           k -= x;           remove(j);         } else {           a[i] = j;           break;         }       }     }     int i = fir;     while (i <= 10) {       if (a[i] < 10)         printf( %d , a[i]);       else         printf( %c ,  a  + a[i] - 10);       i++;     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   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)); }   const long long maxn = 1e5;   long long n, k;   vector<long long> freq(maxn, 0);   vector<long long> arr(maxn);   vector<long long> ans(maxn, 0);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n >> k;     for (long long i = 0; i < n; i++) {       cin >> arr[i];       freq[arr[i]]++;     }     long long counter = 0;     for (long long i = 0; i < 1e4 + 1; i++) {       if (freq[i] > 0) {         for (long long j = i; j < 1e4 + 1; j++) {           if (freq[j] == 0) {             continue;           }           long long now = i ^ j;           if (__builtin_popcount(now) == k) {             if (i == j) {               counter += ((freq[i] * (freq[i] - 1)) / 2);               continue;             }             counter += ((freq[i] * freq[j]));           }         }       }     }     cout << counter;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010], dp[100010][2], cum[100010];   int calc(int at, int flag) {     if (at == n + 1) return 0;     int &ret = dp[at][flag];     if (~ret) return ret;     ret = 0;     if (flag) {       ret = max(ret, calc(at + 1, 1) - a[at]);       ret = max(ret, calc(at + 1, 0) - a[at]);     } else {       ret = max(ret, calc(at + 1, 0) + a[at]);       ret = max(ret, -cum[n] + cum[at - 1]);     }     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     for (int i = 1; i <= n; ++i) cum[i] = cum[i - 1] + a[i];     memset(dp, -1, sizeof dp);     printf( %d , max(calc(1, 0), calc(1, 1)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   string toString(long long n) {     stringstream second;     second << n;     return second.str();   }   long long toNumber(string s) {     stringstream second;     long long n;     second << s;     second >> n;     return n;   }   map<int, int> mapi;   int n, m, a, b, c;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b >> c;       if (mapi[a] > 0) {         mapi[b] = 1 ^ mapi[a];         if (mapi[b] == 0) mapi[b] = 2;         mapi[c] = mapi[a] ^ mapi[b];       } else if (mapi[b] > 0) {         mapi[c] = 1 ^ mapi[b];         if (mapi[c] == 0) mapi[c] = 2;         mapi[a] = mapi[b] ^ mapi[c];       } else if (mapi[c] > 0) {         mapi[a] = 1 ^ mapi[c];         if (mapi[a] == 0) mapi[a] = 2;         mapi[b] = mapi[a] ^ mapi[c];       } else {         mapi[a] = 1;         mapi[b] = 2;         mapi[c] = 3;       }     }     for (int i = 1; i < n + 1; i++) {       cout << mapi[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-9;   const unsigned long long MOD = 1e9 + 7;   const unsigned long long INF = 1e18 + 7;   const unsigned long long MAXN = 2e5 + 7;   unsigned long long n, m, A, B, C, ans;   unsigned long long d[MAXN], out[MAXN], link[MAXN], pos[MAXN], vi[MAXN];   map<unsigned long long, unsigned long long> mp[MAXN];   unordered_set<unsigned long long> st;   vector<pair<unsigned long long, unsigned long long> > f, G[MAXN];   vector<unsigned long long> l[MAXN], r[MAXN], g[MAXN], low, high;   char vis[MAXN];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     unsigned long long i, j, k, mid, u, v, w, res;     cin >> n >> m >> A >> B >> C;     for (i = 1; i <= m; i++) {       cin >> u >> v;       d[u]++;       d[v]++;       f.push_back({min(u, v), max(u, v)});     }     sort(f.begin(), f.end(),          [](pair<unsigned long long, unsigned long long> a,             pair<unsigned long long, unsigned long long> b) {            return a.first < b.first ||                   (a.first == b.first && a.second < b.second);          });     for (auto x : f) {       l[x.second].push_back(x.first);       r[x.first].push_back(x.second);     }     res = 0;     for (i = 1; i < n - 1; i++) {       u = (i + 1) * i / 2 - i;       v = (n - 1) * n / 2 - u - i;       res += A * u * (n - 1 - i) + B * i * (i) * (n - 1 - i) + C * v * (i);     }     ans += res;     res = 0;     for (i = 0; i < m; i++) {       pair<unsigned long long, unsigned long long> x = f[i];       u = x.first * (x.first + 1) / 2 - x.first;       res += A * u + B * x.first * (x.first >= 1 ? x.first : 0ull) +              C * x.second * (x.first >= 1 ? x.first : 0ull);       u = (x.first + x.second) * (x.second - x.first + 1) / 2 - x.first -           x.second;       res += A * x.first * (x.second - x.first - 1) + B * u +              C * x.second * (x.second - x.first - 1);       u = (n - 1 + x.second) * (n - 1 - x.second + 1) / 2 - x.second;       res += A * x.first * (n - 1 - x.second) +              B * x.second * (n - 1 - x.second) + C * u;     }     ans -= res;     res = 0;     unsigned long long suml = 0, sumr = 0, cntl = 0, cntr = 0, len;     for (i = 0; i < n; i++) {       suml = sumr = cntl = cntr = 0;       len = l[i].size();       if (len) {         suml = l[i][0];         cntl = 1;         for (j = 1; j < len; j++) {           res += A * suml + B * l[i][j] * cntl + C * i * cntl;           suml += l[i][j];           cntl++;         }       }       len = r[i].size();       if (len) {         sumr = r[i][0];         cntr = 1;         for (j = 1; j < len; j++) {           res += A * i * cntr + B * sumr + C * r[i][j] * cntr;           sumr += r[i][j];           cntr++;         }       }       res += (A * suml * cntr + B * i * cntl * cntr + C * sumr * cntl) *              (cntr > 0 && cntl > 0);     }     ans += res;     res = 0;     for (auto x : f) {       if (d[x.second] < d[x.first])         G[x.second].push_back({x.first, i});       else         G[x.first].push_back({x.second, i});     }     for (i = 0; i < m; i++) {       u = f[i].first;       v = f[i].second;       for (auto vp : G[u]) pos[vp.first] = vp.second, vi[vp.first] = i + 1;       for (auto vp : G[v]) {         w = vp.first;         if (vi[w] == i + 1) {           unsigned long long x, y, z;           x = min(u, min(v, w));           z = max(u, max(v, w));           y = u + v + w - x - z;           res += A * x + B * y + C * z;         }       }     }     ans -= res;     cout << ans << endl;     return 0;   }


//================code===================//      //#define TLE      #ifdef TLE   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #endif      #include <bits/stdc++.h>   #include <unordered_map>   #include <unordered_set>   #include <random>   #include <ctime>      #define ci(t) cin>>t   #define co(t) cout<<t   #define LL long long   #define ld long double   #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)   #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)   #define setp pair<pair<int,int>,int>   #define setl pair<LL,LL>      #define M_PI 3.14159265358979323846   #define micro 0.000001      using namespace std;      #ifdef OHSOLUTION   #define ce(t) cerr<<t   #define AT cerr <<   n=================ANS================= n    #define AE cerr <<   n===================================== n    LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }   LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }   #else   #define AT   #define AE   #define ce(t)   #define __popcnt __builtin_popcount   #define gcd __gcd   #define lcm __lcm   #endif         pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,1}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN      template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }   template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }   struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } };   struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } };      const int max_v = 2e5 + 7;   const int INF = 1e9 + 7;   const LL LNF = (LL)1e18 + 7ll;   const LL mod = 1e9 + 7;      int v, e;   vector <setl> adj[max_v];   LL dist[max_v][57];   bool vist[max_v][57];      struct node   {    LL first, second;    LL cost;   };      struct cmp   {    bool operator()(const node& x, const node& b)    {     return x.second > b.second;    }   };      int main()   {   #ifdef OHSOLUTION    freopen( input.txt ,  r , stdin);   #endif     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);    ci(v >> e);       fa(i, 0, e)    {     int x, y, cost; ci(x >> y >> cost), --x, --y;     adj[x].push_back({ y,cost });     adj[y].push_back({ x,cost });    }        priority_queue<node, vector<node>, cmp> pq;    fa(i, 0, v) fa(j, 0, 51) dist[i][j] = INF;    dist[0][0] = 0;    pq.push({ 0,0 ,0});       while (!pq.empty())    {     node cur;     do     {      cur = pq.top(); pq.pop();     } while (!pq.empty() && vist[cur.first][cur.cost]);        if (vist[cur.first][cur.cost]) break;     vist[cur.first][cur.cost] = 1;        if (cur.cost)     {      for (auto x : adj[cur.first])      {       if (dist[x.first][0] > dist[cur.first][cur.cost] + (cur.cost + x.second) * (cur.cost + x.second))       {        dist[x.first][0] = dist[cur.first][cur.cost] + (cur.cost + x.second) * (cur.cost + x.second);        pq.push({ x.first,dist[x.first][0],0 });       }      }     }     else     {      for (auto x : adj[cur.first])      {       if (dist[x.first][x.second] > dist[cur.first][cur.cost])       {        dist[x.first][x.second] = dist[cur.first][cur.cost];        pq.push({ x.first,dist[x.first][x.second],x.second });       }      }     }    }       fa(i, 0, v) dist[i][0] == INF ? co(-1 <<    ) : co(dist[i][0] <<    );          return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> v;   string s;   int n;   int main() {     cin >> n >> s;     v.push_back(s);     for (int i = 0; i < n; i++) {       string s1 = s;       if (s[i] != 0) {         int kl = 10 - (s[i] - 48);         for (int j = 0; j < n; j++) {           int zn = s[j] - 48 + kl;           zn %= 10;           s1[j] = zn + 48;         }       }       string s2 =   ;       for (int j = i; j < n; j++) s2 += s1[j];       for (int j = 0; j < i; j++) s2 += s1[j];       v.push_back(s2);     }     sort(v.begin(), v.end());     cout << v[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct _IO {     _IO() {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }   } _io;   const long long maxn = 3e5 + 10, mod = 1e9 + 7;   template <typename... T>   long long madd(T... args) {     long long res = 0;     for (auto i : {args...}) {       res = (res + ((i % mod + mod) % mod)) % mod;     }     return res % mod;   }   template <typename... T>   long long mmul(T... args) {     long long res = 1;     for (auto i : {args...}) {       res = (res * ((i % mod + mod) % mod)) % mod;     }     return res % mod;   }   long long qpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res *= a;       a *= a;       b >>= 1;     }     return res;   }   long long mpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res % mod;   }   long long _inv(long long x) { return mpow(x, mod - 2); }   long long dsufa[maxn], fa[maxn], cnt[maxn];   vector<pair<long long, long long> > query;   vector<long long> edge[maxn];   deque<long long> res;   long long findfa(long long x) {     return x == dsufa[x] ? x : (dsufa[x] = findfa(dsufa[x]));   }   bool mer(long long x, long long y) {     x = findfa(x);     y = findfa(y);     if (x == y) return 0;     dsufa[x] = y;     return 1;   }   void dfs(long long u, long long p) {     for (auto v : edge[u]) {       if (v == p) continue;       fa[v] = u;       dfs(v, u);     }   }   void path(long long x, long long y) {     deque<long long> a(1, x), b(1, y);     res.clear();     while (fa[x] != x) {       x = fa[x];       a.push_front(x);     }     while (fa[y] != y) {       y = fa[y];       b.push_front(y);     }     long long len = min(a.size(), b.size());     long long idx = 0;     for (; idx < len && a[idx] == b[idx]; ++idx)       ;     res.push_back(a[idx - 1]);     for (long long i = idx; i < b.size(); ++i) res.push_back(b[i]);     for (long long i = idx; i < a.size(); ++i) res.push_front(a[i]);   }   void solve() {     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; ++i) dsufa[i] = i;     for (long long i = 1; i <= m; ++i) {       long long x, y;       cin >> x >> y;       if (mer(x, y)) {         edge[x].push_back(y);         edge[y].push_back(x);       }     }     dfs(1, 1);     long long q;     cin >> q;     for (long long i = 1; i <= q; ++i) {       long long x, y;       cin >> x >> y;       query.push_back({x, y});       ++cnt[x];       ++cnt[y];     }     bool ok = 1;     long long oddcnt = 0;     for (long long i = 1; i <= n; ++i) {       if (cnt[i] & 1) {         ok = 0;         ++oddcnt;       }     }     if (!ok) {       cout <<  NO n ;       cout << oddcnt / 2 <<   n ;     } else {       cout <<  YES n ;       for (auto vec : query) {         long long x = vec.first, y = vec.second;         path(x, y);         cout << res.size() <<   n ;         for (long long i = 0; i < res.size(); ++i)           cout << res[i] <<    n [i == (long long)res.size() - 1];       }     }   }   int main() {     long long T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int a[2010];   bool vis[2010];   long long sum;   vector<int> edge[2010];   long long DFS(int u, int d, int fa, int root) {     long long ret = 1;     for (int i = 0; i < edge[u].size(); i++) {       int v = edge[u][i];       if (v != fa && a[root] >= a[v] && a[root] - a[v] <= d &&           !(a[root] == a[v] && v > root)) {         ret = ret * (DFS(v, d, u, root) + 1) % mod;       }     }     return ret;   }   int main() {     int n, d;     scanf( %d %d , &d, &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       edge[a].push_back(b);       edge[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       sum = (sum + DFS(i, d, -1, i)) % mod;       vis[i] = true;     }     printf( %lld n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXK = 21;   long long dp[(1 << MAXK)];   int n, m;   string s;   long long d[MAXK][MAXK];   long long solve(int mask) {     if (mask == ((1 << m) - 1)) return 0ll;     long long &ret = dp[mask];     if (ret != -1) return ret;     ret = 1e10;     long long cost = __builtin_popcount(mask);     for (int i = 0; i < m; ++i) {       if ((mask & (1 << i))) continue;       long long now = solve(mask | (1 << i));       for (int j = 0; j < m; ++j) {         if (i == j) continue;         if ((mask & (1 << j)))           now += cost * d[i][j];         else           now -= cost * d[i][j];       }       ret = min(ret, now);     }     return ret;   }   int main() {     memset(dp, -1, sizeof(dp));     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n >> m;     cin >> s;     for (int i = 0; i < n - 1; ++i) {       int a = s[i] -  a ;       int b = s[i + 1] -  a ;       d[a][b]++;       if (a != b) d[b][a]++;     }     return cout << solve(0) <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     long long n, k;     cin >> n >> k;     long long len = 2 * n;     long long temp = k * 2 / len;     long long ans = k * 2 % len == 0 ? temp : temp + 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   void read(vector<T> &v) {     T x;     cin >> x;     v.push_back(x);   }   int n, a, b, x[1000005];   long long ans = (long long)1000000007 * 1000000007, f[1000005][3];   bool isPrime(int n) {     if (n < 2) return false;     int lim = sqrt(n);     for (int i = (2); i <= (lim); ++i) {       if (n % i == 0) return false;     }     return true;   }   void Solve(int p) {     if (!isPrime(p)) return;     for (int i = (0); i <= (n); ++i) {       for (int k = (0); k <= (2); ++k)         f[i][k] = (long long)1000000007 * 1000000007;     }     f[0][0] = 0;     for (int i = (1); i <= (n); ++i) {       if (x[i] % p == 0) {         f[i][0] = f[i - 1][0];         f[i][2] = min(f[i - 1][1], f[i - 1][2]);       } else if ((x[i] - 1) % p == 0 || (x[i] + 1) % p == 0) {         f[i][0] = f[i - 1][0] + b;         f[i][2] = min(f[i - 1][1], f[i - 1][2]) + b;       }       f[i][1] = min(f[i - 1][0], f[i - 1][1]) + a;     }     for (int k = (0); k <= (2); ++k) ans = min(ans, f[n][k]);   }   void Try(int p) {     int lim = sqrt(p);     for (int i = (1); i <= (lim); ++i) {       if (p % i == 0) {         Solve(i);         Solve(p / i);       }     }   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = (1); i <= (n); ++i) scanf( %d , &x[i]);     for (int d = (-1); d <= (1); ++d) {       Try(x[1] + d);       Try(x[n] + d);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long a[maxn];   pair<long long, long long> st[maxn];   long long top, n, m, k, l, r, rec, rec2;   long long ans;   int main() {     cin >> n >> k >> m;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) {       if (!top || st[top].first != a[i])         st[++top] = make_pair(a[i], 1);       else         st[top].second = (st[top].second + 1) % k;       if (st[top].second == 0) top--;     }     for (long long i = 1; i <= top; i++) {       rec += st[i].second;     }     l = 1, r = top;     while (l < r && st[l].first == st[r].first &&            (st[l].second + st[r].second) % k == 0) {       rec2 += st[l].second + st[r].second;       l++;       r--;     }     if (l == r) {       if (st[l].second * m % k == 0)         ans += m * rec - rec2 * (m) - (st[l].second * m / k * k);       else         ans += m * rec - rec2 * (m - 1) - (st[l].second * m / k * k);     } else {       if (st[l].first == st[r].first)         rec2 += (st[l].second + st[r].second) / k * k;       ans = m * rec - rec2 * (m - 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> t;   void set_val(int p, int x) {     t[p + int(t.size()) / 2] = x;     for (p = (p + int(t.size()) / 2) / 2; p > 0; p /= 2) {       t[p] = max(t[2 * p], t[2 * p + 1]);     }   }   int leftmost(int left, int y) {     if (left >= int(t.size()) / 2) return -1;     int c = left + int(t.size()) / 2;     if (t[c] > y) return left;     for (; c > 1 && !(c % 2 == 0 && t[c + 1] > y);) c /= 2;     if (c == 1) return -1;     ++c;     for (; c < int(t.size()) / 2;) {       if (t[2 * c] > y)         c *= 2;       else         c = 2 * c + 1;     }     return c - int(t.size()) / 2;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<string> req(n);     vector<int> x(n), y(n);     for (int i = 0; i < n; ++i) {       cin >> req[i] >> x[i] >> y[i];     }     vector<int> di = x;     sort(di.begin(), di.end());     di.resize(unique(di.begin(), di.end()) - di.begin());     map<int, int> id;     vector<set<int> > c(di.size());     for (int i = 0; i < int(di.size()); ++i) {       id[di[i]] = i;       c[i].insert(-1);     }     int k = 1;     for (; k < int(di.size());) k *= 2;     t = vector<int>(2 * k, -1);     for (int i = 0; i < n; ++i) {       if (req[i] ==  add ) {         c[id[x[i]]].insert(y[i]);         set<int>::iterator last = c[id[x[i]]].end();         --last;         set_val(id[x[i]], *last);       } else if (req[i] ==  remove ) {         c[id[x[i]]].erase(y[i]);         set<int>::iterator last = c[id[x[i]]].end();         --last;         set_val(id[x[i]], *last);       } else if (req[i] ==  find ) {         int a = leftmost(id[x[i]] + 1, y[i]);         if (a == -1)           cout << -1 << endl;         else           cout << di[a] <<     << *c[a].upper_bound(y[i]) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000001;   const long long LINF = 1000000000000000001LL;   int len[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   string days[] = { monday ,  tuesday ,   wednesday ,  thursday ,                     friday ,  saturday ,  sunday };   int dayId(string s) { return find(days, days + 7, s) - days; }   int main() {     ios_base::sync_with_stdio(0);     string a, b;     cin >> a >> b;     int aid = dayId(a), bid = dayId(b);     for (int i = (0); i <= (10); ++i) {       if ((aid + len[i]) % 7 == bid) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<string> words(4 * n);     string S;     int aabb = 0, abab = 0, abba = 0, aaaa = 0, NO = 0;     for (int i = (0); i < (4 * n); ++i) {       cin >> S;       int size = S.size();       int Kth = 0;       string newS =   ;       bool canRhyme = false;       for (int j = size - 1; j >= 0; --j) {         if (S[j] ==  a  || S[j] ==  e  || S[j] ==  i  || S[j] ==  u  ||             S[j] ==  o ) {           ++Kth;         }         newS = S[j] + newS;         if (Kth == k) {           canRhyme = true;           break;         }       }       if (canRhyme)         words[i] = newS;       else {         stringstream out;         out << i;         words[i] = out.str();       }     }     for (int i = 0; i < n; ++i) {       if (words[4 * i].compare(words[4 * i + 1]) == 0 &&           words[4 * i + 2].compare(words[4 * i + 3]) == 0) {         if (words[4 * i].compare(words[4 * i + 2]) == 0) {           ++aaaa;           ++aabb;           ++abab;           ++abba;         } else           ++aabb;       } else if (words[4 * i].compare(words[4 * i + 2]) == 0 &&                  words[4 * i + 1].compare(words[4 * i + 3]) == 0)         ++abab;       else if (words[4 * i].compare(words[4 * i + 3]) == 0 &&                words[4 * i + 1].compare(words[4 * i + 2]) == 0)         ++abba;       else         ++NO;     }     if (NO)       cout <<  NO  << endl;     else {       if (aaaa == n)         cout <<  aaaa  << endl;       else if (aabb == n)         cout <<  aabb  << endl;       else if (abab == n)         cout <<  abab  << endl;       else if (abba == n)         cout <<  abba  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 1e6 + 44;   const int mod = 1e9 + 9, b = 8888;   long long rcshnt[MN];   int n;   char a[MN];   bool check(int len) {     ;     long long curr = 0;     for (int i = 0; i < len; ++i) curr = (curr * b + a[i]) % mod;     long long pre = curr;     ;     for (int i = len; i < n - 1; ++i) {       ;       ;       curr = ((curr - a[i - len] * rcshnt[len - 1]) % mod * b + a[i]) % mod;       ;       if ((pre - curr) % mod == 0) {         ;         return true;       }     };     return false;   }   int main() {     scanf( %s , a);     n = strlen(a);     rcshnt[0] = 1;     for (int i = 1; i < MN; ++i) {       rcshnt[i] = rcshnt[i - 1] * b % mod;     }     for (int i = 0; i < 10; ++i)       ;     vector<int> pre;     long long ph = 0, sh = 0;     for (int i = 0; i < n - 1; ++i) {       ph = (ph * b + a[i]) % mod;       sh = (sh + a[n - i - 1] * rcshnt[i]) % mod;       if (ph == sh) {         pre.push_back(i + 1);         ;       }     }     int low = 1, high = n - 1, ans = 0;     while (low <= high) {       int med = (low + high) / 2;       if (check(med)) {         ans = med;         low = med + 1;       } else         high = med - 1;     }     int res = -1;     for (auto c : pre) {       if (c <= ans) res = max(res, c);     }     if (res <= 0) {       printf( Just a legend n );     } else {       a[res] = 0;       printf( %s n , a);     }   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long add(long long a, long long b) {     a += b;     if (a >= MOD) a -= MOD;     if (a < 0) a += MOD;     return a;   }   long long mul(long long a, long long b) { return a * 1ll * b % MOD; }   void solve() {     long long n;     string s;     cin >> n >> s;     string ans = string(n,  0 );     long long bal = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  ) ) bal--;       ans[i] = char( 0  + (bal & 1));       if (s[i] ==  ( ) bal++;     }     cout << ans << endl;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }   void sd() {     int n;     cin >> n;     n = 2 * n;     vector<vector<pair<int, long long>>> adj(n + 1);     vector<int> cnt(n + 1, 1);     int i;     for (i = 0; i < n - 1; i++) {       int u, v, t;       cin >> u >> v >> t;       adj[u].emplace_back(v, t);       adj[v].emplace_back(u, t);     }     vector<int> parent(n + 1, -1), topo(1, 1);     vector<long long> cost(n + 1, 0);     parent[1] = 1;     stack<int> st;     st.push(1);     while (!st.empty()) {       int u = st.top();       st.pop();       for (auto [v, c] : adj[u]) {         if (parent[v] == -1) {           parent[v] = u;           cost[v] = c;           topo.push_back(v);           st.push(v);         }       }     }     reverse(topo.begin(), topo.end());     long long G, B;     G = B = 0;     for (int u : topo) {       cnt[parent[u]] += cnt[u];       B += cost[u] * min(cnt[u], n - cnt[u]);       G += cost[u] * (cnt[u] % 2 == 1);     }     cout << G <<     << B << endl;   }   void solve() {     int t;     cin >> t;     while (t--) {       sd();     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int n = 0;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c - 48;     return n;   }   const int maxn = 1e5 + 5, N = 1 << 18, mo = 998244353;   int i, j, n, fa[maxn], size[maxn], ni[maxn], son[maxn];   long long x;   vector<int> g[maxn], F[maxn], s1[maxn << 2], s2[maxn << 2], ans[maxn];   int t1[N], t2[N], len, f[N], w[N];   int qs(int x, int y) {     int s = 1;     for (; y; y >>= 1, x = (long long)x * x % mo)       if (y & 1) s = (long long)s * x % mo;     return s;   }   void mod(int &x) { x -= x >= mo ? mo : 0; }   namespace Poly {   void pre(int len) {     int i, m = len >> 1;     for (i = 1; i <= len - 1; i++) f[i] = f[i >> 1] >> 1 | (i & 1 ? m : 0);   }   void dft(int *a, bool sig) {     int i;     for (i = 0; i <= len - 1; i++)       if (f[i] < i) swap(a[f[i]], a[i]);     for (int i = 1, d = N >> 1; i < len; i <<= 1, d >>= 1)       for (int j = 0; j < len; j += i << 1)         for (int k = 0, o = 0; k < i; k++, o += d) {           int u = a[j + k], v = (long long)a[i + j + k] * w[o] % mo;           a[j + k] = u + v >= mo ? u + v - mo : u + v;           a[i + j + k] = u - v < 0 ? u - v + mo : u - v;         }     if (sig) {       reverse(a + 1, a + len);       int re = qs(len, mo - 2);       for (i = 0; i <= len - 1; i++) a[i] = (long long)a[i] * re % mo;     }   }   void mul(vector<int> &a, vector<int> &b, vector<int> &c) {     len = 1;     for (; len < a.size() + b.size();) len <<= 1;     for (int i = 0; i < a.size(); i++) t1[i] = a[i];     for (int i = a.size(); i < len; i++) t1[i] = 0;     for (int i = 0; i < b.size(); i++) t2[i] = b[i];     for (int i = b.size(); i < len; i++) t2[i] = 0;     pre(len);     dft(t1, 0), dft(t2, 0);     for (int i = 0; i < len; i++) t1[i] = (long long)t1[i] * t2[i] % mo;     dft(t1, 1);     c.resize(a.size() + b.size() - 1);     for (int i = 0; i < c.size(); i++) c[i] = t1[i];   }   void add(vector<int> &a, vector<int> &b, vector<int> &c) {     c.resize((a.size() > b.size() ? a.size() : b.size()));     for (int i = 0; i < c.size(); i++)       mod(c[i] = (i < a.size() ? a[i] : 0) + (i < b.size() ? b[i] : 0));   }   void right(vector<int> &a, vector<int> &b) {     b.resize(a.size() + 1);     for (int i = 1; i < a.size(); i++) b[i + 1] = a[i];     b[0] = 0, b[1] = 1;   }   }  // namespace Poly   void dfs(int x, int y) {     size[x] = 1, fa[x] = y;     for (int i = 0; i < g[x].size(); i++) {       int go = g[x][i];       if (go == y) continue;       dfs(go, x);       size[x] += size[go];       if (size[go] > size[son[x]]) son[x] = go;     }   }   void solve(int k, int l, int r) {     static vector<int> t;     if (l == r) {       s1[k] = s2[k] = F[l];       return;     }     int m = ((l + r) >> 1), lk = k << 1, rk = lk + 1;     solve(lk, l, m);     solve(rk, m + 1, r);     Poly::mul(s1[lk], s1[rk], s1[k]);     Poly::mul(s1[lk], s2[rk], t);     Poly::add(s2[lk], t, s2[k]);   }   void calc(int x) {     int tot = 0;     for (int i = x; i; i = son[i]) F[++tot] = ans[i];     solve(1, 1, tot);     ans[x] = s2[1];   }   void Dfs(int x, int y) {     if (son[x]) Dfs(son[x], y);     for (int i = 0; i < g[x].size(); i++) {       int go = g[x][i];       if (go == fa[x] || go == son[x]) continue;       Dfs(go, go);       Poly::right(ans[go], ans[x]);     }     if (!ans[x].size()) ans[x].resize(2), ans[x][0] = 0, ans[x][1] = 1;     if (x == y) calc(x);   }   int main() {     w[0] = 1, w[1] = qs(3, (mo - 1) / N);     for (i = 2; i <= N - 1; i++) w[i] = (long long)w[i - 1] * w[1] % mo;     n = read(), scanf( %lld , &x);     for (i = 1; i <= n - 1; i++) {       int a = read(), b = read();       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1, 0);     Dfs(1, 1);     long long C = 1, Ans = 0;     x %= mo;     ni[1] = ni[0] = 1;     for (i = 2; i <= n; i++) ni[i] = (long long)(mo - mo / i) * ni[mo % i] % mo;     for (i = 1; i <= n; i++) {       Ans += C * ans[1][i] % mo;       C = C * (i + x) % mo * ni[i] % mo;     }     printf( %I64d n , Ans % mo);   }


#include <bits/stdc++.h>   using namespace std;   int a[1000009];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       int v = 0;       int min1 = 0x3f3f3f3f;       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);       }       for (int i = n; i >= 1; --i) {         min1 = min(a[i], min1);         if (min1 < a[i]) {           v++;         }       }       printf( %d n , v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100005], ans[100005];   struct node {     int x, y, t;   } a[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int r, n;     cin >> r >> n;     a[0].x = a[0].y = 1;     a[0].t = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i].t >> a[i].x >> a[i].y;       dp[i] = -n;       for (int j = i - 1; j >= 0; j--) {         if (a[i].t - a[j].t >= 2 * (r - 1)) {           dp[i] = max(dp[i], ans[j] + 1);           break;         }         if (a[i].t - a[j].t >= abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y)) {           dp[i] = max(dp[i], dp[j] + 1);         }       }       ans[i] = max(dp[i], ans[i - 1]);     }     cout << ans[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a;     cin >> a;     int n, s, t;     while (a--) {       cin >> n >> s >> t;       cout << max(n - s + 1, n - t + 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int query(long long a, long long b) {     cout << a <<     << b << endl << flush;     int ans;     cin >> ans;     return ans;   }   int main() {     long long n;     cin >> n;     long long a = 0, b = 0, sa = 1, sb = 1;     int ans = query(a + sa, b + sb);     while (ans) {       switch (ans) {         case 1:           a += sa;           sa = min(sa * 2, n - a);           break;         case 2:           b += sb;           sb = min(sb * 2, n - b);           break;         case 3:           sa = max(sa / 2, 1ll);           sb = max(sb / 2, 1ll);           break;         default:           return 0;       }       ans = query(a + sa, b + sb);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   int a[maxn], cnt[maxn];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int l = 1, r = 1;     int ans = 0;     cnt[a[1]]++;     while (l <= n) {       if (((r - l + 1) - cnt[a[l]]) <= k) {         ans = max(ans, cnt[a[l]]);         if (r < n) {           r++;           cnt[a[r]]++;         } else {           cnt[a[l]]--;           l++;         }       } else {         cnt[a[l]]--;         l++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define MOD (ll)1000000007   #define pii pair<int,int>   #define pll pair<ll,ll>   #define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());   ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}   ll power(ll a,ll b){ll ret=1;while(b){if(b%2)ret=ret*a%MOD;a=a*a%MOD;b/=2;}return ret;}      ll a[200001];      int main()   {       int tc;       scanf( %d ,&tc);       while(tc--)       {           int n;           scanf( %d ,&n);           for(int i=1;i<=n;i++)               scanf( %lld ,&a[i]);           vector<ll> v;           ll temp = 0;           a[0] = a[n+1] = 1e18;           for(int i=2;i<n;i++)           {               temp = max(temp, abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])-abs(a[i+1]-a[i-1]));           }           temp = max(temp, abs(a[1]-a[2]));           temp = max(temp, abs(a[n]-a[n-1]));           ll ans = 0;           for(int i=2;i<=n;i++)               ans+=abs(a[i]-a[i-1]);           printf( %lld n ,ans-temp);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool has[20];   int dp[1010][12][12];   int use[1010][12][12];   int main() {     for (int i = 1; i <= 10; i++) {       char c;       cin >> c;       if (c ==  1 ) has[i] = true;     }     int m;     cin >> m;     if (m == 1) {       for (int i = 1; i <= 10; i++)         if (has[i]) {           cout <<  YES  << endl << i << endl;           return 0;         }       cout <<  NO  << endl;       return 0;     }     for (int i = 1; i <= 10; i++)       for (int j = 1; j <= 10; j++) {         use[m][i][j] = -1;         dp[m][i][j] = true;       }     for (int i = m - 1; i >= 1; i--)       for (int dif = 1; dif <= 10; dif++)         for (int ls = 1; ls <= 10; ls++)           for (int j = dif + 1; j <= 10; j++)             if (j != ls && has[j]) {               if (dp[i + 1][j - dif][j]) {                 dp[i][dif][ls] = true;                 use[i][dif][ls] = j;                 break;               }             }     for (int i = 1; i <= 10; i++)       if (has[i])         if (dp[1][i][i]) {           cout <<  YES  << endl;           cout << i <<    ;           int k = use[1][i][i];           int diff = i;           int lev = 1;           while (k != -1) {             cout << k <<    ;             lev++;             diff = k - diff;             k = use[lev][diff][k];           }           return 0;         }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < int(n); i++) cin >> a[i];     long long diff = 0;     int m = a[0];     int ans = 0;     for (int i = 0; i < n; i++) {       if (a[i] >= m) {         m = a[i];       } else {         diff = (m - a[i]);         int d = floor(log2(diff)) + 1;         ans = max(d, ans);       }     }     cout << ans << endl;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fa[400005], iv[400005];   pair<long long, long long> p[2005];   long long dp[2005];   long long pw(long long bs, long long x) {     long long ans = 1;     while (x) {       if (x & 1) ans = ans * bs % 1000000007;       bs = bs * bs % 1000000007;       x /= 2;     }     return ans % 1000000007;   }   void init() {     fa[0] = iv[0] = 1;     for (int i = 1; i <= 400000; i++) {       fa[i] = fa[i - 1] * i % 1000000007;       iv[i] = pw(fa[i], 1000000007 - 2) % 1000000007;     }   }   long long cal(long long n, long long m) {     if (m > n) return 0;     long long ans = fa[n] % 1000000007;     ans = (ans * iv[m] % 1000000007) * iv[n - m] % 1000000007;     return ans;   }   long long lu(long long n, long long m) {     if (m == 0) return 1;     return cal(n % 1000000007, m % 1000000007) *            lu(n / 1000000007, m / 1000000007) % 1000000007;   }   int main() {     init();     long long n, m, k;     cin >> n >> m >> k;     n--;     m--;     for (int i = 0; i < k; i++) {       cin >> p[i].first >> p[i].second;       p[i].first--;       p[i].second--;     }     sort(p, p + k);     p[k].first = n;     p[k].second = m;     for (int i = 0; i <= k; i++) {       long long sum = 0;       for (int j = 0; j < i; j++) {         long long x = p[i].first - p[j].first, y = p[i].second - p[j].second;         if (x < 0 || y < 0) continue;         sum = (sum + lu(x + y, x) * dp[j] % 1000000007) % 1000000007;       }       dp[i] = (cal(p[i].first + p[i].second, p[i].first) - sum + 1000000007) %               1000000007;     }     cout << dp[k] % 1000000007 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXPOW = 20;   const int MAXA = 1048577;   const int MAXN = 100009;   int n;   int k;   vector<int> a;   unordered_set<int> visited[MAXN];   bool used[MAXA];   void gen() {     freopen( input.txt ,  w , stdout);     n = 100000;     printf( %d n , n);     for (int i = 0; i < n; ++i) printf( %d  , rand() % 1000001);     exit(0);   }   int stupid() {     used[0] = true;     for (int i = 0; i < n; ++i) {       int x = 0;       for (int j = i; j < n; ++j) {         x |= a[j];         if (!used[x]) {           cerr <<  i                 <<  :   << i << endl;           ;           cerr <<  j                 <<  :   << j << endl;           ;           cerr <<  x                 <<  :   << x << endl;           ;         }         used[x] = true;       }     }     int cnt = 0;     for (int i = 0; i < MAXA; ++i)       if (used[i]) cnt++;     return cnt;   }   int main() {     scanf( %d , &n);     a.resize(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; ++i) {       int x = 0;       for (int j = i; j < n; ++j) {         x |= a[j];         if (visited[j].find(x) != visited[j].end()) break;         visited[j].insert(x);         used[x] = true;       }     }     int cnt = 0;     for (int i = 0; i < MAXA; ++i)       if (used[i]) cnt++;     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int Mo[N], a[N];   inline int gi() {     int x = 0, o = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) ch = getchar(), o = -1;     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   inline int phi(int x) {     int ret = x, y = x;     for (int i = 2; i * i <= y; i++)       if (x % i == 0) {         while (x % i == 0) x /= i;         ret = ret / i * (i - 1);       }     if (x > 1) ret = ret / x * (x - 1);     return ret;   }   inline void calc(int &x, int y, int M) {     long long c = 1LL * x * y;     x = (c < M ? c : c % M + M);   }   inline int Pow(int x, int y, int M) {     int ret = 1;     while (y) {       if (y & 1) calc(ret, x, M);       calc(x, x, M), y >>= 1;     }     return ret;   }   inline int solve(int l, int r, int t) {     if (Mo[t] == 1) return 1;     if (l == r) {       if (a[l] < Mo[t]) return a[l];       return a[l] % Mo[t] + Mo[t];     }     return Pow(a[l], solve(l + 1, r, t + 1), Mo[t]);   }   int main() {     int n, m, q;     cin >> n >> m;     Mo[1] = m;     for (int i = 1; Mo[i] ^ 1;) Mo[++i] = m = phi(m);     for (int i = 1; i <= n; i++) a[i] = gi();     cin >> q;     while (q--) {       int l = gi(), r = gi();       printf( %d n , solve(l, r, 1) % Mo[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string s;       cin >> s;       long long i;       map<char, long long> mp;       for (i = 0; i < n; i++) {         mp[s[i]]++;       }       if (n == 2) {         if (s[0] >= s[1]) {           cout <<  NO  << endl;         } else {           cout <<  YES  << endl;           cout << 2 << endl;           cout << s[0] <<     << s.substr(1, n) << endl;         }       } else {         cout <<  YES  << endl;         cout << 2 << endl;         cout << s[0] <<     << s.substr(1, n) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, flag = 0;     cin >> n >> x >> y;     n /= 2;     if ((n == x && n == y) || (n == (x - 1) && n == (y - 1)) ||         (n == (x) && n == (y - 1)) || (n == (x - 1) && n == (y)))       flag = 1;     if (flag)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   const int inf = 1000000007;   int main() {     int a, b, c;     int x, y, z;     cin >> a >> b >> c;     cin >> x >> y >> z;     int da = a - x;     int db = b - y;     int dc = c - z;     int can = max(0, da / 2) + max(0, db / 2) + max(0, dc / 2);     int needed = min(0, da) + min(0, db) + min(0, dc);     cout << (can + needed >= 0 ?  Yes  :  No ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long s[211111], mx[211111];   int a[211111], bg[211111];   long long hf, ans;   int bhf, aa, bb;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       s[i] = s[i - 1] + a[i];     }     for (int i = k; i <= n; ++i) {       if (s[i] - s[i - k] > mx[i - 1]) {         mx[i] = s[i] - s[i - k];         bg[i] = i - k + 1;       } else         mx[i] = mx[i - 1], bg[i] = bg[i - 1];     }     hf = 0;     for (int i = n - k + 1; i >= 1; --i) {       if (mx[i] + hf >= ans) {         long long tmp = ans;         ans = mx[i] + hf;         if (tmp < ans) aa = bg[i], bb = bhf;         if (bg[i] < aa || (bg[i] == aa && bhf < bb)) {           aa = bg[i], bb = bhf;         }       }       if (s[i + k - 1] - s[i - 1] >= hf) {         hf = s[i + k - 1] - s[i - 1];         bhf = i;       }     }     cout << aa <<     << bb << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[1000003];   pair<long long, long long> b[1000003];   long long calc1() {     for (int i = 0; i < n; i++) b[i] = make_pair(-a[i], i);     sort(b, b + n);     set<signed> s1;     s1.insert(-1);     s1.insert(n);     long long ret = 0;     for (int i = 0; i < n; i++) {       set<int>::iterator tmpr = s1.lower_bound(b[i].second), tmpl = prev(tmpr);       ret -= (b[i].second - *tmpl) * (*tmpr - b[i].second) * b[i].first;       s1.insert(b[i].second);     }     return ret;   }   long long calc2() {     for (int i = 0; i < n; i++) b[i] = make_pair(-b[i].first, b[i].second);     for (int i = 0; i < n / 2; i++) swap(b[i], b[n - i - 1]);     set<signed> s1;     s1.insert(-1);     s1.insert(n);     long long ret = 0;     for (int i = 0; i < n; i++) {       set<int>::iterator tmpr = s1.lower_bound(b[i].second), tmpl = prev(tmpr);       ret += (b[i].second - *tmpl) * (*tmpr - b[i].second) * b[i].first;       s1.insert(b[i].second);     }     return ret;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %lld , a + i);     cout << calc1() - calc2();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int i, j, k, n, m;   pair<int, int> p[N];   int a[N];   int c[N];   int main() {     cin >> n;     for (i = 0; i < n; ++i) {       cin >> p[i].first;       p[i].second = i;     }     sort(p, p + n);     k = 0;     for (i = 0; i < n; ++i) {       c[p[i].first]++;       k = max(k, p[i].first);     }     for (i = 1; i <= k; ++i)       if (c[i] == 0 || (i > 1 && c[i] > c[i - 1])) {         cout << -1 << endl;         return 0;       }     m = 0;     k = 0;     for (i = 0; i < n; ++i) {       if (!i || p[i].first != p[i - 1].first) {         k = 0;       }       ++k;       m = max(m, k);       a[p[i].second] = k;     }     cout << m << endl;     for (i = 0; i < n; ++i) {       cout << a[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct _ {     ios_base::Init i;     _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }   } _;   const int lgn = 32;   int n;   vector<vector<int>> gr;   vector<vector<int>> P;   vector<int> lvl, ans, dp;   map<pair<int, int>, int> ind;   void pre(int curr, int par) {     lvl[curr] = lvl[par] + 1;     P[curr][0] = par;     for (int j = 1; j <= lgn; j++) P[curr][j] = P[P[curr][j - 1]][j - 1];     for (auto child : gr[curr]) {       if (child == par) continue;       pre(child, curr);     }     return;   }   int lca(int u, int v) {     if (lvl[u] > lvl[v]) swap(u, v);     for (int j = lgn; j >= 0; j--) {       if (lvl[P[v][j]] >= lvl[u]) v = P[v][j];     }     if (u == v) return u;     for (int j = lgn; j >= 0; j--) {       if (P[u][j] != P[v][j]) u = P[u][j], v = P[v][j];     }     return P[u][0];   }   void pull(int curr, int par) {     for (auto child : gr[curr]) {       if (child == par) continue;       pull(child, curr);       dp[curr] += dp[child];     }     if (curr != 1) ans[ind[{curr, par}]] = dp[curr];     return;   }   int main() {     cin >> n;     gr.resize(n + 1);     lvl.resize(n + 1, 0);     dp.resize(n + 1, 0);     ans.resize(n - 1, 0);     P.resize(n + 1, vector<int>(lgn + 1, 0));     for (int i = 0; i <= n - 2; i++) {       int u, v;       cin >> u >> v;       gr[u].push_back(v);       gr[v].push_back(u);       ind[{u, v}] = ind[{v, u}] = i;     }     pre(1, 1);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       if (lvl[a] > lvl[b]) swap(a, b);       int lc = lca(a, b);       if (lc == a) {         dp[b]++;         dp[a]--;       } else {         dp[a]++;         dp[b]++;         dp[lc] -= 2;       }     }     pull(1, 1);     for (int i = 0; i <= n - 2; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool rsort1(const pair<long long int, long long int> &a,               const pair<long long int, long long int> &b) {     return (a.first > b.first);   }   bool rsort2(const pair<long long int, long long int> &a,               const pair<long long int, long long int> &b) {     return (a.second > b.second);   }   bool sort2(const pair<long long int, long long int> &a,              const pair<long long int, long long int> &b) {     return (a.second < b.second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int h, m;       cin >> h >> m;       if (m == 0)         cout << (24 - h) * 60 <<   n ;       else         cout << (23 - h) * 60 + (60 - m) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a;       set<int> s;       while (a--) {         int b;         cin >> b;         s.insert(b);       }       cout << s.size() << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, p, q, a;     cin >> p >> q >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (q == 0 || a > p / q) return cout <<  NO , 0;       p -= q * a;       swap(p, q);     }     cout << ((q) ?  NO  :  YES );   }


#include <bits/stdc++.h>   #define maxn 1086      using namespace std;      typedef long long ll;      int n, m;   ll a[maxn][maxn];   ll sum[maxn], sum2[maxn];   map<ll, int> mp;      int main(){    scanf( %d%d , &m, &n);    for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) scanf( %lld , &a[i][j]);    for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) sum[i] += a[i][j], sum2[i] += a[i][j] * a[i][j];    for(int i = 2;i <= n;i++) mp[sum[i] - sum[i - 1]]++;    int mx = 0;    ll d, val;    for(map<ll, int>::iterator it = mp.begin();it != mp.end();++it){     if(it->second > mx) mx = it->second, d = it->first;    }    int x;    for(int i = 2;i <= n;i++){     if(sum[i] - sum[i - 1] != d){      if(i == n) x = n, val = d - (sum[i] - sum[i - 1]);      else if(sum[i + 1] - sum[i] != d) x = i, val = d - (sum[i] - sum[i - 1]);      else x = 1, val = sum[i] - sum[i - 1] - d;      break;     }    }    ll d2;    if(x > 3) d2 = (sum2[1] + sum2[3] - 2 * sum2[2]) / 2;    else d2 = (sum2[n - 2] + sum2[n] - 2 * sum2[n - 1]) / 2;    for(int i = 1;i <= m;i++){     if(x == 1){      if(sum2[x] - a[x][i] * a[x][i] + (a[x][i] + val) * (a[x][i] + val) + sum2[x + 2] - 2 * sum2[x + 1] == 2 * d2) return printf( %d %d , x - 1, a[x][i] + val), 0;     }else if(x == n){      if(sum2[x - 2]+ sum2[x] - a[x][i] * a[x][i] + (a[x][i] + val) * (a[x][i] + val) - 2 * sum2[x - 1] == 2 * d2) return printf( %d %d , x - 1, a[x][i] + val), 0;     }else{      if(sum2[x - 1] + sum2[x + 1] - 2 * (sum2[x] - a[x][i] * a[x][i] + (a[x][i] + val) * (a[x][i] + val)) == 2 * d2) return printf( %d %d , x - 1, a[x][i] + val), 0;     }    }       }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> A, B;   int d[10000010];   int a[10000010];   int pr[10010], pn;   bool isp[100010];   void GetPrime(int n) {     memset(isp + 2, 1, sizeof(isp) - 2);     for (int i = 2; i < n; i++) {       if (isp[i]) pr[pn++] = i;       for (int j = 0; j < pn && pr[j] * i < n; j++) {         isp[pr[j] * i] = 0;         if (i % pr[j] == 0) break;       }     }   }   int main() {     std::ios::sync_with_stdio(false);     GetPrime(10000);     cin >> n >> m;     A.resize(n), B.resize(m);     for (int i = 0; i < n; i++) cin >> A[i];     for (int i = 0; i < m; i++) cin >> B[i];     for (int i = 0; i < n; i++) {       int t = A[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) d[pr[j]]++, t /= pr[j];       }       if (t > 1) d[t]++;     }     for (int i = 0; i < m; i++) {       int t = B[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) d[pr[j]]--, t /= pr[j];       }       if (t > 1) d[t]--;     }     cout << n <<     << m << endl;     for (int i = 0; i < n; i++) {       int r = 1;       int t = A[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) {           t /= pr[j];           if (d[pr[j]] > 0) {             d[pr[j]]--;             r *= pr[j];           }         }       }       if (t > 1 && d[t] > 0) d[t]--, r *= t;       cout << r <<    ;     }     cout << endl;     for (int i = 0; i < m; i++) {       int r = 1;       int t = B[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) {           t /= pr[j];           if (d[pr[j]] < 0) {             d[pr[j]]++;             r *= pr[j];           }         }       }       if (t > 1 && d[t] < 0) d[t]++, r *= t;       cout << r <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long x, y;     long long a = 0, d = 0;     for (long long i = 0; i < n; i++) {       cin >> x >> y;       if (x < 0) {         a++;       } else         d++;     }     if (a <= 1) {       cout <<  Yes  << endl;     } else if (d <= 1) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, ans, mx;   vector<vector<int>> g;   vector<bool> vis;   bool a[100001];   void bfs(int src) {     vis[src] = true;     queue<int> q;     q.push(src);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (!vis[v]) {           vis[v] = true;           q.push(v);           ans++;         }       }     }   }   int main() {     scanf( %d%d , &n, &k);     g.resize(n);     vis.resize(n);     for (int a, b, i = 0; i < k; i++) {       scanf( %d%d , &a, &b);       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 0; i < n; i++) {       if (!vis[i]) bfs(i);     }     cout << k - ans;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long N = 100107;   long long binpow(long long x, long long y) {     if (y == 0) return 1;     if (y == 1)       return x % mod;     else if (y % 2 == 0) {       long long w = binpow(x, y / 2) % mod;       return (w * w) % mod;     } else       return ((x % mod) * (binpow(x, y - 1) % mod)) % mod;   }   int main() {     long long t = 1;     cin >> t;     while (t--) {       long long n, m, k, kol = 0, sum = 0;       set<long long> se1;       set<long long> se2;       vector<long long> v;       string s;       cin >> n >> m;       long long a[n + 10][m + 10];       for (long long i = 1; i <= n; i++)         for (long long j = 1; j <= m; j++) {           cin >> a[i][j];           if (a[i][j] == 1) {             se1.insert(i);             se2.insert(j);           }         }       long long mn = min(n - se1.size(), m - se2.size());       if (mn % 2 == 0)         cout <<  Vivek ;       else         cout <<  Ashish ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b, fr, k1, k2;   int dist[3005][3005];   bool flag[3005][3005];   vector<int> v[3005];   queue<int> q;   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) dist[i][j] = 1e9;     memset(flag, 1, sizeof(flag));     for (int k = 1; k <= n; k++) {       while (!q.empty()) q.pop();       q.push(k);       dist[k][k] = 0;       while (!q.empty()) {         fr = q.front();         q.pop();         flag[fr][fr] = false;         for (int i = 0; i < v[fr].size(); i++) {           if (flag[k][v[fr][i]]) {             flag[k][v[fr][i]] = false;             dist[k][v[fr][i]] = dist[k][fr] + 1;             q.push(v[fr][i]);           }         }       }     }     int s1, t1, l1, s2, t2, l2, ans = -1;     scanf( %d %d %d , &s1, &t1, &l1);     scanf( %d %d %d , &s2, &t2, &l2);     for (int i = 1; i < n; i++) {       for (int j = i + 1; j <= n; j++) {         k1 = min(dist[s1][i] + dist[i][j] + dist[j][t1],                  dist[s1][j] + dist[i][j] + dist[i][t1]);         k2 = min(dist[s2][i] + dist[i][j] + dist[j][t2],                  dist[s2][j] + dist[i][j] + dist[i][t2]);         if (k1 <= l1 && k2 <= l2) {           ans = max(ans, m - k1 - k2 + dist[i][j]);         }       }     }     if (dist[s1][t1] <= l1 && dist[s2][t2] <= l2) {       ans = max(ans, m - dist[s1][t1] - dist[s2][t2]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int cnt[200001], n, par;   vector<int> adj[200001];   vector<pair<int, int> > v;   void count(int h, int p) {     cnt[h]++;     for (auto it : adj[h])       if (it ^ p) {         count(it, h);         cnt[h] += cnt[it];       }   }   int ct(int h, int p) {     for (auto it : adj[h])       if (it ^ p) {         if (cnt[it] > n / 2) return ct(it, h);       }     par = p;     return h;   }   vector<pair<int, pair<int, int> > > res;   void dfs(int h, int p) {     for (auto it : adj[h])       if (it ^ p) {         dfs(it, h);       }     v.push_back({h, p});   }   void f(int h, int p) {     v.clear();     dfs(h, p);     v.pop_back();     int t = h;     for (auto it : v) {       res.push_back({p, {t, it.first}});       res.push_back({it.first, {it.second, h}});       t = it.first;     }     res.push_back({p, {t, h}});   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     count(1, 0);     int cen = ct(1, 0), cen2 = 0;     for (auto it : adj[cen])       if (par ^ it && 2 * cnt[it] == n) cen2 = it;     for (auto it : adj[cen])       if (it ^ cen2) f(it, cen);     for (auto it : adj[cen2])       if (it ^ cen) f(it, cen2);     printf( %d n , res.size());     for (auto it : res)       printf( %d %d %d n , it.first, it.second.first, it.second.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       string s;       cin >> s;       vector<long long> p(m), arr(26, 0);       vector<long long> ans(n, 0);       for (int i = 0; i < int(m); i++) {         cin >> p[i];         ++ans[p[i] - 1];       }       for (long long i = n - 1; i > 0; --i) ans[i - 1] += ans[i];       for (int i = 0; i < int(n); i++) {         arr[s[i] -  a ] += ans[i] + 1;       }       for (int i = 0; i < int(26); i++) cout << arr[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, bal;   string s, t;   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     n = s.length();     bal = m = 0;     for (int i = n - 1; i >= 0; --i) {       if (s[i] ==  0 )         --bal;       else {         if (bal + m >= 0) {           int j = i;           while (j >= 0 && s[j] ==  1 ) {             s[j] =  0 ;             --j;             ++m;           }           --bal;         } else           ++bal;       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int l[200000], r[200000], p[200001];   vector<int> beg[200001], ed[200001];   map<unsigned long long, unsigned long long> cnt, sum;   unsigned long long h[200000], all;   mt19937_64 mt(time(0));   int main() {     scanf( %d%d , &n, &m);     all = 0;     for (int i = 0; i < (int)(n); ++i) {       scanf( %d%d , l + i, r + i);       --l[i], --r[i];       ++p[l[i]];       --p[r[i] + 1];       beg[l[i]].push_back(i);       ed[r[i] + 1].push_back(i);       h[i] = mt();       all ^= h[i];     }     unsigned long long mask = 0, bmask = all, emask = 0, change = 0, ans = 0;     for (int i = 0; i < (int)(m + 1); ++i) {       for (int x : ed[i]) {         emask ^= h[x];       }       mask ^= change;       ans += cnt[mask ^ all ^ bmask] * i - sum[mask ^ all ^ bmask];       ++cnt[mask ^ emask];       sum[mask ^ emask] += i;       for (int x : beg[i]) {         change ^= h[x];         bmask ^= h[x];       }       for (int x : ed[i]) {         change ^= h[x];       }     }     int t = 0, c = 0;     for (int i = 0; i < (int)(m); ++i) {       t += p[i];       if (t > 0) {         c = 0;       } else {         ++c;         ans -= (unsigned long long)c * (c + 1) / 2;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string str;     cin >> str;     for (int i = 0;; i += 2) {       if (i >= str.length() - 1) break;       if (str[i] == str[i + 1]) {         str.erase(str.begin() + i);         i -= 2;       }     }     if (str.length() % 2) str.erase(str.end() - 1);     cout << n - str.length() << endl;     cout << str << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 60;   long long fib[MAXN];   int main() {     int n;     long long k;     cin >> n >> k;     fib[0] = 1;     fib[1] = 1;     for (int i = 2; i <= n; i++) fib[i] = fib[i - 1] + fib[i - 2];     int i = 0;     while (i < n) {       if (fib[n - i - 1] < k) {         k -= fib[n - i - 1];         cout << i + 2 <<     << i + 1 <<    ;         i += 2;       } else {         cout << i + 1 <<    ;         i++;       }     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int cnt;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> k;       cnt = 0;       if (k == 1 || k == 2 || k == 3 || k == 5 || k == 7 || k == 11) {         cout << -1 << endl;       } else {         if (k % 4 == 3) {           k = k - 15;           cnt = 2;         } else if (k % 4 == 2) {           k = k - 6;           cnt = 1;         } else if (k % 4 == 1) {           k = k - 9;           cnt = 1;         }         cnt = cnt + (k / 4);         cout << cnt << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string S;   int MOD;   int len;   long long dp[1 << 18][100];   int cnt[1 << 18];   int bits[1 << 18];   int DMASKS[1 << 18];   int powers[20];   int orig;   long long solve(int mask, int mod) {     if (mask == 0) {       return mod == 0;     }     long long &ret = dp[mask][mod];     if (ret != -1) return ret;     ret = 0;     int pos = len - cnt[mask];     int dMask = pos == 0;     int m = mask;     while (m > 0) {       int b = m & -m;       if (!(dMask & (1 << (S[bits[b]] -  0 )))) {         ret += solve(mask ^ b,                      (mod + powers[len - pos - 1] * (S[bits[b]] -  0 )) % MOD);         dMask |= 1 << (S[bits[b]] -  0 );       }       m -= b;     }     return ret;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> S >> MOD;     len = S.size();     powers[0] = 1;     powers[0] %= MOD;     for (int i = 1; i < 20; i++) {       powers[i] = powers[i - 1] * 10;       powers[i] %= MOD;     }     for (int i = 0; i < 18; i++) {       bits[1 << i] = i;     }     for (int i = 0, to = 1 << 18; i < to; i++) {       cnt[i] = __builtin_popcount(i);     }     orig = (1 << len) - 1;     cout << solve(orig, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 220000;   vector<int> e1[M], e2[M];   int p[M], dis[M];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       e1[u].push_back(v);       e2[v].push_back(u);     }     int k;     cin >> k;     for (int i = 0; i < k; i++) cin >> p[i];     queue<int> q;     q.push(p[k - 1]);     dis[p[k - 1]] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : e2[u]) {         if (dis[v] == 0) {           dis[v] = dis[u] + 1;           q.push(v);         }       }     }     int mi = 0, mx = 0;     for (int i = 0; i < k - 1; i++) {       if (dis[p[i]] != dis[p[i + 1]] + 1) ++mi;       for (int v : e1[p[i]]) {         if (v != p[i + 1] && dis[v] == dis[p[i]] - 1) {           ++mx;           break;         }       }     }     cout << mi <<     << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     if (n == 1 || n == 2) {       cout << n <<   n ;       return 0;     }     int ans = 2, temp = 2;     for (int i = 2; i < n; i++) {       if (a[i] == a[i - 1] + a[i - 2]) {         temp++;         ans = max(ans, temp);       } else {         temp = 2;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = 3.14159265358979323;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     double x0, y0, v, T, n, x, y, r;     vector<tuple<double, double> > c;     cin >> x0 >> y0 >> v >> T;     T = v * T * 1.0;     cin >> n;     while (n--) {       cin >> x >> y >> r;       double angulo, d, adiff;       d = sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));       if (d * d <= r * r || (x == x0 && y == y0)) {         cout <<  1.000 n ;         return 0;       }       if (r == 0) continue;       if (d * d >= ((r + T) * (r + T))) continue;       angulo = atan2(y - y0, x - x0);       if (angulo < 0) {         angulo += 2 * Pi;       }       if (sqrt(d * d - r * r) <= T) {         adiff = asin(r / d);       } else {         adiff = acos((-r * r + T * T + d * d) / (2 * T * d));       }       double x1 = angulo - adiff;       if (x1 < 0) x1 = 2 * Pi + x1;       c.push_back(make_tuple(x1, 1));       x1 = angulo + adiff;       if (x1 > 2 * Pi) x1 -= 2 * Pi;       c.push_back(make_tuple(x1, -1));     }     sort(c.begin(), c.end());     double s = 0.0;     int in = 0, fin = -1;     vector<int> sweep(c.size(), 0);     while (in != fin && c.size() != 0) {       double angulo, con;       if (fin == -1 && in == 0) fin = 0;       tie(angulo, con) = c[in];       if (con == -1 && s == 0) fin = in;       if (con == -1 && s > 0)         s--;       else if (con == 1)         s++;       sweep[in] += s;       in++;       in %= c.size();     }     in = -1;     for (int i = 0; i < c.size(); i++) {       if (sweep[i] == 0) {         in = i;         in++;         in %= c.size();         break;       }     }     if (in == -1 && c.size() != 0) {       cout <<  1.00 ;       return 0;     }     fin = -1;     double sum = 0.0, an = -1;     while (c.size() != 0 && in != fin) {       if (fin == -1) fin = in;       if (sweep[in] == 1 && an == -1) an = get<0>(c[in]);       if (sweep[in] == 0) {         if (get<0>(c[in]) < an)           sum += get<0>(c[in]) - an + 2 * Pi;         else           sum += get<0>(c[in]) - an;         an = -1;       }       in++;       in %= c.size();     }     cout << setprecision(20) << (sum / (2 * Pi)) <<   n ;     return 0;   }


#include<bits/stdc++.h>   // #include <ext/pb_ds/assoc_container.hpp>   // #include <ext/pb_ds/tree_policy.hpp>   // using namespace __gnu_pbds;   using namespace std;   // typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   #define ll long long    #define scn(n) scanf( %d ,&n)   #define lscn(n) scanf( %lld ,&n)   #define lpri(n) printf( %lld ,n)   #define pri(n) printf( %d ,n)   #define pln() printf(  n )   #define priln(n) printf( %d n ,n)   #define lpriln(n) printf( %lld n ,n)   #define rep(i,init,n) for(int i=init;i<n;i++)   #define pb push_back        #define mp make_pair   #define F first   #define S second   #define gcd __gcd   #define inf INT_MAX   #define ninf INT_MIN      #define inf INT_MAX   #define linf LLONG_MAX   #define lninf LLONG_MIN      const int mod = 1e9 + 7;   const int N = 2e5 + 4;      int solve()   {    int n; scn(n);       string s; cin >> s;       vector<int> pre(n + 1, 0), suf(n + 1, 0);       rep(i, 1, n + 1)    {     pre[i] = 1;        if(i - 2 >= 0 and s[i - 1] != s[i - 2])     pre[i] += pre[i - 1];    }       for(int i = n; i >= 1; i--)    {     suf[i] = 1;        if(i < n and s[i - 1] != s[i])     suf[i] += suf[i + 1];    }       rep(i, 0, n + 1)    {     if(i == 0)     {      if(s[i] ==  R )      printf( %d  , suf[i + 1] + 1);      else      printf( 1  );     }     else if(i == n)     {      if(s[i - 1] ==  L )      printf( %d  , pre[i] + 1);      else      printf( 1  );     }     else     {      int ans = 1;         if(s[i] ==  R )      ans += suf[i + 1];         if(s[i - 1] ==  L )      ans += pre[i];         printf( %d  , ans);     }    }       return 0;   }      int main()                     {    int t = 1; scn(t);       while(t--)    {     solve();    }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[200005];   int cnt[400005];   int cv[400005];   int main() {     int t;     scanf( %d , &t);     while (t--) {       memset(cnt, 0, sizeof(cnt));       memset(cv, 0, sizeof(cv));       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i * 2 <= n; i++) {         cnt[a[i] + a[n - i + 1]]++;         cv[min(a[i], a[n - i + 1]) + 1]++, cv[max(a[i], a[n - i + 1]) + k + 1]--;       }       for (int i = 3; i <= 2 * k; i++) cv[i] += cv[i - 1];       int ans = 200005;       for (int x = 2; x <= 2 * k; x++) {         ans = min(ans, n - cnt[x] - cv[x]);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000];   vector<int> adjNos[100001];   vector<long long int> diff;   int main() {     int n;     int m;     long long int sum = 0;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       if (i < m - 1) {         if (a[i] != a[i + 1]) {           adjNos[a[i]].push_back(a[i + 1]);           adjNos[a[i + 1]].push_back(a[i]);         }       }     }     long long int beforeSum;     long long int afterSum;     int vlen;     int median;     for (int i = 1; i <= n; i++) {       vlen = adjNos[i].size();       if (vlen == 0) {         continue;       }       sort(adjNos[i].begin(), adjNos[i].end());       median = adjNos[i][vlen / 2];       beforeSum = 0;       afterSum = 0;       for (int j = 0; j < vlen; j++) {         beforeSum += abs(i - adjNos[i][j]);         afterSum += abs(median - adjNos[i][j]);       }       diff.push_back(beforeSum - afterSum);       sum += beforeSum;     }     sum /= 2;     if (diff.size() != 0) {       sum -= *max_element(diff.begin(), diff.end());     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct node_t {     int l, r, k, id;     friend bool operator<(const node_t& a, const node_t& b) {       if (a.r == b.r) return a.l > b.l;       return a.r < b.r;     }     void print() { printf( l = %d, r = %d, k = %d, id = %d n , l, r, k, id); }   } node_t;   const int maxn = 1e5 + 5;   node_t Q[maxn], P[maxn];   int ans[maxn];   int main() {     ios::sync_with_stdio(false);     int n, m;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d %d , &Q[i].l, &Q[i].r);       Q[i].id = i;     }     scanf( %d , &m);     for (int i = 0; i < m; ++i) {       scanf( %d %d %d , &P[i].l, &P[i].r, &P[i].k);       P[i].id = i + 1;     }     sort(Q, Q + n);     sort(P, P + m);     set<pair<int, int> > st;     set<pair<int, int> >::iterator iter, titer;     int i, j, k;     i = 0;     for (j = 0; j < m; ++j) {       while (i < n && Q[i].r <= P[j].r) {         st.insert(make_pair(Q[i].l, Q[i].id));         ++i;       }       iter = st.lower_bound(make_pair(P[j].l, -1));       while (iter != st.end() && P[j].k-- > 0) {         ans[iter->second] = P[j].id;         titer = iter;         iter++;         st.erase(titer);       }     }     if (i < n || st.size() > 0) {       puts( NO );     } else {       puts( YES );       for (int i = 0; i < n; ++i) {         printf( %d  , ans[i]);       }       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   long long SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   long long SIZE(const T &t) {     return t.size();   }   string to_string(const string s, long long x1 = 0, long long x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(const bool b) { return (b ?  true  :  false ); }   string to_string(const char c) { return string({c}); }   template <size_t N>   string to_string(const bitset<N> &b, long long x1 = 0, long long x2 = 1e9) {     string t =   ;     for (long long __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(const A(&v), long long x1 = 0, long long x2 = 1e9,                    C... coords);   long long l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(const pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(const A(&v), long long x1, long long x2, C... coords) {     long long rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgm() { ; }   template <typename Heads, typename... Tails>   void dbgm(Heads H, Tails... T) {     cerr << to_string(H) <<   |  ;     dbgm(T...);   }   void FIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long N = 2e5 + 6;   int32_t main() {     FIO();     long long tc;     cin >> tc;     while (tc--) {       long long n, m;       cin >> m >> n;       vector<vector<long long> > a(m, vector<long long>(n));       vector<long long> v(n, -1);       for (long long i = 0; i < m; i++) {         for (long long j = 0; j < n; j++) {           cin >> a[i][j];           v[j] = max(v[j], a[i][j]);         }       }       long long ans = 1e18;       for (long long i = 0; i < n; i++) ans = min(ans, v[i]);       if (n <= m) {         long long val = -1;         for (long long i = 0; i < m; i++) {           sort(a[i].begin(), a[i].end());           val = max(val, a[i][n - 2]);         }         ans = min(ans, val);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 7;   const int base = 19260817;   int a[mx];   int n;   unsigned long long hs[mx * 2];   void init() {     hs[0] = 1;     for (int i = 1; i <= 2 * n; i++) hs[i] = hs[i - 1] * base;   }   int main() {     int m, x;     scanf( %d , &n);     init();     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     scanf( %d , &m);     unsigned long long ans = 0, cur = 0;     long long sum = 0;     int p = 1, go = 1;     for (int i = 1; i <= m; i++) {       scanf( %d , &x);       ans += hs[x - 1];     }     if (m == 1) {       printf( 0 n );       return 0;     }     int pre = 0;     for (int i = 1; i <= m; i++) {       sum += (i == 1 ? 0 : abs(a[p] - a[pre]));       cur += hs[p - 1];       pre = p;       p += go;       if (p == n)         go = -1;       else if (p == 1)         go = 1;     }     set<long long> s;     if (cur == ans) s.insert(sum);     for (int i = 2; i <= 2 * n - 2; i++) {       cur -= i > n ? hs[2 * n - i] : hs[i - 2];       int end = i + (m - 1) % (2 * n - 2);       while (end > 2 * n - 2) end -= 2 * n - 2;       cur += end > n ? hs[2 * n - end - 1] : hs[end - 1];       sum -= abs(i <= n ? a[i] - a[i - 1] : a[2 * n - i] - a[2 * n - i + 1]);       sum += abs(end <= n ? (end == 1 ? a[2] - a[1] : a[end] - a[end - 1])                           : a[2 * n - end] - a[2 * n - end + 1]);       if (cur == ans) {         s.insert(sum);       }     }     if (s.size() != 1)       printf( -1 n );     else       printf( %lld n , *s.begin());     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   void rot(int n, int *x, int *y, int rx, int ry);   int xy2d(int n, int x, int y) {     int rx, ry, s, d = 0;     for (s = n / 2; s > 0; s /= 2) {       rx = (x & s) > 0;       ry = (y & s) > 0;       d += s * s * ((3 * rx) ^ ry);       rot(s, &x, &y, rx, ry);     }     return d;   }   void d2xy(int n, int d, int *x, int *y) {     int rx, ry, s, t = d;     *x = *y = 0;     for (s = 1; s < n; s *= 2) {       rx = 1 & (t / 2);       ry = 1 & (t ^ rx);       rot(s, x, y, rx, ry);       *x += s * rx;       *y += s * ry;       t /= 4;     }   }   void rot(int n, int *x, int *y, int rx, int ry) {     int t;     if (ry == 0) {       if (rx == 1) {         *x = n - 1 - *x;         *y = n - 1 - *y;       }       t = *x;       *x = *y;       *y = t;     }   }   int main() {     int a, b;     cin >> a >> b;     int x, y;     d2xy(1 << a, b, &x, &y);     cout << x <<     << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     puts( Even );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[60];     while (scanf( %s , s) == 1) {       int k = strlen(s);       int sum = 0;       for (int i = 0; i < k / 2; i++) {         if (s[i] == s[k - i - 1]) sum++;       }       int ans = k;       if (sum == k / 2) ans -= 1;       int t = 0;       if (ans == k - 1) {         for (int i = 1; i <= (k - 1) / 2; i++) {           if (s[i] == s[k - i]) t++;         }         if (t == (k - 1) / 2) ans = 0;       }       printf( %d n , ans);     }     return 0;   }