#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using namespace std;   const long long p = 998244353, g = 3, gv = 332748118, N = 1e6 + 5;   long long qpow(long long a, int b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % p;       a = a * a % p;       b >>= 1;     }     return ret;   }   long long inv(long long a) { return qpow(a, p - 2); }   int rev[N];   void getrev(int len) {     for (int i = 0; i < len; i++) {       rev[i] = rev[i >> 1] >> 1;       if (i & 1) rev[i] |= (len >> 1);     }   }   void ntt(vector<long long> &a, int len, int tp) {     a.resize(len);     for (int i = 0; i < len; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int i = 2; i <= len; i <<= 1) {       long long wn = qpow(tp == 1 ? g : gv, (p - 1) / i);       int stp = i >> 1;       for (int j = 0; j < len; j += i) {         long long w = 1;         for (int k = j; k < j + stp; k++) {           long long s1 = a[k], s2 = a[k + stp] * w % p;           w = w * wn % p;           a[k] = (s1 + s2) % p, a[k + stp] = (s1 + p - s2) % p;         }       }     }     if (tp == -1) {       long long lv = inv(len);       for (int i = 0; i < len; i++) a[i] = a[i] * lv % p;     }   }   vector<long long> operator*(vector<long long> a, vector<long long> b) {     int len = 1, n = a.size() + b.size() - 1;     while (len < n) len <<= 1;     getrev(len);     ntt(a, len, 1), ntt(b, len, 1);     for (int i = 0; i < len; i++) a[i] = a[i] * b[i] % p;     ntt(a, len, -1);     a.resize(n);     return a;   }   vector<long long> operator+(vector<long long> a, vector<long long> b) {     if (a.size() < b.size()) swap(a, b);     for (int i = 0; i < b.size(); i++) a[i] = (a[i] + b[i]) % p;     return a;   }   vector<long long> operator-(vector<long long> a) {     for (int i = 0; i < a.size(); i++) a[i] = (p - a[i]) % p;     return a;   }   vector<long long> operator-(vector<long long> a, vector<long long> b) {     return a + (-b);   }   vector<long long> operator*(long long b, vector<long long> a) {     for (int i = 0; i < a.size(); i++) a[i] = a[i] * b % p;     return a;   }   vector<long long> operator/(vector<long long> a, long long b) {     int v = inv(b);     for (int i = 0; i < a.size(); i++) a[i] = a[i] * v % p;     return a;   }   long long fac[N], finv[N], iv[N];   int main() {     int n;     long long m;     scanf( %d%lld , &n, &m);     n++;     fac[0] = fac[1] = iv[1] = finv[0] = finv[1] = 1;     for (int i = 2; i <= n; i++)       fac[i] = fac[i - 1] * i % p, iv[i] = (p - p / i) * iv[p % i] % p,       finv[i] = finv[i - 1] * iv[i] % p;     vector<long long> a, b, c;     a.resize(n), b.resize(n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       a[i] = x * 1ll * fac[i] % p, b[n - i - 1] = finv[i];     }     c = a * b;     for (int i = 0; i < n; i++)       a[i] = c[n + i - 1] * 1ll * qpow(iv[i + 1], m % (p - 1)) % p,       b[n - i - 1] = i & 1 ? p - finv[i] : finv[i];     c = a * b;     for (int i = 0; i < n; i++) printf( %lld  , c[n + i - 1] * 1ll * finv[i] % p);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000001], dp[(1 << 22)], N;   int main() {     scanf( %d , &N);     memset(dp, -1, sizeof dp);     for (int i = 0; i < N; i++) {       scanf( %d , &arr[i]);       dp[arr[i]] = arr[i];     }     for (int i = 0; i < (1 << 22); i++) {       for (int j = 0; j < 22; j++) {         if (i & (1 << j)) {           dp[i] = max(dp[i], dp[i ^ (1 << j)]);         }       }     }     for (int i = 0; i < N; i++) {       int need = dp[((1 << 22) - 1) ^ arr[i]];       printf( %d%c , need, i == N - 1 ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string convert(string s) {     int l = s.size();     if (l % 2 == 1) return s;     string s1 = s.substr(0, l / 2), s2 = s.substr(l / 2);     s1 = convert(s1);     s2 = convert(s2);     if (s1 < s2)       return s1 + s2;     else       return s2 + s1;   }   bool equivalent(string s1, string s2) {     s1 = convert(s1);     s2 = convert(s2);     return s1 == s2;   }   int main() {     string a, b;     cin >> a >> b;     if (equivalent(a, b))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct answer {     int b, c;     bool operator==(answer other) const { return b == other.b && c == other.c; }     bool operator!=(answer other) const { return !(*this == other); }   };   answer eval(string secret, string query) {     string left_s, left_q;     answer ans = {0, 0};     for (int i = 0; i < (int)(4); i++) {       if (secret[i] == query[i])         ans.b++;       else {         left_s.push_back(secret[i]);         left_q.push_back(query[i]);       }     }     while (!left_s.empty()) {       auto it = find(left_q.begin(), left_q.end(), left_s.back());       if (it != left_q.end()) {         left_q.erase(it);         ans.c++;       }       left_s.pop_back();     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<string> q(n);     vector<answer> anss(n);     for (int i = 0; i < (int)(n); i++) {       cin >> q[i] >> anss[i].b >> anss[i].c;     }     vector<string> answers;     for (int a = 0; a < 10; a++) {       for (int b = 0; b < 10; b++) {         if (a == b) continue;         for (int c = 0; c < 10; c++) {           if (a == c || b == c) continue;           for (int d = 0; d < 10; d++) {             if (a == d || b == d || c == d) continue;             string s;             s.push_back( 0  + a);             s.push_back( 0  + b);             s.push_back( 0  + c);             s.push_back( 0  + d);             bool ok = true;             for (int i = 0; i < (int)(n); i++) {               if (anss[i] != eval(s, q[i])) {                 ok = false;               }             }             if (ok) {               answers.push_back(s);             }           }         }       }     }     if (answers.empty()) {       cout <<  Incorrect data  << endl;     } else if (answers.size() > 1) {       cout <<  Need more data  << endl;     } else {       cout << answers[0] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000006;   long long num[MAXN << 2];   long long sum[MAXN << 2];   long long N;   void pushup(int rt) {     num[rt] = num[rt << 1] + num[rt << 1 | 1];     sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];   }   void update(int P, int C, int l, int r, int rt) {     if (l == r) {       num[rt] += C;       sum[rt] += 1ll * P * C;       return;     }     int m = (l + r) / 2;     if (P <= m)       update(P, C, l, m, rt << 1);     else       update(P, C, m + 1, r, rt << 1 | 1);     pushup(rt);   }   long long query(int K, int l, int r, int rt) {     if (l == r) {       if (l == MAXN) {         return 0;       }       if (K > 0) {         return 1ll * K * l;       } else         return 0;     }     int m = (l + r) / 2;     if (num[rt << 1] >= K) {       return query(K, l, m, rt << 1);     } else {       return sum[rt << 1] + query(K - num[rt << 1], m + 1, r, rt << 1 | 1);     }   }   vector<pair<int, int> > C[MAXN];   vector<pair<int, int> > O[MAXN];   int main() {     int K, M;     scanf( %d%d%d , &N, &K, &M);     int l, r, c, p;     for (int i = 0; i < M; i++) {       scanf( %d%d%d%d , &l, &r, &c, &p);       C[l].push_back(make_pair(p, c));       O[r].push_back(make_pair(p, c));     }     long long ans = 0;     for (int i = 1; i <= N; i++) {       for (int j = 0; j < C[i].size(); j++)         update(C[i][j].first, C[i][j].second, 1, MAXN, 1);       ans += query(K, 1, MAXN, 1);       for (int j = 0; j < O[i].size(); j++)         update(O[i][j].first, -O[i][j].second, 1, MAXN, 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return (a > b); }   int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main(void) {     int n, p;     cin >> n >> p;     int l[n], r[n], i;     long long int c, cp, l1, l2;     double ans = 0;     for (i = 0; i < n; ++i) cin >> l[i] >> r[i];     for (i = 0; i < n; ++i) {       l1 = r[i] - l[i] + 1;       l2 = r[(i - 1 + n) % n] - l[(i - 1 + n) % n] + 1;       c = r[i] / p - (l[i] - 1) / p;       cp = r[(i - 1 + n) % n] / p - (l[(i - 1 + n) % n] - 1) / p;       ans += (2000.0 * (c * l2 + cp * l1 - (c * cp))) / (l1 * l2);     }     printf( %.10lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using maxHeap = priority_queue<int>;   using minHeap = priority_queue<int, vector<int>, greater<int>>;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int t, x;     double d, p;     cout << fixed << setprecision(10);     for (cin >> t; t; t--) {       cin >> x;       d = x;       if (x * x - 4 * x < 0) {         cout <<  N n ;       } else {         p = sqrt(d * d - 4 * d);         cout <<  Y   << (d - p) / 2 <<     << (d + p) / 2 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int const N = 3e5 + 3;   int ans[N];   int temp[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     vector<pair<int, pair<int, int>>> edges;     for (int i = (0); i < (m); ++i) {       int u, v, w;       cin >> u >> v >> w;       --u;       --v;       edges.push_back({w, {u, v}});     }     sort(begin(edges), end(edges));     fill(ans, ans + n, 0);     fill(temp, temp + n, 0);     for (int i = (0); i < (m); ++i) {       vector<int> cand;       int cur = edges[i].first;       while (i < m && edges[i].first == cur) {         int u = edges[i].second.first;         int v = edges[i].second.second;         cand.push_back(v);         temp[v] = max(temp[v], ans[u] + 1);         ++i;       }       --i;       for (auto& e : cand) {         ans[e] = max(temp[e], ans[e]);         temp[e] = 0;       }     }     cout << *max_element(ans, ans + n) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vll = vector<ll>;   struct vec {     ll x;     ll y;   };   void solve() {     ll t, sx, sy, ex, ey;     cin >> t >> sx >> sy >> ex >> ey;     string s;     cin >> s;     for (int i = 0, time = 0; i < s.size(); ++i, ++time) {       vec d = {ex - sx, ey - sy};       char quater;       if (d.x > 0 && d.y > 0)         quater = 1;       else if (d.x < 0 && d.y > 0)         quater = 2;       else if (d.x < 0 && d.y < 0)         quater = 3;       else if (d.x > 0 && d.y < 0)         quater = 4;       else if (d.x > 0 && d.y == 0)         quater = 5;       else if (d.x == 0 && d.y > 0)         quater = 6;       else if (d.x < 0 && d.y == 0)         quater = 7;       else         quater = 8;       switch (s[i]) {         case  E :           if (quater == 1 || quater == 4 || quater == 5)             sx++;           else             continue;           break;         case  N :           if (quater == 1 || quater == 2 || quater == 6)             sy++;           else             continue;           break;         case  W :           if (quater == 2 || quater == 3 || quater == 7)             sx--;           else             continue;           break;         case  S :           if (quater == 3 || quater == 4 || quater == 8)             sy--;           else             continue;       }       if (sx == ex && sy == ey) {         cout << time + 1 <<   n ;         return;       }     }     cout << -1 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t = 1;     while (t-- > 0) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   string str;   int main() {     cin >> str;     int hun, ten, one;     if (str.size() == 1) {       if (str[0] ==  8  || str[0] ==  0 ) {         cout <<  YES n ;         cout << str << endl;       } else         cout <<  NO n  << endl;     } else if (str.size() == 2) {       ten = str[0] -  0 ;       ten *= 10;       one = str[1] -  0 ;       if ((ten + one) % 8 == 0) {         cout <<  YES n ;         cout << str << endl;       } else if ((ten / 10 == 8) || one == 8) {         cout <<  YES n ;         cout << 8 << endl;       } else if (!ten || !one) {         cout <<  YES n ;         cout << 0 << endl;       } else         cout <<  NO n  << endl;     } else {       for (int i = 0; i < str.size(); i++)         if (str[i] ==  8  || str[i] ==  0 ) {           cout <<  YES n ;           cout << str[i] << endl;           return 0;         }       for (int i = 0; i < str.size() - 1; i++) {         ten = str[i] -  0 ;         ten *= 10;         for (int j = i + 1; j < str.size(); j++) {           one = str[j] -  0 ;           int temp = ten + one;           if (temp % 8 == 0) {             cout <<  YES n ;             cout << temp << endl;             return 0;           }         }       }       for (int i = 0; i < str.size() - 2; i++) {         hun = str[i] -  0 ;         hun *= 100;         for (int j = i + 1; j < str.size() - 1; j++) {           ten = str[j] -  0 ;           ten *= 10;           for (int k = j + 1; k < str.size(); k++) {             one = str[k] -  0 ;             int temp = hun + ten + one;             if (temp % 8 == 0) {               cout <<  YES n ;               cout << temp << endl;               return 0;             }           }         }       }       cout <<  NO n  << endl;     }     return 0;   }


#include <bits/stdc++.h>   long long n, i, res;   using namespace std;   int main() {     cin >> n;     long long a[n];     for (i = 0; i < n; i++) cin >> a[i];     int l = 0, r = n - 1;     long long suma = 0, sumb = 0;     while (l <= r) {       if (suma < sumb) {         suma += a[l];         l++;       } else {         if (suma == sumb) {           res = max(res, suma);           suma += a[l];           l++;         } else {           sumb += a[r];           r--;         }       }     }     if (suma == sumb) res = max(res, suma);     cout << res;     return 0;   }


#include <bits/stdc++.h>   int main() {     using namespace std;     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m, k, t;     cin >> n >> m >> k >> t;     vector<pair<int, int>> w;     for (int i = 0, r, c; i < k; i++, w.push_back(make_pair(r, c))) cin >> r >> c;     sort(w.begin(), w.end());     const char* s[] = { Carrots ,  Kiwis ,  Grapes };     for (int r, c; t--;) {       cin >> r >> c;       auto v = make_pair(r, c);       auto vi = upper_bound(w.begin(), w.end(), v) - w.begin();       int i = (r - 1) * m + c - 1;       if (vi && w[vi - 1] == v)         cout <<  Waste  <<   n ;       else         cout << s[(i - vi) % 3] <<   n ;     }   }


#include <bits/stdc++.h>   int mut(int x) {     if (x < 0)       return -x;     else       return x;   }   int d[1000001][2];   int d1[1000001][2];   int main(void) {     int ax;     int ay;     int bx;     int by;     int cx;     int cy;     int c = 0;     int min = 99999;     scanf( %d%d%d%d%d%d , &ax, &ay, &bx, &by, &cx, &cy);     int x = ax;     int y = ay;     d[c][0] = ax;     d[c][1] = ay;     c++;     if (bx >= ax && by >= ay) {       for (int i = y; i <= by; i++) {         for (int j = x; j <= bx; j++) {           if (min > mut(i - cy) + mut(j - cx)) {             min = mut(i - cy) + mut(j - cx);             d1[min][0] = j;             d1[min][1] = i;           }         }       }     } else if (bx <= ax && by <= ay) {       for (int i = y; i >= by; i--) {         for (int j = x; j >= bx; j--) {           if (min > mut(i - cy) + mut(j - cx)) {             min = mut(i - cy) + mut(j - cx);             d1[min][0] = j;             d1[min][1] = i;           }         }       }     } else if (bx >= ax && by <= ay) {       for (int i = y; i >= by; i--) {         for (int j = x; j <= bx; j++) {           if (min > mut(i - cy) + mut(j - cx)) {             min = mut(i - cy) + mut(j - cx);             d1[min][0] = j;             d1[min][1] = i;           }         }       }     } else if (bx <= ax && by >= ay) {       for (int i = y; i <= by; i++) {         for (int j = x; j >= bx; j--) {           if (min > mut(i - cy) + mut(j - cx)) {             min = mut(i - cy) + mut(j - cx);             d1[min][0] = j;             d1[min][1] = i;           }         }       }     }     int x1 = d1[min][0];     int y1 = d1[min][1];     if (ax < x1) {       while (x < x1) {         x++;         d[c][0] = x;         d[c][1] = y;         c++;       }     } else if (ax > x1) {       while (x > x1) {         x--;         d[c][0] = x;         d[c][1] = y;         c++;       }     }     if (ay > y1) {       while (y > y1) {         y--;         d[c][0] = x;         d[c][1] = y;         c++;       }     } else if (ay < y1) {       while (y < y1) {         y++;         d[c][0] = x;         d[c][1] = y;         c++;       }     }     x = x1;     y = y1;     if (x1 < bx) {       while (x < bx) {         x++;         d[c][0] = x;         d[c][1] = y;         c++;       }     } else if (x1 > bx) {       while (x > bx) {         x--;         d[c][0] = x;         d[c][1] = y;         c++;       }     }     if (y1 > by) {       while (y > by) {         y--;         d[c][0] = x;         d[c][1] = y;         c++;       }     } else if (y1 < by) {       while (y < by) {         y++;         d[c][0] = x;         d[c][1] = y;         c++;       }     }     x = x1;     y = y1;     if (x1 < cx) {       while (x1 < cx) {         x1++;         d[c][0] = x1;         d[c][1] = y1;         c++;       }     } else if (x1 > cx) {       while (x1 > cx) {         x1--;         d[c][0] = x1;         d[c][1] = y1;         c++;       }     }     if (y1 < cy) {       while (y1 < cy) {         y1++;         d[c][0] = x1;         d[c][1] = y1;         c++;       }     } else if (y1 > cy) {       while (y1 > cy) {         y1--;         d[c][0] = x1;         d[c][1] = y1;         c++;       }     }     printf( %d n , c);     for (int i = 0; i < c; i++) {       printf( %d %d n , d[i][0], d[i][1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q;   int h, w, k;   int a[600][600];   int dist[17][17];   int dp[17][65539];   int from[17][65539];   int pos[17];   int getdown(int x, int y) {     int sum = 0;     for (int i = x - 4; i <= x; i++) {       for (int j = y - 2; j <= y + 2; j++) {         sum += a[i][j];       }     }     return sum;   }   int getup(int x, int y) {     int sum = 0;     for (int i = x; i <= x + 4; i++) {       for (int j = y - 2; j <= y + 2; j++) {         sum += a[i][j];       }     }     return sum;   }   int main() {     cin >> q;     for (int ii = 0; ii < q; ii++) {       scanf( %d %d %d , &h, &w, &k);       for (int i = 0; i < h; i++) {         for (int j = 0; j < w; j++) {           scanf( %d , &a[i][j]);         }       }       for (int i = 0; i < k; i++) {         for (int j = 0; j < k; j++) {           if (i != j) {             dist[i][j] = 0;             for (int kk = 5; kk < w - 5; kk++) {               dist[i][j] += abs(getdown((i + 1) * (h / k) - 1, kk) -                                 getup(j * (h / k), kk));             }           }         }       }       for (int mask = 0; mask < (1 << k); mask++) {         for (int who = 0; who < k; who++) {           dp[who][mask] = 1000000000;         }       }       for (int mask = 0; mask < (1 << k); mask++) {         for (int who = 0; who < k; who++) {           if (!((1 << who) & mask)) {             continue;           }           if (mask == (1 << who)) {             dp[who][mask] = 0;           }           if (dp[who][mask] == 1000000000) {             continue;           }           for (int next = 0; next < k; next++) {             if (!((1 << next) & mask)) {               int NewMask = mask | (1 << next);               if (dp[next][NewMask] > dp[who][mask] + dist[who][next]) {                 dp[next][NewMask] = dp[who][mask] + dist[who][next];                 from[next][NewMask] = who;               }             }           }         }       }       int ans = 1000000000;       int i, j;       for (int who = 0; who < k; who++) {         ans = min(ans, dp[who][(1 << k) - 1]);         if (ans == dp[who][(1 << k) - 1]) {           i = who;           j = (1 << k) - 1;         }       }       vector<int> anss;       while (j != 0) {         int ni = from[i][j];         anss.push_back(i + 1);         j ^= (1 << i);         i = ni;       }       reverse(anss.begin(), anss.end());       for (int i = 0; i < (int)anss.size(); i++) {         pos[anss[i]] = i + 1;       }       for (int i = 1; i <= k; i++) {         printf( %d  , pos[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define int long long int   #define double long double   #define endl   n    const int mod = 1000000007;   using namespace std;      int modExpo(int x , int n)   {    int ans = 1;    while (n > 0) {     if ( n & 1 == 1 ) ans = ( ans * x ) % mod;     x = ( x * x ) % mod; n = n / 2;    }    return ans;   }                                 void solve()   {    vector<int> v(4);    for(int i=0;i<4;i++)     cin>>v[i];       int x = max(v[0] , v[1]);    int y = max(v[2] , v[3]);       if(x < v[2] && x < v[3])    {     cout<< NO n ;     return;    }        if(y < v[0] && y < v[1])    {     cout<< NO n ;     return;    }        cout<< YES n ;    // cout<<x<<y;   }                                 int32_t main()   {   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif       fast;    int tt;    cin >> tt;    while (tt--)    {     solve();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 100 * 1000 + 10;   string s, t;   int d[N];   int LastSeen[N];   void input() {     cin >> s >> t;     return;   }   void PrePros() {     int keep = (int)(t.size()) - 1, pnt = (int)(s.size()) - 1;     while (keep >= 0) {       if (s[pnt] == t[keep]) {         LastSeen[keep] = pnt;         keep--;       }       pnt--;     }     LastSeen[t.size()] = s.size();     t.push_back( * );     return;   }   void solve() {     PrePros();     int lastfound = 0;     for (int i = 0; i < s.size(); i++) {       d[i] = LastSeen[lastfound] - i;       if (s[i] == t[lastfound]) lastfound++;     }     return;   }   void output() {     int ans = 0;     for (int i = 0; i < s.size(); i++) ans = max(ans, d[i]);     cout << ans << endl;     return;   }   int main() {     input();     solve();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   void input() {}   int main() {     fastio();     input();     long long int n;     cin >> n;     long long int sum = -1;     map<long long int, long long int> make_pair;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       make_pair[x - i] += x;       sum = max(sum, make_pair[x - i]);     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a, b, c, d;   int main() {     char st =  e ;     cin >> a >> b >> c >> d;     if (a / b == b / c && b / c == c / d) st =  g ;     if (a - b == b - c && b - c == c - d) st =  a ;     if (st ==  e )       cout << 42 << endl;     else if (st ==  g ) {       int d1 = d, b1 = b, a1 = a;       if (d * b / a == d1 * b1 / a1)         cout << d * b / a << endl;       else         cout << 42 << endl;     } else       cout << d + b - a << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = double;   using pii = pair<int, int>;   using vi = vector<int>;   const int N = 1e5 + 100;   int n, d[N], f[N][2], ans;   vi G[N];   void dfs(int x, int fz) {     f[x][0] = 0, f[x][1] = 1;     for (int y : G[x])       if (y != fz) {         dfs(y, x);         ans = max({ans, f[x][0] + f[y][0], f[x][0] + f[y][1], f[x][1] + f[y][0]});         f[x][0] = max({f[x][0], f[y][0] + d[x] - 2, f[y][1] + d[x] - 2});         f[x][1] = max({f[x][1], f[y][0] + 1});       }     ans = max(ans, f[x][1]);   }   signed main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       G[x].push_back(y), G[y].push_back(x);       d[x]++, d[y]++;     }     dfs(1, 0);     printf( %d n , ans);     fprintf(stderr,  time=%.4f n , (db)clock() / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long r, g, b;     cin >> r >> g >> b;     long long ans = 0;     long long tr, tg, tb;     for (long long i = 0; i <= min({r, g, b, 2LL}); i++) {       long long t = i;       tr = r;       tg = g;       tb = b;       tr -= i;       tg -= i;       tb -= i;       t += (tr / 3 + tg / 3 + tb / 3);       ans = max(ans, t);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T& a, const T& b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T& a, const T& b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const long long int MOD = 1e9 + 7, INF = 1e18;   long long int dx[8] = {0, -1, 1, 0, 1, -1, 1, -1},                 dy[8] = {1, 0, 0, -1, -1, -1, 1, 1};   struct edge {     long long int cost;     long long int u, v;   };   long long int N, M;   long long int mp[200][200];   long long int delta[200][200];   int main() {     cin >> N >> M;     for (long long int i = (0), i_end_ = (N); i < i_end_; i++) {       for (long long int j = (0), j_end_ = (M); j < j_end_; j++) {         cin >> mp[i][j];       }     }     for (long long int i = (0), i_end_ = (N); i < i_end_; i++) {       for (long long int j = (0), j_end_ = (M); j < j_end_; j++) {         delta[i][j] = mp[i][j];       }     }     bool flag = true;     vector<pair<long long int, long long int> > pos;     vector<long long int> _row_ans;     vector<long long int> _column_ans;     _row_ans.push_back(0);     if (mp[0][0] == 0)       _column_ans.push_back(0);     else       _column_ans.push_back(1);     for (long long int i = (0), i_end_ = (M - 1); i < i_end_; i++) {       _column_ans.push_back(mp[0][i] ^ mp[0][i + 1] ^ _column_ans.back());     }     for (long long int i = (0), i_end_ = (N - 1); i < i_end_; i++) {       _row_ans.push_back(mp[i][0] ^ mp[i + 1][0] ^ _row_ans.back());       for (long long int j = (0), j_end_ = (M - 1); j < j_end_; j++) {         if ((mp[0][j] ^ mp[0][j + 1]) != (mp[i + 1][j] ^ mp[i + 1][j + 1])) {           pos.push_back({i + 1, j + 1});           flag = false;         }       }     }     if (flag) {       cout <<  YES  <<   n ;       for (long long int i = (0), i_end_ = (N); i < i_end_; i++)         cout << _row_ans[i];       cout <<   n ;       for (long long int i = (0), i_end_ = (M); i < i_end_; i++)         cout << _column_ans[i];       cout <<   n ;       return 0;     }     if (((long long int)(pos).size()) != 1) {       bool _flag = true;       for (long long int i = (0), i_end_ = (((long long int)(pos).size()));            i < i_end_; i++) {         if (pos[i].first == 0) _flag = false;         if (pos[0].second != pos[i].second) _flag = false;       }       for (long long int i = (0), i_end_ = (((long long int)(pos).size()) - 1);            i < i_end_; i++) {         if (pos[i].first + 1 != pos[i + 1].first) _flag = false;       }       if (((long long int)(pos).size()) != N - 1) _flag = false;       if (_flag) {         long long int r = pos[0].second;         pos.clear();         pos.push_back({0, r});       } else {         cout <<  NO  <<   n ;         return 0;       }     }     for (long long int i = (0), i_end_ = (N); i < i_end_; i++) {       for (long long int j = (0), j_end_ = (M); j < j_end_; j++) {         if (i * M + j >= pos[0].first * M + pos[0].second) mp[i][j] ^= 1;       }     }     _row_ans.clear();     _column_ans.clear();     _row_ans.push_back(0);     if (mp[0][0] == 0)       _column_ans.push_back(0);     else       _column_ans.push_back(1);     for (long long int i = (0), i_end_ = (M - 1); i < i_end_; i++) {       _column_ans.push_back(mp[0][i] ^ mp[0][i + 1] ^ _column_ans.back());     }     for (long long int i = (0), i_end_ = (N - 1); i < i_end_; i++) {       _row_ans.push_back(mp[i][0] ^ mp[i + 1][0] ^ _row_ans.back());     }     cout <<  YES  <<   n ;     for (long long int i = (0), i_end_ = (N); i < i_end_; i++)       cout << _row_ans[i];     cout <<   n ;     for (long long int i = (0), i_end_ = (M); i < i_end_; i++)       cout << _column_ans[i];     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)(1e9 + 7);   const int inf = (int)INFINITY;   const long long INF = (long long)INFINITY;   const int MAX = (int)(2e5 + 5);   const int maxn = 2e5 + 5;   int n, m, k, p[maxn], path[maxn];   vector<int> in[maxn], out[maxn];   int maxa, mina;   set<pair<long long, long long> > st;   void dijkstra() {     while (st.size()) {       pair<long long, long long> x = *st.begin();       st.erase(x);       int i = x.second;       for (auto A : in[i]) {         if (path[i] + 1 < path[A]) {           st.erase(pair<long long, long long>(path[A], A));           path[A] = path[i] + 1;           st.insert(pair<long long, long long>(path[A], A));         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (long long i = 0; i < (m); ++i) {       int u, v;       cin >> u >> v;       out[u].push_back(v);       in[v].push_back(u);     }     cin >> k;     for (int i = 1; i <= k; ++i) cin >> p[i];     memset(path, 63, sizeof path);     path[p[k]] = 0;     st.insert(pair<long long, long long>(0, p[k]));     dijkstra();     for (int i = 2; i <= k; ++i) {       if (path[p[i]] != path[p[i - 1]] - 1) {         ++mina;         ++maxa;       } else {         int e = 0;         for (auto A : out[p[i - 1]])           if (A != p[i] && path[A] == path[p[i]]) e = 1;         maxa += e;       }     }     cout << mina <<     << maxa;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double eps = -1e12;   inline bool eq(const long double &x, const long double &y) {     return abs(x - y) < eps || abs(x - y) < eps * abs(x);   }   int main() {     long double x, y, z;     cin >> x >> y >> z;     string expression[12] = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,                               y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,                               z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };     vector<long double> ans(12, 0);     long double res = -1000;     long double logx = log(x);     long double logy = log(y);     long double logz = log(z);     ans[0] = pow(y, z) * logx;     ans[1] = pow(z, y) * logx;     ans[2] = logx * y * z;     ans[3] = ans[2];     ans[4] = pow(x, z) * logy;     ans[5] = pow(z, x) * logy;     ans[6] = logy * x * z;     ans[7] = ans[6];     ans[8] = pow(x, y) * logz;     ans[9] = pow(y, x) * logz;     ans[10] = logz * y * x;     ans[11] = ans[10];     int index = 0;     for (int i = 0; i < 12; ++i) {       if (ans[i] > res && !eq(ans[i], res)) {         res = ans[i];         index = i;       }     }     cout << expression[index] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double X, Y, Z;     void Get() { scanf( %lf%lf%lf , &X, &Y, &Z); }   };   Point operator-(Point A, Point B) {     return (Point){A.X - B.X, A.Y - B.Y, A.Z - B.Z};   }   double operator*(Point A, Point B) { return A.X * B.X + A.Y * B.Y + A.Z * B.Z; }   const double inf = 1e9;   const double eps = 1e-6;   double Solve(Point A, Point V, double R) {     double a = V * V, b = A * V * 2, c = A * A - R * R;     double Delta = b * b - 4 * a * c;     if (Delta < -eps) return inf;     Delta = sqrt(fabs(Delta));     double T0 = (-b + Delta) / (2 * a), T1 = (-b - Delta) / (2 * a);     return (T0 < 0) ? inf : ((T1 < 0) ? T0 : T1);   }   int main() {     Point O, V;     O.Get();     V.Get();     double R, Ans = inf;     scanf( %lf , &R);     int N;     scanf( %d , &N);     while (N--) {       Point _O;       _O.Get();       double r;       scanf( %lf , &r);       Ans = min(Ans, Solve(O - _O, V, R + r));       int M;       scanf( %d , &M);       while (M--) {         Point Delta;         Delta.Get();         Ans = min(Ans, Solve(O - _O - Delta, V, R));       }     }     if (Ans == inf)       printf( -1 n );     else       printf( %0.10lf n , Ans);     return 0;   }


#include <bits/stdc++.h>   struct Candidate {     std::vector<int> d;     Candidate(std::vector<int> d_) {       d = d_;       std::sort(d.begin(), d.end());       std::reverse(d.begin(), d.end());     }     inline bool operator<(const Candidate &rhs) {       if (d[0] < 0 || rhs.d[0] < 0) return d[0] < rhs.d[0];       for (int i = 0; i < static_cast<int>(d.size()); ++i)         if (d[i] != rhs.d[i]) return d[i] < rhs.d[i];       return false;     }   };   int get_enemy_pos(std::vector<int> locations, bool mate) {     std::cout << locations[0] + 1 <<     << locations[1] + 1 <<                   << locations[2] + 1 << std::endl;     if (!mate) {       int pos;       std::cin >> pos;       return pos - 1;     } else {       return -1;     }   }   std::vector<int> get_dist(std::vector<std::vector<int> > &adj, int src) {     auto d = std::vector<int>(adj.size(), -1);     auto q = std::queue<int>();     q.push(src);     d[src] = 0;     while (!q.empty()) {       int at = q.front();       q.pop();       for (auto &next : adj[at]) {         if (d[next] < 0) {           d[next] = d[at] + 1;           q.push(next);         }       }     }     return d;   }   int main() {     int nodes, edges;     std::cin >> nodes >> edges;     auto adj = std::vector<std::vector<int> >(nodes, std::vector<int>());     for (int edge = 0; edge < edges; ++edge) {       int src, dst;       std::cin >> src >> dst;       adj[src - 1].push_back(dst - 1);       adj[dst - 1].push_back(src - 1);     }     srand(time(NULL));     auto dists = std::vector<std::vector<int> >(static_cast<int>(adj.size()),                                                 std::vector<int>());     int best_dist = nodes + 1;     auto best_locs = std::vector<int>(3, -1);     for (int iter = 0; iter < 5000; ++iter) {       auto locs = std::vector<int>(3);       for (int i = 0; i < static_cast<int>(locs.size()); ++i) {         locs[i] = -1;         bool ok = true;         do {           ok = true;           locs[i] = rand() % nodes;           for (int j = 0; j < i; ++j) {             if (locs[i] == locs[j]) ok = false;           }         } while (!ok);         if (dists[locs[i]].size() == 0) {           dists[locs[i]] = get_dist(adj, locs[i]);         }       }       int cand_dist = 1;       for (int i = 0; i < nodes; ++i) {         cand_dist = std::max(             cand_dist, std::min(dists[locs[0]][i],                                 std::min(dists[locs[1]][i], dists[locs[2]][i])));       }       if (cand_dist < best_dist) {         best_dist = cand_dist;         best_locs = locs;       }     }     auto locs = best_locs;     auto enemy_pos = get_enemy_pos(locs, false);     while (enemy_pos >= 0) {       if (enemy_pos == locs[0] || enemy_pos == locs[1] || enemy_pos == locs[2]) {         break;       }       auto targets = std::vector<int>();       targets.push_back(enemy_pos);       for (int repeats = 0; repeats < 0; ++repeats) {         auto ntargets = std::vector<int>();         for (auto &t : targets)           for (auto &x : adj[t]) {             ntargets.push_back(x);           }         for (auto &nt : ntargets) targets.push_back(nt);         std::sort(targets.begin(), targets.end());         targets.resize(std::unique(targets.begin(), targets.end()) -                        targets.begin());       }       for (auto &x : targets) {         if (dists[x].size() == 0) {           dists[x] = get_dist(adj, x);         }       }       auto d = std::vector<int>(static_cast<int>(locs.size()));       auto best =           Candidate(std::vector<int>(static_cast<int>(locs.size()), nodes + 1));       static int best_locs[] = {-1, -1, -1};       static int by[3];       static int choice[3];       for (int i = 0; i < 3; ++i) {         std::random_shuffle(adj[locs[i]].begin(), adj[locs[i]].end());       }       for (choice[0] = 0; choice[0] <= adj[locs[0]].size(); ++choice[0])         for (choice[1] = 0; choice[1] <= adj[locs[1]].size(); ++choice[1])           for (choice[2] = 0; choice[2] <= adj[locs[2]].size(); ++choice[2]) {             bool mate = false;             for (int i = 0; i < 3; ++i) {               by[i] = (choice[i] == 0 ? locs[i] : adj[locs[i]][choice[i] - 1]);               if (by[i] == enemy_pos) mate = true;             }             if (by[0] == by[1] || by[1] == by[2] || by[0] == by[2]) {               continue;             }             for (int j = 0; j < 3; ++j) d[j] = dists[targets[0]][by[j]];             auto cand = Candidate(d);             if (mate) {               cand.d[0] = -1;             }             if (cand < best) {               best = cand;               for (int i = 0; i < 3; ++i) {                 best_locs[i] = by[i];               }             }           }       locs = std::vector<int>(best_locs, best_locs + 3);       enemy_pos = get_enemy_pos(locs, best.d[0] < 0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<pair<int, int>, int> p[200005];   int t[200005], ans[2000005], a[200005];   void san() {     for (int i = 1; i <= n; ++i) t[i] = p[i].first.first;     sort(t + 1, t + 1 + n);     for (int i = 1; i <= n; ++i)       p[i].first.first = lower_bound(t + 1, t + 1 + n, p[i].first.first) - t;   }   bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {     return a.first.second < b.first.second;   }   void add(int x) {     while (x <= n) {       a[x]++;       x += x & (-x);     }   }   int getSum(int x) {     int res = 0;     while (x >= 1) {       res += a[x];       x -= x & (-x);     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &p[i].first.first, &p[i].first.second);       p[i].second = i;     }     san();     sort(p + 1, p + 1 + n, cmp);     for (int i = 1; i <= n; ++i) {       ans[p[i].second] = i - 1 - getSum(p[i].first.first);       add(p[i].first.first);     }     for (int i = 1; i <= n; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y, z;     cin >> x;     cin >> y;     cin >> z;     x += y;     sort(x.begin(), x.end());     sort(z.begin(), z.end());     if (x.length() != z.length())       cout <<  NO             <<   n ;     else {       for (int i = 0; i < x.length(); i++) {         if (x[i] != z[i]) {           cout <<  NO                 <<   n ;           return 0;         }       }       cout <<  YES             <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 510;   int n, k;   int a[MAX], b[MAX];   void init() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     cin >> k;     for (int i = 1; i <= k; i++) cin >> b[i];   }   bool valid(int i, int l, int r) {     int x = i, y = i, sum = a[i];     while (true) {       int old_x = x, old_y = y;       while (x - 1 >= l && sum > a[x - 1]) {         x--;         sum += a[x];       }       while (y + 1 <= r && sum > a[y + 1]) {         y++;         sum += a[y];       }       if (old_x == x && old_y == y) break;     }     return x == l && y == r;   }   void print(int i, int l, int r) {     int x = i, y = i, sum = a[i];     while (true) {       int old_x = x, old_y = y;       while (x - 1 >= l && sum > a[x - 1]) {         cout << x <<   L  <<   n ;         x--;         sum += a[x];       }       while (y + 1 <= r && sum > a[y + 1]) {         cout << x <<   R  <<   n ;         y++;         sum += a[y];       }       if (old_x == x && old_y == y) break;     }   }   void process() {     vector<pair<int, pair<int, int> > > p;     bool found = true;     int l, r = n, pb = k;     while (r >= 1 && pb >= 1) {       l = r;       int sum = a[r];       while (l - 1 >= 1 && a[l - 1] + sum <= b[pb]) {         l--;         sum += a[l];       }       if (sum == b[pb]) {         bool exist = false;         for (int i = l; i <= r; i++)           if (valid(i, l, r)) {             exist = true;             p.push_back(make_pair(i, make_pair(l, r)));             break;           }         if (exist) {           sum = 0;           pb--;         } else {           found = false;           break;         }       } else {         found = false;         break;       }       r = l - 1;     }     if (r != 0 || pb != 0) found = false;     if (!found)       cout <<  NO ;     else {       cout <<  YES  <<   n ;       for (int i = 0; i < (int)p.size(); i++)         print(p[i].first, p[i].second.first, p[i].second.second);     }   }   int main() {     ios_base::sync_with_stdio(false);     init();     process();   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void debug(T a, T b) {     ;   }   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   namespace std {   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   }  // namespace std   long long int readL() {     long long int res;     scanf( %I64d , &res);     return res;   }   void printL(long long int res) { printf( %I64d , res); }   int n, m, n2;   int g[2005][2005];   int order[2005], low[2005], cnt;   stack<int> cur;   int group[2005], gcnt;   int dfs(int v, int p) {     order[v] = cnt++;     low[v] = order[v];     cur.push(v);     for (int i = 0; i < (n); ++i)       if (g[v][i]) {         int to = i;         if (to == p) continue;         if (order[to] != -1) {           low[v] = min(low[v], order[to]);         } else {           low[v] = min(low[v], dfs(to, v));         }       }     if (low[v] < order[v]) return low[v];     while (!cur.empty() && cur.top() != v) {       group[cur.top()] = gcnt;       cur.pop();     }     group[cur.top()] = gcnt;     cur.pop();     ++gcnt;     return low[v];   }   vector<int> g2[2005];   int size[2005];   int subsize[2005];   void prep(int v, int p) {     subsize[v] = size[v];     for (auto to : g2[v]) {       if (to == p) continue;       prep(to, v);       subsize[v] += subsize[to];     }   }   bool tmp[4005];   int dfs2(int v, int p) {     int res = 0;     for (auto to : g2[v]) {       if (to == p) continue;       res += dfs2(to, v);     }     if (p != -1) {       res += size[v] * (subsize[v] - size[v]);     } else {       res += size[v] * (subsize[v] - size[v]);       int sub = subsize[v] - size[v];       memset((tmp), 0, sizeof(tmp));       tmp[0] = true;       for (auto to : g2[v]) {         for (int j = n2; j >= 0; --j)           if (tmp[j]) tmp[j + subsize[to]] = true;       }       int maxi = -1;       for (int i = 0; i < (n2 + 1); ++i)         if (tmp[i]) chmax(maxi, i * (sub - i));       res += maxi;     }     return res;   }   int main() {     cin >> n >> m;     for (int i = 0; i < (m); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a;       --b;       g[a][b] = g[b][a] = 1;     }     memset(order, -1, sizeof(order));     dfs(0, -1);     n2 = n;     ;     ;     debug(group, group + n);     for (int i = 0; i < (n); ++i) {       size[group[i]]++;       for (int j = 0; j < (n); ++j)         if (g[i][j] && group[i] != group[j] && i > j) {           g2[group[i]].push_back(group[j]);           g2[group[j]].push_back(group[i]);         }     };     ;     n = gcnt;     for (int i = 0; i < (n); ++i) debug((g2[i]).begin(), (g2[i]).end());     int res = 0;     for (int i = 0; i < (n); ++i) {       prep(i, -1);       bool fail = 0;       for (auto to : g2[i])         if (subsize[to] * 2 > n2) {           fail = 1;         }       if (!fail) {         int tmp = dfs2(i, -1);         chmax(res, tmp);       }     }     for (int i = 0; i < (n); ++i) res += size[i] * size[i];     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2 * 50004];   int main(void) {     int n, k;     cin >> n >> k;     for (int i = 1; i <= 2 * n; i++) {       a[i] = i;     }     for (int i = 1; i <= k; i++) {       swap(a[2 * i], a[2 * i - 1]);     }     for (int i = 1; i <= 2 * n; i++) {       cout << a[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     cout <<  0  ;     vector<int> cnt(110, 0);     cnt[a[0]]++;     for (int w = 1; w < n; ++w) {       int s = a[w];       int k = 0;       for (int i = 1; i <= 100; ++i) {         if (s + i * cnt[i] <= m) {           s += i * cnt[i];           k += cnt[i];         } else {           int l = -1, r = cnt[i] + 1;           while (r - l > 1) {             int mid = (l + r) / 2;             if (s + i * mid <= m) {               l = mid;             } else {               r = mid;             }           }           k += l;           break;         }       }       cout << w - k <<    ;       cnt[a[w]]++;     }   }


#include <bits/stdc++.h>   const int N = 100010;   using namespace std;   namespace YKY {   inline int rnd() {     int res = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       res = res * 10 + ch -  0 ;       ch = getchar();     }     return res * f;   }   inline void wr(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) wr(x / 10);     putchar(x % 10 +  0 );   }   char s[N];   int n, m, k;   int Main() {     n = rnd();     m = rnd();     k = rnd();     scanf( %s , s + 1);     m = m + k;     for (int i = 1, opt, l, r, c; i <= m; i++) {       opt = rnd();       l = rnd();       r = rnd();       c = rnd();       if (opt == 1)         memset(s + l, c +  0 , r - l + 1);       else         puts(memcmp(s + l, s + l + c, r - l - c + 1) ?  NO  :  YES );     }     return 0;   }   }  // namespace YKY   int main() { return YKY ::Main(); }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     bool operator<(const point &other) const {       return x <= other.x && y <= other.y;     }   };   map<int, set<point> > m;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       point p;       scanf( %d %d , &p.x, &p.y);       m[p.y - p.x].insert(p);     }     vector<point> v;     bool ok = true;     for (int i = 0; i < n; i++) {       int d;       scanf( %d , &d);       if (m.find(d) == m.end())         ok = false;       else if (m[d].size() == 0)         ok = false;       else {         v.push_back(*m[d].begin());         m[d].erase(m[d].begin());       }     }     if ((int)v.size() != n || !ok) {       printf( NO );       return 0;     }     for (int i = 1; i < v.size(); i++) {       if (v[i] < v[i - 1]) {         printf( NO n );         return 0;       }     }     printf( YES n );     for (int i = 0; i < v.size(); i++) {       printf( %d %d n , v[i].x, v[i].y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int a[maxn];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     if (n > min(m, k))       printf( No n );     else       printf( Yes n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 1) + (x << 3) + ch -  0 ;     return x * f;   }   const int N = 250025;   const int M = 1e6 + 10;   int n, m, k, w0, w1, tot;   int u[M], nex[M], a[5];   int h[N], b[N], deep[N], fa[N];   void addedge(int w0, int w1) {     u[++tot] = w1;     nex[tot] = h[w0];     h[w0] = tot;   }   void dfs(int w, int depth) {     if (depth > w1) w0 = w;     deep[w] = depth;     bool leaf = true;     for (int i = h[w]; i; i = nex[i])       if (!deep[u[i]]) {         fa[u[i]] = w;         dfs(u[i], depth + 1);         leaf = false;       }     if (leaf) b[tot++] = w;   }   int main() {     n = read();     m = read();     k = read();     while (m--) {       w0 = read();       w1 = read();       addedge(w0, w1);       addedge(w1, w0);     }     w1 = n / k;     w0 = tot = 0;     fa[1] = 1;     dfs(1, 1);     if (w0) {       printf( PATH n%d n , deep[w0]);       for (; w0 != 1; w0 = fa[w0]) printf( %d  , w0);       printf( 1 n );     } else {       printf( CYCLES n );       for (int i = 0; i < k; i++) {         int j = h[w0 = b[i]];         tot = 0;         for (int cnt = 3; cnt; j = nex[j], cnt--)           if (u[j] != fa[w0]) a[tot++] = u[j];         if ((deep[w0] - deep[a[0]] + 1) % 3 != 0) {           printf( %d n , deep[w0] - deep[a[0]] + 1);           for (; w0 != a[0]; w0 = fa[w0]) printf( %d  , w0);           printf( %d n , a[0]);         } else if ((deep[w0] - deep[a[1]] + 1) % 3 != 0) {           printf( %d n , deep[w0] - deep[a[1]] + 1);           for (; w0 != a[1]; w0 = fa[w0]) printf( %d  , w0);           printf( %d n , a[1]);         } else {           if (deep[a[0]] < deep[a[1]]) swap(a[0], a[1]);           printf( %d n , deep[a[0]] - deep[a[1]] + 2);           printf( %d  , w0);           for (w0 = a[0]; w0 != a[1]; w0 = fa[w0]) printf( %d  , w0);           printf( %d n , a[1]);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int t;     cin >> t;     bool even;     bool odd;     for (int i = 1; i <= t; i++) {       int size;       even = false;       odd = false;       cin >> size;       int arr[size];       for (int j = 0; j < size; j++) cin >> arr[j];       for (int j = 0; j < size; j++)         if (arr[j] % 2 == 0)           even = true;         else           odd = true;       if (even == true && odd == true)         cout <<  YES  << endl;       else if (even == false && size % 2 != 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vint = vector<int>;   using pint = pair<int, int>;   using vpint = vector<pint>;   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   template <class A, class B>   ostream& operator<<(ostream& ost, const pair<A, B>& p) {     ost <<  {  << p.first <<  ,  << p.second <<  } ;     return ost;   }   template <class T>   ostream& operator<<(ostream& ost, const vector<T>& v) {     ost <<  { ;     for (int i = 0; i < v.size(); i++) {       if (i) ost <<  , ;       ost << v[i];     }     ost <<  } ;     return ost;   }   struct Cactus {     vector<vector<int>> G;     vector<vector<int>> cs;     vector<int> vis, par, dep;     void dfs(int v) {       vis[v] = 1;       for (auto u : G[v]) {         if (!vis[u]) {           par[u] = v;           dep[u] = dep[v] + 1;           dfs(u);         } else if (dep[u] < dep[v]) {           int w = v;           vector<int> c{w};           while (true) {             w = par[w];             c.push_back(w);             if (w == u) break;           }           cs.push_back(c);         }       }     }     Cactus(const vector<vector<int>>& G) : G(G) {       vis.resize(G.size());       par.resize(G.size());       dep.resize(G.size());       dfs(0);     }   };   int N, M;   int A[555555], B[555555];   int info[555555];   int dp[555555];   int memA[555555], memB[555555];   signed main() {     scanf( %d%d , &N, &M);     vint lis;     vector<vint> G(N);     map<pint, int> edgeID;     for (int i = 0; i < (M); i++) {       scanf( %d%d , &A[i], &B[i]);       A[i]--;       B[i]--;       G[A[i]].push_back(B[i]);       G[B[i]].push_back(A[i]);       edgeID[{A[i], B[i]}] = i;       edgeID[{B[i], A[i]}] = i;     }     Cactus cac(G);     fill_n(info, M, -1);     for (auto c : cac.cs) {       if (c.size() == 2) continue;       vint id;       for (int i = 0; i < (c.size()); i++) {         int a = c[i];         int b = c[(i + 1) % c.size()];         id.push_back(edgeID[{a, b}]);       }       rotate(id.begin(), min_element((id).begin(), (id).end()), id.end());       int m = max_element((id).begin(), (id).end()) - id.begin();       bool ok = true;       for (int i = 0; i < m; i++)         if (id[i] > id[i + 1]) ok = false;       for (int i = m; i + 1 < id.size(); i++)         if (id[i] < id[i + 1]) ok = false;       if (!ok) continue;       info[id[0]] = id[m];     }     for (int i = 0; i < (N); i++) dp[i] = 1;     for (int i = M - 1; i >= 0; i--) {       int addA = dp[B[i]];       int addB = dp[A[i]];       if (info[i] != -1) {         int k = info[i];         int tmp = memA[k] + memB[k];         addA -= tmp;         addB -= tmp;       }       memA[i] = dp[A[i]];       memB[i] = dp[B[i]];       dp[A[i]] += addA;       dp[B[i]] += addB;     }     for (int i = 0; i < (N); i++) dp[i]--;     for (int i = 0; i < (N); i++) {       if (i) printf(   );       printf( %d , dp[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   using namespace std;   pair<int, int> a[12345];   vector<int> ans[3];   map<pair<int, int>, bool> used;   map<int, int> cnts;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i].first);       a[i].second = i + 1;       cnts[a[i].first]++;     }     int x = 0, y = 0;     for (map<int, int>::iterator it = cnts.begin(); it != cnts.end(); ++it) {       if (it->second >= 3)         y++;       else {         if (it->second == 2) {           x++;         }       }     }     if (x >= 2 || y >= 1) {       puts( YES );       sort(a, a + n);       for (int i = 0; i < n; ++i) {         ans[0].push_back(a[i].second);         if (i != n) {           used[make_pair(i, i + 1)] = false;           used[make_pair(i + 1, i)] = false;         }       }       int temp;       for (int i = 0; i < n - 1; ++i) {         if (!used[make_pair(i, i + 1)] && a[i].first == a[i + 1].first) {           temp = a[i].second;           a[i].second = a[i + 1].second;           a[i + 1].second = temp;           used[make_pair(i, i + 1)] = true;           used[make_pair(i + 1, i)] = true;           break;         }       }       for (int i = 0; i < n; ++i) {         ans[1].push_back(a[i].second);       }       for (int i = 0; i < n - 1; ++i) {         if (!used[make_pair(i, i + 1)] && a[i].first == a[i + 1].first) {           temp = a[i].second;           a[i].second = a[i + 1].second;           a[i + 1].second = temp;           used[make_pair(i, i + 1)] = true;           used[make_pair(i + 1, i)] = true;           break;         }       }       for (int i = 0; i < n; ++i) {         ans[2].push_back(a[i].second);       }       for (int i = 0; i < 3; ++i) {         for (int j = 0; j < ans[i].size(); ++j) {           printf( %d  , ans[i][j]);         }         printf(  n );       }     } else {       cout <<  NO  << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void max_swap(T& a, const T& b) {     a = max(a, b);   }   template <class T>   void min_swap(T& a, const T& b) {     a = min(a, b);   }   const double EPS = 1e-8;   const double PI = acos(-1.0);   const int dx[] = {0, 1, 0, -1};   const int dy[] = {1, 0, -1, 0};   bool valid_pos(int x, int y, int w, int h) {     return 0 <= x && x < w && 0 <= y && y < h;   }   int main() {     ios::sync_with_stdio(false);     string s, t;     cin >> s >> t;     int n = s.size(), m = t.size();     static int dp[5555][5555];     const int mod = 1000000007;     for (int i = 0; i < n; ++i) {       int sum = 0;       for (int j = 0; j < m; ++j) {         if (s[i] == t[j]) {           (dp[i + 1][j + 1] += sum + 1) %= mod;         }         (sum += dp[i][j + 1]) %= mod;       }     }     int res = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) (res += dp[i + 1][j + 1]) %= mod;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char block[][3][4] = {{ ### ,  .#. ,  .#. },                         { #.. ,  ### ,  #.. },                         { .#. ,  .#. ,  ### },                         { ..# ,  ### ,  ..# }};   int cell[10][10], anscell[10][10];   int bcnt, ans;   bool isPlacable(int i, int j, int k) {     for (int p = 0; p < 3; ++p)       for (int q = 0; q < 3; ++q) {         if (cell[i + p][j + q] != -1 && block[k][p][q] ==  # ) return false;       }     return true;   }   void setBlock(int i, int j, int k) {     for (int p = 0; p < 3; ++p)       for (int q = 0; q < 3; ++q) {         if (block[k][p][q] ==  # ) cell[i + p][j + q] = bcnt;       }     ++bcnt;   }   void removeBlock(int i, int j, int k) {     for (int p = 0; p < 3; ++p)       for (int q = 0; q < 3; ++q) {         if (block[k][p][q] ==  # ) cell[i + p][j + q] = -1;       }     --bcnt;   }   void go(int i, int j) {     if (j >= m - 2) {       go(i + 1, 0);       return;     }     if (i == n - 2) {       if (ans < bcnt) {         ans = bcnt;         memcpy(anscell, cell, sizeof(cell));       }       return;     }     if (bcnt + (n * m - (i * m + j)) / 6 <= ans) {       return;     }     for (int k = 0; k < 4; ++k) {       if (isPlacable(i, j, k)) {         setBlock(i, j, k);         go(i, j + (k == 3 ? 3 : 2));         removeBlock(i, j, k);       }     }     go(i, j + 1);   }   int main() {     memset(cell, -1, sizeof(cell));     memset(anscell, -1, sizeof(anscell));     scanf( %d %d , &n, &m);     if (n >= 3 && m >= 3) go(0, 0);     printf( %d n , ans);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         putchar(anscell[i][j] == -1 ?  .  : ( A  + anscell[i][j]));       }       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, o = 0, e = 0;     cin >> n;     for (i = 0; i < n; i = i + 1) {       long long int x;       cin >> x;       if (x % 2 == 0)         e = e + 1;       else         o = o + 1;     }     long long int res = min(o, e);     o = o - res;     res = res + (o / 3);     cout << res << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const long long N = 1e5 + 5;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s;     cin >> s;     vector<long long> pref(n + 2), suff(n + 2);     for (long long i = 1; i <= n; i++) {       if (s[i - 1] ==  G ) {         pref[i] = 1;         pref[i] += pref[i - 1];       }     }     for (long long i = n; i >= 1; i--) {       if (s[i - 1] ==  G ) {         suff[i] = 1;         suff[i] += suff[i + 1];       }     }     long long ans = 0;     long long cnt = 0;     for (long long i = 1; i <= n; i++) {       if (s[i - 1] ==  G ) cnt++;       ans = max(ans, pref[i]);     }     for (long long i = 1; i <= n; i++) {       if (s[i - 1] ==  S ) {         if (i == 4) {           debug() <<   [                    <<  pref[i - 1]                        :                     << (pref[i - 1])                   <<  ]                          [                    <<  suff[i + 1]                        :                     << (suff[i + 1]) <<  ]  ;         }         if (pref[i - 1] + suff[i + 1] < cnt)           ans = max(ans, pref[i - 1] + suff[i + 1] + 1);         else if (pref[i - 1] + suff[i + 1] == cnt) {           ans = max(ans, pref[i - 1] + suff[i + 1]);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using cd = complex<ld>;   int query(int l, int r) {     cout <<  ?   << l <<     << r << endl;     cin >> l;     return l;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> sums;     for (int i = 1; i < n; i++) {       sums.push_back(query(i, i + 1));     }     int sum123 = query(1, 3);     vector<int> a(n);     int a2 = sums[0] + sums[1] - sum123;     a[0] = sums[0] - a2;     a[1] = a2;     for (int i = 2; i < n; i++) {       a[i] = sums[i - 1] - a[i - 1];     }     cout <<  !  ;     for (int x : a) {       cout << x <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ar[100009], f[100009], b[100009], fl = 1;   map<long long, long long> mb, mf;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> f[i];       mf[f[i]]++;       ar[f[i]] = i;     }     for (long long i = 1; i <= m; i++) {       cin >> b[i];       mb[b[i]]++;     }     for (auto pp : mb) {       long long x = pp.first;       if (mf[x] == 0) {         cout <<  Impossible  << endl;         return 0;       }       if (mf[x] != 1) fl = 0;     }     if (!fl)       cout <<  Ambiguity  << endl;     else {       cout <<  Possible  << endl;       for (long long i = 1; i <= m; i++) {         long long x = b[i];         cout << ar[x] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, x = 0;     scanf( %d , &n);     for (i = 2; i <= n / 2; i += 2) {       if ((n - i) % 2 == 0 && i / 2 != (n - i) / 2) x++;     }     printf( %d n , x);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> foo;   long long add = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       foo.push_back(k);     }     cout << n + 1 <<   n ;     for (int i = foo.size() - 1; i >= 0; i--) {       foo[i] += add;       foo[i] %= n;       int q = i - foo[i] + n;       add += q;       cout << 1 <<     << i + 1 <<     << q <<   n ;     }     cout << 2 <<     << n <<     << n;     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d, num, e;     int flag = 1;     scanf(  %d , &num);     num++;     while (1) {       e = num;       a = num % 10;       num = num / 10;       b = num % 10;       num = num / 10;       c = num % 10;       d = num / 10;       if (a != b && a != c && a != d && b != c && b != d && c != d) {         break;       } else {         e++;         num = e;       }     }     printf( %d , e);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int MMAX = 1e4 + 7;   const int MAXDEG = 55;   long long v[MAXDEG][MMAX];   vector<long long int> revs = {0};   void rev_begin() {     vector<long long int> y;     long long t = MOD - 2;     while (t > 0) {       y.push_back(t % 2);       t /= 2;     }     for (int i = 1; i < MAXDEG; i++) {       vector<long long int> a;       long long s = i;       for (int j = 0; j < 100; j++) {         a.push_back(s % MOD);         s = s * s;         s %= MOD;       }       long long ansy = 1;       for (int j = 0; j < y.size(); j++) {         if (y[j] == 1) {           ansy *= a[j];           ansy %= MOD;         }       }       revs.push_back(ansy);     }   }   void clr() {     for (int i = 0; i < MMAX; i++)       for (int j = 0; j < MAXDEG; j++) v[j][i] = 0;   }   void show() {     for (int i = 0; i < 10; i++) {       for (int j = 0; j < 5; j++) {         cout << v[i][j] <<    ;       }       cout << endl;     }   }   void doit(long long int u, int alpha) {     clr();     long long p = 1;     for (int j = 0; j < alpha + 1; j++) {       v[j][0] = p % MOD;       p *= u;       p %= MOD;     }     for (int i = 1; i < MMAX; i++) {       for (int j = 0; j < alpha + 1; j++) {         for (int l = 0; l <= j; l++) {           v[j][i] += (v[l][i - 1] * revs[j + 1]) % MOD;           v[j][i] %= MOD;         }       }     }   }   int main() {     long long n, k;     rev_begin();     cin >> n >> k;     long long ans = 1;     long long t = 2;     while (t * t <= n) {       while (t * t <= n && n % t != 0) t++;       if (n % t == 0) {         int alpha = 0;         while (n % t == 0) {           alpha++;           n /= t;         }         doit(t, alpha);         ans *= v[alpha][k];         ans %= MOD;       }     }     if (n > 1) {       t = n;       doit(t, 1);       ans *= v[1][k];       ans %= MOD;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long ans = 0;     int n;     cin >> n;     char str[65000];     cin >> str;     for (int i = 0; i < n; i++) {       if ((str[i] -  0 ) % 2 == 0) {         ans += i + 1;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a[2000007];   vector<int> deg(2000007, 0);   vector<pair<int, int>> ans;   int n, m;   void bfs(int node) {     vector<bool> used(n);     used[node] = true;     queue<int> q;     q.push(node);     while (!q.empty()) {       int currnode = q.front();       q.pop();       for (auto x : a[currnode]) {         if (used[x]) continue;         ans.push_back({x, currnode});         used[x] = true;         q.push(x);       }     }   }   void solve() {     cin >> n >> m;     int u, v;     for (int i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       a[u].push_back(v);       a[v].push_back(u);       deg[u]++;       deg[v]++;     }     int maxnode = 0;     for (int i = 0; i < n; i++) {       if (deg[maxnode] < deg[i]) maxnode = i;     }     bfs(maxnode);     for (auto x : ans) {       cout << x.first + 1 <<     << x.second + 1 << endl;     }   }   int main() {     int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > s0, s;   int K;   long long xx[200010], yy[200010];   void func(long long x, long long y) {     while (K > 0 && yy[K - 1] < y) K--;     while (K >= 2) {       long long tmp = (x - xx[K - 2]) * (yy[K - 1] - yy[K - 2]) -                       (xx[K - 1] - xx[K - 2]) * (y - yy[K - 2]);       if (tmp < 0)         K--;       else         break;     }     xx[K] = x;     yy[K] = y;     K++;   }   int main(void) {     int N, M, x, y, i;     cin >> N >> M >> x >> y;     for ((i) = 0; (i) < (int)(N); (i)++) {       scanf( %d%d , &x, &y);       s0.insert(make_pair(x, y));       s.insert(make_pair(x, -y));     }     for ((i) = 0; (i) < (int)(M); (i)++) {       scanf( %d%d , &x, &y);       s.insert(make_pair(x, -y));     }     for (__typeof((s).begin()) itr = (s).begin(); itr != (s).end(); itr++) {       x = (*itr).first;       y = (*itr).second;       func(x, -y);     }     int tp;     string ans =  Min ;     for ((i) = 0; (i) < (int)(K); (i)++) {       if (s0.find(make_pair(xx[i], yy[i])) != s0.end()) ans =  Max ;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     char s[1001];     char t[1001];     scanf( %s %s , s, t);     int idx = 0;     while (s[idx] !=   0 ) {       if (t[idx] ==   0 ) {         puts( No );         return 0;       }       char cs = s[idx];       char ct = t[idx];       int cvowel = 0;       int tvowel = 0;       if (cs ==  a  || cs ==  e  || cs ==  i  || cs ==  o  || cs ==  u )         cvowel = 1;       if (ct ==  a  || ct ==  e  || ct ==  i  || ct ==  o  || ct ==  u )         tvowel = 1;       if (cvowel != tvowel) {         puts( No );         return 0;       }       idx++;     }     if (t[idx] !=   0  && s[idx] ==   0 ) {       puts( No );       return 0;     }     puts( Yes );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int kolvo = 0;     int kolvo1 = 0;     for (int i = 0; i < n; i++) {       if (a[i] == 5) {         kolvo++;       }       if (a[i] == 0) {         kolvo1++;       }     }     sort(a.rbegin(), a.rend());     if ((kolvo / 9) > 0 and kolvo1 > 0) {       for (int i = 0; i < (kolvo / 9) * 9; i++) {         cout << a[i];       }       sort(a.begin(), a.end());       for (int i = 0; i < kolvo1; i++) {         cout << a[i];       }     } else {       if (kolvo1 > 0) {         cout << 0;       } else {         cout << -1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200200;   vector<long long int> g[N], e[N];   set<pair<long long int, long long int> > S;   int n, m;   long long int d[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       long long int x, y, z;       cin >> x >> y >> z;       g[x].push_back(y);       e[x].push_back(z);       g[y].push_back(x);       e[y].push_back(z);     }     for (int i = 1; i <= n; i++) {       cin >> d[i];       S.insert(make_pair(d[i], i));     }     while (S.size() != 0) {       int u = S.begin()->second;       S.erase(S.begin());       for (int i = 0; i < g[u].size(); i++) {         long long int v = g[u][i];         long long int cost = e[u][i];         if (cost * 2 + d[u] < d[v]) {           S.erase(make_pair(d[v], v));           d[v] = cost * 2 + d[u];           S.insert(make_pair(d[v], v));         }       }     }     for (int i = 1; i <= n; i++) {       cout << d[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long mod = 1000000007;   const double e = 2.718281828459;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long gcd1(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   long long pow_mod(long long a, long long b, long long c) {     long long ans = 1;     a = a % c;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % c;       b = b / 2;       a = (a * a) % c;     }     return ans;   }   int pow_int(int a, int b) {     int ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = ans * a;       b = b / 2;       a = a * a;     }     return ans;   }   long long pow_llong(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = ans * a;       b = b / 2;       a = a * a;     }     return ans;   }   const int dx[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0};   const int dy[9] = {0, 1, 0, -1, -1, -1, 0, 1, 1};   int Scan() {     int res = 0, flag = 0;     char ch;     if ((ch = getchar()) ==  - ) {       flag = 1;     } else if (ch >=  0  && ch <=  9 ) {       res = ch -  0 ;     }     while ((ch = getchar()) >=  0  && ch <=  9 ) {       res = res * 10 + (ch -  0 );     }     return flag ? -res : res;   }   void Out(int a) {     if (a < 0) {       putchar( - );       a = -a;     }     if (a >= 10) {       Out(a / 10);     }     putchar(a % 10 +  0 );   }   long long jc_mod(long long a, long long b, long long mod) {     long long ans = 1;     b = max(b, a - b);     for (long long i = a; i > b; i--) {       ans *= i;       ans %= mod;     }     return ans;   }   double lg(double a) { return (log(a) / log(10.0)); }   int lowbit(int x) { return x & -x; }   inline int read() {     int f = 1, x = 0;     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;   }   void lisan(int *x, int n) {     int data[100010];     for (int i = 1; i <= n; i++) data[i] = x[i];     sort(data + 1, data + 1 + n);     int o = unique(data + 1, data + 1 + n) - data - 1;     for (int i = 1; i <= n; i++)       x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;   }   long long calc(int M) { return 1; }   int sanfen(int L, int R) {     int M, RM;     while (L + 1 < R) {       M = (L + R) / 2;       RM = (M + R) / 2;       if (calc(M) < calc(RM))         R = RM;       else         L = M;     }     return L;   }   int CaculateWeekDay(int y, int m, int d) {     if (m == 1 || m == 2) {       m += 12;       y--;     }     int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;     return iWeek;   }   map<string, int> mm;   map<char, int> cc;   string a;   char t[100];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cin >> a;       int q = 0;       cc.clear();       int len = a.length();       for (int i = 0; i < len; i++) {         if (!cc[a[i]]) {           cc[a[i]] = 1;           t[q++] = a[i];         }       }       t[q] = 0;       sort(t, t + q);       string y = t;       mm[y] = 1;     }     printf( %d n , mm.size());     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, h, m, h0, m0, c(1), cash(1);     scanf( %d , &n);     scanf( %d%d , &h0, &m0);     while (--n) {       scanf( %d%d , &h, &m);       if (h == h0 && m == m0) {         c += 1;         if (c > cash) {           cash = c;         }       } else {         c = 1;       }       h0 = h;       m0 = m;     }     printf( %d n , cash);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int count = 0;     vector<long long> ans;     int k = 0;     for (int i = 0; i < n; i++) {       int u;       scanf( %d , &u);       if (count > 0 && u != 0) {         if (k != 0)           ans.push_back(count + 1);         else {           ans.push_back(1);           k = 1;         }         count = 0;       } else if (count > 0 && u == 0) {         count++;       } else if (u == 0) {         count++;       } else {         k = 1;       }     }     if (count > 0 && k != 0) {       ans.push_back(1);     } else if (count > 0 && k == 0) {       ans.push_back(0);     }     long long ans1 = 1;     for (int i = 0; i < ans.size(); i++) {       ans1 = ans1 * (ans[i]);     }     printf( %lld n , ans1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     for (; ~scanf( %d%d , &n, &m);) {       if (n == 1) {         if (m == 1)           puts( 0 );         else {           for (int i = 1; i <= m; ++i) printf( %d  , i + 1);           puts(  );         }       } else {         if (m == 1)           for (int i = 1; i <= n; ++i) printf( %d n , i + 1);         else           for (int i = 1; i <= n; ++i) {             for (int j = 1; j <= m; ++j) printf( %d  , i * (j + n));             puts(  );           }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > V1, V2;   int n, s;   int main() {     while (~scanf( %d%d , &n, &s)) {       V1.clear();       V2.clear();       long long sum1 = 0;       long long sum2 = 0;       long long ans = 0;       for (int i = 0; i < n; i++) {         long long a, b, c;         scanf( %lld%lld%lld , &c, &a, &b);         if (a > b) {           sum1 += c;           ans += c * a;           V1.push_back(make_pair(a - b, c));         } else {           sum2 += c;           ans += c * b;           V2.push_back(make_pair(b - a, c));         }       }       sum1 %= s;       sum2 %= s;       if (sum1 + sum2 > s) {         cout << ans << endl;         continue;       } else {         sort(V1.begin(), V1.end());         sort(V2.begin(), V2.end());         long long tmp1 = 0;         long long tmp2 = 0;         int len = V1.size();         for (int i = 0; i < len; i++) {           tmp1 += min(sum1, V1[i].second) * V1[i].first;           sum1 -= min(sum1, V1[i].second);         }         len = V2.size();         for (int i = 0; i < len; i++) {           tmp2 += min(sum2, V2[i].second) * V2[i].first;           sum2 -= min(sum2, V2[i].second);         }         cout << ans - min(tmp1, tmp2) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     vector<long long> step(100, 0);     for (long long i = 0; i < n; i++) {       long long x = 0;       while (a[i] > 0) {         step[x] += a[i] % k;         a[i] /= k;         x++;       }     }     for (long long i = 0; i < 100; i++) {       if (step[i] > 1) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   signed main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     map<int, int> m;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]] = i;     }     long long int b[n];     map<int, int> freq;     for (int i = 0; i < n; i++) {       cin >> b[i];       int shift = m[b[i]] - i;       if (m[b[i]] - i < 0) shift = (n - i + m[b[i]]);       freq[shift]++;     }     int ans = 0;     for (auto i : freq) {       ans = max(ans, i.second);     }     cout << ans <<   n ;     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int size[3010], fa[3010], sum[3010], head[10010];   struct node {     int x, y, next;   } e[3010];   int find(int x) {     if (x != fa[x]) fa[x] = find(fa[x]);     return fa[x];   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y, w;       scanf( %d%d%d , &x, &y, &w);       e[i].x = x;       e[i].y = y;       e[i].next = head[w];       head[w] = i;     }     int s = 0;     for (int i = 1; i <= n; i++) {       fa[i] = i;       size[i] = 1;       scanf( %d , &sum[i]);       s += sum[i];     }     for (int i = 1; i <= 10000; i++) {       int p = head[i];       while (p) {         int x = find(e[p].x), y = find(e[p].y);         fa[y] = x;         size[x] += size[y];         sum[x] += sum[y];         if (size[x] + sum[x] > s) {           printf( %d n , i);           return 0;         }         p = e[p].next;       }     }     puts( 0 );     return 0;   }


#include <bits/stdc++.h>   const int maxx = 2e6 + 5;   using namespace std;   long long a[maxx];   long long biaoji[maxx] = {0};   int main() {     long long t, i, j, m, n;     cin >> n;     long long maxl = 0;     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       maxl = max(maxl, a[i]);       biaoji[a[i]]++;     }     long long sum1 = 0, sum2 = 0;     long long cishu = 0;     long long weizhi = 0;     for (i = 1; i <= maxl + 1; i++) {       if (biaoji[i] > 0) {         if (biaoji[i + 1] > 0 && biaoji[i + 2] > 0) {           sum1++;           i += 2;         } else if (biaoji[i + 1] > 0) {           sum1++;           i++;         } else if (biaoji[i + 2] > 0) {           sum1++;           i += 2;         } else {           sum1++;           i += 2;         }       }     }     for (i = 0; i <= maxl + 1; i++) {       if (i >= 1 && biaoji[i - 1] >= 1) {         sum2++;       } else if (biaoji[i] == 0) {         if (biaoji[i + 1] >= 1) {           biaoji[i + 1]--;           sum2++;         }       } else if (biaoji[i] >= 1) {         biaoji[i]--;         sum2++;       }     }     printf( %lld %lld n , sum1, sum2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     long long val, sum = 0, minOdd = 1000000001;     for (int i = 0; i < n; i++) {       scanf( %lld , &val);       if (val & 1) minOdd = min(minOdd, val);       sum += val;     }     printf( %lld n , (sum & 1) ? sum - minOdd : sum);     return 0;   }


#include <bits/stdc++.h>   namespace pb_ds {   namespace io {   const int MaxBuff = 1 << 15;   const int Output = 1 << 23;   char B[MaxBuff], *S = B, *T = B;   char Out[Output], *iter = Out;   inline void flush() {     fwrite(Out, 1, iter - Out, stdout);     iter = Out;   }   }  // namespace io   template <class Type>   inline Type Read() {     using namespace io;     register char ch;     register Type ans = 0;     register bool neg = 0;     while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T)                      ? 0                      : *S++),            (ch <  0  || ch >  9 ) && ch !=  - )       ;     ch ==  -  ? neg = 1 : ans = ch -  0 ;     while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T)                      ? 0                      : *S++),             0  <= ch && ch <=  9 )       ans = ans * 10 + ch -  0 ;     return neg ? -ans : ans;   }   template <class Type>   inline void Print(register Type x, register char ch =   n ) {     using namespace io;     if (!x)       *iter++ =  0 ;     else {       if (x < 0) *iter++ =  - , x = -x;       static int s[100];       register int t = 0;       while (x) s[++t] = x % 10, x /= 10;       while (t) *iter++ =  0  + s[t--];     }     *iter++ = ch;   }   }  // namespace pb_ds   using namespace pb_ds;   using namespace std;   const int N = 55;   const int inf = 2e9;   struct edge {     int next, to;   } a[N << 1];   int head[N], cnt;   inline void add(int u, int v) {     a[++cnt].to = v;     a[cnt].next = head[u];     head[u] = cnt;   }   int n, m, st, now, ans = inf;   int w[N][N], c[N], deg[N];   int dp[N][N][N][N], f[2][N];   void dfs(int x, int fa) {     for (int i = head[x]; i; i = a[i].next) {       int y = a[i].to;       if (y == fa) continue;       dfs(y, x), c[x] += c[y];     }   }   int solve(int u, int v, int s1, int s2) {     if (!s1) return s2 ? inf : 0;     if (~dp[u][v][s1][s2]) return dp[u][v][s1][s2];     if (deg[v] == 1) return dp[u][v][s1][s2] = (solve(v, u, s2, 0) + w[u][v]);     for (int i = head[v]; i; i = a[i].next) {       int y = a[i].to;       if (y == u) continue;       for (int j = 0; j <= s1; ++j) solve(v, y, j, s1 + s2 - j);     }     memset(f[0], 0, sizeof(f[0])), f[now = 0][0] = inf;     for (int i = head[v]; i; i = a[i].next) {       int y = a[i].to;       if (y == u) continue;       now ^= 1;       memset(f[now], 0, sizeof(f[now]));       for (int j = 0; j <= s1; ++j) {         for (int k = 0; j + k <= s1; ++k) {           f[now][j + k] =               max(f[now][j + k], min(f[now ^ 1][j], solve(v, y, k, s1 + s2 - k)));         }       }     }     return (dp[u][v][s1][s2] = (f[now][s1] + w[u][v]));   }   int main() {     n = Read<int>();     for (int i = 1; i < n; ++i) {       int u = Read<int>(), v = Read<int>();       w[u][v] = w[v][u] = Read<int>();       add(u, v), add(v, u);       ++deg[u], ++deg[v];     }     st = Read<int>(), m = Read<int>();     for (int i = 1; i <= m; ++i) ++c[Read<int>()];     dfs(st, 0), memset(dp, -1, sizeof(dp));     for (int i = head[st]; i; i = a[i].next)       ans = min(ans, solve(st, a[i].to, c[a[i].to], m - c[a[i].to]));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   const double pi = std::acos(-1);   using namespace std;   const long long int mod = 1000000000 + 7;   long long int power(long long int x, long long int y, long long int md) {     long long int res = 1;     x = x % md;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % md;       y = y >> 1;       x = (x * x) % md;     }     return res;   }   long long int m_mul(long long int a, long long int b) {     a = a % mod;     b = b % mod;     return (a * b + mod) % mod;   }   long long int m_add(long long int a, long long int b) {     a = a % mod;     b = b % mod;     return (a + b + mod) % mod;   }   int main() {     long long int tc;     cin >> tc;     while (tc--) {       long long int n, x;       cin >> n >> x;       long long int arr[n];       for (long long int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n, greater<long long int>());       long long int a1 = 1;       long long int k = 0;       for (long long int i = 0; i < n; i++) {         if (arr[i] * a1 >= x) {           a1 = 1;           k++;         } else {           a1++;         }       }       cout << k <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     long long int result = 1;     while (b > 0) {       int lastbit = (b & 1);       if (lastbit) {         result = (result * a);       }       a = (a * a);       b = b >> 1;     }     return result;   }   long long int power2(long long int a, long long int b, long long int p) {     long long int result = 1;     while (b > 0) {       int lastbit = (b & 1);       if (lastbit) {         result = (result * a) % p;       }       a = (a * a) % p;       b = b >> 1;     }     return result % p;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   vector<int> SieveOfEratosthenes(int n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     vector<int> v;     v.push_back(0);     for (int p = 2; p <= n; p++)       if (prime[p]) v.push_back(p);     return v;   }   void InverseofNumber(long long int p) {     long long int n[1000001];     n[0] = n[1] = 1;     for (int i = 2; i <= 1000000; i++) n[i] = n[p % i] * (p - p / i) % p;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int xxx;     cin >> xxx;     for (int tt = 1; tt <= xxx; tt++) {       long long int n;       cin >> n;       long long int t = ceil(sqrt(n));       long long int x = n / t;       if (n % t == 0) {         x--;       }       cout << t + x - 1;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s, t;     cin >> n;     vector<vector<int> > DP(26, vector<int>(26, -10000000));     for (int i = 0; i < n; i++) {       t = s;       cin >> s;       if (i > 0)         DP[t[0] -  a ][t[t.length() - 1] -  a ] =             max(DP[t[0] -  a ][t[t.length() - 1] -  a ], (int)t.length());       for (int j = 0; j < 26; j++)         DP[j][s[s.length() - 1] -  a ] = max(DP[j][s[s.length() - 1] -  a ],                                              DP[j][s[0] -  a ] + (int)s.length());     }     t = s;     DP[t[0] -  a ][t[t.length() - 1] -  a ] =         max(DP[t[0] -  a ][t[t.length() - 1] -  a ], (int)t.length());     int Ans = 0;     for (int i = 0; i < 26; i++) Ans = max(Ans, DP[i][i]);     cout << Ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long int w, x[200005];   int main() {     cin >> n >> w;     for (int i = 0; i < n * 2; i++) cin >> x[i];     sort(x, x + n * 2);     double mid;     mid = min((double)x[n] / 2, (double)x[0]);     mid = (mid + mid * 2) * n;     mid = min(mid, (double)w);     printf( %.6f n , mid);   }


#include <bits/stdc++.h>   using namespace std;   void cp() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int main() {     cp();     {       string s, t;       cin >> s >> t;       if (s.length() == t.length() + 1) {         long long m = 0;         long long in = -1;         char f;         long long j = 0;         for (long long i = 0; i < s.length(); i += 1) {           if (s[i] != t[j]) {             f = s.at(i);             in = i;             m++;             j--;           }           j++;         }         vector<long long> ans;         if (m == 1) {           while (in > -1) {             if (s[in] == f) {               in--;             } else {               break;             }           }           in++;           while (in < s.length()) {             if (s[in] == f) {               ans.push_back(in + 1);               in++;             } else {               break;             }           }           cout << ans.size();           cout << endl;           ;           for (long long i = 0; i < ans.size(); i += 1) cout << ans[i] <<    ;         } else {           cout <<  0 n ;         }       } else {         cout <<  0 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 100 * 1000 + 7;   int a[MX];   int hup[MX], hdown[MX];   long long cup[MX], cdown[MX];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       int cost = 0;       if (a[i] <= hup[i - 1]) cost = (hup[i - 1] + 1 - a[i]);       hup[i] = a[i] + cost;       cup[i] = cup[i - 1] + cost;     }     for (int i = n; i >= 1; i--) {       int cost = 0;       if (a[i] <= hdown[i + 1]) cost = (hdown[i + 1] + 1 - a[i]);       hdown[i] = a[i] + cost;       cdown[i] = cdown[i + 1] + cost;     }     long long res = (long long)1e18;     for (int i = 1; i <= n; i++) {       int need = max(hup[i - 1] + 1, hdown[i + 1] + 1);       int cost = 0;       if (a[i] < need) cost = need - a[i];       res = min(res, cup[i - 1] + cdown[i + 1] + cost);     }     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   struct ww {     long long x, y;   } c[400][400];   int i, j, k, n, m, ma, ren, C, kuai;   int cov[400], zhi[400];   long long b[400][400], s[400][400];   vector<int> a[100010];   inline void gao(int x) {     int i, n = kuai - 1, g[400], r = 0;     long long jum[400];     for (i = 0; i <= n; i++) b[x][i] += cov[x];     cov[x] = 0;     s[x][0] = b[x][0];     for (i = 1; i <= n; i++) s[x][i] = s[x][i - 1] + b[x][i];     for (i = 0; i <= n; i++) {       long long A = s[x][i], F = 0;       for (; r; r--) {         int wei = g[r];         long long B = s[x][wei];         int cha = i - wei;         if (A >= B) continue;         long long ci = (B - A) / cha + ((B - A) % cha > 0);         if (jum[r] >= ci)           continue;         else {           F = ci;           break;         }       }       g[++r] = i, jum[r] = F;     }     jum[r + 1] = 100010;     for (i = 1; i <= r; i++) c[x][i] = (ww){g[i], jum[i + 1]};     zhi[x] = 1;   }   inline void jian(int x) {     int A = x / kuai, B = x % kuai;     b[A][B] -= x;     gao(A);   }   inline void jia(int x) {     if (x < 0) return;     int A = x / kuai, B = x % kuai, i;     for (i = 0; i <= A - 1; i++) {       cov[i]++;       if (c[i][zhi[i]].y == cov[i]) zhi[i]++;     }     for (i = 0; i <= B; i++) b[A][i]++;     gao(A);   }   inline long long suan(int x) {     ww A = c[x][zhi[x]];     return s[x][A.x] + 1ll * cov[x] * (A.x + 1);   }   inline ww cal() {     int i, id;     long long ma, sum;     ma = -1, sum = 0;     for (i = 0; i <= 400 - 1; i++) {       long long re = sum + suan(i);       if (re > ma) ma = re, id = i * kuai + c[i][zhi[i]].x;       sum += s[i][kuai - 1] + 1ll * cov[i] * kuai;     }     return (ww){ma, id};   }   int main() {     kuai = 300;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       a[y].push_back(x - 1);       ma = max(ma, y);     }     for (i = 0; i <= 400 - 1; i++) gao(i);     ren = n;     for (C = 0; C <= ma + 1; C++) {       ww re = cal();       printf( %I64d %I64d n , 1ll * ren * C * m + re.x, re.y + 1);       for (j = 0; j < a[C].size(); j++) {         int A = a[C][j];         ren--;         jia(A);         jian(A + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, x, y, arr1[2] = {0, 0}, arr2[2] = {0, 0};     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t >> x >> y;       if (t == 1) {         arr1[0] += x;         arr1[1] += y;       }       if (t == 2) {         arr2[0] += x;         arr2[1] += y;       }     }     if (arr1[0] >= arr1[1]) {       cout <<  LIVE  << endl;     }     if (arr1[0] < arr1[1]) {       cout <<  DEAD  << endl;     }     if (arr2[0] >= arr2[1]) {       cout <<  LIVE  << endl;     }     if (arr2[0] < arr2[1]) {       cout <<  DEAD  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   bitset<101> usado;   long long dfs(long long nodo) {     if (usado[nodo]) return 0;     usado.set(nodo);     return 1 + dfs(v[nodo]);   }   long long calcmcd(long long a, long long b) {     if (a % b == 0) return b;     return calcmcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     bool puede = true;     long long n, aux, resp, mcd, mcm;     vector<long long> pararesp;     cin >> n;     v.resize(n + 1);     for (long long i = 1; i <= n; i++) {       cin >> v[i];       if (usado[v[i]])         puede = false;       else         usado.set(v[i]);     }     if (puede) {       usado.reset();       for (long long i = 1; i <= n; i++) {         while (i <= n && (usado[i] || v[i] == i)) i++;         if (i <= n) {           aux = dfs(i);           if (aux % 2 == 0) aux /= 2;           pararesp.push_back(aux);         }       }       if (pararesp.empty())         resp = 1;       else {         if (pararesp.size() == 1)           resp = pararesp[0];         else {           mcm = pararesp[pararesp.size() - 1];           for (int i = pararesp.size() - 2; i >= 0; i--) {             if (pararesp[i] > mcm)               mcd = calcmcd(pararesp[i], mcm);             else               mcd = calcmcd(mcm, pararesp[i]);             mcm = mcm * pararesp[i] / mcd;           }           resp = mcm;           pararesp.clear();         }       }       cout << resp <<   n ;     } else       cout <<  -1 n ;     v.clear();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast,no-stack-protector )   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   function<void(void)> ____ = []() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   };   template <typename T>   vector<T> &operator<<(vector<T> &__container, T x) {     __container.push_back(x);     return __container;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> &__container) {     for (T _ : __container) out << _ <<    ;     return out;   }   void sci() {}   template <typename... Args>   void sci(int &x, Args &...args) {     scanf( %d , &x);     sci(args...);   }   void scl() {}   template <typename... Args>   void scl(long long int &x, Args &...args) {     scanf( %lld , &x);     scl(args...);   }   const int MAXN = 1e6 + 7;   int n, m;   struct SegmentTree {     int w[MAXN << 2], l[MAXN << 2], r[MAXN << 2];     void build(int L, int R, int rt = 1) {       l[rt] = L;       r[rt] = R;       w[rt] = 0;       if (L + 1 == R) return;       int mid = (L + R) >> 1;       build(L, mid, rt << 1);       build(mid, R, rt << 1 | 1);     }     void down(int rt) {       if (w[rt]) w[rt << 1] = w[rt << 1 | 1] = w[rt], w[rt] = 0;     }     void modify(int L, int R, int x, int rt = 1) {       if (L >= r[rt] or l[rt] >= R) return;       if (L <= l[rt] and r[rt] <= R) {         w[rt] = x;         return;       }       down(x);       modify(L, R, x, rt << 1);       modify(L, R, x, rt << 1 | 1);     }     int query(int pos, int rt = 1) {       if (l[rt] + 1 == r[rt]) return w[rt];       down(rt);       int mid = (l[rt] + r[rt]) >> 1;       if (pos < mid)         return query(pos, rt << 1);       else         return query(pos, rt << 1 | 1);     }   } seg;   struct FenwickTree {     long long int sum[MAXN];     void modify(int pos, int x) {       while (pos < MAXN) sum[pos] += x, pos += (pos & (-pos));     }     long long int qsum(int pos) {       long long int ret = 0;       while (pos) ret += sum[pos], pos -= (pos & (-pos));       return ret;     }   } bit;   struct Query {     char op;     int x, y, id, qid;   } Q[MAXN];   struct Disjoint_Set_Union {     int fa[MAXN];     Disjoint_Set_Union() {       for (int i = 0; i < MAXN; i++) fa[i] = i;     }     int findx(int x) { return x == fa[x] ? x : fa[x] = findx(fa[x]); }     void merge(int x, int y) {       if (findx(x) != findx(y)) fa[findx(x)] = findx(y);     }   } dsu[2];   struct Graph {     vector<int> g[MAXN];     int tot, dfn[MAXN], idx, sz[MAXN], ed[MAXN];     Graph() { tot = idx = 0; }     void dfs(int u) {       dfn[u] = ++idx;       sz[u] = u <= n ? 1 : 0;       for (int v : g[u]) dfs(v), sz[u] += sz[v];       ed[u] = idx;     }   } G[2];   long long int ret[MAXN];   void solve() {     static char buf[233];     sci(n, m);     G[0].tot = G[1].tot = n;     for (int i = 1; i <= m; i++) {       scanf( %s , buf);       Q[i].id = i;       Q[i].op = buf[0];       if (buf[0] ==  U ) {         sci(Q[i].x, Q[i].y);         G[1].tot++;         G[1].g[G[1].tot] << dsu[1].findx(Q[i].x) << dsu[1].findx(Q[i].y);         dsu[1].merge(Q[i].x, G[1].tot);         dsu[1].merge(Q[i].y, G[1].tot);       } else if (buf[0] ==  M ) {         sci(Q[i].x, Q[i].y);         G[0].tot++;         G[0].g[G[0].tot] << dsu[0].findx(Q[i].x) << dsu[0].findx(Q[i].y);         dsu[0].merge(Q[i].x, G[0].tot);         dsu[0].merge(Q[i].y, G[0].tot);       } else if (buf[0] ==  A )         sci(Q[i].x), Q[i].x = dsu[1].findx(Q[i].x);       else if (buf[0] ==  Z )         sci(Q[i].x), Q[i].x = dsu[0].findx(Q[i].x);       else if (buf[0] ==  Q )         sci(Q[i].x);     }     G[0].tot++;     for (int i = 1; i < G[0].tot; i++)       if (dsu[0].findx(i) == i) G[0].g[G[0].tot] << i;     G[0].dfs(G[0].tot);     G[1].tot++;     for (int i = 1; i < G[1].tot; i++)       if (dsu[1].findx(i) == i) G[1].g[G[1].tot] << i;     G[1].dfs(G[1].tot);     vector<Query> vec;     seg.build(1, MAXN);     int queryid = 0;     for (int i = 1; i <= m; i++) {       if (Q[i].op ==  A )         vec << Q[i];       else if (Q[i].op ==  Z ) {         int st = G[0].dfn[Q[i].x], ed = G[0].ed[Q[i].x];         seg.modify(st, ed + 1, i);       } else if (Q[i].op ==  Q ) {         Q[i].y = 1;         Q[i].qid = ++queryid;         vec << Q[i];         int p = seg.query(G[0].dfn[Q[i].x]);         if (p != 0) {           Q[i].y = -1;           Q[i].id = p;           vec << Q[i];         }       }     }     sort(vec.begin(), vec.end(),          [&](const Query &A, const Query &B) { return A.id < B.id; });     for (Query &qs : vec) {       if (qs.op ==  A ) {         int sz = G[1].sz[qs.x], st = G[1].dfn[qs.x], ed = G[1].ed[qs.x];         bit.modify(st, sz);         bit.modify(ed + 1, -sz);       } else if (qs.op ==  Q )         ret[qs.qid] += qs.y * bit.qsum(G[1].dfn[qs.x]);     }     for (int i = 1; i <= queryid; i++) cout << ret[i] <<   n ;   }   int main() {     solve();     return 0;   }