#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ar[110];     while (cin >> n) {       for (int i = 0; i < n; i++) {         cin >> ar[i];       }       if ((n % 2 == 1) && (ar[0] % 2 == 1) && (ar[n - 1] % 2 == 1))         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   const double inf = 1e19;   const double eps = 1e-9;   int ch[600050][2];   double K[600050], B[600050], L[600050], R[600050];   double TK[600050], TB[600050], TX[600050];   int fa[600050];   double x[300050], y[300050];   double q, a, b;   int n, tot, root;   inline int dir(int x) { return x == ch[fa[x]][1]; }   inline void mutate(int x, double tk, double tb, double tx) {     if (x >= 3) {       L[x] += tx;       R[x] += tx;       B[x] += tb - K[x] * tx;       K[x] += tk;     }     if (x) {       TX[x] += tx;       TB[x] += tb - TK[x] * tx;       TK[x] += tk;     }   }   inline void release(int x) {     mutate(ch[x][0], TK[x], TB[x], TX[x]);     mutate(ch[x][1], TK[x], TB[x], TX[x]);     TK[x] = 0;     TB[x] = 0;     TX[x] = 0;   }   inline void rotate(int x) {     int y, z, a, b, c;     y = fa[x];     z = fa[y];     b = dir(x);     a = ch[x][!b];     if (z) {       c = dir(y);       ch[z][c] = x;     } else       root = x;     fa[x] = z;     fa[y] = x;     ch[x][!b] = y;     ch[y][b] = a;     if (a) fa[a] = y;   }   void splay(int x, int i) {     int y, z, b, c;     while (fa[x] != i) {       y = fa[x];       z = fa[y];       if (z == i) {         release(y);         release(x);         rotate(x);       } else {         b = dir(x);         c = dir(y);         release(z);         release(y);         release(x);         if (b ^ c) {           rotate(x);           rotate(x);         } else {           rotate(y);           rotate(x);         }       }     }     release(x);   }   inline void newnode(int f, int d, double k, double b, double l, double r) {     tot++;     ch[tot][0] = 0;     ch[tot][1] = 0;     fa[tot] = f;     if (f)       ch[f][d] = tot;     else       root = tot;     K[tot] = k;     B[tot] = b;     L[tot] = l;     R[tot] = r;     TK[tot] = 0;     TB[tot] = 0;     TX[tot] = 0;   }   int find_minmax(int i, int d) {     while (ch[i][d]) {       release(i);       i = ch[i][d];     }     return i;   }   inline double calc(int i, double x) { return K[i] * x + B[i]; }   int find(int x) {     int y;     if (x < 3) return 0;     release(x);     if (K[x] * R[x] + B[x] >= 0) {       y = find(ch[x][0]);       if (y)         return y;       else         return x;     }     return find(ch[x][1]);   }   int main() {     double ans;     int i, X, Y;     scanf( %d%lf%lf%lf , &n, &q, &a, &b);     for (i = 1; i <= n; i++) scanf( %lf , &x[i]);     tot = 0;     newnode(0, 0, 0, -inf, -inf, -inf);     newnode(1, 1, 0, inf, inf, inf);     newnode(2, 0, 2, -x[1] * 2, 1, q - (n - 1) * a);     for (i = 1; i <= n; i++) {       splay(1, 0);       splay(2, 1);       X = ch[2][0];       Y = find_minmax(X, 1);       if (K[Y] * R[Y] + B[Y] < 0)         y[i] = R[Y];       else {         Y = find(X);         if (K[Y] * L[Y] + B[Y] > 0)           y[i] = L[Y];         else           y[i] = -B[Y] / K[Y];       }       if (i < n) {         if (b - a > eps) {           splay(Y, 0);           if (y[i] - L[Y] < eps) {             X = find_minmax(ch[Y][0], 1);             splay(X, Y);             newnode(X, 1, 0, 0, y[i] + a, y[i] + b);           } else if (R[Y] - y[i] < eps) {             X = find_minmax(ch[Y][1], 0);             splay(X, Y);             newnode(X, 0, 0, 0, y[i] + a, y[i] + b);           } else {             X = find_minmax(ch[Y][1], 0);             splay(X, Y);             newnode(X, 0, K[Y], B[Y], y[i], R[Y]);             R[Y] = y[i];             newnode(tot, 0, 0, 0, y[i] + a, y[i] + b);           }           splay(tot, 0);           mutate(ch[tot][0], 0, 0, a);           mutate(ch[tot][1], 0, 0, b);         } else           mutate(root, 0, 0, a);         mutate(root, 2, -x[i + 1] * 2, 0);         splay(2, 0);         Y = find_minmax(ch[2][0], 1);         while (L[Y] >= q - (n - i - 1) * a) {           splay(Y, 2);           X = ch[Y][0];           ch[2][0] = X;           fa[X] = 2;           Y = find_minmax(ch[2][0], 1);         }         if (R[Y] > q - (n - i - 1) * a) R[Y] = q - (n - i - 1) * a;       }     }     for (i = n - 1; i >= 1; i--)       if (y[i + 1] - y[i] < a)         y[i] = y[i + 1] - a;       else if (y[i + 1] - y[i] > b)         y[i] = y[i + 1] - b;     ans = 0;     for (i = 1; i <= n; i++) {       printf( %.7lf  , y[i]);       ans += (y[i] - x[i]) * (y[i] - x[i]);     }     printf(  n%.7lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nod = 1e9 + 7;   const int modulo = (119 << 23) + 1;   const int maxn = 3e5 + 1;   int n, m;   vector<int> a(maxn);   int test() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     int l = 0, r = m;     while (l < r) {       bool flag = false;       int mid = (l + r) / 2;       int now = 0;       for (int i = 0; i < n; i++) {         int x = a[i], y = a[i] + mid;         if (x <= now && y >= now || x <= now + m && y >= now + m) continue;         if (now >= x) {           flag = true;           break;         }         now = a[i];       }       if (flag)         l = mid + 1;       else         r = mid;     }     cout << l;     return 0;   }   int solve(int tmp[], int a, int b, int n) {     int cnt = 0;     int div = tmp[b] - tmp[a];     int now = 2;     for (int i = b + 1; i < n; i++) {       if (tmp[i] == tmp[a] + div * now) {         cnt++, now++;       }     }     return cnt;   }   static int search(int num, int b[], int n) {     for (int i = 0; i < n; i++) {       if (b[i] == num) {         i + 1;         return 0;       }     }     return 1;   }   int donot() { return 0; }   int hack() { return 1; }   string me() {     const char* s =  do not hack me ;     return s;   }   class havenoidea {     int ameaninglessnum = 49935;     bool iamanaduit = 1;       public:     int iwillsolvefiveproblems(int x) { return x; }   };   int main() {     if (hack()) donot();     int tmp[6] = {1, 1, 4, 5, 1, 4};     solve(tmp, search(114514, tmp, 6), 1, 6);     int a, b, c, d;     havenoidea fuck;     fuck.iwillsolvefiveproblems(hack());     test();     if (me() ==  do not fack me )       if (me() ==  do not hack me ) hack() == donot();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[200000], b[200000];   int kmp[200000];   int n, m, i, j, first, curr, val[200000], l;   int dyn[200000];   int sum[200000];   int MOD = 1000000007;   int main(void) {     cin >> b >> a;     n = strlen(a);     m = strlen(b);     kmp[0] = 1;     if (n == 1) {       for (i = 0; i <= m - 1; i++) {         if (a[0] == b[i]) {           l++;           val[l] = i;         }       }     } else {       for (i = 1; i <= n - 1; i++) {         j = kmp[i - 1];         while (j < i && a[i] != a[i - j]) j += kmp[i - 1 - j];         if (j == i) {           if (a[i] == a[0])             kmp[i] = i;           else             kmp[i] = i + 1;         } else           kmp[i] = j;       }       if (a[0] == b[0]) {         first = 0;       } else {         first = 1;       }       for (i = 1; i <= m - 1; i++) {         while (first < i && b[i] != a[i - first]) first += kmp[i - 1 - first];         if (first == i) {           if (b[i] == a[0])             first = i;           else             first = i + 1;         }         if (i - first == n - 1) {           l++;           val[l] = first;           first += kmp[n - 1];         }       }     }     val[0] = -1;     dyn[m] = 0;     sum[m] = 1;     for (i = m - 1; i >= 0; i--) {       while (l > 1 && val[l - 1] >= i) l--;       if (val[l] >= i) {         dyn[i] = dyn[i + 1] + sum[val[l] + n];         if (dyn[i] >= MOD) dyn[i] -= MOD;         sum[i] = sum[i + 1] + dyn[i] + 1;         if (sum[i] >= MOD) sum[i] -= MOD;       } else {         dyn[i] = 0;         sum[i] = sum[i + 1] + 1;       }     }     cout << dyn[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9, MOD = INF + 7;   const int N = 1e5 + 5;   int n, a[N], nxt[N], lucky[N];   struct Node {     int mn = INF, cnt = 0, idx = -1, lazy = 0;   } seg[4 * N];   int doLuck(int i, int x) {     if (x > 1e4) return i;     if (x) lucky[i] = x, i++;     i = doLuck(i, 10 * x + 4);     return doLuck(i, 10 * x + 7);   }   void apply(int id, int x) {     seg[id].mn += x;     seg[id].lazy += x;   }   void shift(int id) {     if (seg[id].lazy == 0) return;     apply(2 * id, seg[id].lazy);     apply(2 * id + 1, seg[id].lazy);     seg[id].lazy = 0;   }   Node merge(const Node &x, const Node &y) {     Node z;     z.mn = min(x.mn, y.mn);     if (z.mn == y.mn) z.cnt += y.cnt, z.idx = y.idx;     if (z.mn == x.mn) z.cnt += x.cnt, z.idx = x.idx;     return z;   }   void build(int id = 1, int s = 0, int e = n) {     if (e - s < 2) {       int d = lucky[0] - a[s];       seg[id].mn = d;       seg[id].cnt = 1;       seg[id].idx = s;       return;     }     int md = (s + e) / 2;     build(2 * id, s, md);     build(2 * id + 1, md, e);     seg[id] = merge(seg[2 * id], seg[2 * id + 1]);   }   void update(int l, int r, int x, int id = 1, int s = 0, int e = n) {     if (l >= e || s >= r) return;     if (l <= s && e <= r) {       apply(id, x);       return;     }     shift(id);     int md = (s + e) / 2;     update(l, r, x, 2 * id, s, md);     update(l, r, x, 2 * id + 1, md, e);     seg[id] = merge(seg[2 * id], seg[2 * id + 1]);   }   Node get(int l, int r, int id = 1, int s = 0, int e = n) {     if (l >= e || s >= r) return Node();     if (l <= s && e <= r) return seg[id];     shift(id);     int md = (s + e) / 2;     return merge(get(l, r, 2 * id, s, md), get(l, r, 2 * id + 1, md, e));   }   void recheck() {     if (seg[1].mn >= 0) return;     int x = seg[1].idx;     update(x, x + 1, lucky[nxt[x] + 1] - lucky[nxt[x]]);     nxt[x]++;     recheck();   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int m = doLuck(0, 0);     sort(lucky, lucky + m);     lucky[m] = INF;     int q;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     build();     while (q--) {       recheck();       string s;       cin >> s;       int l, r;       cin >> l >> r;       l--;       if (s ==  add ) {         int d;         cin >> d;         update(l, r, -d);       } else {         Node x = get(l, r);         cout << (x.mn == 0) * x.cnt <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long qpow(long long x, long long y) {     long long ret = 1;     while (y) {       if (y & 1) ret = ret * x % MOD;       y >>= 1;       x = x * x % MOD;     }     return ret % MOD;   }   int main() {     long long n, sum = 0, C = 1;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       C = C * (n - i + 1) % MOD * qpow(i, MOD - 2) % MOD;       if (i & 1)         sum = (sum + C * qpow(3, i) % MOD * qpow(3, n * (n - i))) % MOD;       else         sum = ((sum - C * qpow(3, i) % MOD * qpow(3, n * (n - i))) % MOD + MOD) %               MOD;     }     sum = sum * 2 % MOD;     C = 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (i) C = C * (n - i + 1) % MOD * qpow(i, MOD - 2) % MOD;       long long tmp = qpow(((1 - qpow(3, i)) % MOD + MOD) % MOD, n);       if (n & 1)         tmp = (tmp + qpow(3, i * n)) % MOD;       else         tmp = (tmp - qpow(3, i * n) + MOD) % MOD;       if (i & 1)         ans = (ans + tmp * C) % MOD;       else         ans = ((ans - tmp * C) % MOD + MOD) % MOD;     }     cout << (sum + ans * 3) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mp[200005];   int a[200005];   int n;   int main() {     int y, T, n, m, i, t, j, k, x;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x);       mp[x] = i + 1;     }     for (i = 0; i < n; i++) {       scanf( %d , &x);       a[i] = mp[x];     }     int c = 1;     int ans = 0;     for (i = 0; i < n; i++) {       if (a[i] == c) {         c++;         ans++;       }     }     printf( %d n , n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void equalse(int arr[], int n) {     int m = 0, c = 0;     for (int i = 0; i < n; i += 2) {       if (arr[i] > arr[i + 1]) m++;       if (arr[i] < arr[i + 1]) c++;     }     if (c > m) cout <<  Chris ;     if (m > c) cout <<  Mishka ;     if (m == c) cout <<  Friendship is magic!^^ ;   }   void input(int arr[], int n) {     for (int i = 0; i < n; i++) cin >> arr[i];   }   int main() {     int n;     cin >> n;     n *= 2;     int arr[n];     input(arr, n);     equalse(arr, n);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, i, j;     cin >> n;     int x[n], y[n];     for (i = 0; i < n; ++i) {       cin >> x[i] >> y[i];     }     long long int c1 = 0, c2 = 0;     std::map<pair<double, double>, int> d;     std::map<double, int> k, pa;     for (i = 0; i < n - 1; ++i) {       for (j = i + 1; j < n; ++j) {         double p, c;         if (x[i] != x[j]) {           p = (y[j] - y[i]) * 1.000 / (x[j] - x[i]);           c = (x[j] * y[i] - x[i] * y[j]) * 1.000 / (x[j] - x[i]);           if (!d[make_pair(p, c)]) {             d[make_pair(p, c)]++;             c1++;             pa[p]++;           }         } else {           if (!k[x[i]]) {             k[x[i]]++;             c2++;           }         }       }     }     long long int ans = 0;     map<double, int>::iterator it;     for (it = pa.begin(); it != pa.end(); ++it) {       ans += (c1 - (it->second)) * (it->second);     }     ans = ans / 2;     for (it = pa.begin(); it != pa.end(); ++it) {       ans += c2 * (it->second);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> f;   long long n, mm, ret, cur;   long long a[200005], sum[200005];   long long calc(long long m) {     f.clear();     ret = cur = 0;     for (long long i = 0; i < n; i++) {       sum[i + 1] = sum[i] + (a[i] < m ? -1 : 1);       f[sum[i + 1]]++;     }     for (auto it : f)       if (it.first > 0) cur += it.second;     for (long long i = 0; i < n; i++) {       ret += cur;       f[sum[i + 1]]--;       if (sum[i + 1] > sum[i]) cur--;       if (sum[i + 1] > sum[i])         cur -= f[sum[i + 1]];       else         cur += f[sum[i]];     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     vector<long long> v;     cin >> n >> mm;     for (long long i = 0; i < n; i++) cin >> a[i];     cout << calc(mm) - calc(mm + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m;     scanf( %d:%d , &h, &m);     int tmp = 0;     int htmp = h;     tmp = h % 10;     tmp = tmp * 10;     tmp = tmp + h / 10;     if (tmp >= m && tmp < 60)       printf( %d n , tmp - m);     else {       h++;       while (true) {         tmp = 0;         tmp = h % 10;         tmp = tmp * 10;         tmp = tmp + h / 10;         if (tmp < 60) break;         h++;       }       tmp = (h - htmp - 1) * 60 + tmp + (60 - m);       if (h == 24) {         tmp = 0;         printf( %d n , 60 - m);       } else         printf( %d n , tmp);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 3e5 + 10;   const long long INF = 1e18;   const long long M = 1e6 + 10;   int main() {     int n, i, j, k, l, p, q;     string s;     cin >> n >> s;     set<char> a;     char st[3] = { R ,  G ,  B };     for (i = 0; i < n; i++) a.insert(s[i]);     if (a.size() == 1) {       cout << *a.begin();       return 0;     }     if (n == 2) {       if (s[i] == s[i + 1])         cout << s[i];       else {         for (i = 0; i < 3; i++) {           if (a.find(st[i]) == a.end()) cout << st[i];         }       }     } else {       if (a.size() == 3)         cout <<  BGR ;       else {         char ch;         string s2 =   ;         for (i = 0; i < 3; i++) {           if (a.find(st[i]) == a.end()) ch = st[i];         }         for (i = 0; i < 3; i++) {           l = 0;           for (j = 0; j < n; j++) {             if (s[j] == st[i]) l++;           }           if (l == 1) {             s2 += ch;             s2 += st[i];             sort(s2.begin(), s2.end());             cout << s2;             break;           }         }         if (l != 1) cout <<  BGR ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void _IOS() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);   }   long long a[500009], b[500009];   long long n, m, k;   map<long long, bool> pg;   long long dp[100009][3];   int main() {     _IOS();     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       int i = n - 2;       while (i >= 0 && k--) {         a[n - 1] += a[i];         a[i] = 0;         i--;       }       long long mn = (long long)1e10, mx = 0;       for (int i = 0; i < n; i++) {         mn = min(a[i], mn);         mx = max(a[i], mx);       }       cout << abs(mx - mn) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int len, S, T;   bool o[N * 40][15];   char str[N];   long long n, Ans;   struct matrix {     long long f[4][4];     matrix() { memset(f, 63, sizeof(f)); }   } Trans, bin[70], X;   void cmin(long long& x, long long y) { x = x < y ? x : y; }   matrix operator*(matrix a, matrix b) {     matrix c;     for (int i = 0; i < 4; ++i)       for (int j = 0; j < 4; ++j)         for (int k = 0; k < 4; ++k) cmin(c.f[i][j], a.f[i][k] + b.f[k][j]);     return c;   }   int bfs() {     queue<int> q, d;     q.push(S), d.push(1);     while (!q.empty()) {       int u = q.front(), dis = d.front();       q.pop(), d.pop();       if (!o[u * 4 + T][dis + 1]) return dis + 1;       for (int i = 0; i < 4; ++i) {         int v = u * 4 + i;         q.push(v), d.push(dis + 1);       }     }     return 233;   }   int main() {     scanf( %lld , &n);     scanf( %s , str + 1);     len = strlen(str + 1);     for (int i = 1; i <= len; ++i)       for (int k = 1, tp = 0; i + k - 1 <= len && k <= 10; ++k)         tp = tp * 4 + str[i + k - 1] -  A , o[tp][k] = 1;     for (int i = 0; i < 4; ++i)       for (int j = 0; j < 4; ++j) S = i, T = j, Trans.f[i][j] = bfs() - 1;     bin[0] = Trans;     for (int i = 1; i < 62; ++i) bin[i] = bin[i - 1] * bin[i - 1];     memset(X.f, 0, sizeof(X.f));     for (int i = 61; ~i; --i) {       matrix tmp = X * bin[i];       long long mn = 2e18;       for (int j = 0; j < 4; ++j)         for (int k = 0; k < 4; ++k) cmin(mn, tmp.f[j][k]);       if (mn < n) X = tmp, Ans += 1ll << i;     }     ++Ans;     printf( %lld , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long q, t, v, u, w;     map<long long, long long> cost;     cin >> q;     while (q--) {       cin >> t;       if (t == 1) {         cin >> v >> u >> w;         while (v != u) {           while (u > v) {             cost[u] += w;             u >>= 1;           }           while (v > u) {             cost[v] += w;             v >>= 1;           }         }       } else {         cin >> v >> u;         long long res = 0;         while (v != u) {           while (u > v) {             res += cost[u];             u >>= 1;           }           while (v > u) {             res += cost[v];             v >>= 1;           }         }         cout << res << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long LINF = 1e17;   const double DINF = numeric_limits<double>::max();   const int ITER = 300;   const int MOD = 1e9 + 7;   const double EPS = 1e-10;   const int MAXN = 1e5 + 10;   int n, m;   vector<pair<int, int> > v;   void solve() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int q, w;       cin >> q >> w;       v.push_back({w, q});     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long ans = 0;     for (int i = 0; i < v.size(); i++) {       long long cnt = i + 1;       long long need =           (cnt & 1) ? cnt * (cnt - 1) / 2 : cnt * (cnt - 1) / 2 + cnt / 2 - 1;       if (need + 1 <= n) {         ans += v[i].first;       }     }     cout << ans << endl;   }   int main() {     cout << setprecision(12) << fixed;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   int n, root = 0;   vector<vector<int>> adj;   vector<int> d;   void dfs() {     d.assign(n, INF);     d[root] = 0;     queue<int> q;     q.push(root);     while (!q.empty()) {       int cur = q.front();       q.pop();       for (auto nxt : adj[cur])         if (d[nxt] == INF) {           d[nxt] = 1 + d[cur];           q.push(nxt);         }     }   }   int main() {     cin >> n;     adj.resize(n);     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p -= 1;       adj[i].push_back(p);       adj[p].push_back(i);     }     dfs();     vector<int> cnt(n, 0);     for (int i = 0; i < n; i++) cnt[d[i]] += 1;     int res = 0;     for (int i = 0; i < n; i++) res += (cnt[i] & 1);     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h;     while (~scanf( %d%d , &n, &h)) {       for (int i = 1; i < n; i++) {         printf( %f  , h * (sqrt((double)i / n)));       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, dx[]{-1, 0, 0, 1}, dy[]{0, -1, 1, 0};   vector<string> tab;   vector<vector<int>> dist;   priority_queue<pair<int, pair<int, int>>> PQ;   int dijkstra(int x, int y) {     dist.assign(n, vector<int>(m, INT_MAX / 2));     dist[x][y] = 1;     PQ.push({0, {x, y}});     while (!PQ.empty()) {       int d = -PQ.top().first;       x = PQ.top().second.first;       y = PQ.top().second.second;       PQ.pop();       if (d > dist[x][y]) continue;       for (int i = 0; i < 4; i++) {         int x2 = x + dx[i], y2 = y + dy[i];         if (x2 < 0 or x2 >= n or y2 < 0 or y2 >= m) continue;         d = dist[x][y] + (tab[x][y] != tab[x2][y2]);         if (dist[x2][y2] > d) {           dist[x2][y2] = d;           PQ.push({-d, {x2, y2}});         }       }     }     int maxi = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (tab[i][j] ==  B ) maxi = max(maxi, dist[i][j]);     return maxi;   }   int main() {     cin >> n >> m;     tab.resize(n);     for (int i = 0; i < n; i++) cin >> tab[i];     int ans = INT_MAX;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) ans = min(ans, dijkstra(i, j));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   bool a[N][N][4];   int w, h, n, c[N][N], now;   vector<int> ans;   int dfs(int x, int y) {     c[x][y] = now;     int res = 1;     for (int d = 0; d < 4; ++d)       if (a[x][y][d]) {         int nx = x + dx[d], ny = y + dy[d];         if (!c[nx][ny]) res += dfs(nx, ny);       }     return res;   }   int main() {     scanf( %d%d%d , &w, &h, &n);     for (int i = 0; i < w; ++i) {       for (int j = 0; j < h; ++j) {         for (int d = 0; d < 4; ++d) {           int ni = i + dx[d], nj = j + dy[d];           a[i][j][d] = ni >= 0 && ni < w && nj >= 0 && nj < h;         }       }     }     for (int i = 0; i < n; ++i) {       int x1, x2, y1, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 == x2) {         for (int y = min(y1, y2); y < max(y1, y2); ++y) {           a[x1 - 1][y][1] = false;           a[x1][y][3] = false;         }       } else {         for (int x = min(x1, x2); x < max(x1, x2); ++x) {           a[x][y1 - 1][0] = false;           a[x][y1][2] = false;         }       }     }     for (int i = 0; i < w; ++i) {       for (int j = 0; j < h; ++j) {         if (!c[i][j]) {           ++now;           ans.push_back(dfs(i, j));         }       }     }     sort(ans.begin(), ans.end());     int m = ans.size();     for (int i = 0; i < m; ++i) {       printf( %d%s , ans[i], i + 1 == m ?   n  :    );     }   }


#include <bits/stdc++.h>   using namespace std;   double ans = 1;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     if (k >= m)       printf( 1 n );     else if (n + k < m)       printf( 0 n );     else {       for (int i = 1; i <= k + 1; i++) ans = ans * (m - i + 1) / (n + i);       ans = 1.0 - ans;       printf( %.6lf , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> M[400004];   vector<long long> Z[400004];   map<long long, long long> MA;   map<long long, long long> AM;   long long MAer;   bool cmp(long long& a, long long& b) { return a > b; }   long long xa[200002], xb[200002];   signed main() {     long long n, a, b;     cin >> n;     long long maxx = 0, maxi = 0;     for (long long i = 1; i <= n; i++) {       cin >> a >> b;       MA[a] = 0, MA[b] = 0;       maxx = max(maxx, a);       if (a == maxx) {         maxi = max(maxi, b);       }       xa[i] = a, xb[i] = b;     }     for (auto& it : MA) {       it.second = ++MAer;       AM[it.second] = it.first;     }     for (long long i = MA[maxi] + 1; i <= MA[maxx]; i++) {       M[i][0] = 1;     }     for (long long i = 1; i <= n; i++) {       Z[MA[xa[i]]].push_back(MA[xb[i]]);     }     for (long long i = MA[maxx]; i > 0; i--) {       while (M[i].size() > 1) {         M[i].erase(++M[i].begin(), M[i].end());       }       for (auto& a : Z[i]) {         for (auto& b : M[i]) {           M[a][b.first] += b.second;           M[a][b.first] %= 1000000007;         }       }       for (auto& a : M[i]) {         M[i - 1][AM[i] - AM[i - 1] + a.first] += a.second;         M[i - 1][AM[i] - AM[i - 1] + a.first] %= 1000000007;       }     }     cout << M[1].begin()->second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   int A[100], B[40200], n, N, M[40200];   long long r1;   int lis() {     int L = 0, lo, hi, mid, i;     for (i = 0; i < N; i++) {       lo = 1;       hi = L;       while (lo <= hi) {         mid = (lo + hi) / 2 + ((lo + hi) % 2);         if (B[M[mid]] <= B[i])           lo = mid + 1;         else           hi = mid - 1;       }       M[lo] = i;       if (lo > L) L = lo;       if (i == N - n - 1) r1 = L;     }     return L;   }   int main() {     int T, i, j, k;     long long r2;     scanf( %d%d , &n, &T);     for (i = 0; i < n; i++) {       scanf( %d , &A[i]);     }     if (T <= 401) {       for (i = 0, j = 0; i < T; i++)         for (k = 0; k < n; k++) B[j++] = A[k];       N = n * T;       printf( %d n , lis());     } else {       for (i = 0, j = 0; i < 401; i++)         for (k = 0; k < n; k++) B[j++] = A[k];       N = 401 * n;       r2 = lis();       cout << r1 + (r2 - r1) * (T - 400) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void normal(long long &a) { a = (a + 998244353) % 998244353; }   inline long long modMul(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a * b) % 998244353;   }   inline long long modAdd(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a + b) % 998244353;   }   inline long long modSub(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInv(long long a) { return modPow(a, 998244353 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInv(b));   }   const long long N = 4e5 + 1;   vector<long long> V;   long long n, x, R, C, cntt[N];   map<long long, long long> M;   void solve() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> x;       M[x]++;     }     for (auto u = (M).begin(); u != (M).end(); u++) {       cntt[u->second]++;     }     x = n;     for (long long i = n; i > 0; i--) {       if (R * C < (x / i * i) && i <= x / i) {         R = i, C = x / i;       }       x -= cntt[i];       cntt[i - 1] += cntt[i];     }     cout << R * C << endl;     cout << R <<     << C << endl;     if (!(R * C)) return;     long long ans[R][C];     x = min(R, C);     vector<pair<long long, long long> > p;     for (auto u = (M).begin(); u != (M).end(); u++) {       p.push_back({min(u->second, x), u->first});     }     sort((p).rbegin(), (p).rend());     while ((long long)((p).size())) {       while (p.back().first) {         V.push_back(p.back().second), p.back().first--;       }       p.pop_back();     }     long long i = 0, j = 0, cnt = 0;     for (long long i = 0; i < C; i++) {       for (long long j = 0; j < R; j++) {         ans[j][(i + j) % C] = V.back(), V.pop_back();       }     }     for (long long i = 0; i < R; i++) {       for (long long j = 0; j < C; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     clock_t start, end;     start = clock();     cout << fixed << setprecision(18);     ;     while (t--) {       solve();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     iostream::sync_with_stdio(0);     long long n;     cin >> n;     vector<long long> q{1, 1};     while (q.back() < 1e18) q.push_back(q.back() + q[q.size() - 2]);     cout << upper_bound(q.begin(), q.end(), n) - q.begin() - 2;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 10;   using namespace std;   long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }   long long qpow(long long p, long long q) {     long long f = 1;     while (q) {       if (q & 1) f = f * p;       p = p * p;       q >>= 1;     }     return f;   }   inline long long read() {     long long x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, k, t, c[21][21], vis[21][21], num[4];   struct node {     int cnt, id;     bool operator<(const node& p) const { return cnt > p.cnt; }   } ca[25];   bool flag;   bool solve(int a, int b) {     int d[21][21];     int i, j;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) d[i][j] = c[i][j];     for (i = 1; i <= n; i++) swap(d[i][a], d[i][b]);     for (i = 1; i <= n; i++) {       int now = 0;       for (j = 1; j <= m; j++)         if (d[i][j] != j) now++;       if (now > 2) return false;     }     return true;   }   int main() {     int i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) ca[i].id = i;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         scanf( %d , &c[i][j]);         if (c[i][j] != j) ca[i].cnt++;       }     sort(ca + 1, ca + n + 1);     if (ca[1].cnt <= 2)       puts( YES );     else if (ca[1].cnt > 4)       puts( NO );     else {       j = 0;       int pos = ca[1].id;       for (i = 1; i <= m; i++)         if (c[pos][i] != i) num[j++] = i;       for (i = 0; i <= 3; i++)         for (j = i + 1; j <= 3; j++) {           if (solve(num[i], num[j])) return 0 * puts( YES );         }       puts( NO );     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;   long long dp[2000005]{};   long long dp2[2000005]{};      int main()   {       long long n, t;       cin >> t;       while (t--)       {           string ss;           cin >> n;           cin >> ss;              memset(dp, 0, n * 8 + 40);           memset(dp2, 0, n * 8 + 40);              long long prev = 0;           for (int i = 1; i <= n; i++)           {               if (ss[i - 1] ==  . )               {                   dp[i] = dp[i - 1] + prev;               }               else               {                   prev++;                   dp[i] = dp[i - 1];               }           }           prev = 0;              for (int i = n; i > 0; i--)           {               if (ss[i - 1] ==  . )               {                   dp2[i] = dp2[i + 1] + prev;               }               else               {                   prev++;                   dp2[i] = dp2[i + 1];               }           }              long long ans = dp[n];           for (int i = 1; i <= n - 1; i++)           {               ans = min(ans, dp[i] + dp2[i + 1]);           }              printf( %lld  n , ans);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   void qSort(int *A, int low, int high, int *ii) {     int i = low;     int j = high;     int x = A[(low + high) / 2];     do {       while (A[i] < x) ++i;       while (A[j] > x) --j;       if (i <= j) {         int temp = A[i];         int buf = ii[i];         ii[i] = ii[j];         ii[j] = buf;         A[i] = A[j];         A[j] = temp;         i++;         j--;       }     } while (i <= j);     if (low < j) qSort(A, low, j, ii);     if (i < high) qSort(A, i, high, ii);   }   int gcd(int a, int b) {     if (b == 0) {       return a;     } else {       return gcd(b, a % b);     }   }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   int main() {     int n;     cin >> n;     int *mas = new int[n];     int *ii = new int[n];     for (int i = 0; i < n; i++) {       cin >> mas[i];       ii[i] = i;     }     qSort(mas, 0, n - 1, ii);     if (n % 2 == 0) {       cout << n / 2 << endl;     } else {       cout << n / 2 + 1 << endl;     }     for (int i = 0; i < n; i += 2) {       cout << ii[i] + 1 <<    ;     }     cout << endl;     if (n % 2 == 0) {       cout << n / 2 << endl;     } else {       cout << n / 2 << endl;     }     for (int i = 1; i < n; i += 2) {       cout << ii[i] + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int n1, n2, n3, n4, n5, n6, n7;   int a, b, c;   void doA(int i) {     if (n1 >= i)       n1 -= i;     else       n1 = 0;   }   void doB(int i) {     if (n2 >= i)       n2 -= i;     else {       doA(i - n2);       n2 = 0;     }   }   void doC(int i) {     if (n3 >= i)       n3 -= i;     else {       doB(i - n3);       n3 = 0;     }   }   void work() {     int ans = 0;     ans = n7;     ans += n6;     doA(n6);     ans += n5;     doB(n5);     if (c < a + b) {       ans += n4;       doC(n4);       int ANS = 0x3fffffff;       for (int i = 0; i <= n3; i++) {         int N1 = n1, N2 = n2, N3 = n3;         int j = n3 - i;         int now = max(i, j);         if (i > j) {           doB(i - j);           doA(i - j);         } else           doB(j - i);         now += max((n2 + 1) / 2, (n1 + n2 + 2) / 3);         ANS = min(ANS, now);         n1 = N1;         n2 = N2;         n3 = N3;       }       cout << ans + ANS << endl;     } else {       int ANS = 0x3fffffff;       for (int i = n4; i <= n3 + n4; i++) {         int N1 = n1, N2 = n2, N3 = n3;         int j = n3 + n4 - i;         int now = max(i, j);         if (i > j) {           doB(i - j);           doA(i - j);         } else           doB(j - i);         now += max((n2 + 1) / 2, (n1 + n2 + 2) / 3);         ANS = min(ANS, now);         n1 = N1;         n2 = N2;         n3 = N3;       }       cout << ans + ANS << endl;     }   }   int main() {     cin >> n;     cin >> a >> b >> c;     if (c < b) swap(b, c);     if (b < a) swap(a, b);     if (c < b) swap(b, c);     int x1 = min(a + b, c), x2 = max(a + b, c);     for (int i = 1; i <= n; i++) {       int t;       scanf( %d , &t);       if (t > a + b + c) {         cout << -1 << endl;         return 0;       }       if (t <= a)         n1++;       else if (t <= b)         n2++;       else if (t <= x1)         n3++;       else if (t <= x2)         n4++;       else if (t <= a + c)         n5++;       else if (t <= b + c)         n6++;       else         n7++;     }     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   const int INF = 2000000010;   int n, m, k;   int mi[maxn], ma[maxn], a[maxn], sum[maxn], v[maxn], la[maxn];   vector<pair<int, int>> G;   void add(int x, int cnt) {     for (int i = x; i <= max(n, m); i += (i & -i)) {       sum[i] += cnt;     }   }   int get_sum(int x) {     int ans = 0;     for (int i = x; i >= 1; i -= (i & -i)) {       ans += sum[i];     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) mi[i] = ma[i] = i;     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) {       if (!v[a[i]])         ma[a[i]] = max(ma[a[i]], a[i] + get_sum(n) - get_sum(a[i])), add(a[i], 1);       else         G.push_back(make_pair(v[a[i]], i));       la[i] = v[a[i]] + 1;       v[a[i]] = i;       mi[a[i]] = 1;     }     for (int i = 1; i <= n; i++) {       if (!v[i]) {         int x = get_sum(n) - get_sum(i);         ma[i] = max(ma[i], i + x);       }     }     for (int i = 1; i <= max(n, m); i++) sum[i] = 0;     k = 0;     for (int i = 0; i < (int)G.size(); i++) {       while (k < G[i].second) {         ++k;         add(la[k], 1);         add(k + 1, -1);       }       int x = get_sum(G[i].first);       ma[a[G[i].first]] = max(ma[a[G[i].first]], x);     }     while (k < m) {       ++k;       add(la[k], 1);       add(k + 1, -1);     }     for (int i = 1; i <= n; i++) {       if (v[i] > 0) {         int x = get_sum(v[i]);         ma[i] = max(ma[i], x);       }     }     for (int i = 1; i <= n; i++) {       printf( %d %d n , mi[i], ma[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int get(long long int s, long long int w, long long int cs,                     long long int cw, long long int p) {     if (s > w) return get(w, s, cw, cs, p);     if (s * cs >= p) return p / s;     return cs + min(cw, (p - s * cs) / w);   };   void solve() {     long long int p, f;     cin >> p >> f;     long long int cs, cw;     cin >> cs >> cw;     long long int s, w;     cin >> s >> w;     long long int mx = 0;     for (long long int x = 0; x <= cs; ++x) {       if (x * s <= p) {         long long int y = min(cw, (p - x * s) / w);         mx = max(mx, x + y + get(s, w, cs - x, cw - y, f));       }     }     cout << mx <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long int T = 1;     cin >> T;     for (long long int i = 1; i <= T; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[8], pro[1 << 8];   int bit_cnt[1 << 8];   vector<long long> pp;   bitset<1000000> p;   map<long long, int> H;   int N, an;   int qq(long long x) {     if (H.count(x)) return H[x];     long long X = x;     int res = 0;     for (int i = 0; i < ((int)(pp).size()) && pp[i] * pp[i] <= x; i++) {       while (x % pp[i] == 0) {         x /= pp[i];         res++;       }     }     if (x != 1) res++;     return H[X] = res;   }   int qq2(long long x) {     if (H.count(x)) {       int tmp = H[x];       if (tmp == 1) return 0;       return tmp;     }     long long X = x;     int res = 0;     for (int i = 0; i < ((int)(pp).size()) && pp[i] * pp[i] <= x; i++) {       while (x % pp[i] == 0) {         x /= pp[i];         res++;       }     }     if (x != 1) res++;     H[X] = res;     if (res == 1) return 0;     return res;   }   void dfs(int x, int mask, int v, int head) {     if (x == -1) {       if (head == 1)         an = min(an, v);       else         an = min(an, v + 1);       return;     }     if (!((mask >> x) & 1)) {       v++;       head++;     }     for (int i = 0; i < (1 << x); ++i) {       if (!i) {         dfs(x - 1, mask, v + qq2(a[x]), head);       } else if (!(mask & i) && a[x] % pro[i] == 0) {         dfs(x - 1, mask | i, v + bit_cnt[i] + qq(a[x] / pro[i]), head);       }     }   }   int main() {     for (int i = 3; i < 1000; i += 2) {       for (int j = i * i; j < 1000000; j += i + i) p[j] = 1;     }     pp.push_back(2);     for (int i = 3; i < 1000000; i += 2) {       if (!p[i]) pp.push_back(i);     }     int(n);     scanf( %d , &n);     N = n;     for (int i = 0; i < (n); ++i) cin >> a[i];     sort(a, a + n);     pro[0] = 1;     for (int i = (1); i < (1 << n); ++i) {       int k = 0;       while (!((i >> k) & 1)) k++;       bit_cnt[i] = bit_cnt[i - (1 << k)] + 1;       long long tmp1 = pro[i - (1 << k)];       long long tmp2 = a[k];       if (tmp1 > 10000000000000ll / tmp2)         pro[i] = 10000000000000ll;       else         pro[i] = tmp1 * tmp2;     }     an = 1000000;     dfs(n - 1, 0, 0, 0);     printf( %d n , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, a, b, num_of_results;   pair<int, int> game, results[10101];   int main() {     scanf( %d %d %d %d , &x, &y, &a, &b);     num_of_results = 0;     if (b >= x)       printf( 0 n );     else {       for (int i = a; i <= x; i++) {         for (int j = b; j <= y; j++) {           if (i > j) {             results[num_of_results++] = make_pair(i, j);           }         }       }       cout << num_of_results << endl;       for (int i = 0; i < num_of_results; i++) {         cout << results[i].first <<     << results[i].second << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 16 + 5;   string a[N], x, y;   int n, m, M = -1;   map<string, map<string, int> > mm;   bool vis[N];   void dfs(int deep, int mod) {     if (deep > n + 1) return;     if (deep == n + 1) {       int tot = 0, f = 1;       for (int i = 1; i <= n; ++i) tot += vis[i];       for (int i = 1; i <= n; ++i)         for (int j = i + 1; j <= n; ++j)           if (vis[i] && vis[j])             if (mm[a[i]][a[j]]) {               f = 0;               break;             }       if (f) {         if (mod) {           int tot = 0;           for (int i = 1; i <= n; ++i) tot += vis[i];           if (tot != M) return;           printf( %d n , M);           string res[N];           for (int i = 1; i <= 17; ++i) res[i] =  0 ;           int pos = 1;           for (int i = 1; i <= n; ++i)             if (vis[i]) res[pos++] = a[i];           sort(res + 1, res + pos);           pos = 1;           while (res[pos] !=  0 ) {             cout << res[pos] << endl;             pos++;           }           exit(0);         } else if (mod == 0)           M = max(M, tot);       }     }     vis[deep] = true;     dfs(deep + 1, mod);     vis[deep] = false;     dfs(deep + 1, mod);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= m; ++i) {       cin >> x >> y;       mm[x][y] = mm[y][x] = 1;     }     dfs(1, 0);     dfs(1, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   struct VIS {     int c, p;     int id;     bool operator<(const VIS& t) const {       if (p == t.p) return c < t.c;       return p > t.p;     }   } A[MAXN];   struct TAB {     int c;     int id;     bool operator<(const int t) const { return c < t; }     bool operator<(const TAB& t) const { return c < t.c; }   } Tb[MAXN];   bool vis[MAXN];   struct PAIR {     int v;     int t;     bool operator<(const PAIR& t) const { return v < t.v; }   } pai[MAXN];   int len;   int sum;   int main() {     int N, K;     while (scanf( %d , &(N)) != EOF) {       for (int i = (1); i < (N + 1); ++i) {         scanf( %d%d , &A[i].c, &A[i].p);         A[i].id = i;       }       sort(A + 1, A + N + 1);       scanf( %d , &(K));       for (int i = (1); i < (K + 1); ++i) {         scanf( %d , &(Tb[i].c));         Tb[i].id = i;       }       sort(Tb + 1, Tb + K + 1);       len = 0;       sum = 0;       memset(vis, 0, sizeof(vis));       for (int i = (1); i < (N + 1); ++i) {         int p = lower_bound(Tb + 1, Tb + K + 1, A[i].c) - Tb;         while (p <= K && vis[p]) ++p;         if (p > K) continue;         vis[p] = 1;         sum += A[i].p;         pai[len].v = A[i].id;         pai[len].t = Tb[p].id;         ++len;       }       sort(pai, pai + len);       printf( %d %d n , len, sum);       for (int k = (0); k < (len); ++k) {         printf( %d %d n , pai[k].v, pai[k].t);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double x[2], y[2], r[2];   inline long double sqr(long double x) { return x * x; }   inline long long sqrl(long long x) { return x * x; }   inline long double fcos(long double a, long double b, long double c) {     return acosl((a * a + b * b - c * c) / (2 * a * b));   }   inline long double cut(long double ang, long double r) {     long double s1 = ang * r * r;     long double s2 = sinl(ang) * cosl(ang) * r * r;     return s1 - s2;   }   const long double pi = acosl(-1);   long double solve() {     if (r[0] > r[1]) {       swap(r[0], r[1]);       swap(x[0], x[1]);       swap(y[0], y[1]);     }     long long dx = x[0] - x[1], dy = y[0] - y[1];     long long ds = sqrl(dx) + sqrl(dy);     if (ds >= sqrl(r[0] + r[1])) return 0;     long double d = sqrtl(ds);     if (d + r[0] <= r[1]) return sqr(r[0]) * pi;     long double ang[2];     ang[0] = fcos(d, r[0], r[1]);     ang[1] = fcos(d, r[1], r[0]);     return cut(ang[0], r[0]) + cut(ang[1], r[1]);   }   int main() {     cin >> x[0] >> y[0] >> r[0] >> x[1] >> y[1] >> r[1];     cout << setprecision(8) << solve() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, mini, maxi;     cin >> n >> m;     long long x = n / m;     long long rem = n - (x * m);     mini = rem * (x * (x + 1)) / 2 + (m - rem) * (x * (x - 1)) / 2;     maxi = ((n - m + 1) * (n - m)) / 2;     cout << mini <<     << maxi;   }


#include <bits/stdc++.h>   using namespace std;   bool p[5000020];   int prime[5000020];   void criba() {     p[0] = false;     p[1] = false;     for (int i = 2; i <= 5000000; i++) p[i] = true;     for (int i = 2; i <= 5000000; i++) {       if (p[i]) {         prime[i] = 1;         for (int h = 2; i * h <= 5000000; h++) {           p[i * h] = false;           if (h >= i and h % i == 0) {             int cnt = 0, x = i * h;             while (x % i == 0) {               cnt++;               x = x / i;             }             prime[i * h] += cnt;           } else             prime[i * h]++;         }       }     }     int sum = 0;     for (int i = 1; i <= 5000000; i++) prime[i] += prime[i - 1];   }   int main() {     int tc, a, b;     cin >> tc;     memset(prime, 0, sizeof(prime));     criba();     while (tc--) {       scanf( %d%d , &a, &b);       printf( %d n , prime[a] - prime[b]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k;     int n, m;     double H, L;     cin >> H >> L;     cout << fixed << setprecision(10) << ((L * L - H * H) / (2 * H));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   int dp[N][2];   int a[] = {1, 2};   int solve(int sum, int idx) {     if (sum == 0) return 1;     if (sum < 0 || idx == 2) return 0;     if (dp[sum][idx] != -1) return dp[sum][idx];     return dp[sum][idx] = solve(sum - a[idx], idx) + solve(sum, idx + 1);   }   int main() {     int n;     scanf( %d , &n);     memset(dp, -1, sizeof(dp));     for (int i = 1; i < N; ++i) {       int ans = solve(i, 0);       if (ans == n) {         printf( %d 2 n1 2 , i);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 600009;   const long long MOD = 1e9 + 7;   class {    public:     int n, F[MAXN], G[MAXN];     string s;     int Min;     void solve() {       cin >> n >> s;       for (int i = 1; i <= n; ++i) {         if (s[i - 1] ==  ( )           F[i] = F[i - 1] + 1;         else           F[i] = F[i - 1] - 1;         Min = min(Min, F[i]);       }       for (int i = n + 1; i <= n + n; ++i) {         if (s[i - n - 1] ==  ( )           F[i] = F[i - 1] + 1;         else           F[i] = F[i - 1] - 1;         Min = min(Min, F[i]);       }       if (F[n] != 0) {         cout << 0 <<   n  << 1 <<     << 1 <<   n ;         return;       }       int L, R;       for (int i = 0; i <= n; ++i) {         if (F[i] == Min) {           L = i, R = i + n - 1;         }       }       int tmp = 0;       for (int i = L; i <= R; ++i) {         if (F[i] == Min) tmp++;       }       int count = 0, nl = 0, nr, ans = tmp, ansl = 1, ansr = 0;       for (int i = L; i <= R; ++i) {         if (F[i] - 2 >= Min) {           if (!nl)             nl = nr = i;           else             nr = i;           if (F[i] - 2 == Min) count++;         } else {           nl = 0;           count = 0;         }         if (tmp + count > ans) {           ans = tmp + count;           ansl = nl;           ansr = nr;         }       }       count = 0;       nl = 0;       for (int i = L; i <= R; ++i) {         if (F[i] - 2 >= Min - 1) {           if (!nl)             nl = nr = i;           else             nr = i;           if (F[i] - 2 == Min - 1) count++;         } else {           nl = count = 0;         }         if (count > ans) {           ans = count;           ansl = nl;           ansr = nr;         }       }       ansr++;       if (ansl > n) ansl -= n;       if (ansr > n) ansr -= n;       cout << ans <<   n  << ansl <<     << ansr <<   n ;     }   } NSPACE;   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     NSPACE.solve();   }


#include <bits/stdc++.h>   using namespace std;   const bool testcase = 0;   const long long int mod1 = 1000000007;   const long long int mod2 = 998244353;   const long long int N = 1e5 + 5;   std::vector<long long int> adj[N];   std::vector<long long int> vis(N, false);   bool hasLoop(long long int i, long long int p) {     vis[i] = true;     bool ans = false;     for (auto it : adj[i]) {       if (!vis[it]) {         ans |= hasLoop(it, i);       } else if (it != p) {         ans |= true;       }     }     return ans;   }   void dfs(long long int i) {     vis[i] = true;     for (auto it : adj[i]) {       if (!vis[it]) {         dfs(it);       }     }   }   void solve() {     long long int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       long long int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     bool ok = true;     dfs(1);     for (int i = 1; i <= n; ++i) {       ok &= (vis[i] == 1);     }     if (ok && n == m) {       cout <<  FHTAGN! n ;     } else {       cout <<  NO n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int T_T = 1;     if (testcase) {       cin >> T_T;     }     while (T_T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, e_min = INT_MAX, e_max = INT_MIN;     list<int> l;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> x;       if (x < e_min) e_min = x;       if (x > e_max) e_max = x;       l.push_back(x);     }     l.remove_if(         [e_min, e_max](int it) { return (it == e_min) || (it == e_max); });     cout << l.size();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(0);     long long n, m, k, x, y;     cin >> n >> m >> k >> x >> y;     long long ti = (n * m) + ((n - 2) * m);     if (n == 1 || n == 2) ti = n * m;     long long upd = 0, mid = 0;     long long a[110][110];     long long num = k / ti;     long long rem = k % ti;     upd = num;     mid = 2 * num;     long long ma = mid, mi = upd, ans;     if (n == 1 || n == 2) {       ma = mi;     }     if (x - 1 == 0 || x - 1 == n - 1)       ans = mi;     else       ans = ma;     if (rem == 0) {       cout << ma <<     << mi <<     << ans << endl;       return 0;     }     long long flag = 0;     if (rem != 0) {       for (long long i = 0; i < n; ++i)         for (long long j = 0; j < m; ++j) {           if (i == 0 || i == n - 1) {             a[i][j] = upd;           } else {             a[i][j] = mid;           }         }       for (long long i = 0; i < n; ++i) {         for (long long j = 0; j < m; ++j) {           if (i == 0 || i == n - 1) {             a[i][j]++;             rem--;           } else {             a[i][j]++;             rem--;           }           if (rem == 0) {             flag = 1;             break;           }         }         if (flag) break;       }     }     flag = 0;     if (rem != 0) {       for (long long i = n - 2; i > 0; i--) {         for (long long j = 0; j < m; ++j) {           a[i][j]++;           rem--;           if (rem == 0) {             flag = 1;             break;           }         }         if (flag) break;       }     }     ma = -INFINITY, mi = INFINITY;     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < m; ++j) {         ma = max(a[i][j], ma);         mi = min(a[i][j], mi);         if (i == x - 1 && j == y - 1) {           ans = a[i][j];         }       }     cout << ma <<     << mi <<     << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1001];   int main() {     int n, m, c, q = 0;     cin >> n >> m >> c;     while (m-- && q <= n) {       int x;       cin >> x;       if (x > c / 2)         for (q = n; a[q] >= x; --q)           ;       else         for (q = 1; a[q] && a[q] <= x; ++q)           ;       cout << q << endl;       fflush(stdout);       a[q] = x;       for (q = 1; q <= n && a[q]; ++q)         ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m, i;     cin >> n;     if (n < 4) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     if (n % 2)       cout <<  5 * 4 = 20  << endl            <<  20 + 3 = 23  << endl            <<  23 + 2 = 25  << endl            <<  25 - 1 = 24  << endl,           m = 1;     else       cout <<  1 * 2 = 2  << endl            <<  2 * 3 = 6  << endl            <<  4 * 6 = 24  << endl,           m = 0;     for (i = n; i >= 5 + m; i -= 2)       cout << i <<   -   << i - 1 <<   = 1  << endl <<  24 * 1 = 24  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, i, sum = 0;     scanf( %d%d%d%d , &a, &b, &c, &d);     string str;     cin >> str;     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  1 ) sum += a;       if (str[i] ==  2 ) sum += b;       if (str[i] ==  3 ) sum += c;       if (str[i] ==  4 ) sum += d;     }     printf( %d , sum);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   bool isSquare(int r) {     return int(sqrt((double)r)) * int(sqrt((double)r)) == r;   }   bool check(int a, int b, int c, int d, int N, int M) {     int ans = 0;     ans += isSquare(a * a * (M - 1) + b * b);     ans += isSquare(a * a * (N - 1) + c * c);     ans += isSquare(b * b * (N - 1) + d * d);     ans += isSquare(c * c * (M - 1) + d * d);     return ans == 4;   }   int _127 = 100;   int main() {     int N, M;     cin >> N >> M;     int a, b, c, d;     do {       a = 1 + (rand() % _127);       b = 1 + (rand() % _127);       c = 1 + (rand() % _127);       d = 1 + (rand() % _127);     } while (!check(a, b, c, d, N, M));     for (long long i = 0; i < (int)N - 1; i++) {       for (long long j = 0; j < (int)M - 1; j++) {         cout << a <<    ;       }       cout << b << endl;     }     for (long long j = 0; j < (int)M - 1; j++) {       cout << c <<    ;     }     cout << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, size_t... Is>   struct arr_helper;   template <class T, size_t... Is>   using arr = typename arr_helper<T, Is...>::type;   template <class T>   struct arr_helper<T> {     using type = T;   };   template <class T, size_t I, size_t... Is>   struct arr_helper<T, I, Is...> {     using type = array<arr<T, Is...>, I>;   };   using ll = int64_t;   using u64 = uint64_t;   using u32 = uint32_t;   using vi = vector<int>;   using vvi = vector<vi>;   using pi = pair<int, int>;   using vpi = vector<pi>;   struct DSF {     vi p;     int c;     DSF(int n) : p(n), c(n) { iota(begin(p), end(p), 0); }     int repr(int i) {       if (p[i] != i) p[i] = repr(p[i]);       return p[i];     }     bool join(int a, int b) {       a = repr(a), b = repr(b);       c -= a != b;       p[a] = b;       return a != b;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vpi p(n);     for (auto& [xi, yi] : p) cin >> xi >> yi;     vi c(n), k(n);     for (auto& ci : c) cin >> ci;     for (auto& ki : k) cin >> ki;     vector<tuple<ll, int, int>> e;     for (int i = 0; i < n; ++i) e.emplace_back(c[i], i, n);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         ll per_km = k[i] + k[j];         ll xdist = abs(p[i].first - p[j].first);         ll ydist = abs(p[i].second - p[j].second);         e.emplace_back(per_km * (xdist + ydist), i, j);       }     }     sort(begin(e), end(e));     DSF dsf(n + 1);     vi station;     vpi conn;     ll cost = 0;     for (auto [c, a, b] : e) {       if (dsf.join(a, b)) {         if (b == n)           station.push_back(a);         else           conn.emplace_back(a, b);         cost += c;       }     }     cout << cost <<   n  << station.size() <<   n ;     for (auto i : station) cout << (i + 1) <<    ;     cout <<   n  << conn.size() <<   n ;     for (auto [a, b] : conn) cout << (a + 1) <<     << (b + 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     vector<long long> left;     vector<long long> right;     long long ok = 0;     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       long long l = 0, r = 0;       for (auto it : s) {         if (it ==  ( ) {           l++;         } else if (it ==  )  && l != 0) {           l--;         } else {           r++;         }       }       if (r == 0 && l != 0) {         left.push_back(l);       }       if (r != 0 && l == 0) {         right.push_back(r);       }       if (r == 0 && l == 0) {         ok++;       }     }     sort(left.begin(), left.end());     sort(right.begin(), right.end());     long long r = 0;     long long ans = 0;     for (long long l = 0; l < left.size(); l++) {       long long cur = left[l];       while (r < right.size() && right[r] < cur) {         r++;       }       if (r < right.size() && right[r] == cur) {         r++;         ans++;       }       if (r == right.size()) break;     }     ans += ok / 2;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, l, r, pos;   char in[1000], ans[1000][10];   bool back;   int main() {     scanf( %d , &t);     while (t--) {       back = false;       scanf( %s , in);       n = strlen(in);       for (int i = 1; i <= 8; i++)         for (int j = 0; j <= 3; j++) ans[i][j] =  0 ;       pos = 1;       l = r = 0;       for (int i = 0; i < n;) {         if (in[i] ==  : ) {           if (in[i + 1] ==  : ) {             l = i + 2;             i += 2;             back = true;             pos = 8;           } else {             l = i + 1;             i++;           }           continue;         }         while (i + 1 < n && in[i + 1] !=  : ) i++;         r = i;         int x = 4 - (r - l + 1);         for (int j = r; j >= l; j--) {           ans[pos][j - l + x] = in[j];         }         if (!back)           pos++;         else           pos--;         i++;       }       if (!back) {         for (int i = 1; i <= 8; i++) {           if (i != 1) putchar( : );           for (int j = 0; j <= 3; j++) putchar(ans[i][j]);         }       } else {         for (int i = 1; i <= pos; i++) {           if (i != 1) putchar( : );           for (int j = 0; j <= 3; j++) putchar(ans[i][j]);         }         for (int i = 8; i >= pos + 1; i--) {           putchar( : );           for (int j = 0; j <= 3; j++) putchar(ans[i][j]);         }       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int a[N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int pw = 1;     for (int i = 2; i <= n + 10; i++) {       pw *= 2;       if (pw > n) {         pw /= 2;         break;       }     }     int t = 0;     for (int i = 1; i <= n - 1; i++) {       if (a[i] <= 0) {         cout << t <<   n ;         continue;       }       while (i + pw > n) pw /= 2;       t += a[i];       a[i + pw] += a[i];       a[i] = 0;       cout << t <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     cout << s.size() * 25 + 26 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       if (s[0] ==  > ) {         cout << 0;       } else if (s[n - 1] ==  < )         cout << 0;       else if (s[0] ==  < ) {         int count1 = 0, count2 = 0;         for (int i = 0; i < n; i++) {           if (s[i] ==  > ) break;           count1++;         }         for (int i = n - 1; i >= 0; i--) {           if (s[i] ==  < ) break;           count2++;         }         int ans = min(count1, count2);         cout << ans;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   vector<pair<int, int> > w[5000];   pair<int, int> v[5000];   int p[5000], u[5000], pc[5000], px[5000], res[5000];   int go(int x, int p) {     for (int i = 0; i < ((int)(w[x]).size()); i++) {       int y = w[x][i].first;       int z = w[x][i].second;       if (y != p) {         px[y] = x;         pc[y] = z;         go(y, x);       }     }     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i].first);       v[i].second = i;     }     sort(v, v + n);     for (int i = 1; i < n; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       w[a].push_back(make_pair(b, c));       w[b].push_back(make_pair(a, c));     }     go(0, 0);     for (int i = 0; i < n; i++) {       p[i] = i;       res[i] = -1;     }     int it = 0;     while (true) {       int ok = 1;       for (int i = 0; i < n; i++) u[i] = 0;       for (int i = 0; i < n; i++) {         int j = v[i].second;         if (p[j] > 0 && u[p[j]] < pc[p[j]]) {           ok = 0;           u[p[j]]++;           p[j] = px[p[j]];         } else if (p[j] == 0 && res[j] == -1)           res[j] = it;       }       if (ok) break;       it++;     }     for (int i = 0; i < n; i++) printf( %d  , res[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ll, tt, i, j, a[234567], b[211212], c[211456], d[213456];   long long x, m, n, r, s, t, k, l, y, z;   vector<long long> p[12], q;   pair<long long, long long> pp[345678];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> x;       if (x == 1) {         a[i]++;       } else {         b[i]++;       }       a[i] += a[i - 1];       b[i] += b[i - 1];     }     for (t = 1; t <= n; t++) {       x = 0;       y = 0;       l = 0;       r = 0;       z = 0;       do {         x = lower_bound(a + z + 1, a + n + 1, a[z] + t) - a;         y = lower_bound(b + z + 1, b + n + 1, b[z] + t) - b;         if (x < y) {           l++;           z = x;         } else {           r++;           z = y;         }       } while (x + y <= 2 * n);       if (z == n && l != r) {         if (x == n && l < r) continue;         if (y == n && l > r) continue;         pp[s].first = max(l, r);         pp[s].second = t;         s++;       }     }     sort(pp, pp + s);     cout << s << endl;     for (i = 0; i < s; i++) cout << pp[i].first <<     << pp[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long zero = 0;   long long one = 1;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   long long expo(long long x, long long y) {     long long res = 1;     x = x % 1000000007;     while (y > 0) {       if (y & 1) res = (1ll * res * x) % 1000000007;       y = y >> 1;       x = (1ll * x * x) % 1000000007;     }     return res;   }   long long ncr(long long n, long long r) {     long long res = 1;     if (r > n - r) r = n - r;     for (long long i = 0; i < r; i++) {       res *= n - i;       res /= i + 1;     }     return res;   }   long long max(long long a, long long b) { return (a > b) ? a : b; }   bool prime(long long n) {     long long i;     for (i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return false;     }     return true;   }   bool sortbysec(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     if (a.second == b.second) return a.first < b.first;     return (a.second < b.second);   }   long long rr[] = {       0, 1, 1, 1, 0, -1, -1, -1,   };   long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     string s;     cin >> s;     if (n == 1) return cout << 0, 0;     long long dp[2][n];     memset(dp, 0, sizeof(dp));     dp[0][0] = (s[0] ==  0 );     dp[1][0] = (s[0] ==  1 );     for (long long i = 1; i < n; i++) {       dp[1][i] = dp[0][i - 1] + (s[i] ==  1 );       dp[0][i] = dp[1][i - 1] + (s[i] ==  0 );     }     cout << min(dp[0][n - 1], dp[1][n - 1]);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   struct Tree {     int l, r, num1;     long long num2;   } T[N * 4];   struct Ask {     int l, r, col;     Ask(int _l = 0, int _r = 0, int _col = 0) {       l = _l;       r = _r;       col = _col;     }     inline bool operator<(const Ask &b) const {       return l < b.l || (b.l == l && r < b.r);     }   };   set<Ask> S;   set<int> S2;   vector<int> v1[N << 1], v2[N << 1];   vector<pair<int, int> > A[N], B[N];   int l[N], r[N], a[N << 1], tot, n, k, R[N], L[N];   long long now, ppp;   inline int pd(int x) {     long long now = 0, cnt = 0;     for (int i = 1, j = 0; i <= n; i++) {       if (i != 1) {         for (pair<int, int> k : A[i - 1])           if (k.first > j) now -= k.second;       }       while (now < x) {         j++;         for (pair<int, int> k : B[j])           if (k.first < i) now += k.second;       }       cnt += n - j + 1;       R[i] = j;     }     ppp = cnt - k;     return cnt >= k;   }   inline int ef(int x) {     int l = 1, r = tot;     while (l < r) {       int mid = (l + r) / 2;       if (a[mid] < x)         l = mid + 1;       else         r = mid;     }     return l;   }   inline void build(int x, int l, int r) {     T[x].l = l;     T[x].r = r;     if (l == r) return;     int mid = (l + r) / 2;     build(x * 2, l, mid);     build(x * 2 + 1, mid + 1, r);   }   inline void insert(int x, int y, int z) {     T[x].num1++;     T[x].num2 += z;     if (T[x].l == T[x].r) return;     int mid = (T[x].l + T[x].r) / 2;     if (y <= mid)       insert(x * 2, y, z);     else       insert(x * 2 + 1, y, z);   }   inline long long find(int x, int l, int r, long long z) {     if (T[x].l > r || l > T[x].r) return 0;     if (T[x].l >= l && T[x].r <= r) return T[x].num1 * z - T[x].num2;     return find(x * 2, l, r, z) + find(x * 2 + 1, l, r, z);   }   inline long long solve(int l, int r) {     l++;     return find(1, l, L[r], r);   }   inline void Insert(int x) {     set<int>::iterator iter = S2.upper_bound(x), iter2 = iter;     iter2--;     now -= solve(*iter2, *iter);     now += solve(*iter2, x);     now += solve(x, *iter);     S2.insert(x);   }   inline void Del(int x) {     set<int>::iterator iter = S2.find(x), iter2 = iter;     iter2--;     iter++;     now += solve(*iter2, *iter);     now -= solve(*iter2, x);     now -= solve(x, *iter);     S2.erase(x);   }   signed main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d%d , &l[i], &r[i]), r[i]--;     l[n + 1] = 1;     r[n + 1] = 1e9;     S.insert(Ask(1, 1e9, 0));     for (int i = 1; i <= n + 1; i++) {       set<Ask>::iterator iter = S.upper_bound(Ask(l[i], 1e9, 0));       iter--;       vector<Ask> add;       add.push_back(Ask(l[i], r[i], i));       for (; iter != S.end() && (*iter).l <= r[i];) {         int len = min(r[i], (*iter).r) - max(l[i], (*iter).l) + 1;         if ((*iter).col != 0) A[(*iter).col].push_back(make_pair(i, len));         B[i].push_back(make_pair((*iter).col, len));         if ((*iter).l < l[i])           add.push_back(Ask((*iter).l, l[i] - 1, (*iter).col));         if ((*iter).r > r[i])           add.push_back(Ask(r[i] + 1, (*iter).r, (*iter).col));         S.erase(iter++);       }       for (Ask j : add) S.insert(j);     }     int lll = 0, rrr = 1e9;     while (lll < rrr) {       int mid = (lll + rrr + 1) / 2;       if (pd(mid))         lll = mid;       else         rrr = mid - 1;     }     pd(lll);     for (int i = 1; i <= n; i++) L[R[i]] = i;     for (int i = 1; i <= n + 1; i++) L[i] = max(L[i - 1], L[i]);     for (int i = 1; i <= n; i++) {       r[i]++;       a[++tot] = l[i];       a[++tot] = r[i];     }     sort(a + 1, a + tot + 1);     int num = 1;     for (int i = 2; i <= tot; i++)       if (a[i] != a[num]) a[++num] = a[i];     tot = num;     for (int i = 1; i <= n; i++)       l[i] = ef(l[i]), r[i] = ef(r[i]), v1[l[i]].push_back(i),       v2[r[i]].push_back(i);     long long ans = 0;     k = ppp;     now = k;     S2.insert(0);     S2.insert(n + 1);     build(1, 1, n);     for (int i = 1; i <= n; i++) insert(1, i, R[i]);     for (int i = 1; i < tot; i++) {       for (int j : v1[i]) Insert(j);       for (int j : v2[i]) Del(j);       ans += (long long)(k - now) * (a[i + 1] - a[i]);     }     printf( %lld n , ans - ppp * lll);     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, sum = 0, n;     for (i = 1; i <= 5; i++) {       scanf( %d , &n);       sum += n;     }     if (sum % 5 == 0 && sum != 0)       printf( %d n , sum / 5);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200001;   long long int sz[N], dist[N], every[N];   vector<int> adj[N];   int n, k;   void dfs(int start, int p = -1) {     for (auto child : adj[start]) {       if (child != p) {         dfs(child, start);         sz[start] += sz[child];         dist[start] += dist[child] + sz[child];       }     }   }   void dfs1(int start, int p = -1) {     for (auto child : adj[start]) {       if (child != p) {         every[child] = every[start] + (2 * k - 2 * sz[child]);         dfs1(child, start);       }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < 2 * k; i++) {       int x;       scanf( %d , &x);       sz[x]++;     }     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     every[1] = dist[1];     dfs1(1);     long long int ans = dist[1];     for (int i = 1; i <= n; i++) {       ans = min(ans, every[i]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6 + 3;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n, m;       cin >> n;       long long int a[n + 1];       long long int i = 0;       for (i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       long long int flag = 0;       for (i = 1; i < n; i++) {         if (abs(a[i] - a[i - 1]) > 1) {           flag = 1;           break;         }       }       if (flag == 1)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int NAX = 2e5 + 5, MOD = 1000000007;   struct Node {     set<pair<int, int>> vals;     Node() {}     Node lazylazyMerge(const Node &rhs) {}     Node seglazyMerge(const Node &rhs, const int &l, const int &r) {}     Node segSegMerge(const Node &rhs) {}   };   template <typename segNode>   struct Segtree {     vector<segNode> Seg, Lazy;     vector<segNode> Base;     vector<bool> isLazy;     int n;     Segtree(int _n = 2e5) {       this->n = _n;       Seg.resize(4 * _n + 10);       Lazy.resize(4 * _n + 10);       isLazy.resize(4 * _n + 10);     }     void merge(segNode &curr, segNode &l, segNode &r) { curr = l + r; }     void propagate(int node, int L, int R) {       if (isLazy[node]) {         isLazy[node] = false;         Seg[node] = Seg[node].seglazyMerge(Lazy[node], L, R);         if (L != R) {           Lazy[2 * node] = Lazy[2 * node].lazylazyMerge(Lazy[node]);           Lazy[2 * node + 1] = Lazy[2 * node + 1].lazylazyMerge(Lazy[node]);           isLazy[2 * node] = true;           isLazy[2 * node + 1] = true;         }         Lazy[node] = segNode();       }     }     void build(int node, int start, int end) {       if (start == end) {         Seg[node] = Base[start];         return;       }       int mid = (start + end) / 2;       build(2 * node, start, mid);       build(2 * node + 1, mid + 1, end);       Seg[node] = Seg[2 * node].segSegMerge(Seg[2 * node + 1]);     }     void build(vector<segNode> &Arr) {       Base = Arr;       n = Arr.size();       Seg.resize(4 * n + 10);       Lazy.resize(4 * n + 10);       isLazy.resize(4 * n + 10);       build(1, 0, n - 1);     }     pair<int, int> Query(int node, int start, int end, int qstart, int qend) {       propagate(node, start, end);       if (qend < start || qstart > end || start > end)         return pair<int, int>(MOD, MOD);       if (qstart <= start && end <= qend) {         if ((Seg[node].vals).empty()) return pair<int, int>(MOD, MOD);         return *((Seg[node].vals).begin());       }       int mid = (start + end) / 2;       auto l = Query(2 * node, start, mid, qstart, qend);       auto r = Query(2 * node + 1, mid + 1, end, qstart, qend);       return min(l, r);     }     segNode qQuery(int node, int start, int end, int pos) {       propagate(node, start, end);       if (start == end) return Seg[node];       int mid = (start + end) / 2;       if (pos <= mid) return qQuery(2 * node, start, mid, pos);       return qQuery(2 * node + 1, mid + 1, end, pos);     }     void Update(int node, int start, int end, int qstart, int qend, segNode val) {       propagate(node, start, end);       if (qend < start || qstart > end || start > end) return;       if (qstart <= start && end <= qend) {         isLazy[node] = true;         Lazy[node] = val;         propagate(node, start, end);         return;       }       int mid = (start + end) / 2;       Update(2 * node, start, mid, qstart, qend, val);       Update(2 * node + 1, mid + 1, end, qstart, qend, val);       Seg[node] = Seg[2 * node].segSegMerge(Seg[2 * node + 1]);     }     void pUpdate(int node, int start, int end, int pos, pair<int, int> val) {       Seg[node].vals.insert(val);       if (start == end) {         return;       }       int mid = (start + end) / 2;       if (pos <= mid)         pUpdate(2 * node, start, mid, pos, val);       else         pUpdate(2 * node + 1, mid + 1, end, pos, val);     }     void pdel(int node, int start, int end, int pos, pair<int, int> val) {       Seg[node].vals.erase(val);       if (start == end) {         return;       }       int mid = (start + end) / 2;       if (pos <= mid)         pdel(2 * node, start, mid, pos, val);       else         pdel(2 * node + 1, mid + 1, end, pos, val);     }     segNode query(int pos) { return qQuery(1, 0, n - 1, pos); }     pair<int, int> query(int left, int right) {       return Query(1, 0, n - 1, left, right);     }     void update(int pos, pair<int, int> val) { pUpdate(1, 0, n - 1, pos, val); }     void update(int start, int end, segNode val) {       Update(1, 0, n - 1, start, end, val);     }   };   void solveCase() {     int n;     cin >> n;     ;     vector<pair<pair<int, int>, pair<int, pair<int, int>>>> a(n);     vector<int> ranges;     for (size_t i = 0; i < n; i++) {       cin >> a[i].first.first >> a[i].first.second;       cin >> a[i].second.first >> a[i].second.second.first;       a[i].second.second.second = i;       ranges.push_back(a[i].first.first);       ranges.push_back(a[i].second.first);     }     sort(ranges.begin(), ranges.end());     ranges.erase(unique(ranges.begin(), ranges.end()), ranges.end());     for (size_t i = 0; i < n; i++) {       a[i].first.first =           lower_bound(ranges.begin(), ranges.end(), a[i].first.first) -           ranges.begin();       a[i].second.first =           lower_bound(ranges.begin(), ranges.end(), a[i].second.first) -           ranges.begin();     }     sort(a.begin(), a.end());     ;     vector<int> prev(n, -1), dist(n, MOD);     queue<int> Q;     Segtree<Node> stree(n);     for (size_t i = 0; i < n; i++) {       if (a[i].first.first == 0 && a[i].first.second == 0) {         Q.push(i);         dist[i] = 0;       } else         stree.update(i, {a[i].first.second, i});     }     while (Q.size()) {       auto curr_idx = Q.front();       ;       Q.pop();       int c = a[curr_idx].second.first;       int d = a[curr_idx].second.second.first;       int idx2 = lower_bound(a.begin(), a.end(),                              make_pair(make_pair(c + 1, 0),                                        make_pair(0, make_pair(0, 0)))) -                  a.begin();       --idx2;       ;       while (true) {         auto q = stree.query(0, idx2);         ;         if (q.first > d) break;         int idx = q.second;         Q.push(idx);         dist[idx] = dist[curr_idx] + 1;         prev[idx] = curr_idx;         stree.pdel(1, 0, n - 1, idx, q);       }     };     for (size_t i = 0; i < n; i++) {       if (a[i].second.second.second == (n - 1)) {         if (dist[i] != MOD) {           cout << dist[i] + 1 <<   n ;           vector<int> path;           int curr = i;           while (curr >= 0) {             path.push_back(curr);             curr = prev[curr];           }           for (int i = path.size() - 1; i >= 0; i--) {             cout << a[path[i]].second.second.second + 1 <<    ;           }           cout <<   n ;           return;         }       }     }     cout << -1 <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     ;     for (int i = 1; i <= t; ++i) solveCase();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mn[200010 * 4], lazy_value[4 * 200010];   bool lazy[4 * 200010];   void update_node(int idx, int st, int ed, int val) {     lazy[idx] = 1;     lazy_value[idx] += val;     mn[idx] += val;   }   void update_lazy(int idx, int st, int ed) {     if (st == ed) return;     int mid = (st + ed) / 2;     update_node(2 * idx, st, mid, lazy_value[idx]);     update_node(2 * idx + 1, mid + 1, ed, lazy_value[idx]);     lazy[idx] = lazy_value[idx] = 0;   }   void insert(int idx, int st, int ed, int s, int e, int val) {     if (st == s && ed == e) {       update_node(idx, st, ed, val);       return;     }     if (lazy[idx]) update_lazy(idx, st, ed);     int mid = (st + ed) / 2;     if (e <= mid)       insert(idx * 2, st, mid, s, e, val);     else if (s > mid)       insert(idx * 2 + 1, mid + 1, ed, s, e, val);     else {       insert(idx * 2, st, mid, s, mid, val);       insert(idx * 2 + 1, mid + 1, ed, mid + 1, e, val);     }     mn[idx] = min(mn[idx * 2], mn[idx * 2 + 1]);   }   int query(int idx, int st, int ed, int s, int e) {     if (st == s && ed == e) return mn[idx];     if (lazy[idx]) update_lazy(idx, st, ed);     int mid = (st + ed) / 2;     if (mid >= e)       return query(2 * idx, st, mid, s, e);     else if (s > mid)       return query(2 * idx + 1, mid + 1, ed, s, e);     else       return min(query(idx * 2, st, mid, s, mid),                  query(idx * 2 + 1, mid + 1, ed, mid + 1, e));   }   int main() {     int n, val, i, q, cnt, st, ed;     string s_line;     cin >> n;     for (i = 0; i < n; i++) {       cin >> val;       insert(1, 0, n - 1, i, i, val);     }     cin >> q;     getchar();     while (q--) {       getline(cin, s_line);       stringstream ss1;       ss1 << s_line;       ss1 >> st;       ss1 >> ed;       cnt = 0;       while (ss1 >> val) cnt++;       if (cnt) {         if (st > ed) {           insert(1, 0, n - 1, st, n - 1, val);           insert(1, 0, n - 1, 0, ed, val);         } else           insert(1, 0, n - 1, st, ed, val);       } else {         if (st > ed)           cout << min(query(1, 0, n - 1, st, n - 1), query(1, 0, n - 1, 0, ed));         else           cout << query(1, 0, n - 1, st, ed);         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mp[1010000], ans;   int main() {     int n, m, x;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       mp[x]++;     }     for (int i = 0; i <= 1e6 + 21; i++) {       int num = i;       int numcnt = mp[i];       if (numcnt % 2 == 1) ans++;       mp[num + 1] += numcnt / 2;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   string s;   int32_t main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     long long left = 1;     long long right = n;     while (right - left > 1) {       long long m1 = (right + left) / 2;       long long m2 = m1 + 1;       cout << 1 <<     << m1 <<     << m2 << endl;       cout.flush();       cin >> s;       if (s ==  TAK ) {         right = m1;       } else         left = m2;     }     long long f;     long long s1 = -1;     long long s2 = -1;     if (left == right)       f = left;     else {       cout << 1 <<     << left <<     << right << endl;       cout.flush();       cin >> s;       if (s ==  TAK ) {         f = left;       } else         f = right;     }     left = 1;     right = f - 1;     if (right >= left) {       while (right - left > 1) {         long long m1 = (right + left) / 2;         long long m2 = m1 + 1;         cout << 1 <<     << m1 <<     << m2 << endl;         cout.flush();         cin >> s;         if (s ==  TAK ) {           right = m1;         } else           left = m2;       }       if (left == right)         s1 = left;       else {         cout << 1 <<     << left <<     << right << endl;         cout.flush();         cin >> s;         if (s ==  TAK ) {           s1 = left;         } else           s1 = right;       }     }     left = f + 1;     right = n;     if (right >= left) {       while (right - left > 1) {         long long m1 = (right + left) / 2;         long long m2 = m1 + 1;         cout << 1 <<     << m1 <<     << m2 << endl;         cout.flush();         cin >> s;         if (s ==  TAK ) {           right = m1;         } else           left = m2;       }       if (left == right)         s2 = left;       else {         cout << 1 <<     << left <<     << right << endl;         cout.flush();         cin >> s;         if (s ==  TAK ) {           s2 = left;         } else           s2 = right;       }     }     if (s1 != -1) {       cout <<  1   << s1 <<     << f << endl;       cout.flush();       cin >> s;       if (s ==  TAK ) {         cout << 2 <<     << f <<     << s1 << endl;         cout.flush();         return 0;       }     }     cout << 2 <<     << f <<     << s2 << endl;     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b) {       return a;     }     return b;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   long long int min(long long int a, long long int b) {     if (a < b) {       return a;     }     return b;   }   long long int power(long long int x, long long int n) {     long long int res = 1;     while (n > 0) {       if (n % 2 == 1) {         res = (res * x);       }       x = (x * x);       n = n / 2;     }     return res;   }   long long int factorialNumInverse[1000001];   long long int naturalNumInverse[1000001];   long long int fact[1000001];   void InverseofNumber(long long int n, long long int p) {     naturalNumInverse[0] = naturalNumInverse[1] = 1;     for (long long int i = 2; i <= n; i++)       naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;   }   void InverseofFactorial(long long int n, long long int p) {     factorialNumInverse[0] = factorialNumInverse[1] = 1;     for (long long int i = 2; i <= n; i++)       factorialNumInverse[i] =           (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;   }   void factorial(long long int n, long long int p) {     fact[0] = 1;     for (long long int i = 1; i <= n; i++) {       fact[i] = (fact[i - 1] * i) % p;     }   }   long long int nCrModp(long long int n, long long int r, long long int p) {     long long int ans =         ((fact[n] * factorialNumInverse[r]) % p * factorialNumInverse[n - r]) % p;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int tc;     cin >> tc;     factorial(200005, 1000000007);     InverseofNumber(200005, 1000000007);     InverseofFactorial(200005, 1000000007);     while (tc--) {       long long int n;       cin >> n;       string s;       cin >> s;       long long int ans = 0;       long long int i = 1;       long long int len = 1;       while (i < n) {         if (s[i] == s[0]) {           len++;         }         i++;       }       if (len == n) {         cout << ceil((long double)n / (long double)3) <<   n ;         continue;       }       len = 0;       i = 0;       int j = s.length() - 1;       while (j >= 0 && s[j] == s[0]) {         len++;         j--;       }       while (i <= j && s[i] == s[0]) {         len++;         i++;       }       ans += (len) / 3;       len = 1;       i++;       while (i <= j) {         if (s[i] == s[i - 1]) {           len++;         } else {           ans += (len) / 3;           len = 1;         }         i++;       }       ans += (len) / 3;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, si = 1, leaf;   long long ans[500010];   struct Q {     int s, e, ind;   };   vector<Q> query[500010];   vector<pair<int, int>> tree[500010];   int rs[500010];   struct seg {     long long seg[2000010], lazy[2000010];     void prop(int x) {       seg[x] += lazy[x];       if (x < si) {         lazy[x * 2] += lazy[x];         lazy[x * 2 + 1] += lazy[x];       }       lazy[x] = 0;       return;     }     void add(int s, int e, long long v) {       if (s > e) return;       add(1, 1, si, s, e, v);     }     void add(int x, int l, int r, int s, int e, long long v) {       prop(x);       if (r < s || e < l) return;       if (s <= l && r <= e) {         lazy[x] += v;         prop(x);         return;       }       add(x * 2, l, (l + r) / 2, s, e, v);       add(x * 2 + 1, (l + r) / 2 + 1, r, s, e, v);       seg[x] = min(seg[x * 2], seg[x * 2 + 1]);     }     long long get(int s, int e) { return get(1, 1, si, s, e); }     long long get(int x, int l, int r, int s, int e) {       prop(x);       if (r < s || e < l) return 1000000000000000LL;       if (s <= l && r <= e) return seg[x];       return min(get(x * 2, l, (l + r) / 2, s, e),                  get(x * 2 + 1, (l + r) / 2 + 1, r, s, e));     }   } S;   void makeup(int x, long long dis) {     rs[x] = x;     if (tree[x].size() == 0) {       S.add(x, x, dis);       return;     } else       S.add(x, x, 1000000000000000LL);     for (auto i : tree[x]) {       makeup(i.first, dis + i.second);       rs[x] = max(rs[x], rs[i.first]);     }   }   void dfs(int x) {     for (auto i : query[x]) ans[i.ind] = S.get(i.s, i.e);     for (auto i : tree[x]) {       S.add(i.first, rs[i.first], -i.second);       S.add(1, i.first - 1, i.second);       S.add(rs[i.first] + 1, n, i.second);       dfs(i.first);       S.add(i.first, rs[i.first], i.second);       S.add(1, i.first - 1, -i.second);       S.add(rs[i.first] + 1, n, -i.second);     }   }   int main() {     int i, a, b, c;     scanf( %d %d , &n, &q);     while (si < n) si <<= 1;     for (i = 2; i <= n; i++) {       scanf( %d %d , &a, &b);       tree[a].push_back({i, b});     }     for (i = 1; i <= q; i++) {       scanf( %d %d %d , &a, &b, &c);       query[a].push_back({b, c, i});     }     makeup(1, 0);     dfs(1);     for (i = 1; i <= q; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;      typedef vector <int> vi;   typedef pair <int, int> pii;      const int MAXN = 2e5 + 5;      int N;   int perm[MAXN];   bool bio[MAXN];   deque <pii> ans;      void load() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       int coin;       scanf( %d , &coin);       perm[coin] = i;     }   }      void add_front(int x, int y) {     ans.push_front({x, y});   }      void add_back(int x, int y) {     ans.push_back({x, y});   }      void one_cycle(const vi &cyc) {     int len = cyc.size();     auto add_local = [&](int x, int y) {       add_front(cyc[x % len], cyc[y % len]);     };     add_local(1, 2);     add_local(1, 3);     for (int i = 3; i < len; i++)       add_local(i, i + 1);     add_local(1, 2);     add_local(0, 1);   }      void two_cycles(vi cyc1, vi cyc2) {     cyc2.insert(cyc2.begin(), cyc1.back());     cyc1.pop_back();     cyc1.insert(cyc1.begin(), cyc2.back());     cyc2.pop_back();     int len1 = cyc1.size();     for (int i = 0; i < len1 - 1; i++)       add_front(cyc1[i], cyc1[i + 1]);     int len2 = cyc2.size();     for (int i = 0; i < len2 - 1; i++)       add_front(cyc2[i], cyc2[i + 1]);     add_front(cyc1[0], cyc2[0]);     add_front(cyc1.back(), cyc2.back());   }      void fixed_and_transposition(int x, const vi &tau) {     add_back(x, tau[0]);     add_back(tau[0], tau[1]);     add_back(x, tau[1]);   }      void solve() {     int fixed = 0;     vector <vi> other;     for (int i = 1; i <= N; i++)        if (!bio[i]) {         vi tmp;         for (int x = i; !bio[x]; x = perm[x]) {           tmp.push_back(x);           bio[x] = true;         }         if (tmp.size() > 1)           other.push_back(tmp);         else           fixed = tmp[0];       }     if (!other.empty()) {       int largest = max_element(other.begin(), other.end(), [&](const vi &u, const vi &v) { return u.size() < v.size(); }) - other.begin();       swap(other[0], other[largest]);       int parity = other.size() % 2;       for (int i = parity; i < other.size(); i += 2)         two_cycles(other[i], other[i + 1]);       if (parity) {         if (other[0].size() >= 3)            one_cycle(other[0]);         else            fixed_and_transposition(fixed ? fixed : other[1][0], other[0]);       }     }     printf( %d n , ans.size());     for (auto it : ans) {       printf( %d %d n , perm[it.first], perm[it.second]);       swap(perm[it.first], perm[it.second]);     }   }      int main() {     load();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int u, v, w;   } arr[300010];   bool cmp(node a, node b) { return (a.w < b.w); }   int n, m;   int f[300010], f2[300010];   int main() {     scanf( %d , &n);     ;     scanf( %d , &m);     ;     for (int i = 0; i < m; i++) {       scanf( %d , &arr[i].u);       ;       scanf( %d , &arr[i].v);       ;       scanf( %d , &arr[i].w);       ;     }     sort(arr, arr + m, cmp);     int ans = 0;     for (int i = 0, j = 0; i < m; i = j) {       while (j < m && arr[i].w == arr[j].w) j++;       for (int k = i; k < j; k++) f2[arr[k].v] = f[arr[k].v];       for (int k = i; k < j; k++)         f2[arr[k].v] = max(f2[arr[k].v], 1 + f[arr[k].u]);       for (int k = i; k < j; k++) f[arr[k].v] = f2[arr[k].v];       for (int k = i; k < j; k++) ans = max(ans, f[arr[k].v]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmin(T &x, T y) {     x = x < y ? x : y;   }   template <typename T>   void chkmax(T &x, T y) {     x = x > y ? x : y;   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= f;   }   int a[100010], s[100010], f[100010][105], b[100010][105];   void add(int &x, int y) {     x += y;     if (x >= 998244353) x -= 998244353;   }   int main() {     int n, k, len;     read(n), read(k), read(len);     if (len == 1) return cout <<  0 n , 0;     s[0] = 1;     for (int i = 1; i <= n; i++) read(a[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= k; j++)         if (a[i] == j || a[i] == -1) b[i][j] = 1;     for (int j = 1; j <= k; j++)       for (int i = 1; i <= n; i++) b[i][j] += b[i - 1][j];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= k; j++) {         if (~a[i] && a[i] != j) continue;         f[i][j] = s[i - 1];         if (i >= len && b[i][j] - b[i - len][j] == len)           add(f[i][j], (f[i - len][j] - s[i - len] + 998244353) % 998244353);         add(s[i], f[i][j]);       }     }     cout << s[n] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double x, y;     while (cin >> x >> y) {       double l;       l = sqrt(x * x + y * y);       if (l == (int)l) {         cout <<  black  << endl;         continue;       }       int z = (int)l;       if (z != l) z++;       if (x * y >= 0) {         if (z % 2)           cout <<  black  << endl;         else           cout <<  white  << endl;       } else {         if (z % 2 == 0)           cout <<  black  << endl;         else           cout <<  white  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     }     if (b == 0) {       return a;     }     return gcd(b % a, a);   }   int main() {     long long ra, la, ta, rb, lb, tb;     cin >> la >> ra >> ta;     cin >> lb >> rb >> tb;     long long g = gcd(ta, tb);     if (ta > tb) {       long long j = la, k = ra, l = ta;       la = lb;       ra = rb;       ta = tb;       lb = j;       rb = k;       tb = l;     }     lb -= la;     rb -= la;     long long buff = ((lb + tb) % tb) - lb;     lb += buff;     rb += buff;     ra -= la;     la -= la;     long long bdif = 0;     long long nf = (lb % g) - lb;     lb += nf;     rb += nf;     bdif = max(bdif, 1 + min(rb, ra) - max(lb, la));     long long nl = ((lb + g - 1) % g) - g + 1;     long long df = nl - lb;     lb += df;     rb += df;     bdif = max(bdif, 1 + min(rb, ra) - max(lb, la));     cout << bdif << endl;   }


#include <bits/stdc++.h>   using namespace std;   auto start = std::chrono::high_resolution_clock::now();   long double crrtime() {     auto stop = std::chrono::high_resolution_clock::now();     auto duration =         std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);     return ((long double)duration.count()) / ((long double)1e9);   }   mt19937 rng(2);   int inline randn(int L, int R) {     uniform_int_distribution<int> uid(L, R);     return uid(rng);   }   int inline randn(int N) {     uniform_int_distribution<int> uid(0, N - 1);     return uid(rng);   }   const long long mod = 998244353;   long long n;   long long p[30];   long long a[30][26];   long long g[10000001];   long long h[10000001];   long long F[10000001];   void solve() {     cin >> n;     p[0] = 1;     for (long long i = 1; i < 30; i++) p[i] = 2 * p[i - 1];     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       for (long long j = 0; j < 26; j++) a[i][j] = 0;       for (char c : s) a[i][c -  a ]++;     }     g[0] = 0;     for (long long x = 1; x < p[n]; x++) {       vector<long long> tmp(26, 100000);       long long k = 0;       h[x] = 0;       for (long long i = 0; i < n; i++) {         if (p[i] & x) {           for (long long j = 0; j < 26; j++) tmp[j] = min(tmp[j], a[i][j]);           k++;           h[x]++;           h[x] += i;         }       }       long long cnt = 1;       for (long long i = 0; i < 26; i++) cnt = (cnt * (tmp[i] + 1)) % mod;       h[x] *= k;       g[x] = cnt;       if ((k & 1) == 0) g[x] = -cnt;     }     for (long long i = 0; i < (1 << n); ++i) F[i] = g[i];     for (long long i = 0; i < n; ++i)       for (long long mask = 0; mask < (1 << n); ++mask) {         if (mask & (1 << i)) F[mask] += F[mask ^ (1 << i)];       }     long long ans = 0;     for (long long i = 0; i < p[n]; i++) {       F[i] %= mod;       if (F[i] < 0) F[i] += mod;       ans ^= (F[i] * h[i]);     }     cout << (ans) <<   n ;   }   signed main() {     start = std::chrono::high_resolution_clock::now();     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt = 1;     for (long long tc = 1; tc <= tt; ++tc) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int long long freq[100005], a[100005], final[100005];   int long long pow1(int long long a, int long long b) {     if (a == 0) return 0;     int long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y);         if (x > 1000000007) x %= 1000000007;       }       y = (y * y);       if (y > 1000000007) y %= 1000000007;       b /= 2;     }     return x % 1000000007;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int long long n;     cin >> n;     for (int long long i = 0; i < n; i++) {       cin >> a[i];       freq[a[i]]++;     }     for (int long long i = 100000; i >= 1; i--) {       int long long c1 = 0;       for (int long long j = i; j <= 100000; j = j + i) {         c1 = (c1 + freq[j]) % 1000000007;       }       final[i] = (final[i] + pow1(2, c1) - 1) % 1000000007;       for (int long long j = 2 * i; j <= 100000; j = j + i) {         final[i] = (final[i] + 1000000007 - final[j]) % 1000000007;       }     }     cout << final[1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int xa, ya, xb, yb, n;     cin >> xa >> ya >> xb >> yb >> n;     vector<int> X(n), Y(n), R(n);     for (int i = 0; i < n; ++i) cin >> X[i] >> Y[i] >> R[i];     if (xa > xb) swap(xa, xb);     if (ya > yb) swap(ya, yb);     int ans = 0;     for (int i = xa; i <= xb; i++) {       bool flag = false;       for (int j = 0; j < n; ++j) {         int d = (X[j] - i) * (X[j] - i) + (Y[j] - ya) * (Y[j] - ya);         if (d <= R[j] * R[j]) flag = true;       }       ans += !flag;       flag = false;       for (int j = 0; j < n; ++j) {         int d = (X[j] - i) * (X[j] - i) + (Y[j] - yb) * (Y[j] - yb);         if (d <= R[j] * R[j]) flag = true;       }       ans += !flag;     }     for (int i = ya + 1; i < yb; ++i) {       bool flag = false;       for (int j = 0; j < n; ++j) {         int d = (X[j] - xa) * (X[j] - xa) + (Y[j] - i) * (Y[j] - i);         if (d <= R[j] * R[j]) flag = true;       }       ans += !flag;       flag = false;       for (int j = 0; j < n; ++j) {         int d = (X[j] - xb) * (X[j] - xb) + (Y[j] - i) * (Y[j] - i);         if (d <= R[j] * R[j]) flag = true;       }       ans += !flag;     }     cout << ans <<   n ;     return 0;   }