#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> piles(n);     vector<pair<int, int>> cost(n);     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &tmp);       piles[i] = tmp;       int closest = int(sqrt(tmp) + 0.5f);       cost[i] = pair<int, int>(abs(tmp - closest * closest), tmp);     }     sort(cost.begin(), cost.end());     unsigned long long result = 0;     for (int i = 0; i < n; i++) {       int _cost = cost[i].first;       int _number = cost[i].second;       if (i < n / 2) {         result += _cost;       } else {         if (_cost == 0) result++;         if (_number == 0) result++;       }     }     printf( %llu n , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(int a, int b) {     bool dig[10] = {0};     while (a > 0) {       dig[a % 10] = true;       a /= 10;     }     while (b > 0) {       if (dig[b % 10]) {         return true;       }       b /= 10;     }     return false;   }   int main() {     int a;     cin >> a;     int i, s = 0;     for (i = 1; i * i <= a; i++) {       if (a % i == 0) {         if (check(a, i)) {           s++;         }         if (i != a / i && check(a, a / i)) {           s++;         }       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) {       int c = 0;       std::vector<int> v;       string s[3];       getline(cin, s[0]);       getline(cin, s[1]);       getline(cin, s[2]);       for (int i = 0; i <= 2; i++) {         for (int j = 0; j <= s[i].length() - 1; j++) {           if (s[i][j] ==  a  || s[i][j] ==  e  || s[i][j] ==  i  ||               s[i][j] ==  o  || s[i][j] ==  u )             c++;         }         v.push_back(c);         c = 0;       }       if (v[0] == 5 && v[1] == 7 && v[2] == 5) {         cout <<  YES ;       } else {         cout <<  NO ;       }     }     cerr <<  Time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     string s =    ;     sort(b.rbegin(), b.rend());     if (a.size() > b.size())       s = b.substr(0, a.size());     else       s = b;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  9 )         continue;       else if ((a[i] +  0 ) < (s[0] +  0 )) {         a[i] = s[0];         s.erase(0, 1);       }     }     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, ans =   ;     cin >> s;     int i = 0, j = s.size() - 1;     while (i < j) {       if (s[i] == s[j]) {         i++;         j--;         continue;       } else {         s.insert(s.begin() + j + 1, s[i]);         i++;       }     }     cout << s << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   void Read(int &p) {     p = 0;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) p = p * 10 + c -  0 ;   }   struct ma {     int x, y;     ma(int _x = 0, int _y = 0) : x(_x), y(_y) {}   };   bool operator<(ma a, ma b) { return a.x < b.x; }   priority_queue<ma> q[100005], Q, _q;   int n, m, x, y, z, rot, mi = 1e9, si[100005], nm = 0, be[100005];   int fir[100005], tar[200005], len[200005], nex[200005], cnt;   long long ans1;   void Add(int a, int b, int c) {     ++cnt;     tar[cnt] = b;     len[cnt] = c;     nex[cnt] = fir[a];     fir[a] = cnt;   }   int Dfs(int r, int fa) {     int sz = 1, mx = 0;     for (int i = fir[r]; i; i = nex[i]) {       int v = tar[i];       if (v != fa) {         int sum = Dfs(v, r);         mx = max(mx, sum);         sz += sum;         ans1 += (long long)len[i] * min(sum, n - sum);       }     }     mx = max(mx, n - sz);     if (mx < mi) rot = r, mi = mx;     return sz;   }   void DFS(int x, int fa, int d) {     q[d].push(ma{-x, d});     si[d]++;     be[x] = d;     for (int i = fir[x]; i; i = nex[i])       if (tar[i] != fa) DFS(tar[i], x, d);   }   int work(int u) {     while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop();     ma o;     if (_q.top().y == u) o = _q.top(), _q.pop();     while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop();     u = _q.top().y;     if (o.x) _q.push(o);     return u;   }   int main() {     Read(n);     if (n == 1) {       printf( 0 n1 n );       return 0;     }     for (int i = 1; i < n; i++) {       int u, v, w;       Read(u), Read(v), Read(w);       Add(u, v, w), Add(v, u, w);     }     Dfs(1, 0);     q[0].push(ma{-rot, 0});     _q.push(ma{-rot, 0});     si[0] = 1;     for (int i = fir[rot]; i; i = nex[i]) {       DFS(tar[i], rot, ++nm);       Q.push(ma{si[nm] << 1, nm});       _q.push(ma(q[nm].top().x, nm));     }     printf( %lld n , ans1 << 1);     for (int i = 1; i <= n; i++) {       while (Q.top().x != si[Q.top().y] + q[Q.top().y].size()) Q.pop();       if (be[i] == Q.top().y || Q.top().x < n - i + 1)         m = work(be[i]);       else         m = Q.top().y;       if (i == rot && -q[m].top().x > rot && !q[0].empty() &&           Q.top().x < n - i + 1)         m = 0;       printf( %d  , -q[m].top().x);       q[m].pop();       si[be[i]]--;       if (!q[m].empty()) _q.push(ma(q[m].top().x, m));       Q.push(ma(si[m] + q[m].size(), m));       Q.push(ma(si[be[i]] + q[be[i]].size(), be[i]));     }   }


#include <bits/stdc++.h>   using namespace std;   long long expo(long long base, long long exponent, long long mod) {     long long ans = 1;     while (exponent != 0) {       if (exponent & 1) ans = (1LL * ans * base) % mod;       base = (1LL * base * base) % mod;       exponent >>= 1;     }     return ans % mod;   }   const long long mod = 998244353;   const long long root = 565042129;   const long long root_1 = 950391366;   const long long root_pw = 1 << 20;   void fft(vector<long long> &a, bool invert) {     long long i, j, n = (long long)a.size();     for (i = 1, j = 0; i < n; ++i) {       long long bit = n >> 1;       for (; j >= bit; bit >>= 1) {         j -= bit;       }       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (long long len = 2; len <= n; len <<= 1) {       long long wlen = invert ? root_1 : root;       for (i = len; i < root_pw; i <<= 1) {         wlen = (wlen * wlen % 998244353);       }       for (i = 0; i < n; i += len) {         long long w = 1;         for (j = 0; j < len / 2; ++j) {           long long u = a[i + j],                     v = (long long)(a[i + j + len / 2] * w % 998244353);           a[i + j] = (u + v + 998244353) % 998244353;           a[i + j + len / 2] = (u - v + 998244353) % 998244353;           w = (w * wlen % 998244353);         }       }     }     if (invert) {       long long nrev = expo(n, 998244353 - 2, 998244353);       for (i = 0; i < n; ++i) {         a[i] = (a[i] * nrev % 998244353);       }     }   }   void multiply(const vector<long long> &a, const vector<long long> &b,                 vector<long long> &res) {     vector<long long> fa(a.begin(), a.end()), fb(b.begin(), b.end());     size_t n = 1;     while (n < max(a.size(), b.size())) n <<= 1;     n <<= 1;     fa.resize(n), fb.resize(n);     fft(fa, false), fft(fb, false);     for (size_t i = 0; i < n; ++i) {       fa[i] *= fb[i];     }     fft(fa, true);     res.resize(n);     for (size_t i = 0; i < n; ++i) {       res[i] = fa[i];     }   }   vector<long long> ans;   signed main() {     long long n, first, k;     vector<long long> pol(1001, 0);     vector<long long> ans(1, 1);     cin >> n >> k;     vector<long long> temp;     for (long long i = 0; i < (long long)n; i++) {       cin >> first;       pol[first] = 1;     }     while (k) {       if (k % 2) {         multiply(ans, pol, ans);         for (long long i = 0; i < (long long)ans.size(); i++) {           if (ans[i])             ans[i] = 1;           else             ans[i] = 0;         }       }       multiply(pol, pol, pol);       for (long long i = 0; i < (long long)pol.size(); i++) {         if (pol[i])           pol[i] = 1;         else           pol[i] = 0;       }       k /= 2;     }     for (long long i = 0; i < (long long)ans.size(); i++) {       if (ans[i]) cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c = 0;     cin >> n;     int arr[n];     set<int> s;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     for (int i = 1; i < n; i++) {       if (arr[i] == arr[i - 1]) {         c++;         arr[i]++;       } else if (arr[i] < arr[i - 1]) {         while (arr[i] <= arr[i - 1]) {           arr[i]++;           c++;         }       }     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, s = 0;     cin >> a >> b;     while (b > 1) {       if (b > a) swap(a, b);       s += a / b;       a -= (b * (a / b));       if (a < 1) break;     }     s += a;     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod_Expo(long long int x, long long int n, long long int M) {     if (x == 0) return 0;     if (n == 0)       return 1;     else if (n % 2 == 0)       return mod_Expo((x * x) % M, n / 2, M);     else       return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;   }   long long int binaryExponentiation(long long int x, long long int n) {     if (x == 0) return 0;     if (n == 0)       return 1;     else if (n % 2 == 0)       return binaryExponentiation(x * x, n / 2);     else       return x * binaryExponentiation(x * x, (n - 1) / 2);   }   long long int GCD(long long int A, long long int B) {     if (B == 0)       return A;     else       return GCD(B, A % B);   }   bool prime_check(long long int x) {     bool prime = (x >= 2);     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         prime = false;         break;       }     }     return prime;   }   long long int min1(long long int a, long long int b, long long int c) {     vector<long long int> v1, v2, v3;     v1.push_back(b);     v1.push_back(c);     v1.push_back(a);     sort(v1.begin(), v1.end());     return v1[0];   }   long long int min(long long int a, long long int b) {     if (a <= b)       return a;     else       return b;   }   long long int bin_search(long long int x, long long int low, long long int high,                            vector<long long int> v1) {     while (high > low) {       long long int mid = low + (high - low) / 2;       if (v1[mid] > x)         high = mid;       else         low = mid + 1;     }     return high;   }   long long int digitsum(long long int n) {     long long int sum = 0;     while (n != 0) {       sum = sum + n % 10;       n = n / 10;     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, i, j, t, f = 0, g = 0, x, y, z, k, a = 0, b = 0, c = 0, q,                                  x1, x2, y1, y2, x3, max2, min1 = 1000000, x4,                                  sum, d, M = 998244353, r, p, sum1 = 0, sum2 = 0,                                  sum3 = 0, sum4, sum5, max1 = 0, sum6;     cin >> t;     while (t--) {       cin >> n;       long long int arr[n], arr1[n];       f = 0;       set<long long int> s;       for (i = 0; i < n; i++) {         cin >> arr[i];         s.insert(arr[i]);         arr1[i] = arr[i];       }       sort(arr1, arr1 + n);       for (i = n - 1; i >= 0; i--) {         if (arr1[i] == arr[n - 1 - i]) {           f++;         }       }       if (f == n) {         if (s.size() < n)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else         cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     cin >> n;     int a[n][2], maxi = -100;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j <= 0; j++) {         sum = sum - a[i][j];         sum = sum + a[i][j + 1];         maxi = max(maxi, sum);       }     }     cout << maxi;   }


#include <bits/stdc++.h>   using namespace std;   const long long int maxN = 2e5 + 100;   const long long int maxM = 1e3 + 100;   const long long int mod = 1e9 + 7;   const long long int hmod = 1e16 + 7;   const long double PI = 3.141592653;   const long double eps = 1e-8;   const long long int D = 1379;   const long long int INF = 1e18 + 20;   const long long int Inf = 1e9 + 140;   long long int dp1[maxN];   long long int dp2[maxN];   long long int n, a[maxN];   long long int sum[maxN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long int i = 1; i <= n; i++)       cin >> a[i], sum[i] = sum[i - 1] + a[i];     dp1[n] = sum[n];     dp2[n] = -dp1[n];     for (long long int i = n - 1; i >= 1; i--) {       dp1[i] = max(dp1[i + 1], dp2[i + 1] + sum[i]);       dp2[i] = -dp1[i];     }     cout << dp1[2] << endl;   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long heavy;   long long ukupno;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     cin >> s;     heavy = 0;     ukupno = 0;     for (int i = 4; i < s.size(); i++) {       if (s[i] ==  l  && s[i - 1] ==  a  && s[i - 2] ==  t  && s[i - 3] ==  e  &&           s[i - 4] ==  m )         ukupno += heavy;       else if (s[i] ==  y  && s[i - 1] ==  v  && s[i - 2] ==  a  &&                s[i - 3] ==  e  && s[i - 4] ==  h )         heavy++;     }     cout << ukupno;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[93], b[93];     scanf( %d , &n);     int ans = 0;     a[0] = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i - 1] = a[i] - a[i - 1];     }     b[n] = 90 - a[n];     for (int i = 0; i <= n; i++) {       if (b[i] > 15) {         ans = a[i] + 15;         break;       }     }     if (!ans) ans = 90;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x1fffffffffffffff;   const double INFD = 1e20;   const double EPS = 1e-9;   const double PI = atan(1) * 4;   const long long M = 998244353;   long long mod(long long x) { return ((x % M) + M) % M; }   long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }   long long sub(long long a, long long b) { return mod(mod(a) - mod(b)); }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   long long power(long long b, long long e) {     long long ans = 1;     while (e > 0) {       if (e % 2) ans = mul(ans, b);       b = mul(b, b);       e /= 2;     }     return mod(ans);   }   long long gcd(long long a, long long b) {     for (; b > 0; swap(a, b)) a %= b;     return a;   }   long long extended_euclid(long long a, long long b, long long &x,                             long long &y) {     long long xx = y = 0;     long long yy = x = 1;     while (b) {       long long q = a / b;       long long t = b;       b = a % b;       a = t;       t = xx;       xx = x - q * xx;       x = t;       t = yy;       yy = y - q * yy;       y = t;     }     return a;   }   long long inv(long long a) {     long long x, y;     long long d = extended_euclid(a, M, x, y);     if (d > 1) return -1;     return mod(x);   }   long long scan() {     long long r;     scanf( %lld , &r);     return r;   }   void scanstr(char *buf) { scanf( %s , buf); }   int main() {     long long n = scan();     vector<long long> a(n);     for (long long i = 0; i < n; ++i) {       a[i] = scan();     }     sort(a.begin(), a.end());     vector<long long> pfs(n + 1, 0);     for (long long i = 0; i < n; ++i) pfs[i + 1] = add(pfs[i], a[i]);     long long q_inv = inv(n);     for (long long i = 1; i < n; ++i) {       long long segcount = (i <= n / 2) ? i : (n - i);       long long ballcount = n - i;       long long q = ballcount / segcount;       long long r = ballcount % segcount;       long long ans = mul(q + 1, pfs[r]);       for (long long j = 1; j < q + 1; ++j) {         long long cur = mul(             q + 1 - j, sub(pfs[r + segcount * j], pfs[r + segcount * (j - 1)]));         ans = add(ans, cur);       }       cout << mul(ans, q_inv) << endl;     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[200005];   long long siz = 0;   long long cc = 0;   long long t, n;   long long a[200005];   long long vis[200005];   long long size_dict[200005];   void dfs(long long u) {     vis[u] = cc;     siz += 1;     for (long long i = 0; i < adj[u].size(); i++) {       if (!vis[adj[u][i]]) {         dfs(adj[u][i]);       }     }   }   int main() {     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i <= 200004; i++) {         adj[i].clear();       }       for (long long i = 0; i <= 200004; i++) vis[i] = 0;       for (long long i = 0; i < n; i++) {         cin >> a[i];         adj[i + 1].push_back(a[i]);         adj[a[i]].push_back(i + 1);       }       cc = 0;       for (long long i = 0; i < n; i++) {         if (!vis[i + 1]) {           cc++;           dfs(i + 1);           size_dict[cc] = siz;           siz = 0;         }       }       for (long long i = 1; i <= n; i++) {         cout << size_dict[vis[i]] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n_keys, n_chests;   int odd_keys, even_keys, odd_chests, even_chests;   int main() {     cin >> n_keys >> n_chests;     for (int i = 0; i < n_keys; i++) {       int x;       cin >> x;       if (x % 2 == 0)         even_keys++;       else         odd_keys++;     }     for (int i = 0; i < n_chests; i++) {       int x;       cin >> x;       if (x % 2 == 0)         even_chests++;       else         odd_chests++;     }     cout << min(even_chests, odd_keys) + min(odd_chests, even_keys) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2) {       cout <<  contest n ;     } else {       cout <<  home n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     if (v[0] == v[n / 2]) {       cout <<  Bob  << endl;     } else {       cout <<  Alice  << endl;     }   }


#include <bits/stdc++.h>   int main() {     int n, a[102], sum1 = 0, sum2 = 0;     int s, t;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     scanf( %d %d , &s, &t);     if (s == t) {       printf( 0 n );     } else {       int i;       if (s > t) {         s ^= t;         t ^= s;         s ^= t;       }       for (i = s - 1; i < t - 1; i++) sum1 += a[i];       for (i = t - 1; i < n; i++) sum2 += a[i];       for (i = 0; i < s - 1; i++) sum2 += a[i];       int ans;       sum1 > sum2 ? (ans = sum2) : (ans = sum1);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 3e6 + 10, Maxk = 1e6 + 10;   int a[Maxn], l[Maxn], r[Maxn], s[Maxn], n, k;   vector<int> v[Maxk];   long long ans;   int ask(int k, int l, int r) {     int x = upper_bound(v[k].begin(), v[k].end(), r) - v[k].begin() - 1,         y = lower_bound(v[k].begin(), v[k].end(), l) - v[k].begin() - 1;     return x - y;   }   int main() {     ios::sync_with_stdio(0);     int i, j;     cin >> n >> k;     for (i = 1; i <= n; i++) cin >> a[i], s[i] = (s[i - 1] + a[i]) % k;     for (i = 0; i <= n; i++) v[s[i]].push_back(i);     for (i = 1; i <= n; i++)       for (l[i] = i - 1; l[i] >= 1 && a[l[i]] < a[i]; l[i] = l[l[i]])         ;     for (i = n; i >= 1; i--)       for (r[i] = i + 1; r[i] <= n && a[r[i]] <= a[i]; r[i] = r[r[i]])         ;     for (i = 1; i <= n; i++)       if (i - l[i] < r[i] - i) {         for (j = l[i] + 1; j <= i; j++)           ans += ask((a[i] + s[j - 1]) % k, i, r[i] - 1);       } else {         for (j = i; j <= r[i] - 1; j++)           ans += ask(((s[j] - a[i]) % k + k) % k, l[i], i - 1);       }     cout << ans - n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, ans = 0;       scanf( %d , &n);       map<string, int> book;       vector<string> aa, temp;       for (int i = 1; i <= n; i++) {         string s;         cin >> s;         book[s] = 1;         temp.push_back(s);       }       for (vector<string>::iterator it = temp.begin(); it < temp.end(); it++) {         string s;         s = *it;         if (book[s] == 1) {           book[s]++;           aa.push_back(s);         } else {           for (int i = 0; i <= 9; i++) {             s[3] = i +  0 ;             if (!book.count(s)) {               book[s] = 1;               aa.push_back(s);               break;             }           }           ans++;         }       }       printf( %d n , ans);       for (vector<string>::iterator it = aa.begin(); it < aa.end(); it++)         cout << *it << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t = 1;     while (t--) {       long long l, r, i, sum = 0;       deque<long long> a;       a.push_back(4);       a.push_back(7);       cin >> l >> r;       for (i = l; i <= r;) {         if (i <= a.front()) {           sum += a.front();           i++;         } else {           a.push_back(a.front() * 10 + 4);           a.push_back(a.front() * 10 + 7);           a.pop_front();         }       }       cout << sum <<    ;     }     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.1415926535897932384626433;   const int KL = 1e6;   using namespace std;   const long long MOD = 998244353;   int mul(int x, int y) { return x * 1LL * y % MOD; }   int add(int x, int y) {     x += y;     if (x >= MOD) x -= MOD;     return x;   }   int sub(int x, int y) {     x -= y;     if (x < 0) x += MOD;     return x;   }   int pow(int u, int v) {     if (v == 0) return 1;     int ret = pow(u, v / 2);     ret = mul(ret, ret);     if (v % 2 == 1) ret = mul(ret, u);     return ret;   }   int fact[KL + 10], invi[KL + 10], inv[KL + 10];   void init() {     fact[0] = invi[0] = invi[1] = inv[0] = 1;     for (int i = 1; i < KL; i++) fact[i] = mul(fact[i], i);     for (int i = 2; i < KL; i++) invi[i] = mul(invi[MOD % i], MOD - MOD / i);     for (int i = 1; i < KL; i++) inv[i] = mul(inv[i - 1], invi[i]);   }   int C(int u, int v) {     if (u < v) return 0;     return mul(fact[u], mul(inv[v], inv[u - v]));   }   int k, A, h, pw[KL], place[KL];   vector<pair<int, int>> res[2][2];   void solve(int mask, int pos) {     vector<int> vec;     if (pos == 0)       for (int i = 1; i <= pw[k - 1]; i++) vec.push_back(i);     else       for (int i = pw[k - 1] + 1; i <= pw[k]; i++) vec.push_back(i);     int ret = 0, cnt = 0;     while (1) {       if (vec.size() == 1) {         place[vec[0]] = 2;         int ad = mul(A, vec[0]);         res[pos][0].push_back({add(ad, ret), mask});         ad = mul(ad, A);         res[pos][1].push_back({add(ad, ret), mask});         break;       }       vector<int> nw;       for (int j = 1; j < vec.size(); j += 2) {         if ((mask & pw[cnt])) {           nw.push_back(vec[j - 1]);           int ad = mul(vec[j], pow(A, (int)vec.size() + 1));           ret = add(ret, ad);           place[vec[j]] = vec.size() + 1;         } else {           nw.push_back(vec[j]);           int ad = mul(vec[j - 1], pow(A, (int)vec.size() + 1));           ret = add(ret, ad);           place[vec[j - 1]] = vec.size() + 1;         }         cnt++;       }       vec.clear();       for (auto v : nw) vec.push_back(v);     }   }   map<int, int> mp;   bool fnd(int i, int j) {     mp.clear();     int pos = 1;     for (auto v : res[0][i]) {       mp[v.first] = pos;       pos++;     }     int pos1 = 0, pos2 = 1;     for (auto v : res[1][j]) {       int rem = sub(h, v.first);       pos1 = mp[rem];       if (pos1 > 0) break;       pos2++;     }     if (pos1 == 0) return false;     int mask1 = res[0][i][pos1 - 1].second;     int mask2 = res[1][j][pos2 - 1].second;     solve(mask1, 0);     solve(mask2, 1);     if (i == 0) {       for (int id = 1; id <= pw[k - 1]; id++)         if (place[id] == 2) place[id] = 1;     } else {       for (int id = pw[k - 1] + 1; id <= pw[k]; id++)         if (place[id] == 2) place[id] = 1;     }     for (int id = 1; id <= pw[k]; id++) printf( %d  , place[id]);     printf(  n );     return 1;   }   int main() {     pw[0] = 1;     for (int i = 1; i <= 17; i++) pw[i] = mul(pw[i - 1], 2);     scanf( %d , &k);     scanf( %d , &A);     scanf( %d , &h);     for (int mask = 0; mask < pw[pw[k - 1]]; mask++) {       solve(mask, 0);       solve(mask, 1);     }     if (fnd(1, 0)) return 0;     if (fnd(0, 1)) return 0;     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int typetest;   inline void fastIOfileinput() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     typetest = 1;   }   const int N = 1e2 + 2;   long long n;   void Enter() { cin >> n; }   long long cnt() {     return (long long)((long long)sqrt((long double)(24 * n + 1)) - 7) / 6;   }   void solve() {     long long ans = 0, x;     while (n > 1) {       ++ans;       x = cnt();       n -= (x + 1) * (3 * x + 4) / 2;     }     cout << ans <<   n ;   }   int main() {     fastIOfileinput();     if (typetest) {       int t;       cin >> t;       while (t--) {         Enter();         solve();       }     } else {       Enter();       solve();     }   }


#include <bits/stdc++.h>   int main() {     float a, b, x, y, v, g, k = 10000.000;     int i, n;     scanf( %f %f %d , &a, &b, &n);     for (i = 0; i < n; i++) {       scanf( %f %f %f , &x, &y, &v);       g = (x - a) * (x - a) + (y - b) * (y - b);       g = sqrt(g);       g = g / v;       if (g < k) {         k = g;       }     }     printf( %f n , k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string toString(T a) {     ostringstream os(  );     os << a;     return os.str();   }   template <typename T>   inline long long toLong(T a) {     long long res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline int toInt(T a) {     int res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline double toDouble(T a) {     double res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline T SQ(T a) {     return a * a;   }   template <typename T>   inline T GCD(T a, T b) {     if (b == 0)       return a;     else       return GCD(b, a % b);   }   template <typename T>   inline T LCM(T a, T b) {     long long res = a * b;     res /= GCD(a, b);     return res;   }   template <typename T>   inline unsigned long long BIGMOD(T a, T b, T m) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return SQ(BIGMOD(a, b / 2, m)) % m;     else       return (a % m * BIGMOD(a, b - 1, m)) % m;   }   template <typename T>   inline vector<string> PARSE(T str) {     vector<string> res;     string s;     istringstream os(str);     while (os >> s) res.push_back(s);     return res;   }   template <typename T>   inline unsigned long long DIST(T A, T B) {     unsigned long long res =         (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);     return res;   }   template <typename T>   inline long long CROSS(T A, T B, T C) {     return (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y);   }   template <typename T>   inline double cosAngle(T a, T b, T c) {     double res = a * a + b * b - c * c;     res = res / (2 * a * b);     res = acos(res);     return res;   }   template <typename T>   inline T POWER(T base, int po) {     T res = 1;     if (base == 0) return 0;     for (int i = (0); i < (po); i++) res *= base;     return res;   }   template <typename T>   inline bool IS_ON(T mask, T pos) {     return mask & (1 << pos);   }   template <typename T>   inline int OFF(T mask, T pos) {     return mask ^ (1 << pos);   }   template <typename T>   inline int ON(T mask, T pos) {     return mask | (1 << pos);   }   template <typename T>   inline bool INSIDE_GRID(int R, int C, int ro, int clm) {     if (R >= 0 && C >= 0 && R < ro && C < clm) return 1;     return 0;   }   template <typename T>   inline void PRINT_GRID(T GRID, int ro, int clm) {     cout <<  GRID           <<  :   << GRID << endl;     for (int i = (0); i < (ro); i++) {       for (int j = (0); j < (clm); j++) cout << GRID[i][j] <<    ;       puts(  );     }   }   map<string, int> mp;   pair<long long, long long> dp[800005];   vector<int> g[800005];   vector<int> gr[800005];   int stk[800008];   string str, str2;   vector<string> inp;   pair<long long, long long> Tolower(string &str) {     int len = str.size(), r = 0;     for (int i = (0); i < (len); i++) {       str[i] = tolower(str[i]);       if (str[i] ==  r ) r++;     }     return make_pair((long long)r, (long long)len);   }   int vis[800005], top = 0, rng;   void trop(int u) {     vis[u] = 1;     for (int i = (g[u].size() - 1); i >= (0); i--)       if (!vis[g[u][i]]) trop(g[u][i]);     stk[++top] = u;   }   void manipul(int u, int papa) {     vis[u] = 3;     dp[u] = min(dp[u], dp[papa]);     for (int i = (gr[u].size() - 1); i >= (0); i--)       if (vis[gr[u][i]] != 3) manipul(gr[u][i], papa);   }   pair<long long, long long> DP(int pos) {     if (vis[pos] != 2) {       vis[pos] = 2;       for (int i = (g[pos].size() - 1); i >= (0); i--)         dp[pos] = min(dp[pos], DP(g[pos][i]));     }     return dp[pos];   }   int main() {     int n, m;     int cnt = 1;     int s, d, len, r;     for (int i = (0); i < (800000); i++)       dp[i] = make_pair(100000000000000LL, 100000000000000LL);     scanf( %d , &n);     pair<long long, long long> tmp;     for (int i = (0); i < (n); i++) {       cin >> str;       tmp = Tolower(str);       inp.push_back(str);       if (mp.find(str) == mp.end()) mp[str] = cnt++;       s = mp[str];       dp[s] = min(dp[s], tmp);     }     rng = cnt;     scanf( %d , &m);     for (int i = (0); i < (m); i++) {       cin >> str >> str2;       tmp = Tolower(str);       tmp = Tolower(str2);       if (mp.find(str) == mp.end()) mp[str] = cnt++;       if (mp.find(str2) == mp.end()) mp[str2] = cnt++;       s = mp[str];       d = mp[str2];       dp[d] = min(dp[d], tmp);       dp[s] = min(dp[s], dp[d]);       g[s].push_back(d);       gr[d].push_back(s);     }     pair<long long, long long> res;     res = make_pair(0, 0);     for (int i = (0); i < (n); i++) {       s = mp[inp[i]];       if (!vis[s]) trop(s);     }     for (int i = (top + 1 - 1); i >= (0); i--) {       DP(stk[i]);     }     for (int i = (top + 1 - 1); i >= (0); i--) {       if (vis[stk[i]] != 3) manipul(stk[i], stk[i]);     }     for (int i = (0); i < (n); i++) {       s = mp[inp[i]];       res.first += dp[s].first;       res.second += dp[s].second;     }     cout << res.first <<     << res.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   const long long int mod = 1e9 + 7;   const long long int mod1 = 998244353;   const long long int inf = 1e18;   const long long int MX = 1e6 + 1;   const double PI = 3.141592653589793238;   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& v) {     out <<  [ ;     for (auto i = v.begin(); i != v.end(); i++)       out << (i != v.begin() ?  ,  :   ) << (*i);     return (out <<  ] );   }   template <typename T>   ostream& operator<<(ostream& out, const set<T>& s) {     out <<  [ ;     for (auto i = s.begin(); i != s.end(); i++)       out << (i != s.begin() ?  ,  :   ) << (*i);     return (out <<  ] );   }   template <typename T>   ostream& operator<<(ostream& out, const unordered_set<T>& s) {     out <<   n  <<  [ ;     for (auto i = s.begin(); i != s.end(); i++)       out << (i != s.begin() ?  ,  :   ) << (*i);     return (out <<  ] );   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, const pair<T1, T2>& p) {     return (out <<  (  << p.first <<  ,  << p.second <<  ) );   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, const map<T1, T2>& m) {     out <<  {  <<   n ;     for (auto x : m) out <<      << x.first <<   ->   << x.second <<   n ;     return (out <<  } );   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, const unordered_map<T1, T2>& m) {     out <<  {  <<   n ;     for (auto x : m) out <<      << x.first <<   ->   << x.second <<   n ;     return (out <<  } );   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     cin.ignore();     while (t--) {       long long int n, m;       cin >> n >> m;       map<long long int, long long int> mp;       for (long long int i = 0; i < m; i++) {         long long int x, y, z;         cin >> x >> y >> z;         mp[y]++;       }       long long int p1 = 0;       for (long long int i = 0; i < n; i++) {         if (mp.find(i + 1) == mp.end()) {           p1 = i + 1;           break;         }       }       for (long long int i = 0; i < n; i++) {         if (i + 1 == p1) {           continue;         }         cout << p1 <<     << i + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void Solve() {     int n;     string a, b;     cin >> n >> a >> b;     a =  -  + a +  - ;     b =  -  + b +  - ;     int val = 0;     for (int i = 1; i <= n; i++) {       if (a[i] != b[i])         val += 2;       else if (a[i] ==  0 ) {         val++;         if (a[i - 1] ==  1  && b[i - 1] ==  1 )           val++;         else if (a[i + 1] ==  1  && b[i + 1] ==  1 ) {           val++;           a[i + 1] = b[i + 1] =  - ;         }       }     }     cout << val << endl;   }   int main() {     int t;     cin >> t;     while (t--) Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     bool f = 1;     char s = getchar();     while ((s <  0  || s >  9 ) && s > 0) {       if (s ==  - ) f ^= 1;       s = getchar();     }     while (s >=  0  && s <=  9 ) x = (x << 1) + (x << 3) + s -  0 , s = getchar();     return f ? x : -x;   }   int n, m, ans[500005];   int IN, dfn[500005], low[500005], bl[500005], tot;   stack<int> st;   int d1[500005], sd[500005], d2[500005], ccg[500005];   vector<int> G[500005], cl[500005];   inline void dfs0(int x, int fa) {     dfn[x] = low[x] = ++IN, st.push(x);     for (unsigned i = 0; i < G[x].size(); i++) {       int v = G[x][i];       if (v == fa) continue;       if (!dfn[v])         dfs0(v, x), low[x] = min(low[x], low[v]);       else         low[x] = min(low[x], dfn[v]);     }     if (low[x] == dfn[x]) {       tot++;       while (!st.empty() && dfn[st.top()] >= dfn[x])         bl[st.top()] = tot, cl[tot].push_back(st.top()), st.pop();     }   }   queue<int> q;   int db[500005];   inline void bfs1(int x) {     for (int i = 1; i <= n; i++) db[i] = -1;     db[x] = 0, q.push(x);     while (!q.empty()) {       int u = q.front();       q.pop();       for (unsigned i = 0; i < G[u].size(); i++) {         int v = G[u][i];         if (db[v] < 0) db[v] = db[u] + 1, q.push(v);       }     }   }   inline void dfs1(int x) {     d1[x] = 1;     for (unsigned i = 0; i < G[x].size(); i++) {       int v = G[x][i];       if (db[v] == db[x] + 1) {         if (!d1[v]) dfs1(v);         d1[x] = max(d1[x], d1[v] + 1);       }     }   }   struct node {     int x, y;     node() {}     node(int X, int Y) { x = X, y = Y; }   };   int dq[500005 << 1], hd, tl;   bool vis[500005];   inline void dfs2(int x) {     vis[x] = 1;     int len = cl[x].size(), cj = len >> 1;     for (int id = 0; id < len; id++) {       int u = cl[x][id];       sd[u] = ans[u] = 1;       for (unsigned i = 0; i < G[u].size(); i++) {         int v = G[u][i];         if (bl[u] != bl[v]) sd[u] = max(sd[u], d1[v] + 1);       }     }     hd = tl = 0;     for (int i = cj, lim = len << 1; i < lim; i++) {       int u = cl[x][i % len], p;       while (hd < tl && i - dq[hd] > cj) hd++;       if (hd < tl) p = dq[hd], ans[u] = max(ans[u], i - p + sd[cl[x][p % len]]);       while (hd < tl && ((p = dq[tl - 1]) || 1) &&              i - p + sd[cl[x][p % len]] < sd[u])         tl--;       dq[tl++] = i;     }     hd = tl = 0;     for (int i = cj, g = (len << 1) - 1; i <= g; i++) {       int u = cl[x][(g - i) % len], p;       while (hd < tl && i - dq[hd] > cj) hd++;       if (hd < tl)         p = dq[hd], ans[u] = max(ans[u], i - p + sd[cl[x][(g - p) % len]]);       while (hd < tl && ((p = dq[tl - 1]) || 1) &&              i - p + sd[cl[x][(g - p) % len]] < sd[u])         tl--;       dq[tl++] = i;     }     for (int id = 0; id < len; id++) {       int u = cl[x][id];       hd = tl = 0;       for (unsigned i = 0; i < G[u].size(); i++)         if (bl[G[u][i]] != x) {           int v = G[u][i];           while (hd < tl && d1[dq[tl - 1]] < d1[v]) tl--;           dq[tl++] = v;         }       for (unsigned i = 0; i < G[u].size(); i++)         if (bl[G[u][i]] != x) {           int v = G[u][i], cg = ans[u];           if (hd < tl && dq[hd] == v) hd++;           if (hd < tl) cg = max(cg, d1[dq[hd]] + 1);           while (hd < tl && d1[dq[tl - 1]] < d1[v]) tl--;           dq[tl++] = v;           if (!vis[bl[v]]) ccg[v] = cg;         }       for (unsigned i = 0; i < G[u].size(); i++)         if (bl[G[u][i]] != x) {           int v = G[u][i];           if (!vis[bl[v]]) swap(d1[u], ccg[v]), dfs2(bl[v]), swap(d1[u], ccg[v]);         }     }   }   signed main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int u = read(), v = read();       G[u].push_back(v), G[v].push_back(u);     }     dfs0(1, 0);     bfs1(1), dfs1(1);     dfs2(bl[1]);     for (int i = 1; i <= n; i++) printf( %d  , max(ans[i], sd[i]) - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Read() {     char c;     while (c = getchar(), (c !=  - ) && (c <  0  || c >  9 ))       ;     bool neg = (c ==  - );     int ret = (neg ? 0 : c - 48);     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + c - 48;     return neg ? -ret : ret;   }   const int MAXN = 300005;   const long double eps = 1e-10;   struct node {     long double l, r, a, b, c, dx, da, db, dc;     int fa, son[2];     long double F(long double x) { return (a * x + b) * x + c; }   } t[MAXN << 1];   int N, Q, A, B, root, cnt;   long double ans[MAXN], apex[MAXN];   inline int CreateNew(long double l, long double r, long double a = 0,                        long double b = 0, long double c = 0, int c0 = 0,                        int c1 = 0) {     return t[++cnt].l = l, t[cnt].r = r, t[cnt].a = a, t[cnt].b = b, t[cnt].c = c,            t[cnt].son[0] = c0, t[cnt].son[1] = c1, cnt;   }   inline void MarkX(int x, long double dx) {     t[x].c += (t[x].a * dx - t[x].b) * dx;     t[x].dc += (t[x].da * dx - t[x].db) * dx;     t[x].b += -2 * t[x].a * dx, t[x].db += -2 * t[x].da * dx;     t[x].l += dx, t[x].r += dx, t[x].dx += dx;   }   inline void MarkY(int x, long double da, long double db, long double dc) {     t[x].a += da, t[x].b += db, t[x].c += dc;     t[x].da += da, t[x].db += db, t[x].dc += dc;   }   inline void Pushdown(int x) {     if (t[x].son[0])       MarkX(t[x].son[0], t[x].dx), MarkY(t[x].son[0], t[x].da, t[x].db, t[x].dc);     if (t[x].son[1])       MarkX(t[x].son[1], t[x].dx), MarkY(t[x].son[1], t[x].da, t[x].db, t[x].dc);     t[x].dx = t[x].da = t[x].db = t[x].dc = 0;   }   inline void Rotate(int x, int tp) {     int y = t[x].fa;     Pushdown(y), Pushdown(x);     t[y].son[!tp] = t[x].son[tp];     t[x].fa = t[y].fa;     if (t[x].son[tp]) t[t[x].son[tp]].fa = y;     if (t[y].fa)       t[t[y].fa].son[t[t[y].fa].son[1] == y] = x;     else       root = x;     t[y].fa = x, t[x].son[tp] = y;   }   inline void Splay(int x) {     for (Pushdown(x); t[x].fa;)       if (t[x].fa == root)         Rotate(x, t[t[x].fa].son[0] == x);       else {         int y = t[x].fa, z = t[y].fa;         if (y == t[z].son[0])           if (x == t[y].son[0])             Rotate(y, 1), Rotate(x, 1);           else             Rotate(x, 0), Rotate(x, 1);         else if (x == t[y].son[1])           Rotate(y, 0), Rotate(x, 0);         else           Rotate(x, 1), Rotate(x, 0);       }   }   inline long double FindOpt(int x) {     for (;;) {       Pushdown(x);       long double opt = min(-t[x].b * 0.5 / t[x].a, (long double)Q);       if (opt < t[x].l - eps)         if (t[x].son[0])           x = t[x].son[0];         else           return Splay(x), t[x].l;       else if (opt > t[x].r + eps)         if (t[x].son[1])           x = t[x].son[1];         else           return Splay(x), t[x].r;       else         return Splay(x), opt;     }   }   int main() {     scanf( %d%d%d%d , &N, &Q, &A, &B);     memset(t, 0, sizeof(t));     root = CreateNew(1, Q);     for (int i = 1; i <= N; i++) {       if (i > 1) {         if (A < B) {           long double opt = FindOpt(root);           apex[i] = opt;           int l(t[root].son[0]), r(t[root].son[1]);           if (opt - t[root].l > eps) {             l = CreateNew(t[root].l, opt, t[root].a, t[root].b, t[root].c,                           t[root].son[0], 0);             if (t[root].son[0]) t[t[root].son[0]].fa = l;             t[l].fa = root;           }           if (t[root].r - opt > eps) {             r = CreateNew(opt, t[root].r, t[root].a, t[root].b, t[root].c, 0,                           t[root].son[1]);             if (t[root].son[1]) t[t[root].son[1]].fa = r;             t[r].fa = root;           }           if (l) MarkX(l, A);           if (r) MarkX(r, B);           t[root].c = t[root].F(opt);           t[root].son[0] = l, t[root].son[1] = r, t[root].l = opt + A,           t[root].r = opt + B;           t[root].a = t[root].b = t[root].da = t[root].db = t[root].dc =               t[root].dx = 0;         } else           MarkX(root, A);       }       double x = Read();       MarkY(root, 1, -2 * x, x * x);     }     long double opt = FindOpt(root);     double sum = t[root].F(opt);     for (int i = N; i >= 1; i--) {       ans[i] = opt;       if (opt > apex[i] + B)         opt -= B;       else if (opt < apex[i] + A)         opt -= A;       else         opt = apex[i];     }     for (int i = 1; i <= N; i++)       printf( %.10f%c , (double)ans[i], i < N ?     :   n );     printf( %.10f n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   struct rge {     T b, e;   };   template <class T>   rge<T> range(T i, T j) {     return rge<T>{i, j};   };   template <class A, class B>   ostream &operator<<(ostream &os, pair<A, B> p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream &operator<<(ostream &os, rge<T> d) {     os <<  [ ;     for (auto it = d.b; it != d.e; it++) os << (it == d.b ?    :  ,  ) << *it;     return os <<  ] ;   }   const int N = 1e5 + 5;   const long long inf = 1e18;   long long stones[N], frogs[N];   int n, jump;   bool can(long long x) {     for (int i = (1); i <= ((n)); i += (+1)) {       frogs[i] = 0;     }     frogs[0] = x;     int l = 0, r = 1;     while (l < n) {       while (frogs[l] > 0) {         while (r <= n && stones[r] - frogs[r] <= 0) {           r++;         }         if (l + jump < r) {           return false;         }         long long add = min(frogs[l], stones[r] - frogs[r]);         frogs[r] += add;         frogs[l] -= add;       }       l++;       r = max(l + 1, r);     }     return true;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);     cin >> n >> jump;     for (int i = (1); i <= ((n - 1)); i += (+1)) {       cin >> stones[i];     }     stones[n] = inf;     long long lo = 0, hi = inf;     while (lo + 1 < hi) {       long long mid = (lo + hi) / 2;       if (can(mid)) {         lo = mid;       } else {         hi = mid;       }     }     while (can(lo + 1)) {       lo++;     }     cout << lo <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::vector<int> v[100005];   int dist[100005];   void dfs(int s, int par) {     if (par != -1) dist[s] = dist[par] + 1;     for (int i = 0; i < v[s].size(); i++) {       if (par != v[s][i]) dfs(v[s][i], s);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1, xx, x = 0, y = 0, cc, m, k, n;     cin >> t;     while (t--) {       int a, b, da, db;       cin >> n >> a >> b >> da >> db;       for (int i = 1; i < n; i++) {         cin >> x >> y;         v[x].push_back(y);         v[y].push_back(x);         dist[i] = 0;       }       dist[n] = 0;       dfs(a, -1);       int ab = dist[b];       int farest, mx = -1;       for (int i = 1; i < n + 1; i++) {         if (mx < dist[i]) {           mx = dist[i];           farest = i;         }       }       for (int i = 1; i < n + 1; i++) dist[i] = 0;       dfs(farest, -1);       int diameter = -1;       for (int i = 1; i < n + 1; i++) diameter = max(diameter, dist[i]);       if (ab <= da || 2 * da >= diameter || 2 * da >= db)         cout <<  Alice  << endl;       else         cout <<  Bob  << endl;       for (int i = 1; i < n + 1; i++) v[i].clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename F, typename S>   ostream &operator<<(ostream &os, const pair<F, S> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename F, typename S>   ostream &operator<<(ostream &os, const map<F, S> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   void faltu() { cerr << endl; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr << endl;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n, s;       cin >> n;       s = sqrt(n);       if (n == 1) {         cout << 0 << endl;         continue;       } else {         if (s * s == n) {           cout << 2 * s - 2 << endl;         } else if ((s + 1) * s >= n) {           cout << 2 * s - 1 << endl;         } else if ((s + 1) * (s + 1) >= n) {           cout << 2 * s << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, a[maxn], b[maxn], t[maxn];   bool check(int num, int pos) {     t[pos] = num;     if (pos == n) return true;     for (int i = 0; i <= 3; i++) {       if ((num | i) == a[pos] && (num & i) == b[pos]) return check(i, pos + 1);     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i < n; i++) {       scanf( %d , &b[i]);     }     for (int i = 0; i <= 3; i++) {       if (check(i, 1)) {         printf( YES n );         for (int j = 1; j <= n; j++) {           printf( %d  , t[j]);         }         return 0;       }     }     printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 10;   const int M = 5 * N;   const int OO = 1000000000;   int ans = 0;   int anum = 0;   int i;   int n;   int result;   int sum[N];   int tree[M];   string s;   int lowbit(int x) { return x & (-x); }   int min(int a, int b) { return a < b ? a : b; }   int ask(int x) {     int i = x;     int result = OO;     while (i > 0) {       result = min(result, tree[i]);       i -= lowbit(i);     }     return result;   }   void update(int x, int y) {     int i = x;     while (i < M) {       tree[i] = min(tree[i], y);       i += lowbit(i);     }   }   int main() {     getline(cin, s);     n = s.size();     for (i = 0; i < n; i++)       if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ;     for (i = 0; i < n; i++) {       sum[i + 1] = sum[i];       if (s[i] ==  A  || s[i] ==  E  || s[i] ==  I  || s[i] ==  O  || s[i] ==  U )         sum[i + 1]--;       else         sum[i + 1] += 2;     }     for (i = 0; i <= n; i++) sum[i] += 2 * n;     for (i = 0; i < M; i++) tree[i] = OO;     update(sum[0], 0);     for (i = 1; i <= n; i++) {       result = ask(sum[i]);       if (i - result > ans) {         ans = i - result;         anum = 0;       }       if (i - result == ans) anum++;       update(sum[i], i);     }     if (ans > 0)       cout << ans <<     << anum <<   n ;     else       cout <<  No solution n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAX_N = 1e5 + 50;   int w[MAX_N];   void solve() {     int n, m;     cin >> n >> m;     long long ret = ((long long)w[n] + (long long)w[m] - 1LL) * 2LL;     cout << ret % MOD <<   n ;   }   void precal() {     w[0] = 0;     w[1] = 1;     w[2] = 2;     for (int i = (3); i < (MAX_N); ++i) {       w[i] = w[i - 1] + w[i - 2];       w[i] %= MOD;     }   }   signed main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     precal();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 2e5;   int p[MAXN + 10], rub[MAXN + 10];   bool mark[MAXN + 10];   bool palin(int x) {     stringstream sst;     sst << x;     string s;     sst >> s;     for (int i = 0; i < s.length(); i++)       if (s[i] != s[s.length() - i - 1]) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     rub[1] = 1;     cerr << palin(121) << endl;     long double a, b;     cin >> a >> b;     for (int i = 2; i <= MAXN; i++) {       if (palin(i)) {         rub[i] = rub[i - 1] + 1;       } else         rub[i] = rub[i - 1];       if (!mark[i]) {         p[i] = p[i - 1] + 1;         for (int j = i + i; j <= MAXN; j += i) mark[j] = true;       } else         p[i] = p[i - 1];     }     long double x = a / b;     int Max = 0;     for (int i = 1; i <= MAXN; i++)       if ((long double)p[i] / (long double)rub[i] <= x) Max = i;     cout << Max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SZ = 200005;   vector<int> graph[SZ];   int par[SZ];   int dst[SZ];   int tot;   void dfs(int x, int crt) {     par[x] = crt;     tot++;     for (int nxt : graph[x]) {       if (par[nxt]) continue;       dfs(nxt, crt);     }   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         graph[i].clear();         par[i] = 0;         dst[i] = 0;       }       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         graph[i].push_back(x);       }       int pp = 0;       for (int i = 1; i <= n; i++) {         if (par[i]) continue;         tot = 0;         dfs(i, ++pp);         dst[pp] = tot;       }       for (int i = 1; i <= n; i++) cout << dst[par[i]] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const int maxn = 1e6 + 100;   const double EPS = 1e-12;   struct point {     double x, y;   };   string a[11] = { zero ,  one ,    two ,    three ,  four ,  five ,                    six ,   seven ,  eight ,  nine ,   ten };   string b[11] = {  ,      ,     twen ,   thir ,  for ,                    fif ,  six ,  seven ,  eigh ,  nine };   string c[11] = {  ,      ,      ,       thir ,  four ,                    fif ,  six ,  seven ,  eigh ,  nine };   int n;   int main() {     cin >> n;     if (n <= 10) {       cout << a[n] << endl;       return 0;     }     if (n < 20) {       if (n == 11)         cout <<  eleven  << endl;       else if (n == 12)         cout <<  twelve  << endl;       else         cout << c[n % 10] <<  teen  << endl;       return 0;     }     if (n % 10 == 0) {       cout << b[n / 10] <<  ty  << endl;       return 0;     }     cout << b[n / 10] <<  ty-  << a[n % 10] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t read() {     bool b = 0;     int64_t n = 0;     char c = getchar();     for (; !(( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) b = (c ==  - );     for (; (( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) n = 10 * n + (c -  0 );     if (b) n = -n;     return n;   }   const int64_t N = 1e5 + 10;   int64_t _log[2 * N], ss[2 * N][20], bl[N][20];   vector<int64_t> adj[N];   int64_t h[N], first[N];   vector<int64_t> et;   int64_t V[N];   int64_t n, q;   int64_t tin[N], tout[N], t = -1;   int64_t stlen, sth;   int64_t lp[N];   int64_t st[2 * N];   void calc(int64_t i, int64_t k) {     st[i] = st[i << 1] + st[i << 1 | 1] + lp[i] * k;   }   void app(int64_t i, int64_t vv, int64_t k) {     st[i] += vv * k;     if (i < stlen) lp[i] += vv;   }   void build(int64_t l, int64_t r) {     int64_t k = 2;     for (l += stlen, r += stlen - 1; l > 1; k <<= 1) {       l >>= 1, r >>= 1;       for (int64_t i = r; i >= l; --i) calc(i, k);     }   }   void push(int64_t l, int64_t r) {     int64_t s = sth, k = 1 << (sth - 1);     for (l += stlen, r += stlen - 1; s > 0; --s, k >>= 1)       for (int64_t i = l >> s; i <= r >> s; ++i)         if (lp[i] != 0) {           app(i << 1, lp[i], k);           app(i << 1 | 1, lp[i], k);           lp[i] = 0;         }   }   void add(int64_t l, int64_t r, int64_t vv) {     push(l, l + 1), push(r - 1, r);     int64_t l0 = l, r0 = r, k = 1;     for (l += stlen, r += stlen; l < r; l >>= 1, r >>= 1, k <<= 1) {       if (l & 1) app(l++, vv, k);       if (r & 1) app(--r, vv, k);     }     build(l0, l0 + 1), build(r0 - 1, r0);   }   int64_t query(int64_t l, int64_t r) {     int64_t l0 = l, r0 = r;     push(l, l + 1), push(r - 1, r);     int64_t res = 0;     for (l += stlen, r += stlen; l < r; l >>= 1, r >>= 1) {       if (l & 1) res += st[l++];       if (r & 1) res += st[--r];     }     l = l0, r = r0;     return res;   }   void _clog() {     for (int64_t i = 2; i < 2 * N; ++i) _log[i] = _log[i >> 1] + 1;   }   void clca() {     int64_t n = et.size();     for (int64_t i = 0; (i) < (n); ++(i)) ss[i][0] = et[i];     for (int64_t k = 1; (1 << k) <= n; ++k)       for (int64_t i = 0; i + (1 << k) <= n; ++i) {         int64_t j = i + (1 << (k - 1));         if (h[ss[i][k - 1]] < h[ss[j][k - 1]])           ss[i][k] = ss[i][k - 1];         else           ss[i][k] = ss[j][k - 1];       }   }   int64_t lca(int64_t l, int64_t r) {     l = first[l], r = first[r];     if (r < l) swap(l, r);     int64_t k = _log[r - l + 1];     int64_t a = ss[l][k], b = ss[r - (1 << k) + 1][k];     if (h[a] < h[b])       return a;     else       return b;   }   void pdfs(int64_t v, int64_t p) {     first[v] = int64_t((et).size());     tin[v] = ++t;     et.push_back(v);     bl[v][0] = p;     for (int64_t i = 0; (i) < (19); ++(i)) bl[v][i + 1] = bl[bl[v][i]][i];     for (int64_t c : adj[v]) {       if (c == p) continue;       h[c] = h[v] + 1;       pdfs(c, v);       et.push_back(v);     }     tout[v] = t;   }   int64_t rlca(int64_t root, int64_t l, int64_t r) {     return lca(l, root) ^ lca(r, root) ^ lca(l, r);   }   int64_t up(int64_t v, int64_t first) {     for (int64_t i = 19; first && i >= 0; --i)       if ((1 << i) <= first) v = bl[v][i], first -= (1 << i);     return v;   }   int64_t qsub(int64_t v) { return query(tin[v], tout[v] + 1); }   void msub(int64_t v, int64_t vv) { add(tin[v], tout[v] + 1, vv); }   int main() {     ;     n = read(), q = read(), stlen = n;     sth = 8 * 4 - __builtin_clz(stlen);     ;     for (int64_t i = 0; (i) < (n); ++(i)) V[i] = read();     int64_t a, b;     for (int64_t i = 0; (i) < (n - 1); ++(i)) {       a = read() - 1, b = read() - 1;       adj[a].push_back(b);       adj[b].push_back(a);     }     _log[1] = 0;     _clog();     pdfs(0, 0);     clca();     ;     for (int64_t i = 0; (i) < (n); ++(i))       ;     ;     ;     ;     for (int64_t i = 0; (i) < (n); ++(i))       ;     ;     ;     for (int64_t i = 0; (i) < (n); ++(i)) st[stlen + tin[i]] = V[i];     build(0, n);     int64_t op, root = 0;     while (q--) {       op = read();       if (op == 1) {         root = read() - 1;       } else if (op == 2) {         int64_t v = rlca(root, read() - 1, read() - 1);         int64_t vv = read();         if (root == v) {           msub(0, vv);         } else if (lca(v, root) == v) {           ;           msub(0, vv), msub(up(root, h[root] - h[v] - 1), -vv);         } else {           msub(v, vv);         }       } else {         int64_t v = read() - 1;         ;         assert(op == 3);         if (root == v) {           printf( %lld n , qsub(0));         } else if (lca(v, root) == v) {           ;           ;           printf( %lld n , qsub(0) - qsub(up(root, h[root] - h[v] - 1)));         } else {           printf( %lld n , qsub(v));         }       };       for (int64_t i = 0; (i) < (n); ++(i))         ;       ;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char board[n][n];     bool even = true;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> board[i][j];     for (int i = 0; i < n; i++) {       int c = 0;       for (int j = 0; j < n; j++) {         if (i - 1 >= 0 and board[i - 1][j] ==  o ) c++;         if (i + 1 < n and board[i + 1][j] ==  o ) c++;         if (j - 1 >= 0 and board[i][j - 1] ==  o ) c++;         if (j + 1 < n and board[i][j + 1] ==  o ) c++;         if (c % 2 == 1) even = false;       }     }     if (even)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MAX = 1e7 + 7;   const long long int MOD = 1000000007;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   int main() {     fast();     long long int TEST_CASES = 1;     while (TEST_CASES--) {       int n;       cin >> n;       vector<pair<string, int>> v(n);       map<string, long long int> mp, now;       for (long long int(i) = 0; (i) < n; (i)++) {         cin >> v[i].first >> v[i].second;         mp[v[i].first] += v[i].second;       }       string mxs;       long long int mx = INT_MIN;       for (auto i : mp) {         if (mx < i.second) {           mx = i.second;           mxs = i.first;         }       }       string str;       for (int i = 0; i < n; i++) {         now[v[i].first] += v[i].second;         if (mp[v[i].first] == mx && now[v[i].first] >= mx) {           str = v[i].first;           break;         }       }       cout << str <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     int freq;     char l;   } db;   int comp(const void *a, const void *b) {     db *x = (db *)a;     db *y = (db *)b;     return x->freq - y->freq;   }   int main() {     db aa[30];     db e;     string str;     int let[30], sz, i, cnt, k, d, j;     while (cin >> str) {       cin >> d;       memset(let, 0, sizeof(let));       sz = str.length();       for (i = 0; i < sz; i++) {         let[str[i] -  a ]++;       }       cnt = 0;       k = 0;       for (i = 0; i < 26; i++) {         if (let[i]) {           cnt++;           aa[k].l = i +  a ;           aa[k].freq = let[i];           k++;         }       }       qsort(aa, k, sizeof(db), comp);       sz = str.size();       for (i = 0; i < k; i++) {         if (d == 0) break;         for (j = 0; j < str.size() && d > 0; j++) {           if (str[j] == aa[i].l) {             str.erase(j, 1);             j--;             let[aa[i].l -  a ]--;             d--;           }         }       }       cnt = 0;       for (i = 0; i < 26; i++) {         if (let[i]) cnt++;       }       cout << cnt << endl;       cout << str << endl;     }     return 0;   }


#include <bits/stdc++.h>   char c[10005];   int main() {     int i, j, k, n, m;     int x0 = 0, x = 0, y0 = 0, y = 0;     scanf( %d%s , &n, c + 1);     for (i = 1; i <= n; i++) {       if (!x0 && c[i] ==  R ) x0 = i;       if (c[i] ==  R ) x = i;       if (!y0 && c[i] ==  L ) y0 = i;       if (c[i] ==  L ) y = i;     }     if (!x0)       printf( %d %d n , y, y0 - 1);     else if (!y0)       printf( %d %d n , x0, x + 1);     else       printf( %d %d n , x0, x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int blk_size;   struct node {     int l, r, id;     long long int ans = 0;   };   bool compare(node a, node b) {     if (a.l / blk_size != b.l / blk_size)       return (a.l) / blk_size < (b.l) / blk_size;     return a.r < b.r;   }   bool compare2(node a, node b) { return a.id < b.id; }   long long int freq[3000001];   int main() {     ios_base::sync_with_stdio(false);     ;     int n, m, k;     cin >> n >> m >> k;     std::vector<int> a(n), pxor(n + 1);     for (int i = 0; i < n; i++) cin >> a[i];     pxor[0] = 0;     for (int i = 1; i <= n; i++) pxor[i] = pxor[i - 1] ^ a[i - 1];     blk_size = sqrt(n + 1);     std::vector<node> q(m);     for (int i = 0; i < m; i++) {       cin >> q[i].l >> q[i].r;       q[i].id = i;     }     sort(q.begin(), q.end(), compare);     int start = 0, end = 0;     long long int ans = 0;     freq[0] = 1;     for (int i = 0; i < m; i++) {       int l = q[i].l - 1, r = q[i].r;       while (start > l) {         start--;         ans += freq[pxor[start] ^ k];         freq[pxor[start]]++;       }       while (start < l) {         freq[pxor[start]]--;         ans -= freq[pxor[start] ^ k];         start++;       }       while (end > r) {         freq[pxor[end]]--;         ans -= freq[pxor[end] ^ k];         end--;       }       while (end < r) {         end++;         ans += freq[pxor[end] ^ k];         freq[pxor[end]]++;       }       q[i].ans = ans;     }     sort(q.begin(), q.end(), compare2);     for (int i = 0; i < m; i++) printf( %lld n , q[i].ans);     return 0;   }


#include <bits/stdc++.h>   const long long MOD = 1000000007;   int N, K;   long long a[5002], FUL[5001];   long long inv[5001];   long long O;   long long POWER(long long a, long long b) {     long long r = 1;     for (; b; b >>= 1) {       if (b & 1) r = r * a % MOD;       a = a * a % MOD;     }     return r;   }   int main() {     scanf( %d%d , &N, &K);     if (N == 1) {       printf( %lld n , K % MOD);       return 0;     }     FUL[0] = 1;     for (int i = 1; i <= N; i++) {       scanf( %lld , a + i);       FUL[i] = 0;       for (int j = i; j; j--) FUL[j] = (FUL[j] * a[i] - FUL[j - 1] + MOD) % MOD;       FUL[0] = FUL[0] * a[i] % MOD;     }     inv[1] = 1;     for (int i = 2; i <= N; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;     for (int i = 1; i <= N; i++) {       static long long pol[5000];       pol[N - 1] = (MOD - FUL[N]) % MOD;       for (int j = N - 2; ~j; j--)         pol[j] = (pol[j + 1] * a[i] - FUL[j + 1] + MOD) % MOD;       long long TPW = 1;       for (int a = 0; a < N && a < K; a++) {         TPW = TPW * inv[N] % MOD * (K - a) % MOD;         O = (O + pol[a] % MOD * inv[a + 1] % MOD * TPW) % MOD;       }     }     printf( %lld n , O);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ld = long double;   template <class T>   inline T gcd(T a, T b) {     return !a ? b : gcd(b % a, a);   }   template <class T>   inline T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   mt19937 rnd(time(0));   const int INF = 1e9;   const long long LLINF = 1e15;   void solve() {     int n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     int ans = 0;     vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] = max(0, max(dp[i - 1][j], dp[i][j - 1]) - 1);         if (a[i - 1] == b[j - 1]) {           dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);         }         ans = max(ans, dp[i][j]);       }     }     cout << ans <<   n ;     return;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t = 1;     while (t-- > 0) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void solve() {     long long int l, r;     cin >> l >> r;     long long int mposs = (r - 1) >> 1;     if (r - mposs >= l)       cout << mposs <<   n ;     else       cout << r % l <<   n ;   }   signed main() {     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ans, sum, pro;   string s, str;   long long int solve(int st, int end, string z) {     long long int sum2 = 0, pro2 = 1;     for (int i = st; i <= end; i++) {       if (z[i] ==  + ) {         sum2 += pro2;         pro2 = 1;       } else if (i % 2 == 0)         pro2 *= s[i] -  0 ;     }     return sum2 + pro2;   }   int main() {     cin >> s;     str =  1* ;     str += s;     str +=  *1 ;     s = str;     for (int i = 1; i < s.size(); i += 2) {       if (s[i] ==  + ) continue;       for (int j = i + 2; j < s.size(); j += 2) {         if (s[j] ==  * ) {           sum = 0, pro = 1;           for (int k = 0; k < s.size(); k++) {             if (k == i)               pro *= solve(i + 1, j - 1, s);             else if (k >= i && k <= j)               continue;             else if (s[k] ==  + ) {               sum += pro;               pro = 1;             } else if (k % 2 == 0)               pro *= s[k] -  0 ;           }           sum += pro;           ans = max(ans, sum);         }       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool bad[105];   string A[105];   bool check(string a, string b) {     if ((int)a.size() != (int)b.size()) return false;     for (int i = 0; i < (int)a.size(); i++)       if (tolower(a[i]) != tolower(b[i])) return false;     return true;   }   int main() {     int n, i, j, k;     char c, c2;     string s;     cin >> n;     for (i = 0; i < n; i++) cin >> A[i];     cin >> s >> c;     for (i = 0; i < n; i++) {       for (j = 0; j < (int)s.size(); j++)         if (check(s.substr(j, (int)A[i].size()), A[i]))           for (k = j; k < j + (int)A[i].size(); k++) bad[k] = true;     }     for (i = 0; i < (int)s.size(); i++)       if (bad[i]) {         if (isupper(s[i]))           c2 = toupper(c);         else           c2 = tolower(c);         if (s[i] == c2) {           if (isupper(s[i])) {             for (c2 =  A ; c2 <=  Z ; c2++)               if (c2 != s[i]) {                 s[i] = c2;                 break;               }           } else {             for (c2 =  a ; c2 <=  z ; c2++)               if (c2 != s[i]) {                 s[i] = c2;                 break;               }           }         } else           s[i] = c2;       }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using std ::vector;   template <typename T>   T max(T x, T y) {     return (x > y) ? x : y;   }   template <typename T>   T min(T x, T y) {     return (x < y) ? x : y;   }   template <typename T>   bool chkmax(T &x, T y) {     return (x >= y) ? 0 : (x = y, 1);   }   template <typename T>   bool chkmin(T &x, T y) {     return (x <= y) ? 0 : (x = y, 1);   }   template <typename T>   T read(T &in) {     in = 0;     char ch;     T f = 1;     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) in = in * 10 + ch -  0 , ch = getchar();     return in *= f;   }   static const int max1 = 100000 + 11;   static const int BIT = 16;   bool vis[max1];   vector<int> fac[max1];   struct Node {     Node *ch[2];     int v;     Node() { ch[0] = ch[1] = NULL, v = 100001; }   };   struct Trie {     Node *root;     Trie() { root = new Node; }     void Insert(int x) {       Node *o = root;       chkmin(o->v, x);       for (int i = (BIT), ir = (0); i >= (ir); --i) {         int c = x >> i & 1;         if (!o->ch[c]) o->ch[c] = new Node;         o = o->ch[c];         chkmin(o->v, x);       }     }   } T[max1];   void Init(int n = 100000) {     for (int i = 1; i <= n; ++i)       for (int j = i; j <= n; j += i) fac[j].push_back(i);   }   void Modify(int x) {     if (vis[x]) return;     vis[x] = 1;     for (vector<int>::iterator i = fac[x].begin(); i != fac[x].end(); ++i)       T[*i].Insert(x);   }   int Query(int x, int k, int s) {     if (x % k) return -1;     s -= x;     int c = 0;     Node *o = T[k].root;     if (o->v > s) return -1;     for (int i = (BIT), ir = (0); i >= (ir); --i) {       int w = x >> i & 1;       if (s < (1 << i) || o->ch[1] && o->ch[1]->v > s)         o = o->ch[0];       else if (!o->ch[0])         o = o->ch[1], c += 1 << i;       else if (!o->ch[1])         o = o->ch[0];       else if (w)         o = o->ch[0];       else         o = o->ch[1], c += 1 << i;     }     return c;   }   int main() {     int q;     read(q);     Init();     while (q--) {       int o, x, k, s;       read(o), read(x);       if (o == 1) {         Modify(x);       } else {         read(k), read(s);         printf( %d n , Query(x, k, s));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans, n, a[10005], cnt, f, i, j, vis[10005];   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     ans = 0;     f = 0;     cnt = 0;     memset(vis, 0, sizeof vis);     for (i = 0; i < n; i++) {       if (!f) {         for (j = 0; j < n; j++) {           if (cnt >= a[j] && !vis[j]) {             vis[j] = 1;             cnt++;           }         }       } else {         for (j = n - 1; j >= 0; j--) {           if (cnt >= a[j] && !vis[j]) {             vis[j] = 1;             cnt++;           }         }       }       if (cnt == n) {         break;       } else {         ans++;       }       f = 1 - f;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], ans = 0, maxi = 0;     for (int i = 0; i < 7; i++) {       cin >> a[i];       maxi += a[i];     }     int t;     if (maxi >= n)       t = 1;     else if (n % maxi == 0) {       t = n / maxi;     } else {       t = n / maxi + 1;     }     while (t--) {       for (int i = 0; i < 7; i++) {         n -= a[i];         if (n <= 0) {           ans = i + 1;           break;         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   int b[500][100005], c[500];   int main() {     srand(time(0));     int n, m, i, j, k;     scanf( %d %d , &n, &m);     map<int, vector<int> > a;     for (i = 0; i < n; i++) {       scanf( %d , &k);       if (k <= n) a[k].push_back(i + 1);     }     vector<int> v;     map<int, vector<int> >::iterator it;     for (it = a.begin(); it != a.end(); it++)       if (it->first > it->second.size()) v.push_back(it->first);     for (i = 0; i < v.size(); i++) a.erase(v[i]);     k = 0;     for (it = a.begin(); it != a.end(); it++) {       c[k] = it->first;       for (i = 0; i < it->second.size(); i++) b[k][it->second[i]] = 1;       for (i = 1; i <= n; i++) b[k][i] += b[k][i - 1];       k++;     }     while (m--) {       scanf( %d %d , &i, &j);       int cnt = 0;       for (n = 0; n < k; n++)         if (c[n] == b[n][j] - b[n][i - 1]) cnt++;       printf( %d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int num[26];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       string s, t;       cin >> n >> s >> t;       int rev = 0, flg = 0;       memset(num, 0, sizeof(num));       for (int i = 0; i < n; i++) {         for (int j = s[i] -  a  + 1; j < 26; j++) {           rev += num[j];         }         num[s[i] -  a ]++;       }       for (int i = 0; i < 26; i++) {         if (num[i] >= 2) flg = 1;       }       memset(num, 0, sizeof(num));       for (int i = 0; i < n; i++) {         for (int j = t[i] -  a  + 1; j < 26; j++) {           rev += num[j];         }         num[t[i] -  a ]++;       }       for (int i = 0; i < 26; i++) {         if (num[i] >= 2) flg = 1;       }       sort(s.begin(), s.end());       sort(t.begin(), t.end());       if (s != t || (rev % 2 != 0 && !flg))         puts( NO );       else         puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dr[] = {-1, 1, 0, 0, -1, 1, -1, 1};   long long dc[] = {0, 0, -1, 1, -1, -1, 1, 1};   int main() {     long long T;     cin >> T;     while (T--) {       string a, b;       cin >> a >> b;       if (a < b) {         cout << a <<   n ;         continue;       }       bool f = 0;       long long sz = min(a.size(), b.size());       long long loop = 0;       for (long long i = 0; i < sz; i++) {         if (a[i] < b[i]) {           f = 1;           break;         } else {           long long indx = -1;           char mn = b[i];           for (long long j = i + 1; j < a.size(); j++) {             if (a[j] <= mn) {               mn = a[j];               indx = j;             }           }           if (indx == -1 and a[i] > b[i]) {             break;           } else if (indx == -1 and a[i] == b[i]) {             continue;           }           if (a[i] == a[indx]) continue;           swap(a[i], a[indx]);           loop++;           if (a < b) {             f = 1;           }           break;         }       }       if (f == 1) {         cout << a <<   n ;       } else {         cout <<  ---               <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long LAKLSNCJKQ() {     char c = getchar();     if (32281 > 23346) {       long long SJQTNVYTHY;       SJQTNVYTHY = 890;       long long VLABDWDNOG;       double QHJMZGOBOX;       bool SJAZLHXFNS;     }     long long x = 0;     double IBTBRLYCXT;     IBTBRLYCXT = 22204;     if (IBTBRLYCXT) {       if (28191 > 11727) {         if (31516 > 10166) {           short OIYWZWGUMU;           OIYWZWGUMU = 32597;           bool KBORLDDWJN;           KBORLDDWJN = 28507;           if (15624 > 14783) {             double XPAYQSVEQU;             bool KTQMTWTZFW;           }           bool ATVFEDBUXZ;           ATVFEDBUXZ = 5419;           if (ATVFEDBUXZ) {             short YGYZAWOKXY;           }         }         double BQWXBOXCPY;         BQWXBOXCPY = 6361;       }       long long VAOVGFEAUK;       long long FEIASNIVBT;       FEIASNIVBT = 18457;     }     bool f = 0;     if (22244 > 7895) {       short MVPVMWUJOD;       MVPVMWUJOD = 28548;       if (MVPVMWUJOD) {         if (13366 > 13803) {           bool XDCCNBURPK;           XDCCNBURPK = 13989;           long long UPCCKTPSFJ;           UPCCKTPSFJ = 5412;         }       }     }     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     if (331 > 31276) {       double XUKCKKWRRB;       XUKCKKWRRB = 2944;       if (XUKCKKWRRB) {         short KHPLISVQGN;         KHPLISVQGN = 21673;         if (10023 > 7274) {           if (3328 > 5414) {             bool JYTIEGOKKQ;           }           bool XBXALUHDZX;           XBXALUHDZX = 9228;           if (XBXALUHDZX) {             long long HEXFFVFFRE;           }           short FLWZRFLJBM;           FLWZRFLJBM = 6345;           if (FLWZRFLJBM) {             double YOOXQTHBXQ;             long long SWBPNZOBPM;             short MIMUYITJME;             long long LVFSTHJESV;           }         }       }       if (7446 > 10128) {         double MQGRWENFXI;         MQGRWENFXI = 16177;         if (31692 > 5532) {           bool VEXACEEMMA;           VEXACEEMMA = 5606;           if (11065 > 16359) {             double EOSLBZHSUN;           }           if (9892 > 13627) {             short GMZDPSFDZG;             long long JFHPKLADKT;             bool FYESZAROVH;           }         }         long long LXVYMIPDCK;       }       short XYCYVTPGLD;       XYCYVTPGLD = 25583;     }     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (23117 > 2644) {       double LTCKFKKIVJ;       if (17820 > 22924) {         double VKBSTTDPFF;         VKBSTTDPFF = 26648;         if (VKBSTTDPFF) {           if (16774 > 5619) {             long long AZVUQUXROT;             double GISFTHWSVA;             long long YWTCSRLTNK;             short EYBHYCANBM;           }           bool MSQJZZIUHR;           MSQJZZIUHR = 14372;           double BTTXSQBCBR;           BTTXSQBCBR = 28650;         }         if (17173 > 31740) {           if (10763 > 16891) {             short RDTWNHMTID;           }           double OUHOEPPBMO;           bool KXNZUQYVPS;         }         if (17326 > 28582) {           bool WWXKPIIHCE;           WWXKPIIHCE = 30063;         }       }     }     if (f) x = -x;     return x;     if (17432 > 28544) {       if (828 > 28220) {         long long FNDIWALLAX;         FNDIWALLAX = 31062;         if (FNDIWALLAX) {           long long TYAMBDKTLO;           TYAMBDKTLO = 22072;           if (23808 > 27160) {             long long DTDGOVKVWS;             double NZZOJGQYGA;             long long UMAYDUQNKS;           }         }         long long EKBLPPACGT;         EKBLPPACGT = 26135;         if (EKBLPPACGT) {           long long OWRLBFHLLO;           OWRLBFHLLO = 9211;           if (OWRLBFHLLO) {             double SXDKTWOMBI;           }           bool GKCDYTVHSG;           if (5365 > 24741) {             double IIIWGIIJSZ;             long long FDJQMWIQZF;           }         }         bool UKNSMRJBST;         UKNSMRJBST = 11817;         if (UKNSMRJBST) {           double KSQRSYJYHA;           if (10789 > 3838) {             double QUJBIILQGR;             double RJBINMMZGZ;             long long IJFIBQPBAT;           }           short XVZPFSLVNQ;         }       }       if (27853 > 9859) {         if (7496 > 18297) {           if (9508 > 1820) {             long long BRRIBTPAGH;             double IZYQBJHUQZ;           }         }       }       if (13069 > 13617) {         if (28990 > 9166) {           bool IPTBNMVVTS;           IPTBNMVVTS = 20463;         }         short BRZLWCLFWL;         BRZLWCLFWL = 29016;       }     }   }   using namespace std;   const long long Mask = (1ll << 30) - 1, inf = 1e18;   long long n;   char s[600005];   long long PKCNKSQOWC[600005][20], NOQEFVKSSX[600005];   long long PASLQWKEND1, PASLQWKEND2, a26, a30, PASLQWKEND;   map<long long, long long> ZLMQOGHJFF;   long long OZXICPQWDF[600005], ODIUVNKJQW[600005];   inline long long ask(long long l, long long r) {     if (l > r) swap(l, r);     long long k = NOQEFVKSSX[r - l + 1];     long long RJYRZIFLXF;     RJYRZIFLXF = 4416;     return min(PKCNKSQOWC[r][k], PKCNKSQOWC[l + (1 << k) - 1][k]);     if (11184 > 12519) {       short BJCZAVIHQU;       BJCZAVIHQU = 21585;       double JTPTTPPEIW;       if (7270 > 10837) {         bool YXCIVCJQUR;         YXCIVCJQUR = 18023;         if (YXCIVCJQUR) {           short HMEDVWYZAD;           double BIZBSPXTPI;           BIZBSPXTPI = 19761;         }         bool EPFHBLNBQV;         EPFHBLNBQV = 16855;         if (EPFHBLNBQV) {           if (8920 > 87) {             long long GUTVDVDAUP;             long long TQQSGXKQKB;             long long CWYOQFLQWS;           }         }       }       bool MFGSZBWZXL;     }   }   void print(long long x, long long y) {     if (!y) {       printf( %lld n , x);       return;       short PQCMYOUFVD;       PQCMYOUFVD = 21379;       if (PQCMYOUFVD) {         short KYVFDSGZVL;         KYVFDSGZVL = 28299;         if (KYVFDSGZVL) {           if (14693 > 25213) {             short FEZICBMRZI;             long long VDNSTGUSLU;             long long IHWUUSLHLQ;           }           short VRRFLEUIWY;           VRRFLEUIWY = 16770;           if (VRRFLEUIWY) {             bool HKMSYIJLMH;             short FTMBCPPWWL;             long long HBVFUJHJXC;           }           long long AWEWSLADGZ;           AWEWSLADGZ = 32404;           if (AWEWSLADGZ) {             long long TUOIXVWQLK;             bool VNAAHTOMCM;             double RYYBVYDOFI;           }         }         double PUKHNXGHLR;         PUKHNXGHLR = 11134;       }     }     printf( %lld , y);     bool BFZFAJAHJP;     BFZFAJAHJP = 27702;     if (BFZFAJAHJP) {       long long GRJKVDSUPK;       GRJKVDSUPK = 31083;       if (GRJKVDSUPK) {         if (7344 > 21031) {           if (13430 > 6930) {             long long YZTEKYCEXH;             double RMGXTHTCXE;             short WOFOSURDYX;           }           double KYVQLKWMKV;         }         long long CJSSCLMZUU;         CJSSCLMZUU = 24416;         if (1470 > 27735) {           long long MMUICAJFAP;           if (5792 > 14230) {             double DPSXHZDHOT;             long long NPKNGIBVQT;             double UVEGIPSWFF;             short SRFYCDCVFU;             short CJRMQOIKBI;           }         }       }       if (11216 > 22837) {         long long MNKZBFRGFJ;         short ICSTNOPDLO;         ICSTNOPDLO = 6349;         if (ICSTNOPDLO) {           if (27645 > 14013) {             long long FOLNJLTMDX;             long long RQGHCPFZMY;             long long CBANSDKKKB;             long long RDOHCWWIPX;           }           if (10160 > 24441) {             double VSVQHUFVMW;           }         }         long long XPTKNPPOHX;         XPTKNPPOHX = 18014;         if (3933 > 31689) {           long long FNXJPICBKA;         }       }       double BAGZRPCXQH;       BAGZRPCXQH = 11896;     }     long long now = inf / 10;     long long QLXZPYBXTJ;     QLXZPYBXTJ = 17162;     while (now > x && now >= 10) putchar( 0 ), now /= 10;     if (2226 > 31142) {       long long EDWJMGBWHJ;       EDWJMGBWHJ = 32093;       if (EDWJMGBWHJ) {         if (7027 > 23752) {           if (15643 > 24958) {             bool UNBRLRBRKZ;             short CYZELXDDHX;             bool MIKZQCQKLS;             bool CVPGIILVHA;           }         }         long long QYISVVTYAS;         QYISVVTYAS = 30577;       }       long long XAHLGLMGRD;       XAHLGLMGRD = 11996;       if (XAHLGLMGRD) {         long long ETKECDJAMX;         ETKECDJAMX = 6319;         if (28138 > 7202) {           if (24397 > 24360) {             bool VNTZVBCFYC;           }           double FNIAMKXDKC;           FNIAMKXDKC = 2707;           if (FNIAMKXDKC) {             long long BTPDBRLEIW;             short NCOLRHIITE;             double HQFYCCBACD;             bool GMZIUJWMFA;             long long EDXJKJUBFW;           }         }         if (8285 > 10375) {           long long OCOYCBMFLM;           OCOYCBMFLM = 21978;           if (27175 > 15533) {             short UZEPJAZTDP;             double GNJDGVOAMW;             double FCHIHZFDER;             short OGUZXULEOL;           }           if (14265 > 20236) {             long long KABFUJALMS;             short ZGBWNAUAER;           }         }       }     }     printf( %lld n , x);     if (6512 > 31058) {       if (20281 > 1432) {         if (13622 > 17665) {           if (29270 > 7054) {             long long FFGDTLRVDD;             long long FVQIHPGNGA;             short GPQZERIEVA;           }           short BJGSVDUUAU;           bool KVAOEUMIRF;         }         bool DHTVYEZTDC;         if (8247 > 8501) {           if (24741 > 12098) {             bool IYROVUUNZX;             long long WQROVRNZFF;             bool JCDKQKUXWP;             long long XBGJSYBGKU;           }           long long ZTZOASWUJT;           ZTZOASWUJT = 7936;           if (ZTZOASWUJT) {             short BGLTBDDZXJ;           }           if (27819 > 5085) {             long long NYCVYZFPER;             long long FAGJEBIZYM;           }         }       }       long long CWQAYAGVVA;       if (7808 > 24851) {         long long LVDDJUADIK;         LVDDJUADIK = 27710;       }     }   }   signed main() {     n = LAKLSNCJKQ(), NOQEFVKSSX[0] = -1;     bool OJBUOKHNZP;     OJBUOKHNZP = 9527;     if (OJBUOKHNZP) {       long long THDITISJUK;       THDITISJUK = 32453;       if (THDITISJUK) {         bool AEKBKKXSQJ;         AEKBKKXSQJ = 4561;         if (AEKBKKXSQJ) {           double OTNTQJYURH;           OTNTQJYURH = 8786;         }         if (32521 > 3021) {           bool LIPPFKNCSW;           if (4668 > 21251) {             bool GEEJRXLMRQ;             long long EQOMAXBWSR;             long long YFWKKNUBNX;           }         }         long long OCTWNVRHIS;       }       double IDABZUKKIV;     }     for (long long i = (1); i <= (n); ++i) NOQEFVKSSX[i] = NOQEFVKSSX[i >> 1] + 1;     if (7728 > 10480) {       long long TJWNMUJCBD;       TJWNMUJCBD = 899;       if (TJWNMUJCBD) {         double OCLIDBOVHI;         short FEHVYHHCKQ;         FEHVYHHCKQ = 21844;         double TIKOQFHVPD;         TIKOQFHVPD = 27273;         long long WIHBCOGVWF;       }       bool SLJQQOMDJC;       SLJQQOMDJC = 27775;       short ZJSCRHEQMD;     }     OZXICPQWDF[0] = -1;     double CHVRMSFDIT;     CHVRMSFDIT = 28336;     for (long long i = (1); i <= (n); ++i) {       scanf( %s , s + i);       if (5013 > 30592) {         double YYLFBDEYIA;         YYLFBDEYIA = 17517;         bool TNAWJTYVJW;         TNAWJTYVJW = 32675;         long long KZZTAJUUMW;       }       s[i] = ((s[i] -  a  + a26) % 26) +  a ;       bool AVCQWAUQGM;       AVCQWAUQGM = 17877;       if (AVCQWAUQGM) {         short KNDWIIAUDN;         KNDWIIAUDN = 11578;         if (KNDWIIAUDN) {           bool XZGWKECTXO;           long long ROMCPCZVRW;         }         if (3031 > 28497) {           if (5615 > 28550) {             long long KMYCQLCMRK;             long long NUJUQEZAGM;             bool AQHLXZSMJF;             long long GPHHMIDCDN;             short MGXFDNMKLV;           }           double QWLZXBLCUV;           QWLZXBLCUV = 11743;           if (QWLZXBLCUV) {             double CEMFHTAJKE;           }           long long MLDXLMCEZM;         }         bool LREWUAAYZU;         short OVACEMKBUI;       }       long long w = LAKLSNCJKQ();       short RZYSLIYYLY;       RZYSLIYYLY = 9499;       w ^= (a30 & Mask);       short HBIHGJNXAH;       PKCNKSQOWC[i][0] = w;       short TWUENILLHZ;       for (long long j = (1); j <= (19); ++j)         if (i >= (1 << j))           PKCNKSQOWC[i][j] =               min(PKCNKSQOWC[i - (1 << (j - 1))][j - 1], PKCNKSQOWC[i][j - 1]);       long long j = OZXICPQWDF[i - 1];       if (6425 > 25228) {         long long OVKNAHKQGH;         OVKNAHKQGH = 4501;         if (OVKNAHKQGH) {           if (31760 > 16539) {             short RLTXWGZHYR;             short GEOBYOKLES;           }           long long XHZSTOCISZ;           XHZSTOCISZ = 22954;           if (29408 > 21905) {             bool JHYTHTGDKJ;           }           short RAXAIPWLJW;           RAXAIPWLJW = 6467;           if (RAXAIPWLJW) {             long long ZGOYUWAYZD;           }         }         long long EIPPCNMEQF;         EIPPCNMEQF = 3644;         short ZYDUAOZJRA;         ZYDUAOZJRA = 632;         if (ZYDUAOZJRA) {           short PZAFKAOQXY;           double SAAAUIOWLM;           SAAAUIOWLM = 22279;           if (SAAAUIOWLM) {             short UFYBMKZBDF;             short JYGBVNQHDC;           }           bool EFYYBKVPFD;           EFYYBKVPFD = 10307;           if (EFYYBKVPFD) {             bool RQCXPYVCCR;             bool CMCMTSPIFA;           }           if (30868 > 25897) {             long long EWIHEWTHXS;             double RDUMYFGMYW;           }         }       }       while (j >= 0 && s[j + 1] != s[i]) j = OZXICPQWDF[j];       bool RTAMEHWMGO;       RTAMEHWMGO = 1477;       OZXICPQWDF[i] = j + 1;       if (19881 > 32092) {         long long RIUVFDXUGO;         if (13388 > 21570) {           if (21487 > 7615) {             short PSWIBTGZKN;           }           short XPOHUCUACK;           XPOHUCUACK = 32156;           if (XPOHUCUACK) {             long long KZDFMDYGLZ;             long long YRIRTLEODA;           }           bool BUKJIWBLIS;           BUKJIWBLIS = 27616;           if (BUKJIWBLIS) {             short UIHOWHWHZP;           }           short ASQZFIRDXA;           ASQZFIRDXA = 3309;         }       }       if (s[i] == s[OZXICPQWDF[i - 1] + 1])         ODIUVNKJQW[i - 1] = ODIUVNKJQW[OZXICPQWDF[i - 1]];       else         ODIUVNKJQW[i - 1] = OZXICPQWDF[i - 1];       if (27391 > 3744) {         long long RSCAKDIEHL;         RSCAKDIEHL = 11196;         if (RSCAKDIEHL) {           if (28157 > 27255) {             double IWGDFKWLXD;             bool VOMUPWPIND;           }           if (4100 > 11906) {             bool QIXZLSKWDV;             bool PLLNOGQRTF;           }           if (32712 > 11866) {             short CZXRVBXXPU;             short LASWUSAAMX;             short JXQLYTDOKM;           }         }         long long JGORDMHITJ;         JGORDMHITJ = 16257;       }       j = i - 1;       long long ZGLUSKXMSY;       ZGLUSKXMSY = 21361;       while (j >= 1) {         if (s[j + 1] == s[i])           j = ODIUVNKJQW[j];         else {           long long t = ask(i - j, i - 1);           long long ZXXEWLUNJN;           PASLQWKEND -= t, ZLMQOGHJFF[t]--, j = OZXICPQWDF[j];           if (26848 > 4959) {             double ZIUPHCQHXF;             long long ENGJOSZHOX;           }         }       }       long long add = (s[i] == s[1]);       double BJDVQKKZOO;       BJDVQKKZOO = 11772;       while (ZLMQOGHJFF.size() && ((--ZLMQOGHJFF.end())->first) > w) {         auto it = --ZLMQOGHJFF.end();         if (20559 > 3094) {           long long VEQQVLIMKJ;           VEQQVLIMKJ = 9639;           if (15413 > 18844) {             short DBCPWNWZKU;             long long CBRMFIYLBH;           }           if (10465 > 8950) {             long long QAVPKTSOLN;             bool PIIKHCBCWK;           }           double NVGIGZTZQY;           NVGIGZTZQY = 28060;           if (NVGIGZTZQY) {             double VGVNCHNPGM;             short YRZQUOSJUM;           }           bool CPHJORRGJS;         }         add += it->second, PASLQWKEND -= it->second * it->first;         if (11171 > 21467) {           long long KRHUPMUQCT;           KRHUPMUQCT = 4789;           if (31245 > 5281) {             long long CADVVAFLGJ;           }         }         ZLMQOGHJFF.erase(it);         long long YGIXFXONAK;         YGIXFXONAK = 8967;       }       PASLQWKEND += add * w, ZLMQOGHJFF[w] += add;       if (30861 > 32345) {         long long MJHZOWCGQF;         bool FJCOTOGVFN;         FJCOTOGVFN = 13155;         if (28712 > 12867) {           if (27262 > 15580) {             long long XRHQKNJWFK;             bool WMWMAFDFVN;             long long TSZBACQOUC;           }           if (8570 > 21638) {             bool XLZICHFHVW;           }           short QGZZGTPGNW;           QGZZGTPGNW = 32135;           if (QGZZGTPGNW) {             long long UJNORZHGWS;             long long YTIXUOYAEX;             bool YCXWDEQSDG;           }           long long MCPDAQXWVP;         }       }       a26 = (a26 + PASLQWKEND) % 26, a30 = (a30 + PASLQWKEND) & Mask;       long long KEDZHCKFIZ;       KEDZHCKFIZ = 2329;       if (KEDZHCKFIZ) {         long long ZYURMHVIGM;       }       PASLQWKEND1 += PASLQWKEND;       if (28120 > 8670) {         bool THTEVDTHEQ;       }       if (PASLQWKEND1 >= inf) PASLQWKEND2++, PASLQWKEND1 -= inf;       print(PASLQWKEND1, PASLQWKEND2);       if (20512 > 5823) {         if (4608 > 16596) {           double YWDFXFBSAN;           YWDFXFBSAN = 8542;           if (YWDFXFBSAN) {             short YKRCRINEMM;             long long GRKAGLHJPR;             long long YBGWHEWZXM;             short SLGRSYCQMB;           }           if (17831 > 8044) {             long long WSSQXKMEWI;           }         }         bool WPHZJRTOXT;         WPHZJRTOXT = 23409;         long long ZVKRUTMJKO;         ZVKRUTMJKO = 1981;       }     }     return 0;     long long ZUSFQYEYXO;     ZUSFQYEYXO = 20994;     if (ZUSFQYEYXO) {       bool RTWAUOYVNL;       long long SVOEZZDQBR;       SVOEZZDQBR = 25293;       double DHZACPREKX;       DHZACPREKX = 25408;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> p1[1005];   pair<long long, long long> p2[1005];   vector<long long> v;   int main() {     long long i, j, n, x, y, a, b;     cin >> n;     for (i = 0; i < n; i++) cin >> p1[i].first >> p1[i].second;     for (i = 0; i < n; i++) cin >> p2[i].first >> p2[i].second;     sort(p1, p1 + n);     sort(p2, p2 + n);     cout << p1[0].first + p2[n - 1].first <<              << p1[0].second + p2[n - 1].second;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 2147483647;   const long long ll = 9223372036854775807, ninf = 1000000000;   const double eps = 1e-6;   const long long nll = 1000000000000000000;   vector<int> node[200005];   vector<int> num;   int deg[200005] = {};   void dfs(int x) {     for (int i = 0; i < node[x].size(); i++) {       dfs(node[x][i]);     }     num.push_back(x);   }   int A[200005] = {};   int main() {     int a;     while (cin >> a) {       int r = 1;       for (int i = 1; i <= a; i++) {         cin >> A[i];         deg[A[i]]++;         if (A[i]) {           deg[i]++;           node[A[i]].push_back(i);         } else {           r = i;         }       }       if (a % 2 == 0) {         cout <<  NO  <<   n ;         continue;       }       dfs(r);       vector<int> ans1, ans2;       cout <<  YES  <<   n ;       for (int i = 0; i < num.size(); i++) {         int now = num[i];         if (deg[now] % 2 == 0) {           ans2.push_back(now);           deg[A[now]]--;         } else {           ans1.push_back(now);         }       }       for (int i = 0; i < ans2.size(); i++) {         cout << ans2[i] <<   n ;       }       reverse(ans1.begin(), ans1.end());       for (int i = 0; i < ans1.size(); i++) {         cout << ans1[i] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int fa[2][maxn << 1];   int cost[2][maxn][maxn];   int dd[2][maxn];   int n;   int sz[2];   int dp[maxn];   void init(int t) {     cin >> sz[t];     for (int i = (2); i <= (sz[t]); ++i) cin >> fa[t][i];     for (int i = (1); i <= (n); ++i) cin >> dd[t][i];   }   void cal(int t) {     for (int l = (1); l <= (n); ++l) {       vector<int> sons(sz[t] + 1, 0);       for (int i = (1); i <= (sz[t]); ++i) sons[fa[t][i]]++;       for (int r = (l); r <= (n); ++r) {         int now = dd[t][r];         int val = 0;         while (now != 1 && sons[now] == 0)           val++, sons[fa[t][now]]--, now = fa[t][now];         cost[t][l][r] = cost[t][l][r - 1] + val;       }     }   }   void solve() {     for (int i = (1); i <= (n); ++i) {       int& ans = dp[i];       for (int j = (0); j < (i); ++j)         ans = max(ans, dp[j] + max(cost[1][j + 1][i], cost[0][j + 1][i]));     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = (0); i < (2); ++i) init(i);     for (int i = (0); i < (2); ++i) cal(i);     solve();     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T SQR(T x) {     return x * x;   }   template <class T>   inline string TOSTR(const T &x) {     stringstream ss;     ss << x;     return ss.str();   }   template <class T>   void UPDATE_MIN(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UPDATE_MAX(T &x, T y) {     if (x < y) {       x = y;     }   }   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   long long powmod(long long a, long long p, long long m) {     long long r = 1;     while (p) {       if (p & 1) r = r * a % m;       p >>= 1;       a = a * a % m;     }     return r;   }   const int MOD = 1000 * 1000 * 1000 + 7;   const double PI = 3.1415926535897932384626433832795l;   long long n, m, k;   long long p10[10000];   long long p9_10[10000];   long long counts_a[100] = {};   long long counts_b[100] = {};   long long *counts, *counts2;   int main() {     cin >> n >> k >> m;     long long a10 = 1, a9_10 = 1;     for (int(i) = 0; (i) < (int)(n); (i)++) {       p10[i] = a10;       p9_10[i] = a9_10;       a10 = (a10 * 10LL) % k;       a9_10 = (a9_10 * ((i == 0) ? 9LL : 10LL)) % m;     }     counts = counts_a;     counts2 = counts_b;     counts[0] = 1;     long long res = 0;     for (int(i) = 0; (i) < (int)(n); (i)++) {       for (int(j) = 0; (j) < (int)(k); (j)++) counts2[j] = 0;       for (int(r) = 0; (r) < (int)(k); (r)++) {         int mind = ((i == n) ? 1 : 0);         for (int(d) = mind; (d) < (int)(10); (d)++) {           long long r2 = (d * p10[i] + r) % k;           counts2[r2] = (counts2[r2] + counts[r]) % m;         }       }       res += (counts2[0] - 1) * p9_10[n - i - 1];       res %= m;       while (res < 0) res += m;       counts2[0] = 1;       {         __typeof(counts) tmp = counts;         counts = counts2;         counts2 = tmp;       };     }     cout << res << endl;     return 0;   }