#include <bits/stdc++.h>   using namespace std;   long long x[200001], y[200001], dp[200001], n;   bool s[200001];   long long find_upper_bound(long long l, long long r, long long value) {     long long mid, index = 1;     while (l <= r) {       mid = l + (r - l) / 2;       if (x[mid] >= value) {         index = mid;         r = mid - 1;       } else         l = mid + 1;     }     return index;   }   int main() {     int t;     t = 1;     while (t--) {       dp[0] = 0;       cin >> n;       for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> s[i];       long long ans = (x[n] + 1) % 998244353, temp;       for (int i = 1; i <= n; i++) {         temp = find_upper_bound(1, i, y[i]);         dp[i] = x[i] - y[i];         if (temp != i)           dp[i] = (dp[i] + (dp[i - 1] - dp[temp - 1] + 998244353) % 998244353) %                   998244353;         if (s[i]) ans = (ans + dp[i]) % 998244353;         dp[i] = (dp[i] + dp[i - 1]) % 998244353;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long xa, xb, ya, yb, xc, yc, t;   long long cp(long long x1, long long x2, long long y1, long long y2) {     return x1 * y2 - x2 * y1;   }   int main() {     cin >> xa >> ya >> xb >> yb >> xc >> yc;     t = cp(xc - xa, xb - xa, yc - ya, yb - ya);     if (t == 0) {       cout <<  TOWARDS  << endl;     }     if (t < 0) {       cout <<  LEFT  << endl;     }     if (t > 0) {       cout <<  RIGHT  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c[2000007];   set<int> s;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < 2000007; i++) {       s.insert(i);     }     set<int>::iterator it;     int maxy = 0;     for (int i = 0; i < n; i++) {       string l;       cin >> l;       int k;       scanf( %d , &k);       while (k--) {         int x;         scanf( %d , &x);         while (1) {           it = s.lower_bound(x);           if (it != s.end() && (*it) <= l.length() + x - 1) {             c[*it] = l[(*it) - x];             maxy = max(maxy, *it);             s.erase(it);           } else             break;         }       }     }     c[maxy + 1] =   0 ;     for (int i = 1; i <= maxy; i++) {       if (s.find(i) != s.end()) c[i] =  a ;     }     printf( %s n , c + 1);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int inf = 0x3f3f3f3f;   inline long long read() {     register long long x = 0, f = 1;     register char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return x * f;   }   void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   const int maxn = 1e4 + 233;   struct node {     int x, y, opt, id;     bool operator<(const node &w) const {       return x < w.x || (x == w.x && y < w.y);     }   } a[maxn * 2], c;   int ans[maxn], n;   node operator-(node a, node b) { return (node){a.x - b.x, a.y - b.y, 0, 0}; }   int cross(node a, node b) { return a.x * b.y - a.y * b.x; }   bool cmp(node a, node b) { return cross(a - c, b - c) > 0; }   void work(int l, int r) {     if (l > r) return;     int p = min_element(a + l, a + r + 1) - a;     swap(a[l], a[p]);     c = a[l];     sort(a + l + 1, a + r + 1, cmp);     int cnt1 = 0, cnt2 = 0, k = r;     while (!(c.opt != a[k].opt && cnt1 == cnt2)) {       if (c.opt == a[k].opt)         cnt1++;       else         cnt2++;       k--;     }     if (c.opt == 1)       ans[a[k].id] = c.id;     else       ans[c.id] = a[k].id;     work(l + 1, k - 1);     work(k + 1, r);   }   int main() {     n = read();     for (register int i = (0); i < int(2 * n); ++i) {       a[i].x = read();       a[i].y = read();       a[i].opt = i < n ? 0 : 1;       a[i].id = i < n ? i + 1 : i - n + 1;     }     work(0, 2 * n - 1);     for (register int i = (1); i <= int(n); ++i) writeln(ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int m = 10000 * 100000 + 7;   int main() {     string s;     cin >> s;     int n = s.length();     long long p = 0, q = 1;     for (int i = n - 1; i > 0; --i) {       if (s[i] ==  1 ) p = (p + q) % m;       q = q * 2 % m;     }     if (s[0] ==  1 ) p = (p + q) % m;     cout << p * q % m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct $ {     $() {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);     }   } $;   const int N = 100002;   int n, m;   vector<int> a[N];   vector<int> pri[N];   vector<int> ans;   vector<tuple<int, int>> where[N];   const int NPR = 20;   int primes[NPR] = {       2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, 23, 25, 27, 29, 31, 32, 36, 37,   };   int mod[NPR], cnt[NPR];   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       int k;       cin >> k;       a[i].resize(k);       for (int j = 0; j < k; ++j) {         cin >> a[i][j];         where[a[i][j]].emplace_back(i, j);       }       for (int j = 0; j < NPR; ++j)         if (k % primes[j] == 0) pri[i].emplace_back(j);     }     ans.resize(m + 1);     for (int i = 0; i < n; ++i) {       const auto &v = a[i];       int ki = int(v.size());       for (int j = 0; j < ki; ++j) {         int x = v[j];         if (ans[x]) continue;         ans[x] = 1;         auto wit = begin(where[x]);         for (int start = -2, stop = -2; wit != end(where[x]); ++wit) {           int row, off;           tie(row, off) = *wit;           if (row != stop) {             start = stop = row;             fill(begin(cnt), end(cnt), 0);           }           for (int prq : pri[stop]) {             if (mod[prq] == off % primes[prq]) {               ++cnt[prq];             } else {               for (; cnt[prq]; ++start) {                 for (int prp : pri[start]) --cnt[prp];               }               cnt[prq] = 1;               mod[prq] = off % primes[prq];             }           }           ++stop;           ans[x] = max(ans[x], stop - start);         }       }     }     for (int i = 1; i <= m; ++i) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   int nrg, nrv;   string s;   bool gg(int pos) {     if (pos < 2) return 0;     return ((s[pos] >=  0  && s[pos] <=  9 ) &&             (s[pos - 1] >=  0  && s[pos - 1] <=  9 ) && (s[pos - 2] ==  . ));   }   deque<int> dg;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     for (int i = 0; i < s.size(); ++i) {       if (s[i] >=  a  && s[i] <=  z ) continue;       int l = i;       while (i < s.size() && !(s[i] >=  a  && s[i] <=  z )) ++i;       --i;       int r = i;       if (gg(r)) {         nrv = nrv + (s[r] -  0 ) + 10 * (s[r - 1] -  0 );         r -= 3;       }       int ex = 1;       while (r >= 0 && !(s[r] >=  a  && s[r] <=  z )) {         if (s[r] !=  . ) nrg = nrg + ex * (s[r] -  0 ), ex = ex * 10;         --r;       }     }     nrg += nrv / 100;     nrv %= 100;     do {       dg.push_front(nrg % 10);       nrg /= 10;     } while (nrg);     for (int i = 0; i < dg.size(); ++i) {       if (i && (dg.size() - i) % 3 == 0) cout <<  . ;       cout << dg[i];     }     if (nrv) {       cout <<  . ;       if (nrv < 10) cout <<  0 ;       cout << nrv;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     char c;     long long num, f = 1;     while (c = (char)getchar(), !isdigit(c))       if (c ==  - ) f = -1;     num = (long long)(c -  0 );     while (c = (char)getchar(), isdigit(c)) num = num * 10 + (long long)(c -  0 );     return num * f;   }   long long n, m;   vector<long long> a;   long long greaterCount(long long m) {     vector<long long> s(2 * n + 1);     long long sum = n, result = 0, add = 0;     s[sum] = 1;     for (long long i = 0; i < n; i++) {       if (a[i] < m)         sum--, add -= s[sum];       else         add += s[sum], sum++;       result += add;       s[sum]++;     }     return result;   }   void work() {     n = read();     m = read();     a = vector<long long>(n);     for (long long i = 0; i < n; i++) a[i] = read();     cout << greaterCount(m) - greaterCount(m + 1) << endl;     return;   }   signed main() {     long long T = 1;     for (long long Case = 1; Case <= T; Case++) {       work();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, x, y, z, m, n, k, l, r, f, mi = 1e9;   int a[200];   bool pr(int n) {     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return true;     return false;   }   int main() {     scanf( %d , &n);     a[1] = a[2] = a[3] = -1;     a[4] = 1;     for (int i = 5; i < 100; i++) {       int t = -1;       if (pr(i)) t = 1;       for (int j = 4; j <= i / 2; j++)         if (pr(j) && pr(i - j)) t = max(t, a[j] + a[i - j]);       a[i] = t;     }     while (n--) {       scanf( %d , &m);       int ans;       if (m < 20)         ans = a[m];       else {         ans = m / 4;         m = m % 4;         if (m == 1) ans--;         if (m == 3) ans--;       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long dx[] = {-2, -1, 1, 2, -2, 1, -1, 2};   const long long dy[] = {-1, -2, 2, 1, 1, -2, 2, -1};   const long long Mod = 1e9 + 7;   const long long N = 5e5;   const long long inf = 1e9 + 1;   const long long N_N = 1e2;   long long n, m, x, y, cnt;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> x >> y;       cnt = max(cnt, y + x);     }     cout << max(cnt, m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[50];   int main() {     int f = 2, ct[110];     ct[0] = 0;     ct[1] = 0;     ct[2] = 1;     for (int i = 3; i <= 101; i++) {       ct[i] = ct[i - 1] + f;       f++;     }     string s;     int n, m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       m = s[0] - 96;       a[m]++;     }     int sum = 0, dis, l;     for (int i = 1; i <= 26; i++) {       if (a[i] != 0) {         dis = a[i] / 2;         l = a[i] - dis;         sum += (ct[l] + ct[dis]);       }     }     cout << sum << endl;     return 0;   }


#include <algorithm>   #include <cmath>   #include <cstring>   #include <iostream>   #include <limits>   #include <queue>   #include <set>   #include <sstream>   #include <stack>   #include <unordered_map>   #include <utility>   #include <vector>      using namespace std;      typedef long long ll;   typedef vector<int> vi;   typedef vector<int>::iterator vit;   typedef vector<vector<int>> vii;      #define REP(i, a, b) for (int i = a; i < b; i++)   #define VECITR(itr, v) for (vit itr = v.begin(); itr != v.end(); itr++)   #define PB push_back   #define MP make_pair   #define F first   #define S second   #define sq(a) ((a) * (a))      int gcd(int a, int b)   {       if (b == 0)           return a;       return gcd(b, a % b);   }      string next_valid_bracket_sequence(const string &x)   {       string s = x;       int n = s.size();       int d = 0;       for (int i = n - 1; i >= 1; i--)       {           if (s[i] ==  ) )               d++;           else           {               d--;               if (d > 0)               {                   s[i] =  ) ;                   s = s.substr(0, i + 1);                   REP(j, 0, (n - i - d) / 2) { s +=  ( ; }                   REP(j, 0, (n - i + d - 2) / 2) { s +=  ) ; }                   if (s.size() < n) return s +  ) ;                   return s;               }           }       }          return   ;   }      ll modulo(ll x, ll m)    {       int r = x % m;       return r < 0 ? r + m : r;   }         int dfs(vector<vector<bool>> &change, vector<string> &arr, int i, int j, int k)   {       return 0;   }         void run()   {       ll n; cin >> n;       ll copy = n;          while(n % 4 == 0 && n > 4)            n /= 4;          if (n == 2 || n == 4) { cout <<  YES n ; return; }          n = copy;          if (n % 2 == 0 && (n / 2) == sq(ll(sqrt(double(n / 2))))) { cout <<  YES n ; return; }       if (n % 4 == 0 && (n / 4) == sq(ll(sqrt(double(n / 4))))) { cout <<  YES n ; return; }       else cout <<  NO n ;   }      int main()   {       cin.tie(NULL);       ios_base::sync_with_stdio(false);          int t = 1;       cin >> t;          REP(i, 0, t) { run(); }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     static int r, sign;     static char c;     r = 0, c = getchar(), sign = 1;     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) sign = -1, c = getchar();     while (c >=  0  && c <=  9 ) r = r * 10 + (c -  0 ), c = getchar();     return r * sign;   }   template <typename T>   inline void print(T *a, int n) {     for (int i = 1; i < n; ++i) cout << a[i] <<    ;     cout << a[n] << endl;   }   const int mod = (int)1e9 + 7;   int n, x = 0, y = 0;   char m[4][10010 + 1];   int f[2][64];   inline int get(int x, int p) { return (x >> (p - 1) * 2) & 3; }   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int solve() {     memset(f, 0, sizeof f);     f[0][0] = 1;     for (int i = 1; i <= n; ++i) {       memset(f[i & 1], 0, sizeof f[i & 1]);       for (int j = 0; j < 64; ++j) {         if (!f[i & 1 ^ 1][j]) continue;         for (int k = 0; k < 64; ++k) {           bool ok = true;           for (int x = 1; ok && x <= 3; ++x) {             if (get(j, x) == 1 && get(k, x) != 2) ok = false;             if (get(k, x) == 2 && get(j, x) != 1) ok = false;             if (m[x][i] !=  X  && get(k, x) == 0) ok = false;             if (m[x][i] ==  X  && get(k, x) != 0) ok = false;           }           if (get(k, 1) == 3 && get(k, 2) != 3) ok = false;           if (get(k, 2) != 3 && get(k, 3) == 3) ok = false;           if (get(k, 2) == 3 && get(k, 1) != 3 && get(k, 3) != 3) ok = false;           if (get(k, 1) == 3 && get(k, 2) == 3 && get(k, 3) == 3) ok = false;           if (!ok) continue;           add(f[i & 1][k], f[i & 1 ^ 1][j]);         }       }     }     int ans = 0;     for (int i = 0; i < 64; ++i) {       bool ok = true;       for (int x = 1; ok && x <= 3; ++x)         if (get(i, x) == 1) ok = false;       if (!ok) continue;       add(ans, f[n & 1][i]);     }     return ans;   }   const int dir[8][2] = {{0, 1},   {1, 0},  {-1, 0}, {0, -1},                          {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};   int main(int argc, char *argv[]) {     scanf( %d , &n);     scanf( %s n%s n%s n , m[1] + 1, m[2] + 1, m[3] + 1);     for (int i = 1; !x && i <= n; ++i)       for (int j = 1; j <= 3; ++j)         if (m[j][i] ==  O ) x = j, y = i;     m[x][y] =  X ;     int ans = solve();     if (x == 2 && y > 1 && y < n) {       bool need = true;       for (int i = 0; i < 8; ++i) {         int nx = x + dir[i][0], ny = y + dir[i][1];         if (m[nx][ny] ==  X ) need = false;       }       if (need) {         for (int i = 0; i < 8; ++i) {           int nx = x + dir[i][0], ny = y + dir[i][1];           m[nx][ny] =  X ;         }         ans -= 2 * solve() % mod;         if (ans < 0) ans += mod;       }     }     printf( %d n , ans);     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sim(vector<int> s, int p, int x) {     s.insert(s.begin() + p, x);     int l = p, r = p;     int acum = 0;     int ans = 0;     for (;;) {       while (l >= 0 && s[l] == x) l--;       while (r <= (int)s.size() - 1 && s[r] == x) r++;       int dis = r - l - 1;       if (dis - acum >= 3) {         ans += dis - acum;         acum += dis - acum;       } else         break;       if (l == -1 || r == (int)s.size()) break;       if (s[l] == s[r]) x = s[l];     }     return ans - 1;   }   int main() {     int n, k, x;     cin >> n >> k >> x;     vector<int> ns(n);     for (int i = 0; i < n; i++) cin >> ns[i];     int ans = 0;     for (int i = 0; i <= n; i++) {       ans = max(ans, sim(ns, i, x));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     getline(cin, str);     char c = 0;     int n = str.length();     for (int i = n - 1; i >= 0; i--) {       if ((str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122)) {         c = str[i];         break;       }     }     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  ||         c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y )       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     int m;     cin >> m;     string s;     cin >> s;     int n = s.size();     vector<int> cnt(26);     vector<int> have(n);     for (int c = 0; c < 26; ++c) {       for (int i = 0; i < n; ++i) {         if (s[i] -  a  == c) {           have[i] = 1;           ++cnt[c];         }       }       bool fl = 1;       int lst = -1;       for (int i = 0; i < n; ++i) {         if (have[i]) {           fl &= (i - lst - 1 < m);           lst = i;         }       }       fl &= (n - lst - 1 < m);       if (!fl) {         continue;       } else {         int lst = -1;         int nxt = 0;         for (int i = 0; i < n; ++i) {           nxt = max(nxt, i + 1);           while (nxt < n && !have[nxt]) ++nxt;           if (have[i] && s[i] -  a  == c && nxt - lst - 1 < m) {             --cnt[c];           } else if (have[i])             lst = i;         }         for (int i = 0; i < 26; ++i) {           for (int j = 0; j < cnt[i]; ++j) {             cout << char( a  + i);           }         }         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     if (x < 0)       return -x;     else       return x;   }   int main() {     double A, B, C, D;     scanf( %lf%lf , &A, &B);     scanf( %lf%lf , &C, &D);     if (A * D > B * C) {       swap(A, B);       swap(D, C);     }     double l = 0, r = 1e9;     for (int T = 0; T < 200; ++T) {       double mid = (l + r) / 2.0;       bool flag = false;       double a = A - mid;       for (int i = 0; i < 2; ++i) {         double b = B - mid;         for (int j = 0; j < 2; ++j) {           double c = C - mid;           for (int u = 0; u < 2; ++u) {             double d = D - mid;             for (int v = 0; v < 2; ++v) {               if (a * d > b * c) {                 flag = true;               }               d += mid;               d += mid;             }             c += mid;             c += mid;           }           b += mid;           b += mid;         }         a += mid;         a += mid;       }       if (flag)         r = mid;       else         l = mid;     }     printf( %.12f n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   const int maxn = 300000 + 500;   const int maxk = 5005;   const int INF = 2e9 + 100;   int a[maxn];   int d[maxk][maxk];   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int large = n % k;     int small = k - large;     int seg = n / k;     sort(a + 1, a + n + 1);     for (int i = 0; i <= k; i++)       for (int j = 0; j <= k; j++) d[i][j] = INF;     d[0][0] = 0;     for (int i = 0; i <= large; i++) {       for (int j = 0; j <= small; j++) {         int nxt = i * (seg + 1) + j * seg + 1;         if (i < large) {           int add = a[nxt + seg] - a[nxt];           d[i + 1][j] = min(d[i + 1][j], d[i][j] + add);         }         if (j < small) {           int add = a[nxt + seg - 1] - a[nxt];           d[i][j + 1] = min(d[i][j + 1], d[i][j] + add);         }       }     }     cout << d[large][small] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int n, k, x, arr[N];   long long tree[2][17000];   void build(int pos, int l, int r, int dim) {     if (l == r) {       if (l <= k)         tree[dim][pos] = arr[l];       else         tree[dim][pos] = -1e18;       return;     }     int mid = (l + r) >> 1;     build(pos << 1, l, mid, dim);     build(pos << 1 | 1, mid + 1, r, dim);     tree[dim][pos] = max(tree[dim][pos << 1], tree[dim][pos << 1 | 1]);   }   void update(int pos, int l, int r, int x, long long v, int dim) {     if (l == r) {       tree[dim][pos] = v;       return;     }     int mid = (l + r) >> 1;     if (mid >= x)       update(pos << 1, l, mid, x, v, dim);     else       update(pos << 1 | 1, mid + 1, r, x, v, dim);     tree[dim][pos] = max(tree[dim][pos << 1], tree[dim][pos << 1 | 1]);   }   long long get(int pos, int l, int r, int qLow, int qHigh, int dim) {     if (l >= qLow && r <= qHigh) return tree[dim][pos];     int mid = (l + r) >> 1;     long long a = -1, b = -1;     if (mid >= qLow) a = get(pos << 1, l, mid, qLow, qHigh, dim);     if (mid + 1 <= qHigh) b = get(pos << 1 | 1, mid + 1, r, qLow, qHigh, dim);     return max(a, b);   }   int main() {     scanf( %d%d%d , &n, &k, &x);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     for (int i = 1; i <= k; i++) tree[0][i] = arr[i];     for (int i = k + 1; i <= n; i++) tree[0][i] = -1e18;     int p = 1;     for (int z = 2; z <= x; z++) {       deque<int> q;       for (int i = max(0, z - k); i < z; i++) {         while (!q.empty() && tree[!p][i] >= tree[!p][q.back()]) q.pop_back();         q.push_back(i);       }       for (int i = z; i <= n; i++) {         while (!q.empty() && q.front() < i - k) q.pop_front();         long long zorbe7 = tree[!p][q.front()];         while (!q.empty() && tree[!p][i] >= tree[!p][q.back()]) q.pop_back();         q.push_back(i);         long long ans = arr[i] + (zorbe7 < 0 ? -1e18 : zorbe7);         tree[p][i] = ans;       }       p = !p;     }     long long zorbe7 = -1e18;     for (int i = n - k + 1; i <= n; i++) zorbe7 = max(zorbe7, tree[!p][i]);     printf( %lld , zorbe7 > 0 ? zorbe7 : -1);     return 0;   }


#include <bits/stdc++.h>   char a[1001][1001];   int n, m;   int findG(int r) {     int i;     for (i = 0; i < m; i = i + 1)       if (a[r][i] ==  G ) return i;   }   int findS(int r) {     int i;     for (i = 0; i < m; i = i + 1)       if (a[r][i] ==  S ) return i;   }   int main() {     scanf( %d%d , &n, &m);     int N = n;     while (N--) {       scanf( %s , &a[N]);     }     int f[1001] = {0};     for (int l = 0; l < n; l++) {       int dif = findS(l) - findG(l);       if (dif < 0) {         printf( -1 );         return 0;       } else         f[dif] = 1;     }     int s = 0;     for (int d = 0; d < m; d++) s = s + f[d];     printf( %d , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int rs, p;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> a >> b;     if (a.size() != b.size()) return cout <<  NO , 0;     for (int i = 0; i < a.size(); i++)       if (a[i] != b[i]) rs++, p = i;     if (rs != 2) return cout <<  NO , 0;     for (int i = 0; i < a.size(); i++)       if (a[i] != b[i] && a[i] == b[p] && a[p] == b[i])         return cout <<  YES , 0;       else if (a[i] != b[i])         return cout <<  NO , 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<int, int> &p1, const pair<int, int> &p2) {     if (p1.first == p2.first) {       return p1.second < p2.second;     }     return p1.first > p2.first;   }   int main() {     int n, m, e, x, y;     cin >> n >> m;     std::vector<pair<int, int> > E;     for (int i = 0; i < n; ++i) {       cin >> e;       E.push_back(make_pair(e, i));     }     sort(E.begin(), E.end(), cmp);     int inv[n];     for (int i = 0; i < n; ++i) {       inv[E[i].second] = i;     }     bool isThere[n];     for (int i = 0; i < n; ++i) isThere[i] = false;     std::vector<vector<int> > adj(n);     for (int i = 0; i < m; ++i) {       cin >> x >> y;       adj[x - 1].push_back(y - 1);       adj[y - 1].push_back(x - 1);     }     long long int sum = 0;     for (int i = 0; i < n; ++i) {       int ind = E[i].second;       for (int j = 0; j < adj[ind].size(); ++j) {         if (isThere[adj[ind][j]]) continue;         sum += E[inv[adj[ind][j]]].first;       }       isThere[ind] = true;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Prime(int a) {     if (a == 1) return true;     for (int i = 2; i * i <= a; i++)       if (a % i == 0) return false;     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int count = 0;       for (int i = 0; i < s.length(); i++)         if (s[i] ==  N ) count++;       count == 1 ? cout <<  NO  : cout <<  YES ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int INF = 1234567890;   int t, T;   int fa[100000], opp[100000];   int l[100000], r[100000];   int col[100000];   set<pair<int, int> > rp;   set<pair<int, int> > lp;   int find(int a) {     if (a == -1) return -1;     if (fa[a] == -1) return a;     return fa[a] = find(fa[a]);   }   bool check(int a, int b) {     if (a == -1 || b == -1) return true;     if (a == b) return false;     return r[a] + r[b] >= t && l[a] + l[b] <= T;   }   bool merge(int a, int b) {     if (a == b) return true;     if (a == -1 || b == -1) return true;     fa[b] = a;     lp.erase(make_pair(l[b], b));     rp.erase(make_pair(r[b], b));     if (l[b] > l[a]) {       if (lp.find(make_pair(l[a], a)) != lp.end()) {         lp.erase(make_pair(l[a], a));         lp.insert(make_pair(l[b], a));       }       l[a] = l[b];     }     if (r[b] < r[a]) {       if (rp.find(make_pair(r[a], a)) != rp.end()) {         rp.erase(make_pair(r[a], a));         rp.insert(make_pair(r[b], a));       }       r[a] = r[b];     }     return l[a] <= r[a];   }   bool diff(int a, int b) {     a = find(a);     b = find(b);     int aa = find(opp[a]);     int bb = find(opp[b]);     if (a == b) return false;     if (!check(a, b)) return false;     if (!check(aa, bb)) return false;     if (opp[a] == -1) opp[a] = b;     if (opp[b] == -1) opp[b] = a;     return merge(aa, b) && merge(a, bb);   }   bool same(int a, int b) {     a = find(a);     b = find(b);     int aa = find(opp[a]);     int bb = find(opp[b]);     if (!check(a, bb)) return false;     if (!check(aa, b)) return false;     if (opp[a] == -1) opp[a] = opp[b];     if (opp[b] == -1) opp[b] = opp[a];     return merge(a, b) && merge(aa, bb);   }   int get(int a) {     if (col[a] != -1) return col[a];     if (fa[a] == -1) {       col[a] = 0;       if (opp[a] != -1) col[find(opp[a])] = 1;       return 0;     }     return col[a] = get(find(a));   }   int main() {     while (scanf( %d%d , &t, &T) == 2) {       rp.clear();       lp.clear();       int n, m;       scanf( %d%d , &n, &m);       bool f = true;       memset(fa, -1, sizeof(fa));       memset(opp, -1, sizeof(opp));       for (int i = 0; i < n; i++) {         scanf( %d%d , l + i, r + i);         rp.insert(make_pair(r[i], i));         lp.insert(make_pair(l[i], i));         if (l[i] > T) f = false;       }       while (m--) {         int a, b;         scanf( %d%d , &a, &b);         a--;         b--;         a = find(a);         b = find(b);         if (!diff(a, b)) f = false;       }       if (n == 1) {         if (l[0] > T || r[0] < t)           printf( IMPOSSIBLE n );         else           printf( POSSIBLE n%d 0 n1 n , max(l[0], t));         continue;       }       for (int i = 0; i < n && f; i++) {         if (find(i) != i) continue;         rp.erase(rp.find(make_pair(r[i], i)));         lp.erase(lp.find(make_pair(l[i], i)));         while (f && !lp.empty()) {           set<pair<int, int> >::iterator itr = lp.end();           itr--;           int b = find(itr->second);           if (b == find(opp[i])) {             b = itr->second;             rp.erase(make_pair(r[b], b));             lp.erase(make_pair(l[b], b));             continue;           }           if (r[i] < l[b])             f = diff(i, b);           else             break;         }         while (f && !lp.empty()) {           set<pair<int, int> >::iterator itr = lp.end();           itr--;           int b = find(itr->second);           if (b == find(opp[i])) {             b = itr->second;             rp.erase(make_pair(r[b], b));             lp.erase(make_pair(l[b], b));             continue;           }           if (l[i] + l[b] > T)             f = same(i, b);           else             break;         }         while (f && !lp.empty()) {           set<pair<int, int> >::iterator itr = rp.begin();           int b = find(itr->second);           if (b == find(opp[i])) {             b = itr->second;             rp.erase(make_pair(r[b], b));             lp.erase(make_pair(l[b], b));             continue;           }           if (r[i] + r[b] < t)             f = same(i, b);           else             break;         }         if (i == find(i)) {           rp.insert(make_pair(r[i], i));           lp.insert(make_pair(l[i], i));         }         if (opp[i] != -1) {           int j = find(opp[i]);           rp.insert(make_pair(r[j], j));           lp.insert(make_pair(l[j], j));         }       }       if (!f)         printf( IMPOSSIBLE n );       else {         printf( POSSIBLE n );         memset(col, -1, sizeof(col));         int l0 = 0, r0 = T, l1 = 0, r1 = T;         for (int i = 0; i < n; i++) {           if (get(i)) {             l1 = max(l1, l[i]);             r1 = min(r1, r[i]);           } else {             l0 = max(l0, l[i]);             r0 = min(r0, r[i]);           }         }         int L = l0, R = l1;         int ndd = t - l0 - l1;         if (ndd > 0) {           if (ndd + L <= r0) {             L += ndd;           } else {             L = r0;             ndd -= r0 - l0;             R += ndd;           }         }         printf( %d %d n , L, R);         for (int i = 0; i < n; i++) printf( %d , col[i] + 1);         printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXL = 40000;   pair<int, int> p[MAXL];   int Init() {     for (int i = 0; i * i < MAXL; i++) {       for (int j = i; j * j + i * i < MAXL; j++) {         int now = i * i + j * j;         p[now].first = i;         p[now].second = j;       }     }     return 0;   }   inline bool cmp(pair<int, int> a, pair<int, int> b) {     return a.first * a.first + a.second * a.second >            b.first * b.first + b.second * b.second;   }   inline bool cmp2(pair<int, int> a, pair<int, int> b) {     return atan2(a.second, a.first) < atan2(b.second, b.first) - (1e-8);   }   int L(int a, int b) { return a * a + b * b; }   int n;   int Solve() {     vector<pair<int, int> > e;     int sum = 0;     scanf( %d , &n);     for (int i = 0; i < MAXL && e.size() <= n; i++) {       if (p[i].first == 0 && p[i].second == 0) continue;       sum ^= p[i].first ^ p[i].second;       e.push_back(p[i]);     }     reverse(e.begin(), e.end());     for (vector<pair<int, int> >::iterator it = e.begin(); it != e.end(); it++) {       if (((sum ^ it->first ^ it->second) & 1) == 0) {         e.erase(it);         break;       }     }     sort(e.begin(), e.end(), cmp);     int ix = 0, iy = 0;     for (vector<pair<int, int> >::iterator it = e.begin(); it != e.end(); it++) {       int fx = 1, fy = 1;       int xx = it->first, yy = it->second;       if (ix > 0) fx = -1;       if (iy > 0) fy = -1;       if (L(fx * xx + ix, fy * yy + iy) < L(fx * yy + ix, fy * xx + iy))         *it = make_pair(fx * xx, fy * yy);       else         *it = make_pair(fx * yy, fy * xx);       ix = it->first + ix;       iy = it->second + iy;     }     sort(e.begin(), e.end(), cmp2);     puts( YES );     for (vector<pair<int, int> >::iterator it = e.begin(); it != e.end(); it++) {       printf( %d %d n , ix, iy);       ix += it->first;       iy += it->second;     }     return 0;   }   int main() {     Init();     Solve();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:134217728 )   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int dx[4] = {0, 1, 0, -1};   int dy[4] = {1, 0, -1, 0};   string s[5001];   vector<int> t[5001];   string ss[5001];   vector<pair<int, int> > root[4][5001];   vector<pair<int, int> > next239[4][5001];   int good(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }   int ans[10000];   pair<int, int> get_root(int t, pair<int, int> o) {     if (root[t][o.first][o.second] == o) return o;     return root[t][o.first][o.second] = get_root(t, root[t][o.first][o.second]);   }   void merge(int t, pair<int, int> a, pair<int, int> b) {     a = get_root(t, a);     root[t][a.first][a.second] = get_root(t, b);   }   int main() {     cin >> n >> m;     for (int i = 0; i < (n); i++) cin >> s[i];     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (s[i][j] !=  . ) {           int c = s[i][j];           if (c ==  U ) t[i].push_back(3);           if (c ==  D ) t[i].push_back(1);           if (c ==  L ) t[i].push_back(2);           if (c ==  R ) t[i].push_back(0);         } else           t[i].push_back(-1);     for (int o = 0; o < (4); o++) {       for (int i = 0; i < (n); i++)         for (int j = 0; j < (m); j++) {           int cx = i + dx[o];           int cy = j + dy[o];           while (good(cx, cy) && s[cx][cy] ==  . ) {             cx += dx[o];             cy += dy[o];           }           if (good(cx, cy))             next239[o][i].push_back(make_pair(cx, cy));           else             next239[o][i].push_back(make_pair(n, m));         }     }     for (int o = 0; o < (4); o++)       for (int i = 0; i < (n + 1); i++) root[o][i].resize(m + 1);     for (int x = 0; x < (n); x++)       for (int y = 0; y < (m); y++)         if (s[x][y] !=  . ) {           for (int i = 0; i < (n + 1); i++)             for (int j = 0; j < (m + 1); j++)               for (int o = 0; o < (4); o++) root[o][i][j] = make_pair(i, j);           int cx = x, cy = y;           int col = 1;           while (good(cx, cy)) {             pair<int, int> tmp = get_root(t[cx][cy], next239[t[cx][cy]][cx][cy]);             if (!good(tmp.first, tmp.second)) break;             for (int o = 0; o < (4); o++) {               merge(o, make_pair(cx, cy), next239[o][cx][cy]);             }             cx = tmp.first;             cy = tmp.second;             col++;           }           ans[col]++;         }     int o = n * m;     while (ans[o] == 0) o--;     cout << o <<     << ans[o] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, ans = 0;     cin >> n;     long long boy[n];     for (long long i = 0; i < n; i++) cin >> boy[i];     cin >> m;     long long girl[m];     for (long long i = 0; i < m; i++) cin >> girl[i];     sort(boy, boy + n);     sort(girl, girl + m);     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (abs(boy[i] - girl[j]) <= 1) {           ans++;           girl[j] = 200;           break;         }       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000 * 1000 * 1000 + 7;   const int mod = 1000 * 1000 * 1000 + 9;   const int num = 1000 * 1000 + 7;   const int N = 1000 + 7;   const double PI = 3.1415926535897932384626433832795;   int ux_x[5] = {0, 0, 1, -1};   int ux_y[5] = {1, -1, 0, 0};   int n, t, m, k;   long long a[num];   bool used[num];   long long ans = 0, ans1 = 0;   void solve() {     string s;     cin >> s;     vector<int> v1, v2;     for (int i = 0; i < s.length(); ++i) {       int e = s[i] -  0 ;       ans += e;       if (e % 3 == 1) {         v1.push_back(i);       }       if (e % 3 == 2) {         v2.push_back(i);       }     }     reverse(v1.begin(), v1.end());     reverse(v2.begin(), v2.end());     if (ans % 3 == 0) {       cout << s << endl;       exit(0);     }     if (s.length() == 1) {       cout << -1;       exit(0);     }     if (ans % 3 == 1) {       if (v1.size() == 0) {         if (v2.size() < 1 || s.length() == 2) {           cout << -1;           exit(0);         }         s.erase(s.begin() + v2[0]);         s.erase(s.begin() + v2[1]);         if (s.length() == 1) {           cout << s << endl;           exit(0);         }         int e = 0;         while (e < s.length() && s[e] ==  0 ) e++;         if (e == s.length()) {           cout << 0;           exit(0);         }         for (int i = e; i < s.length(); ++i) {           cout << s[i];         }         exit(0);       } else {         if (v1[0] == 0 && s.length() > 2 && s[1] ==  0  && s[2] ==  0  &&             v2.size() > 1) {           s.erase(s.begin() + v2[0]);           s.erase(s.begin() + v2[1]);           if (s.length() == 1) {             cout << s << endl;             exit(0);           }           int e = 0;           while (e < s.length() && s[e] ==  0 ) e++;           if (e == s.length()) {             cout << 0;             exit(0);           }           for (int i = e; i < s.length(); ++i) {             cout << s[i];           }           exit(0);         }         s.erase(s.begin() + v1[0]);         if (s.length() == 1) {           cout << s << endl;           exit(0);         }         int e = 0;         while (e < s.length() && s[e] ==  0 ) e++;         if (e == s.length()) {           cout << 0;           exit(0);         }         for (int i = e; i < s.length(); ++i) {           cout << s[i];         }         exit(0);       }     } else {       if (v2.size() == 0) {         if (v1.size() < 1 || s.length() == 2) {           cout << -1;           exit(0);         }         s.erase(s.begin() + v1[0]);         s.erase(s.begin() + v1[1]);         if (s.length() == 1) {           cout << s << endl;           exit(0);         }         int e = 0;         while (e < s.length() && s[e] ==  0 ) e++;         if (e == s.length()) {           cout << 0;           exit(0);         }         for (int i = e; i < s.length(); ++i) {           cout << s[i];         }         exit(0);       } else {         if (v2[0] == 0 && s.length() > 2 && s[1] ==  0  && s[2] ==  0  &&             v1.size() > 1) {           s.erase(s.begin() + v1[0]);           s.erase(s.begin() + v1[1]);           if (s.length() == 1) {             cout << s << endl;             exit(0);           }           int e = 0;           while (e < s.length() && s[e] ==  0 ) e++;           if (e == s.length()) {             cout << 0;             exit(0);           }           for (int i = e; i < s.length(); ++i) {             cout << s[i];           }           exit(0);         }         s.erase(s.begin() + v2[0]);         int e = 0;         if (s.length() == 1) {           cout << s << endl;           exit(0);         }         while (e < s.length() && s[e] ==  0 ) e++;         if (e == s.length()) {           cout << 0;           exit(0);         }         for (int i = e; i < s.length(); ++i) {           cout << s[i];         }         exit(0);       }     }   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int getidx(const vector<int>& ar, int x) {     return lower_bound(ar.begin(), ar.end(), x) - ar.begin();   }   inline long long GCD(long long a, long long b) {     long long n;     if (a < b) swap(a, b);     while (b != 0) {       n = a % b;       a = b;       b = n;     }     return a;   }   inline long long LCM(long long a, long long b) {     if (a == 0 || b == 0) return GCD(a, b);     return a / GCD(a, b) * b;   }   inline long long CEIL(long long n, long long d) {     return n / d + (long long)(n % d != 0);   }   inline long long ROUND(long long n, long long d) {     return n / d + (long long)((n % d) * 2 >= d);   }   inline long long POW(long long a, long long n) {     if (n < 0) return 0;     long long ret = 1;     while (n) {       if (n % 2) ret *= a;       a = a * a;       n /= 2;     }     return ret;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   template <class T>   ostream& operator<<(ostream& os, vector<T> v) {     os <<  [ ;     int cnt = 0;     for (auto vv : v) {       os << vv;       if (++cnt < v.size()) os <<  , ;     }     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> v) {     os <<  [ ;     int cnt = 0;     for (auto vv : v) {       os << vv;       if (++cnt < v.size()) os <<  , ;     }     return os <<  ] ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   const int INF = 0x3fffffff, MOD = 1e9 + 7;   int n;   map<int, int> dp;   set<int> non0;   void input() { cin >> n; }   int solve() {     dp[-INF] = 1, dp[INF] = 0;     non0.insert(-INF);     while (n--) {       int x;       string qur;       cin >> qur >> x;       if (qur ==  ADD ) {         auto it = dp.lower_bound(x);         --it;         dp[x] = it->second;         non0.insert(x);       } else {         auto hi = dp.find(x);         auto lo = prev(hi);         lo->second = (lo->second + hi->second) % MOD;         non0.insert(lo->first);         non0.erase(hi->first);         dp.erase(hi);         for (auto it = non0.begin(); it != non0.end();) {           if (*it == lo->first)             ++it;           else             dp[*it] = 0, it = non0.erase(it);         }       }     }     int ans = 0;     for (auto p : dp) {       ans = (ans + p.second) % MOD;     }     cout << ans <<   n ;     return 0;   }   void execute() { input(), solve(); }   int main(void) {     cin.tie(0);     ios_base::sync_with_stdio(false);     execute();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, col[N], maxx, cnt[N], p[N], eid, Son, mx[N], sz[N];   long long sum, ans[N];   struct edge {     int v, nxt;   } e[N << 1];   inline void addedge(int u, int v) { e[++eid] = (edge){v, p[u]}, p[u] = eid; }   inline void dfs0(int u, int fa) {     sz[u] = 1;     for (int i = p[u]; i; i = e[i].nxt)       if (e[i].v != fa) {         int v = e[i].v;         dfs0(v, u), sz[u] += sz[v];         if (sz[v] > sz[mx[u]]) mx[u] = v;       }   }   inline void add(int u, int fa, int d) {     cnt[col[u]] += d;     if (cnt[col[u]] > maxx)       maxx = cnt[col[u]], sum = col[u];     else if (cnt[col[u]] == maxx)       sum += col[u];     for (int i = p[u]; i; i = e[i].nxt)       if (e[i].v != fa && e[i].v != Son) add(e[i].v, u, d);   }   inline void dfs(int u, int fa, int d) {     for (int i = p[u]; i; i = e[i].nxt)       if (e[i].v != fa && e[i].v != mx[u]) dfs(e[i].v, u, 0);     if (mx[u]) dfs(mx[u], u, 1), Son = mx[u];     add(u, fa, 1), Son = 0, ans[u] = sum;     if (!d) add(u, fa, -1), sum = maxx = 0;   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) scanf( %d , &col[i]);     for (int i = (1); i <= (n - 1); i++) {       int u, v;       scanf( %d%d , &u, &v);       addedge(u, v), addedge(v, u);     }     dfs0(1, 0), dfs(1, 0, 0);     for (int i = (1); i <= (n); i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   int main() {     double d, h, v, e;     while (scanf( %lf%lf%lf%lf , &d, &h, &v, &e) != EOF) {       double t = v / (PI * (d / 2) * (d / 2));       if (t > e) {         printf( YES n );         double ti = h / (t - e);         printf( %lf n , ti);       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, p, w, d;   int main() {     cin >> n >> p >> w >> d;     for (long long i = 0; i < w; i++) {       if ((p - i * d) % w == 0) {         long long x = (p - i * d) / w;         if (x >= 0 && x + i <= n) {           printf( %lld %lld %lld n , x, i, n - x - i);           return 0;         }       }     }     cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 3e5;   int t, n, m, h[N], val[N];   std::set<int> adj[N], jda[N], res;   std::map<int, std::set<int>> map;   void reset() {     for (int i = 1; i <= n; ++i) {       adj[i].clear();       jda[i].clear();       h[i] = 0;       val[i] = 0;     }     map.clear();     res.clear();   }   void dfs(int u) {     if (h[u]) return;     for (int v : adj[u]) {       dfs(v);       h[u] = std::max(h[u], h[v]);     }     map[-++h[u]].insert(u);   }   void turn_off(int u) {     val[u] = n;     for (int v : adj[u]) --val[v];   }   void turn_on(int u) {     --val[u];     for (int v : adj[u])       if (!++val[v]) turn_off(v);   }   int greedy(int u) {     if (!val[u]) {       for (int v : jda[u]) assert(val[v] > 0);       --val[u];       for (int v : adj[u])         if (!val[v])           turn_on(v);         else if (~val[v])           val[v] = n;     }     return val[u];   }   void solve() {     scanf( %d%d , &n, &m);     reset();     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].insert(v);       jda[v].insert(u);     }     for (int i = 1; i <= n; ++i) dfs(i);     for (auto pset : map)       for (int x : pset.second)         if (greedy(x) > 0) res.insert(x);     printf( %u n , res.size());     for (int x : res) printf( %d  , x);     printf(  n );   }   int main() {     scanf( %d , &t);     for (int i = 0; i < t; ++i) solve();   }


#include <bits/stdc++.h>   using namespace std;   struct el {     long long hp, dmg, i;   };   bool comp(el a, el b) { return (a.hp - a.dmg) > (b.hp - b.dmg); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, a, b, i = 0;     cin >> n >> a >> b;     el sol[n];     for (i = (0); i < (n); i++) {       cin >> sol[i].hp >> sol[i].dmg;       sol[i].i = i;     }     sort(sol, sol + n, comp);     long long sum = 0;     for (i = (0); i < (n); i++) {       if (i < b)         sum += max(sol[i].hp, sol[i].dmg);       else         sum += sol[i].dmg;     }     if (b == 0) {       cout << sum <<   n ;       return 0;     }     long long x = (1LL << a);     long long res = sum;     for (i = (0); i < (n); i++) {       long long temp = res;       if (i < b) {         temp -= max(sol[i].hp, sol[i].dmg);         temp += (sol[i].hp) * x;         sum = max(sum, temp);       } else {         temp -= sol[i].dmg;         temp += sol[i].hp * x;         temp -= max(sol[b - 1].hp, sol[b - 1].dmg);         temp += sol[b - 1].dmg;         sum = max(sum, temp);       }     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   void sync_stdio() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   int intersect(pair<int, int> a, pair<int, int> b) {     return !(b.second <= a.first || a.second <= b.first);   }   int main() {     int a, ta, b, tb;     scanf( %d%d%d%d , &a, &ta, &b, &tb);     int h, m;     scanf( %d:%d , &h, &m);     int tm = h * 60 + m;     int START = 5 * 60;     int END = 24 * 60;     int res = 0;     for (int i = START; i < END; i += b) {       if (intersect({tm, tm + ta}, {i, i + tb})) {         ++res;       }     }     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     vector<long long> arr;     arr.push_back(0);     int sz = 1;     long long max_ele = -1;     long long pre_ind = 0;     while (q--) {       int x;       cin >> x;       if (x == 1) {         long long v;         cin >> v;         if (sz == 0)           arr.push_back(v);         else           arr.push_back(v + arr[sz - 1]);         sz++;         max_ele = v;         continue;       }       if (sz == 2) {         cout << setprecision(10) << 0.0l <<   n ;         continue;       }       long long pre_sum = arr[pre_ind];       long long pre_numer = (pre_ind)*max_ele - pre_sum;       long double val = (long double)pre_numer / (pre_ind + 1);       while (pre_ind + 1 <= sz - 2) {         if ((long double)((pre_ind + 1) * max_ele - arr[pre_ind + 1]) /                 (pre_ind + 2) >             val) {           val = (long double)((pre_ind + 1) * max_ele - arr[pre_ind + 1]) /                 (pre_ind + 2);           pre_ind++;         } else           break;       }       cout << setprecision(10) << val <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> big;   vector<int> s[100010];   vector<int> pos[100010];   unsigned int h[100010], n, m, q;   int same[320][100010];   unsigned int BND;   long long a[100010], sum[100010], add[100010];   void Debug() {     unsigned int i, j;     printf( light: n );     for (i = 0; i < m; i++) {       for (j = 0; j < s[i].size(); j++) {         if (j) printf(   );         printf( %I64d , a[s[i][j]]);       }       if (s[i].size() > BND)         printf(  heavy n );       else         printf(  light n );     }     printf(  n );     for (i = 0; i < big.size(); i++)       for (j = 0; j < m; j++) printf( same:%d %d= %d n , h[i], j, same[i][j]);   }   int main() {     unsigned int i, j, k;     scanf( %d%d%d , &n, &m, &q);     BND = sqrt(n);     for (i = 0; i < n; i++) scanf( %I64d , &a[i]);     for (i = 0; i < m; i++) {       unsigned int cnt;       scanf( %d , &cnt);       for (j = 0; j < cnt; j++) {         int tmp;         scanf( %d , &tmp);         tmp--;         s[i].push_back(tmp);         pos[tmp].push_back(i);         sum[i] += a[tmp];       }     }     for (i = 0; i < m; i++)       if (s[i].size() > BND) {         big.push_back(i);         h[big.size() - 1] = i;         for (j = 0; j < s[i].size(); j++) {           int tmp = s[i][j];           for (k = 0; k < pos[tmp].size(); k++)             same[big.size() - 1][pos[tmp][k]]++;         }       }     char o[2];     long long x;     while (q--) {       scanf( %s , o);       if (o[0] ==  + ) {         scanf( %d%I64d , &k, &x);         k--;         if (s[k].size() > BND) {           add[k] += x;           for (i = 0; i < big.size(); i++)             if (h[i] != k) sum[h[i]] += x * (long long)(same[i][k]);         } else {           for (i = 0; i < s[k].size(); i++) a[s[k][i]] += x;           for (i = 0; i < big.size(); i++)             sum[h[i]] += x * (long long)(same[i][k]);         }       } else {         scanf( %d , &k);         k--;         if (s[k].size() > BND) {           long long ans = sum[k] + (long long)s[k].size() * add[k];           printf( %I64d n , ans);         } else {           long long ans = 0;           for (i = 0; i < s[k].size(); i++) ans += a[s[k][i]];           for (i = 0; i < big.size(); i++) ans += add[h[i]] * same[i][k];           printf( %I64d n , ans);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Comm {     int first;     int second;     Comm(int a, int b) {       first = a;       second = b;     }     bool operator<(const Comm& other) const {       if (this->first == other.first) return this->second < other.second;       return this->first < other.first;     }   };   vector<int> P;   vector<int> G;   vector<Comm> ans;   int n;   int main() {     int x, scoP = 0, scoG = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (x == 1)         scoP++;       else         scoG++;       P.push_back(scoP);       G.push_back(scoG);     }     int pntP = 0, pntG = 0, setP = 0, setG = 0;     int maxPoint = max(scoP, scoG);     for (int i = maxPoint; i > 0; i--) {       int tar1 = i, tar2 = i;       int pos = 0;       setP = setG = pntG = pntP = 0;       while (pos < n && !(pntG == pntP && pntG == n)) {         pntP = lower_bound(P.begin() + pos, P.end(), tar1) - P.begin();         pntG = lower_bound(G.begin() + pos, G.end(), tar2) - G.begin();         if (pntP < pntG) {           setP++;           pos = pntP + 1;           tar1 = P[pntP] + i;           tar2 = G[pntP] + i;         }         if (pntP > pntG) {           setG++;           pos = pntG + 1;           tar1 = P[pntG] + i;           tar2 = G[pntG] + i;         }       }       int tmp = max(setG, setP);       if (tmp == setG && x == 1 || tmp == setP && x == 2 || setG == setP ||           pntG == pntP && pntG == n) {         continue;       }       Comm m(tmp, i);       ans.push_back(m);     }     printf( %d n , ans.size());     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long INF = 1e7;   signed main() {     cin.tie(0), ios_base::sync_with_stdio(false);     ;     long long n, s;     cin >> n >> s;     vector<long long> arr(n);     long long su = 0, mi = 1e18;     for (long long i = 0; i < n; ++i) {       cin >> arr[i];       su += arr[i];       if (mi > arr[i]) {         mi = arr[i];       }     }     su -= s;     if (su < 0) {       cout << -1;       return 0;     }     cout << min(su / n, mi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 2e5 + 10;   int per(int tot, int cur) { return (cur * 100 + tot / 2) / tot; }   int main() {     int n, k;     cin >> n >> k;     map<pair<int, int>, int> mc;     queue<int> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       q.push(x);     }     int cur = 0;     map<int, int> ans;     while (!q.empty() || !mc.empty()) {       while (mc.size() < k && !q.empty()) {         mc[make_pair(q.front(), q.size())] = 0;         q.pop();       }       vector<pair<int, int>> vp;       int key = per(n, cur);       for (auto& p : mc) {         p.second++;         if (p.second == key) ans[p.first.second] = 1;         if (p.second == p.first.first) vp.emplace_back(p.first);       }       for (auto& p : vp) mc.erase(p), cur++;     }     printf( %d n , ans.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   int ara[200005], dist[200005], ans[200005];   vector<int> even, odd, ad[200005];   bool vis[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, i, j;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ara[i];       if (ara[i] & 1)         odd.push_back(i);       else         even.push_back(i);       if (i - ara[i] >= 1) ad[i - ara[i]].push_back(i);       if (i + ara[i] <= n) ad[i + ara[i]].push_back(i);     }     memset(dist, -1, sizeof dist);     queue<int> q;     for (i = 0; i < (int)even.size(); i++) {       q.push(even[i]);       dist[even[i]] = 0;       vis[even[i]] = true;     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (i = 0; i < (int)ad[u].size(); i++) {         int v = ad[u][i];         if (!vis[v]) {           vis[v] = true;           q.push(v);           dist[v] = dist[u] + 1;           if (ara[v] & 1) ans[v] = dist[v];         }       }     }     memset(vis, false, sizeof vis);     memset(dist, -1, sizeof dist);     for (i = 0; i < (int)odd.size(); i++) {       q.push(odd[i]);       dist[odd[i]] = 0;       vis[odd[i]] = true;     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (i = 0; i < (int)ad[u].size(); i++) {         int v = ad[u][i];         if (!vis[v]) {           vis[v] = true;           q.push(v);           dist[v] = dist[u] + 1;           if (ara[v] % 2 == 0) ans[v] = dist[v];         }       }     }     for (i = 1; i <= n; i++) {       if (!ans[i]) ans[i] = -1;       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50, maxm = 5e3, inf = 1e8;   int n, m, q, k, tot, ter[maxm + 3], cap[maxm + 3], wei[maxm + 3], nxt[maxm + 3],       lnk[maxn + 3], dist[maxn + 3], pre[maxn + 3], f[maxn + 3];   bool in[maxn + 3];   long long g[maxn + 3], h[maxn + 3];   void add(int u, int v, int c, int w) {     ter[++tot] = v, cap[tot] = c, wei[tot] = w, nxt[tot] = lnk[u], lnk[u] = tot;   }   void add_flow(int u, int v, int c, int w) { add(u, v, c, w), add(v, u, 0, -w); }   int rev(int x) { return x & 1 ? x + 1 : x - 1; }   bool spfa() {     fill(dist + 1, dist + n + 1, inf);     fill(pre + 1, pre + n + 1, 0);     queue<int> Q;     Q.push(1), dist[1] = 0, in[1] = true;     while (!Q.empty()) {       int u = Q.front();       Q.pop(), in[u] = false;       for (int i = lnk[u], v, c, w; i; i = nxt[i]) {         v = ter[i], c = cap[i], w = wei[i];         if (c > 0 && dist[v] > dist[u] + w) {           dist[v] = dist[u] + w, pre[v] = i;           if (!in[v]) {             in[v] = true, Q.push(v);           }         }       }     }     return pre[n];   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1, u, v, w; i <= m; i++) {       scanf( %d %d %d , &u, &v, &w);       add_flow(u, v, 1, w);     }     while (spfa()) {       int x = n, t;       while (x != 1) {         t = pre[x];         cap[t]--, cap[rev(t)]++;         x = ter[rev(t)];       }       f[++k] = dist[n];       g[k] = g[k - 1] + f[k];       h[k] = 1ll * k * f[k] - g[k];     }     scanf( %d , &q);     for (int x, t; q-- > 0;) {       scanf( %d , &x);       t = upper_bound(h + 1, h + k + 1, x) - (h + 1);       printf( %.9lf n , 1. * (g[t] + x) / t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long int;   int main() {     lint n;     cin >> n;     vector<lint> v(n);     for (lint i = 0; i < n; i++) {       cin >> v[i];     }     lint val = 2 * accumulate(v.begin(), v.end(), 0ll) / n;     vector<lint> visited(n);     for (lint i = 0; i < n; i++) {       if (visited[i]) {         continue;       }       for (lint j = i + 1; j < n; j++) {         if (visited[j]) {           continue;         }         if (v[i] + v[j] == val) {           visited[i] = 1;           visited[j] = 1;           cout << (i + 1) <<     << (j + 1) << endl;           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int f[55][55][55][55];   string s[100];   bool dfs(int n, int a, int b, int c) {     if (n == 1) return 1;     if (f[n][a][b][c]) return 0;     if (s[c][0] == s[b][0] || s[c][1] == s[b][1])       if (dfs(n - 1, n - 3, a, c)) return 1;     if (n > 3 && (s[c][0] == s[n - 3][0] || s[c][1] == s[n - 3][1]))       if (dfs(n - 1, c, a, b)) return 1;     f[n][a][b][c] = 1;     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> s[i];     bool ans = dfs(n, n - 2, n - 1, n);     if (ans == 0)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = (int)1e4 + 5, N = (int)1e5 + 5;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int n, m, p;   int a[M], b[N];   vector<int> fac, dp;   int fast(int a, int b) {     int re = 1;     while (b) {       if (b & 1) re = (long long)re * a % p;       a = (long long)a * a % p, b >>= 1;     }     return re;   }   int main() {     scanf( %d %d %d , &n, &m, &p);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) scanf( %d , &b[i]);     for (int i = 1; i * i < p; i++)       if ((p - 1) % i == 0) {         fac.push_back(i);         if ((p - 1) / i != i) fac.push_back((p - 1) / i);       }     sort(fac.begin(), fac.end());     int gd = p - 1;     for (int i = 1; i <= m; i++) gd = gcd(gd, b[i]);     dp.resize(fac.size());     for (int i = 1, ab, t; i <= n; i++) {       ab = fast(a[i], gd);       t = fac.size() - 1;       while (fast(ab, (p - 1) / fac[t]) != 1) t--;       dp[t] = (p - 1) / fac[t];     }     long long ans = 0;     for (int i = dp.size() - 1; i >= 0; i--)       if (dp[i]) {         for (int j = dp.size() - 1; j > i; j--)           if (fac[j] % fac[i] == 0) dp[i] -= dp[j];         ans += dp[i];       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kMaxN = 1010;   struct Cell {     int x, y, val;     bool operator<(const Cell &p) const { return val > p.val; }   } cell[kMaxN * kMaxN];   vector<int> vec[kMaxN];   int g[kMaxN][kMaxN];   int n, m;   void init() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         scanf( %d , &cell[i * m + j].val);         cell[i * m + j].x = i;         cell[i * m + j].y = j;       }     }     sort(cell, cell + n * m);   }   void solve() {     for (int i = 0; i < n * m; ++i) {       int j = cell[i].y;       int q = cell[i].x;       for (int l = 0; l < ((int)(vec[j]).size()); ++l) {         int p = vec[j][l];         if (g[p][q]) {           printf( %d n , cell[i].val);           return;         }         g[p][q] = g[q][p] = 1;       }       vec[j].push_back(q);     }   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 5;   long long a[maxn];   long long pre[maxn];   map<long long, long long> mp;   int main() {     int n, l;     scanf( %d%d , &n, &l);     for (int i = 0; i < n; i++) {       scanf( %I64d , &a[i]);       mp[a[i]]++;     }     sort(a, a + n);     long long cnt = unique(a, a + n) - a;     for (int i = 1; i <= cnt; i++) {       pre[i] = pre[i - 1] + mp[a[i - 1]];     }     l *= 8;     long long temp = log(cnt) / log(2);     if ((1 << temp) < cnt) temp++;     if (temp * n <= l) {       printf( 0 n );       return 0;     }     long long sum = l / n;     sum = (1 << sum);     long long ans = -0x3f3f3f3f;     for (int i = 1, j = i + sum; j <= cnt; i++, j++) {       ans = max(ans, pre[j] - pre[i]);     }     printf( %I64d n , n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char x[105];   bool g;   int main() {     scanf( %s , x);     for (int i = 0; x[i]; i++)       if (x[i] ==  a  || x[i] ==  e  || x[i] ==  i  || x[i] ==  o  || x[i] ==  u )         g = 0;       else if (g) {         puts( NO );         return 0;       } else if (x[i] !=  n )         g = 1;     puts(g ?  NO  :  YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool flag = false;   long long n;   long long mat[1000][1000];   bool vis[1000][1000];   long long ans[1000][1000];   bool isSol() {     long long s = 0;     for (int i = 0; i < n; i++) {       s += ans[i][i];     }     long long s2 = 0;     for (int i = 0; i < n; i++) {       s2 += ans[n - i - 1][i];     }     if (s2 != s) return false;     for (int i = 0; i < n; i++) {       s2 = 0;       for (int j = 0; j < n; j++) {         s2 += ans[i][j];       }       if (s2 != s) return false;     }     for (int i = 0; i < n; i++) {       s2 = 0;       for (int j = 0; j < n; j++) {         s2 += ans[j][i];       }       if (s2 != s) return false;     }     return true;   }   void find_sol(long long pos) {     if (flag) return;     if (pos == n * n) {       if (isSol()) flag = true;       return;     }     long long pos_x = pos / n;     long long pos_y = pos % n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (!vis[i][j] && !flag) {           vis[i][j] = true;           ans[pos_x][pos_y] = mat[i][j];           find_sol(pos + 1);           vis[i][j] = false;         }       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> mat[i][j];         vis[i][j] = false;       }     }     find_sol(0);     long long s = 0;     for (int i = 0; i < n; i++) s += ans[i][0];     cout << s << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }     return 0;   }


#include <cstdio>   #include <algorithm>   using namespace std;   #define ADD(x) ((x>=mod)?x-mod:x)   const int mod=1e9+7;   int n,c[110],b[110],sum[110],sum1[110],sumc[110],dp[110][10010],ans,Min,T,x;   int main()   {    scanf( %d ,&n);    for (int i=1;i<=n;i++) scanf( %d ,&c[i]),sumc[i]=sumc[i-1]+c[i];    for (int i=1;i<n;i++) scanf( %d ,&b[i]),sum[i]=sum[i-1]+b[i];    for (int i=1;i<=n;i++) sum1[i]=sum1[i-1]+sum[i-1];    scanf( %d%d ,&T,&x);    dp[0][0]=1;    for (int i=1;i<=n;i++)     for (int j=x*i+sum1[i];j<=sumc[i];j++)      for (int k=min(j,c[i]);k>=0;k--)       dp[i][j]=ADD(dp[i][j]+dp[i-1][j-k]);    for (int i=0;i<=sumc[n];i++) ans=ADD(ans+dp[n][i]);    printf( %d n ,ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int i, int j) {     if (j == 0)       return i;     else       return gcd(j, i % j);   }   template <typename T>   inline T getint() {     T val = 0;     char c;     bool neg = false;     while ((c = getchar()) && !(c >=  0  && c <=  9 )) {       neg |= c ==  - ;     }     do {       val = (val * 10) + c -  0 ;     } while ((c = getchar()) && (c >=  0  && c <=  9 ));     return val * (neg ? -1 : 1);   }   const long long INF = 1e17;   const int Y = 200100;   vector<int> Ed[Y];   int mx;   int ans[Y];   int n, k;   int qw(int l, int r) {     vector<int> q;     for (int j = l; j <= r; ++j) {       for (auto x : Ed[j]) q.push_back(x);     }     sort(q.begin(), q.end());     cout <<  ?   << q.size() <<    ;     for (auto x : q) cout << x <<    ;     cout << endl;     int x;     cin >> x;     return x;   }   void Mrec(int l, int r) {     if (l > r) return;     if (r == l) {       set<int> q;       for (int j = 0; j < n; ++j) {         q.insert(j + 1);       }       for (auto x : Ed[l]) {         q.erase(q.find(x));       }       cout <<  ?   << q.size() <<    ;       for (auto x : q) cout << x <<    ;       cout << endl;       cin >> ans[l];       return;     }     int len = (r - l + 1) / 2;     int mid = l + len - 1;     int r1 = qw(l, mid);     if (r1 == mx) {       for (int j = mid + 1; j <= r; ++j) ans[j] = mx;       if (len == 1 || l == r) {         set<int> q;         for (int j = 0; j < n; ++j) {           q.insert(j + 1);         }         for (auto x : Ed[l]) {           q.erase(q.find(x));         }         cout <<  ?   << q.size() <<    ;         for (auto x : q) cout << x <<    ;         cout << endl;         cin >> ans[l];         return;       } else {         Mrec(l, mid);       }     } else {       for (int j = l; j <= mid; ++j) ans[j] = mx;       ++mid;       if (r == mid || l == r) {         set<int> q;         for (int j = 0; j < n; ++j) {           q.insert(j + 1);         }         for (auto x : Ed[r]) {           q.erase(q.find(x));         }         cout <<  ?   << q.size() <<    ;         for (auto x : q) cout << x <<    ;         cout << endl;         cin >> ans[r];         return;       } else {         Mrec(mid, r);       }     }   }   int32_t main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < k; ++i) ans[i] = 0;       for (int i = 0; i < k; ++i) {         Ed[i].clear();         int tt;         cin >> tt;         for (int j = 0; j < tt; ++j) {           int tmp;           cin >> tmp;           Ed[i].push_back(tmp);         }       }       cout <<  ?   << n;       for (int i = 1; i <= n; ++i) cout <<     << i;       cout << endl;       cin >> mx;       Mrec(0, k - 1);       cout <<  !  ;       for (int i = 0; i < k; ++i) cout << ans[i] <<    ;       cout << endl;       string s;       cin >> s;       if (s ==  Incorrect ) {         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     vector<int> data(n), ans(n);     long long suma = 0;     for (auto &i : data) cin >> i;     for (int i = 0; i < n; ++i) {       vector<int> data1;       data1 = data;       for (int j = i - 1; j >= 0; --j) data1[j] = min(data1[j], data1[j + 1]);       for (int j = i + 1; j < n; ++j) data1[j] = min(data1[j], data1[j - 1]);       long long sum = 0;       for (auto i : data1) sum += i;       if (sum > suma) {         suma = sum;         ans = data1;       }     }     for (auto i : ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};   long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};   class pa3 {    public:     long long x;     long long y, z;     pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}     bool operator<(const pa3& p) const {       if (x != p.x) return x < p.x;       if (y != p.y) return y < p.y;       return z < p.z;     }     bool operator>(const pa3& p) const {       if (x != p.x) return x > p.x;       if (y != p.y) return y > p.y;       return z > p.z;     }     bool operator==(const pa3& p) const {       return x == p.x && y == p.y && z == p.z;     }     bool operator!=(const pa3& p) const {       return !(x == p.x && y == p.y && z == p.z);     }   };   class pa4 {    public:     long long x;     long long y, z, w;     pa4(long long x = 0, long long y = 0, long long z = 0, long long w = 0)         : x(x), y(y), z(z), w(w) {}     bool operator<(const pa4& p) const {       if (x != p.x) return x < p.x;       if (y != p.y) return y < p.y;       if (z != p.z) return z < p.z;       return w < p.w;     }     bool operator>(const pa4& p) const {       if (x != p.x) return x > p.x;       if (y != p.y) return y > p.y;       if (z != p.z) return z > p.z;       return w > p.w;     }     bool operator==(const pa4& p) const {       return x == p.x && y == p.y && z == p.z && w == p.w;     }   };   class pa2 {    public:     long long x, y;     pa2(long long x = 0, long long y = 0) : x(x), y(y) {}     pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }     pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }     bool operator<(const pa2& p) const { return y != p.y ? y < p.y : x < p.x; }     bool operator>(const pa2& p) const { return x != p.x ? x < p.x : y < p.y; }     bool operator==(const pa2& p) const {       return abs(x - p.x) == 0 && abs(y - p.y) == 0;     }     bool operator!=(const pa2& p) const {       return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);     }   };   string itos(long long i) {     ostringstream s;     s << i;     return s.str();   }   long long Gcd(long long v, long long b) {     if (v == 0) return b;     if (b == 0) return v;     if (v > b) return Gcd(b, v);     if (v == b) return b;     if (b % v == 0) return v;     return Gcd(v, b % v);   }   long long mod;   long long extgcd(long long a, long long b, long long& x, long long& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long d = extgcd(b, a % b, y, x);     y -= a / b * x;     return d;   }   pair<long long, long long> operator+(const pair<long long, long long>& l,                                        const pair<long long, long long>& r) {     return {l.first + r.first, l.second + r.second};   }   pair<long long, long long> operator-(const pair<long long, long long>& l,                                        const pair<long long, long long>& r) {     return {l.first - r.first, l.second - r.second};   }   ostream& operator<<(ostream& os, const vector<long long>& VEC) {     for (auto v : VEC) os << v <<    ;     return os;   }   ostream& operator<<(ostream& os, const pair<long long, long long>& PAI) {     os << PAI.first <<   :   << PAI.second;     return os;   }   ostream& operator<<(ostream& os, const pa3& PAI) {     os << PAI.x <<   :   << PAI.y <<   :   << PAI.z;     return os;   }   ostream& operator<<(ostream& os, const pa4& PAI) {     os << PAI.x <<   :   << PAI.y <<   :   << PAI.z <<   :   << PAI.w;     return os;   }   ostream& operator<<(ostream& os,                       const vector<pair<long long, long long> >& VEC) {     for (auto v : VEC) os << v <<    ;     return os;   }   long long beki(long long wa, long long rr, long long warukazu) {     if (rr == 0) return 1 % warukazu;     if (rr == 1) return wa % warukazu;     wa %= warukazu;     if (rr % 2 == 1)       return ((long long)beki(wa, rr - 1, warukazu) * (long long)wa) % warukazu;     long long zx = beki(wa, rr / 2, warukazu);     return (zx * zx) % warukazu;   }   long long pr[1100000];   long long inv[1100000];   long long comb(long long nn, long long rr) {     if (rr < 0 || rr > nn || nn < 0) return 0;     long long r = pr[nn] * inv[rr];     r %= mod;     r *= inv[nn - rr];     r %= mod;     return r;   }   void gya(long long ert) {     pr[0] = 1;     for (long long i = 1; i <= ert; i++) {       pr[i] = ((long long)pr[i - 1] * i) % mod;     }     inv[ert] = beki(pr[ert], mod - 2, mod);     for (long long i = ert - 1; i >= 0; i--) {       inv[i] = (long long)inv[i + 1] * (i + 1) % mod;     }   }   struct seg_rangeupd_getsum {    private:    public:     long long cor = (1 << 18);     long long inff = 1000000007 * 1000000ll;     vector<long long> vec;     vector<long long> lazy;     void shoki1() {       vec.resize(2 * cor + 3, 0);       lazy.resize(2 * cor + 3, inff);     }     void shoki2() {}     long long chien(long long k, long long len) {       if (lazy[k] == inff) return vec[k];       if (k < cor) {         vec[k] = lazy[k] * len;         lazy[2 * k] = lazy[k];         lazy[2 * k + 1] = lazy[k];         lazy[k] = inff;       } else {         vec[k] = lazy[k];         lazy[k] = inff;       }       return vec[k];     }     void clear_chien(long long r) {       if (r == 0) return;       long long f = 31 - __builtin_clz(r);       long long pos = 0;       long long len = cor;       for (long long i = f; i >= 0; i--) {         pos *= 2;         pos += !!(r & (1 << i));         chien(pos, len);         len /= 2;       }     }     void rangeupd(long long a, long long b, long long w) {       a += cor, b += cor;       long long aa = a / (a & (-a)) / 2;       long long bb = b / (b & (-b)) / 2;       long long lenaa = 2 * (a & -a);       long long lenbb = 2 * (b & -b);       clear_chien(aa);       clear_chien(bb);       while (a < b) {         if (a & 1) {           lazy[a] = w;           a++;         }         if (b & 1) {           b--;           lazy[b] = w;         }         a /= 2, b /= 2;       }       while (aa > 0 || bb > 0) {         if (aa > bb) {           vec[aa] = chien(2 * aa, lenaa / 2) + chien(2 * aa + 1, lenaa / 2);           aa /= 2;           lenaa *= 2;         } else if (aa < bb) {           vec[bb] = chien(2 * bb, lenbb / 2) + chien(2 * bb + 1, lenbb / 2);           bb /= 2;           lenbb *= 2;         } else {           vec[aa] = chien(2 * aa, lenaa / 2) + chien(2 * aa + 1, lenaa / 2);           aa /= 2;           lenaa *= 2;           bb = aa, lenbb = aa;         }       }     }     long long getsum(long long a, long long b) {       a += cor, b += cor;       long long aa = a / (a & (-a)) / 2;       long long bb = b / (b & (-b)) / 2;       clear_chien(aa);       clear_chien(bb);       long long ans = 0;       long long len = 1;       while (a < b) {         if (a & 1) {           ans += chien(a, len);           a++;         }         if (b & 1) {           b--;           ans += chien(b, len);         }         a /= 2, b /= 2, len *= 2;       }       return ans;     }     long long lower_bound(long long p, long long x) {       p += cor;       long long ima = 0;       bool fst = 1;       long long len = 1;       while (1) {         while (!(p & 1)) p /= 2, len *= 2;         if (fst) fst = 0, clear_chien(p / 2);         if (ima + chien(p, len) >= x) break;         ima = ima + vec[p];         p++;         if (p == (p & (-p))) return cor;       }       while (1) {         if (p >= cor) return p - cor;         p *= 2;         len /= 2;         if (ima + chien(p, len) < x) {           ima += vec[p];           p++;         }       }     }     long long upper_bound(long long p, long long x) {       p += cor;       long long ima = 0;       bool fst = 1;       long long len = 1;       while (1) {         while (!(p & 1)) p /= 2, len *= 2;         if (fst) fst = 0, clear_chien(p / 2);         if (ima + chien(p, len) > x) break;         ima = ima + vec[p];         p++;         if (p == (p & (-p))) return cor;       }       while (1) {         if (p >= cor) return p - cor;         p *= 2;         len /= 2;         if (ima + chien(p, len) <= x) {           ima += vec[p];           p++;         }       }     }   };   void solve() {     long long n, q, t;     cin >> n >> q >> t;     string s;     cin >> s;     seg_rangeupd_getsum ss;     ss.shoki1();     ss.shoki2();     for (long long i = 0; i < n; i++) {       ss.rangeupd(i, i + 1, s[i] -  a );     }     set<long long> se;     long long dp[11][11] = {};     for (long long i = 0; i < n - 1; i++) {       if (s[i] != s[i + 1]) {         se.insert(i);         dp[s[i] -  a ][s[i + 1] -  a ]++;       }     }     se.insert(1000000007);     while (q--) {       long long e;       cin >> e;       if (e == 1) {         long long l, r;         char c;         cin >> l >> r >> c;         l--;         auto it = se.lower_bound(l - 1);         while (1) {           if (*it >= r) break;           long long mae = ss.getsum(*it, *it + 1);           long long ato = ss.getsum(*it + 1, *it + 2);           dp[mae][ato]--;           it = se.erase(it);         }         ss.rangeupd(l, r, c -  a );         if (l) {           long long mae = ss.getsum(l - 1, l);           long long ato = ss.getsum(l, l + 1);           if (mae != ato) dp[mae][ato]++, se.insert(l - 1);         }         if (r < n) {           long long mae = ss.getsum(r - 1, r);           long long ato = ss.getsum(r, r + 1);           if (mae != ato) dp[mae][ato]++, se.insert(r - 1);         }       } else {         string w;         cin >> w;         long long ans = n;         for (long long i = 0; i < t; i++)           for (long long j = i + 1; j < t; j++) {             ans -= dp[w[i] -  a ][w[j] -  a ];           }         cout << ans << endl;       }     }   }   signed main() {     mod = 1000000007;     cin.tie(0);     ios::sync_with_stdio(false);     long long n = 1;     for (long long i = 0; i < n; i++) solve();     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define sz(x) (int)(x).size()    #define int long long int   #define loop(i,a,b) for(int i=a;i<b;i++)   #define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]   #define vi vector<int>   #define si set<int>   #define pii pair <int, int>   #define sii set<pii>   #define vii vector<pii>   #define mii map <int, int>   #define pb push_back   #define ff first   #define ss second   #define all(aa) aa.begin(), aa.end()   #define rall(a) a.rbegin() , a.rend()   #define read(a,b) int a,b;  cin>>a>>b   #define readt(a,b,c) int a,b,c; cin>>a>>b>>c   #define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;   #define print(v) for(auto x:v) cout<<x<<   ;cout<<endl   #define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<   <<p.second<<endl;   #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)         void solve(int test)   {      int n;cin>>n;     // if(n<=9)     // {     //   cout<<n<<endl;     //   return ;     // }     // if(n<=100)     // {     //  int ans=9;     //  loop(i,10,100)     //  {     //   if(i%10==i/10)     //     ans++;     //  }        //  cout<<ans<<endl;     //  return ;     // }        int cp=n , d=0;     while(cp!=0)     {       d++;       cp/=10;     }        int ans=9*(d-1);     int f=n/pow(10,d-1);     ans+=f;     int cpp=f;     string req;     loop(i,0,d)     req+=to_string(f);        f=stoi(req);     // for(int i=1;i<=d-1;i++)     // {     //   int prev=f;     //   f=f*pow(10,i) ;     //   f+=prev;     // }        //cout<<f<<endl;        if(f>n)     {       ans--;     }        cout<<ans<<endl;   }      int32_t main()   {         #ifndef ONLINE_JUDGE             freopen( input.txt ,  r , stdin);             freopen( op.txt ,  w , stdout);         #endif         faster;         //fact(mod);         int t=1;         cin>>t;         for(int test=1;test<=t;test++)         {           //cout<< Case # <<test<< :  ;             solve(test);         }   }


#include <bits/stdc++.h>   using namespace std;   string st;   vector<long> v;   long r;   int main() {     ios_base::sync_with_stdio(0);     cin >> st;     st +=  + ;     for (int i = 0; i < st.size(); i++) {       if (st[i] ==  + ) {         v.push_back(r);         r = 0;       } else         r = r * 10 + st[i] - 48;     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  + ;       cout << v[i];     }     cout << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 2500;   struct P {     int x, y;     P() {}     P(int x, int y) : x(x), y(y) {}   };   long long operator^(const P& a, const P& b) {     return (long long)a.x * b.y - (long long)a.y * b.x;   }   P operator-(const P& a, const P& b) { return P(a.x - b.x, a.y - b.y); }   bool operator<(const P& a, const P& b) {     bool apos = a.y > 0 || a.y == 0 && a.x > 0;     bool bpos = b.y > 0 || b.y == 0 && b.x > 0;     if (apos != bpos) return apos;     return (a ^ b) > 0;   }   int n;   P p[MAXN];   long long C[MAXN + 1][5 + 1];   P q[2 * (MAXN - 1)];   int nq;   long long solve() {     for (int i = (0); i <= (n); ++i)       for (int j = (0); j <= (5); ++j) C[i][j] = 0;     for (int i = (0); i <= (n); ++i) {       C[i][0] = 1;       for (int j = (1); j <= (min(5, i)); ++j)         C[i][j] = C[i - 1][j - 1] + C[i - 1][j];     }     long long cnttot = C[n][5];     long long cntside = 0;     for (int i = (0); i < (n); ++i) {       nq = 0;       for (int j = (0); j < (n); ++j)         if (j != i) q[nq++] = p[j] - p[i];       sort(q, q + nq);       for (int j = (0); j < (nq); ++j) q[nq + j] = q[j];       int to = 0;       for (int at = (0); at < (nq); ++at) {         to = max(to, at + 1);         while (to - at < nq && (q[at] ^ q[to]) > 0) ++to;         int cur = to - at - 1;         cntside += C[cur][3];       }     }     return 5 * cnttot - cntside;   }   void run() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d%d , &p[i].x, &p[i].y);     printf( %lld n , solve());   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double p[22], f[(1 << 20) + 10], ans[22];   int n, m;   int main() {     int cnt = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lf , &p[i]);       if (p[i] > 1e-7) cnt++;     }     if (cnt <= m) {       for (int i = 1; i <= n; i++)         if (p[i] > 1e-7)           printf( 1  );         else           printf( 0  );       return 0;     }     int ss = (1 << n) - 1;     f[0] = 1;     for (int i = 0; i <= ss; i++) {       cnt = 0;       for (int j = 1; j <= n; j++)         if (i & (1 << (j - 1))) cnt++;       if (cnt > m) continue;       if (cnt == m) {         for (int j = 1; j <= n; j++)           if (i & (1 << (j - 1))) ans[j] += f[i];         continue;       }       double t = 1;       for (int j = 1; j <= n; j++)         if (i & (1 << (j - 1))) t -= p[j];       for (int j = 1; j <= n; j++) {         if (i & (1 << (j - 1))) continue;         f[i + (1 << (j - 1))] += f[i] * p[j] / t;       }     }     for (int i = 1; i <= n; i++) printf( %.7lf  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100002];   int b[100002];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     int ret = 0;     for (int i = n - 1; i >= 0; i--) {       int mx = 1;       for (int j = 1; j * j <= a[i]; j++)         if (a[i] % j == 0) {           mx = max(mx, 1 + b[a[i] / j]);           mx = max(mx, 1 + b[j]);         }       for (int j = 1; j * j <= a[i]; j++)         if (a[i] % j == 0) {           if (j != 1) b[j] = max(b[j], mx);           b[a[i] / j] = max(b[a[i] / j], mx);         }       ret = max(ret, mx);     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int count[2] = {0, 0};     bool all_even = 1;     for (int i = 0; i < n; i++) {       static string s;       cin >> s;       if (static_cast<int>(s.size()) & 1) all_even = 0;       for (const char &c : s) count[c -  0 ]++;     }     if (all_even && (count[0] & 1) && (count[1] & 1))       cout << n - 1;     else       cout << n;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef pair<int,int> PII;   const int maxn=1111111,mod=998244353;   #define MP make_pair   #define PB push_back   #define lson o<<1,l,mid   #define rson o<<1|1,mid+1,r   #define FOR(i,a,b) for(int i=(a);i<=(b);i++)   #define ROF(i,a,b) for(int i=(a);i>=(b);i--)   #define MEM(x,v) memset(x,v,sizeof(x))   inline ll read(){    char ch=getchar();ll x=0,f=0;    while(ch< 0  || ch> 9 ) f|=ch== - ,ch=getchar();    while(ch>= 0  && ch<= 9 ) x=x*10+ch- 0 ,ch=getchar();    return f?-x:x;   }   int n,m,deg[maxn],p[maxn],q[maxn],rem,que[maxn],h,r,el,head[maxn],to[maxn],nxt[maxn];   bool in[maxn];   set<PII,greater<PII> > s;   set<int> nvis,e[maxn];   inline void add(int u,int v){    e[u].insert(v);   }   inline void add2(int u,int v){   // printf( add(%d,%d) n ,u,v);    to[++el]=v;nxt[el]=head[u];head[u]=el;   }   void clear(){    FOR(i,1,n) deg[i]=p[i]=q[i]=head[i]=in[i]=0;    s.clear();    nvis.clear();    FOR(i,1,n) e[i].clear();    FOR(i,1,el) to[i]=nxt[i]=0;    el=0;   }   bool dfs(int u,int f){    int son=0,cnt=0;    for(int i=head[u];i;i=nxt[i]){     int v=to[i];     if(dfs(v,u)) cnt++;     else son=v;    }   // printf( u=%d,cnt=%d n ,u,cnt);    if(cnt){     for(int i=head[u];i;i=nxt[i]){      int v=to[i];      if(!in[v]) continue;      p[v]=rem;      q[v]=--rem;     }     q[u]=rem+cnt;     p[u]=rem--;     return in[u]=false;    }    else if(!f){     assert(son);   //  puts( in );     p[u]=q[u]=rem--;     swap(p[u],p[son]);     return in[u]=false;    }    else return in[u]=true;   }   void bfs(int s){    que[h=r=1]=s;    while(h<=r){     int u=que[h++];     for(set<int>::iterator it=nvis.begin();it!=nvis.end();){      int v=*it;   //   printf( try %d to %d n ,u,v);      if(e[u].find(v)!=e[u].end()){it++;continue;}      set<int>::iterator it1=it++;      nvis.erase(it1);      que[++r]=v;      add2(u,v);     }    }    dfs(s,0);   /* set<int>::iterator it=nvis.begin();    int son=0;    if(!vec[u].empty()){     p[u]=rem;     FOR(i,0,(int)vec[u].size()-1) p[vec[u][i]]=rem-i-1;     FOR(i,0,(int)vec[u].size()-1) q[vec[u][i]]=rem-i;     q[u]=rem-=vec[u].size();     return false;    }    else if(rt){     assert(son);     p[u]=q[u]=rem--;     swap(q[u],q[son]);     return false;    }    else return true;*/   }   void solve(){    n=read();m=read();    FOR(i,1,m){     int u=read(),v=read();     add(u,v);add(v,u);     deg[u]++;deg[v]++;    }    FOR(i,1,n) s.insert(MP(deg[i],i));    rem=n;    while(!s.empty() && s.begin()->first==(int)s.size()-1){     int u=s.begin()->second;     s.erase(s.begin());   //  printf( erase %d n ,u);     p[u]=q[u]=rem--;     for(set<int>::iterator it=e[u].begin();it!=e[u].end();it++){      int v=*it;      s.erase(MP(deg[v],v));      s.insert(MP(--deg[v],v));      e[v].erase(u);     }     e[u].clear();     deg[u]=0;    }    FOR(i,1,n) if(!p[i]) nvis.insert(i);    FOR(i,1,n) if(!p[i]){     nvis.erase(i);     bfs(i);    }    FOR(i,1,n) printf( %d  ,p[i]);    puts(  );    FOR(i,1,n) printf( %d  ,q[i]);    puts(  );    clear();   }   int main(){    int T=read();    while(T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, k, lb, ub, ans = -1;   void init() {     long long l, r;     scanf( %lld%lld%lld%lld , &n, &l, &r, &k);     x = (r >= l ? r - l + 1 : r + n - l + 1) % n;   }   void solve() {     for (long long i = k, j, r; i; i = j) {       j = k / (k / i + 1);       r = k / i;       ub = min(2 * n, i);       lb = max(n, j + 1);       ub = min(ub, min((2 * n + k - 2 * x + 1) / (r + 1), (k - x) / r));       lb = max(lb, (k - 2 * x + r - 1) / r);       if (ub >= lb) ans = max(ans, ub);     }     if (x <= k && k <= x * 2) ans = max(ans, n + min(k - x, x - 1) + n - x + 1);     if (!x && k == n) ans = max(ans, n + 1);     printf( %lld n , ~ans ? ans - n : ans);   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long INFL = 1e18 + 123;   const double PI = atan2(0, -1);   mt19937 tw(960172);   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   int cur_sum, deleted_sum;   vector<tuple<int, int, int>> back, front;   void init() {     cur_sum = 0;     deleted_sum = 0;     back.clear();     front.clear();   }   int get_min_back() {     if (((int)(back).size())) {       return get<2>(back.back());     }     return INF;   }   int get_min_front() {     if (((int)(front).size())) {       return get<2>(front.back());     }     return INF;   }   void add(int val) {     cur_sum += val;     back.push_back({val, cur_sum, min(cur_sum, get_min_back())});   }   void pop() {     assert(((int)(back).size()) || ((int)(front).size()));     if (!((int)(front).size())) {       while (((int)(back).size())) {         int val, sum, tmp;         tie(val, sum, tmp) = back.back();         back.pop_back();         front.push_back({val, sum, min(sum, get_min_front())});       }     }     deleted_sum += get<0>(front.back());     front.pop_back();   }   int get_min() { return min(get_min_front(), get_min_back()) - deleted_sum; }   void solve() {     int n, l;     cin >> n >> l;     vector<int> boys, girls;     for (int i = 0; i < n; ++i) {       int num;       cin >> num;       boys.push_back(num);       boys.push_back(num + l);     }     for (int i = 0; i < n; ++i) {       int num;       cin >> num;       girls.push_back(num - l);       girls.push_back(num);       girls.push_back(num + l);     }     sort(boys.begin(), boys.end());     sort(girls.begin(), girls.end());     int lg = -1, rg = l / 2;     while (rg - lg > 1) {       int mid = (lg + rg) / 2;       init();       bool flag = true;       int c1 = 0, c2 = 0, c3 = 0;       while (girls[c2] - mid <= boys[c1]) {         ++c2;       }       c3 = c2;       while (c3) {         if (boys[0] - girls[c3 - 1] <= mid) {           --c3;         } else {           break;         }       }       int c0 = c2;       for (int i = 0; i < n; ++i) {         while (girls[c3] < boys[i] - mid) {           ++c3;         }         while (girls[c0] - mid <= boys[i]) {           ++c0;         }         c2 = max(c2, c0);         while (true) {           if (girls[c2] - mid <= boys[c1]) {             if (c2 == c3 + n) {               break;             }             add(1);             ++c2;           } else {             if (boys[c1] + mid >= boys[i] + l - mid) {               break;             }             add(-1);             ++c1;           }         }         if (c0 - c3 + get_min() < 0) {           flag = false;           break;         }         if (i == n - 1) {           break;         }         int tmp = deleted_sum;         pop();         --tmp;         assert(tmp == deleted_sum);         while ((((int)(front).size()) || ((int)(back).size())) &&                girls[c0] - mid <= boys[i + 1]) {           pop();           ++tmp;           ++c0;         }         assert(tmp == deleted_sum);       }       if (flag) {         rg = mid;       } else {         lg = mid;       }     }     cout << rg <<   n ;   }   int main() {     cerr << fixed << setprecision(15);     cout << fixed << setprecision(15);     ios::sync_with_stdio(false);     int tests = 1;     for (int it = 1; it <= tests; ++it) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e9;   const int M = 1e9;   int ix, iy, fx, fy;   map<pair<int, int>, int> pres;   map<pair<int, int>, int> dist;   map<pair<int, int>, bool> vis;   int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};   int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};   bool check(int x, int y) {     if (x >= 1 && x <= 1e9 && y >= 1 && y <= 1e9) {       if (pres[make_pair(x, y)]) return true;       return false;     }     return false;   }   void bfs(int x, int y) {     queue<pair<int, int> > q;     pair<int, int> tmp;     q.push(make_pair(x, y));     while (q.size() > 0) {       tmp = q.front();       q.pop();       for (int i = 0; i < 9; ++i) {         int x1 = tmp.first + dx[i];         int y1 = tmp.second + dy[i];         if (check(x1, y1) && vis[make_pair(x1, y1)] == 0) {           vis[make_pair(x1, y1)] = 1;           dist[make_pair(x1, y1)] = dist[tmp] + 1;           q.push(make_pair(x1, y1));         }       }     }   }   int main() {     cin >> ix >> iy >> fx >> fy;     int Q;     cin >> Q;     int x, y, z;     for (int q = 1; q <= Q; ++q) {       scanf( %d%d%d , &x, &y, &z);       for (int i = y; i <= z; ++i) {         pres[make_pair(x, i)] = 1;       }     }     dist[make_pair(ix, iy)] = 0;     dist[make_pair(fx, fy)] = 1e9;     vis[make_pair(ix, iy)] = 1;     bfs(ix, iy);     int res = dist[make_pair(fx, fy)];     if (res >= 1e9) res = -1;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     double n, m;     char ch;     cin >> n >> ch >> m;     if (n >= 12) n -= 12;     double ans1, ans2;     ans2 = 6 * m;     ans1 = n * 30 + 0.5 * m;     cout << ans1 <<     << ans2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long getInt() {     long long ret;     char tmpc;     bool sign = 0;     while (tmpc = getchar(), !isdigit(tmpc)) sign = (tmpc ==  - );     ret = tmpc -  0 ;     while (tmpc = getchar(), isdigit(tmpc)) ret = ret * 10 + tmpc -  0 ;     if (sign) ret *= -1;     return ret;   }   const int mx = 1e5 + 10;   int n, ans, dp[2][mx];   int main() {     n = getInt();     vector<int> in(n + 2);     for (int i = 1; i <= n; i++) {       in[i] = getInt();       dp[0][i] = min(in[i], dp[0][i - 1] + 1);     }     for (int i = n; i >= 1; i--) {       dp[1][i] = min(in[i], dp[1][i + 1] + 1);       ans = max(ans, min(dp[0][i], dp[1][i]));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, f, a, b;     vector<pair<long long int, long long int> > v;     cin >> n >> f;     int i;     for (i = 0; i < n; i++) {       cin >> a >> b;       v.push_back(make_pair(a, b));     }     long long int ans = 0;     vector<long long int> t;     for (i = 0; i < n; i++) {       ans = ans + min(v[i].first, v[i].second);       long long int mins =           min(v[i].first * 2, v[i].second) - min(v[i].first, v[i].second);       t.push_back(mins);     }     sort(t.begin(), t.end());     for (i = n - 1; i >= 0; i--) {       if (t[i] > 0 && f != 0) {         ans = ans + t[i];         f--;       }       if (f == 0) break;     }     cout << ans;   }


#include <bits/stdc++.h>   using ll = long long;   int n, a, v[10005];   ll d[1000005], ans;   char s[10005];   int main() {     scanf( %d , &a);     scanf( %s , s + 1);     n = std::strlen(s + 1);     int lim = n * 10;     for (int i = 1; i <= n; ++i) v[i] = v[i - 1] + s[i] -  0 ;     for (int l = 1; l <= n; ++l)       for (int r = l; r <= n; ++r) {         d[v[r] - v[l - 1]]++;       }     if (a == 0) {       ans = d[0] * (ll)n * (n + 1) - d[0] * d[0];     } else {       for (int i = 1; i * i <= a; ++i) {         if (a % i) continue;         int j = a / i;         if (i <= lim && j <= lim) ans += d[i] * d[j] * (1 + (i != j));       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long int MOD = 1e9 + 7;   const long long int INV2 = 500000004;   int A[N][4];   int main(int argc, char const *argv[]) {     cin.sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int v = 1;     for (int i = 1; i <= n; i++) {       A[i][0] = v++;       A[i][3] = v++;     }     for (int i = 1; i <= n; i++) {       A[i][1] = v++;       A[i][2] = v++;     }     for (int i = 1; i <= n; i++) {       if (A[i][1] <= m) cout << A[i][1] <<    ;       if (A[i][0] <= m) cout << A[i][0] <<    ;       if (A[i][2] <= m) cout << A[i][2] <<    ;       if (A[i][3] <= m) cout << A[i][3] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, const string& delim =    ) {     vector<string> res;     string t;     for (int i = 0; i != s.size(); i++) {       if (delim.find(s[i]) != string::npos) {         if (!t.empty()) {           res.push_back(t);           t =   ;         }       } else {         t += s[i];       }     }     if (!t.empty()) {       res.push_back(t);     }     return res;   }   vector<int> splitInt(const string& s, const string& delim =    ) {     vector<string> tok = split(s, delim);     vector<int> res;     for (int i = 0; i != tok.size(); i++) res.push_back(atoi(tok[i].c_str()));     return res;   }   template <typename T>   void print(T a) {     cerr << a;   }   static void print(long long a) { cerr << a <<  L ; }   static void print(string a) { cerr <<     << a <<    ; }   template <typename T>   void print(vector<T> a) {     cerr <<  { ;     for (int i = 0; i != a.size(); i++) {       if (i != 0) cerr <<  ,  ;       print(a[i]);     }     cerr <<  }  << endl;   }   int main() {     int n, m;     while (cin >> n >> m) {       int res = 0;       if (n <= 1 || m <= 1) res = m * n;       if (n == 2 || m == 2) {         int x = max(m, n);         res = max(res, x / 4 * 4 + min((x % 4) * 2, 4));       }       int x = m * n / 2;       int y = m * n - x;       res = max(max(res, x), y);       res = min(res, m * n);       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double s, a, b, c;   int main() {     cin >> s >> a >> b >> c;     if (a + b + c == 0) {       cout << 0 <<     << 0 <<     << 0 << endl;       return 0;     }     long double x = s * a / (a + b + c);     long double y = s * b / (a + b + c);     long double z = s * c / (a + b + c);     printf( %.10lf %.10lf %.10lf n , (double)x, (double)y, (double)z);     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef unsigned long long ll;   typedef long double ld;   typedef vector<ll> vl;   typedef vector<int> vi;   typedef vector<vector<int>> vvi;   typedef vector<vector<ll>> vvl;   typedef vector<ll, vector<ll>> vll;   #define ln   n    #define mp make_pair   #define pb push_back   #define st first   #define nd second   #define all(x) (x).begin(), (x).end()   #define sz(x) ((ll)(x).size())      void solve()   {     ll n;     cin >> n;        if (n % 2 != 0)     {       cout <<  NO  << ln;       return;     }        ll j = n;        while (j % 2 == 0)     {       j = j / 2;     }        if (j == 1)     {       cout <<  YES  << ln;       return;     }        ll sq = sqrt(j);     if (sq * sq == j)     {       cout <<  YES  << ln;       return;     }        cout <<  NO  << ln;   }      int main()   {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);        int test;     cin >> test;     for (int i = 1; i <= test; i++)       solve();        return 0;   }