#include <bits/stdc++.h>   using namespace std;   long long abs(long long, long long);   double dis(long long x1, long long y1, long long x2, long long y2) {     double d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     d = sqrt(d * 1.0);     return d;   }   void solve() {     long long w, h;     cin >> w >> h;     long long u1, d1, u2, d2;     cin >> u1 >> d1 >> u2 >> d2;     long long a = w;     for (long long i = h; i > 0; i--) {       a += i;       if (i == d1) {         a -= u1;         if (a < 0) a = 0;       }       if (i == d2) {         a -= u2;         if (a < 0) a = 0;       }     }     cout << a;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long TESTS = 1;     while (TESTS--) {       solve();     }     return 0;   }   long long abs(long long a, long long b) {     if (a > b)       return a - b;     else       return b - a;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, t, m, y, z, k;     cin >> t;     while (t--) {       cin >> n >> m;       vector<vector<long long> > a(n, vector<long long>(m));       string s;       for (int i = 0; i < n; i++) {         cin >> s;         for (int j = 0; j < m; j++) {           a[i][j] = s[j] -  0 ;         }       }       vector<vector<long long> > ans;       auto f = [&](int i, int j) { a[i][j] ^= 1; };       for (int i = 0; i < n - 2; i++) {         for (int j = 0; j < m - 1; j++) {           if (a[i][j]) {             ans.push_back({i, j, i + 1, j, i, j + 1});             f(i, j);             f(i + 1, j);             f(i, j + 1);           }         }         if (a[i][m - 1]) {           ans.push_back({i, m - 1, i + 1, m - 1, i + 1, m - 2});           f(i, m - 1);           f(i + 1, m - 1);           f(i + 1, m - 2);         }       }       for (int j = 0; j < m - 2; j++) {         if (a[n - 2][j] && a[n - 1][j]) {           ans.push_back({n - 2, j, n - 1, j, n - 2, j + 1});           f(n - 2, j);           f(n - 1, j);           f(n - 2, j + 1);         } else if (a[n - 2][j]) {           ans.push_back({n - 2, j, n - 1, j + 1, n - 2, j + 1});           f(n - 2, j);           f(n - 1, j + 1);           f(n - 2, j + 1);         } else if (a[n - 1][j]) {           ans.push_back({n - 1, j, n - 1, j + 1, n - 2, j + 1});           f(n - 1, j);           f(n - 1, j + 1);           f(n - 2, j + 1);         }       }       for (int k = 0; k < 4; k++) {         vector<long long> move;         auto choose = [&](pair<long long, long long> o) {           move.push_back(o.first);           move.push_back(o.second);           a[o.first][o.second] ^= 1;         };         vector<pair<long long, long long> > b, g;         for (int i = n - 2; i < n; i++) {           for (int j = m - 2; j < m; j++) {             if (a[i][j])               b.push_back({i, j});             else               g.push_back({i, j});           }         }         if (b.size() == 0) break;         if (b.size() == 4) {           choose(b[0]);           choose(b[1]);           choose(b[2]);         } else if (b.size() == 1) {           choose(b[0]);           choose(g[0]);           choose(g[1]);         } else if (b.size() == 2) {           choose(b[0]);           choose(g[0]);           choose(g[1]);         } else if (b.size() == 3) {           choose(b[0]);           choose(b[1]);           choose(b[2]);         }         ans.push_back(move);       }       cout << ans.size() <<   n ;       for (auto &it : ans) {         for (int j : it) {           cout << j + 1 <<    ;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long long n, d, m, l, i, le, ri, step;     while (~scanf( %I64d%I64d%I64d%I64d , &n, &d, &m, &l)) {       for (i = 0; i < n; i++) {         le = i * m + l;         ri = (i + 1) * m;         step = (le + d) / d;         if (step * d < ri) break;       }       printf( %I64d n , step * d);     }   }


#include <bits/stdc++.h>   using namespace std;   int q, n;   long long k;   long long len[100004];   string s1 =  What are you doing while sending  ,          s2 =  ? Are you busy? Will you send  , s3 =  ? ,          f0 =               What are you doing at the end of the world? Are you busy? Will you                 save us? ;   int ge;   void pre() {     s1 +=    ;     s2 =     + s2 +    ;     s3 =     + s3;     len[0] = 75;     for (int i = 1; i <= 100000; i++) {       len[i] = len[i - 1] * 2 + 33 + 30 + 1 + 1 + 2 + 1;       if (len[i] > 1000000000000000000LL) {         ge = i;         return;       }     }   }   int dfs(int x) {     if (x <= ge && k > len[x]) return printf( . );     if (!x) return printf( %c , f0[k - 1]);     if (k <= 34) return printf( %c , s1[k - 1]), 0;     k -= 34;     if (x > ge || k <= len[x - 1]) return dfs(x - 1);     k -= len[x - 1];     if (k <= 32) return printf( %c , s2[k - 1]), 0;     k -= 32;     if (k <= len[x - 1]) return dfs(x - 1);     k -= len[x - 1];     return printf( %c , s3[k - 1]);   }   int main() {     scanf( %d , &q);     pre();     while (q--) {       scanf( %d%I64d , &n, &k);       dfs(n);     }     return 0;   }


#include <bits/stdc++.h>   using uint64 = unsigned long long;   const int N = 100, seed = 65537;   char s[N];   std::unordered_map<uint64, int> words;   std::unordered_set<uint64> mark;   int dfs(int d, uint64 hs) {     if (s[d] == 0) {       if (mark.count(hs)) return 0;       mark.insert(hs);       auto it = words.find(hs);       if (it == words.end())         return 0;       else         return it->second;     }     int ret = 0;     if (s[d] ==  ? ) {       ret += dfs(d + 1, hs);       for (char c =  a ; c <=  e ; ++c) {         ret += dfs(d + 1, hs * seed + c);       }     } else {       ret += dfs(d + 1, hs * seed + s[d]);     }     return ret;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       uint64 hs = 0;       for (int j = 0; s[j]; ++j) {         hs = hs * seed + s[j];       }       words[hs] += 1;     }     for (int i = 0; i < m; ++i) {       scanf( %s , s);       mark.clear();       printf( %d n , dfs(0, 0));     }     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1);   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 1e6 + 5;   const double eps = 1e-9;   using namespace std;   int main() {     for (int i = 0; i < 9; i++) printf( %d ? ?<>%d n , i, i + 1);     printf( 9 ? ?>> ? ?0 n ? ?<>1 n );     for (int i = 0; i <= 9; i++) printf(  ?%d>>%d ? n , i, i);     printf(  ?>> ? ? n>> ? n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long w, m, k;   long long comp;   long long getpre(long long a) {     long long tmp = 1, ct = 0;     while (a >= tmp) tmp *= 10, ++ct;     tmp /= 10;     long long t = 1;     long long ans = 0;     for (long long i = 1; i < ct; ++i) ans += i * 9 * t, t *= 10;     ans += (a - tmp + 1) * ct;     return ans;   }   bool judge(long long len) {     long long tl = m - 1;     long long tr = m + len - 1;     if (getpre(tr) - getpre(tl) <= comp) return true;     return false;   }   int main() {     cin >> w >> m >> k;     long long l = 0, r = w / k + 1, ans = 0;     comp = r - 1;     while (l <= r) {       long long mid = (l + r) >> 1;       if (judge(mid))         l = mid + 1, ans = mid;       else         r = mid - 1;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       if (k % 2 == 0)         k = 2;       else         k = 1;       while (k--) {         long long m = -10000000000;         for (int i = 0; i < n; i++) {           m = max(m, a[i]);         }         for (int i = 0; i < n; i++) {           a[i] = m - a[i];         }       }       for (int i = 0; i < n; i++) cout << a[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[500005];   int main() {     string s;     cin >> s;     for (int i = 1; i <= s.size(); i++)       f[i] = (s[i - 1] ==  I  || s[i - 1] ==  O  || s[i - 1] ==  E  ||               s[i - 1] ==  A  || s[i - 1] ==  U  || s[i - 1] ==  Y );     for (int i = 1; i <= s.size(); i++) f[i] = f[i - 1] + f[i];     long long cur = 0;     long double ans = 0;     for (int i = 1; i <= s.size(); i++)       cur += (f[s.size() - i + 1] - f[i - 1]),           ans += (long double)cur / (long double)i;     printf( %.10Lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     long long t;     cin >> n >> t;     vector<long long> a, b;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       x += t;       a.push_back(x);     }     vector<int> breaks;     bool poss = true;     long long cur = 0;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       b.push_back(x);       if (x < i) poss = false;       if (x < cur) poss = false;       if (x != cur && i != (cur + 1)) poss = false;       if (x != cur) {         breaks.push_back(1);       } else {         breaks.push_back(0);       }       cur = x;     }     for (int i = 1; i < n; i++) {       if (breaks[i] && !breaks[i - 1] && a[i - 1] + 1 == a[i]) poss = false;     }     if (!poss) {       cout <<  No  << endl;       return 0;     }     cout <<  Yes  << endl;     for (int i = 0; i < n; i++) {       if (b[i] == n) {         cout << a[n - 1] + i + 1 <<    ;       } else {         cout << a[b[i]] - (b[i] - i) <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     long long int a[n + 1];     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     long long int f = 0;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= n; j++) {         if (j != i) {           for (long long int k = 1; k <= n; k++) {             if (k != j) {               if (a[i] == a[j] + a[k]) {                 f = 1;                 cout << i <<     << j <<     << k << endl;                 break;               }             }           }           if (f) {             break;           }         }       }       if (f) {         break;       }     }     if (f == 0) {       cout << -1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, j = 0;     cin >> n;     vector<int> ai(n);     if (n == 4) {       cout << 4 <<   n ;       cout << 3 <<     << 1 <<     << 4 <<     << 2 <<   n ;       return 0;     }     for (int i = 1; i <= n; i += 2) {       ai[j] = i;       j++;     }     for (int k = 2; k <= n; k += 2) {       if (abs(ai[j - 1] - k) != 1) {         ai[j] = k;         j++;       }     }     cout << j <<   n ;     for (int i = 0; i < j; i++) cout << ai[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     if (m >= n && k >= n) {       cout <<  Yes  << endl;     } else       cout <<  No  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, v[105], frec[105];   vector<int> ans;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= n; i++)       if (!frec[v[i]]) {         frec[v[i]] = 1;         ans.push_back(i);         if (ans.size() == k) break;       }     if (ans.size() == k) {       cout <<  YES  <<   n ;       for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;       cout <<   n ;     } else       cout <<  NO  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int lg = 22;   const long long int N = 2e5 + 5;   const long long int INF = 1e18;   const long long int mod = 1e9 + 7;   const double PI = 3.14159265358979323846;   template <typename T>   T power(T x, T y, long long int m) {     T ans = 1;     while (y > 0) {       if (y & 1LL) ans = (ans * x) % m;       y >>= 1LL;       x = (x * x) % m;     }     return ans % m;   }   inline long long int mul(long long int a, long long int b, long long int p) {     return (a * 1ll * b) % p;   }   inline long long int sub(long long int a, long long int b, long long int p) {     long long int c = a - b;     if (c < 0) c += p;     return c;   }   inline long long int add(long long int a, long long int b, long long int p) {     long long int c = a + b;     if (c > p) c -= p;     return c;   }   long long int mark[N];   long long int n, q, a[N], minidx[N], maxidx[N];   int main() {     long long int ans = 0;     cin >> n >> q;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];       if (minidx[a[i]] == 0) {         minidx[a[i]] = i;       }       maxidx[a[i]] = i;     }     for (long long int i = 1; i <= n; i++) {       long long int maxcnt = 0, cnt = 0;       long long int maxi = maxidx[a[i]];       if (mark[i]) {         continue;       }       map<long long int, long long int> xfreq;       for (long long int j = i; j <= maxi; j++) {         cnt++;         mark[j] = 1;         xfreq[a[j]]++;         maxcnt = max(maxcnt, xfreq[a[j]]);         maxi = max(maxi, maxidx[a[j]]);       }       ans += (cnt - maxcnt);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<set<int> > A;   set<int>::iterator it;   int main() {     int n, m, a;     cin >> n;     A.resize(n);     int D[101];     for (int i = 1; i <= 100; ++i) D[i] = 0;     for (int i = 0; i < n; ++i) {       cin >> m;       for (int j = 0; j < m; ++j) {         cin >> a;         ++D[a];         A[i].insert(a);       }     }     for (int i = 0; i < n; ++i) {       bool yes = 1;       for (int j = 0; j < n; ++j) {         if (i != j) {           bool y = 0;           for (it = A[j].begin(); it != A[j].end(); ++it)             if (A[i].count(*it) == 0) y = 1;           if (y == 0) yes = 0;         }       }       if (yes)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   int main() {     int n, a[1010], temp, lamak, maxin, max, i, j;     long int count;     while (scanf( %d , &n) != EOF) {       count = 0;       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);       }     again:       max = 0;       for (i = 0; i < n; i++) {         if (a[i] >= max) {           max = a[i];           maxin = i;         }       }       if (max > a[0]) {         a[maxin] = a[maxin] - 1;         a[0] = a[0] + 1;         count = count + 1;         goto again;       }       if (max == a[0] && maxin != 0) {         a[maxin] = a[maxin] - 1;         a[0] = a[0] + 1;         count = count + 1;         printf( %ld n , count);       } else {         printf( %ld n , count);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 17;   const long long MOD = 1000000009;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-8;   vector<pair<long long, long long> > Vu;   int main() {     int N, K, M, i, j;     scanf( %d %d %d , &N, &K, &M);     for (i = 1; i <= N; i++) {       int t;       scanf( %d , &t);       if (!Vu.empty() && Vu.back().first == t) {         Vu.back().second++;         if (Vu.back().second == K) Vu.pop_back();       } else         Vu.emplace_back(t, 1);     }     long long s = 0;     for (auto it : Vu) s += it.second;     if (M == 1 || s == 0) return !printf( %lld n , s);     s *= M;     int st = 0, en = (int)Vu.size() - 1;     while (st < en) {       if (Vu[st].first != Vu[en].first) return !printf( %lld n , s);       if (Vu[st].second + Vu[en].second == K) {         s -= (long long)(M - 1) * K;         st++, en--;         continue;       }       if (Vu[st].second + Vu[en].second > K) s -= (long long)(M - 1) * K;       return !printf( %lld n , s);     }     long long x = Vu[st].second * M;     if (x % K == 0) {       return !printf( 0 n );     } else {       return !printf( %lld n , s - (x / K) * K);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MXN = 1e5 + 1;   const int MAXN = 1e3 + 1;   const long long INF = 1e16;   const int MOD = 65000;   const int MAX = 1e2;   const double EPS = 1e-9;   long long n;   long long a, b, c, d, e, first, g, h;   int main() {     ios_base::sync_with_stdio(0);     string second;     cin >> second;     for (int i = 0; i < second.size(); ++i) {       if (second[i] ==  B ) ++a;       if (second[i] ==  u ) ++b;       if (second[i] ==  l ) ++c;       if (second[i] ==  b ) ++d;       if (second[i] ==  a ) ++e;       if (second[i] ==  s ) ++first;       if (second[i] ==  u ) ++g;       if (second[i] ==  r ) ++h;     }     g = g / 2;     e = e / 2;     cout << min(a, min(b, min(c, min(d, min(e, min(first, min(g, h)))))));     return 0;   }


#include <iostream>   #include <vector>   #include <algorithm>   using namespace std;      int main() {    int testCase;     cin >> testCase;    while (testCase--) {     vector<int> balls;     int ball;     cin >> ball;     while (ball--) {      int num;      cin >> num;      balls.push_back(num);     }     int maxNum = 1;     int lastNum = balls[0];     int count = 1;     for (int i = 1;i < balls.size();i++) {      if (balls[i] != lastNum) {       lastNum = balls[i];       maxNum = max(count, maxNum);       count = 1;      }      else {       count++;      }     }     maxNum = max(count, maxNum);     cout << maxNum << endl;    }    return 0;   }


#include <bits/stdc++.h>   #define int long long      #pragma GCC target ( avx2 )   #pragma GCC optimization ( O3 )   #pragma GCC optimization ( unroll-loops )      /*#include <ext/pb_ds/assoc_container.hpp>   #include <ext/pb_ds/tree_policy.hpp>   using namespace __gnu_pbds;   #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/      using namespace std;         signed main() {       //ios_base::sync_with_stdio(0);       //cin.tie(0);       //cout.tie(0);       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; ++i) cin >> a[i];       vector <pair <int, pair <int, int> > > goga;       for (int i = 0; i < n; ++i) {           for (int j = i + 1; j < n; ++j) {               if (a[i] > a[j]) goga.push_back({a[i] - a[j], {i, j}});               else goga.push_back({a[j] - a[i], {j, i}});           }       }       sort(goga.begin(), goga.end());       reverse(goga.begin(), goga.end());       for (int i = 0; i < goga.size(); ++i) {           if (goga[i].first >= 0 && i < goga.size()) {           int first = goga[i].second.first, second = goga[i].second.second;           cout <<  ?   << first + 1 <<     << second + 1 << endl;           string lol;           cin >> lol;           if (lol ==  Yes ) {               cout <<  !   << first + 1 <<     << second + 1 << endl;               return 0;           }           }       }       cout <<  !   << 0 <<     << 0 << endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1004;   int a[N];   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int> > vec;     int i;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vec.push_back(make_pair(a[i], i));     }     sort(vec.begin(), vec.end());     reverse(vec.begin(), vec.end());     int ans = 0;     for (i = 0; i < vec.size(); i++) {       ans = ans + (i)*vec[i].first + 1;     }     printf( %d n , ans);     for (i = 0; i < vec.size(); i++) printf( %d  , vec[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ms, type[5005], dp[5005];   int main() {     scanf( %d %d , &n, &ms);     for (int i = 1; i <= n; i++) {       double x;       scanf( %d %lf , type + i, &x);     }     for (int i = 1; i <= n; i++) {       int j = type[i];       for (int k = j; k >= 1; k--) {         dp[j] = max(dp[j], 1 + dp[k]);       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans = max(ans, dp[i]);     }     printf( %d n , n - ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char s[105];     cin >> s;     vector<int> a;     string ans =   ;     int j, ct = 0;     for (int i = 0; i <= n - 1;) {       if (s[i] ==  o  && s[i + 1] ==  g  && s[i + 2] ==  o  && i <= n - 3) {         ct = 0;         for (j = i + 3; j < n - 1;) {           if (s[j] ==  g  && s[j + 1] ==  o ) {             ct = 1;             j = j + 2;             i = j;           } else {             i = j;             break;           }         }         i = j;         if (ct == 1) {           ans +=  *** ;         } else {           ans +=  *** ;         }       } else {         ans += s[i];         i++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 1e5 + 13;   int n, m;   set<int> e[N];   set<pair<int, int> > q;   int p[N];   int tin[N], cnt, w[N], ans;   int gcd(int a, int b) { return (!a ? b : gcd(b % a, a)); }   void init() {     for (int i = 0; i < N; ++i) p[i] = i;   }   int find(int u) {     if (p[u] == u) return u;     return p[u] = find(p[u]);   }   void uni(int a, int b) {     a = find(a);     b = find(b);     if (a == b) return;     if (e[a].size() < e[b].size()) swap(a, b);     for (int to : e[b]) e[a].insert(find(to));     p[b] = a;     e[b].clear();   }   void print(int ans) {     printf( %d n , ans);     exit(0);   }   pair<int, int> getMax() {     auto it = q.end();     --it;     pair<int, int> res = (*it);     return res;   }   void merge(int id) {     if (id != find(id)) return;     vector<int> ver;     for (int v : e[id]) ver.push_back(find(v));     e[id].clear();     for (int i = 0; i < ver.size(); ++i) {       int pi = find(ver[i]);       q.erase(make_pair(e[pi].size(), pi));     }     for (int i = 1; i < ver.size(); ++i) uni(ver[i], ver[i - 1]);     int lv = find(ver[0]);     id = find(id);     e[id].insert(lv);     q.insert(make_pair(e[lv].size(), lv));     q.insert(make_pair(e[id].size(), id));     if (e[id].find(id) != e[id].end()) print(1);   }   void compress() {     for (int i = 0; i < n; ++i) {       q.insert(make_pair(e[i].size(), find(i)));     }     while (true) {       pair<int, int> cur = getMax();       if (cur.first < 2) return;       q.erase(cur);       merge(cur.second);     }   }   void dfs(int u) {     w[u] = 1;     tin[u] = cnt;     ++cnt;     for (int to : e[u]) {       int vt = find(to);       if (!w[vt])         dfs(vt);       else if (w[vt] == 1) {         ans = gcd(ans, tin[u] - tin[vt] + 1);       }     }     w[u] = 2;     --cnt;   }   void solve() {     init();     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u;       --v;       if (u == v) print(1);       e[u].insert(find(v));     }     compress();     for (int i = 0; i < n; ++i)       if (!w[find(i)]) dfs(find(i));     if (ans == 0) ans = n;     printf( %d n , ans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum(int a[], int size) {     int sum = 0;     for (int i = 0; i < size; i++) {       sum = sum + a[i];     }     return sum;   }   int main() {     int n;     cin >> n;     int a1[n], a2[n - 1], a3[n - 3];     for (int i = 0; i < n; i++) {       cin >> a1[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> a2[i];     }     for (int i = 0; i < n - 2; i++) {       cin >> a3[i];     }     cout << sum(a1, n) - sum(a2, n - 1) << endl          << sum(a2, n - 1) - sum(a3, n - 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dir[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},                    {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   int main() {     int n, k, p, x, y;     int cntY = 0, a[1100] = {0}, sum = 0;     scanf( %d %d %d %d %d , &n, &k, &p, &x, &y);     for (int i = 1; i <= k; i++) {       scanf( %d , &a[i]);       sum += a[i];       if (a[i] >= y) cntY++;     }     int Mid = (n + 1) / 2;     if (cntY >= Mid) {       sum += (n - k);       if (sum > x)         printf( -1 n );       else {         for (int i = 1; i <= (n - k); i++) printf( 1%c , i == n - k ?   n  :    );       }     } else {       sum += y * (Mid - cntY) + n - k - Mid + cntY;       if (sum > x || k - cntY >= Mid)         printf( -1 n );       else {         for (int i = 1; i <= (Mid - cntY); i++)           printf( %d%c , y, i == n - k ?   n  :    );         for (int i = 1; i <= n - k - Mid + cntY; i++)           printf( 1%c , i == n - k - Mid + cntY ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1);   const double EPS = 1e-6;   const long long MOD = 998244353;   const long long N = 30 + 10;   template <typename T>   inline T Abs(T x) {     return x < 0 ? x * -1 : x;   }   template <typename T>   inline T Max(T x, T y, T z) {     return std::max(std::max(x, y), z);   }   template <typename T>   inline T Min(T x, T y, T z) {     return std::min(std::min(x, y), z);   }   template <typename T>   inline void Ckmax(T &x, T y) {     x = std::max(x, y);   }   template <typename T>   inline void Ckmin(T &x, T y) {     x = std::min(x, y);   }   template <typename T>   inline T Sqr(T x) {     return x * x;   }   template <typename T>   inline T Pow(T x, T y) {     T r = 1;     while (y > 0) {       if (y % 2 > 0) (r *= x) %= MOD;       (x *= x) %= MOD;       y /= 2;     }     return r % MOD;   }   template <typename T>   T Pow(T x, T y, T z) {     T r = 1;     while (y > 0) {       if (y % 2 > 0) (r *= x) %= z;       (x *= x) %= z;       y /= 2;     }     return r % z;   }   template <typename T>   inline T gcd(T x, T y) {     return y > 0 ? gcd(y, x % y) : x;   }   template <typename T>   inline T lcm(T x, T y) {     return x / gcd(x, y) * y;   }   inline void cinspu(void) {     std::ios::sync_with_stdio(0);     std::cin.tie(0);   }   inline long long fac(long long x) {     long long r = 1;     for (; x > 1; --x) (r *= x) %= MOD;     return r;   }   int a[N], b[N], ans[N], tim;   int print(char z, int x, int y) {     ++tim;     printf( %c %d %d n , z, x, y);     fflush(stdout);     if (z ==  ? ) {       int r;       scanf( %d , &r);       return r;     }     return -2;   }   int main() {     const char q =  ? ;     for (int i = 29, x = 0, y = 0; i >= 0; --i) {       int n = (1 << i), r;       if (ans[i])         r = ans[i] - 3;       else         r = print(q, x, y);       if (r > 0) {         int p = print(q, x + n, y + n);         if (p > 0) {           int t = print(q, x + n, y);           if (t > 0) {             a[i] = b[i] = 0;             ans[i - 1] = 3 + r;           } else {             a[i] = b[i] = 1;             ans[i - 1] = 3 + p;             x += n;             y += n;           }         } else {           a[i] = 1;           b[i] = 0;           x += n;         }       } else if (r < 0) {         int p = print(q, x + n, y + n);         if (p < 0) {           int t = print(q, x + n, y);           if (t > 0) {             a[i] = b[i] = 0;             ans[i - 1] = 3 + r;           } else {             a[i] = b[i] = 1;             ans[i - 1] = 3 + p;             x += n;             y += n;           }         } else {           a[i] = 0;           b[i] = 1;           y += n;         }       } else {         r = print(q, x + n, y);         if (r > 0) {           a[i] = b[i] = 0;         } else {           a[i] = b[i] = 1;           x += n;           y += n;         }       }     }     int x = 0;     for (int i = 0; i < 30; ++i) x += a[i] * (1 << i);     int y = 0;     for (int i = 0; i < 30; ++i) y += b[i] * (1 << i);     print( ! , x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, c;     cin >> a >> b >> c;     cout << (int)ceil(c * (a - b) / b);   }


#include <bits/stdc++.h>   inline int read() {     int x = 0, w = 1;     char ch = 0;     while (ch <  0  || ch >  9 ) {       ch = getchar();       if (ch ==  - ) w = -1;     }     while (ch <=  9  && ch >=  0 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * w;   }   using namespace std;   const int N = 5005;   const int M = 2e6 + 5;   const int Mod = 1e9 + 7;   char str[M];   int n, k1, k2, tot, tim, ans;   int s[N], bg[N], vis[N];   int dfn[N], low[N], b[N];   int mn[N], mx[N], cnt[N];   int fac[M], inv[M];   inline void ad(int &x, int y) {     x += y;     if (x >= Mod) x -= Mod;     if (x < 0) x += Mod;   }   inline int Pow(int x, int y) {     int res = 1;     while (y) {       if (y & 1) res = 1ll * res * x % Mod;       x = 1ll * x * x % Mod;       y >>= 1;     }     return res;   }   inline void math_init(int nn) {     fac[0] = 1;     for (int i = 1; i <= nn; ++i) fac[i] = 1ll * fac[i - 1] * i % Mod;     inv[nn] = Pow(fac[nn], Mod - 2);     for (int i = nn; i; --i) inv[i - 1] = 1ll * inv[i] * i % Mod;   }   inline int C(int x, int y) {     if (x < y || x < 0 || y < 0) return 0;     return 1ll * (1ll * fac[x] * inv[y] % Mod) * inv[x - y] % Mod;   }   vector<int> G[N], g[N], f[N];   stack<int> sta;   int gcd(int x, int y) {     if (!y) return x;     return gcd(y, x % y);   }   inline void input() {     n = read(), k1 = read(), k2 = read();     for (int i = 1; i <= n; ++i) {       scanf( %s , str + 1);       for (int j = 1; j <= n; ++j)         if (str[j] ==  1 ) G[i].push_back(j);     }     for (int i = 1; i <= n; ++i) {       s[i] = read();       scanf( %s , str + 1);       for (int j = 1; j <= s[i]; ++j) {         g[i].push_back(str[j] -  0 );         mn[i] += str[j] -  0 ;       }     }   }   void tarjan(int x) {     dfn[x] = low[x] = ++tim;     sta.push(x), vis[x] = 1;     for (int i = 0, sz = G[x].size(); i < sz; ++i) {       int y = G[x][i];       if (!dfn[y]) {         tarjan(y);         low[x] = min(low[x], low[y]);       } else if (vis[y])         low[x] = min(low[x], dfn[y]);     }     if (low[x] == dfn[x]) {       int now = 0;       ++tot;       do {         now = sta.top(), sta.pop(), vis[now] = 0;         b[now] = tot, bg[tot] = gcd(bg[tot], s[now]);       } while (now != x);     }   }   namespace sub1 {   inline void build() {     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i);     for (int i = 1; i <= tot; ++i) f[i].resize(bg[i] + 1);     for (int i = 1; i <= n; ++i)       for (int j = 0; j < s[i]; ++j) f[b[i]][j % bg[b[i]]] |= g[i][j];   }   inline void solve() {     build();     for (int i = tot; i > 1; --i) {       int now = gcd(bg[i], bg[i - 1]);       for (int j = 0; j < bg[i]; ++j) {         f[i - 1][j % now] |= f[i][j];         cnt[i] += f[i][j];       }     }     for (int i = 0; i < bg[1]; ++i) cnt[1] += f[1][i];     for (int i = 1; i <= n; ++i) mx[i] = 1ll * cnt[b[i]] * s[i] / bg[b[i]];   }   }  // namespace sub1   namespace sub2 {   inline void solve() {     for (int i = 1; i <= n; ++i) {       int cnt1 = 0, cnt2 = 0;       for (int j = 1; j <= n; ++j) {         if (i == j) continue;         if (mn[j] > mx[i])           ++cnt1;         else if (mx[j] > mx[i] || (mx[j] == mx[i] && j < i))           ++cnt2;       }       if (cnt1 > k1 - 1) continue;       for (int j = min(k2, min(k1 - 1 - cnt1, cnt2)); j + cnt1 + 1 >= k2; --j)         ad(ans, 1ll * C(cnt2, j) * C(cnt1, k2 - j - 1) % Mod);     }     printf( %d n , ans);   }   }  // namespace sub2   int main() {     math_init(M - 5), input();     sub1::solve(), sub2::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (m == 3 && n > 4) {       cout <<  -1  << endl;       return 0;     }     int cnt = 0, ans = 0;     for (int i = 0; i < m; i++) printf( %d %d n , i, ans += (cnt++));     if (m < n) cout << m + 100000 <<     << ans << endl;     for (int i = m + 1; i < n; i++) printf( %d %d n , i + 100000, ans -= (--cnt));     return 0;   }


#include <bits/stdc++.h>   const long long INF = 1e18;   void swap(long long &a, long long &b) {     long long temp;     temp = a;     a = b;     b = temp;   }   using namespace std;   void solve() {     long long n, k, ans;     cin >> n >> k;     ans = n;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i <= k) ans = min(ans, i);         if (i <= k) ans = min(ans, n / i);       }     }     cout << ans;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n >> x;     int pos = 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       ans += 1LL * (l - pos) % x + (r - l + 1);       pos = r + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int strike[10010];   bool isIn(long long x, long long y, long long cx, long long cr) {     return (x - cx) * (x - cx) + y * y <= cr * cr;   }   int main() {     int n, m;     cin >> n;     vector<pair<pair<long long, long long>, int> > mish(n + 2);     for (int i = 1; i <= n; i++)       cin >> mish[i].first.first >> mish[i].first.second, mish[i].second = i;     n += 1;     mish[0].first.first = -100000;     mish[0].first.second = 0;     mish[n].first.first = 100000;     mish[n].first.second = 0;     sort(mish.begin(), mish.end());     for (int i = 1; i <= n; i++) strike[i] = -1;     cin >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       int l = 0, r = n;       while (l < r) {         int s = (l + r) / 2 + 1;         if (x < mish[s].first.first)           r = s - 1;         else           l = s;       }       if (strike[mish[l].second] == -1 &&           isIn(x, y, mish[l].first.first, mish[l].first.second))         strike[mish[l].second] = i;       if (strike[mish[l + 1].second] == -1 &&           isIn(x, y, mish[l + 1].first.first, mish[l + 1].first.second))         strike[mish[l + 1].second] = i;     }     int c = 0;     for (int i = 1; i < n; i++)       if (strike[i] != -1) c++;     cout << c << endl;     for (int i = 1; i < n; i++) cout << strike[i] <<    ;   exit:     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   const int N = 300005;   int p[N], sum[N], dp[N];   vector<int> g[N];   bool cmp(int q, int w) { return (sum[q] > sum[w]); }   void dfs(int v, int pr = 0) {     p[v] = pr;     sum[v] = 1;     if (pr && g[v].size() == 1) {       dp[v] = v;       return;     }     vector<int> a;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (to == pr) continue;       dfs(to, v);       a.push_back(to);       sum[v] += sum[to];     }     sort((a).begin(), (a).end(), cmp);     int n = a.size();     int first = dp[a[0]];     while (sum[v] - sum[first] > sum[v] / 2) {       first = p[first];     }     dp[v] = first;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     for (int i = 2; i <= n; i++) {       int first;       cin >> first;       g[i].push_back(first);       g[first].push_back(i);     }     dfs(1);     for (int i = 1; i <= m; i++) {       int first;       cin >> first;       cout << dp[first] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mn = (long long)(1e9);   long long n, ans, k, a[311111], near[2111111], x;   bool mark[2111111];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       mark[a[i]] = 1;       mn = min(mn, a[i]);     }     for (int i = 1; i <= 2000000; i++) {       near[i] = x;       if (mark[i]) x = i;     }     for (int i = mn; i >= 1; i--) {       long long mx = -(long long)(1e9);       for (int j = 0; j <= 1000000; j += i) {         if (near[j + i] >= j) mx = max(mx, near[j + i] - j);       }       if (mx != -(long long)(1e9) && mx <= k) {         cout << i;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   unsigned long long power(long long x, unsigned long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   const long long maxn = 3000 * 3000;   long long g[maxn];   deque<pair<long long, long long>> d;   long long mat[3001][3001];   long long mn[3001][3001];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, m, a, b, x, y, z;     cin >> n >> m >> a >> b;     cin >> g[0] >> x >> y >> z;     for (long long i = 1; i < n * m + 1; i++) {       g[i] = (g[i - 1] * x + y) % z;     }     for (long long i = 1; i < n + 1; i++) {       for (long long j = 1; j < m + 1; j++) {         mat[i][j] = g[(i - 1) * m + j - 1];       }     }     for (long long i = 1; i < n + 1; i++) {       d.clear();       for (long long j = 1; j < m + 1; j++) {         while (d.size() && d.back().first > mat[i][j]) {           d.pop_back();         }         d.push_back({mat[i][j], j});         if (j >= b) {           mn[i][j] = d.front().first;           if (j - d.front().second >= b - 1) {             d.pop_front();           }         }       }     }     d.clear();     for (long long j = b; j < m + 1; j++) {       d.clear();       for (long long i = 1; i < n + 1; i++) {         while (d.size() && d.back().first > mn[i][j]) {           d.pop_back();         }         d.push_back({mn[i][j], i});         if (i >= a) {           mat[i][j] = d.front().first;           if (i - d.front().second >= a - 1) {             d.pop_front();           }         }       }     }     long long ans = 0;     for (long long i = a; i < n + 1; i++) {       for (long long j = b; j < m + 1; j++) {         ans += mat[i][j];       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(0);     std::cout.tie(0);     std::cin.tie(0);     int n;     std::cin >> n;     int a[n];     for (int i = 0; i < n; ++i) std::cin >> a[i];     std::sort(a, a + n);     for (int i = n - 1; i >= 0; --i) {       int t = sqrt(a[i]);       if (t * t != a[i]) {         std::cout << a[i] <<   n ;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, z, inf = 1e9, f[210][210], n, m, Max[210];   pair<pair<int, int>, int> p[40010];   pair<int, int> q[210];   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   int main() {     read(n);     read(m);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) f[i][j] = f[j][i] = inf;     for (int i = 1; i <= m; i++) {       read(x);       read(y);       read(z);       f[x][y] = f[y][x] = z;       p[i] = make_pair(make_pair(x, y), z);     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         if (i != k)           for (int j = 1; j <= n; j++)             if (j != i && j != k) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);     double Min = 1e9;     for (int i = 1; i <= n; i++) {       double Max = 0;       for (int j = 1; j <= n; j++) Max = max(Max, (double)f[i][j]);       Min = min(Min, Max);     }     for (int i = 1; i <= m; i++) {       int x = p[i].first.first, y = p[i].first.second;       for (int j = 1; j <= n; j++) q[j] = make_pair(f[x][j], f[y][j]);       sort(q + 1, q + n + 1);       Max[n + 1] = 0;       for (int j = n; j; j--) Max[j] = max(Max[j + 1], q[j].second);       for (int j = 1; j <= n; j++) {         int l = q[j].first, r = Max[j + 1];         if (l > r) swap(l, r);         if (l + p[i].second >= r) Min = min(Min, (l + p[i].second + r) / 2.0);       }     }     printf( %.1lf n , Min);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     multiset<int> s;     for (int v : a) s.insert(v);     int ans = 0;     for (int i = 0; i < n; ++i) {       auto it = s.upper_bound(a[i]);       if (it != s.end()) {         ++ans;         s.erase(it);       }     }     cout << ans <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios::sync_with_stdio(0);     solve();     return 0;   }   int a[1000001];   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       int v;       cin >> v;       a[v]++;     }     for (int i = 0; i < m; ++i) {       int v;       cin >> v;       a[v]--;     }     int ans = 0;     int j = 0;     for (int i = 1; i <= 1000000; ++i) {       if (a[i] > 0) {         j = max(j, i);         bool f = 0;         while (j <= 1000000 && !f) {           if (a[j] < 0) {             a[j]++;             f = 1;           } else             j++;         }         ans += !f;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char s[100000];   int col[100000], dp[21][1 << 20];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf(  %s , s);       for (int j = 0; j < m; j++) col[j] |= (s[j] -  0 ) << i;     }     for (int i = 0; i < m; i++) dp[0][col[i]]++;     for (int k = 1; k <= n; k++)       for (int mask = 0; mask < (1 << n); mask++) {         int sum = k > 1 ? (k - 2 - n) * dp[k - 2][mask] : 0;         for (int p = 0; p < n; p++) sum += dp[k - 1][mask ^ (1 << p)];         dp[k][mask] = sum / k;       }     int ans = n * m;     for (int mask = 0; mask < (1 << n); mask++) {       int cnt = 0;       for (int k = 0; k <= n; k++) cnt += min(k, n - k) * dp[k][mask];       ans = min(ans, cnt);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e11;   const int M = 1e5 + 5;   vector<pair<long long, int> > adj[M];   vector<int> ans;   long long d[M], vis[M], pre[M];   int n, m;   void Dijkstra() {     for (int i = 1; i <= n; ++i) d[i] = INF;     d[1] = 0;     priority_queue<pair<long long, int> > q;     q.push(make_pair(d[1], 1));     while (!q.empty()) {       int u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = 1;       for (int i = 0; i < adj[u].size(); ++i) {         int v = adj[u][i].second;         long long dist = adj[u][i].first + d[u];         if (d[v] > dist) {           d[v] = dist;           pre[v] = u;           q.push(make_pair(-d[v], v));         }       }     }   }   int main() {     int u, v, w;     cin >> n >> m;     while (m--) {       cin >> u >> v >> w;       adj[u].push_back(make_pair(w, v));       adj[v].push_back(make_pair(w, u));     }     Dijkstra();     if (d[n] == INF)       cout <<  -1  << endl;     else {       for (int i = n; pre[i]; i = pre[i]) ans.push_back(pre[i]);       for (int i = ans.size() - 1; i >= 0; --i) cout << ans[i] <<    ;       cout << n <<    ;       cout << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     int f = 0;     for (; !isdigit(c); c = getchar()) f |= c ==  - ;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     if (f) x = -x;   }   template <typename T>   void write(T x, char ed =   n ) {     static short st[30];     short tp = 0;     if (x < 0) putchar( - ), x = -x;     do st[++tp] = x % 10, x /= 10;     while (x);     while (tp) putchar(st[tp--] |  0 );     putchar(ed);   }   const int N = 505000;   struct node {     long long d;     int id;     bool operator<(const node &i) const { return id < i.id; }     node(long long D = 0, int I = 0) : d(D), id(I) {}   };   vector<vector<node> > vec;   vector<node> ety;   int ne[N << 1], to[N << 1], h[N], f[N], rt, tot, n;   inline void add(int x, int y) { ne[++tot] = h[x], to[h[x] = tot] = y; }   int dep[N], L[N], R[N], cnt;   int son[N], mxd[N], rev[N];   long long ans[N];   void dfs1(int x, int fa) {     mxd[x] = dep[x] = dep[fa] + 1, L[x] = ++cnt, rev[cnt] = x;     if (dep[x] >= vec.size()) vec.push_back(ety);     vec[dep[x]].push_back(node(0, L[x]));     for (int i = h[x]; i; i = ne[i]) {       int y = to[i];       dfs1(to[i], x);       if (mxd[y] >= mxd[x]) son[x] = y, mxd[x] = mxd[y];     }     R[x] = cnt;   }   inline bool inc(int x, int l, int r) { return R[x] >= r && L[x] <= l; }   long long tab[N], t[N];   void dfs2(int x) {     int ct = 0, nw = dep[x];     long long res = 0;     t[dep[x]]++;     auto pl = lower_bound(vec[dep[x]].begin(), vec[dep[x]].end(), node(0, L[x])),          pr = pl;     ++pr;     while ( jzpakioi , true) {       res += 1ll * (ct += t[nw]) * (pr - pl) + tab[nw];       tab[nw] = t[nw] = 0, pl->d += res;       if (pr != vec[nw].end()) pr->d -= res;       if (++nw > mxd[x]) break;       pl = lower_bound(vec[nw].begin(), vec[nw].end(), node(0, L[x]));       pr = upper_bound(vec[nw].begin(), vec[nw].end(), node(0, R[x]));       if (inc(son[x], pl->id, (pr - 1)->id)) {         t[nw] += ct, tab[nw] += res;         break;       }     }     if (son[x]) dfs2(son[x]);     for (int i = h[x]; i; i = ne[i])       if (to[i] != son[x]) dfs2(to[i]);   }   int main() {     read(n), vec.push_back(ety);     for (int i = 1; i <= n; i++) read(f[i]), f[i] ? add(f[i], i), 0 : rt = i;     dfs1(rt, 0), dfs2(rt);     for (int i = 1; i <= mxd[rt]; i++) {       long long res = 0;       for (auto t : vec[i]) res += t.d, ans[rev[t.id]] += res;     }     for (int i = 1; i <= n; i++) write(ans[i] - dep[i],    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1};   int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};   vector<int> adj[300010], val(300010, 1), vis(300010, 0), dis1(300010, 0),       dis2(300010, 0);   int myrandom(int i) { return std::rand() % i; }   int dp[5010];   int n;   set<pair<int, int>> st;   int maxi = 0;   int poss[5010][5010];   void dfs(int a) {     vis[a] = 1;     int cnt = 0;     vector<int> v;     for (auto i : adj[a]) {       if (vis[i] == 0) {         dfs(i);         if (dp[i] > 0) {           v.push_back(dp[i]);         }         cnt = cnt + dp[i];       }     }     int cnt1 = n - cnt - 1;     if (cnt1 > 0) {       v.push_back(cnt1);     }     int n = (int)v.size();     int sum = accumulate((v).begin(), (v).end(), 0);     int res[sum + 1];     memset(res, 0, sizeof(res));     res[0] = 1;     for (int i = 0; i < n; i++) {       for (int j = sum; j >= 0; j--) {         if (j - v[i] >= 0) {           res[j] = res[j] | res[j - v[i]];         }       }     }     maxi = max(maxi, sum);     for (int i = 1; i < sum; i++) {       poss[i][sum - i] = poss[i][sum - i] | res[i];     }     dp[a] = 1 + cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     memset(poss, 0, sizeof(poss));     dfs(1);     vector<pair<int, int>> ans;     for (int i = 1; i <= 5000; i++) {       for (int j = 1; j <= 5000; j++) {         if (i + j == maxi && poss[i][j] == 1) {           ans.push_back({i, j});         }       }     }     cout << (int)ans.size() <<   n ;     for (auto i : ans) {       cout << i.first <<     << i.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct st {     int t, p, g;     char s[30];   } a[100];   int x[3];   int y[6];   int main() {     int n, m, i, j, k;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%s , &m, a[i].s);       for (j = 0; j < m; j++) {         scanf( %d-%d-%d , &x[0], &x[1], &x[2]);         for (k = 0; k < 3; k++) {           y[k * 2] = x[k] / 10;           y[k * 2 + 1] = x[k] % 10;         }         for (k = 0; k < 5; k++)           if (y[k] != y[k + 1]) break;         if (k == 5) {           a[i].t++;           continue;         }         for (k = 0; k < 5; k++)           if (y[k] <= y[k + 1]) break;         if (k == 5)           a[i].p++;         else           a[i].g++;       }     }     vector<int> ans;     int ma = a[0].t;     ans.push_back(0);     for (i = 1; i < n; i++) {       if (a[i].t > ma) {         ans.clear();         ans.push_back(i);         ma = a[i].t;       } else if (a[i].t == ma) {         ans.push_back(i);       }     }     printf( If you want to call a taxi, you should call:  );     printf( %s , a[ans[0]].s);     for (i = 1; i < ans.size(); i++) printf( , %s , a[ans[i]].s);     printf( . n );     ans.clear();     ma = a[0].p;     ans.push_back(0);     for (i = 1; i < n; i++) {       if (a[i].p > ma) {         ans.clear();         ans.push_back(i);         ma = a[i].p;       } else if (a[i].p == ma) {         ans.push_back(i);       }     }     printf( If you want to order a pizza, you should call:  );     printf( %s , a[ans[0]].s);     for (i = 1; i < ans.size(); i++) printf( , %s , a[ans[i]].s);     printf( . n );     ans.clear();     ma = a[0].g;     ans.push_back(0);     for (i = 1; i < n; i++) {       if (a[i].g > ma) {         ans.clear();         ans.push_back(i);         ma = a[i].g;       } else if (a[i].g == ma) {         ans.push_back(i);       }     }     printf(          If you want to go to a cafe with a wonderful girl, you should call:  );     printf( %s , a[ans[0]].s);     for (i = 1; i < ans.size(); i++) printf( , %s , a[ans[i]].s);     printf( . n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n, x, sum(0), cnt(0), prev(INT_MAX);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (i && x == prev)         cnt++;       else         cnt = 1;       prev = x;       sum += cnt;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, bool> mp;   bool check(int x, int y, int z) {     if (y < x) swap(x, y);     if (z < y) swap(z, y);     if (y < x) swap(x, y);     if (x + y > z && z > y && mp.count({x, y}) == 0) {       mp[{x, y}] = 1;       return 1;     } else       return 0;   }   int main() {     int n;     cin >> n;     long long ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if ((i ^ j) <= n && check(i, j, (i ^ j))) ans++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int n;     while (t--) {       int n;       string s;       cin >> n;       cin >> s;       int flag = 1, start = 0, end = n - 1;       while (start <= end) {         char ssp = s[start] + 1;         char sep = s[end] + 1;         char sem = s[end] - 1;         char ssm = s[start] - 1;         if ((ssp == sep) || (ssp == sem) || (ssm == sep) || (ssm == sem))           flag = 1;         else {           flag = 0;           break;         }         start++;         end--;       }       if (flag == 0)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[111];   int main() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &arr[i]);     sort(arr, arr + n);     int t = 10;     int ans = 0;     int qts = 0;     for (int i = (0); i < (n); ++i) {       t += arr[i];       if (t > 720) break;       qts++;       if (t > 360) ans += (t - 360);     }     printf( %d %d n , qts, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m, ti;     scanf( %d:%d , &h, &m);     scanf( %d , &ti);     int realh = ti / 60, realmin = ti % 60;     while (realh--) {       if (h == 23)         h = 0;       else         h++;     }     while (realmin--) {       if (m == 59) {         m = 0;         if (h == 23)           h = 0;         else           h++;       } else         m++;     }     if (h < 10) printf( 0 );     printf( %d: , h);     if (m < 10) printf( 0 );     printf( %d , m);     return 0;   }


#include <bits/stdc++.h>   using i64 = long long;   template <typename _Tp>   inline void chkMax(_Tp &x, const _Tp &y) {     (x < y) and (x = y);   }   namespace IOManager {   constexpr int FILESZ = 131072;   char buf[FILESZ];   const char *ibuf = buf, *tbuf = buf;   struct IOManager {     inline char gc() {       return (ibuf == tbuf) and                      (tbuf = (ibuf = buf) + fread(buf, 1, FILESZ, stdin),                       ibuf == tbuf)                  ? EOF                  : *ibuf++;     }     template <typename _Tp>     inline operator _Tp() {       _Tp s = 0u;       char c = gc();       for (; c < 48; c = gc())         ;       for (; c > 47; c = gc()) s = (_Tp)(s * 10u + c - 48u);       return s;     }   };   }  // namespace IOManager   IOManager::IOManager io;   int main() {     static std::map<i64, i64> f;     const int n = io;     for (int i = 1; i <= n; ++i) {       const i64 a = io;       if (i == 1) f[a - 1] = 0;       for (auto it = f.rbegin(); it not_eq f.rend() and it->first >= a; ++it) {         const i64 v = it->first;         chkMax(f[v % a], it->second + (v - v % a) * (i - 1ll));         chkMax(f[a - 1], it->second + ((v - a + 1ll) / a * a) * (i - 1ll));       }       f.erase(f.lower_bound(a), f.end());     }     i64 ans = 0;     for (const auto it : f) chkMax(ans, it.second + it.first * n);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005];   long long k1[200005];   long long k2[200005];   string ss =  first ;   string sp =  second ;   int main() {     int n;     cin >> n;     int r1 = 0;     int r2 = 0;     long long s1 = 0;     long long s2 = 0;     int l1 = 0;     int l2 = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > 0) {         { k1[l1++] = a[i]; }         s1 += a[i];         r1 = 1;       } else {         { k2[l2++] = -a[i]; }         s2 += -a[i];         r1 = 0;       }     }     if (s1 > s2) {       cout << ss << endl;       return 0;     }     if (s1 < s2) {       cout << sp << endl;       return 0;     }     if (s1 == s2) {       for (int i = 0; i < min(l1, l2); i++) {         if (k1[i] > k2[i]) {           cout << ss << endl;           return 0;         }         if (k2[i] > k1[i]) {           cout << sp << endl;           return 0;         }       }       if (!r1) {         cout << sp << endl;         return 0;       } else {         cout << ss << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int input() {     int res = 0, m = 1;     char c =    ;     while (c <  0  && c !=  - ) c = getchar();     if (c ==  - ) m = -1, c = getchar();     while (c >=  0 ) res = res * 10 + (c -  0 ), c = getchar();     return res * m;   }   const int N = 501;   int n, k, lft[N], l_siz, fl[N], rht[N], r_siz, fr[N];   void shift() {     while (r_siz) lft[l_siz] = rht[--r_siz], ++l_siz;     if (l_siz) fl[0] = lft[0];     for (int i = 1; i < l_siz; ++i) fl[i] = max(fl[i - 1], lft[i]);   }   void push(int x) {     int prev = (r_siz ? fr[r_siz - 1] : 0);     rht[r_siz] = x, fr[r_siz] = max(prev, x), ++r_siz;   }   void pop() {     if (!l_siz) shift();     --l_siz;   }   int get() {     int res = 0;     if (l_siz) res = fl[l_siz - 1];     if (r_siz) res = max(res, fr[r_siz - 1]);     return res;   }   int a[N][N], mx[N][N], ans = 2e9;   int main() {     int n = input(), m = input(), k = input();     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) a[i][j] = 2e9;     for (int q = input(); q; --q) {       int i = input() - 1, j = input() - 1, t = input();       a[i][j] = t;     }     for (int j = 0; j < m; ++j) {       for (int i = 0; i < k; ++i) push(a[i][j]);       mx[0][j] = get();       for (int i = 0; i < n - k; ++i) {         pop(), push(a[i + k][j]);         mx[i + 1][j] = get();       }       while (l_siz + r_siz) pop();     }     for (int i = 0; i <= n - k; ++i) {       for (int j = 0; j < k; ++j) push(mx[i][j]);       ans = min(ans, get());       for (int j = 0; j < m - k; ++j) {         pop(), push(mx[i][j + k]);         ans = min(ans, get());       }       while (l_siz + r_siz) pop();     }     cout << (ans == 2e9 ? -1 : ans);   }


#include <bits/stdc++.h>   int main() {     int t, a, b, c, d, k, i, pen, pencil;     scanf( %d , &t);     for (i = 0; i < t; i++) {       scanf( %d %d %d %d %d , &a, &b, &c, &d, &k);       if (a % c != 0) {         pen = (a / c) + 1;       }       if (a % c == 0) {         pen = (a / c);       }       if (b % d != 0) {         pencil = (b / d) + 1;       }       if (b % d == 0) {         pencil = (b / d);       }       if (pen + pencil <= k) {         printf( %d %d n , pen, pencil);       } else {         printf( -1 n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int countInversions(long long int a[], long long int temp[],                                 long long int l, long long int r) {     if (l >= r) {       return 0;     }     long long int count1 = countInversions(a, temp, l, (l + r) / 2);     long long int count2 = countInversions(a, temp, (l + r) / 2 + 1, r);     long long int mergeCount = 0;     long long int indexLeft = l;     long long int endLeft = (l + r) / 2 + 1;     long long int indexRight = (l + r) / 2 + 1;     while (indexRight <= r && indexLeft < endLeft) {       while (indexLeft < endLeft && a[indexLeft] <= a[indexRight]) {         indexLeft++;       }       mergeCount += endLeft - indexLeft;       indexRight++;     }     indexLeft = l, indexRight = (l + r) / 2 + 1;     long long int idx = l;     while (indexRight <= r && indexLeft < endLeft) {       if (a[indexLeft] <= a[indexRight]) {         temp[idx++] = a[indexLeft];         indexLeft++;       } else {         temp[idx++] = a[indexRight];         indexRight++;       }     }     while (indexRight <= r) {       temp[idx++] = a[indexRight];       indexRight++;     }     while (indexLeft < endLeft) {       temp[idx++] = a[indexLeft];       indexLeft++;     }     for (long long int i = l; i <= r; i++) {       a[i] = temp[i];     }     return mergeCount + count1 + count2;   }   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     map<char, deque<long long int>> positionsOfLetters;     long long int i, n, count = 0;     cin >> n;     char s[n];     for (i = 0; i < n; i++) {       cin >> s[i];       positionsOfLetters[s[i]].push_back(i);     }     reverse(s, s + n);     long long int permuation[n];     for (i = 0; i < n; i++) {       permuation[i] = positionsOfLetters[s[i]].front();       positionsOfLetters[s[i]].pop_front();     }     long long int temp[n + 1];     cout << countInversions(permuation, temp, 0, n - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s;     bool ok = false;     for (int i = 0; i < s.size(); i++) {       if (s.size() - i < 26) break;       int j = i;       vector<int> f(26);       int qq = 0;       while (j < s.size() && j - i + 1 <= 26) {         if (s[j] !=  ? )           f[s[j] -  A ]++;         else           qq++;         if (j - i + 1 == 26) break;         j++;       }       int have = 0;       queue<char> need;       for (int k = 0; k < 26; k++) {         if (f[k] > 0)           have++;         else           need.push(char(k +  A ));       }       int want = 26 - have;       if (want == qq) {         ok = true;         for (int k = i; k <= j; k++)           if (s[k] ==  ? ) {             s[k] = need.front();             need.pop();           }       }     }     if (!ok) {       puts( -1 );     } else {       for (auto c : s) {         if (c ==  ? )           cout <<  A  <<   ;         else           cout << c <<   ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[400005];   int q, x;   int main() {     int aux, cnt = 0, maxim = 0;     cin >> q >> x;     for (int i = 1; i <= q; i++) {       cin >> aux;       a[aux % x]++;       while (a[cnt] > maxim) {         cnt++;         if (cnt == x) {           cnt = 0;           maxim++;         }       }       cout << maxim * x + cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[4] = {-1, 0, 0, 1};   int dy[4] = {0, -1, 1, 0};   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first == b.first) return a.second < b.second;     return (a.first < b.first);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long x, y, t, c;     cin >> x >> y;     if (y == 0) {       cout <<  No  << endl;       return 0;     }     if (y == 1) {       if (x > 0) {         cout <<  No  << endl;         return 0;       }     }     t = y - 1;     t = x - t;     if (t % 2 == 0 && t >= 0) {       cout <<  Yes  << endl;       return 0;     }     cout <<  No  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[6], b[6];   int getMinWin(int idx) {     if (idx == 3) return a[0] + a[1] + a[2];     int ret = INT_MAX;     int bIdx = idx;     int bIdxPrev = (idx - 1 + 3) % 3;     int minIdxbIdx = min(a[idx], b[bIdx]);     a[idx] -= minIdxbIdx;     b[bIdx] -= minIdxbIdx;     int minIdxbIdxPrev = min(a[idx], b[bIdxPrev]);     a[idx] -= minIdxbIdxPrev;     b[bIdxPrev] -= minIdxbIdxPrev;     ret = min(ret, getMinWin(idx + 1));     a[idx] += minIdxbIdx;     b[bIdx] += minIdxbIdx;     a[idx] += minIdxbIdxPrev;     b[bIdxPrev] += minIdxbIdxPrev;     return ret;   }   int getMaxWin() { return min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0]); }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < 3; i++) scanf( %d , &a[i]);     for (int i = 0; i < 3; i++) scanf( %d , &b[i]);     int minWin = INT_MAX;     for (int i = 0; i < 3; i++) {       minWin = min(minWin, getMinWin(0));       for (int j = 0; j < 2; j++) {         swap(a[j], a[j + 1]);         swap(b[j], b[j + 1]);       }     }     printf( %d %d n , minWin, getMaxWin());   }


#include <bits/stdc++.h>   int n, d, m, t[200005][2], l, p, r, b;   long long ans;   std::pair<int, int> s[200005];   bool a = true;   int main() {     scanf( %d %d %d , &d, &n, &m);     for (int i = 0; i < m; i++) scanf( %d %d , &s[i].first, &s[i].second);     std::sort(s, s + m);     t[l][0] = 0;     t[l++][1] = n;     s[m].first = d;     s[m].second = 0;     for (int i = 0; i <= m && a; i++) {       if (s[i].first - p > n)         a = false;       else {         r = s[i].first - p;         while (s[i].first > p) {           if (p + t[b][1] <= s[i].first) {             ans += (long long)t[b][0] * t[b][1];             p += t[b][1];             b++;           } else {             ans += (long long)t[b][0] * (s[i].first - p);             t[b][1] -= s[i].first - p;             p = s[i].first;           }         }         while (l > b && s[i].second <= t[l - 1][0]) r += t[--l][1];         t[l][0] = s[i].second;         t[l++][1] = r;       }     }     printf( %I64d n , a ? ans : -1);     scanf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if ((a == 0) || (b == 0)) return a + b;     return gcd(b, a % b);   }   long long pow_mod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   long long pow_2(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a);       a = (a * a);       b >>= 1;     }     return res;   }   bool isPrime(long long a) {     for (int i = 3; (i * i) <= a; i += 2) {       if ((a % i) == 0) return false;     }     if ((a != 2) && ((a % 2) == 0)) return false;     return true;   }   string con_ll_to_str(int a) {     stringstream mystr;     mystr << a;     return mystr.str();   }   long long con_str_to_ll(string st) {     long long numb = 0;     int len = st.size(), i, j = 0;     for (i = len - 1; i >= 0; i--) {       numb += (pow_mod(10, j) * (st[i] -  0 ));       j++;     }     return numb;   }   long long baseno_to_decimal(string st, long long basee) {     long long i = 0, j, anss = 0;     for (j = (int)st.length() - 1; j >= 0; j--) {       anss += (st[j] -  0 ) * pow_2(basee, i);       i++;     }     return anss;   }   string decimal_to_string(long long num, long long basee) {     long long i = 0, j, opop;     string anss =   ;     vector<string> stri;     stri.push_back( 0 );     stri.push_back( 1 );     stri.push_back( 2 );     stri.push_back( 3 );     stri.push_back( 4 );     stri.push_back( 5 );     stri.push_back( 6 );     stri.push_back( 7 );     stri.push_back( 8 );     stri.push_back( 9 );     stri.push_back( A );     stri.push_back( B );     stri.push_back( C );     stri.push_back( D );     stri.push_back( E );     stri.push_back( F );     while (num) {       opop = num % basee;       anss += stri[opop];       num /= basee;     }     reverse(anss.begin(), anss.end());     return anss;   }   long long par[10010], dist[10010], N, M;   bool flag1, flag2;   pair<long long, long long> mapp[6];   map<string, string> ma;   vector<long long> vc[10010];   string st[110];   vector<long long> path_d;   struct comp {     bool operator()(pair<long long, long long> n1,                     pair<long long, long long> n2) {       return n1.second > n2.second;     }   };   void dijk(long long src) {     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >, comp>         prqu;     prqu.push(make_pair(src, 0));     long long i, j, kk;     for (i = 0; i <= 10000; i++) {       dist[i] = INT_MAX;     }     memset(par, -1, sizeof(par));     dist[src] = 0;     while (!prqu.empty()) {       pair<long long, long long> xx = prqu.top();       prqu.pop();       for (kk = 0; kk <= (int)vc[xx.first].size() - 1; kk++) {         if (dist[vc[xx.first][kk]] > (xx.second + 1)) {           par[vc[xx.first][kk]] = xx.first;           dist[vc[xx.first][kk]] = xx.second + 1;           prqu.push(make_pair(vc[xx.first][kk], xx.second + 1));         }       }     }   }   void gr_cons(long long i, long long j, long long fi) {     if (i <= 0 || i > N || j <= 0 || j > M) {       return;     }     long long sec;     if (st[i][j] ==  .  || st[i][j] ==  F ) {       sec = ((i - 1) * M) + j;       vc[fi].push_back(sec);     }   }   string rev(string ch) {     if (ch ==  U  || ch ==  D ) {       if (ch ==  U ) return  D ;       return  U ;     }     if (ch ==  L  || ch ==  R ) {       if (ch ==  L ) return  R ;       return  L ;     }   }   void find_pos(long long i, long long j, pair<long long, long long> poss) {     if ((poss.first + 1) == i && j == poss.second) {       cout << ma[ D ] <<   n ;     } else if ((poss.first - 1) == i && j == poss.second) {       cout << ma[ U ] <<   n ;     } else if (poss.first == i && j == (poss.second - 1)) {       cout << ma[ L ] <<   n ;     } else {       cout << ma[ R ] <<   n ;     }   }   int main() {     long long i, j, fi, X, Y, o1;     cin >> N >> M;     for (i = 1; i <= N; i++) {       cin >> st[i];       st[i] =  #  + st[i];       st[0] = st[i];       st[N + 1] = st[i];     }     for (i = 0; i <= M; i++) {       st[0][i] =  . ;       st[i][0] =  . ;       st[i][M + 1] =  . ;       st[N + 1][i] =  . ;     }     for (i = 1; i <= N; i++) {       for (j = 1; j <= M; j++) {         if (st[i][j] ==  .  || st[i][j] ==  F ) {           fi = (i - 1) * M + j;           gr_cons(i - 1, j, fi);           gr_cons(i + 1, j, fi);           gr_cons(i, j - 1, fi);           gr_cons(i, j + 1, fi);         }         if (st[i][j] ==  F ) {           o1 = (i - 1) * M + j;         }       }     }     dijk(1);     while (o1 != -1) {       path_d.push_back(o1);       o1 = par[o1];     }     reverse(path_d.begin(), path_d.end());     pair<long long, long long> pos = make_pair(1, 1);     stack<string> stac;     if (st[pos.first + 1][pos.second] !=  *  &&         st[pos.first - 1][pos.second] !=  * ) {       flag1 = 1;       fflush(stdout);       cout <<  U             <<   n ;       fflush(stdout);       cin >> X >> Y;       if (st[X][Y] ==  F ) {         return 0;       }       if (X == (pos.first - 1) || X == pos.first) {         ma[ U ] =  U ;         ma[ D ] =  D ;       } else {         ma[ U ] =  D ;         ma[ D ] =  U ;       }       pos = make_pair(X, Y);     } else if (st[pos.first][pos.second + 1] !=  *  &&                st[pos.first][pos.second - 1] !=  * ) {       flag2 = 1;       fflush(stdout);       cout <<  R             <<   n ;       fflush(stdout);       cin >> X >> Y;       if (st[X][Y] ==  F ) {         return 0;       }       if (Y == (pos.second + 1)) {         ma[ L ] =  L ;         ma[ R ] =  R ;       } else {         ma[ L ] =  R ;         ma[ R ] =  L ;       }       pos = make_pair(X, Y);     }     if (flag1) {       if (pos != make_pair(1LL, 1LL)) {         fflush(stdout);         cout << rev( U ) <<   n ;         fflush(stdout);         cin >> X >> Y;       }       pos = make_pair(1, 1);       while (1) {         if (st[pos.first][pos.second + 1] !=  *  &&             st[pos.first][pos.second - 1] !=  * ) {           fflush(stdout);           cout <<  R                 <<   n ;           fflush(stdout);           cin >> X >> Y;           if (pos != make_pair(X, Y)) stac.push(rev( R ));           if (st[X][Y] ==  F ) {             return 0;           }           if (Y == (pos.second + 1)) {             ma[ L ] =  L ;             ma[ R ] =  R ;           } else {             ma[ L ] =  R ;             ma[ R ] =  L ;           }           pos = make_pair(X, Y);           break;         }         fflush(stdout);         cout << ma[ D ] <<   n ;         fflush(stdout);         cin >> X >> Y;         pos = make_pair(X, Y);         stac.push(rev(ma[ D ]));         if (st[X][Y] ==  F ) {           return 0;         }       }     } else {       if (pos != make_pair(1LL, 1LL)) {         fflush(stdout);         cout << rev( R ) <<   n ;         fflush(stdout);         cin >> X >> Y;       }       while (1) {         if (st[pos.first + 1][pos.second] !=  *  &&             st[pos.first - 1][pos.second] !=  * ) {           fflush(stdout);           cout <<  U                 <<   n ;           fflush(stdout);           cin >> X >> Y;           if (pos != make_pair(X, Y)) stac.push(rev( U ));           if (st[X][Y] ==  F ) {             return 0;           }           if (X == (pos.first - 1) || X == pos.first) {             ma[ U ] =  U ;             ma[ D ] =  D ;           } else {             ma[ U ] =  D ;             ma[ D ] =  U ;           }           pos = make_pair(X, Y);           break;         }         fflush(stdout);         cout << ma[ R ] <<   n ;         fflush(stdout);         cin >> X >> Y;         pos = make_pair(X, Y);         stac.push(rev(ma[ R ]));         if (st[X][Y] ==  F ) {           return 0;         }       }     }     if (pos != make_pair(1LL, 1LL)) {       while (stac.size()) {         fflush(stdout);         cout << stac.top() <<   n ;         fflush(stdout);         stac.pop();         cin >> X >> Y;       }     }     pos = make_pair(1, 1);     for (i = 1; i <= (int)path_d.size() - 1; i++) {       fflush(stdout);       if (!(path_d[i] % M)) {         find_pos(path_d[i] / M, M, pos);       } else {         find_pos((path_d[i] / M) + 1, (path_d[i] % M), pos);       }       fflush(stdout);       cin >> X >> Y;       pos = make_pair(X, Y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i;   int p[200011];   int aib[200011];   int ord[2][200011];   int ans[200011];   int zrs(int x) { return (x & (x - 1)) ^ x; }   void add(int x, int v) {     while (x <= n) {       aib[x] += v;       x += zrs(x);     }   }   int sum(int x) {     int ans = 0;     while (x > 0) {       ans += aib[x];       x -= zrs(x);     }     return ans;   }   int cb(int x) {     int ans = 0;     for (int step = (1 << 19); step > 0; step >>= 1)       if (ans + step <= n)         if (aib[ans + step] <= x) x -= aib[ans += step];     return ans;   }   void get_order(int n, int *p, int *ans) {     int i;     for (i = 1; i <= n; i++) aib[i] = zrs(i);     memset(ans, 0, sizeof(ans));     for (i = 1; i <= n; i++) {       ans[n - i] = sum(p[i] - 1);       add(p[i], -1);     }   }   void get_perm(int n, int *ord, int *ans) {     int i, cnt, pos;     for (i = 1; i <= n; i++) aib[i] = zrs(i);     memset(ans, 0, sizeof(ans));     for (i = 1; i <= n; i++) {       cnt = ord[n - i] + 1;       pos = cb(cnt - 1) + 1;       ans[i] = pos;       add(pos, -1);     }   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &p[i]), p[i]++;     get_order(n, p, ord[0]);     for (i = 1; i <= n; i++) scanf( %d , &p[i]), p[i]++;     get_order(n, p, ord[1]);     for (i = 1; i <= n; i++) ord[0][i] += ord[1][i];     for (i = 1; i <= n; i++) {       ord[0][i + 1] += ord[0][i] / (i + 1);       ord[0][i] %= i + 1;     }     get_perm(n, ord[0], ans);     for (i = 1; i <= n; i++) printf( %d  , ans[i] - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N = 0, p = 0, q = 0;     int k = 0;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> p >> q;       if (q - p >= 2) k++;     }     cout << k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int nax = 1e6 + 10;   vector<int> tree(4 * nax);   long long i, j, x, y, k;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, t;     cin >> t;     while (t--) {       cin >> n;       vector<long long> a;       set<long long> b;       for (i = 0; i < n; i++) {         cin >> x;         a.push_back(x);         b.insert(x);       }       if (b.size() == 1) {         cout << 1 << endl;         for (i = 0; i < n; i++) cout << 1 <<    ;       } else if (a.size() % 2 == 0) {         cout << 2 << endl;         for (i = 0; i < n / 2; i++) cout << 1 <<     << 2 <<    ;       } else if (a.size() % 2 != 0) {         vector<long long> ans;         int p = 0, q = 0;         ans.push_back(1);         for (i = 1; i < a.size() - 1; i++) {           if (a[i] == a[i - 1] && p == 0) {             ans.push_back(ans[i - 1]);             p = 1;           } else if (q == 0) {             ans.push_back(2);             q = 1;           } else if (q == 1) {             ans.push_back(1);             q = 0;           }         }         if (p == 1) {           if (q == 1)             ans.push_back(1);           else             ans.push_back(2);         } else {           if (a[n - 1] == a[n - 2])             ans.push_back(ans[n - 2]);           else if (a[n - 1] == a[0])             ans.push_back(ans[0]);           else             ans.push_back(3);         }         if (ans[n - 1] == 3)           cout << 3 << endl;         else           cout << 2 << endl;         for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> lucky;   void backtrack(long long x) {     if (x > 1e10) return;     lucky.push_back(x);     backtrack(x * 10 + 4);     backtrack(x * 10 + 7);   }   int main() {     long long ans = 0;     backtrack(0);     sort(lucky.begin(), lucky.end());     int a, b;     cin >> a >> b;     for (int i = 1; i < (int)lucky.size(); i++) {       int l, r, m;       l = a, r = b;       while (l <= r) {         m = (l + r) >> 1;         if (m <= lucky[i]) {           ans += lucky[i] * (m - l + 1);           a = m + 1;           i--;           break;         } else {           r = m - 1;         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     vector<pair<int, int>> vp(n);     for (int i = 0; i < n; i++) cin >> vp[i].first >> vp[i].second;     sort(vp.begin(), vp.end());     long long res = 1;     pair<int, int> pa = {vp[0].first, vp[0].second};     for (int i = 0; i < n; i++) {       if (vp[i].first > pa.second)         pa = {vp[i].first, vp[i].second}, res++;       else if (vp[i].second < pa.second)         pa = {vp[i].first, vp[i].second};     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     int m, c;     int mc = 0, cc = 0;     cin >> t;     while (t--) {       cin >> m >> c;       if (m > c)         mc++;       else if (m < c)         cc++;     }     if (mc == cc)       cout <<  Friendship is magic!^^ ;     else if (mc < cc)       cout <<  Chris ;     else       cout <<  Mishka ;   }


#include <bits/stdc++.h>   using namespace std;   int N;   struct node {     int val, pos;   } A[2005];   int res[2005];   int cmp1(node a, node b) { return a.val > b.val; }   int main() {     A[0].val = 0x7fffffff;     cin >> N;     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i].val);       A[i].pos = i;     }     sort(A + 1, A + 1 + N, cmp1);     for (int i = 1; i <= N; i++) {       if (A[i - 1].val == A[i].val)         res[A[i].pos] = res[A[i - 1].pos];       else         res[A[i].pos] = i;     }     for (int i = 1; i <= N; i++) printf( %d%c , res[i], i == N ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 10;   const long long M = 1e6 + 11;   const long long big = 1e17;   const long long hsh2 = 1964325029;   const long long mod = 1e9 + 7;   const double EPS = 1e-9;   const long long block = 1e14;   const long long shift = 2e3;   const double pi = acos(-1.0);   mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());   long long n;   struct dsu {     long long p[N], sz[N];     set<long long> comp;     void init() {       for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1, comp.insert(i);     }     long long fnd(long long a) { return (p[a] = (p[a] == a ? a : fnd(p[a]))); }     void unt(long long a, long long b) {       a = fnd(a), b = fnd(b);       if (a == b) return;       if (sz[a] < sz[b]) swap(a, b);       comp.erase(b);       sz[a] += sz[b];       p[b] = a;     }   } rt[2];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     rt[0].init();     rt[1].init();     long long m[2] = {0};     cin >> m[0] >> m[1];     long long sm[2] = {m[0], m[1]};     while (m[0]--) {       long long a, b;       cin >> a >> b;       rt[0].unt(a, b);     }     while (m[1]--) {       long long a, b;       cin >> a >> b;       rt[1].unt(a, b);     }     vector<pair<long long, long long> > ans;     while (sm[0] < n - 1 && sm[1] < n - 1) {       long long i = bruh() % n + 1, j = bruh() % n + 1;       auto it = rt[0].comp.lower_bound(i), it2 = rt[1].comp.lower_bound(j);       if (it == rt[0].comp.end()) it--;       if (it2 == rt[1].comp.end()) it2--;       i = *it, j = *it2;       if (rt[0].fnd(i) != rt[0].fnd(j) && rt[1].fnd(i) != rt[1].fnd(j)) {         sm[0]++, sm[1]++;         rt[0].unt(i, j);         rt[1].unt(i, j);         ans.push_back(make_pair(i, j));       }     }     cout << ans.size() <<   n ;     for (auto u : ans) cout << u.first <<     << u.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[100005];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     int cur = min(2, n);     int best = min(2, n);     for (int i = 2; i < n; i++) {       if (arr[i - 2] + arr[i - 1] == arr[i])         cur++;       else         cur = 2;       best = max(best, cur);     }     cout << best << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l;     cin >> n;     string s;     for (int i = 0; i < n; i++) {       cin >> l;       cin >> s;       int ans = 0;       bool lol = false;       int tmp = 0;       for (int j = 0; j < l; j++) {         if (s[j] ==  A ) {           lol = true;           if (tmp > ans) ans = tmp;           tmp = 0;         } else {           if (lol) {             tmp++;           }         }       }       if (tmp > ans) ans = tmp;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z;     int sol;     int s[100009];     cin >> x >> y;     s[0] = 0;     for (int i = 1; i < x; i++) {       cin >> z;       s[i] = z + s[i - 1];     }     sol = s[y];     for (int i = y + 1; i < x; i++) {       sol = min(sol, s[i] - s[i - y]);     }     cout << sol << endl;   }


#include <bits/stdc++.h>   const int N = 1010;   double f[N][N];   bool vis[N][N];   inline double F(int m, int n) {     if (!m) return 1. / (n + 1);     if (!n) return 1;     if (vis[m][n]) return f[m][n];     vis[m][n] = true;     double p = 1 / (1 + (1. / ((n + 1) * F(n, m - 1))));     return f[m][n] = p * n / (n + 1) * (1 - F(n - 1, m)) + 1 - p;   }   int main() {     int m, n;     scanf( %d%d , &m, &n);     printf( %.11f %.11f n , F(m, n), 1 - F(m, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, len, ct;   int a[maxn], tot[maxn], cur[maxn];   long long ans;   void solve() {     for (int i = 1; i <= n; i++) tot[i] = cur[i] = 0;     for (int i = 1; i <= n; i++) tot[a[i]]++;     int r = 1;     for (int i = 1; i <= (n - 1) / 2; i++) {       while (r <= (n - 1) / 2 && (cur[a[r]] + 1) * 2 <= tot[a[r]]) {         cur[a[r]]++;         r++;       }       ans += r - i + 1;       if (a[i] != a[n - i + 1]) break;       tot[a[i]] -= 2;       cur[a[i]]--;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), tot[a[i]]++;     int val = 0;     for (int i = 1; i <= n; i++)       if (tot[i] & 1) {         if (val) {           puts( 0 );           return 0;         }         val = i;       }     while (1 + len <= n && n - len >= 1 && a[1 + len] == a[n - len]) len++;     if (len == n) {       printf( %lld n , 1LL * n * (n + 1) / 2);       return 0;     }     int l = n / 2, r = n / 2 + 1 + (n & 1);     while (l - ct >= 1 && r + ct <= n && a[l - ct] == a[r + ct]) ct++;     for (int i = 1; i <= n; i++) cur[i] = 0;     for (int i = len + 1; i <= l - ct; i++) cur[a[i]]++;     bool bad = false;     for (int i = r + ct; i <= n - len; i++) {       if (!cur[a[i]]) {         bad = true;         break;       }       cur[a[i]]--;     }     if (!bad) ans = 2LL * (len + 1) * (ct + 1);     solve();     reverse(a + 1, a + 1 + n);     solve();     ans -= len + 1;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int a[N];   long long ans[N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (n == 1) {       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << -a[1] <<   n ;       return 0;     }     for (int i = 1; i <= n; i++) {       long long x = a[i];       long long yu = x % (n - 1);       long long byu = (n - 1 - yu) * n;       ans[i] = byu + a[i];     }     cout << 1 <<     << n <<   n ;     for (int i = 1; i <= n; i++) {       cout << ans[i] - a[i] <<    ;     }     cout <<   n ;     cout << 1 <<     << 1 <<   n ;     cout << -ans[1] <<   n ;     cout << 2 <<     << n <<   n ;     for (int i = 2; i <= n; i++) {       cout << -ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1100000;   const long long M = 1000000007;   long long i, j, k, l, m, n, o, p, K, w, F[N], ni[N];   inline long long fastmi(long long x, long long m) {     long long ans = 1;     while (m) {       if (m & 1) ans = (ans * x) % M;       x = (x * x) % M;       m >>= 1;     }     return ans;   }   inline long long get(long long l, long long r) {     long long ans;     if ((r < 0) || (l < 0)) return 0;     if (l > r) return 1;     if (l == 0) return 0;     ans = (F[r] * ni[l - 1]) % M;     return ans;   }   inline long long Solve() {     long long ans1, ans2, ans, cul, cant;     F[0] = 1;     ni[0] = 1;     for (i = 1; i <= K; i++) {       F[i] = (F[i - 1] * i) % M;       ni[i] = fastmi(F[i], M - 2);     }     ans = 0;     for (i = 0; i <= K - 1; i++) {       cant = i + 1 - w + 1;       if (cant < 0) cant = 0;       k = K - cant;       o = (get(K - i, K - 1) * min(w, i + 1)) % M;       l = w - i - 2;       if (l < 0) l = 0;       j = w - 1 - l;       p = (fastmi(k, l) * get(k - j + 1, k)) % M;       cul = (o * p) % M;       ans += cul;       if (ans >= M) ans -= M;     }     ans1 = ans;     ans = 0;     for (i = 0; i <= K - 1; i++) {       cant = i + 1 - (w - 1) + 1;       if (cant < 0) cant = 0;       k = K - cant;       o = (get(K - i, K - 1) * min(w - 1, i + 1)) % M;       l = w - 1 - i - 2;       if (l < 0) l = 0;       j = w - 1 - l;       p = (fastmi(k, l) * get(k - j + 1, k)) % M;       cul = (o * p) % M;       ans += cul;       if (ans >= M) ans -= M;     }     ans2 = ans1 - ans;     if (ans2 < 0) ans2 += M;     ans1 = ans1 + ans1;     if (ans1 >= M) ans1 -= M;     ans1 -= ans2;     if (ans1 < 0) ans1 += M;     ans = (ans1 * K) % M;     return ans;   }   int main() {     cin >> K >> w;     cout << Solve() << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 5;   const int MOD = 1000000009;   int s[N * 4], f[N], a[N], taga[N * 4], tagb[N * 4];   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 * 10 + ch -  0 ;     return x * f;   }   void update(int x) { s[x] = (s[x << 1] + s[x << 1 | 1]) % MOD; }   void push(int x, int a, int b, int n) {     taga[x] = (taga[x] + a) % MOD;     tagb[x] = (tagb[x] + b) % MOD;     s[x] = ((long long)f[n] * a + (long long)(f[n + 1] - 1) * b + s[x]) % MOD;   }   void pushdown(int x, int l, int r) {     if (taga[x] > 0 || tagb[x] > 0) {       int mid = (l + r) >> 1, a = taga[x], b = tagb[x], C = mid - l,           A = ((long long)f[C] * a + (long long)f[C + 1] * b) % MOD,           B = ((long long)f[C + 1] * a + (long long)f[C + 2] * b) % MOD;       push(x << 1, a, b, mid - l + 1), push(x << 1 | 1, A, B, r - mid);       taga[x] = tagb[x] = 0;     }   }   void build(int x, int l, int r) {     if (l == r) {       s[x] = a[l];       return;     }     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);     update(x);   }   void change(int x, int l, int r, int p, int q) {     if (l > q || r < p) return;     if (l >= p && r <= q) {       push(x, f[l - p + 1], f[l - p + 2], r - l + 1);       return;     }     int mid = (l + r) >> 1;     pushdown(x, l, r);     change(x << 1, l, mid, p, q);     change(x << 1 | 1, mid + 1, r, p, q);     update(x);   }   int query(int x, int l, int r, int p, int q) {     if (l > q || r < p) return 0;     if (l >= p && r <= q) return s[x];     int mid = (l + r) >> 1;     pushdown(x, l, r);     return (query(x << 1, l, mid, p, q) + query(x << 1 | 1, mid + 1, r, p, q)) %            MOD;   }   void prints(int x, int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     pushdown(x, l, r);     prints(x << 1, l, mid);     prints(x << 1 | 1, mid + 1, r);   }   int main() {     int n = read(), m = read();     f[0] = 0, f[1] = 1;     for (int i = 2; i <= n + 2; i++) f[i] = (f[i - 1] + f[i - 2]) % MOD;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     build(1, 1, n);     for (int i = 1; i <= m; i++) {       int t = read(), l = read(), r = read();       if (t == 1)         change(1, 1, n, l, r);       else         printf( %d n , query(1, 1, n, l, r));     }   }


#include <bits/stdc++.h>   using namespace std;   int n, q, fa[50005], ff[50005], h[50005], tot, e[50005 << 1], nxt[50005 << 1],       mx[50005][256], cnt[50005][256], Ans[50005][256], ans, val[50005],       dep[50005];   template <class T>   inline void read(T &x) {     x = 0;     bool emm = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) emm = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ;     x *= emm;   }   inline void add(int x, int y) { e[++tot] = y, nxt[tot] = h[x], h[x] = tot; }   inline void dfs(int x) {     dep[x] = dep[fa[x]] + 1;     int i;     if (dep[x] >= 256) {       int l, r, mid, s;       for (i = x; dep[x] - dep[i] < 256; i = fa[i]) {         mx[x][val[i] >> 8] =             max(mx[x][val[i] >> 8], (dep[x] - dep[i] ^ val[i]) & 255);         cnt[x][val[i] >> 8]++;       }       ff[x] = i;       for (i = 1; i < 256; i++) cnt[x][i] += cnt[x][i - 1];       for (i = 0; i <= (n - 1) / 256; i++) {         for (l = s = 0, r = 256, mid = r >> 1; l < r - 1; mid = l + r >> 1) {           if ((s ^ i) < mid) {             if (cnt[x][r - 1] > cnt[x][mid - 1])               s |= r - mid, l = mid;             else               r = mid;           } else {             if (cnt[x][mid - 1] > ((l) ? cnt[x][l - 1] : 0))               s |= r - mid, r = mid;             else               l = mid;           }         }         Ans[x][i] = (s << 8) | mx[x][l];       }     }     for (i = h[x]; i; i = nxt[i])       if (e[i] != fa[x]) fa[e[i]] = x, dfs(e[i]);   }   int main() {     read(n), read(q);     for (int i = 1; i <= n; i++) read(val[i]);     for (int x, y, i = 1; i < n; i++) read(x), read(y), add(x, y), add(y, x);     for (dfs(1); q--;) {       int u, v, dis;       read(u), read(v);       for (dis = ans = 0; dep[v] - dep[u] >= 256; v = ff[v], dis++)         ans = max(ans, Ans[v][dis]);       for (dis <<= 8; v != fa[u]; v = fa[v], dis++) ans = max(ans, dis ^ val[v]);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using point_t = pair<int, int>;   int main() {     size_t n;     cin >> n;     vector<point_t> obelisks(n), clues(n);     for (point_t &p : obelisks) cin >> p.first >> p.second;     for (point_t &p : clues) cin >> p.first >> p.second;     point_t treasure;     map<point_t, size_t> finds;     for (point_t &ob : obelisks)       for (point_t &cl : clues) {         point_t p{ob.first + cl.first, ob.second + cl.second};         size_t &c{++finds[p]};         if (c == n) {           cout << p.first <<     << p.second << endl;           return 0;         }       }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long num[20];   int cnt;   int main() {     int n;     long long k, x;     long long ans = 0LL;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cnt = 0;       scanf( %I64d%I64d , &x, &k);       long long r = x + k - 1LL;       long long l = x;       while (l % 4 != 0 && l <= r) num[++cnt] = l++;       l--;       while (r % 4 != 3 && l < r) num[++cnt] = r--;       for (int j = 1; j <= cnt; j++) ans ^= num[j];     }     if (ans == 0LL)       printf( bolik n );     else       printf( tolik n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000110;   string str[7] = { monday ,  tuesday ,   wednesday ,  thursday ,                     friday ,  saturday ,  sunday };   int main() {     string s, s1;     while (cin >> s >> s1) {       int i;       int a, b;       for (i = 0; i < 7; i++) {         if (s == str[i]) a = i;         if (s1 == str[i]) b = i;       }       if (b - a == 3 || b - a == 0 || b - a == -4 || b - a == 2 || b - a == -4 ||           b - a == 2 || b - a == 3 || b - a == -4 || b - a == 2 || b - a == 3 ||           b - a == -5)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>    using namespace std;   #define     ll              long long   #define     mp              make_pair   #define     rep(i,a,b)      for( i=a;i<b;++i)   #define     repr(i,a,b)     for( i=a;i>=b;i--)   #define     up              upper_bound   #define     lb              lower_bound   #define     t()             int test;cin>>test;while(test--)   #define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);      #define TRACE   #ifdef TRACE   #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)       template <typename Arg1>       void __f(const char* name, Arg1&& arg1){           cout << name <<   :   << arg1 << endl;           //use cerr if u want to display at the bottom       }       template <typename Arg1, typename... Args>       void __f(const char* names, Arg1&& arg1, Args&&... args){           const char* comma = strchr(names + 1,  , ); cout.write(names, comma - names) <<   :   << arg1<<  |  ;__f(comma+1, args...);       }   #else   #define trace(...)   #endif      bool cmp(pair<ll,ll> a,pair<ll,ll> b){       if(a.first != b.first){           return a.first < b.first;       }else{           return a.second < b.second;       }   }      int main()   {         #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);       #endif       IOS;       ll t;       cin >> t;       while(t--){           ll n;            cin >> n;           vector<string> s(n);           for(ll i = 0;i < n;i++){                   cin >> s[i];           }            ll k= 0;           for(ll i = 0;i < n;i++){               for(ll j = 0;j < n;j++){                   if (s[i][j] !=  . ){                        k++;                   }               }           }           bool flag = true;           for(ll x = 0;x < 3;x++){               for(ll y = 0;y < 3;y++){                   if(x == y){                       continue;                   }else{                       ll count = 0;                       for(ll i = 0;i < n;i++){                           for(ll j= 0;j < n;j++){                               if(s[i][j] ==  X  && (i + j)%3 == x){                                   count++;                               }else if(s[i][j] ==  O  && (i + j)%3 == y){                                   count++;                               }                           }                       }                       if(count <= k/3){                           for(ll i = 0;i < n;i++){                               for(ll j= 0;j < n;j++){                                   if(s[i][j] ==  X  && (i + j)%3 == x){                                       s[i][j] =  O ;                                   }else if(s[i][j] ==  O  && (i + j)%3 == y){                                       s[i][j] =  X ;                                   }                               }                           }                           for(auto it : s){                               cout << it <<   n ;                           }                           flag = false;                           break;                       }                      }               }               if(!flag){                   break;               }           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int MM[500], FF[500];   int main() {     ios::sync_with_stdio(0);     int N;     cin >> N;     for (int i = 0; i < N; i++) {       char g;       int from, to;       cin >> g >> from >> to;       int *v;       if (g ==  M )         for (int i = from; i <= to; i++) MM[i]++;       else         for (int i = from; i <= to; i++) FF[i]++;     }     int MAX = 0;     for (int i = 1; i < 400; i++) MAX = max(MAX, min(MM[i], FF[i]) * 2);     cout << MAX;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int input() {     int x = 0, f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= ch ==  0 , ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   int n, m, du[2100];   bool Check() {     for (int i = 1; i <= n; i++) {       if (du[i] % 2 == 1) return 0;     }     printf( 1 n );     for (int i = 1; i < n; i++) printf( 1  );     printf( 1 n );     return 1;   }   bitset<2100> s[2100];   void Gauss() {     int x = 1;     for (int j = 1; j <= n; j++) {       for (int i = x; i <= n; i++) {         if (s[i][j] == 1) {           swap(s[i], s[x]);           break;         }       }       if (s[x][j] == 0) continue;       for (int i = 1; i <= n; i++) {         if (i == x) continue;         if (s[i][j] == 1) s[i] ^= s[x];       }       x++;     }   }   int as[2100];   void Solve() {     int x, y;     n = input(), m = input();     for (int i = 1; i <= n; i++) s[i].reset();     memset(du, 0, sizeof du);     for (int i = 1; i <= m; i++) {       x = input(), y = input();       du[x]++, du[y]++;       s[x][y] = 1, s[y][x] = 1;     }     if (Check()) return;     for (int i = 1; i <= n; i++) {       if (du[i] % 2 == 1) s[i][i] = 1, s[i][n + 1] = 1;     }     Gauss();     x = 1;     for (int j = 1; j <= n; j++) {       if (s[x][j] == 0) {         as[j] = 1;         continue;       }       as[j] = s[x][n + 1] + 1;       x++;     }     printf( 2 n );     for (int i = 1; i < n; i++) printf( %d  , as[i]);     printf( %d n , as[n]);   }   int main() {     int T;     T = input();     while (T--) {       Solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int ans[100000 + 1];   void reverseAns(int l, int r) {     if (l > r) return;     int mid = (l + r) >> 1;     for (int i = 1; i <= mid - l + 1; ++i) {       swap(ans[i + l - 1], ans[r - i + 1]);     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       ans[i] = i;     }     int block = round(sqrt(n));     int tot = n / block;     for (int i = 1; i <= tot; ++i) {       reverseAns((i - 1) * block + 1, i * block);     }     reverseAns(tot * block + 1, n);     for (int i = 1; i <= n; ++i) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }